00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __itkImageFunction_h
00018 #define __itkImageFunction_h
00019
00020 #include "itkFunctionBase.h"
00021 #include "itkPoint.h"
00022 #include "itkIndex.h"
00023 #include "itkContinuousIndex.h"
00024 #include "itkImageBase.h"
00025
00026 namespace itk
00027 {
00028
00029
00055 template <
00056 class TInputImage,
00057 class TOutput,
00058 class TCoordRep = float
00059 >
00060 class ITK_EXPORT ImageFunction :
00061 public FunctionBase< Point<TCoordRep,
00062 ::itk::GetImageDimension<TInputImage>::ImageDimension>,
00063 TOutput >
00064 {
00065 public:
00067 itkStaticConstMacro(ImageDimension, unsigned int,
00068 TInputImage::ImageDimension);
00069
00071 typedef ImageFunction Self;
00072 typedef FunctionBase<
00073 Point<TCoordRep, itkGetStaticConstMacro(ImageDimension)>,
00074 TOutput > Superclass;
00075 typedef SmartPointer<Self> Pointer;
00076 typedef SmartPointer<const Self> ConstPointer;
00077
00079 itkTypeMacro(ImageFunction, FunctionBase);
00080
00082 typedef TInputImage InputImageType;
00083
00085 typedef typename InputImageType::PixelType InputPixelType;
00086
00088 typedef typename InputImageType::ConstPointer InputImageConstPointer;
00089
00091 typedef TOutput OutputType;
00092
00094 typedef TCoordRep CoordRepType;
00095
00097 typedef typename InputImageType::IndexType IndexType;
00098
00100 typedef ContinuousIndex<TCoordRep,itkGetStaticConstMacro(ImageDimension)>
00101 ContinuousIndexType;
00102
00104 typedef Point<TCoordRep,itkGetStaticConstMacro(ImageDimension)> PointType;
00105
00110 virtual void SetInputImage( const InputImageType * ptr );
00111
00113 const InputImageType * GetInputImage() const
00114 { return m_Image.GetPointer(); }
00115
00118 virtual TOutput Evaluate( const PointType& point ) const = 0;
00119
00122 virtual TOutput EvaluateAtIndex( const IndexType & index ) const = 0;
00123
00126 virtual TOutput EvaluateAtContinuousIndex(
00127 const ContinuousIndexType & index ) const = 0;
00128
00136 virtual bool IsInsideBuffer( const IndexType & index ) const
00137 {
00138 for( unsigned int j = 0; j < ImageDimension; j++ )
00139 {
00140 if( index[j] < m_StartIndex[j] )
00141 {
00142 return false;
00143 }
00144 if( index[j] > m_EndIndex[j] )
00145 {
00146 return false;
00147 }
00148 }
00149 return true;
00150 }
00152
00156 virtual bool IsInsideBuffer( const ContinuousIndexType & index ) const
00157 {
00158 for( unsigned int j = 0; j < ImageDimension; j++ )
00159 {
00160 if( index[j] < m_StartContinuousIndex[j] )
00161 {
00162 return false;
00163 }
00164 if( index[j] > m_EndContinuousIndex[j] )
00165 {
00166 return false;
00167 }
00168 }
00169 return true;
00170 }
00172
00176 virtual bool IsInsideBuffer( const PointType & point ) const
00177 {
00178 ContinuousIndexType index;
00179 m_Image->TransformPhysicalPointToContinuousIndex( point, index );
00180 return this->IsInsideBuffer( index );
00181 }
00183
00185 void ConvertPointToNearestIndex( const PointType & point,
00186 IndexType & index ) const
00187 {
00188 ContinuousIndexType cindex;
00189 m_Image->TransformPhysicalPointToContinuousIndex( point, cindex );
00190 this->ConvertContinuousIndexToNearestIndex( cindex, index );
00191 }
00193
00195 void ConvertPointToContinousIndex( const PointType & point,
00196 ContinuousIndexType & cindex ) const
00197 {
00198 itkWarningMacro("Please change your code to use ConvertPointToContinuousIndex "
00199 << "rather than ConvertPointToContinousIndex. The latter method name was "
00200 << "mispelled and the ITK developers failed to correct it before it was released."
00201 << "The mispelled method name is retained in order to maintain backward compatibility.");
00202 this->ConvertPointToContinuousIndex( point, cindex );
00203 }
00205
00207 void ConvertPointToContinuousIndex( const PointType & point,
00208 ContinuousIndexType & cindex ) const
00209 {
00210 m_Image->TransformPhysicalPointToContinuousIndex( point, cindex );
00211 }
00212
00214 inline void ConvertContinuousIndexToNearestIndex( const ContinuousIndexType & cindex,
00215 IndexType & index ) const
00216 {
00217 index.CopyWithRound( cindex );
00218 }
00219
00220 itkGetConstReferenceMacro(StartIndex, IndexType);
00221 itkGetConstReferenceMacro(EndIndex, IndexType);
00222
00223 itkGetConstReferenceMacro(StartContinuousIndex, ContinuousIndexType);
00224 itkGetConstReferenceMacro(EndContinuousIndex, ContinuousIndexType);
00225
00226 protected:
00227 ImageFunction();
00228 ~ImageFunction() {}
00229 void PrintSelf(std::ostream& os, Indent indent) const;
00230
00232 InputImageConstPointer m_Image;
00233
00235 IndexType m_StartIndex;
00236 IndexType m_EndIndex;
00237 ContinuousIndexType m_StartContinuousIndex;
00238 ContinuousIndexType m_EndContinuousIndex;
00239
00240 private:
00241 ImageFunction(const Self&);
00242 void operator=(const Self&);
00243
00244 };
00245
00246 }
00247
00248
00249
00250 #define ITK_TEMPLATE_ImageFunction(_, EXPORT, x, y) namespace itk { \
00251 _(3(class EXPORT ImageFunction< ITK_TEMPLATE_3 x >)) \
00252 namespace Templates { typedef ImageFunction< ITK_TEMPLATE_3 x > ImageFunction##y; } \
00253 }
00254
00255 #if ITK_TEMPLATE_EXPLICIT
00256 # include "Templates/itkImageFunction+-.h"
00257 #endif
00258
00259 #if ITK_TEMPLATE_TXX
00260 # include "itkImageFunction.txx"
00261 #endif
00262
00263 #endif
00264