ITK  6.0.0
Insight Toolkit
itkConstNeighborhoodIteratorWithOnlyIndex.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 itkConstNeighborhoodIteratorWithOnlyIndex_h
19#define itkConstNeighborhoodIteratorWithOnlyIndex_h
20
21#include <vector>
22#include <cstring>
23#include <iostream>
24#include "itkImage.h"
25#include "itkNeighborhood.h"
26#include "itkMacro.h"
27
28namespace itk
29{
59template <typename TImage>
60class ITK_TEMPLATE_EXPORT ConstNeighborhoodIteratorWithOnlyIndex : public Neighborhood<char, TImage::ImageDimension>
61{
62public:
64
66 using DimensionValueType = unsigned int;
67
69 static constexpr DimensionValueType Dimension = TImage::ImageDimension;
70
72
76
78 using typename Superclass::OffsetType;
79 using typename Superclass::RadiusType;
80 using typename Superclass::SizeType;
81 using typename Superclass::Iterator;
82 using typename Superclass::ConstIterator;
83
85 using ImageType = TImage;
89
92
95
98
101 ConstNeighborhoodIteratorWithOnlyIndex(const SizeType & radius, const ImageType * ptr, const RegionType & region);
102
104 void
105 PrintSelf(std::ostream &, Indent) const override;
106
111
114 GetBound() const
115 {
116 return m_Bound;
117 }
118
123 {
124 return m_Bound[n];
125 }
126
128 const ImageType *
130 {
131 return m_ConstImage;
132 }
133
137 GetIndex() const
138 {
139 return m_Loop;
140 }
141
145 GetIndex(const OffsetType & o) const
146 {
147 return (this->GetIndex() + o);
148 }
149
154 {
155 return (this->GetIndex() + this->GetOffset(i));
156 }
157
160 GetRegion() const
161 {
162 return m_Region;
163 }
164
169 {
170 return m_BeginIndex;
171 }
172
177
179 void
181
184 void
186
189 void
190 Initialize(const SizeType & radius, const ImageType * ptr, const RegionType & region);
191
194 bool
195 IsAtBegin() const
196 {
197 return (this->GetIndex() == m_BeginIndex);
198 }
199
202 bool
203 IsAtEnd() const;
204
209 Self &
211
216 Self &
218
222 bool
223 operator==(const Self & it) const
224 {
225 return it.GetIndex() == this->GetIndex();
226 }
227
229
235 bool
236 operator<(const Self & it) const;
237
243 bool
244 operator<=(const Self & it) const;
245
251 bool
252 operator>(const Self & it) const;
253
259 bool
260 operator>=(const Self & it) const;
261
266 void
267 SetLocation(const IndexType & position)
268 {
269 this->SetLoop(position);
270 }
271
275 Self &
277
281 Self &
283
286 operator-(const Self & b) const
287 {
288 return m_Loop - b.m_Loop;
289 }
290
294 bool
295 InBounds() const;
296
308 bool
309 IndexInBounds(const NeighborIndexType n, OffsetType & internalIndex, OffsetType & offset) const;
310
312 void
314 {
315 this->SetNeedToUseBoundaryCondition(true);
316 }
317
318 void
320 {
321 this->SetNeedToUseBoundaryCondition(false);
322 }
323
324 void
326 {
327 m_NeedToUseBoundaryCondition = b;
328 }
329
330 bool
332 {
333 return m_NeedToUseBoundaryCondition;
334 }
335
336protected:
339 void
341 {
342 m_Loop = p;
343 m_IsInBoundsValid = false;
344 }
345
349 void
351
354 void
356 {
357 m_BeginIndex = start;
358 }
359
362 void
364
367 IndexType m_BeginIndex{ { 0 } };
368
370 IndexType m_Bound{ { 0 } };
371
373 typename ImageType::ConstPointer m_ConstImage{};
374
377 IndexType m_EndIndex{ { 0 } };
378
380 IndexType m_Loop{ { 0 } };
381
383 RegionType m_Region{};
384
387 mutable bool m_InBounds[Dimension]{ false };
388
390 mutable bool m_IsInBounds{ false };
391
395 mutable bool m_IsInBoundsValid{ false };
396
398 IndexType m_InnerBoundsLow{};
399
401 IndexType m_InnerBoundsHigh{};
402
404 bool m_NeedToUseBoundaryCondition{ false };
405};
406
407template <typename TImage>
408inline ConstNeighborhoodIteratorWithOnlyIndex<TImage>
411{
413 ret += ind;
414 return ret;
415}
416
417template <typename TImage>
418inline ConstNeighborhoodIteratorWithOnlyIndex<TImage>
421{
422 return (it + ind);
423}
424
425template <typename TImage>
426inline ConstNeighborhoodIteratorWithOnlyIndex<TImage>
429{
431 ret -= ind;
432 return ret;
433}
434} // namespace itk
435
436#ifndef ITK_MANUAL_INSTANTIATION
437# include "itkConstNeighborhoodIteratorWithOnlyIndex.hxx"
438#endif
439
440#endif
Pixel-wise addition of two images.
Index-only version of ConstNeighborhoodIterator, defining iteration of a local N-dimensional neighbor...
Self & operator-=(const OffsetType &)
bool operator>=(const Self &it) const
ConstNeighborhoodIteratorWithOnlyIndex(const SizeType &radius, const ImageType *ptr, const RegionType &region)
bool IndexInBounds(const NeighborIndexType n, OffsetType &internalIndex, OffsetType &offset) const
void Initialize(const SizeType &radius, const ImageType *ptr, const RegionType &region)
OffsetType ComputeInternalIndex(NeighborIndexType n) const
typename NeighborhoodType::NeighborIndexType NeighborIndexType
void PrintSelf(std::ostream &, Indent) const override
ITK_DEFAULT_COPY_AND_MOVE(ConstNeighborhoodIteratorWithOnlyIndex)
bool operator>(const Self &it) const
Self & operator+=(const OffsetType &)
~ConstNeighborhoodIteratorWithOnlyIndex() override=default
Control indentation during Print() invocation.
Definition: itkIndent.h:50
A light-weight container object for storing an N-dimensional neighborhood of values.
typename AllocatorType::iterator Iterator
SizeValueType NeighborIndexType
typename AllocatorType::const_iterator ConstIterator
SmartPointer< const Self > ConstPointer
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
bool operator<=(const Index< VDimension > &one, const Index< VDimension > &two)
Definition: itkIndex.h:571
long IndexValueType
Definition: itkIntTypes.h:93
ConstNeighborhoodIterator< TImage > operator-(const ConstNeighborhoodIterator< TImage > &it, const typename ConstNeighborhoodIterator< TImage >::OffsetType &ind)
ConstNeighborhoodIterator< TImage > operator+(const ConstNeighborhoodIterator< TImage > &it, const typename ConstNeighborhoodIterator< TImage >::OffsetType &ind)
bool operator<(const Index< VDimension > &one, const Index< VDimension > &two)
Definition: itkIndex.h:557