KWStyle - itkImageRegionConstIteratorWithIndex.h
 
Matrix View
Description

1 /*=========================================================================
2
3   Program:   Insight Segmentation & Registration Toolkit
4   Module:    $RCSfile: itkImageRegionConstIteratorWithIndex.h.html,v $
5   Language:  C++
6   Date:      $Date: 2006/01/17 19:15:39 $
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 __itkImageRegionConstIteratorWithIndex_h
18 #define __itkImageRegionConstIteratorWithIndex_h
19
20 #include "itkImageConstIteratorWithIndex.h"
21
22 namespace itk
23 {
24
25 /** \class ImageRegionConstIteratorWithIndex
26  * \brief A multi-dimensional
27  * iterator templated over image type that walks an image region and is
28  * specialized to keep track of its index location.
29  *
30  * The "WithIndex" family of iteators was designed for algorithms that use both
31  * the values and locations of image pixels in calculations. Unlike
32  * ImageRegionIterator, which calculates an index only when requested,
33  * ImageRegionIteratorWithIndex maintains its index location as a member
34  * variable that is updated during increment and decrement operations.
35  * Iteration speed is penalized, but index queries become more efficient.
36  * 
37  * ImageRegionConstIteratorWithIndex is a multi-dimensional iterator,
38  * requiring more information be specified before the iterator can be
39  * used than conventional iterators. Whereas the std::vector::iterator
40  * from the STL only needs to be passed a pointer to establish the
41  * iterator, the multi-dimensional image iterator needs a pointer, the
42  * size of the buffer, the size of the region, the start index of the
43  * buffer, and the start index of the region. To gain access to this
44  * information, ImageRegionConstIteratorWithIndex holds a reference to the
45  * image over which it is traversing.
46  *
47  * ImageRegionConstIteratorWithIndex assumes a particular layout of
48  * the image data. The is arranged in a 1D array as if it were
49  * [][][][slice][row][col] with Index[0] = col, Index[1] = row,
50  * Index[2] = slice, etc.
51  *
52  * operator++ provides a simple syntax for walking around a region of
53  * a multidimensional image. operator++ iterates across a row, constraining
54  * the movement to within a region of image. When the iterator reaches
55  * the boundary of the region along a row, the iterator automatically
56  * wraps to the next row, starting at the first pixel in the row that is
57  * part of the region. This allows for simple processing loops of the form:
58  *
59  *
60  * \code
61  * 
62  *  IteratorType it( image, image->GetRequestedRegion() );
63  *
64  *  it.Begin();
65  *
66  *  while( ! it.IsAtEnd() ) 
67  *  {  
68 IND **    it.Set( 100.0 + it.Get() );
69 IND **    ++it;
70 IND **  }
71  *
72  * \endcode
73  *
74  *  It also can be used for walking in the reverse direction like
75  *
76  * \code
77  * 
78  *  IteratorType it( image, image->GetRequestedRegion() );
79  *
80  *  it.End();
81  *
82  *  while( !it.IsAtBegin() ) 
83  *  {  
84 IND **    it.Set( 100.0 );
85 IND **    --it;
86 IND **  }
87  *
88  * \endcode
89  *
90  * \par MORE INFORMATION
91  *
92  * \example Iterators/ImageRegionIteratorWithIndex.cxx
93  *
94  * For a complete description of the ITK Image Iterators and their API, please
95  * see the Iterators chapter in the ITK Software Guide.  The ITK Software Guide
96  * is available in print and as a free .pdf download from http://www.itk.org.
97  *
98  * \ingroup ImageIterators
99  *
100  * \sa ImageConstIterator \sa ConditionalConstIterator
101  * \sa ConstNeighborhoodIterator \sa ConstShapedNeighborhoodIterator
102  * \sa ConstSliceIterator  \sa CorrespondenceDataStructureIterator 
103  * \sa FloodFilledFunctionConditionalConstIterator 
104  * \sa FloodFilledImageFunctionConditionalConstIterator 
105  * \sa FloodFilledImageFunctionConditionalIterator 
106  * \sa FloodFilledSpatialFunctionConditionalConstIterator 
107  * \sa FloodFilledSpatialFunctionConditionalIterator 
108  * \sa ImageConstIterator \sa ImageConstIteratorWithIndex 
109  * \sa ImageIterator \sa ImageIteratorWithIndex
110  * \sa ImageLinearConstIteratorWithIndex  \sa ImageLinearIteratorWithIndex 
111  * \sa ImageRandomConstIteratorWithIndex  \sa ImageRandomIteratorWithIndex 
112  * \sa ImageRegionConstIterator \sa ImageRegionConstIteratorWithIndex 
113  * \sa ImageRegionExclusionConstIteratorWithIndex 
114  * \sa ImageRegionExclusionIteratorWithIndex 
115  * \sa ImageRegionIterator  \sa ImageRegionIteratorWithIndex 
116  * \sa ImageRegionReverseConstIterator  \sa ImageRegionReverseIterator 
117  * \sa ImageReverseConstIterator  \sa ImageReverseIterator 
118  * \sa ImageSliceConstIteratorWithIndex  \sa ImageSliceIteratorWithIndex 
119  * \sa NeighborhoodIterator \sa PathConstIterator  \sa PathIterator 
120  * \sa ShapedNeighborhoodIterator  \sa SliceIterator 
121  * \sa ImageConstIteratorWithIndex */
122 template<typename TImage>
123 LEN class ITK_EXPORT ImageRegionConstIteratorWithIndex : public ImageConstIteratorWithIndex<TImage>
124 {
125 public:
126   /** Standard class typedefs. */
127   typedef ImageRegionConstIteratorWithIndex Self;
128 TDA   typedef ImageConstIteratorWithIndex<TImage>  Superclass;
129   
130   /** Index typedef support. While this was already typdef'ed in the superclass
131    * it needs to be redone here for this subclass to compile properly with gcc.
132    * Note that we have to rescope Index back to itk::Index to that is it not
133    * confused with ImageIterator::Index. */
134   typedef typename TImage::IndexType  IndexType;
135
136   /** Image typedef support. While this was already typdef'ed in the superclass
137    * it needs to be redone here for this subclass to compile properly with gcc.
138    * Note that we have to rescope Image back to itk::Image to that is it not
139    * confused with ImageIterator::Image. */
140   typedef TImage ImageType;
141
142   /** PixelContainer typedef support. Used to refer to the container for
143    * the pixel data. While this was already typdef'ed in the superclass
144 LEN    * it needs to be redone here for this subclass to compile properly with gcc. */
145   typedef typename TImage::PixelContainer PixelContainer;
146 TDA   typedef typename PixelContainer::Pointer PixelContainerPointer;
147   
148   /** Region typedef support. While this was already typdef'ed in the superclass
149    * it needs to be redone here for this subclass to compile properly with gcc.
150    * Note that we have to rescope Region back to itk::ImageRegion so that is
151    * it not confused with ImageIterator::Index. */
152   typedef typename TImage::RegionType RegionType;
153
154   /** Default constructor. Needed since we provide a cast constructor. */
155   ImageRegionConstIteratorWithIndex() : ImageConstIteratorWithIndex<TImage>() {}
156   
157   /** Constructor establishes an iterator to walk a particular image and a
158    * particular region of that image. */
159   ImageRegionConstIteratorWithIndex( const TImage *ptr,
160                                   const RegionType& region )
161 IND ****: ImageConstIteratorWithIndex<TImage>(ptr, region) {}
162
163   /** Constructor that can be used to cast from an ImageIterator to an
164 LEN    * ImageRegionConstIteratorWithIndex. Many routines return an ImageIterator but for a
165 LEN    * particular task, you may want an ImageRegionConstIteratorWithIndex.  Rather than
166    * provide overloaded APIs that return different types of Iterators, itk
167    * returns ImageIterators and uses constructors to cast from an
168    * ImageIterator to a ImageRegionConstIteratorWithIndex. */
169 LEN   ImageRegionConstIteratorWithIndex( const ImageConstIteratorWithIndex<TImage> &it)
170     { this->ImageConstIteratorWithIndex<TImage>::operator=(it); }
171
172   /** Increment (prefix) the fastest moving dimension of the iterator's index.
173    * This operator will constrain the iterator within the region (i.e. the
174    * iterator will automatically wrap from the end of the row of the region
175    * to the beginning of the next row of the region) up until the iterator
176    * tries to moves past the last pixel of the region.  Here, the iterator
177    * will be set to be one pixel past the end of the region.
178    * \sa operator-- */
179   Self & operator++();
180
181   /** Decrement (prefix) the fastest moving dimension of the iterator's index.
182    * This operator will constrain the iterator within the region (i.e. the
183    * iterator will automatically wrap from the beginning of the row of the 
184    * region to the end of the previous row of the region) up until the iterator
185    * tries to moves past the first pixel of the region.  Here, the iterator
186    * will be set to be one pixel past the beginning of the region.
187    * \sa operator++ */
188   Self & operator--();
189 };
190
191 /** \example itkImageIteratorTest.cpp */
192 /** \example itkIteratorTests.cpp */
193
194 // end namespace itk
195
196 #ifndef ITK_MANUAL_INSTANTIATION
197 #include "itkImageRegionConstIteratorWithIndex.txx"
198 #endif
199
200 #endif 
201
202 EOF

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