ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
itkConstShapedNeighborhoodIterator.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 itkConstShapedNeighborhoodIterator_h
19#define itkConstShapedNeighborhoodIterator_h
20
21#include <vector>
22#include <list>
23#include <type_traits> // For remove_const_t.
24
26
27namespace itk
28{
73template <typename TImage, typename TBoundaryCondition = ZeroFluxNeumannBoundaryCondition<TImage>>
74class ITK_TEMPLATE_EXPORT ConstShapedNeighborhoodIterator : private NeighborhoodIterator<TImage, TBoundaryCondition>
75{
76public:
78 using InternalPixelType = typename TImage::InternalPixelType;
79 using PixelType = typename TImage::PixelType;
80
82 static constexpr unsigned int Dimension = TImage::ImageDimension;
83
87
89 using typename Superclass::OffsetType;
91 using typename Superclass::RadiusType;
92 using typename Superclass::SizeType;
94
96 using ImageType = TImage;
97 using RegionType = typename TImage::RegionType;
101
103
106 using IndexListType = std::list<NeighborIndexType>;
107
108 using IndexListIterator = typename IndexListType::iterator;
109 using IndexListConstIterator = typename IndexListType::const_iterator;
110
112 using BoundaryConditionType = TBoundaryCondition;
113
116
119 {
121 : m_NeighborhoodIterator(nullptr)
122 {}
125 {
126 this->GoToBegin();
127 }
128
129 ~ConstIterator() = default;
130
132 operator=(const ConstIterator & o) = default;
133
138
139 void
141 {
143 }
144
145 void
147 {
149 }
150
151 const ConstIterator &
153 {
155 return *this;
156 }
157
158 const ConstIterator &
160 {
162 return *this;
163 }
164
165 bool
166 operator==(const ConstIterator & o) const
167 {
168 return m_ListIterator == o.m_ListIterator;
169 }
170
172
173 [[nodiscard]] bool
174 IsAtEnd() const
175 {
176 if (m_ListIterator == m_NeighborhoodIterator->GetActiveIndexList().end())
177 {
178 return true;
179 }
180
181 return false;
182 }
183
184 void
186 {
187 m_ListIterator = m_NeighborhoodIterator->GetActiveIndexList().begin();
188 }
189
190 void
192 {
193 m_ListIterator = m_NeighborhoodIterator->GetActiveIndexList().end();
194 }
195
196 [[nodiscard]] PixelType
197 Get() const
198 {
199 return m_NeighborhoodIterator->GetPixel(*m_ListIterator);
200 }
201
202 [[nodiscard]] OffsetType
204 {
205 return m_NeighborhoodIterator->GetOffset(*m_ListIterator);
206 }
207
208 [[nodiscard]] typename IndexListType::value_type
210 {
211 return *m_ListIterator;
212 }
213
214 protected:
215 friend Self;
216
217 ConstIterator(const Self * s, const typename IndexListType::const_iterator & li)
218 : m_NeighborhoodIterator(const_cast<Self *>(s))
219 , m_ListIterator(li)
220 {}
221
223
224 typename IndexListType::const_iterator m_ListIterator;
225
226 void
227 ProtectedSet(const PixelType & v) const
228 {
230 }
231 };
232
235 ConstIterator
236 Begin() const
237 {
238 return ConstIterator(this, this->m_ActiveIndexList.begin());
239 }
240
243 ConstIterator
244 End() const
245 {
246 return ConstIterator(this, this->m_ActiveIndexList.end());
247 }
248
251
254
257 ConstShapedNeighborhoodIterator(const SizeType & radius, const TImage * ptr, const RegionType & region)
258 : Superclass(radius, const_cast<ImageType *>(ptr), region)
259 {}
260
263
264 // Expose the following methods from the superclass. This is a
265 // restricted subset of the methods available for
266 // ConstNeighborhoodIterator.
279 using Superclass::operator==;
280#ifndef ITK_EXPERIMENTAL_CXX20_REWRITTEN_UNEQUAL_OPERATOR
281 using Superclass::operator!=;
282#endif
283 using Superclass::operator<;
284 using Superclass::operator>;
285 using Superclass::operator>=;
286 using Superclass::operator<=;
287 using Superclass::operator[];
300 using Superclass::Print;
301 using Superclass::operator-;
304
306 Self &
307 operator=(const Self & orig)
308 {
309 if (this != &orig)
310 {
314 }
315 return *this;
316 }
317
319 void
320 PrintSelf(std::ostream &, Indent) const override;
321
326 void
331 void
336
339 template <typename TOffsets>
340 void
341 ActivateOffsets(const TOffsets & offsets)
342 {
343 for (const auto & offset : offsets)
344 {
345 this->ActivateOffset(offset);
346 }
347 }
348
350 void
352 {
353 m_ActiveIndexList.clear();
354 m_CenterIsActive = false;
355 }
356
358 const IndexListType &
360 {
361 return m_ActiveIndexList;
362 }
363
365 typename IndexListType::size_type
367 {
368 return m_ActiveIndexList.size();
369 }
370
375 template <typename TNeighborPixel>
376 void
378 void
380 {
381 // just delegate to the templated version
383 }
384
387 Self &
389
392 Self &
394
398 Self &
400
404 Self &
406
407protected:
410
411 friend struct ConstIterator;
412
415 // Superclass::SetPixel;
416 // Superclass::SetCenterPixel;
417
424
426
427
428 bool m_CenterIsActive{ false };
430};
431
432// Deduction guide for class template argument deduction (CTAD).
433template <typename TImage>
434ConstShapedNeighborhoodIterator(const typename TImage::SizeType &,
436 const typename TImage::RegionType &)
438
439} // namespace itk
440
441#ifndef ITK_MANUAL_INSTANTIATION
442# include "itkConstShapedNeighborhoodIterator.hxx"
443#endif
444
445#endif
void SetRegion(const RegionType &region)
void OverrideBoundaryCondition(const ImageBoundaryConditionPointerType i)
PixelType GetPixel(const NeighborIndexType i) const
void SetBoundaryCondition(const TBoundaryCondition &c)
ImageBoundaryConditionPointerType GetBoundaryCondition() const
void SetLocation(const IndexType &position)
Const version of ShapedNeighborhoodIterator, defining iteration of a local N-dimensional neighborhood...
void PrintSelf(std::ostream &, Indent) const override
typename OffsetType::OffsetValueType OffsetValueType
ImageBoundaryCondition< ImageType > * ImageBoundaryConditionPointerType
void CreateActiveListFromNeighborhood(const NeighborhoodType &neighborhood)
typename IndexListType::const_iterator IndexListConstIterator
Self & operator-=(const OffsetType &)
ConstShapedNeighborhoodIterator(const SizeType &radius, const TImage *ptr, const RegionType &region)
typename TImage::InternalPixelType InternalPixelType
Neighborhood< PixelType, Self::Dimension > NeighborhoodType
void CreateActiveListFromNeighborhood(const Neighborhood< TNeighborPixel, Self::Dimension > &)
ConstShapedNeighborhoodIterator(const ConstShapedNeighborhoodIterator &)=delete
Self & operator+=(const OffsetType &)
typename NeighborhoodType::NeighborIndexType NeighborIndexType
~ConstShapedNeighborhoodIterator() override=default
NeighborhoodIterator< TImage, TBoundaryCondition > Superclass
A virtual base object that defines an interface to a class of boundary condition objects for use by n...
Control indentation during Print() invocation.
Definition itkIndent.h:51
void SetPixel(const unsigned int n, const PixelType &v, bool &status)
A light-weight container object for storing an N-dimensional neighborhood of values.
TImage::InternalPixelType *& GetElement(NeighborIndexType i)
virtual NeighborIndexType GetNeighborhoodIndex(const OffsetType &) const
Implements transparent reference counting.
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
ConstShapedNeighborhoodIterator(const typename TImage::SizeType &, SmartPointer< TImage >, const typename TImage::RegionType &) -> ConstShapedNeighborhoodIterator< std::remove_const_t< TImage > >
ConstIterator & operator=(const ConstIterator &o)=default
ConstIterator(const Self *s, const typename IndexListType::const_iterator &li)
Represent a n-dimensional index in a n-dimensional image.
Definition itkIndex.h:69
itk::IndexValueType IndexValueType
Definition itkIndex.h:79
itk::OffsetValueType OffsetValueType
Definition itkOffset.h:77
itk::SizeValueType SizeValueType
Definition itkSize.h:80