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 {
120 {
122 this->GoToBegin();
123 }
124
125
126 ~ConstIterator() = default;
127
130 {
133 return *this;
134 }
135
141
142 void
144 {
146 }
147
148 void
150 {
152 }
153
154 const ConstIterator &
156 {
158 return *this;
159 }
160
161 const ConstIterator &
163 {
165 return *this;
166 }
167
168 bool
169 operator==(const ConstIterator & o) const
171 return m_ListIterator == o.m_ListIterator;
172 }
173
175
176 bool
177 IsAtEnd() const
178 {
179 if (m_ListIterator == m_NeighborhoodIterator->GetActiveIndexList().end())
180 {
181 return true;
182 }
183
184 return false;
185 }
186
187 void
189 {
190 m_ListIterator = m_NeighborhoodIterator->GetActiveIndexList().begin();
191 }
192
193 void
195 {
196 m_ListIterator = m_NeighborhoodIterator->GetActiveIndexList().end();
197 }
198
200 Get() const
201 {
202 return m_NeighborhoodIterator->GetPixel(*m_ListIterator);
203 }
204
207 {
208 return m_NeighborhoodIterator->GetOffset(*m_ListIterator);
209 }
210
211 typename IndexListType::value_type
213 {
214 return *m_ListIterator;
215 }
216
217 protected:
218 friend Self;
219
220 ConstIterator(const Self * s, const typename IndexListType::const_iterator & li)
221 : m_NeighborhoodIterator(const_cast<Self *>(s))
222 , m_ListIterator(li)
223 {}
224
226
227 typename IndexListType::const_iterator m_ListIterator;
228
229 void
230 ProtectedSet(const PixelType & v) const
231 {
233 }
234 };
235
238 ConstIterator
239 Begin() const
240 {
241 return ConstIterator(this, this->m_ActiveIndexList.begin());
242 }
243
246 ConstIterator
247 End() const
248 {
249 return ConstIterator(this, this->m_ActiveIndexList.end());
250 }
251
254
255 /** Virtual destructor */
257
260 ConstShapedNeighborhoodIterator(const SizeType & radius, const ImageType * ptr, const RegionType & region)
261 : Superclass(radius, const_cast<ImageType *>(ptr), region)
262 {}
263
266
267 // Expose the following methods from the superclass. This is a
268 // restricted subset of the methods available for
269 // ConstNeighborhoodIterator.
282 using Superclass::operator==;
283#ifndef ITK_EXPERIMENTAL_CXX20_REWRITTEN_UNEQUAL_OPERATOR
284 using Superclass::operator!=;
285#endif
286 using Superclass::operator<;
287 using Superclass::operator>;
288 using Superclass::operator>=;
289 using Superclass::operator<=;
290 using Superclass::operator[];
303 using Superclass::Print;
304 using Superclass::operator-;
307
309 Self &
310 operator=(const Self & orig)
311 {
312 if (this != &orig)
313 {
317 }
318 return *this;
319 }
320
321
323 void
324 PrintSelf(std::ostream &, Indent) const override;
325
329 void
334 void
339
340
343 template <typename TOffsets>
344 void
345 ActivateOffsets(const TOffsets & offsets)
346 {
347 for (const auto & offset : offsets)
348 {
349 this->ActivateOffset(offset);
350 }
351 }
352
353
355 void
357 {
358 m_ActiveIndexList.clear();
359 m_CenterIsActive = false;
360 }
361
362
364 const IndexListType &
366 {
367 return m_ActiveIndexList;
368 }
369
371 typename IndexListType::size_type
373 {
374 return m_ActiveIndexList.size();
375 }
376
380 template <typename TNeighborPixel>
381 void
383 void
385 {
386 // just delegate to the templated version
388 }
389
390
393 Self &
395
398 Self &
400
404 Self &
406
410 Self &
412
413protected:
416
417 friend struct ConstIterator;
418
421 // Superclass::SetPixel;
422 // Superclass::SetCenterPixel;
423
430
432
433
434 bool m_CenterIsActive{ false };
436};
437} // namespace itk
438
439#ifndef ITK_MANUAL_INSTANTIATION
440# include "itkConstShapedNeighborhoodIterator.hxx"
441#endif
442
443#endif
void OverrideBoundaryCondition(const ImageBoundaryConditionPointerType i)
void PrintSelf(std::ostream &, Indent) const override
typename OffsetType::OffsetValueType OffsetValueType
ImageBoundaryCondition< ImageType > * ImageBoundaryConditionPointerType
ConstShapedNeighborhoodIterator(const SizeType &radius, const ImageType *ptr, const RegionType &region)
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
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
AddImageFilter Self
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
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