ITK  5.4.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 using DimensionValueType = unsigned int;
65
67 static constexpr DimensionValueType Dimension = TImage::ImageDimension;
68
70
74
76 using typename Superclass::OffsetType;
77 using typename Superclass::RadiusType;
78 using typename Superclass::SizeType;
79 using typename Superclass::Iterator;
80 using typename Superclass::ConstIterator;
81
83 using ImageType = TImage;
87
90
93
96
99
102 ConstNeighborhoodIteratorWithOnlyIndex(const SizeType & radius, const ImageType * ptr, const RegionType & region);
103
105 Self &
106 operator=(const Self & orig);
107
109 void
110 PrintSelf(std::ostream &, Indent) const override;
111
116
119 GetBound() const
120 {
121 return m_Bound;
122 }
123
128 {
129 return m_Bound[n];
130 }
131
133 const ImageType *
135 {
136 return m_ConstImage;
137 }
138
141 ITK_ITERATOR_VIRTUAL IndexType
142 GetIndex() const ITK_ITERATOR_FINAL
143 {
144 return m_Loop;
145 }
146
149 ITK_ITERATOR_VIRTUAL IndexType
150 GetIndex(const OffsetType & o) const ITK_ITERATOR_FINAL
151 {
152 return (this->GetIndex() + o);
153 }
154
157 ITK_ITERATOR_VIRTUAL IndexType
158 GetIndex(NeighborIndexType i) const ITK_ITERATOR_FINAL
159 {
160 return (this->GetIndex() + this->GetOffset(i));
161 }
162
165 GetRegion() const
166 {
167 return m_Region;
168 }
169
174 {
175 return m_BeginIndex;
176 }
177
182
184 ITK_ITERATOR_VIRTUAL void
185 GoToBegin() ITK_ITERATOR_FINAL;
186
189 ITK_ITERATOR_VIRTUAL void
190 GoToEnd() ITK_ITERATOR_FINAL;
191
194 ITK_ITERATOR_VIRTUAL void
195 Initialize(const SizeType & radius, const ImageType * ptr, const RegionType & region) ITK_ITERATOR_FINAL;
196
199 ITK_ITERATOR_VIRTUAL bool
200 IsAtBegin() const ITK_ITERATOR_FINAL
201 {
202 return (this->GetIndex() == m_BeginIndex);
203 }
204
207 ITK_ITERATOR_VIRTUAL bool
208 IsAtEnd() const ITK_ITERATOR_FINAL;
209
214 Self &
215 operator++();
216
221 Self &
222 operator--();
223
227 bool
228 operator==(const Self & it) const
229 {
230 return it.GetIndex() == this->GetIndex();
231 }
232
234
240 bool
241 operator<(const Self & it) const;
242
248 bool
249 operator<=(const Self & it) const;
250
256 bool
257 operator>(const Self & it) const;
258
264 bool
265 operator>=(const Self & it) const;
266
271 void
272 SetLocation(const IndexType & position)
273 {
274 this->SetLoop(position);
275 }
276
280 Self &
282
286 Self &
288
291 operator-(const Self & b) const
292 {
293 return m_Loop - b.m_Loop;
294 }
295
299 bool
300 InBounds() const;
301
313 bool
314 IndexInBounds(const NeighborIndexType n, OffsetType & internalIndex, OffsetType & offset) const;
315
317 void
319 {
320 this->SetNeedToUseBoundaryCondition(true);
321 }
322
323 void
325 {
326 this->SetNeedToUseBoundaryCondition(false);
327 }
328
329 void
331 {
332 m_NeedToUseBoundaryCondition = b;
333 }
334
335 bool
337 {
338 return m_NeedToUseBoundaryCondition;
339 }
340
341protected:
344 ITK_ITERATOR_VIRTUAL void
345 SetLoop(const IndexType & p) ITK_ITERATOR_FINAL
346 {
347 m_Loop = p;
348 m_IsInBoundsValid = false;
349 }
350
354 ITK_ITERATOR_VIRTUAL void
355 SetBound(const SizeType &) ITK_ITERATOR_FINAL;
356
359 ITK_ITERATOR_VIRTUAL void
360 SetBeginIndex(const IndexType & start) ITK_ITERATOR_FINAL
361 {
362 m_BeginIndex = start;
363 }
364
367 ITK_ITERATOR_VIRTUAL void
368 SetEndIndex() ITK_ITERATOR_FINAL;
369
372 IndexType m_BeginIndex{ { 0 } };
373
375 IndexType m_Bound{ { 0 } };
376
378 typename ImageType::ConstPointer m_ConstImage{};
379
382 IndexType m_EndIndex{ { 0 } };
383
385 IndexType m_Loop{ { 0 } };
386
388 RegionType m_Region{};
389
392 mutable bool m_InBounds[Dimension]{ false };
393
395 mutable bool m_IsInBounds{ false };
396
400 mutable bool m_IsInBoundsValid{ false };
401
403 IndexType m_InnerBoundsLow{};
404
406 IndexType m_InnerBoundsHigh{};
407
409 bool m_NeedToUseBoundaryCondition{ false };
410};
411
412template <typename TImage>
413inline ConstNeighborhoodIteratorWithOnlyIndex<TImage>
416{
418 ret = it;
419 ret += ind;
420 return ret;
421}
422
423template <typename TImage>
424inline ConstNeighborhoodIteratorWithOnlyIndex<TImage>
427{
428 return (it + ind);
429}
430
431template <typename TImage>
432inline ConstNeighborhoodIteratorWithOnlyIndex<TImage>
435{
437 ret = it;
438 ret -= ind;
439 return ret;
440}
441} // namespace itk
442
443#ifndef ITK_MANUAL_INSTANTIATION
444# include "itkConstNeighborhoodIteratorWithOnlyIndex.hxx"
445#endif
446
447#endif
Pixel-wise addition of two images.
Index-only version of ConstNeighborhoodIterator, defining iteration of a local N-dimensional neighbor...
ITK_ITERATOR_VIRTUAL void SetEndIndex() ITK_ITERATOR_FINAL
Self & operator-=(const OffsetType &)
ITK_ITERATOR_VIRTUAL void SetBound(const SizeType &) ITK_ITERATOR_FINAL
ITK_ITERATOR_VIRTUAL void GoToBegin() ITK_ITERATOR_FINAL
bool operator>=(const Self &it) const
ConstNeighborhoodIteratorWithOnlyIndex(const SizeType &radius, const ImageType *ptr, const RegionType &region)
ITK_ITERATOR_VIRTUAL bool IsAtEnd() const ITK_ITERATOR_FINAL
ITK_ITERATOR_VIRTUAL IndexType GetIndex() const ITK_ITERATOR_FINAL
ITK_ITERATOR_VIRTUAL IndexType GetIndex(NeighborIndexType i) const ITK_ITERATOR_FINAL
bool IndexInBounds(const NeighborIndexType n, OffsetType &internalIndex, OffsetType &offset) const
ITK_ITERATOR_VIRTUAL IndexType GetIndex(const OffsetType &o) const ITK_ITERATOR_FINAL
ITK_ITERATOR_VIRTUAL void SetBeginIndex(const IndexType &start) ITK_ITERATOR_FINAL
OffsetType ComputeInternalIndex(NeighborIndexType n) const
typename NeighborhoodType::NeighborIndexType NeighborIndexType
void PrintSelf(std::ostream &, Indent) const override
ConstNeighborhoodIteratorWithOnlyIndex(const ConstNeighborhoodIteratorWithOnlyIndex &)
bool operator>(const Self &it) const
Self & operator+=(const OffsetType &)
~ConstNeighborhoodIteratorWithOnlyIndex() override=default
ITK_ITERATOR_VIRTUAL void SetLoop(const IndexType &p) ITK_ITERATOR_FINAL
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:573
long IndexValueType
Definition: itkIntTypes.h:90
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:559