ITK  4.8.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 {
62 template< typename TImage >
64  public ImageConstIterator< TImage >
65 {
66 public:
70 
75  itkStaticConstMacro(ImageIteratorDimension, unsigned int,
77 
84  typedef typename Superclass::IndexType IndexType;
85  typedef typename Superclass::SizeType SizeType;
88  typedef typename Superclass::ImageType ImageType;
92  typedef typename Superclass::PixelType PixelType;
94 
97 
100  :ImageConstIterator< TImage >()
101  {
102  m_SpanBeginOffset = 0;
103  m_SpanEndOffset = 0;
104  }
106 
109  ImageScanlineConstIterator(const ImageType *ptr, const RegionType & region):
110  ImageConstIterator< TImage >(ptr, region)
111  {
113  m_SpanEndOffset = this->m_BeginOffset + static_cast< OffsetValueType >( this->m_Region.GetSize()[0] );
114  }
116 
124  {
126 
127  IndexType ind = this->GetIndex();
128  m_SpanEndOffset = this->m_Offset + static_cast< OffsetValueType >( this->m_Region.GetSize()[0] )
129  - ( ind[0] - this->m_Region.GetIndex()[0] );
131  - static_cast< OffsetValueType >( this->m_Region.GetSize()[0] );
132  }
133 
141  {
143 
144  IndexType ind = this->GetIndex();
145  m_SpanEndOffset = this->m_Offset + static_cast< OffsetValueType >( this->m_Region.GetSize()[0] )
146  - ( ind[0] - this->m_Region.GetIndex()[0] );
148  - static_cast< OffsetValueType >( this->m_Region.GetSize()[0] );
149  }
150 
153  void GoToBegin()
154  {
156 
157  // reset the span offsets
159  m_SpanEndOffset = this->m_BeginOffset + static_cast< OffsetValueType >( this->m_Region.GetSize()[0] );
160  }
161 
167  void GoToEnd()
168  {
170 
171  // reset the span offsets
173  m_SpanBeginOffset = m_SpanEndOffset - static_cast< OffsetValueType >( this->m_Region.GetSize()[0] );
174  }
175 
183  void GoToBeginOfLine(void)
184  {
185  this->m_Offset = m_SpanBeginOffset;
186  }
187 
196  void GoToEndOfLine(void)
197  {
198  this->m_Offset = m_SpanEndOffset;
199  }
200 
203  inline bool IsAtEndOfLine(void)
204  {
205  return this->m_Offset >= m_SpanEndOffset;
206  }
207 
208 
214  void SetIndex(const IndexType & ind) ITK_OVERRIDE
215  {
217  m_SpanEndOffset = this->m_Offset + static_cast< OffsetValueType >( this->m_Region.GetSize()[0] )
218  - ( ind[0] - this->m_Region.GetIndex()[0] );
219  m_SpanBeginOffset = m_SpanEndOffset - static_cast< OffsetValueType >( this->m_Region.GetSize()[0] );
220  }
222 
231  inline void NextLine(void)
232  {
233  this->Increment();
234  };
236 
245  {
246  itkAssertInDebugAndIgnoreInReleaseMacro( !this->IsAtEndOfLine() );
247  ++this->m_Offset;
248  return *this;
249  }
251 
256  {
257  itkAssertInDebugAndIgnoreInReleaseMacro( !this->IsAtEndOfLine() );
258  --this->m_Offset;
259  return *this;
260  }
262 
263 
264 protected:
265  OffsetValueType m_SpanBeginOffset; // one pixel the beginning of the scanline
266  OffsetValueType m_SpanEndOffset; // one pixel past the end of the scanline
267 
268 private:
269 
270  /* Move to the beginning of the next scanline
271  */
272  void Increment();
273 
274 };
275 } // end namespace itk
276 
277 #ifndef ITK_MANUAL_INSTANTIATION
278 #include "itkImageScanlineConstIterator.hxx"
279 #endif
280 
281 #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)
void SetIndex(const IndexType &ind) override
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)