ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
itkRLEImageIterator.h
Go to the documentation of this file.
1/*=========================================================================
2 *
3 * Copyright NumFOCUS
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 * https://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
24namespace itk
25{
34
35template <typename TPixel, unsigned int VImageDimension, typename CounterType>
36class ImageIterator<RLEImage<TPixel, VImageDimension, CounterType>>
37 : public ImageConstIterator<RLEImage<TPixel, VImageDimension, CounterType>>
38{
39public:
42
47 static constexpr unsigned int ImageIteratorDimension = VImageDimension;
48
51
53 using IndexType = typename Superclass::IndexType;
54 using SizeType = typename Superclass::SizeType;
55 using OffsetType = typename Superclass::OffsetType;
56 using RegionType = typename Superclass::RegionType;
57 using ImageType = typename Superclass::ImageType;
58 using InternalPixelType = typename Superclass::InternalPixelType;
59 using PixelType = typename Superclass::PixelType;
60
63 ImageIterator() = default;
65 ~ImageIterator() override = default;
68 ImageIterator(const Self & it)
70 {}
71
74 ImageIterator(ImageType * ptr, const RegionType & region)
75 : ImageConstIterator<ImageType>(ptr, region)
76 {}
77
80 Self &
81 operator=(const Self & it)
82 {
84 return *this;
85 }
86
89 void
90 Set(const PixelType & value) const
91 {
92 const_cast<ImageType *>(this->m_Image.GetPointer())
93 ->SetPixel(*const_cast<typename ImageType::RLLine *>(this->m_RunLengthLine),
94 this->m_SegmentRemainder,
95 this->m_RealIndex,
96 value);
97 }
98
100 // * Setting this value would change value of the whole run-length segment.
101 // * If we wanted to safely enable it,
102 // * we would isolate this pixel into its own segment. */
103 // PixelType & Value()
104 // {
105 // return m_Buffer[m_Index[2]][m_Index[1]][m_RealIndex].second;
106 // }
107
109 ImageType *
110 GetImage() const
111 {
112 // const_cast is needed here because m_Image is declared as a const pointer
113 // in the base class which is the ConstIterator.
114 return const_cast<ImageType *>(this->m_Image.GetPointer());
115 }
116
117protected:
123 Self &
125 {
127 return *this;
128 }
129};
130
131template <typename TPixel, unsigned int VImageDimension, typename CounterType>
132class ImageIteratorWithIndex<RLEImage<TPixel, VImageDimension, CounterType>>
133 : public ImageConstIteratorWithIndex<RLEImage<TPixel, VImageDimension, CounterType>>
134{
135public:
137
139
145
149
152 ImageIteratorWithIndex(const ImageType * ptr, const RegionType & region)
154 {}
155
158 void
159 Set(const TPixel & value) const
160 {
161 const_cast<ImageType *>(this->m_Image.GetPointer())
162 ->SetPixel(*const_cast<typename ImageType::RLLine *>(this->m_RunLengthLine),
163 this->m_SegmentRemainder,
164 this->m_RealIndex,
165 value);
166 }
167
169 ImageType *
170 GetImage() const
171 {
172 // const_cast is needed here because m_Image is declared as a const pointer
173 // in the base class which is the ConstIterator.
174 return const_cast<ImageType *>(this->m_Image.GetPointer());
175 }
176}; // no additional implementation required
177} // end namespace itk
178
179#endif // itkRLEImageIterator_h
Read-only ImageIterator: ImageConstIterator<TImage> behaves as ImageIterator<const TImage>.
typename itk::ImageConstIterator< RLEImage< TPixel, VImageDimension, CounterType > >::RegionType RegionType
WeakPointer< RLEImage< TPixel, VImageDimension, CounterType > > m_Image
detail::IteratorImageType_t< TImage > ImageType
ImageConstIterator< RLEImage< TPixel, VImageDimension, CounterType > > Superclass
detail::IteratorImageType_t< TImage > ImageType
WeakPointer< RLEImage< TPixel, VImageDimension, CounterType > > m_Image
Run-Length Encoded image. It saves memory for label images at the expense of processing times....
Definition itkRLEImage.h:53
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....