23 #ifndef otbSubsampledImageRegionConstIterator_hxx
24 #define otbSubsampledImageRegionConstIterator_hxx
31 template <
class TImage>
37 const IndexType& startIndex = this->m_Region.GetIndex();
38 const SizeType& size = this->m_Region.GetSize();
47 template <
class TImage>
49 :
itk::ImageRegionConstIterator<TImage>(ptr, region)
54 const IndexType& startIndex = this->m_Region.GetIndex();
55 const SizeType& size = this->m_Region.GetSize();
64 template <
class TImage>
70 const IndexType& startIndex = this->m_Region.GetIndex();
71 const SizeType& size = this->m_Region.GetSize();
80 template <
class TImage>
82 :
itk::ImageRegionConstIterator<TImage>(it)
86 const IndexType& startIndex = this->m_Region.GetIndex();
87 const SizeType& size = this->m_Region.GetSize();
98 template <
class TImage>
103 SetSubsampleFactor(index);
106 template <
class TImage>
109 this->m_SubsampleFactor = factor;
112 const IndexType& startIndex = this->m_Region.GetIndex();
113 const SizeType& size = this->m_Region.GetSize();
115 for (
unsigned int i = 0; i < ImageIteratorDimension; ++i)
117 m_FirstUsableIndex[i] = startIndex[i];
118 while (m_FirstUsableIndex[i] != (m_SubsampleFactor[i] * (m_FirstUsableIndex[i] / m_SubsampleFactor[i])))
120 ++m_FirstUsableIndex[i];
122 m_LastUsableIndex[i] = startIndex[i] +
static_cast<IndexValueType>(m_SubsampleFactor[i] * ((size[i] - 1) / m_SubsampleFactor[i]));
125 m_SubSampledBeginOffset = this->m_Image->ComputeOffset(m_FirstUsableIndex);
128 m_SubSampledEndOffset = this->m_Image->ComputeOffset(m_LastUsableIndex) + 1;
131 template <
class TImage>
134 this->m_Offset = m_SubSampledBeginOffset;
136 const SizeType& size = this->m_Region.GetSize();
138 this->m_SpanBeginOffset = this->m_Offset;
139 this->m_SpanEndOffset = this->m_Offset +
static_cast<IndexValueType>(m_SubsampleFactor[0] * ((size[0] - 1) / m_SubsampleFactor[0])) + 1;
142 template <
class TImage>
145 this->m_Offset = m_SubSampledEndOffset - 1;
146 this->m_SpanEndOffset = this->m_Offset + 1;
147 this->m_SpanBeginOffset = this->m_Offset - m_LastUsableIndex[0];
150 template <
class TImage>
155 for (
unsigned int i = 0; i < ImageIteratorDimension; ++i)
157 while (theIndex[i] != (m_SubsampleFactor[i] * (theIndex[i] / m_SubsampleFactor[i])))
162 if (theIndex[i] >
static_cast<IndexValueType>(this->m_Region.GetIndex()[i] + this->m_Region.GetSize()[i]))
164 theIndex[i] = ind[i];
165 while (theIndex[i] != (m_SubsampleFactor[i] * (theIndex[i] / m_SubsampleFactor[i])))
170 if (theIndex[i] < this->m_Region.GetIndex()[i])
171 theIndex[i] = ind[i];
176 OffsetType theOffset = this->m_Image->ComputeOffset(theIndex);
177 SetOffset(theOffset);
180 template <
class TImage>
183 this->m_Offset = offset;
185 const SizeType& size = this->m_Region.GetSize();
187 this->m_SpanBeginOffset = this->m_Offset;
188 this->m_SpanEndOffset = this->m_Offset +
static_cast<IndexValueType>(m_SubsampleFactor[0] * ((size[0] - 1) / m_SubsampleFactor[0])) + 1;
191 template <
class TImage>
194 IndexType startIndex = this->m_Region.GetIndex();
195 SizeType size = this->m_Region.GetSize();
197 for (
unsigned int i = 0; i < ImageIteratorDimension; ++i)
199 startIndex[i] /= m_SubsampleFactor[i];
201 size[i] /= m_SubsampleFactor[i];
206 newRegion.SetIndex(startIndex);
207 newRegion.SetSize(size);
211 std::cerr <<
"InitialImageSize (";
212 for (
unsigned int i = 0; i < ImageIteratorDimension - 1; ++i)
213 std::cerr << this->m_Region.GetSize()[i] <<
", ";
214 std::cerr << this->m_Region.GetSize()[ImageIteratorDimension - 1] <<
") with index (";
215 for (
unsigned int i = 0; i < ImageIteratorDimension - 1; ++i)
216 std::cerr << this->m_Region.GetIndex()[i] <<
", ";
217 std::cerr << this->m_Region.GetIndex()[ImageIteratorDimension - 1] <<
")\n";
219 std::cerr <<
"NewRegionSize (";
220 for (
unsigned int i = 0; i < ImageIteratorDimension - 1; ++i)
221 std::cerr << size[i] <<
", ";
222 std::cerr << size[ImageIteratorDimension - 1] <<
") with index (";
223 for (
unsigned int i = 0; i < ImageIteratorDimension - 1; ++i)
224 std::cerr << startIndex[i] <<
", ";
225 std::cerr << startIndex[ImageIteratorDimension - 1] <<
")\n";
227 std::cerr <<
"FirstIndex (";
228 for (
unsigned int i = 0; i < ImageIteratorDimension - 1; ++i)
229 std::cerr << m_FirstUsableIndex[i] <<
", ";
230 std::cerr << m_FirstUsableIndex[ImageIteratorDimension - 1] <<
") offset=";
231 std::cerr << m_SubSampledBeginOffset <<
"\n";
233 std::cerr <<
"LastIndex (";
234 for (
unsigned int i = 0; i < ImageIteratorDimension - 1; ++i)
235 std::cerr << m_LastUsableIndex[i] <<
", ";
236 std::cerr << m_LastUsableIndex[ImageIteratorDimension - 1] <<
") offset=";
237 std::cerr << m_SubSampledEndOffset <<
"\n";
243 template <
class TImage>
247 IndexType ind = this->m_Image->ComputeIndex(
static_cast<typename TImage::OffsetValueType
>(this->m_Offset));
249 const IndexType& startIndex = this->m_Region.GetIndex();
250 const SizeType& size = this->m_Region.GetSize();
257 ind[0] += m_SubsampleFactor[0];
258 bool done = (ind[0] > m_LastUsableIndex[0]);
259 for (
unsigned int i = 1; done && i < ImageIteratorDimension; ++i)
261 done = (ind[i] >= m_LastUsableIndex[i]);
269 while ((dim + 1 < ImageIteratorDimension) && (ind[dim] > m_LastUsableIndex[dim]))
271 ind[dim] = startIndex[dim];
273 ind[dim] += m_SubsampleFactor[dim];
276 this->m_Offset = this->m_Image->ComputeOffset(ind);
277 this->m_SpanEndOffset = this->m_Offset +
static_cast<IndexValueType>(m_SubsampleFactor[0] * ((size[0] - 1) / m_SubsampleFactor[0])) + 1;
278 this->m_SpanBeginOffset = this->m_Offset;
281 template <
class TImage>
286 const IndexType& startIndex = this->m_Region.GetIndex();
294 ind[0] -= m_SubsampleFactor[0];
295 done = (ind[0] <= startIndex[0] - 1);
296 for (
unsigned int i = 1; done && i < ImageIteratorDimension; ++i)
298 done = (ind[i] <= startIndex[i]);
306 while ((dim < ImageIteratorDimension - 1) && (ind[dim] < startIndex[dim]))
308 ind[dim] = m_LastUsableIndex[dim];
310 ind[dim] -= m_SubsampleFactor[dim];
313 this->m_Offset = this->m_Image->ComputeOffset(ind);
314 this->m_SpanEndOffset = this->m_Offset + 1;
315 this->m_SpanBeginOffset = this->m_Offset - m_LastUsableIndex[0];