Go to the documentation of this file.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 typedef typename InputImageType::IndexValueType IndexValueType;
00099
00101 typedef ContinuousIndex<TCoordRep,itkGetStaticConstMacro(ImageDimension)>
00102 ContinuousIndexType;
00103
00105 typedef Point<TCoordRep,itkGetStaticConstMacro(ImageDimension)> PointType;
00106
00111 virtual void SetInputImage( const InputImageType * ptr );
00112
00114 const InputImageType * GetInputImage() const
00115 { return m_Image.GetPointer(); }
00116
00119 virtual TOutput Evaluate( const PointType& point ) const = 0;
00120
00123 virtual TOutput EvaluateAtIndex( const IndexType & index ) const = 0;
00124
00127 virtual TOutput EvaluateAtContinuousIndex(
00128 const ContinuousIndexType & index ) const = 0;
00129
00137 virtual bool IsInsideBuffer( const IndexType & index ) const
00138 {
00139 for( unsigned int j = 0; j < ImageDimension; j++ )
00140 {
00141 if( index[j] < m_StartIndex[j] )
00142 {
00143 return false;
00144 }
00145 if( index[j] > m_EndIndex[j] )
00146 {
00147 return false;
00148 }
00149 }
00150 return true;
00151 }
00153
00157 virtual bool IsInsideBuffer( const ContinuousIndexType & index ) const
00158 {
00159 for( unsigned int j = 0; j < ImageDimension; j++ )
00160 {
00161 if( index[j] < m_StartContinuousIndex[j] )
00162 {
00163 return false;
00164 }
00165 #ifdef ITK_USE_CENTERED_PIXEL_COORDINATES_CONSISTENTLY
00166 if( index[j] >= m_EndContinuousIndex[j] )
00167 #else
00168 if( index[j] > m_EndContinuousIndex[j] )
00169 #endif
00170 {
00171 return false;
00172 }
00173 }
00174 return true;
00175 }
00177
00181 virtual bool IsInsideBuffer( const PointType & point ) const
00182 {
00183 ContinuousIndexType index;
00184 m_Image->TransformPhysicalPointToContinuousIndex( point, index );
00185 return this->IsInsideBuffer( index );
00186 }
00188
00190 void ConvertPointToNearestIndex( const PointType & point,
00191 IndexType & index ) const
00192 {
00193 ContinuousIndexType cindex;
00194 m_Image->TransformPhysicalPointToContinuousIndex( point, cindex );
00195 this->ConvertContinuousIndexToNearestIndex( cindex, index );
00196 }
00198
00200 void ConvertPointToContinousIndex( const PointType & point,
00201 ContinuousIndexType & cindex ) const
00202 {
00203 itkWarningMacro("Please change your code to use ConvertPointToContinuousIndex "
00204 << "rather than ConvertPointToContinousIndex. The latter method name was "
00205 << "mispelled and the ITK developers failed to correct it before it was released."
00206 << "The mispelled method name is retained in order to maintain backward compatibility.");
00207 this->ConvertPointToContinuousIndex( point, cindex );
00208 }
00210
00212 void ConvertPointToContinuousIndex( const PointType & point,
00213 ContinuousIndexType & cindex ) const
00214 {
00215 m_Image->TransformPhysicalPointToContinuousIndex( point, cindex );
00216 }
00217
00219 inline void ConvertContinuousIndexToNearestIndex( const ContinuousIndexType & cindex,
00220 IndexType & index ) const
00221 {
00222 index.CopyWithRound( cindex );
00223 }
00224
00225 itkGetConstReferenceMacro(StartIndex, IndexType);
00226 itkGetConstReferenceMacro(EndIndex, IndexType);
00227
00228 itkGetConstReferenceMacro(StartContinuousIndex, ContinuousIndexType);
00229 itkGetConstReferenceMacro(EndContinuousIndex, ContinuousIndexType);
00230
00231 protected:
00232 ImageFunction();
00233 ~ImageFunction() {}
00234 void PrintSelf(std::ostream& os, Indent indent) const;
00235
00237 InputImageConstPointer m_Image;
00238
00240 IndexType m_StartIndex;
00241 IndexType m_EndIndex;
00242 ContinuousIndexType m_StartContinuousIndex;
00243 ContinuousIndexType m_EndContinuousIndex;
00244
00245 private:
00246 ImageFunction(const Self&);
00247 void operator=(const Self&);
00248
00249 };
00250
00251 }
00252
00253
00254
00255 #define ITK_TEMPLATE_ImageFunction(_, EXPORT, x, y) namespace itk { \
00256 _(3(class EXPORT ImageFunction< ITK_TEMPLATE_3 x >)) \
00257 namespace Templates { typedef ImageFunction< ITK_TEMPLATE_3 x > ImageFunction##y; } \
00258 }
00259
00260 #if ITK_TEMPLATE_EXPLICIT
00261 # include "Templates/itkImageFunction+-.h"
00262 #endif
00263
00264 #if ITK_TEMPLATE_TXX
00265 # include "itkImageFunction.txx"
00266 #endif
00267
00268 #endif
00269