| 1 |
|
/*========================================================================= |
| 2 |
|
|
| 3 |
|
Program: Insight Segmentation & Registration Toolkit |
| 4 |
|
Module: $RCSfile: itkPathConstIterator.h.html,v $ |
| 5 |
|
Language: C++ |
| 6 |
|
Date: $Date: 2006/01/17 19:15:43 $ |
| 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 __itkPathConstIterator_h |
| 18 |
|
#define __itkPathConstIterator_h |
| 19 |
|
|
| 20 |
|
#include "itkIndex.h" |
| 21 |
|
#include "itkImage.h" |
| 22 |
|
#include "itkPath.h" |
| 23 |
|
|
| 24 |
|
namespace itk |
| 25 |
|
{ |
| 26 |
|
|
| 27 |
|
/** |
| 28 |
|
* \class PathConstIterator |
| 29 |
|
* \brief PathConstIterator iterates (traces) over a path through an image. |
| 30 |
|
* |
| 31 |
|
* This iterator visits only those indices of the image that are overlapped by |
| 32 |
|
* a specified 1D path. All indicies are visited in path order. If a path |
| 33 |
|
* crosses itself at an index, that index of the image will be visited twice. |
| 34 |
|
* An exception to this rule is that if the path is closed, i.e. its starting |
| 35 |
|
* and ending indicies are coincident. When starting and ending indicies are |
| 36 |
|
* coincident, GoToBegin() will go to the second index, since the "first" index |
| 37 |
|
* will be visited later as the "last" index. This is so that paths |
| 38 |
|
* (especially parametric paths) can be properly closed, without |
| 39 |
|
* double-visiting the starting/ending point. This behavior can be overridden |
| 40 |
|
* by calling VisitStartIndexAsLastIndexIfClosed(false) before calling |
| 41 |
|
* GoToBegin(). This class is the const version of the PathIterator, and for |
| 42 |
|
* this reason it doesn't support the Set() method. |
| 43 |
|
* |
| 44 |
|
* \par MORE INFORMATION |
| 45 |
|
* For a complete description of the ITK Image Iterators and their API, please |
| 46 |
|
* see the Iterators chapter in the ITK Software Guide. The ITK Software Guide |
| 47 |
|
* is available in print and as a free .pdf download from http://www.itk.org. |
| 48 |
|
* |
| 49 |
|
* \ingroup PathObjects \ingroup ImageIterators |
| 50 |
|
* |
| 51 |
|
* \sa ImageConstIterator \sa ConditionalConstIterator |
| 52 |
|
* \sa ConstNeighborhoodIterator \sa ConstShapedNeighborhoodIterator |
| 53 |
|
* \sa ConstSliceIterator \sa CorrespondenceDataStructureIterator |
| 54 |
|
* \sa FloodFilledFunctionConditionalConstIterator |
| 55 |
|
* \sa FloodFilledImageFunctionConditionalConstIterator |
| 56 |
|
* \sa FloodFilledImageFunctionConditionalIterator |
| 57 |
|
* \sa FloodFilledSpatialFunctionConditionalConstIterator |
| 58 |
|
* \sa FloodFilledSpatialFunctionConditionalIterator |
| 59 |
|
* \sa ImageConstIterator \sa ImageConstIteratorWithIndex |
| 60 |
|
* \sa ImageIterator \sa ImageIteratorWithIndex |
| 61 |
|
* \sa ImageLinearConstIteratorWithIndex \sa ImageLinearIteratorWithIndex |
| 62 |
|
* \sa ImageRandomConstIteratorWithIndex \sa ImageRandomIteratorWithIndex |
| 63 |
|
* \sa ImageRegionConstIterator \sa ImageRegionConstIteratorWithIndex |
| 64 |
|
* \sa ImageRegionExclusionConstIteratorWithIndex |
| 65 |
|
* \sa ImageRegionExclusionIteratorWithIndex |
| 66 |
|
* \sa ImageRegionIterator \sa ImageRegionIteratorWithIndex |
| 67 |
|
* \sa ImageRegionReverseConstIterator \sa ImageRegionReverseIterator |
| 68 |
|
* \sa ImageReverseConstIterator \sa ImageReverseIterator |
| 69 |
|
* \sa ImageSliceConstIteratorWithIndex \sa ImageSliceIteratorWithIndex |
| 70 |
|
* \sa NeighborhoodIterator \sa PathIterator \sa ShapedNeighborhoodIterator |
| 71 |
|
* \sa SliceIterator \sa ImageConstIteratorWithIndex */ |
| 72 |
|
template<class TImage, class TPath> |
| 73 |
|
class ITK_EXPORT PathConstIterator |
| 74 |
|
{ |
| 75 |
|
public: |
| 76 |
|
/** Standard class typedefs. */ |
| 77 |
|
typedef PathConstIterator Self; |
| 78 |
|
|
| 79 |
|
/** Dimension of the image the iterator walks. This constant is needed so |
| 80 |
|
* that functions that are templated over image iterator type (as opposed to |
| 81 |
|
* being templated over pixel type and dimension) can have compile time |
| 82 |
|
* access to the dimension of the image that the iterator walks. */ |
| 83 |
|
itkStaticConstMacro(ImageIteratorDimension, unsigned int, |
| 84 |
|
TImage::ImageDimension); |
| 85 |
|
|
| 86 |
|
/** Index typedef support. */ |
| 87 |
|
typedef typename TImage::IndexType IndexType; |
| 88 |
|
typedef typename TImage::IndexValueType IndexValueType; |
| 89 |
|
|
| 90 |
|
/** Offset typedef support. */ |
| 91 |
|
typedef typename TImage::OffsetType OffsetType; |
| 92 |
|
typedef typename TImage::OffsetValueType OffsetValueType; |
| 93 |
|
|
| 94 |
|
/** Size typedef support. */ |
| 95 |
|
typedef typename TImage::SizeType SizeType; |
| 96 |
|
typedef typename TImage::SizeValueType SizeValueType; |
| 97 |
|
|
| 98 |
|
/** Region typedef support */ |
| 99 |
|
typedef typename TImage::RegionType RegionType; |
| 100 |
|
|
| 101 |
|
/** Spacing typedef support */ |
| 102 |
|
typedef typename TImage::SpacingType SpacingType; |
| 103 |
|
|
| 104 |
|
/** Origin typedef support */ |
| 105 |
|
typedef typename TImage::PointType PointType; |
| 106 |
|
|
| 107 |
|
/** Image typedef support. */ |
| 108 |
|
typedef TImage ImageType; |
| 109 |
|
|
| 110 |
|
/** PixelContainer typedef support. Used to refer to the container for |
| 111 |
|
* the pixel data. While this was already typdef'ed in the superclass |
| 112 |
LEN |
* it needs to be redone here for this subclass to compile properly with gcc. */ |
| 113 |
|
typedef typename TImage::PixelContainer PixelContainer; |
| 114 |
|
typedef typename PixelContainer::Pointer PixelContainerPointer; |
| 115 |
|
|
| 116 |
|
/** Internal Pixel Type */ |
| 117 |
|
typedef typename TImage::InternalPixelType InternalPixelType; |
| 118 |
|
|
| 119 |
|
/** External Pixel Type */ |
| 120 |
|
typedef typename TImage::PixelType PixelType; |
| 121 |
|
|
| 122 |
|
/** Accessor type that convert data between internal and external |
| 123 |
|
* representations. */ |
| 124 |
|
typedef typename TImage::AccessorType AccessorType; |
| 125 |
|
|
| 126 |
|
/** Path typedef support */ |
| 127 |
|
typedef TPath PathType; |
| 128 |
|
|
| 129 |
|
/** Path 1D Input Type */ |
| 130 |
|
typedef typename PathType::InputType PathInputType; |
| 131 |
|
|
| 132 |
|
/** Path ND Output Type, which is not necessarily an index type */ |
| 133 |
|
typedef typename PathType::OutputType PathOutputType; |
| 134 |
|
|
| 135 |
|
/** Run-time type information (and related methods). */ |
| 136 |
|
itkTypeMacro(PathConstIterator, None); |
| 137 |
|
|
| 138 |
|
/** Get the dimension (size) of the index. */ |
| 139 |
|
static unsigned int GetImageIteratorDimension() |
| 140 |
|
{ |
| 141 |
|
return TImage::ImageDimension; |
| 142 |
|
} |
| 143 |
|
|
| 144 |
|
/** Get the input. This provides a read only reference to the input. */ |
| 145 |
|
const PathInputType GetPathPosition() |
| 146 |
|
{ |
| 147 |
|
return m_CurrentPathPosition; |
| 148 |
|
} |
| 149 |
|
|
| 150 |
|
/** Get the index. This provides a read only reference to the index. */ |
| 151 |
|
const IndexType GetIndex() |
| 152 |
|
{ |
| 153 |
|
return m_CurrentImageIndex; |
| 154 |
|
} |
| 155 |
|
|
| 156 |
|
/** Get the pixel value */ |
| 157 |
|
const PixelType & Get(void) const |
| 158 |
|
{ |
| 159 |
|
return m_Image->GetPixel(m_CurrentImageIndex ); |
| 160 |
|
} |
| 161 |
|
|
| 162 |
|
/** Is the iterator at the end of the path? |
| 163 |
|
* Note that for a closed path, it may be possible to increment back to the |
| 164 |
|
* start of the path. */ |
| 165 |
|
bool IsAtEnd() |
| 166 |
|
{ |
| 167 |
|
return m_IsAtEnd; |
| 168 |
|
} |
| 169 |
|
|
| 170 |
|
/** Should GoToBegin() initially skip the first index of a closed path so that |
| 171 |
|
* the first index will only be visited once--at the end of the path? If set |
| 172 |
|
* to false, then GoToBegin() will always move to the 1'st index. The |
| 173 |
|
* constructor presets m_VisitStartIndexAsLastIndexIfClosed to true. */ |
| 174 |
|
inline virtual void VisitStartIndexAsLastIndexIfClosed(bool flag) |
| 175 |
|
{ |
| 176 |
|
m_VisitStartIndexAsLastIndexIfClosed = flag; |
| 177 |
|
} |
| 178 |
|
|
| 179 |
|
/** Move an iterator to the beginning of the path. If the starting and ending |
| 180 |
|
* indicies of the path are coincident, then move to the 2'nd index of the |
| 181 |
|
* path, since the 1'st index will be visited later as the last index. |
| 182 |
|
* However, if m_VisitStartIndexAsLastIndexIfClosed is false, then GoToBegin() |
| 183 |
|
* will always move to the 1'st index. */ |
| 184 |
|
void GoToBegin(); |
| 185 |
|
|
| 186 |
|
/** Walk forward along the path to the next index in the image. */ |
| 187 |
|
void operator++(); |
| 188 |
|
|
| 189 |
|
/** operator= is provided to make sure the handles to the image and path are |
| 190 |
|
* properly reference counted. */ |
| 191 |
|
Self &operator=(const Self& it); |
| 192 |
|
|
| 193 |
|
/** Constructor establishes an iterator to walk along a path */ |
| 194 |
|
PathConstIterator(const ImageType *imagePtr, const PathType *pathPtr); |
| 195 |
|
|
| 196 |
|
/** Default Destructor. */ |
| 197 |
|
virtual ~PathConstIterator() {}; |
| 198 |
|
|
| 199 |
|
protected: //made protected so other iterators can access |
| 200 |
|
// This "constant" is initialized in the constructor |
| 201 |
|
OffsetType m_ZeroOffset; // = 0 for all dimensions |
| 202 |
|
|
| 203 |
|
/** Smart pointer to the source image. */ |
| 204 |
|
typename ImageType::ConstWeakPointer m_Image; |
| 205 |
|
|
| 206 |
|
/** Smart pointer to the path we're following */ |
| 207 |
|
typename PathType::ConstPointer m_Path; |
| 208 |
|
|
| 209 |
|
/** Region type to iterate over. */ |
| 210 |
|
RegionType m_Region; |
| 211 |
|
|
| 212 |
|
/** The origin of the source image */ |
| 213 |
|
PointType m_ImageOrigin; |
| 214 |
|
|
| 215 |
|
/** The spacing of the source image */ |
| 216 |
|
SpacingType m_ImageSpacing; |
| 217 |
|
|
| 218 |
|
/** Size of the source image */ |
| 219 |
|
const unsigned long int* m_ImageSize; |
| 220 |
|
|
| 221 |
|
/** Should GoToBegin() initially skip the first index of a closed path so that |
| 222 |
|
* the first index will only be visited once--at the end of the path? If |
| 223 |
|
* false, then GoToBegin() will always move to the 1'st index. The default |
| 224 |
|
* value is true, which is set the constructor. */ |
| 225 |
|
bool m_VisitStartIndexAsLastIndexIfClosed; |
| 226 |
|
|
| 227 |
|
/** Is the iterator at the end of its walk? */ |
| 228 |
|
bool m_IsAtEnd; |
| 229 |
|
|
| 230 |
|
/** Current 1D position along the path, such as time or arc length */ |
| 231 |
|
PathInputType m_CurrentPathPosition; |
| 232 |
|
|
| 233 |
|
/** Current ND index position in the image of the path */ |
| 234 |
|
IndexType m_CurrentImageIndex; |
| 235 |
|
}; |
| 236 |
|
|
| 237 |
|
} // end namespace itk |
| 238 |
|
|
| 239 |
|
#ifndef ITK_MANUAL_INSTANTIATION |
| 240 |
|
#include "itkPathConstIterator.txx" |
| 241 |
|
#endif |
| 242 |
|
|
| 243 |
|
#endif |
| 244 |
|
|