ITK  4.13.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  itkStaticConstMacro( ImageIteratorDimension, unsigned int, VImageDimension );
48 
51 
53  typedef typename Superclass::IndexType IndexType;
54  typedef typename Superclass::SizeType SizeType;
57  typedef typename Superclass::ImageType ImageType;
59  typedef typename Superclass::PixelType PixelType;
60 
64 
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 
140  typedef typename itk::ImageConstIterator<
142 
147  {}
148 
152  {
154  }
155 
158  ImageIteratorWithIndex( const ImageType* ptr, const RegionType& region )
159  : ImageConstIteratorWithIndex< ImageType >( ptr, region )
160  {}
161 
164  void
165  Set( const TPixel& value ) const
166  {
167  const_cast< ImageType * >( this->m_Image.GetPointer() )->SetPixel(
168  *const_cast< typename ImageType::RLLine * >( this->m_RunLengthLine ),
169  this->m_SegmentRemainder, this->m_RealIndex, value );
170  }
171 
173  ImageType *
174  GetImage() const
175  {
176  // const_cast is needed here because m_Image is declared as a const pointer
177  // in the base class which is the ConstIterator.
178  return const_cast< ImageType * >( this->m_Image.GetPointer() );
179  }
180 }; // no additional implementation required
181 } // end namespace itk
183 
184 #endif // itkRLEImageIterator_h
Self & operator=(const ImageConstIterator< ImageType > &it)
Self & operator=(const Self &it)
A multi-dimensional iterator templated over image type.
An image region represents a structured region of data.
ImageIterator Self
A multi-dimensional image iterator templated over image type.
Self & operator=(const Self &it)
A base class for multi-dimensional iterators templated over image type that are designed to efficient...
itk::ImageConstIterator< RLEImage< TPixel, VImageDimension, CounterType > >::RegionType RegionType
A base class for multi-dimensional iterators templated over image type that are designed to efficient...
Superclass::ImageType ImageType
static const unsigned int ImageIteratorDimension
TImage::ConstWeakPointer m_Image
ImageConstIterator< RLEImage< TPixel, VImageDimension, CounterType > > Superclass
Run-Length Encoded image. It saves memory for label images at the expense of processing times...
Definition: itkRLEImage.h:52