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 {
106 template <typename TImage>
107 class ITK_TEMPLATE_EXPORT ImageRegionConstIterator : public ImageConstIterator<TImage>
108 {
109 public:
113 
118  static constexpr unsigned int ImageIteratorDimension = Superclass::ImageIteratorDimension;
119 
127  using SizeType = typename Superclass::SizeType;
136 
139 
142  : ImageConstIterator<TImage>()
143  {
144  m_SpanBeginOffset = 0;
145  m_SpanEndOffset = 0;
146  }
148 
151  ImageRegionConstIterator(const ImageType * ptr, const RegionType & region)
152  : ImageConstIterator<TImage>(ptr, region)
153  {
154  m_SpanBeginOffset = this->m_BeginOffset;
155  m_SpanEndOffset = this->m_BeginOffset + static_cast<OffsetValueType>(this->m_Region.GetSize()[0]);
156  }
158 
166  {
168 
169  IndexType ind = this->GetIndex();
170  m_SpanEndOffset = this->m_Offset + static_cast<OffsetValueType>(this->m_Region.GetSize()[0]) -
171  (ind[0] - this->m_Region.GetIndex()[0]);
172  m_SpanBeginOffset = m_SpanEndOffset - static_cast<OffsetValueType>(this->m_Region.GetSize()[0]);
173  }
174 
182  {
184 
185  IndexType ind = this->GetIndex();
186  m_SpanEndOffset = this->m_Offset + static_cast<OffsetValueType>(this->m_Region.GetSize()[0]) -
187  (ind[0] - this->m_Region.GetIndex()[0]);
188  m_SpanBeginOffset = m_SpanEndOffset - static_cast<OffsetValueType>(this->m_Region.GetSize()[0]);
189  }
190 
193  void
195  {
196  Superclass::GoToBegin();
197 
198  // reset the span offsets
199  m_SpanBeginOffset = this->m_BeginOffset;
200  m_SpanEndOffset = this->m_BeginOffset + static_cast<OffsetValueType>(this->m_Region.GetSize()[0]);
201  }
202 
205  void
207  {
208  Superclass::GoToEnd();
209 
210  // reset the span offsets
211  m_SpanEndOffset = this->m_EndOffset;
212  m_SpanBeginOffset = m_SpanEndOffset - static_cast<OffsetValueType>(this->m_Region.GetSize()[0]);
213  }
214 
218  void
219  SetIndex(const IndexType & ind) override
220  {
221  Superclass::SetIndex(ind);
222  m_SpanEndOffset = this->m_Offset + static_cast<OffsetValueType>(this->m_Region.GetSize()[0]) -
223  (ind[0] - this->m_Region.GetIndex()[0]);
224  m_SpanBeginOffset = m_SpanEndOffset - static_cast<OffsetValueType>(this->m_Region.GetSize()[0]);
225  }
227 
235  Self &
237  {
238  if (++this->m_Offset >= m_SpanEndOffset)
239  {
240  this->Increment();
241  }
242  return *this;
243  }
245 
253  Self &
255  {
256  if (--this->m_Offset < m_SpanBeginOffset)
257  {
258  this->Decrement();
259  }
260  return *this;
261  }
263 
264 protected:
265  OffsetValueType m_SpanBeginOffset; // one pixel before the beginning of the span
266  // (row)
267  OffsetValueType m_SpanEndOffset; // one pixel past the end of the span (row)
268 
269 private:
270  void
271  Increment(); // advance in a direction other than the fastest moving
272 
273  void
274  Decrement(); // go back in a direction other than the fastest moving
275 };
276 } // end namespace itk
277 
278 #ifndef ITK_MANUAL_INSTANTIATION
279 # include "itkImageRegionConstIterator.hxx"
280 #endif
281 
282 #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:165
itk::ImageRegionConstIterator::GoToBegin
void GoToBegin()
Definition: itkImageRegionConstIterator.h:194
itk::ImageRegionConstIterator::SetIndex
void SetIndex(const IndexType &ind) override
Definition: itkImageRegionConstIterator.h:219
itk::ImageConstIterator< ImageType >::OffsetType
typename ImageType ::OffsetType OffsetType
Definition: itkImageConstIterator.h:106
itk::ImageRegionConstIterator::ImageRegionConstIterator
ImageRegionConstIterator(const ImageConstIterator< TImage > &it)
Definition: itkImageRegionConstIterator.h:181
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:236
itk::ImageRegionConstIterator::ImageRegionConstIterator
ImageRegionConstIterator()
Definition: itkImageRegionConstIterator.h:141
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:206
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:267
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:265
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:151
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:107
itk::ImageRegionConstIterator::operator--
Self & operator--()
Definition: itkImageRegionConstIterator.h:254