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