ITK  6.0.0
Insight Toolkit
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;
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 {
118 ConstIterator() { m_NeighborhoodIterator = nullptr; }
120 {
121 m_NeighborhoodIterator = s;
122 this->GoToBegin();
123 }
126 ~ConstIterator() = default;
127
130 {
131 m_NeighborhoodIterator = o.m_NeighborhoodIterator;
132 m_ListIterator = o.m_ListIterator;
133 return *this;
134 }
135
137 {
138 m_NeighborhoodIterator = o.m_NeighborhoodIterator;
139 m_ListIterator = o.m_ListIterator;
140 }
141
142 void
144 {
145 ++m_ListIterator;
146 }
147
148 void
150 {
151 --m_ListIterator;
152 }
153
154 const ConstIterator &
156 {
157 ++m_ListIterator;
158 return *this;
159 }
160
161 const ConstIterator &
163 {
164 --m_ListIterator;
165 return *this;
166 }
168 bool
169 operator==(const ConstIterator & o) const
171 return m_ListIterator == o.m_ListIterator;
174 ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(ConstIterator);
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 {
232 m_NeighborhoodIterator->SetPixel(*m_ListIterator, v);
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
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.
270 using Superclass::GetImagePointer;
271 using Superclass::GetRadius;
272 using Superclass::GetIndex;
273 using Superclass::GetNeighborhoodIndex;
274 using Superclass::GetCenterNeighborhoodIndex;
275 using Superclass::GetRegion;
276 using Superclass::GetBeginIndex;
277 using Superclass::GoToBegin;
278 using Superclass::GoToEnd;
279 using Superclass::IsAtBegin;
280 using Superclass::IsAtEnd;
281 using Superclass::GetOffset;
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[];
291 using Superclass::GetElement;
292 using Superclass::SetLocation;
293 using Superclass::GetCenterPointer;
294 using Superclass::GetCenterPixel;
295 using Superclass::OverrideBoundaryCondition;
296 using Superclass::ResetBoundaryCondition;
297 using Superclass::GetBoundaryCondition;
298 using Superclass::SetBoundaryCondition;
299 using Superclass::GetNeedToUseBoundaryCondition;
300 using Superclass::SetNeedToUseBoundaryCondition;
301 using Superclass::NeedToUseBoundaryConditionOn;
302 using Superclass::NeedToUseBoundaryConditionOff;
303 using Superclass::Print;
304 using Superclass::operator-;
305 using Superclass::GetPixel;
306 using Superclass::SetRegion;
307
309 Self &
310 operator=(const Self & orig)
311 {
312 if (this != &orig)
313 {
314 Superclass::operator=(orig);
315 m_ActiveIndexList = orig.m_ActiveIndexList;
316 m_CenterIsActive = orig.m_CenterIsActive;
317 }
318 return *this;
319 }
323 void
324 PrintSelf(std::ostream &, Indent) const override;
325
329 void
331 {
332 this->ActivateIndex(Superclass::GetNeighborhoodIndex(off));
333 }
334 void
336 {
337 this->DeactivateIndex(Superclass::GetNeighborhoodIndex(off));
338 }
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 }
355 void
357 {
358 m_ActiveIndexList.clear();
359 m_CenterIsActive = false;
360 }
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
387 this->CreateActiveListFromNeighborhood<PixelType>(neighborhood);
388 }
393 Self &
395
398 Self &
400
404 Self &
406
410 Self &
412
413protected:
414 using Superclass::SetPixel;
415 using Superclass::SetCenterPixel;
416
417 friend struct ConstIterator;
418
421 // Superclass::SetPixel;
422 // Superclass::SetCenterPixel;
423
430
432
433
434 bool m_CenterIsActive{ false };
435 IndexListType m_ActiveIndexList{};
436};
437} // namespace itk
438
439#ifndef ITK_MANUAL_INSTANTIATION
440# include "itkConstShapedNeighborhoodIterator.hxx"
441#endif
442
443#endif
Pixel-wise addition of two images.
Const version of ShapedNeighborhoodIterator, defining iteration of a local N-dimensional neighborhood...
IndexListType::size_type GetActiveIndexListSize() const
void PrintSelf(std::ostream &, Indent) const override
typename OffsetType::OffsetValueType OffsetValueType
void ActivateIndex(NeighborIndexType)
ConstShapedNeighborhoodIterator(const SizeType &radius, const ImageType *ptr, const RegionType &region)
void SetPixel(const unsigned int n, const PixelType &v, bool &status)
void CreateActiveListFromNeighborhood(const NeighborhoodType &neighborhood)
typename IndexListType::const_iterator IndexListConstIterator
Self & operator-=(const OffsetType &)
typename TImage::InternalPixelType InternalPixelType
typename IndexType::IndexValueType IndexValueType
void CreateActiveListFromNeighborhood(const Neighborhood< TNeighborPixel, Self::Dimension > &)
void DeactivateIndex(NeighborIndexType)
ConstShapedNeighborhoodIterator(const ConstShapedNeighborhoodIterator &)=delete
Self & operator+=(const OffsetType &)
typename NeighborhoodType::NeighborIndexType NeighborIndexType
~ConstShapedNeighborhoodIterator() override=default
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
Defines iteration of a local N-dimensional neighborhood of pixels across an itk::Image.
A light-weight container object for storing an N-dimensional neighborhood of values.
SizeValueType NeighborIndexType
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
long IndexValueType
Definition: itkIntTypes.h:93
bool operator==(const Index< VDimension > &one, const Index< VDimension > &two)
Definition: itkIndex.h:552
unsigned long SizeValueType
Definition: itkIntTypes.h:86
long OffsetValueType
Definition: itkIntTypes.h:97
ConstIterator(const Self *s, const typename IndexListType::const_iterator &li)
const OffsetValueType * GetOffset() const
Definition: itkOffset.h:181