2014-12-09 21:30:06 +00:00
|
|
|
namespace dk {
|
2014-12-12 19:04:48 +00:00
|
|
|
namespace implem {
|
2015-01-08 11:20:17 +00:00
|
|
|
template <uint32_t D>
|
2015-06-06 11:52:48 +00:00
|
|
|
inline size_t get_index_from_pos (const Vector<D>& parPos, const Vector<D>& parSize) {
|
2014-12-12 19:04:48 +00:00
|
|
|
size_t index = 0;
|
|
|
|
for (size_t d = 0; d < D; ++d) {
|
|
|
|
size_t pos = static_cast<size_t>(parPos[D - 1 - d]);
|
|
|
|
for (size_t p = 0; p < D - 1 - d; ++p) {
|
|
|
|
pos *= static_cast<size_t>(parSize[p]);
|
|
|
|
}
|
|
|
|
|
|
|
|
index += pos;
|
|
|
|
}
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(NDEBUG)
|
|
|
|
template <>
|
2015-06-06 11:52:48 +00:00
|
|
|
inline size_t get_index_from_pos<2> (const Vector<2>& parPos, const Vector<2>& parSize) {
|
2014-12-12 19:04:48 +00:00
|
|
|
return parPos.y() * parSize.x() + parPos.x();
|
|
|
|
}
|
|
|
|
#endif
|
2014-12-14 12:13:10 +00:00
|
|
|
|
2015-01-08 11:20:17 +00:00
|
|
|
template <uint32_t D>
|
2015-06-06 11:52:48 +00:00
|
|
|
inline Vector<D> buildPastEndCoordinate (const Vector<D>& parFrom, const Vector<D>& parTo) {
|
|
|
|
Vector<D> retval;
|
2014-12-14 12:13:10 +00:00
|
|
|
for (size_t d = 0; d < D - 1; ++d) {
|
|
|
|
retval[d] = parFrom[d];
|
|
|
|
}
|
|
|
|
retval[D - 1] = parTo[D - 1];
|
|
|
|
return retval;
|
|
|
|
}
|
2015-05-24 15:17:53 +00:00
|
|
|
|
|
|
|
template <typename T, uint32_t D, typename T1>
|
2015-06-06 11:52:48 +00:00
|
|
|
inline const Vector<D>& get_from_from_iterator (const TileIterator<T, D, T1>& parIterator) {
|
2015-05-24 15:17:53 +00:00
|
|
|
return parIterator.m_from;
|
|
|
|
}
|
2014-12-12 19:04:48 +00:00
|
|
|
} //namespace implem
|
|
|
|
|
2015-01-08 11:20:17 +00:00
|
|
|
template <typename T, uint32_t D, typename T1>
|
2014-12-30 16:53:15 +00:00
|
|
|
TileIterator<T, D, T1>::TileIterator() :
|
2014-12-09 21:30:06 +00:00
|
|
|
m_pos(CoordinateScalarType()),
|
|
|
|
m_from(CoordinateScalarType()),
|
|
|
|
m_to(CoordinateScalarType()),
|
2015-01-06 15:00:24 +00:00
|
|
|
m_subdivareasize(CoordinateScalarType()),
|
|
|
|
m_data(nullptr),
|
|
|
|
m_subindex(0),
|
|
|
|
m_maxsubindex(0)
|
2014-12-09 21:30:06 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-01-08 11:20:17 +00:00
|
|
|
template <typename T, uint32_t D, typename T1>
|
2014-12-30 16:53:15 +00:00
|
|
|
TileIterator<T, D, T1>::TileIterator (qualif_vector_type* parData, const coords& parFrom, const coords& parTo) :
|
2014-12-09 21:30:06 +00:00
|
|
|
m_pos(parFrom),
|
|
|
|
m_from(parFrom),
|
|
|
|
m_to(parTo),
|
2015-01-06 15:00:24 +00:00
|
|
|
m_subdivareasize(parTo - parFrom),
|
|
|
|
m_data(parData),
|
|
|
|
m_subindex(0),
|
|
|
|
m_maxsubindex(0)
|
2014-12-09 21:30:06 +00:00
|
|
|
{
|
2014-12-12 19:04:48 +00:00
|
|
|
DK_ASSERT(parData);
|
2014-12-09 21:30:06 +00:00
|
|
|
}
|
|
|
|
|
2015-01-08 11:20:17 +00:00
|
|
|
template <typename T, uint32_t D, typename T1>
|
2014-12-30 16:53:15 +00:00
|
|
|
TileIterator<T, D, T1>::TileIterator (qualif_vector_type* parData, const coords& parFrom, const coords& parTo, const coords& parAreaFrom, const coords& parAreaTo) :
|
2014-12-09 21:30:06 +00:00
|
|
|
m_pos(parFrom),
|
|
|
|
m_from(parFrom),
|
|
|
|
m_to(parTo),
|
2015-01-06 15:00:24 +00:00
|
|
|
m_subdivareasize(parAreaTo - parAreaFrom),
|
|
|
|
m_data(parData),
|
|
|
|
m_subindex(0),
|
|
|
|
m_maxsubindex(0)
|
|
|
|
{
|
|
|
|
DK_ASSERT(parData);
|
|
|
|
}
|
|
|
|
|
2015-01-08 11:20:17 +00:00
|
|
|
template <typename T, uint32_t D, typename T1>
|
2015-01-06 15:00:24 +00:00
|
|
|
TileIterator<T, D, T1>::TileIterator (qualif_vector_type* parData, const coords& parFrom, const coords& parTo, const coords& parAreaFrom, const coords& parAreaTo, const coords& parSubdiv) :
|
|
|
|
m_pos(parFrom),
|
|
|
|
m_from(parFrom),
|
|
|
|
m_to(parTo),
|
|
|
|
m_subdivareasize((parAreaTo - parAreaFrom) * parSubdiv),
|
|
|
|
m_data(parData),
|
|
|
|
m_subindex(0),
|
|
|
|
m_maxsubindex(implem::area(parSubdiv) - 1)
|
2014-12-09 21:30:06 +00:00
|
|
|
{
|
2014-12-12 19:04:48 +00:00
|
|
|
DK_ASSERT(parData);
|
2014-12-09 21:30:06 +00:00
|
|
|
}
|
|
|
|
|
2015-01-08 11:20:17 +00:00
|
|
|
template <typename T, uint32_t D, typename T1>
|
2014-12-30 16:53:15 +00:00
|
|
|
void TileIterator<T, D, T1>::increment() {
|
2015-01-06 15:00:24 +00:00
|
|
|
if (m_subindex < m_maxsubindex) {
|
|
|
|
++m_subindex;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_subindex = 0;
|
2014-12-09 21:30:06 +00:00
|
|
|
for (size_t d = 0; d < D - 1; ++d) {
|
|
|
|
++m_pos[d];
|
2015-01-05 17:01:28 +00:00
|
|
|
if (m_pos[d] >= m_to[d])
|
|
|
|
m_pos[d] = m_from[d];
|
2014-12-09 21:30:06 +00:00
|
|
|
else
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
++m_pos[D - 1];
|
|
|
|
}
|
2014-12-11 22:58:52 +00:00
|
|
|
|
2015-01-08 11:20:17 +00:00
|
|
|
template <typename T, uint32_t D, typename T1>
|
2014-12-30 16:53:15 +00:00
|
|
|
void TileIterator<T, D, T1>::decrement() {
|
2015-01-06 15:00:24 +00:00
|
|
|
if (m_maxsubindex > 0 and m_subindex == 0) {
|
|
|
|
--m_subindex;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_subindex = m_maxsubindex;
|
2014-12-11 22:58:52 +00:00
|
|
|
for (size_t d = 0; d < D; ++d) {
|
2015-01-05 17:01:28 +00:00
|
|
|
if (m_pos[d] > m_from[d]) {
|
2014-12-11 22:58:52 +00:00
|
|
|
--m_pos[d];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else {
|
2015-01-06 15:00:24 +00:00
|
|
|
m_pos[d] = m_to[d];
|
2014-12-11 22:58:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
++m_pos[D - 1];
|
|
|
|
}
|
|
|
|
|
2015-01-08 11:20:17 +00:00
|
|
|
template <typename T, uint32_t D, typename T1>
|
2015-05-27 22:25:06 +00:00
|
|
|
void TileIterator<T, D, T1>::advance (size_t /*parAdvance*/) {
|
2014-12-11 22:58:52 +00:00
|
|
|
//TODO: implement
|
|
|
|
}
|
|
|
|
|
2015-01-08 11:20:17 +00:00
|
|
|
template <typename T, uint32_t D, typename T1>
|
2014-12-30 16:53:15 +00:00
|
|
|
ptrdiff_t TileIterator<T, D, T1>::distance_to (const TileIterator& parOther) {
|
2014-12-12 19:04:48 +00:00
|
|
|
return std::distance(this->get_current_index(), parOther.get_current_index());
|
2014-12-11 22:58:52 +00:00
|
|
|
}
|
|
|
|
|
2015-01-08 11:20:17 +00:00
|
|
|
template <typename T, uint32_t D, typename T1>
|
2014-12-30 16:53:15 +00:00
|
|
|
bool TileIterator<T, D, T1>::equal (const TileIterator& parOther) const {
|
2014-12-12 19:04:48 +00:00
|
|
|
return m_data == parOther.m_data and m_pos == parOther.m_pos;
|
2014-12-11 22:58:52 +00:00
|
|
|
}
|
2015-05-24 15:18:46 +00:00
|
|
|
|
|
|
|
template <typename T, uint32_t D, typename T1>
|
|
|
|
T& TileIterator<T, D, T1>::dereference() const {
|
|
|
|
const auto index = this->get_current_index();
|
2015-08-14 10:30:27 +00:00
|
|
|
DK_ASSERT(m_data);
|
|
|
|
DK_ASSERT(index < m_data->size());
|
2015-05-24 15:18:46 +00:00
|
|
|
return (*m_data)[index];
|
|
|
|
}
|
2014-12-09 21:30:06 +00:00
|
|
|
} //namespace dk
|