ITK  4.4.0
Insight Segmentation and Registration Toolkit
itkImageScanlineConstIterator.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 __itkImageScanlineConstIterator_h
19 #define __itkImageScanlineConstIterator_h
20 
21 #include "itkImageIterator.h"
22 
23 namespace itk
24 {
57 template< typename TImage >
58 class ITK_EXPORT ImageScanlineConstIterator:
59  public ImageConstIterator< TImage >
60 {
61 public:
65 
70  itkStaticConstMacro(ImageIteratorDimension, unsigned int,
71  Superclass::ImageIteratorDimension);
72 
79  typedef typename Superclass::IndexType IndexType;
80  typedef typename Superclass::SizeType SizeType;
83  typedef typename Superclass::ImageType ImageType;
87  typedef typename Superclass::PixelType PixelType;
89 
92 
95  :ImageConstIterator< TImage >()
96  {
97  m_SpanBeginOffset = 0;
98  m_SpanEndOffset = 0;
99  }
101 
104  ImageScanlineConstIterator(const ImageType *ptr, const RegionType & region):
105  ImageConstIterator< TImage >(ptr, region)
106  {
107  m_SpanBeginOffset = this->m_BeginOffset;
108  m_SpanEndOffset = this->m_BeginOffset + static_cast< OffsetValueType >( this->m_Region.GetSize()[0] );
109  }
111 
119  {
121 
122  IndexType ind = this->GetIndex();
123  m_SpanEndOffset = this->m_Offset + static_cast< OffsetValueType >( this->m_Region.GetSize()[0] )
124  - ( ind[0] - this->m_Region.GetIndex()[0] );
125  m_SpanBeginOffset = m_SpanEndOffset
126  - static_cast< OffsetValueType >( this->m_Region.GetSize()[0] );
127  }
128 
136  {
138 
139  IndexType ind = this->GetIndex();
140  m_SpanEndOffset = this->m_Offset + static_cast< OffsetValueType >( this->m_Region.GetSize()[0] )
141  - ( ind[0] - this->m_Region.GetIndex()[0] );
142  m_SpanBeginOffset = m_SpanEndOffset
143  - static_cast< OffsetValueType >( this->m_Region.GetSize()[0] );
144  }
145 
148  void GoToBegin()
149  {
150  Superclass::GoToBegin();
151 
152  // reset the span offsets
153  m_SpanBeginOffset = this->m_BeginOffset;
154  m_SpanEndOffset = this->m_BeginOffset + static_cast< OffsetValueType >( this->m_Region.GetSize()[0] );
155  }
156 
162  void GoToEnd()
163  {
164  Superclass::GoToEnd();
165 
166  // reset the span offsets
167  m_SpanEndOffset = this->m_EndOffset;
168  m_SpanBeginOffset = m_SpanEndOffset - static_cast< OffsetValueType >( this->m_Region.GetSize()[0] );
169  }
170 
178  void GoToBeginOfLine(void)
179  {
180  this->Offset = m_SpanBeginOffset;
181  }
182 
191  void GoToEndOfLine(void)
192  {
193  this->Offset = m_SpanEndOffset;
194  }
195 
198  inline bool IsAtEndOfLine(void)
199  {
200  return this->m_Offset >= m_SpanEndOffset;
201  }
202 
203 
209  void SetIndex(const IndexType & ind)
210  {
211  Superclass::SetIndex(ind);
212  m_SpanEndOffset = this->m_Offset + static_cast< OffsetValueType >( this->m_Region.GetSize()[0] )
213  - ( ind[0] - this->m_Region.GetIndex()[0] );
214  m_SpanBeginOffset = m_SpanEndOffset - static_cast< OffsetValueType >( this->m_Region.GetSize()[0] );
215  }
217 
226  inline void NextLine(void)
227  {
228  this->Increment();
229  };
231 
239  Self& operator++()
240  {
241  itkAssertInDebugAndIgnoreInReleaseMacro( !this->IsAtEndOfLine() );
242  ++this->m_Offset;
243  return *this;
244  }
246 
247 
248 protected:
249  OffsetValueType m_SpanBeginOffset; // one pixel the beginning of the scanline
250  OffsetValueType m_SpanEndOffset; // one pixel past the end of the scanline
251 
252 private:
253 
254  /* Move to the beginning of the next scanline
255  */
256  void Increment();
257 
258 };
259 } // end namespace itk
260 
261 #ifndef ITK_MANUAL_INSTANTIATION
262 #include "itkImageScanlineConstIterator.hxx"
263 #endif
264 
265 #endif
266