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>
15 template< class _TFilter, class _TVertex, class _TOutput >
20 typedef Algorithm Self;
21 typedef _TFilter Superclass;
22 typedef itk::SmartPointer< Self > Pointer;
23 typedef itk::SmartPointer< const Self > ConstPointer;
25 typedef _TVertex TVertex;
26 typedef _TOutput TOutput;
27 typedef unsigned long TFrontId;
29 // Different functions
30 typedef std::vector< TVertex > TNeighborhood;
31 typedef itk::FunctionBase< TVertex, TNeighborhood > TNeighborhoodFunction;
33 // Minigraph to represent collisions
34 typedef std::pair< _TVertex, bool > TCollision;
35 typedef std::vector< TCollision > TCollisionsRow;
36 typedef std::vector< TCollisionsRow > TCollisions;
46 _TQueueNode( const TVertex& v );
47 _TQueueNode( const TVertex& v, const _TQueueNode& n );
51 itkTypeMacro( Self, _TFilter );
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 );
61 itkGetConstMacro( InitResult, _TOutput );
62 itkSetMacro( InitResult, _TOutput );
64 itkBooleanMacro( StopAtOneFront );
65 itkGetConstMacro( StopAtOneFront, bool );
66 itkSetMacro( StopAtOneFront, bool );
68 itkGetObjectMacro( NeighborhoodFunction, TNeighborhoodFunction );
69 itkSetObjectMacro( NeighborhoodFunction, TNeighborhoodFunction );
72 void AddSeed( const TVertex& seed, const TOutput& value );
76 virtual ~Algorithm( );
78 virtual void GenerateData( ) fpa_OVERRIDE;
81 virtual void _Loop( );
83 virtual void _BeforeGenerateData( );
84 virtual void _AfterGenerateData( );
85 virtual void _BeforeLoop( );
86 virtual void _AfterLoop( );
88 virtual bool _ValidLoop( ) const;
89 virtual void _UpdateCollisions( const TVertex& a, const TVertex& b );
91 virtual void _InitMarks( ) = 0;
92 virtual void _InitResults( const TOutput& init_value ) = 0;
93 virtual bool _IsMarked( const _TVertex& v ) const = 0;
94 virtual void _Mark( const _TQueueNode& n ) = 0;
95 virtual TFrontId _GetMark( const _TVertex& v ) const = 0;
96 virtual void _UpdateResult( const _TQueueNode& n ) = 0;
98 virtual bool _UpdateValue( _TQueueNode& v, const _TQueueNode& p ) = 0;
99 virtual unsigned long _QueueSize( ) const = 0;
100 virtual void _QueueClear( ) = 0;
101 virtual void _QueuePush( const _TQueueNode& node ) = 0;
102 virtual _TQueueNode _QueuePop( ) = 0;
105 // Purposely not implemented.
106 Algorithm( const Self& other );
107 Self& operator=( const Self& other );
110 _TOutput m_InitResult;
111 bool m_StopAtOneFront;
112 typename TNeighborhoodFunction::Pointer m_NeighborhoodFunction;
113 std::vector< _TQueueNode > m_Seeds;
114 TCollisions m_Collisions;
115 unsigned int m_NumberOfFronts;
122 #ifndef ITK_MANUAL_INSTANTIATION
123 # include <fpa/Base/Algorithm.hxx>
124 #endif // ITK_MANUAL_INSTANTIATION
126 #endif // __fpa__Base__Algorithm__h__