ITK  5.0.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 >
63 class ITK_TEMPLATE_EXPORT ImageScanlineConstIterator:
64  public ImageConstIterator< TImage >
65 {
66 public:
70 
75  static constexpr unsigned int ImageIteratorDimension = Superclass::ImageIteratorDimension;
76 
83  using IndexType = typename Superclass::IndexType;
84  using SizeType = typename Superclass::SizeType;
87  using ImageType = typename Superclass::ImageType;
91  using PixelType = typename Superclass::PixelType;
93 
96 
99  :ImageConstIterator< TImage >()
100  {
101  m_SpanBeginOffset = 0;
102  m_SpanEndOffset = 0;
103  }
105 
108  ImageScanlineConstIterator(const ImageType *ptr, const RegionType & region):
109  ImageConstIterator< TImage >(ptr, region)
110  {
111  m_SpanBeginOffset = this->m_BeginOffset;
112  m_SpanEndOffset = this->m_BeginOffset + static_cast< OffsetValueType >( this->m_Region.GetSize()[0] );
113  }
115 
123  {
125 
126  IndexType ind = this->GetIndex();
127  m_SpanEndOffset = this->m_Offset + static_cast< OffsetValueType >( this->m_Region.GetSize()[0] )
128  - ( ind[0] - this->m_Region.GetIndex()[0] );
129  m_SpanBeginOffset = m_SpanEndOffset
130  - static_cast< OffsetValueType >( this->m_Region.GetSize()[0] );
131  }
132 
140  {
142 
143  IndexType ind = this->GetIndex();
144  m_SpanEndOffset = this->m_Offset + static_cast< OffsetValueType >( this->m_Region.GetSize()[0] )
145  - ( ind[0] - this->m_Region.GetIndex()[0] );
146  m_SpanBeginOffset = m_SpanEndOffset
147  - static_cast< OffsetValueType >( this->m_Region.GetSize()[0] );
148  }
149 
152  void GoToBegin()
153  {
154  Superclass::GoToBegin();
155 
156  // reset the span offsets
157  m_SpanBeginOffset = this->m_BeginOffset;
158  m_SpanEndOffset = this->m_BeginOffset + static_cast< OffsetValueType >( this->m_Region.GetSize()[0] );
159  }
160 
166  void GoToEnd()
167  {
168  Superclass::GoToEnd();
169 
170  // reset the span offsets
171  m_SpanEndOffset = this->m_EndOffset;
172  m_SpanBeginOffset = m_SpanEndOffset - static_cast< OffsetValueType >( this->m_Region.GetSize()[0] );
173  }
174 
183  {
184  this->m_Offset = m_SpanBeginOffset;
185  }
186 
196  {
197  this->m_Offset = m_SpanEndOffset;
198  }
199 
202  inline bool IsAtEndOfLine() const
203  {
204  return this->m_Offset >= m_SpanEndOffset;
205  }
206 
207 
213  void SetIndex(const IndexType & ind) override
214  {
215  Superclass::SetIndex(ind);
216  m_SpanEndOffset = this->m_Offset + static_cast< OffsetValueType >( this->m_Region.GetSize()[0] )
217  - ( ind[0] - this->m_Region.GetIndex()[0] );
218  m_SpanBeginOffset = m_SpanEndOffset - static_cast< OffsetValueType >( this->m_Region.GetSize()[0] );
219  }
221 
230  inline void NextLine()
231  {
232  this->Increment();
233  };
235 
244  {
245  itkAssertInDebugAndIgnoreInReleaseMacro( !this->IsAtEndOfLine() );
246  ++this->m_Offset;
247  return *this;
248  }
250 
255  {
256  itkAssertInDebugAndIgnoreInReleaseMacro( !this->IsAtEndOfLine() );
257  --this->m_Offset;
258  return *this;
259  }
261 
262 
263 protected:
264  OffsetValueType m_SpanBeginOffset; // one pixel the beginning of the scanline
265  OffsetValueType m_SpanEndOffset; // one pixel past the end of the scanline
266 
267 private:
268 
269  /* Move to the beginning of the next scanline
270  */
271  void Increment();
272 
273 };
274 } // end namespace itk
275 
276 #ifndef ITK_MANUAL_INSTANTIATION
277 #include "itkImageScanlineConstIterator.hxx"
278 #endif
279 
280 #endif
typename TImage::OffsetType OffsetType
typename TImage::InternalPixelType InternalPixelType
A multi-dimensional iterator templated over image type.
typename PixelContainer::Pointer PixelContainerPointer
typename TImage::PixelType PixelType
typename TImage::PixelContainer PixelContainer
A multi-dimensional image iterator templated over image type.
Self & operator=(const Self &it)
ImageScanlineConstIterator(const ImageType *ptr, const RegionType &region)
typename TImage::IndexType IndexType
typename TImage::SizeType SizeType
ImageScanlineConstIterator(const ImageIterator< TImage > &it)
void SetIndex(const IndexType &ind) override
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.
typename TImage::AccessorType AccessorType
typename TImage::RegionType RegionType
ImageScanlineConstIterator(const ImageConstIterator< TImage > &it)
signed long OffsetValueType
Definition: itkIntTypes.h:94