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: 2008-10-17 13:35:26 $
00007   Version:   $Revision: 1.47 $
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<
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 
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] )
00137         {
00138         return false;
00139         }
00140       if( index[j] > m_EndIndex[j] )
00141         {
00142         return false;
00143         }
00144       }
00145     return true;
00146     }
00148 
00152   virtual bool IsInsideBuffer( const ContinuousIndexType & index ) const
00153     {
00154     for( unsigned int j = 0; j < ImageDimension; j++ )
00155       {
00156       if( index[j] < m_StartContinuousIndex[j] )
00157         {
00158         return false;
00159         }
00160       if( index[j] > m_EndContinuousIndex[j] )
00161         {
00162         return false;
00163         }
00164       }
00165     return true;
00166     }
00168 
00172   virtual bool IsInsideBuffer( const PointType & point ) const
00173     {
00174     ContinuousIndexType index;
00175     m_Image->TransformPhysicalPointToContinuousIndex( point, index );
00176     return this->IsInsideBuffer( index );
00177     }
00179 
00181   void ConvertPointToNearestIndex( const PointType & point,
00182     IndexType & index ) const
00183     {
00184     ContinuousIndexType cindex;
00185     m_Image->TransformPhysicalPointToContinuousIndex( point, cindex );
00186     this->ConvertContinuousIndexToNearestIndex( cindex, index );
00187     }
00189 
00191   void ConvertPointToContinousIndex( const PointType & point,
00192     ContinuousIndexType & cindex ) const
00193     {
00194     itkWarningMacro("Please change your code to use ConvertPointToContinuousIndex "
00195       << "rather than ConvertPointToContinousIndex. The latter method name was "
00196       << "mispelled and the ITK developers failed to correct it before it was released."
00197       << "The mispelled method name is retained in order to maintain backward compatibility.");
00198     this->ConvertPointToContinuousIndex( point, cindex );
00199     }
00201 
00203   void ConvertPointToContinuousIndex( const PointType & point,
00204     ContinuousIndexType & cindex ) const
00205     {
00206     m_Image->TransformPhysicalPointToContinuousIndex( point, cindex );
00207     }
00208 
00210   inline void ConvertContinuousIndexToNearestIndex( const ContinuousIndexType & cindex,
00211     IndexType & index ) const
00212     {
00213     index.CopyWithRound( cindex );
00214     }
00215 
00216   itkGetConstReferenceMacro(StartIndex, IndexType);
00217   itkGetConstReferenceMacro(EndIndex, IndexType);
00218 
00219   itkGetConstReferenceMacro(StartContinuousIndex, ContinuousIndexType);
00220   itkGetConstReferenceMacro(EndContinuousIndex, ContinuousIndexType);
00221 
00222 protected:
00223   ImageFunction();
00224   ~ImageFunction() {}
00225   void PrintSelf(std::ostream& os, Indent indent) const;
00226 
00228   InputImageConstPointer  m_Image;
00229 
00231   IndexType               m_StartIndex;
00232   IndexType               m_EndIndex;
00233   ContinuousIndexType     m_StartContinuousIndex;
00234   ContinuousIndexType     m_EndContinuousIndex;
00235 
00236 private:
00237   ImageFunction(const Self&); //purposely not implemented
00238   void operator=(const Self&); //purposely not implemented
00239 
00240 };
00241 
00242 } // end namespace itk
00243 
00244 // Define instantiation macro for this template.
00245 #define ITK_TEMPLATE_ImageFunction(_, EXPORT, x, y) namespace itk { \
00246   _(3(class EXPORT ImageFunction< ITK_TEMPLATE_3 x >)) \
00247   namespace Templates { typedef ImageFunction< ITK_TEMPLATE_3 x > ImageFunction##y; } \
00248   }
00249 
00250 #if ITK_TEMPLATE_EXPLICIT
00251 # include "Templates/itkImageFunction+-.h"
00252 #endif
00253 
00254 #if ITK_TEMPLATE_TXX
00255 # include "itkImageFunction.txx"
00256 #endif
00257 
00258 #endif
00259 

Generated at Wed Nov 5 21:58:27 2008 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000