| 1 |
|
/*========================================================================= |
| 2 |
|
|
| 3 |
|
Program: Insight Segmentation & Registration Toolkit |
| 4 |
|
Module: $RCSfile: itkChainCodePath.h.html,v $ |
| 5 |
|
Language: C++ |
| 6 |
|
Date: $Date: 2006/01/17 19:15:33 $ |
| 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 |
|
|
| 18 |
DEF |
#ifndef _itkChainCodePath_h |
| 19 |
DEF |
#define _itkChainCodePath_h |
| 20 |
|
|
| 21 |
|
#include "itkPath.h" |
| 22 |
|
#include "itkIndex.h" |
| 23 |
|
#include "itkOffset.h" |
| 24 |
|
#include <vector> |
| 25 |
|
|
| 26 |
|
namespace itk |
| 27 |
|
{ |
| 28 |
|
|
| 29 |
|
|
| 30 |
|
/** \class ChainCodePath |
| 31 |
|
* \brief Represent a path as a sequence of connected image index offsets |
| 32 |
|
* |
| 33 |
|
* This class is intended to represent sequences of connected indices in an |
| 34 |
|
* image. It does so by storing the offset of each index from its immediately |
| 35 |
|
* preceeding, connected, index. The only image index stored directly is that |
| 36 |
|
* of the first index. ChainCodePath maps a 1D integer input (step number) to |
| 37 |
|
* an ND interger output (either an offset or an image index, depending on |
| 38 |
|
* whether Evaluate or EvaluateToIndex is called). |
| 39 |
|
* |
| 40 |
|
* \sa ChainCodePath2D |
| 41 |
|
* \sa ParametricPath |
| 42 |
|
* \sa Path |
| 43 |
|
* \sa Index |
| 44 |
|
* \sa Offset |
| 45 |
|
* |
| 46 |
|
* \ingroup PathObjects |
| 47 |
|
*/ |
| 48 |
|
template <unsigned int VDimension> |
| 49 |
|
class ITK_EXPORT ChainCodePath : public |
| 50 |
|
Path< unsigned int, Offset< VDimension >, VDimension > |
| 51 |
|
{ |
| 52 |
|
public: |
| 53 |
|
/** Dimension underlying input image. */ |
| 54 |
|
itkStaticConstMacro(Dimension, unsigned int, VDimension); |
| 55 |
|
|
| 56 |
|
/** Standard class typedefs. */ |
| 57 |
|
typedef ChainCodePath<VDimension> Self; |
| 58 |
|
typedef Path< unsigned int, Offset< VDimension >, VDimension > Superclass; |
| 59 |
|
|
| 60 |
|
typedef SmartPointer<Self> Pointer; |
| 61 |
TDA |
typedef SmartPointer<const Self> ConstPointer; |
| 62 |
|
|
| 63 |
|
/** Run-time type information (and related methods). */ |
| 64 |
|
itkTypeMacro(ChainCodePath, Path); |
| 65 |
|
|
| 66 |
|
|
| 67 |
|
/** OutputType typedef support. */ |
| 68 |
|
typedef typename Superclass::OutputType OutputType; |
| 69 |
|
typedef typename Superclass::InputType InputType; |
| 70 |
|
|
| 71 |
|
/** The output type of this function is an Index */ |
| 72 |
|
typedef OutputType OffsetType; |
| 73 |
|
typedef Index<VDimension> IndexType; |
| 74 |
|
|
| 75 |
|
typedef std::vector<OffsetType> ChainCodeType; |
| 76 |
|
|
| 77 |
|
|
| 78 |
EML |
|
| 79 |
|
// Functions inherited from Path |
| 80 |
|
|
| 81 |
|
/** Evaluate the chaincode for the offset at the specified path-position. */ |
| 82 |
|
virtual OutputType Evaluate( const InputType & input ) const |
| 83 |
|
{ |
| 84 |
|
return m_Chain[input]; |
| 85 |
|
} |
| 86 |
|
|
| 87 |
|
/** Like Evaluate(), but returns the index at the specified path-position. */ |
| 88 |
|
virtual IndexType EvaluateToIndex( const InputType & input ) const; |
| 89 |
|
|
| 90 |
|
/** Increment the input variable passed by reference and then return the |
| 91 |
|
* offset stored at the new path-position. If the chaincode is unable to be |
| 92 |
|
* incremented, input is not changed and an offset of zero is returned, which |
| 93 |
|
* may be used to check for the end of the chain code. */ |
| 94 |
|
virtual OffsetType IncrementInput(InputType & input) const; |
| 95 |
|
|
| 96 |
|
/** Where does the path end (what is the last valid input value)? */ |
| 97 |
|
virtual inline InputType EndOfInput() const |
| 98 |
|
{ |
| 99 |
|
return NumberOfSteps(); // 0 is before the first step, 1 is after it |
| 100 |
|
} |
| 101 |
|
|
| 102 |
|
|
| 103 |
|
|
| 104 |
|
// Functions specific to ChainCodePath |
| 105 |
|
|
| 106 |
|
/** New() method for dynamic construction */ |
| 107 |
|
itkNewMacro( Self ); |
| 108 |
|
|
| 109 |
|
/** Set/Get the index associated with the initial position of the path */ |
| 110 |
|
itkSetMacro( Start, IndexType ); |
| 111 |
|
itkGetConstReferenceMacro( Start, IndexType ); |
| 112 |
|
|
| 113 |
|
/** Insert a new step into the chaincode at a specified position */ |
| 114 |
|
virtual inline void InsertStep( InputType position, OffsetType step ) |
| 115 |
|
{ |
| 116 |
|
m_Chain.insert( m_Chain.begin()+position, step ); |
| 117 |
|
this->Modified(); |
| 118 |
|
} |
| 119 |
|
|
| 120 |
|
/** Change the direction of a step in the chaincode */ |
| 121 |
|
virtual inline void ChangeStep( InputType position, OffsetType step ) |
| 122 |
|
{ |
| 123 |
|
m_Chain[position]=step; |
| 124 |
|
this->Modified(); |
| 125 |
|
} |
| 126 |
|
|
| 127 |
|
/** Remove all steps from the chain code */ |
| 128 |
|
virtual inline void Clear() |
| 129 |
|
{ |
| 130 |
|
m_Chain.clear(); |
| 131 |
|
this->Modified(); |
| 132 |
|
} |
| 133 |
|
|
| 134 |
|
/** How many steps in the chaincode? */ |
| 135 |
|
virtual inline unsigned int NumberOfSteps() const |
| 136 |
|
{ |
| 137 |
|
return m_Chain.size(); |
| 138 |
|
} |
| 139 |
|
|
| 140 |
|
/** Needed for Pipelining */ |
| 141 |
|
virtual void Initialize(void) |
| 142 |
|
{ |
| 143 |
|
m_Start = this->GetZeroIndex(); |
| 144 |
|
this->Clear(); |
| 145 |
|
} |
| 146 |
|
|
| 147 |
|
|
| 148 |
EML |
|
| 149 |
|
protected: |
| 150 |
|
ChainCodePath(); |
| 151 |
|
~ChainCodePath() {} |
| 152 |
|
void PrintSelf(std::ostream& os, Indent indent) const; |
| 153 |
|
|
| 154 |
|
|
| 155 |
|
private: |
| 156 |
|
ChainCodePath(const Self&); //purposely not implemented |
| 157 |
|
void operator=(const Self&); //purposely not implemented |
| 158 |
|
|
| 159 |
|
IndexType m_Start; // origin image index for the path |
| 160 |
|
ChainCodeType m_Chain; // the chain code (vector of offsets) |
| 161 |
|
}; |
| 162 |
|
|
| 163 |
|
} // namespace itk |
| 164 |
|
|
| 165 |
|
#ifndef ITK_MANUAL_INSTANTIATION |
| 166 |
|
#include "itkChainCodePath.txx" |
| 167 |
|
#endif |
| 168 |
|
|
| 169 |
|
#endif |
| 170 |
|
|