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 }
167
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 else
184 {
185 return false;
186 }
187 }
188
189 void
191 {
192 m_ListIterator = m_NeighborhoodIterator->GetActiveIndexList().begin();
193 }
194
195 void
197 {
198 m_ListIterator = m_NeighborhoodIterator->GetActiveIndexList().end();
199 }
200
202 Get() const
203 {
204 return m_NeighborhoodIterator->GetPixel(*m_ListIterator);
205 }
206
209 {
210 return m_NeighborhoodIterator->GetOffset(*m_ListIterator);
211 }
212
213 typename IndexListType::value_type
215 {
216 return *m_ListIterator;
217 }
218
219 protected:
220 friend Self;
221
222 ConstIterator(const Self * s, const typename IndexListType::const_iterator & li)
223 : m_NeighborhoodIterator(const_cast<Self *>(s))
224 , m_ListIterator(li)
225 {}
226
228
229 typename IndexListType::const_iterator m_ListIterator;
230
231 void
232 ProtectedSet(const PixelType & v) const
233 {
234 m_NeighborhoodIterator->SetPixel(*m_ListIterator, v);
235 }
236 };
237
240 ConstIterator
241 Begin() const
242 {
243 return ConstIterator(this, this->m_ActiveIndexList.begin());
244 }
245
248 ConstIterator
249 End() const
250 {
251 return ConstIterator(this, this->m_ActiveIndexList.end());
252 }
253
256
259
262 ConstShapedNeighborhoodIterator(const SizeType & radius, const ImageType * ptr, const RegionType & region)
263 : Superclass(radius, const_cast<ImageType *>(ptr), region)
264 {}
265
268
269 // Expose the following methods from the superclass. This is a
270 // restricted subset of the methods available for
271 // ConstNeighborhoodIterator.
272 using Superclass::GetImagePointer;
273 using Superclass::GetRadius;
274 using Superclass::GetIndex;
275 using Superclass::GetNeighborhoodIndex;
276 using Superclass::GetCenterNeighborhoodIndex;
277 using Superclass::GetRegion;
278 using Superclass::GetBeginIndex;
279 using Superclass::GoToBegin;
280 using Superclass::GoToEnd;
281 using Superclass::IsAtBegin;
282 using Superclass::IsAtEnd;
283 using Superclass::GetOffset;
284 using Superclass::operator==;
285#ifndef ITK_EXPERIMENTAL_CXX20_REWRITTEN_UNEQUAL_OPERATOR
286 using Superclass::operator!=;
287#endif
288 using Superclass::operator<;
289 using Superclass::operator>;
290 using Superclass::operator>=;
291 using Superclass::operator<=;
292 using Superclass::operator[];
293 using Superclass::GetElement;
294 using Superclass::SetLocation;
295 using Superclass::GetCenterPointer;
296 using Superclass::GetCenterPixel;
297 using Superclass::OverrideBoundaryCondition;
298 using Superclass::ResetBoundaryCondition;
299 using Superclass::GetBoundaryCondition;
300 using Superclass::SetBoundaryCondition;
301 using Superclass::GetNeedToUseBoundaryCondition;
302 using Superclass::SetNeedToUseBoundaryCondition;
303 using Superclass::NeedToUseBoundaryConditionOn;
304 using Superclass::NeedToUseBoundaryConditionOff;
305 using Superclass::Print;
306 using Superclass::operator-;
307 using Superclass::GetPixel;
308 using Superclass::SetRegion;
309
311 Self &
312 operator=(const Self & orig)
313 {
314 if (this != &orig)
315 {
316 Superclass::operator=(orig);
317 m_ActiveIndexList = orig.m_ActiveIndexList;
318 m_CenterIsActive = orig.m_CenterIsActive;
319 }
320 return *this;
321 }
325 void
326 PrintSelf(std::ostream &, Indent) const override;
327
331 void
333 {
334 this->ActivateIndex(Superclass::GetNeighborhoodIndex(off));
335 }
336 void
338 {
339 this->DeactivateIndex(Superclass::GetNeighborhoodIndex(off));
340 }
345 template <typename TOffsets>
346 void
347 ActivateOffsets(const TOffsets & offsets)
348 {
349 for (const auto & offset : offsets)
350 {
351 this->ActivateOffset(offset);
352 }
353 }
357 void
359 {
360 m_ActiveIndexList.clear();
361 m_CenterIsActive = false;
362 }
366 const IndexListType &
368 {
369 return m_ActiveIndexList;
370 }
371
373 typename IndexListType::size_type
375 {
376 return m_ActiveIndexList.size();
377 }
378
382 template <typename TNeighborPixel>
383 void
385 void
387 {
388 // just delegate to the templated version
389 this->CreateActiveListFromNeighborhood<PixelType>(neighborhood);
390 }
395 Self &
397
400 Self &
402
406 Self &
408
412 Self &
414
415protected:
416 using Superclass::SetPixel;
417 using Superclass::SetCenterPixel;
418
419 friend struct ConstIterator;
420
423 // Superclass::SetPixel;
424 // Superclass::SetCenterPixel;
425
432
434
435
436 bool m_CenterIsActive{ false };
437 IndexListType m_ActiveIndexList{};
438};
439} // namespace itk
440
441#ifndef ITK_MANUAL_INSTANTIATION
442# include "itkConstShapedNeighborhoodIterator.hxx"
443#endif
444
445#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 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 &)
void SetPixel(const unsigned int i, const PixelType &v, bool &status)
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:543
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