ITK  4.13.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  itkStaticConstMacro(ImageIteratorDimension, unsigned int,
119  Superclass::ImageIteratorDimension);
120 
128  typedef typename Superclass::SizeType SizeType;
137 
140 
143  {
144  m_SpanBeginOffset = 0;
145  m_SpanEndOffset = 0;
146  }
147 
151  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
173  - static_cast< OffsetValueType >( this->m_Region.GetSize()[0] );
174  }
175 
183  {
185 
186  IndexType ind = this->GetIndex();
187  m_SpanEndOffset = this->m_Offset + static_cast< OffsetValueType >( this->m_Region.GetSize()[0] )
188  - ( ind[0] - this->m_Region.GetIndex()[0] );
189  m_SpanBeginOffset = m_SpanEndOffset
190  - static_cast< OffsetValueType >( this->m_Region.GetSize()[0] );
191  }
192 
195  void GoToBegin()
196  {
197  Superclass::GoToBegin();
198 
199  // reset the span offsets
200  m_SpanBeginOffset = this->m_BeginOffset;
201  m_SpanEndOffset = this->m_BeginOffset + static_cast< OffsetValueType >( this->m_Region.GetSize()[0] );
202  }
203 
206  void GoToEnd()
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  itkLegacyMacro(Self Begin(void) const);
219 
223  itkLegacyMacro(Self End(void) const);
224 
228  void SetIndex(const IndexType & ind) ITK_OVERRIDE
229  {
230  Superclass::SetIndex(ind);
231  m_SpanEndOffset = this->m_Offset + static_cast< OffsetValueType >( this->m_Region.GetSize()[0] )
232  - ( ind[0] - this->m_Region.GetIndex()[0] );
233  m_SpanBeginOffset = m_SpanEndOffset - static_cast< OffsetValueType >( this->m_Region.GetSize()[0] );
234  }
236 
244  Self &
246  {
247  if ( ++this->m_Offset >= m_SpanEndOffset )
248  {
249  this->Increment();
250  }
251  return *this;
252  }
254 
263  {
264  if ( --this->m_Offset < m_SpanBeginOffset )
265  {
266  this->Decrement();
267  }
268  return *this;
269  }
271 
272 protected:
273  OffsetValueType m_SpanBeginOffset; // one pixel before the beginning of the span
274  // (row)
275  OffsetValueType m_SpanEndOffset; // one pixel past the end of the span (row)
276 
277 private:
278  void Increment(); // advance in a direction other than the fastest moving
279 
280  void Decrement(); // go back in a direction other than the fastest moving
281 };
282 } // end namespace itk
283 
284 #ifndef ITK_MANUAL_INSTANTIATION
285 #include "itkImageRegionConstIterator.hxx"
286 #endif
287 
288 #endif
void SetIndex(const IndexType &ind) override
signed long OffsetValueType
Definition: itkIntTypes.h:154
Superclass::InternalPixelType InternalPixelType
ImageRegionConstIterator(const ImageConstIterator< TImage > &it)
A multi-dimensional iterator templated over image type.
Superclass::PixelContainerPointer PixelContainerPointer
ImageRegionConstIterator(const ImageIterator< TImage > &it)
A multi-dimensional image iterator templated over image type.
Self & operator=(const Self &it)
BufferType::InternalPixelType InternalPixelType
A multi-dimensional iterator templated over image type that walks a region of pixels.
ImageRegionConstIterator(const ImageType *ptr, const RegionType &region)
ImageConstIterator< TImage > Superclass
Superclass::PixelContainer PixelContainer