ITK  4.3.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 {
107 template< typename TImage >
108 class ITK_EXPORT ImageRegionConstIterator:public ImageConstIterator< TImage >
109 {
110 public:
114 
119  itkStaticConstMacro(ImageIteratorDimension, unsigned int,
120  Superclass::ImageIteratorDimension);
121 
129  typedef typename Superclass::SizeType SizeType;
138 
141 
144  {
145  m_SpanBeginOffset = 0;
146  m_SpanEndOffset = 0;
147  }
148 
152  const RegionType & region):
153  ImageConstIterator< TImage >(ptr, region)
154  {
155  m_SpanBeginOffset = this->m_BeginOffset;
156  m_SpanEndOffset = this->m_BeginOffset + static_cast< OffsetValueType >( this->m_Region.GetSize()[0] );
157  }
159 
167  {
169 
170  IndexType ind = this->GetIndex();
171  m_SpanEndOffset = this->m_Offset + static_cast< OffsetValueType >( this->m_Region.GetSize()[0] )
172  - ( ind[0] - this->m_Region.GetIndex()[0] );
173  m_SpanBeginOffset = m_SpanEndOffset
174  - 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
191  - static_cast< OffsetValueType >( this->m_Region.GetSize()[0] );
192  }
193 
196  void GoToBegin()
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 GoToEnd()
208  {
209  Superclass::GoToEnd();
210 
211  // reset the span offsets
212  m_SpanEndOffset = this->m_EndOffset;
213  m_SpanBeginOffset = m_SpanEndOffset - static_cast< OffsetValueType >( this->m_Region.GetSize()[0] );
214  }
215 
219  itkLegacyMacro(Self Begin(void) const);
220 
224  itkLegacyMacro(Self End(void) const);
225 
229  void SetIndex(const IndexType & ind)
230  {
231  Superclass::SetIndex(ind);
232  m_SpanEndOffset = this->m_Offset + static_cast< OffsetValueType >( this->m_Region.GetSize()[0] )
233  - ( ind[0] - this->m_Region.GetIndex()[0] );
234  m_SpanBeginOffset = m_SpanEndOffset - static_cast< OffsetValueType >( this->m_Region.GetSize()[0] );
235  }
237 
245  Self &
246  operator++()
247  {
248  if ( ++this->m_Offset >= m_SpanEndOffset )
249  {
250  this->Increment();
251  }
252  return *this;
253  }
255 
263  Self & operator--()
264  {
265  if ( --this->m_Offset < m_SpanBeginOffset )
266  {
267  this->Decrement();
268  }
269  return *this;
270  }
272 
273 protected:
274  OffsetValueType m_SpanBeginOffset; // one pixel before the beginning of the span
275  // (row)
276  OffsetValueType m_SpanEndOffset; // one pixel past the end of the span (row)
277 
278 private:
279  void Increment(); // advance in a direction other than the fastest moving
280 
281  void Decrement(); // go back in a direction other than the fastest moving
282 };
283 } // end namespace itk
284 
285 #ifndef ITK_MANUAL_INSTANTIATION
286 #include "itkImageRegionConstIterator.hxx"
287 #endif
288 
289 #endif
290