]> Creatis software - FrontAlgorithms.git/blob - lib/fpa/Functors/Dijkstra/Image/Gaussian.h
2effb513f4f707236c3203be83514168b9700420
[FrontAlgorithms.git] / lib / fpa / Functors / Dijkstra / Image / Gaussian.h
1 // =========================================================================
2 // @author Leonardo Florez Valencia
3 // @email florez-l@javeriana.edu.co
4 // =========================================================================
5 #ifndef __fpa__Functors__Dijkstra__Image__Gaussian__h__
6 #define __fpa__Functors__Dijkstra__Image__Gaussian__h__
7
8 #include <cmath>
9 #include <fpa/Functors/VertexFunction.h>
10
11 namespace fpa
12 {
13   namespace Functors
14   {
15     namespace Dijkstra
16     {
17       namespace Image
18       {
19         /**
20          */
21         template< class _TImage, class _TValue >
22         class Gaussian
23           : public fpa::Functors::VertexFunction< typename _TImage::IndexType, _TValue >
24         {
25         public:
26           typedef _TImage TImage;
27           typedef _TValue TValue;
28           typedef typename TImage::IndexType TVertex;
29           typedef fpa::Functors::VertexFunction< TVertex, TValue >  Superclass;
30           typedef Gaussian                        Self;
31           typedef itk::SmartPointer< Self >       Pointer;
32           typedef itk::SmartPointer< const Self > ConstPointer;
33
34         public:
35           itkNewMacro( Self );
36           itkTypeMacro(
37             fpa::Functors::Dijkstra::Image::Gaussian,
38             fpa::Functors::VertexFunction
39             );
40
41           itkGetConstMacro( Beta, TValue );
42           itkSetMacro( Beta, TValue );
43
44           itkGetConstMacro( Epsilon, TValue );
45           itkSetMacro( Epsilon, TValue );
46
47           itkBooleanMacro( TreatAsWeight );
48           itkGetConstMacro( TreatAsWeight, bool );
49           itkSetMacro( TreatAsWeight, bool );
50
51         public:
52           virtual TValue Evaluate(
53             const TVertex& v, const TVertex& p
54             ) const override
55             {
56               const TImage* image =
57                 dynamic_cast< const TImage* >(
58                   this->m_DataObject.GetPointer( )
59                   );
60               if( image != NULL )
61               {
62                 TValue d = TValue( image->GetPixel( v ) );
63                 d       -= TValue( image->GetPixel( p ) );
64                 d       /= this->m_Beta;
65                 d       *= d;
66                 if( this->m_TreatAsWeight ) d = std::exp(  d );
67                 else                        d = std::exp( -d );
68
69                 if( d < this->m_Epsilon ) return( this->m_Epsilon );
70                 else                      return( d );
71               }
72               else
73                 return( TValue( -1 ) );
74             }
75
76         protected:
77           Gaussian( )
78             : Superclass( ),
79               m_Beta( TValue( 1 ) ),
80               m_Epsilon( TValue( 1e-5 ) ),
81               m_TreatAsWeight( true )
82             {
83             }
84           virtual ~Gaussian( )
85             {
86             }
87
88         private:
89           // Purposely not implemented.
90           Gaussian( const Self& other );
91           Self& operator=( const Self& other );
92
93         protected:
94           TValue m_Beta;
95           TValue m_Epsilon;
96           bool   m_TreatAsWeight;
97         };
98
99       } // ecapseman
100
101     } // ecapseman
102
103   } // ecapseman
104
105 } // ecapseman
106
107 #endif // __fpa__Functors__Dijkstra__Gaussian__h__
108 // eof - $RCSfile$