1 #ifndef __fpa__Base__Algorithm__h__
2 #define __fpa__Base__Algorithm__h__
5 #include <itkFunctionBase.h>
6 #include <fpa/Config.h>
7 #include <fpa/Base/Events.h>
8 #include <fpa/Base/Functors/VertexCostFunctionBase.h>
16 template< class _TFilter, class _TVertex, class _TOutput >
21 typedef Algorithm Self;
22 typedef _TFilter Superclass;
23 typedef itk::SmartPointer< Self > Pointer;
24 typedef itk::SmartPointer< const Self > ConstPointer;
26 typedef _TVertex TVertex;
27 typedef _TOutput TOutput;
28 typedef unsigned long TFrontId;
30 // Different functions
31 typedef std::vector< TVertex > TNeighborhood;
32 typedef itk::FunctionBase< TVertex, TNeighborhood > TNeighborhoodFunction;
33 typedef itk::FunctionBase< TOutput, TOutput > TConversionFunction;
34 typedef fpa::Base::Functors::VertexCostFunctionBase< TVertex, TOutput > TVertexFunction;
36 // Minigraph to represent collisions
37 typedef std::pair< _TVertex, bool > TCollision;
38 typedef std::vector< TCollision > TCollisionsRow;
39 typedef std::vector< TCollisionsRow > TCollisions;
49 _TQueueNode( const TVertex& v );
50 _TQueueNode( const TVertex& v, const _TQueueNode& n );
54 itkTypeMacro( Self, _TFilter );
56 fpa_Base_NewEvent( TStartEvent );
57 fpa_Base_NewEvent( TEndEvent );
58 fpa_Base_NewEvent( TStartLoopEvent );
59 fpa_Base_NewEvent( TEndLoopEvent );
60 fpa_Base_NewEventWithVertex( TPushEvent, TVertex );
61 fpa_Base_NewEventWithVertex( TPopEvent, TVertex );
62 fpa_Base_NewEventWithVertex( TMarkEvent, TVertex );
64 itkGetConstMacro( InitResult, _TOutput );
65 itkSetMacro( InitResult, _TOutput );
67 itkBooleanMacro( StopAtOneFront );
68 itkGetConstMacro( StopAtOneFront, bool );
69 itkSetMacro( StopAtOneFront, bool );
71 itkGetObjectMacro( NeighborhoodFunction, TNeighborhoodFunction );
72 itkGetObjectMacro( ConversionFunction, TConversionFunction );
73 itkGetObjectMacro( VertexFunction, TVertexFunction );
75 itkGetConstObjectMacro( NeighborhoodFunction, TNeighborhoodFunction );
76 itkGetConstObjectMacro( ConversionFunction, TConversionFunction );
77 itkGetConstObjectMacro( VertexFunction, TVertexFunction );
79 itkSetObjectMacro( NeighborhoodFunction, TNeighborhoodFunction );
80 itkSetObjectMacro( ConversionFunction, TConversionFunction );
81 itkSetObjectMacro( VertexFunction, TVertexFunction );
85 void AddSeed( const TVertex& seed, const TOutput& value );
89 virtual ~Algorithm( );
91 virtual void GenerateData( ) override;
94 virtual bool _ContinueGenerateData( );
95 virtual void _Loop( );
97 virtual void _BeforeGenerateData( );
98 virtual void _AfterGenerateData( );
99 virtual void _BeforeLoop( );
100 virtual void _AfterLoop( );
102 virtual bool _ValidLoop( ) const;
103 virtual void _UpdateCollisions( const TVertex& a, const TVertex& b );
105 virtual _TOutput _GetInputValue( const _TQueueNode& v, const _TQueueNode& p );
107 virtual void _InitMarks( ) = 0;
108 virtual void _InitResults( const TOutput& init_value ) = 0;
109 virtual bool _IsMarked( const _TVertex& v ) const = 0;
110 virtual void _Mark( const _TQueueNode& n ) = 0;
111 virtual TFrontId _GetMark( const _TVertex& v ) const = 0;
112 virtual void _UpdateResult( const _TQueueNode& n ) = 0;
113 virtual TOutput _GetResult( const _TVertex& v ) const = 0;
114 virtual unsigned int _GetNumberOfDimensions( ) const = 0;
116 virtual bool _UpdateValue( _TQueueNode& v, const _TQueueNode& p ) = 0;
117 virtual unsigned long _QueueSize( ) const = 0;
118 virtual void _QueueClear( ) = 0;
119 virtual void _QueuePush( const _TQueueNode& node ) = 0;
120 virtual _TQueueNode _QueuePop( ) = 0;
123 // Purposely not implemented.
124 Algorithm( const Self& other );
125 Self& operator=( const Self& other );
128 _TOutput m_InitResult;
129 bool m_StopAtOneFront;
131 typename TNeighborhoodFunction::Pointer m_NeighborhoodFunction;
132 typename TConversionFunction::Pointer m_ConversionFunction;
133 typename TVertexFunction::Pointer m_VertexFunction;
135 std::vector< _TQueueNode > m_Seeds;
136 TCollisions m_Collisions;
137 unsigned int m_NumberOfFronts;
144 #ifndef ITK_MANUAL_INSTANTIATION
145 # include <fpa/Base/Algorithm.hxx>
146 #endif // ITK_MANUAL_INSTANTIATION
148 #endif // __fpa__Base__Algorithm__h__