]> Creatis software - cpPlugins.git/blob - lib/cpExtensions/Algorithms/GradientFunctionBase.h
...
[cpPlugins.git] / lib / cpExtensions / Algorithms / GradientFunctionBase.h
1 // -------------------------------------------------------------------------
2 // @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
3 // -------------------------------------------------------------------------
4
5 #ifndef __CPEXTENSIONS__ALGORITHMS__GRADIENTFUNCTIONBASE__H__
6 #define __CPEXTENSIONS__ALGORITHMS__GRADIENTFUNCTIONBASE__H__
7
8 #include <map>
9 #include <itkImageFunction.h>
10
11 namespace cpExtensions
12 {
13   namespace Algorithms
14   {
15     /**
16      */
17     template< class G >
18     class GradientFunctionBase
19       : public itk::ImageFunction< G, typename G::PixelType::ValueType, typename G::PixelType::ValueType >
20     {
21     public:
22       // Types from input arguments
23       typedef G                           TGradient;
24       typedef typename G::PixelType       TVector;
25       typedef typename TVector::ValueType TScalar;
26       itkStaticConstMacro( Dimension, unsigned int, G::ImageDimension );
27
28       // Standard itk types
29       typedef GradientFunctionBase                      Self;
30       typedef itk::ImageFunction< G, TScalar, TScalar > Superclass;
31       typedef itk::SmartPointer< Self >                 Pointer;
32       typedef itk::SmartPointer< const Self >           ConstPointer;
33
34       // Types from base itk::ImageFunction
35       typedef typename Superclass::InputType           TInput;
36       typedef typename Superclass::OutputType          TOutput;
37       typedef typename Superclass::PointType           TPoint;
38       typedef typename Superclass::ContinuousIndexType TContIndex;
39       typedef typename Superclass::IndexType           TIndex;
40
41       // Sparse buffer
42       typedef std::map< TIndex, TOutput, typename TIndex::LexicographicCompare > TBuffer;
43
44     public:
45       itkTypeMacro( GradientFunctionBase, itkImageFunction );
46
47       itkBooleanMacro( BufferResults );
48       itkGetConstMacro( BufferResults, bool );
49       itkSetMacro( BufferResults, bool );
50
51     public:
52       virtual void ResetBuffer( );
53
54       virtual TOutput Evaluate( const TPoint& p ) const;
55       virtual TOutput EvaluateAtIndex( const TIndex& i ) const;
56       virtual TOutput EvaluateAtContinuousIndex( const TContIndex& i ) const;
57
58     protected:
59       GradientFunctionBase( );
60       virtual ~GradientFunctionBase( );
61
62       virtual TOutput _Evaluate( const TIndex& i ) const = 0;
63
64     private:
65       // Purposely not implemented.
66       GradientFunctionBase( const Self& );
67       void operator=( const Self& );
68
69     protected:
70       mutable TBuffer m_Buffer;
71       bool m_BufferResults;
72     };
73
74   } // ecapseman
75
76 } // ecapseman
77
78 #include <cpExtensions/Algorithms/GradientFunctionBase.hxx>
79
80 #endif // __CPEXTENSIONS__ALGORITHMS__GRADIENTFUNCTIONBASE__H__
81
82 // eof - $RCSfile$