KWStyle - itkConstShapedNeighborhoodIterator.h
 
Matrix View
Description

1 /*=========================================================================
2
3   Program:   Insight Segmentation & Registration Toolkit
4   Module:    $RCSfile: itkConstShapedNeighborhoodIterator.h.html,v $
5   Language:  C++
6   Date:      $Date: 2006/01/17 19:15:34 $
7   Version:   $Revision: 1.4 $
8
9   Copyright (c) Insight Software Consortium. All rights reserved.
10   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11
12      This software is distributed WITHOUT ANY WARRANTY; without even 
13      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
14      PURPOSE.  See the above copyright notices for more information.
15
16 =========================================================================*/
17 #ifndef __itkConstShapedNeighborhoodIterator_h
18 #define __itkConstShapedNeighborhoodIterator_h
19
20 #include <vector>
21 #include <list>
22 #include "itkNeighborhoodIterator.h"
23
24 namespace itk {
25
26 /** \class ConstShapedNeighborhoodIterator
27  *
28 LEN  * \brief Const version of ShapedNeighborhoodIterator, defining iteration of a local
29  * N-dimensional neighborhood of pixels across an itk::Image.
30  *
31  * ConstShapedNeighborhoodIterator implements the read-only methods of
32  * ShapedNeighborhoodIterator.  A "shaped" neighborhood iterator is one that
33  * allows you to specify which neighbor elements are active and which are
34  * inactive.  See ShapedNeighborhoodIterator for more information.
35  *
36  * \sa Neighborhood
37  *
38  * \par MORE INFORMATION
39  * For a complete description of the ITK Image Iterators and their API, please
40  * see the Iterators chapter in the ITK Software Guide.  The ITK Software Guide
41  * is available in print and as a free .pdf download from http://www.itk.org.
42  *
43  * \ingroup ImageIterators
44  *
45  * \sa ImageConstIterator \sa ConditionalConstIterator
46  * \sa ConstNeighborhoodIterator \sa ConstShapedNeighborhoodIterator
47  * \sa ConstSliceIterator  \sa CorrespondenceDataStructureIterator 
48  * \sa FloodFilledFunctionConditionalConstIterator 
49  * \sa FloodFilledImageFunctionConditionalConstIterator 
50  * \sa FloodFilledImageFunctionConditionalIterator 
51  * \sa FloodFilledSpatialFunctionConditionalConstIterator 
52  * \sa FloodFilledSpatialFunctionConditionalIterator 
53  * \sa ImageConstIterator \sa ImageConstIteratorWithIndex 
54  * \sa ImageIterator \sa ImageIteratorWithIndex
55  * \sa ImageLinearConstIteratorWithIndex  \sa ImageLinearIteratorWithIndex 
56  * \sa ImageRandomConstIteratorWithIndex  \sa ImageRandomIteratorWithIndex 
57  * \sa ImageRegionConstIterator \sa ImageRegionConstIteratorWithIndex 
58  * \sa ImageRegionExclusionConstIteratorWithIndex 
59  * \sa ImageRegionExclusionIteratorWithIndex 
60  * \sa ImageRegionIterator  \sa ImageRegionIteratorWithIndex 
61  * \sa ImageRegionReverseConstIterator  \sa ImageRegionReverseIterator 
62  * \sa ImageReverseConstIterator  \sa ImageReverseIterator 
63  * \sa ImageSliceConstIteratorWithIndex  \sa ImageSliceIteratorWithIndex 
64  * \sa NeighborhoodIterator \sa PathConstIterator  \sa PathIterator 
65  * \sa ShapedNeighborhoodIterator  \sa SliceIterator 
66  * \sa ImageConstIteratorWithIndex */
67 template<class TImage,  class TBoundaryCondition
68                        = ZeroFluxNeumannBoundaryCondition<TImage> >
69 class ITK_EXPORT ConstShapedNeighborhoodIterator
70 IND **:  private NeighborhoodIterator<TImage, TBoundaryCondition>
71 {
72 public:
73   /** Extract image type information. */
74   typedef typename TImage::InternalPixelType InternalPixelType;
75 TDA   typedef typename TImage::PixelType PixelType;
76     
77   /** Save the image dimension. */
78   itkStaticConstMacro(Dimension, unsigned int, TImage::ImageDimension);
79   
80   /** Standard class typedefs. */
81   typedef ConstShapedNeighborhoodIterator Self;
82 TDA   typedef NeighborhoodIterator<TImage, TBoundaryCondition> Superclass;
83
84   /** Inherit typedefs from superclass */
85   typedef typename Superclass::OffsetType OffsetType;
86 TDA   typedef typename OffsetType::OffsetValueType OffsetValueType;
87   typedef typename Superclass::RadiusType RadiusType;  
88 TDA   typedef typename Superclass::SizeType SizeType;
89 TDA   typedef typename Superclass::SizeValueType SizeValueType;
90   
91   /** Typedef support for common objects */
92   typedef TImage ImageType;
93 TDA   typedef typename TImage::RegionType RegionType;
94 TDA   typedef Index<itkGetStaticConstMacro(Dimension)> IndexType;
95 TDA   typedef typename IndexType::IndexValueType IndexValueType;
96 LEN,TDA   typedef Neighborhood<PixelType, itkGetStaticConstMacro(Dimension)> NeighborhoodType;
97
98   /** An stl storage container type that can be sorted.  The type used for
99 IND ******the list of active offsets in the neighborhood.*/
100   typedef std::list<unsigned int> IndexListType;
101
102   /** Typedef for boundary condition type. */
103   typedef TBoundaryCondition BoundaryConditionType;
104   
105   /** Typedef for generic boundary condition pointer */
106   typedef ImageBoundaryCondition<ImageType> *ImageBoundaryConditionPointerType;
107
108   /** A const iterator for the ShapedNeighborhood classes.*/
109   struct ConstIterator
110 IND **{
111     ConstIterator() { m_NeighborhoodIterator = 0; }
112     ConstIterator(Self *s)
113 IND ****{
114       m_NeighborhoodIterator = s;
115       this->GoToBegin();
116 IND ****}
117     ~ConstIterator() {}
118     const ConstIterator &operator=(const ConstIterator &o)
119 IND ****{
120       m_NeighborhoodIterator = o.m_NeighborhoodIterator;
121       m_ListIterator = o.m_ListIterator;
122       return *this;
123 IND ****}
124     
125     ConstIterator(const ConstIterator &o)
126 IND ****{
127       m_NeighborhoodIterator = o.m_NeighborhoodIterator;
128       m_ListIterator = o.m_ListIterator;
129 IND ****}
130
131     void operator++(int)
132 IND ****{ m_ListIterator++; }
133
134     void operator--(int)
135 IND ****{ m_ListIterator--; }
136     
137     const ConstIterator &operator++()
138 IND ****{
139       m_ListIterator++;
140       return *this;
141 IND ****}
142     const ConstIterator &operator--()
143 IND ****{
144       m_ListIterator--;
145       return *this;
146 IND ****}
147     
148     bool operator!=(const ConstIterator &o) const
149 IND ****{ return m_ListIterator.operator!=(o.m_ListIterator); }
150     bool operator==(const ConstIterator &o) const
151 IND ****{ return m_ListIterator.operator==(o.m_ListIterator); }
152
153     bool IsAtEnd() const
154 IND ****{
155       if (m_ListIterator == m_NeighborhoodIterator->GetActiveIndexList().end())
156         { return true; }
157       else { return false; }
158 IND ****}
159
160     void GoToBegin()
161 IND ****{
162       m_ListIterator = m_NeighborhoodIterator->GetActiveIndexList().begin();
163 IND ****}
164
165     void GoToEnd()
166 IND ****{
167       m_ListIterator = m_NeighborhoodIterator->GetActiveIndexList().end();
168 IND ****}
169
170     PixelType Get() const
171 IND ****{ return m_NeighborhoodIterator->GetPixel(*m_ListIterator); }
172
173     OffsetType GetNeighborhoodOffset() const
174 IND ****{ return m_NeighborhoodIterator->GetOffset(*m_ListIterator); }
175
176     typename IndexListType::value_type GetNeighborhoodIndex() const
177 IND ****{ return *m_ListIterator; }
178
179   protected:
180     Self *m_NeighborhoodIterator;
181     typename IndexListType::const_iterator m_ListIterator;
182
183     void ProtectedSet(const PixelType &v) const
184 IND ****{ m_NeighborhoodIterator->SetPixel(*m_ListIterator, v); } 
185 IND **};
186
187   /** Returns a const iterator for the neighborhood which points to the first
188    * pixel in the neighborhood. */
189   const ConstIterator &Begin() const
190 IND **{    return m_ConstBeginIterator;  }
191
192   /** Returns a const iterator for the neighborhood which points to the last
193    * pixel in the neighborhood. */
194   const ConstIterator &End() const
195 IND **{    return m_ConstEndIterator;  }
196   
197   /** Default constructor */
198   ConstShapedNeighborhoodIterator()
199 IND **{
200     m_ConstBeginIterator = ConstIterator(this);
201     m_ConstEndIterator = ConstIterator(this);
202     m_ConstEndIterator.GoToEnd();
203     m_CenterIsActive = false;
204 IND **}
205
206   /** Virtual destructor */
207   virtual ~ConstShapedNeighborhoodIterator()  { }
208
209   /** Constructor which establishes the region size, neighborhood, and image
210    * over which to walk. */
211   ConstShapedNeighborhoodIterator(const SizeType &radius,
212                        const ImageType * ptr,
213                        const RegionType ®ion
214 LEN,IND **********************************) : Superclass (radius, const_cast<ImageType*>(ptr),
215 IND **************************************************region)
216 IND **{
217     m_ConstBeginIterator = ConstIterator(this);
218     m_ConstEndIterator = ConstIterator(this);
219     m_ConstEndIterator.GoToEnd();
220     m_CenterIsActive = false;
221 IND **}
222   
223   // Expose the following methods from the superclass.  This is a restricted
224   // subset of the methods available for ConstNeighborhoodIterator.
225   Superclass::GetImagePointer;
226   Superclass::GetRadius;
227   Superclass::GetIndex;
228   Superclass::GetNeighborhoodIndex;
229   Superclass::GetCenterNeighborhoodIndex;
230   Superclass::GetRegion;
231   Superclass::GetBeginIndex;
232   Superclass::GoToBegin;
233   Superclass::GoToEnd;
234   Superclass::IsAtBegin;
235   Superclass::IsAtEnd;
236   Superclass::GetOffset;
237   Superclass::operator==;
238   Superclass::operator!=;
239   Superclass::operator<;
240   Superclass::operator>;
241   Superclass::operator>=;
242   Superclass::operator<=;
243   Superclass::operator[];
244   Superclass::GetElement;
245   Superclass::SetLocation;
246   Superclass::GetCenterPointer;
247   Superclass::GetCenterPixel;
248   Superclass::OverrideBoundaryCondition;
249   Superclass::ResetBoundaryCondition;
250   Superclass::GetBoundaryCondition;
251   Superclass::Print;
252   Superclass::operator-;
253  
254   Superclass::GetPixel;
255   
256   /** Assignment operator */
257   Self &operator=(const Self& orig)
258   {
259     Superclass::operator=(orig);
260     m_ActiveIndexList = orig.m_ActiveIndexList;
261     m_CenterIsActive = orig.m_CenterIsActive;
262
263     // Reset begin and end pointers
264     m_ConstBeginIterator.GoToBegin();
265     m_ConstEndIterator.GoToBegin();
266     return *this;
267   }
268
269   /** Standard itk print method */
270   virtual void PrintSelf(std::ostream &, Indent) const;
271
272 LEN   /** Add/Remove a neighborhood offset (from the center of the neighborhood) to/from the
273       active list.  Active list offsets are the only locations updated and
274       accessible through the iterator.  */
275   virtual void ActivateOffset(const OffsetType& off)
276   { this->ActivateIndex( Superclass::GetNeighborhoodIndex(off) ); }
277   virtual void DeactivateOffset(const OffsetType& off)
278 IND **{ this->DeactivateIndex( Superclass::GetNeighborhoodIndex(off) ); }
279
280   /** Removes all active pixels from this neighborhood. */
281   virtual void ClearActiveList()
282 IND **{
283     m_ActiveIndexList.clear();
284     m_ConstBeginIterator.GoToBegin();
285     m_ConstEndIterator.GoToEnd();
286     m_CenterIsActive = false;
287 IND **}
288   
289   /** Returns the list of active indicies in the neighborhood */
290   const IndexListType &GetActiveIndexList() const
291 IND **{ return m_ActiveIndexList; }
292
293   /** Returns the size of the list of active neighborhood indicies. */
294   typename IndexListType::size_type GetActiveIndexListSize() const
295 IND **{ return m_ActiveIndexList.size(); }
296
297   /** Reimplements the operator++ method so that only active pixel locations
298    * are updataed.*/
299   Self &operator++();
300
301   /** Reimplements the operator-- method so that only active pixel locations
302    * are updataed.*/
303   Self &operator--();
304
305 IND */** Addition of an itk::Offset.  Note that this method does not do any bounds
306    * checking.  Adding an offset that moves the iterator out of its assigned
307    * region will produce undefined results. */
308   Self &operator+=(const OffsetType &);
309
310 LEN   /** Subtraction of an itk::Offset. Note that this method does not do any bounds
311    * checking.  Subtracting an offset that moves the iterator out of its
312    * assigned region will produce undefined results. */
313   Self &operator-=(const OffsetType &);
314
315   // Should be protected, but Borland compiler will not allow it.  A workaround
316   // must be found.
317   Superclass::SetPixel;
318   Superclass::SetCenterPixel;
319 protected:
320 IND ***/** Copy constructor */
321   ConstShapedNeighborhoodIterator( const ConstShapedNeighborhoodIterator & );
322   // purposely not implemented
323
324   friend struct ConstIterator;
325   
326   /** Class is protected here so that it is not publicly accessible, but can be
327    * accessed by subclasses.. */
328   //  Superclass::SetPixel;
329   //  Superclass::SetCenterPixel;
330
331   /** Add/Remove a neighborhood index to/from the active.  Locations in the
332 IND ******active list are the only accessible elements in the neighborhood. The
333 IND ******argument is an index location calculated as an offset into a linear
334 IND ******array which represents the image region defined by the radius of this
335 IND ******iterator, with the smallest dimension as the fastest increasing index. */
336   virtual void ActivateIndex(const unsigned int);
337   virtual void DeactivateIndex(const unsigned int);
338
339   bool m_CenterIsActive;
340   IndexListType m_ActiveIndexList;
341   ConstIterator m_ConstEndIterator;
342   ConstIterator m_ConstBeginIterator;
343 };
344
345
346 // namespace itk
347
348
349 #ifndef ITK_MANUAL_INSTANTIATION
350 #include "itkConstShapedNeighborhoodIterator.txx"
351 #endif
352
353 #endif
354
355 EOF

Generated by KWStyle 1.0b on Tuesday January,17 at 02:14:03PM
© Kitware Inc.