Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkImageFunction.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkImageFunction.h,v $
00005   Language:  C++
00006   Date:      $Date: 2007/01/30 23:39:53 $
00007   Version:   $Revision: 1.43 $
00008 
00009   Copyright (c) Insight Software Consortium. All rights reserved.
00010   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
00011 
00012      This software is distributed WITHOUT ANY WARRANTY; without even 
00013      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00014      PURPOSE.  See the above copyright notices for more information.
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< Point<TCoordRep,
00073                               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 
00132   virtual bool IsInsideBuffer( const IndexType & index ) const
00133     { 
00134       for ( unsigned int j = 0; j < ImageDimension; j++ )
00135         {
00136         if ( index[j] < m_StartIndex[j] ) { return false; };
00137         if ( index[j] > m_EndIndex[j] ) { return false; };
00138         }
00139       return true;
00140     }
00142 
00146   virtual bool IsInsideBuffer( const ContinuousIndexType & index ) const
00147     { 
00148       for ( unsigned int j = 0; j < ImageDimension; j++ )
00149         {
00150         if ( index[j] < m_StartContinuousIndex[j] ) { return false; };
00151         if ( index[j] > m_EndContinuousIndex[j] ) { return false; };
00152         }
00153       return true;
00154     }
00156 
00160   virtual bool IsInsideBuffer( const PointType & point ) const
00161     { 
00162     ContinuousIndexType index;
00163     m_Image->TransformPhysicalPointToContinuousIndex( point, index );
00164     return this->IsInsideBuffer( index );
00165     }
00167 
00169   void ConvertPointToNearestIndex( const PointType & point,
00170     IndexType & index ) const
00171     {
00172     ContinuousIndexType cindex;
00173     m_Image->TransformPhysicalPointToContinuousIndex( point, cindex );
00174     this->ConvertContinuousIndexToNearestIndex( cindex, index );
00175     }
00177 
00179    void ConvertPointToContinousIndex( const PointType & point,
00180     ContinuousIndexType & cindex ) const
00181     {
00182     m_Image->TransformPhysicalPointToContinuousIndex( point, cindex );
00183     }
00184 
00185 // The Windows implementaton of vnl_math_rnd() does not round the
00186 // same way as the linux versions. It appears to round down on
00187 // .5. This code replaces the standard vnl implementation that uses
00188 // assembler code. The code below will be slower for windows but will
00189 // produce consistent results.
00190 #if defined (VCL_VC) && !defined(__GCCXML__)
00191 #define vnl_math_rnd(x) ((x>=0.0)?(int)(x + 0.5):(int)(x - 0.5))
00192 #endif
00193 
00194   void ConvertContinuousIndexToNearestIndex( const ContinuousIndexType & cindex,
00195     IndexType & index ) const
00196     {
00197     typedef typename IndexType::IndexValueType ValueType;
00198     for ( unsigned int j = 0; j < ImageDimension; j++ )
00199       { index[j] = static_cast<ValueType>( vnl_math_rnd( cindex[j] ) ); }
00200     }
00201 #if defined (VCL_VC) && !defined(__GCCXML__)
00202 #undef vnl_math_rnd
00203 #endif
00204 
00205 
00206   itkGetConstReferenceMacro(StartIndex, IndexType);
00207   itkGetConstReferenceMacro(EndIndex, IndexType);
00208 
00209   itkGetConstReferenceMacro(StartContinuousIndex, ContinuousIndexType);
00210   itkGetConstReferenceMacro(EndContinuousIndex, ContinuousIndexType);
00211 
00212 protected:
00213   ImageFunction();
00214   ~ImageFunction() {}
00215   void PrintSelf(std::ostream& os, Indent indent) const;
00216 
00218   InputImageConstPointer  m_Image;
00219 
00221   IndexType               m_StartIndex;
00222   IndexType               m_EndIndex;
00223   ContinuousIndexType     m_StartContinuousIndex;
00224   ContinuousIndexType     m_EndContinuousIndex;
00225 
00226 private:
00227   ImageFunction(const Self&); //purposely not implemented
00228   void operator=(const Self&); //purposely not implemented
00229   
00230 };
00231 
00232 } // end namespace itk
00233 
00234 // Define instantiation macro for this template.
00235 #define ITK_TEMPLATE_ImageFunction(_, EXPORT, x, y) namespace itk { \
00236   _(3(class EXPORT ImageFunction< ITK_TEMPLATE_3 x >)) \
00237   namespace Templates { typedef ImageFunction< ITK_TEMPLATE_3 x > ImageFunction##y; } \
00238   }
00239 
00240 #if ITK_TEMPLATE_EXPLICIT
00241 # include "Templates/itkImageFunction+-.h"
00242 #endif
00243 
00244 #if ITK_TEMPLATE_TXX
00245 # include "itkImageFunction.txx"
00246 #endif
00247 
00248 #endif
00249 

Generated at Sun Sep 23 12:55:38 2007 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000