ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
itkRLEImageRegionConstIterator.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 itkRLEImageRegionConstIterator_h
19#define itkRLEImageRegionConstIterator_h
20
25
26class MultiLabelMeshPipeline;
27
28namespace itk
29{
41template <typename TPixel, unsigned int VImageDimension, typename CounterType>
42class ImageRegionConstIterator<RLEImage<TPixel, VImageDimension, CounterType>>
43 : public ImageConstIterator<RLEImage<TPixel, VImageDimension, CounterType>>
44{
45 friend class ::MultiLabelMeshPipeline;
46
47public:
51
56 static constexpr unsigned int ImageIteratorDimension = VImageDimension;
57
63 using IndexType = typename Superclass::IndexType;
64 using SizeType = typename Superclass::SizeType;
65 using OffsetType = typename Superclass::OffsetType;
66 using RegionType = typename Superclass::RegionType;
67 using ImageType = typename Superclass::ImageType;
69 using PixelType = typename Superclass::PixelType;
70
72 itkOverrideGetNameOfClassMacro(ImageRegionConstIterator);
73
77 {}
78
81 ImageRegionConstIterator(const ImageType * ptr, const RegionType & region)
82 : ImageConstIterator<ImageType>(ptr, region)
83 {}
84
92
100
108 Self &
109 operator++()
110 {
111 this->m_Index0++;
112
113 if (this->m_Index0 >= this->m_EndIndex0)
114 {
115 ++(this->m_BI);
116 if (!this->m_BI.IsAtEnd())
117 {
118 this->SetIndexInternal(this->m_BeginIndex0);
119 }
120 else
121 {
122 this->m_Index0 = this->m_BeginIndex0;
123 }
124 return *this;
125 }
126
127 this->m_SegmentRemainder--;
128 if (this->m_SegmentRemainder > 0)
129 {
130 return *this;
131 }
132
133 this->m_RealIndex++;
134 this->m_SegmentRemainder = (*this->m_RunLengthLine)[this->m_RealIndex].first;
135 return *this;
136 } // ++
137
145 Self &
146 operator--()
147 {
148 this->m_Index0--;
149
150 if (this->m_Index0 < this->m_BeginIndex0)
151 {
152 --(this->m_BI);
153 this->SetIndexInternal(this->m_EndIndex0 - 1);
154 return *this;
155 }
156
157 this->m_SegmentRemainder++;
158 if (this->m_SegmentRemainder <= (*this->m_RunLengthLine)[this->m_RealIndex].first)
159 {
160 return *this;
161 }
162
163 this->m_RealIndex--;
164 this->m_SegmentRemainder = 1;
165 return *this;
166 } // --
167};
168
169template <typename TPixel, unsigned int VImageDimension, typename CounterType>
170class ImageRegionConstIteratorWithIndex<RLEImage<TPixel, VImageDimension, CounterType>>
171 : public ImageRegionConstIterator<RLEImage<TPixel, VImageDimension, CounterType>>
172{
173public:
175
177
182
186 : ImageRegionConstIterator<ImageType>(ptr, region)
187 {}
188
189 void
191 {
192 this->m_BI.GoToEnd(); // after last pixel
193 --(this->m_BI); // go to last valid pixel
194 this->m_Index0 = this->m_EndIndex0 - 1;
195 this->SetIndexInternal(this->m_Index0); // valid index required
196 }
197
198 bool
200 {
201 return (this->m_Index0 == this->m_BeginIndex0) && this->m_BI.IsAtBegin();
202 }
203
214}; // no additional implementation required
215
216template <typename TPixel, unsigned int VImageDimension, typename CounterType>
217class ImageRegionConstIteratorWithOnlyIndex<RLEImage<TPixel, VImageDimension, CounterType>>
218 : public ImageRegionConstIteratorWithIndex<RLEImage<TPixel, VImageDimension, CounterType>>
219{
220 // just inherit constructors
221
222public:
224
226
231
237
248}; // no additional implementation required
249
250// CTAD deduction guide. C++17 generates implicit deduction guides only from
251// the primary template; the RLEImage partial specialization needs an explicit
252// guide so generic code calling `ImageRegionConstIterator it(img, region);`
253// (e.g. itkImageAlgorithm.hxx) compiles when img is an RLEImage.
254template <typename TPixel, unsigned int VImageDimension, typename CounterType>
258
259} // end namespace itk
260
261#endif // itkRLEImageRegionConstIterator_h
Read-only ImageIterator: ImageConstIterator<TImage> behaves as ImageIterator<const TImage>.
A multi-dimensional image iterator templated over image type.
detail::IteratorImageType_t< TImage > ImageType
static constexpr unsigned int ImageIteratorDimension
typename TImage::OffsetType OffsetType
typename TImage::InternalPixelType InternalPixelType
typename TImage::IndexType IndexType
typename TImage::SizeType SizeType
typename TImage::RegionType RegionType
friend class ImageIterator
typename TImage::PixelType PixelType
typename itk::ImageConstIterator< RLEImage< TPixel, VImageDimension, CounterType > >::RegionType RegionType
typename itk::ImageConstIterator< RLEImage< TPixel, VImageDimension, CounterType > >::RegionType RegionType
Read-only ImageRegionIterator: ImageRegionConstIterator<TImage> behaves as ImageRegionIterator<const ...
ImageRegionIterator< std::add_const_t< TImage > > Superclass
detail::IteratorImageType_t< TImage > ImageType
typename TImage::InternalPixelType InternalPixelType
Run-Length Encoded image. It saves memory for label images at the expense of processing times....
Definition itkRLEImage.h:53
typename Superclass::RegionType RegionType
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
ImageConstIterator(const TImage *, const typename TImage::RegionType &) -> ImageConstIterator< TImage >
ImageRegionConstIterator(const TImage *, const typename TImage::RegionType &) -> ImageRegionConstIterator< TImage >