ITK  4.9.0
Insight Segmentation and Registration Toolkit
itkConstShapedNeighborhoodIterator.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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  * http://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 
25 namespace itk
26 {
70 template< typename TImage, typename TBoundaryCondition =
73  private NeighborhoodIterator< TImage, TBoundaryCondition >
74 {
75 public:
76 
78  typedef typename TImage::InternalPixelType InternalPixelType;
79  typedef typename TImage::PixelType PixelType;
80 
82  itkStaticConstMacro(Dimension, unsigned int, TImage::ImageDimension);
83 
87 
92  typedef typename Superclass::SizeType SizeType;
94 
96  typedef TImage ImageType;
97  typedef typename TImage::RegionType RegionType;
103 
105 
108  typedef std::list< NeighborIndexType > IndexListType;
109 
110  typedef typename IndexListType::iterator IndexListIterator;
111  typedef typename IndexListType::const_iterator IndexListConstIterator;
112 
114  typedef TBoundaryCondition BoundaryConditionType;
115 
118 
120  struct ConstIterator {
123  {
125  this->GoToBegin();
126  }
128 
129  virtual ~ConstIterator() {}
130 
132  {
135  return *this;
136  }
137 
139  {
142  }
143 
144  void operator++(int)
145  { m_ListIterator++; }
146 
147  void operator--(int)
148  { m_ListIterator--; }
149 
151  {
152  m_ListIterator++;
153  return *this;
154  }
155 
157  {
158  m_ListIterator--;
159  return *this;
160  }
161 
162  bool operator!=(const ConstIterator & o) const
163  { return m_ListIterator != o.m_ListIterator; }
164  bool operator==(const ConstIterator & o) const
165  { return m_ListIterator == o.m_ListIterator; }
166 
167  bool IsAtEnd() const
168  {
169  if ( m_ListIterator == m_NeighborhoodIterator->GetActiveIndexList().end() )
170  {
171  return true;
172  }
173  else
174  {
175  return false;
176  }
177  }
178 
179  void GoToBegin()
180  {
181  m_ListIterator = m_NeighborhoodIterator->GetActiveIndexList().begin();
182  }
183 
184  void GoToEnd()
185  {
186  m_ListIterator = m_NeighborhoodIterator->GetActiveIndexList().end();
187  }
188 
189  PixelType Get() const
191 
194 
195  typename IndexListType::value_type GetNeighborhoodIndex() const
196  { return *m_ListIterator; }
197 
198 protected:
199 
201 
202  typename IndexListType::const_iterator m_ListIterator;
203 
204  void ProtectedSet(const PixelType & v) const
205  { m_NeighborhoodIterator->SetPixel(*m_ListIterator, v); }
206  };
207 
210  const ConstIterator & Begin() const
211  { return m_ConstBeginIterator; }
212 
215  const ConstIterator & End() const
216  { return m_ConstEndIterator; }
217 
220  {
222  }
223 
226  {
230  m_CenterIsActive = false;
231  }
233 
236 
240  const ImageType *ptr,
241  const RegionType & region):
242  Superclass (radius, const_cast< ImageType * >( ptr ), region)
243  {
245  }
246 
247  // Expose the following methods from the superclass. This is a
248  // restricted subset of the methods available for
249  // ConstNeighborhoodIterator.
251  using Superclass::GetRadius;
252  using Superclass::GetIndex;
255  using Superclass::GetRegion;
257  using Superclass::GoToBegin;
258  using Superclass::GoToEnd;
259  using Superclass::IsAtBegin;
260  using Superclass::IsAtEnd;
261  using Superclass::GetOffset;
262  using Superclass::operator==;
263  using Superclass::operator!=;
264  using Superclass::operator<;
265  using Superclass::operator>;
266  using Superclass::operator>=;
267  using Superclass::operator<=;
268  using Superclass::operator[];
280  using Superclass::Print;
281  using Superclass::operator-;
282  using Superclass::GetPixel;
283  using Superclass::SetRegion;
284 
286  Self & operator=(const Self & orig)
287  {
288  if(this != &orig)
289  {
290  Superclass::operator=(orig);
291  m_ActiveIndexList = orig.m_ActiveIndexList;
292  m_CenterIsActive = orig.m_CenterIsActive;
294 
295  // Reset begin and end pointers
298  }
299  return *this;
300  }
301 
303  virtual void PrintSelf(std::ostream &, Indent) const;
304 
308  virtual void ActivateOffset(const OffsetType & off)
310  virtual void DeactivateOffset(const OffsetType & off)
313 
315  virtual void ClearActiveList()
316  {
317  m_ActiveIndexList.clear();
320  m_CenterIsActive = false;
321  }
323 
326  { return m_ActiveIndexList; }
327 
329  typename IndexListType::size_type GetActiveIndexListSize() const
330  { return m_ActiveIndexList.size(); }
331 
336 
339  Self & operator++();
340 
343  Self & operator--();
344 
348  Self & operator+=(const OffsetType &);
349 
353  Self & operator-=(const OffsetType &);
354 
355 protected:
356  using Superclass::SetPixel;
360 
361  friend struct ConstIterator;
362 
365  // Superclass::SetPixel;
366  // Superclass::SetCenterPixel;
367 
373  virtual void ActivateIndex( NeighborIndexType );
374 
375  virtual void DeactivateIndex( NeighborIndexType );
376 
379  ConstIterator m_ConstEndIterator;
380  ConstIterator m_ConstBeginIterator;
381 };
382 } // namespace itk
383 
384 #ifndef ITK_MANUAL_INSTANTIATION
385 #include "itkConstShapedNeighborhoodIterator.hxx"
386 #endif
387 
388 #endif
virtual IndexType GetIndex(void) const
Const version of ShapedNeighborhoodIterator, defining iteration of a local N-dimensional neighborhood...
Index< itkGetStaticConstMacro(Dimension) > IndexType
virtual PixelType GetPixel(NeighborIndexType i) const
ImageBoundaryCondition< ImageType > * ImageBoundaryConditionPointerType
virtual void OverrideBoundaryCondition(const ImageBoundaryConditionPointerType i)
A light-weight container object for storing an N-dimensional neighborhood of values.
virtual void ActivateOffset(const OffsetType &off)
Self & operator-=(const OffsetType &)
virtual NeighborIndexType GetNeighborhoodIndex(const OffsetType &) const
Const version of NeighborhoodIterator, defining iteration of a local N-dimensional neighborhood of pi...
unsigned long SizeValueType
Definition: itkIntTypes.h:143
virtual void DeactivateOffset(const OffsetType &off)
OffsetType GetOffset(NeighborIndexType i) const
virtual void DeactivateIndex(NeighborIndexType)
TImage::InternalPixelType *& GetElement(NeighborIndexType i)
void SetLocation(const IndexType &position)
virtual void SetCenterPixel(const PixelType &p)
Neighborhood< PixelType, itkGetStaticConstMacro(Dimension) > NeighborhoodType
IndexListType::size_type GetActiveIndexListSize() const
virtual void ActivateIndex(NeighborIndexType)
void CreateActiveListFromNeighborhood(const NeighborhoodType &)
virtual void SetRegion(const RegionType &region)
Superclass::RadiusType RadiusType
Self & operator+=(const OffsetType &)
ConstShapedNeighborhoodIterator(const SizeType &radius, const ImageType *ptr, const RegionType &region)
virtual void PrintSelf(std::ostream &, Indent) const
const ImageType * GetImagePointer(void) const
virtual void SetPixel(const unsigned i, const PixelType &v, bool &status)
Self & operator=(const Self &orig)
InternalPixelType * GetCenterPointer()
NeighborhoodIterator< TImage, TBoundaryCondition > Superclass
NeighborhoodType::NeighborIndexType NeighborIndexType
Control indentation during Print() invocation.
Definition: itkIndent.h:49
ImageBoundaryConditionPointerType GetBoundaryCondition() const
itk::OffsetValueType OffsetValueType
Definition: itkOffset.h:69
Defines iteration of a local N-dimensional neighborhood of pixels across an itk::Image.
SizeValueType NeighborIndexType