ITK  4.4.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< class TImage, class TBoundaryCondition =
71  ZeroFluxNeumannBoundaryCondition< TImage > >
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 
91  typedef typename Superclass::RadiusType RadiusType;
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 {
121  ConstIterator() { m_NeighborhoodIterator = 0; }
123  {
124  m_NeighborhoodIterator = s;
125  this->GoToBegin();
126  }
128 
129  virtual ~ConstIterator() {}
130 
131  const ConstIterator & operator=(const ConstIterator & o)
132  {
133  m_NeighborhoodIterator = o.m_NeighborhoodIterator;
134  m_ListIterator = o.m_ListIterator;
135  return *this;
136  }
137 
139  {
140  m_NeighborhoodIterator = o.m_NeighborhoodIterator;
141  m_ListIterator = o.m_ListIterator;
142  }
143 
144  void operator++(int)
145  { m_ListIterator++; }
146 
147  void operator--(int)
148  { m_ListIterator--; }
149 
150  const ConstIterator & operator++()
151  {
152  m_ListIterator++;
153  return *this;
154  }
155 
156  const ConstIterator & operator--()
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
190  { return m_NeighborhoodIterator->GetPixel(*m_ListIterator); }
191 
192  OffsetType GetNeighborhoodOffset() const
193  { return m_NeighborhoodIterator->GetOffset(*m_ListIterator); }
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  {
221  InitializeConstShapedNeighborhoodIterator();
222  }
223 
225  void InitializeConstShapedNeighborhoodIterator()
226  {
227  m_ConstBeginIterator = ConstIterator(this);
228  m_ConstEndIterator = ConstIterator(this);
229  m_ConstEndIterator.GoToEnd();
230  m_CenterIsActive = false;
231  }
233 
236 
240  const ImageType *ptr,
241  const RegionType & region):
242  Superclass (radius, const_cast< ImageType * >( ptr ), region)
243  {
244  InitializeConstShapedNeighborhoodIterator();
245  }
246 
247  // Expose the following methods from the superclass. This is a
248  // restricted subset of the methods available for
249  // ConstNeighborhoodIterator.
250  using Superclass::GetImagePointer;
251  using Superclass::GetRadius;
252  using Superclass::GetIndex;
253  using Superclass::GetNeighborhoodIndex;
254  using Superclass::GetCenterNeighborhoodIndex;
255  using Superclass::GetRegion;
256  using Superclass::GetBeginIndex;
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[];
269  using Superclass::GetElement;
270  using Superclass::SetLocation;
271  using Superclass::GetCenterPointer;
272  using Superclass::GetCenterPixel;
273  using Superclass::OverrideBoundaryCondition;
274  using Superclass::ResetBoundaryCondition;
275  using Superclass::GetBoundaryCondition;
276  using Superclass::GetNeedToUseBoundaryCondition;
277  using Superclass::SetNeedToUseBoundaryCondition;
278  using Superclass::NeedToUseBoundaryConditionOn;
279  using Superclass::NeedToUseBoundaryConditionOff;
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
296  m_ConstBeginIterator.GoToBegin();
297  m_ConstEndIterator.GoToBegin();
298  }
299  return *this;
300  }
301 
303  virtual void PrintSelf(std::ostream &, Indent) const;
304 
308  virtual void ActivateOffset(const OffsetType & off)
309  { this->ActivateIndex( Superclass::GetNeighborhoodIndex(off) ); }
310  virtual void DeactivateOffset(const OffsetType & off)
311  { this->DeactivateIndex( Superclass::GetNeighborhoodIndex(off) ); }
313 
315  virtual void ClearActiveList()
316  {
317  m_ActiveIndexList.clear();
318  m_ConstBeginIterator.GoToBegin();
319  m_ConstEndIterator.GoToEnd();
320  m_CenterIsActive = false;
321  }
323 
325  const IndexListType & GetActiveIndexList() const
326  { return m_ActiveIndexList; }
327 
329  typename IndexListType::size_type GetActiveIndexListSize() const
330  { return m_ActiveIndexList.size(); }
331 
335  void CreateActiveListFromNeighborhood(const NeighborhoodType &);
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;
357  using Superclass::SetCenterPixel;
360  // purposely not implemented
361 
362  friend struct ConstIterator;
363 
366  // Superclass::SetPixel;
367  // Superclass::SetCenterPixel;
368 
374  virtual void ActivateIndex( NeighborIndexType );
375 
376  virtual void DeactivateIndex( NeighborIndexType );
377 
382 };
383 } // namespace itk
384 
385 #ifndef ITK_MANUAL_INSTANTIATION
386 #include "itkConstShapedNeighborhoodIterator.hxx"
387 #endif
388 
389 #endif
390