ITK  4.13.0
Insight Segmentation and Registration Toolkit
itkRLEImageScanlineConstIterator.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 itkRLEImageScanlineConstIterator_h
19 #define itkRLEImageScanlineConstIterator_h
20 
23 
24 namespace itk
25 {
33 template< typename TPixel, unsigned int VImageDimension, typename CounterType >
34 class ImageScanlineConstIterator< RLEImage< TPixel, VImageDimension, CounterType > > :
35  public ImageRegionConstIterator< RLEImage< TPixel, VImageDimension, CounterType > >
36 {
37 public:
41 
46  itkStaticConstMacro( ImageIteratorDimension, unsigned int, VImageDimension );
47 
54  typedef typename Superclass::IndexType IndexType;
55  typedef typename Superclass::SizeType SizeType;
58  typedef typename Superclass::ImageType ImageType;
60  typedef typename Superclass::PixelType PixelType;
61 
64 
68  {}
69 
72  ImageScanlineConstIterator( const ImageType* ptr, const RegionType& region )
73  : ImageRegionConstIterator< ImageType >( ptr, region )
74  {}
75 
84  {}
85 
93  {
95  }
96 
98  void
100  {
101  this->m_Index0 = this->m_BeginIndex0;
102  this->m_RealIndex = 0;
103  this->m_SegmentRemainder = ( *this->m_RunLengthLine )[this->m_RealIndex].first;
104  }
106 
108  void
110  {
111  this->m_Index0 = this->m_EndIndex0;
112  this->m_RealIndex = this->m_RunLengthLine->size() - 1;
113  this->m_SegmentRemainder = 0;
114  }
116 
118  inline bool
120  {
121  return this->m_Index0 == this->m_EndIndex0;
122  }
123 
125  inline void
126  NextLine( void )
127  {
128  ++( this->m_BI );
129  if ( !this->m_BI.IsAtEnd() )
130  {
131  this->SetIndexInternal( this->m_BeginIndex0 );
132  }
133  else
134  {
135  this->m_Index0 = this->m_BeginIndex0; // make this iterator at end too
136  }
137  }
139 
147  Self &
149  {
150  itkAssertInDebugAndIgnoreInReleaseMacro( !this->IsAtEndOfLine() );
151  this->m_Index0++;
152  this->m_SegmentRemainder--;
153  if ( this->m_SegmentRemainder > 0 )
154  {
155  return *this;
156  }
158 
159  if ( this->IsAtEndOfLine() )
160  {
161  return *this;
162  }
163  this->m_RealIndex++;
164  this->m_SegmentRemainder = ( *this->m_RunLengthLine )[this->m_RealIndex].first;
165  return *this;
166  } // ++
167 
171  Self &
173  {
174  this->m_Index0--;
175  this->m_SegmentRemainder++;
176  if ( this->m_SegmentRemainder <= ( *this->m_RunLengthLine )[this->m_RealIndex].first )
177  {
178  return *this;
179  }
181 
182  this->m_RealIndex--;
183  this->m_SegmentRemainder = 1;
184  return *this;
185  }
186 };
187 } // end namespace itk
188 
189 #endif // itkRLEImageScanlineConstIterator_h
ImageRegionConstIterator< RLEImage< TPixel, VImageDimension, CounterType > > Superclass
A multi-dimensional iterator templated over image type.
An image region represents a structured region of data.
static const unsigned int ImageIteratorDimension
Self & operator=(const Self &it)
A multi-dimensional iterator templated over image type that walks a region of pixels.
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.
Run-Length Encoded image. It saves memory for label images at the expense of processing times...
Definition: itkRLEImage.h:52