ITK  5.2.0
Insight Toolkit
itkImageRegionConstIterator.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  * http://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 itkImageRegionConstIterator_h
19 #define itkImageRegionConstIterator_h
20 
21 #include "itkImageIterator.h"
22 
23 namespace itk
24 {
108 template <typename TImage>
109 class ITK_TEMPLATE_EXPORT ImageRegionConstIterator : public ImageConstIterator<TImage>
110 {
111 public:
115 
120  static constexpr unsigned int ImageIteratorDimension = Superclass::ImageIteratorDimension;
121 
129  using SizeType = typename Superclass::SizeType;
138 
141 
144  : ImageConstIterator<TImage>()
145  {
146  m_SpanBeginOffset = 0;
147  m_SpanEndOffset = 0;
148  }
150 
153  ImageRegionConstIterator(const ImageType * ptr, const RegionType & region)
154  : ImageConstIterator<TImage>(ptr, region)
155  {
156  m_SpanBeginOffset = this->m_BeginOffset;
157  m_SpanEndOffset = this->m_BeginOffset + static_cast<OffsetValueType>(this->m_Region.GetSize()[0]);
158  }
160 
168  {
170 
171  IndexType ind = this->GetIndex();
172  m_SpanEndOffset = this->m_Offset + static_cast<OffsetValueType>(this->m_Region.GetSize()[0]) -
173  (ind[0] - this->m_Region.GetIndex()[0]);
174  m_SpanBeginOffset = m_SpanEndOffset - static_cast<OffsetValueType>(this->m_Region.GetSize()[0]);
175  }
176 
184  {
186 
187  IndexType ind = this->GetIndex();
188  m_SpanEndOffset = this->m_Offset + static_cast<OffsetValueType>(this->m_Region.GetSize()[0]) -
189  (ind[0] - this->m_Region.GetIndex()[0]);
190  m_SpanBeginOffset = m_SpanEndOffset - static_cast<OffsetValueType>(this->m_Region.GetSize()[0]);
191  }
192 
195  void
197  {
198  Superclass::GoToBegin();
199 
200  // reset the span offsets
201  m_SpanBeginOffset = this->m_BeginOffset;
202  m_SpanEndOffset = this->m_BeginOffset + static_cast<OffsetValueType>(this->m_Region.GetSize()[0]);
203  }
204 
207  void
209  {
210  Superclass::GoToEnd();
211 
212  // reset the span offsets
213  m_SpanEndOffset = this->m_EndOffset;
214  m_SpanBeginOffset = m_SpanEndOffset - static_cast<OffsetValueType>(this->m_Region.GetSize()[0]);
215  }
216 
220  void
221  SetIndex(const IndexType & ind) override
222  {
223  Superclass::SetIndex(ind);
224  m_SpanEndOffset = this->m_Offset + static_cast<OffsetValueType>(this->m_Region.GetSize()[0]) -
225  (ind[0] - this->m_Region.GetIndex()[0]);
226  m_SpanBeginOffset = m_SpanEndOffset - static_cast<OffsetValueType>(this->m_Region.GetSize()[0]);
227  }
229 
237  Self &
239  {
240  if (++this->m_Offset >= m_SpanEndOffset)
241  {
242  this->Increment();
243  }
244  return *this;
245  }
247 
255  Self &
257  {
258  if (--this->m_Offset < m_SpanBeginOffset)
259  {
260  this->Decrement();
261  }
262  return *this;
263  }
265 
266 protected:
267  OffsetValueType m_SpanBeginOffset; // one pixel before the beginning of the span
268  // (row)
269  OffsetValueType m_SpanEndOffset; // one pixel past the end of the span (row)
270 
271 private:
272  void
273  Increment(); // advance in a direction other than the fastest moving
274 
275  void
276  Decrement(); // go back in a direction other than the fastest moving
277 };
278 } // end namespace itk
279 
280 #ifndef ITK_MANUAL_INSTANTIATION
281 # include "itkImageRegionConstIterator.hxx"
282 #endif
283 
284 #endif
itkImageIterator.h
itk::ImageConstIterator< ImageType >::SizeType
typename ImageType ::SizeType SizeType
Definition: itkImageConstIterator.h:103
itk::ImageConstIterator< ImageType >::PixelType
typename ImageType ::PixelType PixelType
Definition: itkImageConstIterator.h:124
itk::ImageRegionConstIterator::ImageRegionConstIterator
ImageRegionConstIterator(const ImageIterator< TImage > &it)
Definition: itkImageRegionConstIterator.h:167
itk::ImageRegionConstIterator::GoToBegin
void GoToBegin()
Definition: itkImageRegionConstIterator.h:196
itk::ImageRegionConstIterator::SetIndex
void SetIndex(const IndexType &ind) override
Definition: itkImageRegionConstIterator.h:221
itk::ImageConstIterator< ImageType >::OffsetType
typename ImageType ::OffsetType OffsetType
Definition: itkImageConstIterator.h:106
itk::ImageRegionConstIterator::ImageRegionConstIterator
ImageRegionConstIterator(const ImageConstIterator< TImage > &it)
Definition: itkImageRegionConstIterator.h:183
itk::ImageConstIterator< ImageType >::AccessorType
typename ImageType ::AccessorType AccessorType
Definition: itkImageConstIterator.h:128
itk::ImageConstIterator< ImageType >::RegionType
typename ImageType ::RegionType RegionType
Definition: itkImageConstIterator.h:109
itk::ImageRegionConstIterator::operator++
Self & operator++()
Definition: itkImageRegionConstIterator.h:238
itk::ImageRegionConstIterator::ImageRegionConstIterator
ImageRegionConstIterator()
Definition: itkImageRegionConstIterator.h:143
itk::GTest::TypedefsAndConstructors::Dimension2::SizeType
ImageBaseType::SizeType SizeType
Definition: itkGTestTypedefsAndConstructors.h:49
itk::ImageConstIterator::operator=
Self & operator=(const Self &it)
Definition: itkImageConstIterator.h:185
itk::ImageRegionConstIterator::GoToEnd
void GoToEnd()
Definition: itkImageRegionConstIterator.h:208
itk::ImageConstIterator< ImageType >::PixelContainerPointer
typename PixelContainer::Pointer PixelContainerPointer
Definition: itkImageConstIterator.h:118
itk::GTest::TypedefsAndConstructors::Dimension2::IndexType
ImageBaseType::IndexType IndexType
Definition: itkGTestTypedefsAndConstructors.h:50
itk::GTest::TypedefsAndConstructors::Dimension2::RegionType
ImageBaseType::RegionType RegionType
Definition: itkGTestTypedefsAndConstructors.h:54
itk::ImageRegionConstIterator::m_SpanEndOffset
OffsetValueType m_SpanEndOffset
Definition: itkImageRegionConstIterator.h:269
itk::ImageConstIterator< ImageType >::InternalPixelType
typename ImageType ::InternalPixelType InternalPixelType
Definition: itkImageConstIterator.h:121
itk::ImageIterator
A multi-dimensional iterator templated over image type.
Definition: itkImageIterator.h:65
itk::ImageRegionConstIterator::m_SpanBeginOffset
OffsetValueType m_SpanBeginOffset
Definition: itkImageRegionConstIterator.h:267
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::ImageConstIterator
A multi-dimensional image iterator templated over image type.
Definition: itkImageConstIterator.h:84
itk::OffsetValueType
signed long OffsetValueType
Definition: itkIntTypes.h:94
itk::ImageConstIterator< ImageType >::ImageType
ImageType ImageType
Definition: itkImageConstIterator.h:112
itk::ImageConstIterator< ImageType >::PixelContainer
typename ImageType ::PixelContainer PixelContainer
Definition: itkImageConstIterator.h:117
itk::ImageRegionConstIterator::ImageRegionConstIterator
ImageRegionConstIterator(const ImageType *ptr, const RegionType &region)
Definition: itkImageRegionConstIterator.h:153
itk::ImageConstIterator< ImageType >::IndexType
typename ImageType ::IndexType IndexType
Definition: itkImageConstIterator.h:100
itk::ImageRegionConstIterator
A multi-dimensional iterator templated over image type that walks a region of pixels.
Definition: itkImageRegionConstIterator.h:109
itk::ImageRegionConstIterator::operator--
Self & operator--()
Definition: itkImageRegionConstIterator.h:256