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>
24
25namespace itk
26{
71template <typename TImage, typename TBoundaryCondition = ZeroFluxNeumannBoundaryCondition<TImage>>
72class ITK_TEMPLATE_EXPORT ConstShapedNeighborhoodIterator : private NeighborhoodIterator<TImage, TBoundaryCondition>
73{
74public:
76 using InternalPixelType = typename TImage::InternalPixelType;
77 using PixelType = typename TImage::PixelType;
78
80 static constexpr unsigned int Dimension = TImage::ImageDimension;
81
85
87 using typename Superclass::OffsetType;
89 using typename Superclass::RadiusType;
90 using typename Superclass::SizeType;
92
94 using ImageType = TImage;
95 using RegionType = typename TImage::RegionType;
99
101
104 using IndexListType = std::list<NeighborIndexType>;
105
106 using IndexListIterator = typename IndexListType::iterator;
107 using IndexListConstIterator = typename IndexListType::const_iterator;
108
110 using BoundaryConditionType = TBoundaryCondition;
111
114
117 {
119 : m_NeighborhoodIterator(nullptr)
120 {}
123 {
124 this->GoToBegin();
125 }
126
127 ~ConstIterator() = default;
128
130 operator=(const ConstIterator & o) = default;
131
136
137 void
139 {
141 }
142
143 void
145 {
147 }
148
149 const ConstIterator &
151 {
153 return *this;
154 }
155
156 const ConstIterator &
158 {
160 return *this;
161 }
162
163 bool
164 operator==(const ConstIterator & o) const
165 {
166 return m_ListIterator == o.m_ListIterator;
167 }
168
171 [[nodiscard]] bool
172 IsAtEnd() const
173 {
174 if (m_ListIterator == m_NeighborhoodIterator->GetActiveIndexList().end())
175 {
176 return true;
177 }
178
179 return false;
180 }
181
182 void
184 {
185 m_ListIterator = m_NeighborhoodIterator->GetActiveIndexList().begin();
186 }
187
188 void
190 {
191 m_ListIterator = m_NeighborhoodIterator->GetActiveIndexList().end();
192 }
193
194 [[nodiscard]] PixelType
195 Get() const
196 {
197 return m_NeighborhoodIterator->GetPixel(*m_ListIterator);
198 }
199
200 [[nodiscard]] OffsetType
202 {
203 return m_NeighborhoodIterator->GetOffset(*m_ListIterator);
204 }
205
206 [[nodiscard]] typename IndexListType::value_type
208 {
209 return *m_ListIterator;
210 }
211
212 protected:
213 friend Self;
214
215 ConstIterator(const Self * s, const typename IndexListType::const_iterator & li)
216 : m_NeighborhoodIterator(const_cast<Self *>(s))
217 , m_ListIterator(li)
218 {}
219
221
222 typename IndexListType::const_iterator m_ListIterator;
223
224 void
225 ProtectedSet(const PixelType & v) const
226 {
228 }
229 };
230
233 ConstIterator
234 Begin() const
235 {
236 return ConstIterator(this, this->m_ActiveIndexList.begin());
237 }
238
241 ConstIterator
242 End() const
243 {
244 return ConstIterator(this, this->m_ActiveIndexList.end());
245 }
246
249
252
255 ConstShapedNeighborhoodIterator(const SizeType & radius, const ImageType * ptr, const RegionType & region)
256 : Superclass(radius, const_cast<ImageType *>(ptr), region)
257 {}
258
261
262 // Expose the following methods from the superclass. This is a
263 // restricted subset of the methods available for
264 // ConstNeighborhoodIterator.
277 using Superclass::operator==;
278#ifndef ITK_EXPERIMENTAL_CXX20_REWRITTEN_UNEQUAL_OPERATOR
279 using Superclass::operator!=;
280#endif
281 using Superclass::operator<;
282 using Superclass::operator>;
283 using Superclass::operator>=;
284 using Superclass::operator<=;
285 using Superclass::operator[];
298 using Superclass::Print;
299 using Superclass::operator-;
302
304 Self &
305 operator=(const Self & orig)
306 {
307 if (this != &orig)
308 {
312 }
313 return *this;
314 }
315
317 void
318 PrintSelf(std::ostream &, Indent) const override;
319
324 void
329 void
334
337 template <typename TOffsets>
338 void
339 ActivateOffsets(const TOffsets & offsets)
340 {
341 for (const auto & offset : offsets)
342 {
343 this->ActivateOffset(offset);
344 }
345 }
346
348 void
350 {
351 m_ActiveIndexList.clear();
352 m_CenterIsActive = false;
353 }
354
356 const IndexListType &
358 {
359 return m_ActiveIndexList;
360 }
361
363 typename IndexListType::size_type
365 {
366 return m_ActiveIndexList.size();
367 }
368
373 template <typename TNeighborPixel>
374 void
376 void
378 {
379 // just delegate to the templated version
381 }
382
385 Self &
387
390 Self &
392
396 Self &
398
402 Self &
404
405protected:
408
409 friend struct ConstIterator;
410
413 // Superclass::SetPixel;
414 // Superclass::SetCenterPixel;
415
422
424
425
426 bool m_CenterIsActive{ false };
428};
429} // namespace itk
430
431#ifndef ITK_MANUAL_INSTANTIATION
432# include "itkConstShapedNeighborhoodIterator.hxx"
433#endif
434
435#endif
void OverrideBoundaryCondition(const ImageBoundaryConditionPointerType i)
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 &)
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:50
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
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
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