ITK  6.0.0
Insight Toolkit
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
23namespace itk
24{
100template <typename TImage>
101class ITK_TEMPLATE_EXPORT ImageLinearConstIteratorWithIndex : public ImageConstIteratorWithIndex<TImage>
102{
103public:
107
112 using IndexType = typename TImage::IndexType;
113
119
124 using ImageType = TImage;
125
129 using PixelContainer = typename TImage::PixelContainer;
131
135
136 {}
137
141
149 {
151 }
152
155 inline void
157
160 inline void
162
165 void
167
170 void
172
175 void
177
179 inline bool
181 {
182 return this->m_PositionIndex[m_Direction] >= this->m_EndIndex[m_Direction];
183 }
184
186 inline bool
188 {
189 return this->m_PositionIndex[m_Direction] < this->m_BeginIndex[m_Direction];
190 }
191
193 inline void
194 SetDirection(unsigned int direction)
195 {
196 if (direction >= TImage::ImageDimension)
197 {
198 itkGenericExceptionMacro("In image of dimension " << TImage::ImageDimension << " Direction " << direction
199 << " was selected");
200 }
201 m_Direction = direction;
202 m_Jump = this->m_OffsetTable[m_Direction];
203 }
207 unsigned int
209 {
210 return m_Direction;
211 }
212
215 inline Self &
217 {
218 this->m_PositionIndex[m_Direction]++;
219 this->m_Position += m_Jump;
220 return *this;
221 }
226 inline Self &
228 {
229 this->m_PositionIndex[m_Direction]--;
230 this->m_Position -= m_Jump;
231 return *this;
232 }
235private:
236 OffsetValueType m_Jump{ 0 };
237 unsigned int m_Direction{ 0 };
238};
239
240//----------------------------------------------------------------------
241// Go to next line
242//----------------------------------------------------------------------
243template <typename TImage>
244inline void
246{
247 this->m_Position -=
248 this->m_OffsetTable[m_Direction] * (this->m_PositionIndex[m_Direction] - this->m_BeginIndex[m_Direction]);
249
250 this->m_PositionIndex[m_Direction] = this->m_BeginIndex[m_Direction];
251
252 for (unsigned int n = 0; n < TImage::ImageDimension; ++n)
253 {
254 this->m_Remaining = false;
255
256 if (n == m_Direction)
257 {
258 continue;
259 }
260
261 this->m_PositionIndex[n]++;
262 if (this->m_PositionIndex[n] < this->m_EndIndex[n])
263 {
264 this->m_Position += this->m_OffsetTable[n];
265 this->m_Remaining = true;
266 break;
267 }
268
269 this->m_Position -= this->m_OffsetTable[n] * (this->m_Region.GetSize()[n] - 1);
270 this->m_PositionIndex[n] = this->m_BeginIndex[n];
271 }
272}
273
274//----------------------------------------------------------------------
275// Pass to the last pixel on the previous line
276//----------------------------------------------------------------------
277template <typename TImage>
278inline void
280{
281 this->m_Position +=
282 this->m_OffsetTable[m_Direction] * (this->m_EndIndex[m_Direction] - 1 - this->m_PositionIndex[m_Direction]);
283
284 this->m_PositionIndex[m_Direction] = this->m_EndIndex[m_Direction] - 1;
285
286 for (unsigned int n = 0; n < TImage::ImageDimension; ++n)
287 {
288 this->m_Remaining = false;
289
290 if (n == m_Direction)
291 {
292 continue;
293 }
294
295 this->m_PositionIndex[n]--;
296 if (this->m_PositionIndex[n] >= this->m_BeginIndex[n])
297 {
298 this->m_Position -= this->m_OffsetTable[n];
299 this->m_Remaining = true;
300 break;
301 }
302
303 this->m_Position += this->m_OffsetTable[n] * (this->m_Region.GetSize()[n] - 1);
304 this->m_PositionIndex[n] = this->m_EndIndex[n] - 1;
305 }
306}
307} // end namespace itk
308
309#ifndef ITK_MANUAL_INSTANTIATION
310# include "itkImageLinearConstIteratorWithIndex.hxx"
311#endif
312
313#endif
Pixel-wise addition of two images.
A base class for multi-dimensional iterators templated over image type that are designed to efficient...
typename OffsetType::OffsetValueType OffsetValueType
Self & operator=(const Self &it)
typename PixelContainer::Pointer PixelContainerPointer
typename TImage::PixelContainer PixelContainer
A multi-dimensional image iterator that visits image pixels within a region in a "scan-line" order.
ImageLinearConstIteratorWithIndex(const ImageType *ptr, const RegionType &region)
ImageLinearConstIteratorWithIndex(const ImageConstIteratorWithIndex< TImage > &it)
SmartPointer< Self > Pointer
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....