X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2Ffpa%2FBase%2FAlgorithm.h;h=8750c5f7fb2360e2ac3afc44df84ec01d6414bb0;hb=ed2108383e59a45c6fa2e9259a27256a93d8aa6a;hp=662bdf1434273c7866abd12a18e073b074b0d08a;hpb=ea46079b5aef76c1782648ed23e70ea944649635;p=FrontAlgorithms.git diff --git a/lib/fpa/Base/Algorithm.h b/lib/fpa/Base/Algorithm.h index 662bdf1..8750c5f 100644 --- a/lib/fpa/Base/Algorithm.h +++ b/lib/fpa/Base/Algorithm.h @@ -1,10 +1,16 @@ +// ========================================================================= +// @author Leonardo Florez Valencia +// @email florez-l@javeriana.edu.co +// ========================================================================= + #ifndef __fpa__Base__Algorithm__h__ #define __fpa__Base__Algorithm__h__ -#include -#include #include -#include + +#include +#include +#include namespace fpa { @@ -12,112 +18,106 @@ namespace fpa { /** */ - template< class _TFilter, class _TVertex, class _TOutput > + template< class _TFilter, class _TMarksInterface, class _TSeedsInterface > class Algorithm - : public _TFilter + : public _TFilter, + public _TMarksInterface, + public _TSeedsInterface { public: typedef Algorithm Self; typedef _TFilter Superclass; + typedef _TMarksInterface TMarksInterface; + typedef _TSeedsInterface TSeedsInterface; typedef itk::SmartPointer< Self > Pointer; typedef itk::SmartPointer< const Self > ConstPointer; - typedef _TVertex TVertex; - typedef _TOutput TOutput; - typedef unsigned long TFrontId; - - // Different functions - typedef std::vector< TVertex > TNeighborhood; - typedef itk::FunctionBase< TVertex, TNeighborhood > TNeighborhoodFunction; + typedef typename _TSeedsInterface::TInputValue TInputValue; + typedef typename _TSeedsInterface::TOutputValue TOutputValue; + typedef typename _TSeedsInterface::TNode TNode; + typedef typename _TSeedsInterface::TNodes TNodes; + typedef typename _TSeedsInterface::TSeeds TSeeds; + typedef typename _TSeedsInterface::TVertex TVertex; - // Minigraph to represent collisions - typedef std::pair< _TVertex, bool > TCollision; - typedef std::vector< TCollision > TCollisionsRow; - typedef std::vector< TCollisionsRow > TCollisions; + typedef std::vector< TVertex > TNeighborhood; - protected: - struct _TQueueNode + /** + */ + class TEvent + : public itk::EventObject { - TVertex Vertex; - TVertex Parent; - TOutput Result; - TFrontId FrontId; - _TQueueNode( ); - _TQueueNode( const TVertex& v ); - _TQueueNode( const TVertex& v, const _TQueueNode& n ); + public: + typedef TEvent Self; + typedef itk::EventObject Superclass; + + public: + TEvent( ); + TEvent( const TVertex& v, unsigned long fid, bool intoq ); + virtual ~TEvent( ); + virtual const char* GetEventName( ) const override; + virtual bool CheckEvent( const itk::EventObject* e ) const override; + virtual itk::EventObject* MakeObject( ) const override; + + private: + // Purposely not implemented. + Self& operator=( const Self& other ); + + public: + TVertex Vertex; + unsigned long FrontId; + bool IntoQueue; }; public: - itkTypeMacro( Self, _TFilter ); + itkTypeMacro( fpa::Base::Algorithm, _TFilter ); - fpa_Base_NewEvent( TStartEvent ); - fpa_Base_NewEvent( TEndEvent ); - fpa_Base_NewEvent( TStartLoopEvent ); - fpa_Base_NewEvent( TEndLoopEvent ); - fpa_Base_NewEventWithVertex( TPushEvent, TVertex ); - fpa_Base_NewEventWithVertex( TPopEvent, TVertex ); - fpa_Base_NewEventWithVertex( TMarkEvent, TVertex ); + itkBooleanMacro( VisualDebug ); - itkGetConstMacro( InitResult, _TOutput ); - itkSetMacro( InitResult, _TOutput ); + itkGetConstMacro( InitValue, TOutputValue ); + itkGetConstMacro( VisualDebug, bool ); - itkBooleanMacro( StopAtOneFront ); - itkGetConstMacro( StopAtOneFront, bool ); - itkSetMacro( StopAtOneFront, bool ); - - itkGetObjectMacro( NeighborhoodFunction, TNeighborhoodFunction ); - itkSetObjectMacro( NeighborhoodFunction, TNeighborhoodFunction ); + itkSetMacro( InitValue, TOutputValue ); + itkSetMacro( VisualDebug, bool ); public: - void AddSeed( const TVertex& seed, const TOutput& value ); + virtual void InvokeEvent( const itk::EventObject& e ); + virtual void InvokeEvent( const itk::EventObject& e ) const; protected: Algorithm( ); virtual ~Algorithm( ); - virtual void GenerateData( ) fpa_OVERRIDE; - - // Particular methods - virtual void _Loop( ); - + virtual void GenerateData( ) override; virtual void _BeforeGenerateData( ); virtual void _AfterGenerateData( ); - virtual void _BeforeLoop( ); - virtual void _AfterLoop( ); - virtual bool _ValidLoop( ) const; - virtual void _UpdateCollisions( const TVertex& a, const TVertex& b ); + virtual void _QueueInit( ); - virtual void _InitMarks( ) = 0; - virtual void _InitResults( const TOutput& init_value ) = 0; - virtual bool _IsMarked( const _TVertex& v ) const = 0; - virtual void _Mark( const _TQueueNode& n ) = 0; - virtual TFrontId _GetMark( const _TVertex& v ) const = 0; - virtual void _UpdateResult( const _TQueueNode& n ) = 0; + virtual void _ConfigureOutput( const TOutputValue& v ) = 0; + virtual TNeighborhood _GetNeighbors( const TVertex& v ) const = 0; + virtual TInputValue _GetInputValue( const TVertex& v ) const = 0; + virtual TOutputValue _GetOutputValue( const TVertex& v ) const = 0; - virtual bool _UpdateValue( _TQueueNode& v, const _TQueueNode& p ) = 0; - virtual unsigned long _QueueSize( ) const = 0; + virtual TOutputValue _ComputeOutputValue( const TNode& n ) = 0; + virtual void _UpdateOutputValue( const TNode& n ) = 0; virtual void _QueueClear( ) = 0; - virtual void _QueuePush( const _TQueueNode& node ) = 0; - virtual _TQueueNode _QueuePop( ) = 0; + virtual void _QueuePush( const TNode& node ) = 0; + virtual unsigned long _QueueSize( ) const = 0; + virtual TNode _QueuePop( ) = 0; private: - // Purposely not implemented. + // Purposely not implemented Algorithm( const Self& other ); Self& operator=( const Self& other ); protected: - _TOutput m_InitResult; - bool m_StopAtOneFront; - typename TNeighborhoodFunction::Pointer m_NeighborhoodFunction; - std::vector< _TQueueNode > m_Seeds; - TCollisions m_Collisions; - unsigned int m_NumberOfFronts; + bool m_VisualDebug; + TOutputValue m_InitValue; }; - } // ecaseman + } // ecapseman -} // ecaseman +} // ecapseman #ifndef ITK_MANUAL_INSTANTIATION # include