ITK  4.6.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 >
59  public ImageConstIterator< TImage >
60 {
61 public:
65 
70  itkStaticConstMacro(ImageIteratorDimension, unsigned int,
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  {
98  m_SpanEndOffset = 0;
99  }
101 
104  ImageScanlineConstIterator(const ImageType *ptr, const RegionType & region):
105  ImageConstIterator< TImage >(ptr, region)
106  {
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] );
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] );
143  - static_cast< OffsetValueType >( this->m_Region.GetSize()[0] );
144  }
145 
148  void GoToBegin()
149  {
151 
152  // reset the span offsets
154  m_SpanEndOffset = this->m_BeginOffset + static_cast< OffsetValueType >( this->m_Region.GetSize()[0] );
155  }
156 
162  void GoToEnd()
163  {
165 
166  // reset the span offsets
168  m_SpanBeginOffset = m_SpanEndOffset - static_cast< OffsetValueType >( this->m_Region.GetSize()[0] );
169  }
170 
178  void GoToBeginOfLine(void)
179  {
180  this->m_Offset = m_SpanBeginOffset;
181  }
182 
191  void GoToEndOfLine(void)
192  {
193  this->m_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  {
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 
240  {
241  itkAssertInDebugAndIgnoreInReleaseMacro( !this->IsAtEndOfLine() );
242  ++this->m_Offset;
243  return *this;
244  }
246 
251  {
252  itkAssertInDebugAndIgnoreInReleaseMacro( !this->IsAtEndOfLine() );
253  --this->m_Offset;
254  return *this;
255  }
257 
258 
259 protected:
260  OffsetValueType m_SpanBeginOffset; // one pixel the beginning of the scanline
261  OffsetValueType m_SpanEndOffset; // one pixel past the end of the scanline
262 
263 private:
264 
265  /* Move to the beginning of the next scanline
266  */
267  void Increment();
268 
269 };
270 } // end namespace itk
271 
272 #ifndef ITK_MANUAL_INSTANTIATION
273 #include "itkImageScanlineConstIterator.hxx"
274 #endif
275 
276 #endif
PixelContainer::Pointer PixelContainerPointer
signed long OffsetValueType
Definition: itkIntTypes.h:154
A multi-dimensional iterator templated over image type.
const IndexType GetIndex() const
Superclass::InternalPixelType InternalPixelType
static const unsigned int ImageIteratorDimension
A multi-dimensional image iterator templated over image type.
Self & operator=(const Self &it)
TImage::AccessorType AccessorType
TImage::InternalPixelType InternalPixelType
virtual void SetIndex(const IndexType &ind)
ImageScanlineConstIterator(const ImageType *ptr, const RegionType &region)
Superclass::PixelContainerPointer PixelContainerPointer
static const unsigned int ImageIteratorDimension
ImageScanlineConstIterator(const ImageIterator< TImage > &it)
TImage::PixelContainer PixelContainer
A multi-dimensional iterator templated over image type that walks a region of pixels, scanline by scanline or in the direction of the fastest axis.
ImageScanlineConstIterator(const ImageConstIterator< TImage > &it)