ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
itkImageRegionReverseConstIterator.h
Go to the documentation of this file.
1/*=========================================================================
2 *
3 * Copyright NumFOCUS
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * https://www.apache.org/licenses/LICENSE-2.0.txt
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 *=========================================================================*/
18#ifndef itkImageRegionReverseConstIterator_h
19#define itkImageRegionReverseConstIterator_h
20
23
24namespace itk
25{
102template <typename TImage>
103class ITK_TEMPLATE_EXPORT ImageRegionReverseConstIterator : public ImageReverseConstIterator<TImage>
104{
105public:
109
112 using typename Superclass::IndexType;
113
116 using typename Superclass::SizeType;
117
120 using typename Superclass::OffsetType;
121
123 using typename Superclass::RegionType;
124
127 using typename Superclass::ImageType;
128
132 using typename Superclass::PixelContainer;
133 using PixelContainerPointer = typename PixelContainer::Pointer;
134
136 using typename Superclass::InternalPixelType;
137
139 using typename Superclass::PixelType;
140
143 using typename Superclass::AccessorType;
144
146 itkOverrideGetNameOfClassMacro(ImageRegionReverseConstIterator);
147
155
159 : Superclass(ptr, region)
160 {
162 m_SpanEndOffset = this->m_BeginOffset - static_cast<OffsetValueType>(this->m_Region.GetSize()[0]);
163 }
164
173 : Superclass(it)
174 {
175 IndexType ind = this->GetIndex();
176
177 m_SpanBeginOffset = this->m_Offset + static_cast<OffsetValueType>(this->m_Region.GetSize()[0]) -
178 (ind[0] - this->m_Region.GetIndex()[0]);
179 m_SpanEndOffset = m_SpanBeginOffset - static_cast<OffsetValueType>(this->m_Region.GetSize()[0]);
180 }
181
185 : Superclass(it)
186 {
187 IndexType ind = this->GetIndex();
188
189 m_SpanBeginOffset = this->m_Offset + static_cast<OffsetValueType>(this->m_Region.GetSize()[0]) -
190 (ind[0] - this->m_Region.GetIndex()[0]);
191 m_SpanEndOffset = m_SpanBeginOffset - static_cast<OffsetValueType>(this->m_Region.GetSize()[0]);
192 }
193
197 : Superclass(it)
198 {
199 IndexType ind = this->GetIndex();
200
201 m_SpanBeginOffset = this->m_Offset + static_cast<OffsetValueType>(this->m_Region.GetSize()[0]) -
202 (ind[0] - this->m_Region.GetIndex()[0]);
203 m_SpanEndOffset = m_SpanBeginOffset - static_cast<OffsetValueType>(this->m_Region.GetSize()[0]);
204 }
205
208 void
210 {
212
213 // reset the span offsets
215 m_SpanEndOffset = this->m_BeginOffset - static_cast<OffsetValueType>(this->m_Region.GetSize()[0]);
216 }
217
220 void
222 {
224
225 // reset the span offsets
227 m_SpanBeginOffset = m_SpanEndOffset + static_cast<OffsetValueType>(this->m_Region.GetSize()[0]);
228 }
229
233 void
234 SetIndex(const IndexType & ind) override
235 {
237 m_SpanBeginOffset = this->m_Offset + static_cast<OffsetValueType>(this->m_Region.GetSize()[0]) -
238 (ind[0] - this->m_Region.GetIndex()[0]);
239 m_SpanEndOffset = m_SpanBeginOffset - static_cast<OffsetValueType>(this->m_Region.GetSize()[0]);
240 }
241
250 Self &
252 {
253 if (--this->m_Offset <= m_SpanEndOffset)
254 {
255 // We have past the beginning of the span (row), need to wrap around.
256
257 // First move forward one pixel, because we are going to use a different
258 // algorithm to compute the next pixel
259 this->m_Offset++;
260
261 // Get the index of the first pixel on the span (row)
263 this->m_Image->ComputeIndex(static_cast<OffsetValueType>(this->m_Offset));
264
265 const typename ImageConstIterator<TImage>::IndexType & startIndex = this->m_Region.GetIndex();
266 const typename ImageConstIterator<TImage>::SizeType & size = this->m_Region.GetSize();
267
268 // Decrement along a row, then wrap at the beginning of the region row.
269
270 // Check to see if we are past the first pixel in the region
271 // Note that --ind[0] moves to the previous pixel along the row.
272 bool done = (--ind[0] == startIndex[0] - 1);
273 for (unsigned int i = 1; done && i < this->ImageIteratorDimension; ++i)
274 {
275 done = (ind[i] == startIndex[i]);
276 }
277
278 // if the iterator is outside the region (but not past region begin) then
279 // we need to wrap around the region
280 unsigned int dim = 0;
281 if (!done)
282 {
283 while ((dim < this->ImageIteratorDimension - 1) && (ind[dim] < startIndex[dim]))
284 {
285 ind[dim] = startIndex[dim] + static_cast<OffsetValueType>(size[dim]) - 1;
286 ind[++dim]--;
287 }
288 }
289 this->m_Offset = this->m_Image->ComputeOffset(ind);
291 m_SpanEndOffset = m_SpanBeginOffset - static_cast<OffsetValueType>(size[0]);
292 }
293 return *this;
294 }
295
304 Self &
306 {
307 if (++this->m_Offset >= m_SpanBeginOffset)
308 {
309 // We have reached the end of the span (row), need to wrap around.
310
311 // First back up one pixel, because we are going to use a different
312 // algorithm to compute the next pixel
313 --this->m_Offset;
314
315 // Get the index of the last pixel on the span (row)
317 this->m_Image->ComputeIndex(static_cast<OffsetValueType>(this->m_Offset));
318
319 const typename ImageIterator<TImage>::IndexType & startIndex = this->m_Region.GetIndex();
320 const typename ImageIterator<TImage>::SizeType & size = this->m_Region.GetSize();
321
322 // Increment along a row, then wrap at the end of the region row.
323 // Check to see if we are past the last pixel in the region
324 // Note that ++ind[0] moves to the next pixel along the row.
325 bool done = (++ind[0] == startIndex[0] + static_cast<OffsetValueType>(size[0]));
326 for (unsigned int i = 1; done && i < this->ImageIteratorDimension; ++i)
327 {
328 done = (ind[i] == startIndex[i] + static_cast<OffsetValueType>(size[i]) - 1);
329 }
330
331 // if the iterator is outside the region (but not past region end) then
332 // we need to wrap around the region
333 unsigned int dim = 0;
334 if (!done)
335 {
336 while ((dim < this->ImageIteratorDimension - 1) &&
337 (ind[dim] > startIndex[dim] + static_cast<OffsetValueType>(size[dim]) - 1))
338 {
339 ind[dim] = startIndex[dim];
340 ind[++dim]++;
341 }
342 }
343 this->m_Offset = this->m_Image->ComputeOffset(ind);
345 m_SpanEndOffset = this->m_Offset - static_cast<OffsetValueType>(size[0]);
346 }
347 return *this;
348 }
349
350protected:
351 SizeValueType m_SpanBeginOffset{}; // offset to last pixel in the row
352 SizeValueType m_SpanEndOffset{}; // offset to one pixel before the row
353};
354} // end namespace itk
355
356#endif
A multi-dimensional image iterator templated over image type.
typename TImage::IndexType IndexType
typename TImage::SizeType SizeType
typename TImage::IndexType IndexType
typename TImage::SizeType SizeType
A multi-dimensional iterator templated over image type that walks a region of pixels.
ImageRegionReverseConstIterator(const ImageRegionIterator< TImage > &it)
ImageRegionReverseConstIterator(const ImageReverseConstIterator< TImage > &it)
ImageRegionReverseConstIterator(const ImageType *ptr, const RegionType &region)
ImageRegionReverseConstIterator(const ImageConstIterator< TImage > &it)
virtual void SetIndex(const IndexType &ind)
static constexpr unsigned int ImageIteratorDimension
typename TImage::AccessorType AccessorType
typename TImage::PixelContainer PixelContainer
typename TImage::InternalPixelType InternalPixelType
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
unsigned long SizeValueType
Definition itkIntTypes.h:86
long OffsetValueType
Definition itkIntTypes.h:97