ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkRLEImageIterator.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 itkRLEImageIterator_h
19 #define itkRLEImageIterator_h
20 
23 
24 namespace itk
25 {
35 template< typename TPixel, unsigned int VImageDimension, typename CounterType >
36 class ImageIterator< RLEImage< TPixel, VImageDimension, CounterType > > :
37  public ImageConstIterator< RLEImage< TPixel, VImageDimension, CounterType > >
38 {
39 public:
42 
47  static constexpr unsigned int ImageIteratorDimension = VImageDimension;
48 
51 
53  using IndexType = typename Superclass::IndexType;
54  using SizeType = typename Superclass::SizeType;
57  using ImageType = typename Superclass::ImageType;
59  using PixelType = typename Superclass::PixelType;
60 
64 
66  ~ImageIterator() override {}
67 
70  ImageIterator( const Self& it )
71  : ImageConstIterator< ImageType >( it )
72  {}
73 
76  ImageIterator( ImageType* ptr, const RegionType& region )
77  : ImageConstIterator< ImageType >( ptr, region )
78  {}
79 
82  Self &
83  operator=( const Self& it )
84  {
86  return *this;
87  }
89 
92  void
93  Set( const PixelType& value ) const
94  {
95  const_cast< ImageType * >( this->m_Image.GetPointer() )->SetPixel(
96  *const_cast< typename ImageType::RLLine * >( this->m_RunLengthLine ),
97  this->m_SegmentRemainder, this->m_RealIndex, value );
98  }
99 
104  // PixelType & Value(void)
105  // {
106  // return m_Buffer[m_Index[2]][m_Index[1]][m_RealIndex].second;
107  // }
108 
110  ImageType *
111  GetImage() const
112  {
113  // const_cast is needed here because m_Image is declared as a const pointer
114  // in the base class which is the ConstIterator.
115  return const_cast< ImageType * >( this->m_Image.GetPointer() );
116  }
117 
118 protected:
122  : ImageConstIterator< ImageType >( it )
123  {}
124  Self &
126  {
128  return *this;
129  }
130 };
132 
133 template< typename TPixel, unsigned int VImageDimension, typename CounterType >
134 class ImageIteratorWithIndex< RLEImage< TPixel, VImageDimension, CounterType > > :
135  public ImageConstIteratorWithIndex< RLEImage< TPixel, VImageDimension, CounterType > >
136 {
137 public:
139 
141 
146  {}
147 
151  {
153  }
154 
157  ImageIteratorWithIndex( const ImageType* ptr, const RegionType& region )
158  : ImageConstIteratorWithIndex< ImageType >( ptr, region )
159  {}
160 
163  void
164  Set( const TPixel& value ) const
165  {
166  const_cast< ImageType * >( this->m_Image.GetPointer() )->SetPixel(
167  *const_cast< typename ImageType::RLLine * >( this->m_RunLengthLine ),
168  this->m_SegmentRemainder, this->m_RealIndex, value );
169  }
170 
172  ImageType *
173  GetImage() const
174  {
175  // const_cast is needed here because m_Image is declared as a const pointer
176  // in the base class which is the ConstIterator.
177  return const_cast< ImageType * >( this->m_Image.GetPointer() );
178  }
179 }; // no additional implementation required
180 } // end namespace itk
182 
183 #endif // itkRLEImageIterator_h
static constexpr unsigned int ImageIteratorDimension
typename Superclass::RegionType RegionType
Self & operator=(const ImageConstIterator< ImageType > &it)
typename TImage::OffsetType OffsetType
typename TImage::InternalPixelType InternalPixelType
ImageIterator Self
Self & operator=(const Self &it)
A multi-dimensional iterator templated over image type.
typename TImage::PixelType PixelType
A multi-dimensional image iterator templated over image type.
Self & operator=(const Self &it)
typename Superclass::ImageType ImageType
A base class for multi-dimensional iterators templated over image type that are designed to efficient...
A base class for multi-dimensional iterators templated over image type that are designed to efficient...
typename TImage::IndexType IndexType
TImage::ConstWeakPointer m_Image
ImageIterator()=default
typename TImage::SizeType SizeType
typename Superclass::ImageType ImageType
Run-Length Encoded image. It saves memory for label images at the expense of processing times...
Definition: itkRLEImage.h:52
typename TImage::RegionType RegionType