| 1 |
|
/*========================================================================= |
| 2 |
|
|
| 3 |
|
Program: Insight Segmentation & Registration Toolkit |
| 4 |
|
Module: $RCSfile: itkImageLinearConstIteratorWithIndex.h.html,v $ |
| 5 |
|
Language: C++ |
| 6 |
|
Date: $Date: 2006/01/17 19:15:38 $ |
| 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 __itkImageLinearConstIteratorWithIndex_h |
| 18 |
|
#define __itkImageLinearConstIteratorWithIndex_h |
| 19 |
|
|
| 20 |
|
#include "itkImageConstIteratorWithIndex.h" |
| 21 |
|
|
| 22 |
|
namespace itk |
| 23 |
|
{ |
| 24 |
|
|
| 25 |
|
/** \class ImageLinearConstIteratorWithIndex |
| 26 |
|
* \brief A multi-dimensional image iterator that visits image pixels within a |
| 27 |
|
* region in a "scan-line" order. |
| 28 |
|
* |
| 29 |
|
* ImageLinearConstIteratorWithIndex is templated over image type and is |
| 30 |
|
* constrained to walk within a specified image region. It is designed for |
| 31 |
|
* line-by-line processing of images. This iterator walks a linear path along |
| 32 |
|
* a selected image direction that is parallel to one of the coordinate axes |
| 33 |
|
* of the image. The iterator conceptually breaks the image into a set of |
| 34 |
|
* parallel lines that span the selected image dimension. |
| 35 |
|
* |
| 36 |
|
* ImageLinearConstIteratorWithIndex assumes a particular layout of the image |
| 37 |
|
* data. The is arranged in a 1D array as if it were [][][][slice][row][col] |
| 38 |
|
* with Index[0] = col, Index[1] = row, Index[2] = slice, etc. |
| 39 |
|
* |
| 40 |
|
* operator++ provides a simple syntax for walking around a region of a |
| 41 |
|
* multidimensional image. operator++ iterates across a preselected direction |
| 42 |
|
* constraining the movement to within a region of image. The user can verify |
| 43 |
|
* when the iterator reaches the boundary of the region along this direction, |
| 44 |
|
* by calling the IsAtEndOfLine() method. Then it is possible to pass to the |
| 45 |
|
* next line starting at the first pixel in the row that is part of the region |
| 46 |
|
* by calling the NextLine() method. |
| 47 |
|
* |
| 48 |
|
* This is the typical use of this iterator in a loop: |
| 49 |
|
* |
| 50 |
|
* \code |
| 51 |
|
* |
| 52 |
LEN |
* ImageLinearConstIteratorWithIndex<ImageType> it( image, image->GetRequestedRegion() ); |
| 53 |
|
* |
| 54 |
|
* it.SetDirection(2); |
| 55 |
|
* it.GoToBegin(); |
| 56 |
|
* while( !it.IsAtEnd() ) |
| 57 |
|
* { |
| 58 |
IND |
** while( !it.IsAtEndOfLine() ) |
| 59 |
IND |
** { |
| 60 |
IND |
** value = it.Get(); // it.Set() doesn't exist in the Const Iterator |
| 61 |
IND |
** ++it; |
| 62 |
IND |
** } |
| 63 |
IND |
** it.NextLine(); |
| 64 |
IND |
** } |
| 65 |
|
* |
| 66 |
|
* \endcode |
| 67 |
|
* |
| 68 |
|
* \example Examples/Iterators/ImageLinearIteratorWithIndex.cxx |
| 69 |
|
* |
| 70 |
|
* \par MORE INFORMATION |
| 71 |
|
* For a complete description of the ITK Image Iterators and their API, please |
| 72 |
|
* see the Iterators chapter in the ITK Software Guide. The ITK Software Guide |
| 73 |
|
* is available in print and as a free .pdf download from http://www.itk.org. |
| 74 |
|
* |
| 75 |
|
* \ingroup ImageIterators |
| 76 |
|
* |
| 77 |
|
* \sa ImageConstIterator \sa ConditionalConstIterator |
| 78 |
|
* \sa ConstNeighborhoodIterator \sa ConstShapedNeighborhoodIterator |
| 79 |
|
* \sa ConstSliceIterator \sa CorrespondenceDataStructureIterator |
| 80 |
|
* \sa FloodFilledFunctionConditionalConstIterator |
| 81 |
|
* \sa FloodFilledImageFunctionConditionalConstIterator |
| 82 |
|
* \sa FloodFilledImageFunctionConditionalIterator |
| 83 |
|
* \sa FloodFilledSpatialFunctionConditionalConstIterator |
| 84 |
|
* \sa FloodFilledSpatialFunctionConditionalIterator |
| 85 |
|
* \sa ImageConstIterator \sa ImageConstIteratorWithIndex |
| 86 |
|
* \sa ImageIterator \sa ImageIteratorWithIndex |
| 87 |
|
* \sa ImageLinearConstIteratorWithIndex \sa ImageLinearIteratorWithIndex |
| 88 |
|
* \sa ImageRandomConstIteratorWithIndex \sa ImageRandomIteratorWithIndex |
| 89 |
|
* \sa ImageRegionConstIterator \sa ImageRegionConstIteratorWithIndex |
| 90 |
|
* \sa ImageRegionExclusionConstIteratorWithIndex |
| 91 |
|
* \sa ImageRegionExclusionIteratorWithIndex |
| 92 |
|
* \sa ImageRegionIterator \sa ImageRegionIteratorWithIndex |
| 93 |
|
* \sa ImageRegionReverseConstIterator \sa ImageRegionReverseIterator |
| 94 |
|
* \sa ImageReverseConstIterator \sa ImageReverseIterator |
| 95 |
|
* \sa ImageSliceConstIteratorWithIndex \sa ImageSliceIteratorWithIndex |
| 96 |
|
* \sa NeighborhoodIterator \sa PathConstIterator \sa PathIterator |
| 97 |
|
* \sa ShapedNeighborhoodIterator \sa SliceIterator |
| 98 |
|
* \sa ImageConstIteratorWithIndex |
| 99 |
|
* |
| 100 |
|
*/ |
| 101 |
|
template<typename TImage> |
| 102 |
LEN |
class ITK_EXPORT ImageLinearConstIteratorWithIndex : public ImageConstIteratorWithIndex<TImage> |
| 103 |
|
{ |
| 104 |
|
public: |
| 105 |
|
/** Standard class typedefs. */ |
| 106 |
|
typedef ImageLinearConstIteratorWithIndex Self; |
| 107 |
TDA |
typedef ImageConstIteratorWithIndex<TImage> Superclass; |
| 108 |
|
|
| 109 |
|
/** Index typedef support. While this was already typdef'ed in the superclass |
| 110 |
|
* it needs to be redone here for this subclass to compile properly with gcc. |
| 111 |
|
* Note that we have to rescope Index back to itk::Index to that is it not |
| 112 |
|
* confused with ImageIterator::Index. */ |
| 113 |
|
typedef typename TImage::IndexType IndexType; |
| 114 |
|
|
| 115 |
|
/** Region typedef support. While this was already typdef'ed in the superclass |
| 116 |
|
* it needs to be redone here for this subclass to compile properly with gcc. |
| 117 |
|
* Note that we have to rescope Region back to itk::ImageRegion so that is |
| 118 |
|
* it not confused with ImageIterator::Index. */ |
| 119 |
|
typedef typename TImage::RegionType RegionType; |
| 120 |
|
|
| 121 |
|
/** Image typedef support. While this was already typdef'ed in the superclass |
| 122 |
|
* it needs to be redone here for this subclass to compile properly with gcc. |
| 123 |
|
* Note that we have to rescope Index back to itk::Index to that is it not |
| 124 |
|
* confused with ImageIterator::Index. */ |
| 125 |
|
typedef TImage ImageType; |
| 126 |
|
|
| 127 |
|
/** PixelContainer typedef support. Used to refer to the container for |
| 128 |
|
* the pixel data. While this was already typdef'ed in the superclass |
| 129 |
LEN |
* it needs to be redone here for this subclass to compile properly with gcc. */ |
| 130 |
|
typedef typename TImage::PixelContainer PixelContainer; |
| 131 |
TDA |
typedef typename PixelContainer::Pointer PixelContainerPointer; |
| 132 |
|
|
| 133 |
|
/** Default constructor. Needed since we provide a cast constructor. */ |
| 134 |
|
ImageLinearConstIteratorWithIndex() : ImageConstIteratorWithIndex<TImage>() {} |
| 135 |
|
|
| 136 |
|
/** Constructor establishes an iterator to walk a particular image and a |
| 137 |
|
* particular region of that image. */ |
| 138 |
LEN |
ImageLinearConstIteratorWithIndex(const ImageType *ptr, const RegionType& region); |
| 139 |
|
|
| 140 |
|
/** Constructor that can be used to cast from an ImageIterator to an |
| 141 |
LEN |
* ImageLinearConstIteratorWithIndex. Many routines return an ImageIterator but for a |
| 142 |
LEN |
* particular task, you may want an ImageLinearConstIteratorWithIndex. Rather than |
| 143 |
|
* provide overloaded APIs that return different types of Iterators, itk |
| 144 |
|
* returns ImageIterators and uses constructors to cast from an |
| 145 |
|
* ImageIterator to a ImageLinearConstIteratorWithIndex. */ |
| 146 |
LEN |
ImageLinearConstIteratorWithIndex( const ImageConstIteratorWithIndex<TImage> &it) |
| 147 |
|
{ this->ImageConstIteratorWithIndex<TImage>::operator=(it); } |
| 148 |
|
|
| 149 |
|
/** Go to the next line. |
| 150 |
LEN |
* \sa operator++ \sa operator-- \sa IsAtEndOfLine \sa PreviousLine \sa End */ |
| 151 |
|
inline void NextLine(void); |
| 152 |
|
|
| 153 |
|
/** Go to the previous line. |
| 154 |
|
* \sa operator++ \sa operator-- \sa IsAtEndOfLine \sa NextLine \sa End */ |
| 155 |
|
inline void PreviousLine(void); |
| 156 |
|
|
| 157 |
|
/** Go to the beginning pixel of the current line. |
| 158 |
LEN |
* \sa GoToReverseBeginOfLine \sa operator++ \sa operator-- \sa NextLine \sa IsAtEndOfLine */ |
| 159 |
|
void GoToBeginOfLine(void); |
| 160 |
|
|
| 161 |
|
/** Go to the beginning pixel of the current line. |
| 162 |
LEN |
* \sa GoToBeginOfLine \sa operator++ \sa operator-- \sa NextLine \sa IsAtEndOfLine */ |
| 163 |
|
void GoToReverseBeginOfLine(void); |
| 164 |
|
|
| 165 |
|
/** Go to the past end pixel of the current line. |
| 166 |
LEN |
* \sa GoToBeginOfLine \sa operator++ \sa operator-- \sa NextLine \sa IsAtEndOfLine */ |
| 167 |
|
void GoToEndOfLine(void); |
| 168 |
|
|
| 169 |
|
/** Test if the index is at the end of line */ |
| 170 |
|
inline bool IsAtEndOfLine(void); |
| 171 |
|
|
| 172 |
|
/** Test if the index is at the begin of line */ |
| 173 |
|
inline bool IsAtReverseEndOfLine(void); |
| 174 |
|
|
| 175 |
|
/** Set the direction of movement */ |
| 176 |
SEM |
inline void SetDirection(unsigned int direction) ; |
| 177 |
|
|
| 178 |
|
/** Increment (prefix) the selected dimension. |
| 179 |
|
* No bounds checking is performed. \sa GetIndex \sa operator-- */ |
| 180 |
|
inline Self & operator++(); |
| 181 |
|
|
| 182 |
|
/** Decrement (prefix) the selected dimension. |
| 183 |
|
* No bounds checking is performed. \sa GetIndex \sa operator++ */ |
| 184 |
|
inline Self & operator--(); |
| 185 |
|
|
| 186 |
|
private: |
| 187 |
IND |
****unsigned long m_Jump; |
| 188 |
IND |
****unsigned int m_Direction; |
| 189 |
|
}; |
| 190 |
|
|
| 191 |
|
} // end namespace itk |
| 192 |
|
|
| 193 |
|
#ifndef ITK_MANUAL_INSTANTIATION |
| 194 |
|
#include "itkImageLinearConstIteratorWithIndex.txx" |
| 195 |
|
#endif |
| 196 |
|
|
| 197 |
|
#endif |
| 198 |
|
|