]> 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 AddSeed( const TVertex& seed, const TOutput& value );
73
74     protected:
75       Algorithm( );
76       virtual ~Algorithm( );
77
78       virtual void GenerateData( ) override;
79
80       // Particular methods
81       virtual bool _ContinueGenerateData( );
82       virtual void _Loop( );
83
84       virtual void _BeforeGenerateData( );
85       virtual void _AfterGenerateData( );
86       virtual void _BeforeLoop( );
87       virtual void _AfterLoop( );
88
89       virtual bool _ValidLoop( ) const;
90       virtual void _UpdateCollisions( const TVertex& a, const TVertex& b );
91
92       virtual void _InitMarks( ) = 0;
93       virtual void _InitResults( const TOutput& init_value ) = 0;
94       virtual bool _IsMarked( const _TVertex& v ) const = 0;
95       virtual void _Mark( const _TQueueNode& n ) = 0;
96       virtual TFrontId _GetMark( const _TVertex& v ) const = 0;
97       virtual void _UpdateResult( const _TQueueNode& n ) = 0;
98
99       virtual bool _UpdateValue( _TQueueNode& v, const _TQueueNode& p ) = 0;
100       virtual unsigned long _QueueSize( ) const = 0;
101       virtual void _QueueClear( ) = 0;
102       virtual void _QueuePush( const _TQueueNode& node ) = 0;
103       virtual _TQueueNode _QueuePop( ) = 0;
104
105     private:
106       // Purposely not implemented.
107       Algorithm( const Self& other );
108       Self& operator=( const Self& other );
109
110     protected:
111       _TOutput m_InitResult;
112       bool m_StopAtOneFront;
113       typename TNeighborhoodFunction::Pointer m_NeighborhoodFunction;
114       std::vector< _TQueueNode > m_Seeds;
115       TCollisions m_Collisions;
116       unsigned int m_NumberOfFronts;
117     };
118
119   } // ecaseman
120
121 } // ecaseman
122
123 #ifndef ITK_MANUAL_INSTANTIATION
124 #  include <fpa/Base/Algorithm.hxx>
125 #endif // ITK_MANUAL_INSTANTIATION
126
127 #endif // __fpa__Base__Algorithm__h__
128
129 // eof - $RCSfile$