ITK  4.3.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  const ConstIterator & operator=(const ConstIterator & o)
131  {
132  m_NeighborhoodIterator = o.m_NeighborhoodIterator;
133  m_ListIterator = o.m_ListIterator;
134  return *this;
135  }
136 
138  {
139  m_NeighborhoodIterator = o.m_NeighborhoodIterator;
140  m_ListIterator = o.m_ListIterator;
141  }
142 
143  void operator++(int)
144  { m_ListIterator++; }
145 
146  void operator--(int)
147  { m_ListIterator--; }
148 
149  const ConstIterator & operator++()
150  {
151  m_ListIterator++;
152  return *this;
153  }
154 
155  const ConstIterator & operator--()
156  {
157  m_ListIterator--;
158  return *this;
159  }
160 
161  bool operator!=(const ConstIterator & o) const
162  { return m_ListIterator != o.m_ListIterator; }
163  bool operator==(const ConstIterator & o) const
164  { return m_ListIterator == o.m_ListIterator; }
165 
166  bool IsAtEnd() const
167  {
168  if ( m_ListIterator == m_NeighborhoodIterator->GetActiveIndexList().end() )
169  {
170  return true;
171  }
172  else
173  {
174  return false;
175  }
176  }
177 
178  void GoToBegin()
179  {
180  m_ListIterator = m_NeighborhoodIterator->GetActiveIndexList().begin();
181  }
182 
183  void GoToEnd()
184  {
185  m_ListIterator = m_NeighborhoodIterator->GetActiveIndexList().end();
186  }
187 
188  PixelType Get() const
189  { return m_NeighborhoodIterator->GetPixel(*m_ListIterator); }
190 
191  OffsetType GetNeighborhoodOffset() const
192  { return m_NeighborhoodIterator->GetOffset(*m_ListIterator); }
193 
194  typename IndexListType::value_type GetNeighborhoodIndex() const
195  { return *m_ListIterator; }
196 
197 protected:
198 
200 
201  typename IndexListType::const_iterator m_ListIterator;
202 
203  void ProtectedSet(const PixelType & v) const
204  { m_NeighborhoodIterator->SetPixel(*m_ListIterator, v); }
205  };
206 
209  const ConstIterator & Begin() const
210  { return m_ConstBeginIterator; }
211 
214  const ConstIterator & End() const
215  { return m_ConstEndIterator; }
216 
219  {
220  InitializeConstShapedNeighborhoodIterator();
221  }
222 
224  void InitializeConstShapedNeighborhoodIterator()
225  {
226  m_ConstBeginIterator = ConstIterator(this);
227  m_ConstEndIterator = ConstIterator(this);
228  m_ConstEndIterator.GoToEnd();
229  m_CenterIsActive = false;
230  }
232 
235 
239  const ImageType *ptr,
240  const RegionType & region):
241  Superclass (radius, const_cast< ImageType * >( ptr ), region)
242  {
243  InitializeConstShapedNeighborhoodIterator();
244  }
245 
246  // Expose the following methods from the superclass. This is a
247  // restricted subset of the methods available for
248  // ConstNeighborhoodIterator.
249  using Superclass::GetImagePointer;
250  using Superclass::GetRadius;
251  using Superclass::GetIndex;
252  using Superclass::GetNeighborhoodIndex;
253  using Superclass::GetCenterNeighborhoodIndex;
254  using Superclass::GetRegion;
255  using Superclass::GetBeginIndex;
256  using Superclass::GoToBegin;
257  using Superclass::GoToEnd;
258  using Superclass::IsAtBegin;
259  using Superclass::IsAtEnd;
260  using Superclass::GetOffset;
261  using Superclass::operator==;
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::GetElement;
269  using Superclass::SetLocation;
270  using Superclass::GetCenterPointer;
271  using Superclass::GetCenterPixel;
272  using Superclass::OverrideBoundaryCondition;
273  using Superclass::ResetBoundaryCondition;
274  using Superclass::GetBoundaryCondition;
275  using Superclass::GetNeedToUseBoundaryCondition;
276  using Superclass::SetNeedToUseBoundaryCondition;
277  using Superclass::NeedToUseBoundaryConditionOn;
278  using Superclass::NeedToUseBoundaryConditionOff;
279  using Superclass::Print;
280  using Superclass::operator-;
281  using Superclass::GetPixel;
282  using Superclass::SetRegion;
283 
285  Self & operator=(const Self & orig)
286  {
287  Superclass::operator=(orig);
288  m_ActiveIndexList = orig.m_ActiveIndexList;
289  m_CenterIsActive = orig.m_CenterIsActive;
291 
292  // Reset begin and end pointers
293  m_ConstBeginIterator.GoToBegin();
294  m_ConstEndIterator.GoToBegin();
295  return *this;
296  }
297 
299  virtual void PrintSelf(std::ostream &, Indent) const;
300 
304  virtual void ActivateOffset(const OffsetType & off)
305  { this->ActivateIndex( Superclass::GetNeighborhoodIndex(off) ); }
306  virtual void DeactivateOffset(const OffsetType & off)
307  { this->DeactivateIndex( Superclass::GetNeighborhoodIndex(off) ); }
309 
311  virtual void ClearActiveList()
312  {
313  m_ActiveIndexList.clear();
314  m_ConstBeginIterator.GoToBegin();
315  m_ConstEndIterator.GoToEnd();
316  m_CenterIsActive = false;
317  }
319 
321  const IndexListType & GetActiveIndexList() const
322  { return m_ActiveIndexList; }
323 
325  typename IndexListType::size_type GetActiveIndexListSize() const
326  { return m_ActiveIndexList.size(); }
327 
331  void CreateActiveListFromNeighborhood(const NeighborhoodType &);
332 
335  Self & operator++();
336 
339  Self & operator--();
340 
344  Self & operator+=(const OffsetType &);
345 
349  Self & operator-=(const OffsetType &);
350 
351 protected:
352  using Superclass::SetPixel;
353  using Superclass::SetCenterPixel;
356  // purposely not implemented
357 
358  friend struct ConstIterator;
359 
362  // Superclass::SetPixel;
363  // Superclass::SetCenterPixel;
364 
370  virtual void ActivateIndex( NeighborIndexType );
371 
372  virtual void DeactivateIndex( NeighborIndexType );
373 
378 };
379 } // namespace itk
380 
381 #ifndef ITK_MANUAL_INSTANTIATION
382 #include "itkConstShapedNeighborhoodIterator.hxx"
383 #endif
384 
385 #endif
386