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 else
269 {
270 this->m_Position -= this->m_OffsetTable[n] * (this->m_Region.GetSize()[n] - 1);
271 this->m_PositionIndex[n] = this->m_BeginIndex[n];
272 }
273 }
274}
275
276//----------------------------------------------------------------------
277// Pass to the last pixel on the previous line
278//----------------------------------------------------------------------
279template <typename TImage>
280inline void
282{
283 this->m_Position +=
284 this->m_OffsetTable[m_Direction] * (this->m_EndIndex[m_Direction] - 1 - this->m_PositionIndex[m_Direction]);
285
286 this->m_PositionIndex[m_Direction] = this->m_EndIndex[m_Direction] - 1;
287
288 for (unsigned int n = 0; n < TImage::ImageDimension; ++n)
289 {
290 this->m_Remaining = false;
291
292 if (n == m_Direction)
293 {
294 continue;
295 }
296
297 this->m_PositionIndex[n]--;
298 if (this->m_PositionIndex[n] >= this->m_BeginIndex[n])
299 {
300 this->m_Position -= this->m_OffsetTable[n];
301 this->m_Remaining = true;
302 break;
303 }
304 else
305 {
306 this->m_Position += this->m_OffsetTable[n] * (this->m_Region.GetSize()[n] - 1);
307 this->m_PositionIndex[n] = this->m_EndIndex[n] - 1;
308 }
309 }
310}
311} // end namespace itk
312
313#ifndef ITK_MANUAL_INSTANTIATION
314# include "itkImageLinearConstIteratorWithIndex.hxx"
315#endif
316
317#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....