ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkImageRegionConstIterator.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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  {
143  m_SpanBeginOffset = 0;
144  m_SpanEndOffset = 0;
145  }
146 
150  const RegionType & region):
151  ImageConstIterator< TImage >(ptr, region)
152  {
153  m_SpanBeginOffset = this->m_BeginOffset;
154  m_SpanEndOffset = this->m_BeginOffset + static_cast< OffsetValueType >( this->m_Region.GetSize()[0] );
155  }
157 
165  {
167 
168  IndexType ind = this->GetIndex();
169  m_SpanEndOffset = this->m_Offset + static_cast< OffsetValueType >( this->m_Region.GetSize()[0] )
170  - ( ind[0] - this->m_Region.GetIndex()[0] );
171  m_SpanBeginOffset = m_SpanEndOffset
172  - 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
189  - static_cast< OffsetValueType >( this->m_Region.GetSize()[0] );
190  }
191 
194  void GoToBegin()
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 GoToEnd()
206  {
207  Superclass::GoToEnd();
208 
209  // reset the span offsets
210  m_SpanEndOffset = this->m_EndOffset;
211  m_SpanBeginOffset = m_SpanEndOffset - static_cast< OffsetValueType >( this->m_Region.GetSize()[0] );
212  }
213 
217  void SetIndex(const IndexType & ind) override
218  {
219  Superclass::SetIndex(ind);
220  m_SpanEndOffset = this->m_Offset + static_cast< OffsetValueType >( this->m_Region.GetSize()[0] )
221  - ( ind[0] - this->m_Region.GetIndex()[0] );
222  m_SpanBeginOffset = m_SpanEndOffset - static_cast< OffsetValueType >( this->m_Region.GetSize()[0] );
223  }
225 
233  Self &
235  {
236  if ( ++this->m_Offset >= m_SpanEndOffset )
237  {
238  this->Increment();
239  }
240  return *this;
241  }
243 
252  {
253  if ( --this->m_Offset < m_SpanBeginOffset )
254  {
255  this->Decrement();
256  }
257  return *this;
258  }
260 
261 protected:
262  OffsetValueType m_SpanBeginOffset; // one pixel before the beginning of the span
263  // (row)
264  OffsetValueType m_SpanEndOffset; // one pixel past the end of the span (row)
265 
266 private:
267  void Increment(); // advance in a direction other than the fastest moving
268 
269  void Decrement(); // go back in a direction other than the fastest moving
270 };
271 } // end namespace itk
272 
273 #ifndef ITK_MANUAL_INSTANTIATION
274 #include "itkImageRegionConstIterator.hxx"
275 #endif
276 
277 #endif
void SetIndex(const IndexType &ind) override
typename BufferType::OffsetType OffsetType
typename BufferType::InternalPixelType InternalPixelType
ImageRegionConstIterator(const ImageConstIterator< TImage > &it)
A multi-dimensional iterator templated over image type.
typename PixelContainer::Pointer PixelContainerPointer
typename BufferType::PixelType PixelType
typename BufferType::PixelContainer PixelContainer
ImageRegionConstIterator(const ImageIterator< TImage > &it)
A multi-dimensional image iterator templated over image type.
Self & operator=(const Self &it)
A multi-dimensional iterator templated over image type that walks a region of pixels.
typename BufferType::IndexType IndexType
typename BufferType::SizeType SizeType
ImageRegionConstIterator(const ImageType *ptr, const RegionType &region)
typename BufferType::AccessorType AccessorType
typename BufferType::RegionType RegionType
signed long OffsetValueType
Definition: itkIntTypes.h:94