]> Creatis software - FrontAlgorithms.git/blob - lib/fpa/Image/Algorithm.h
289eb6c0e7da7dad12899fcf8c929b3b0e58d5f1
[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     /**
12      * A generic front propagation algorithm were vertices are image pixels.
13      *
14      * @param I    Input image type
15      * @param A    Base algorithm (RegionGrow, Dijkstra or FastMarching)
16      */
17     template< class I, class A >
18     class Algorithm
19       : public A
20     {
21     public:
22       /// Standard class typdedefs
23       typedef Algorithm                       Self;
24       typedef A                               Superclass;
25       typedef itk::SmartPointer< Self >       Pointer;
26       typedef itk::SmartPointer< const Self > ConstPointer;
27
28       /// Template input values
29       typedef I TInputImage;
30       typedef A TBaseAlgorithm;
31
32       typedef typename A::TTraits            TTraits;
33       typedef typename TTraits::TCost        TCost;
34       typedef typename TTraits::TResult      TResult;
35       typedef typename TTraits::TVertex      TVertex;
36       typedef typename TTraits::TVertexValue TVertexValue;
37
38       typedef itk::Image< TResult, I::ImageDimension > TOutputImage;
39       typedef itk::FunctionBase< TCost, TCost > TCostConversionFunction;
40
41     protected:
42       typedef typename TTraits::TFrontId _TFrontId;
43       typedef typename TTraits::TNode    _TNode;
44       typedef typename TTraits::TNodes   _TNodes;
45
46     private:
47       typedef itk::Image< bool, I::ImageDimension >      _TMarks;
48       typedef itk::Image< _TFrontId, I::ImageDimension > _TFrontsIds;
49       typedef itk::Image< TVertex, I::ImageDimension >   _TParents;
50
51     public:
52       itkTypeMacro( Algorithm, TAlgorithm );
53
54       /// Set/Get
55       itkGetConstMacro( NeighborhoodOrder, unsigned int );
56       itkGetConstObjectMacro( CostConversion, TCostConversionFunction );
57       itkGetObjectMacro( CostConversion, TCostConversionFunction );
58
59       itkSetMacro( NeighborhoodOrder, unsigned int );
60       itkSetObjectMacro( CostConversion, TCostConversionFunction );
61
62     protected:
63       Algorithm( );
64       virtual ~Algorithm( );
65
66       /// Base interface
67       virtual bool _UpdateResult( _TNode& n );
68
69       /// Pure virtual interface: vertices
70       virtual unsigned long _NumberOfVertices ( ) const;
71       virtual  TVertexValue _Value            ( const TVertex& v ) const;
72       virtual       TResult _Result           ( const TVertex& v ) const;
73
74       /// Pure virtual interface: edges
75       virtual double _Norm ( const TVertex& a, const TVertex& b ) const;
76       virtual   bool _Edge ( const TVertex& a, const TVertex& b ) const;
77       virtual  TCost _Cost ( const TVertex& a, const TVertex& b ) const;
78
79       /// Pure virtual interface: neighborhood
80       virtual void _Neighs      ( const _TNode& n, _TNodes& N ) const;
81       virtual void _NeighsInDim ( const _TNode& n,
82                                   const unsigned int& d,
83                                   _TNodes& N );
84
85       /// Pure virtual interface: results
86       virtual void _InitializeResults ( );
87
88     private:
89       Algorithm( const Self& );      // Not impl.
90       void operator=( const Self& ); // Not impl.
91
92     protected:
93       unsigned int                              m_NeighborhoodOrder;
94       typename TCostConversionFunction::Pointer m_CostConversion;
95     };
96
97   } // ecapseman
98
99 } // ecapseman
100
101 #include <fpa/Image/Algorithm.hxx>
102
103 #endif // __FPA__IMAGE__ALGORITHM__H__
104
105 // eof - $RCSfile$