ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
itkImageLinearConstIteratorWithIndex.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 itkImageLinearConstIteratorWithIndex_h
19#define itkImageLinearConstIteratorWithIndex_h
20
22#include <type_traits> // For remove_const_t.
23
24namespace itk
25{
101template <typename TImage>
102class ITK_TEMPLATE_EXPORT ImageLinearConstIteratorWithIndex : public ImageConstIteratorWithIndex<TImage>
103{
104public:
108
113 using IndexType = typename TImage::IndexType;
114
119 using RegionType = typename TImage::RegionType;
120
125 using ImageType = TImage;
126
130 using PixelContainer = typename TImage::PixelContainer;
131 using PixelContainerPointer = typename PixelContainer::Pointer;
132
138
141 ImageLinearConstIteratorWithIndex(const TImage * ptr, const RegionType & region);
142
153
156 inline void
158
161 inline void
163
166 void
168
171 void
173
176 void
178
180 [[nodiscard]] inline bool
182 {
183 return this->m_PositionIndex[m_Direction] >= this->m_EndIndex[m_Direction];
184 }
185
187 [[nodiscard]] inline bool
189 {
191 }
192
194 inline void
195 SetDirection(unsigned int direction)
196 {
197 if (direction >= TImage::ImageDimension)
198 {
199 itkGenericExceptionMacro("In image of dimension " << TImage::ImageDimension << " Direction " << direction
200 << " was selected");
201 }
202 m_Direction = direction;
204 }
205
207 unsigned int
209 {
210 return m_Direction;
211 }
212
215 inline Self &
217 {
219 this->m_Position += m_Jump;
220 return *this;
221 }
222
225 inline Self &
227 {
229 this->m_Position -= m_Jump;
230 return *this;
231 }
232
233private:
235 unsigned int m_Direction{ 0 };
236};
237
238// Deduction guide for class template argument deduction (CTAD).
239template <typename TImage>
240ImageLinearConstIteratorWithIndex(SmartPointer<TImage>, const typename TImage::RegionType &)
242
243
244//----------------------------------------------------------------------
245// Go to next line
246//----------------------------------------------------------------------
247template <typename TImage>
248inline void
250{
251 this->m_Position -=
253
255
256 for (unsigned int n = 0; n < TImage::ImageDimension; ++n)
257 {
258 this->m_Remaining = false;
259
260 if (n == m_Direction)
261 {
262 continue;
263 }
264
265 this->m_PositionIndex[n]++;
266 if (this->m_PositionIndex[n] < this->m_EndIndex[n])
267 {
268 this->m_Position += this->m_OffsetTable[n];
269 this->m_Remaining = true;
270 break;
271 }
272
273 this->m_Position -= this->m_OffsetTable[n] * (this->m_Region.GetSize()[n] - 1);
274 this->m_PositionIndex[n] = this->m_BeginIndex[n];
275 }
276}
277
278//----------------------------------------------------------------------
279// Pass to the last pixel on the previous line
280//----------------------------------------------------------------------
281template <typename TImage>
282inline void
284{
285 this->m_Position +=
287
289
290 for (unsigned int n = 0; n < TImage::ImageDimension; ++n)
291 {
292 this->m_Remaining = false;
293
294 if (n == m_Direction)
295 {
296 continue;
297 }
298
299 this->m_PositionIndex[n]--;
300 if (this->m_PositionIndex[n] >= this->m_BeginIndex[n])
301 {
302 this->m_Position -= this->m_OffsetTable[n];
303 this->m_Remaining = true;
304 break;
305 }
306
307 this->m_Position += this->m_OffsetTable[n] * (this->m_Region.GetSize()[n] - 1);
308 this->m_PositionIndex[n] = this->m_EndIndex[n] - 1;
309 }
310}
311} // end namespace itk
312
313#ifndef ITK_MANUAL_INSTANTIATION
314# include "itkImageLinearConstIteratorWithIndex.hxx"
315#endif
316
317#endif
typename OffsetType::OffsetValueType OffsetValueType
Self & operator=(const Self &it)
OffsetValueType m_OffsetTable[ImageDimension+1]
A multi-dimensional image iterator that visits image pixels within a region in a "scan-line" order.
ImageLinearConstIteratorWithIndex(const TImage *ptr, const RegionType &region)
ImageLinearConstIteratorWithIndex(const ImageConstIteratorWithIndex< TImage > &it)
Implements transparent reference counting.
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
ImageLinearConstIteratorWithIndex(SmartPointer< TImage >, const typename TImage::RegionType &) -> ImageLinearConstIteratorWithIndex< std::remove_const_t< TImage > >