ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkRLEImageRegionConstIterator.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 itkRLEImageRegionConstIterator_h
19 #define itkRLEImageRegionConstIterator_h
20 
25 
26 class MultiLabelMeshPipeline;
27 
28 namespace itk
29 {
41 template< typename TPixel, unsigned int VImageDimension, typename CounterType >
42 class ImageRegionConstIterator< RLEImage< TPixel, VImageDimension, CounterType > > :
43  public ImageConstIterator< RLEImage< TPixel, VImageDimension, CounterType > >
44 {
45  friend class ::MultiLabelMeshPipeline;
46 
47 public:
51 
56  static constexpr unsigned int ImageIteratorDimension = VImageDimension;
57 
64  using IndexType = typename Superclass::IndexType;
65  using SizeType = typename Superclass::SizeType;
68  using ImageType = typename Superclass::ImageType;
70  using PixelType = typename Superclass::PixelType;
71 
74 
78  {}
79 
82  ImageRegionConstIterator( const ImageType* ptr, const RegionType& region )
83  : ImageConstIterator< ImageType >( ptr, region )
84  {}
85 
93  {
95  }
96 
104  {
106  }
107 
115  Self &
117  {
118  this->m_Index0++;
119 
120  if ( this->m_Index0 >= this->m_EndIndex0 )
121  {
122  ++( this->m_BI );
123  if ( !this->m_BI.IsAtEnd() )
124  {
125  this->SetIndexInternal( this->m_BeginIndex0 );
126  }
127  else
128  {
129  this->m_Index0 = this->m_BeginIndex0;
130  }
131  return *this;
132  }
133 
134  this->m_SegmentRemainder--;
135  if ( this->m_SegmentRemainder > 0 )
136  {
137  return *this;
138  }
139 
140  this->m_RealIndex++;
141  this->m_SegmentRemainder = ( *this->m_RunLengthLine )[this->m_RealIndex].first;
142  return *this;
143  } // ++
144 
152  Self &
154  {
155  this->m_Index0--;
156 
157  if ( this->m_Index0 < this->m_BeginIndex0 )
158  {
159  --( this->m_BI );
160  this->SetIndexInternal( this->m_EndIndex0 - 1 );
161  return *this;
162  }
163 
164  this->m_SegmentRemainder++;
165  if ( this->m_SegmentRemainder <= ( *this->m_RunLengthLine )[this->m_RealIndex].first )
166  {
167  return *this;
168  }
169 
170  this->m_RealIndex--;
171  this->m_SegmentRemainder = 1;
172  return *this;
173  } // --
174 };
175 
176 template< typename TPixel, unsigned int VImageDimension, typename CounterType >
177 class ImageRegionConstIteratorWithIndex< RLEImage< TPixel, VImageDimension, CounterType > > :
178  public ImageRegionConstIterator< RLEImage< TPixel, VImageDimension, CounterType > >
179 {
180 public:
182 
184 
188  {}
189 
193  : ImageRegionConstIterator< ImageType >( ptr, region )
194  {}
195 
196  void
198  {
199  this->m_BI.GoToEnd(); // after last pixel
200  --( this->m_BI ); // go to last valid pixel
201  this->m_Index0 = this->m_EndIndex0 - 1;
202  this->SetIndexInternal( this->m_Index0 ); // valid index required
203  }
204 
205  bool
207  {
208  return ( this->m_Index0 == this->m_BeginIndex0 ) && this->m_BI.IsAtBegin();
209  }
210 
218  {
220  }
221 }; // no additional implementation required
223 
224 template< typename TPixel, unsigned int VImageDimension, typename CounterType >
225 class ImageRegionConstIteratorWithOnlyIndex< RLEImage< TPixel, VImageDimension, CounterType > > :
226  public ImageRegionConstIteratorWithIndex< RLEImage< TPixel, VImageDimension, CounterType > >
227 {
228 // just inherit constructors
229 
230 public:
232 
234 
238  {}
239 
243  : ImageRegionConstIteratorWithIndex< ImageType >( ptr, region )
244  {}
245 
253  {
255  }
256 }; // no additional implementation required
257 } // end namespace itk
259 
260 #endif // itkRLEImageRegionConstIterator_h
typename TImage::OffsetType OffsetType
static constexpr unsigned int ImageIteratorDimension
typename TImage::InternalPixelType InternalPixelType
A multi-dimensional iterator templated over image type that walks an image region and is specialized ...
A multi-dimensional iterator templated over image type.
typename TImage::PixelType PixelType
A multi-dimensional iterator templated over image type that walks an image region and is specialized ...
A multi-dimensional image iterator templated over image type.
Self & operator=(const Self &it)
A multi-dimensional iterator templated over image type that walks a region of pixels.
typename TImage::IndexType IndexType
typename TImage::SizeType SizeType
Run-Length Encoded image. It saves memory for label images at the expense of processing times...
Definition: itkRLEImage.h:52
typename TImage::RegionType RegionType