]> Creatis software - FrontAlgorithms.git/blob - lib/fpa/Image/Algorithm.h
Segmentation guided by a gaussian estimator added -- Not yet finished
[FrontAlgorithms.git] / lib / fpa / Image / Algorithm.h
1 #ifndef __FPA__IMAGE__ALGORITHM__H__
2 #define __FPA__IMAGE__ALGORITHM__H__
3
4 #include <itkImage.h>
5 #include <itkFunctionBase.h>
6
7 namespace fpa
8 {
9   namespace Image
10   {
11     namespace Functors
12     {
13       /**
14        */
15       template< class VV, class C >
16       class CastVertexValueToCost
17         : public itk::FunctionBase< VV, C >
18       {
19       public:
20         // Type-related and pointers
21         typedef CastVertexValueToCost           Self;
22         typedef itk::FunctionBase< VV, C >      Superclass;
23         typedef itk::SmartPointer< Self >       Pointer;
24         typedef itk::SmartPointer< const Self > ConstPointer;
25
26       public:
27         itkNewMacro( Self );
28         itkTypeMacro( CastVertexValueToCost, itkFunctionBase );
29
30       public:
31         virtual C Evaluate( const VV& v ) const
32           { return( C( v ) ); }
33
34       protected:
35         CastVertexValueToCost( )
36           : Superclass( )
37           { }
38         virtual ~CastVertexValueToCost( )
39           { }
40
41       private:
42         // Purposely not implemented
43         CastVertexValueToCost( const Self& );
44         void operator=( const Self& );
45       };
46
47       /**
48        */
49       template< class VV, class C >
50       class CastVertexValueToConstantCost
51         : public itk::FunctionBase< VV, C >
52       {
53       public:
54         // Type-related and pointers
55         typedef CastVertexValueToConstantCost   Self;
56         typedef itk::FunctionBase< VV, C >      Superclass;
57         typedef itk::SmartPointer< Self >       Pointer;
58         typedef itk::SmartPointer< const Self > ConstPointer;
59
60       public:
61         itkNewMacro( Self );
62         itkTypeMacro( CastVertexValueToConstantCost, itkFunctionBase );
63
64       public:
65         virtual C Evaluate( const VV& v ) const
66           { return( C( 1 ) ); }
67
68       protected:
69         CastVertexValueToConstantCost( )
70           : Superclass( )
71           { }
72         virtual ~CastVertexValueToConstantCost( )
73           { }
74
75       private:
76         // Purposely not implemented
77         CastVertexValueToConstantCost( const Self& );
78         void operator=( const Self& );
79       };
80
81     } // ecapseman
82
83     /**
84      * A generic front propagation algorithm were vertices are image pixels.
85      *
86      * @param I    Input image type
87      * @param A    Base algorithm (RegionGrow, Dijkstra or FastMarching)
88      */
89     template< class I, class A, class CC >
90     class Algorithm
91       : public A
92     {
93     public:
94       /// Standard class typdedefs
95       typedef Algorithm                       Self;
96       typedef A                               Superclass;
97       typedef itk::SmartPointer< Self >       Pointer;
98       typedef itk::SmartPointer< const Self > ConstPointer;
99
100       /// Template input values
101       typedef I  TInputImage;
102       typedef A  TBaseAlgorithm;
103       typedef CC TCostConversionFunction;
104
105       typedef typename A::TTraits            TTraits;
106       typedef typename TTraits::TCost        TCost;
107       typedef typename TTraits::TResult      TResult;
108       typedef typename TTraits::TVertex      TVertex;
109       typedef typename TTraits::TVertexValue TVertexValue;
110
111       typedef itk::Image< TResult, I::ImageDimension > TOutputImage;
112
113     protected:
114       typedef typename TTraits::TFrontId _TFrontId;
115       typedef typename TTraits::TNode    _TNode;
116       typedef typename TTraits::TNodes   _TNodes;
117
118     private:
119       typedef itk::Image< bool, I::ImageDimension >      _TMarks;
120       typedef itk::Image< _TFrontId, I::ImageDimension > _TFrontsIds;
121       typedef itk::Image< TVertex, I::ImageDimension >   _TParents;
122
123     public:
124       itkTypeMacro( Algorithm, TAlgorithm );
125
126       /// Set/Get
127       itkGetConstMacro( NeighborhoodOrder, unsigned int );
128       itkGetConstObjectMacro( CostConversion, TCostConversionFunction );
129       itkGetObjectMacro( CostConversion, TCostConversionFunction );
130
131       itkSetMacro( NeighborhoodOrder, unsigned int );
132       itkSetObjectMacro( CostConversion, TCostConversionFunction );
133
134     protected:
135       Algorithm( );
136       virtual ~Algorithm( );
137
138       /// Base interface
139       virtual bool _UpdateResult( _TNode& n );
140
141       /// Pure virtual interface: vertices
142       virtual unsigned long _NumberOfVertices ( ) const;
143       virtual  TVertexValue _Value            ( const TVertex& v ) const;
144       virtual       TResult _Result           ( const TVertex& v ) const;
145
146       /// Pure virtual interface: edges
147       virtual double _Norm ( const TVertex& a, const TVertex& b ) const;
148       virtual   bool _Edge ( const TVertex& a, const TVertex& b ) const;
149       virtual  TCost _Cost ( const TVertex& a, const TVertex& b ) const;
150
151       /// Pure virtual interface: neighborhood
152       virtual void _Neighs      ( const _TNode& n, _TNodes& N ) const;
153       virtual void _NeighsInDim ( const _TNode& n,
154                                   const unsigned int& d,
155                                   _TNodes& N );
156
157       /// Pure virtual interface: results
158       virtual void _InitializeResults ( );
159
160     private:
161       Algorithm( const Self& );      // Not impl.
162       void operator=( const Self& ); // Not impl.
163
164     protected:
165       unsigned int                              m_NeighborhoodOrder;
166       typename TCostConversionFunction::Pointer m_CostConversion;
167     };
168
169   } // ecapseman
170
171 } // ecapseman
172
173 #include <fpa/Image/Algorithm.hxx>
174
175 #endif // __FPA__IMAGE__ALGORITHM__H__
176
177 // eof - $RCSfile$