]> Creatis software - FrontAlgorithms.git/blob - lib/fpa/Base/Algorithm.h
...
[FrontAlgorithms.git] / lib / fpa / Base / Algorithm.h
1 #ifndef __fpa__Base__Algorithm__h__
2 #define __fpa__Base__Algorithm__h__
3
4 #include <vector>
5 #include <itkFunctionBase.h>
6 #include <fpa/Config.h>
7 #include <fpa/Base/Events.h>
8
9 namespace fpa
10 {
11   namespace Base
12   {
13     /**
14      */
15     template< class _TFilter, class _TVertex, class _TOutput >
16     class Algorithm
17       : public _TFilter
18     {
19     public:
20       typedef Algorithm                       Self;
21       typedef _TFilter                        Superclass;
22       typedef itk::SmartPointer< Self >       Pointer;
23       typedef itk::SmartPointer< const Self > ConstPointer;
24
25       typedef _TVertex      TVertex;
26       typedef _TOutput      TOutput;
27       typedef unsigned long TFrontId;
28
29       // Different functions
30       typedef std::vector< TVertex >                      TNeighborhood;
31       typedef itk::FunctionBase< TVertex, TNeighborhood > TNeighborhoodFunction;
32
33       // Minigraph to represent collisions
34       typedef std::pair< _TVertex, bool >   TCollision;
35       typedef std::vector< TCollision >     TCollisionsRow;
36       typedef std::vector< TCollisionsRow > TCollisions;
37
38     protected:
39       struct _TQueueNode
40       {
41         TVertex  Vertex;
42         TVertex  Parent;
43         TOutput  Result;
44         TFrontId FrontId;
45         _TQueueNode( );
46         _TQueueNode( const TVertex& v );
47         _TQueueNode( const TVertex& v, const _TQueueNode& n );
48       };
49
50     public:
51       itkTypeMacro( Self, _TFilter );
52
53       fpa_Base_NewEvent( TStartEvent );
54       fpa_Base_NewEvent( TEndEvent );
55       fpa_Base_NewEvent( TStartLoopEvent );
56       fpa_Base_NewEvent( TEndLoopEvent );
57       fpa_Base_NewEventWithVertex( TPushEvent, TVertex );
58       fpa_Base_NewEventWithVertex( TPopEvent, TVertex );
59       fpa_Base_NewEventWithVertex( TMarkEvent, TVertex );
60
61       itkGetConstMacro( InitResult, _TOutput );
62       itkSetMacro( InitResult, _TOutput );
63
64       itkBooleanMacro( StopAtOneFront );
65       itkGetConstMacro( StopAtOneFront, bool );
66       itkSetMacro( StopAtOneFront, bool );
67
68       itkGetObjectMacro( NeighborhoodFunction, TNeighborhoodFunction );
69       itkSetObjectMacro( NeighborhoodFunction, TNeighborhoodFunction );
70
71     public:
72       void ClearSeeds( );
73       void AddSeed( const TVertex& seed, const TOutput& value );
74
75     protected:
76       Algorithm( );
77       virtual ~Algorithm( );
78
79       virtual void GenerateData( ) override;
80
81       // Particular methods
82       virtual bool _ContinueGenerateData( );
83       virtual void _Loop( );
84
85       virtual void _BeforeGenerateData( );
86       virtual void _AfterGenerateData( );
87       virtual void _BeforeLoop( );
88       virtual void _AfterLoop( );
89
90       virtual bool _ValidLoop( ) const;
91       virtual void _UpdateCollisions( const TVertex& a, const TVertex& b );
92
93       virtual void _InitMarks( ) = 0;
94       virtual void _InitResults( const TOutput& init_value ) = 0;
95       virtual bool _IsMarked( const _TVertex& v ) const = 0;
96       virtual void _Mark( const _TQueueNode& n ) = 0;
97       virtual TFrontId _GetMark( const _TVertex& v ) const = 0;
98       virtual void _UpdateResult( const _TQueueNode& n ) = 0;
99
100       virtual bool _UpdateValue( _TQueueNode& v, const _TQueueNode& p ) = 0;
101       virtual unsigned long _QueueSize( ) const = 0;
102       virtual void _QueueClear( ) = 0;
103       virtual void _QueuePush( const _TQueueNode& node ) = 0;
104       virtual _TQueueNode _QueuePop( ) = 0;
105
106     private:
107       // Purposely not implemented.
108       Algorithm( const Self& other );
109       Self& operator=( const Self& other );
110
111     protected:
112       _TOutput m_InitResult;
113       bool m_StopAtOneFront;
114       typename TNeighborhoodFunction::Pointer m_NeighborhoodFunction;
115       std::vector< _TQueueNode > m_Seeds;
116       TCollisions m_Collisions;
117       unsigned int m_NumberOfFronts;
118     };
119
120   } // ecaseman
121
122 } // ecaseman
123
124 #ifndef ITK_MANUAL_INSTANTIATION
125 #  include <fpa/Base/Algorithm.hxx>
126 #endif // ITK_MANUAL_INSTANTIATION
127
128 #endif // __fpa__Base__Algorithm__h__
129
130 // eof - $RCSfile$