]> Creatis software - FrontAlgorithms.git/blob - lib/fpa/Functors/Dijkstra/Image/Gaussian.h
...
[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                 if( this->m_TreatAsWeight ) d = std::exp( d * d ) - TValue( 1 );
66                 else                        d = std::exp( -std::fabs( d ) );
67
68                 if( d < this->m_Epsilon ) return( this->m_Epsilon );
69                 else                      return( d );
70               }
71               else
72                 return( TValue( -1 ) );
73             }
74
75         protected:
76           Gaussian( )
77             : Superclass( ),
78               m_Beta( TValue( 1 ) ),
79               m_Epsilon( TValue( 1e-5 ) ),
80               m_TreatAsWeight( true )
81             {
82             }
83           virtual ~Gaussian( )
84             {
85             }
86
87         private:
88           // Purposely not implemented.
89           Gaussian( const Self& other );
90           Self& operator=( const Self& other );
91
92         protected:
93           TValue m_Beta;
94           TValue m_Epsilon;
95           bool   m_TreatAsWeight;
96         };
97
98       } // ecapseman
99
100     } // ecapseman
101
102   } // ecapseman
103
104 } // ecapseman
105
106 #endif // __fpa__Functors__Dijkstra__Gaussian__h__
107 // eof - $RCSfile$