X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2Ffpa%2FBase%2FAlgorithm.h;h=8750c5f7fb2360e2ac3afc44df84ec01d6414bb0;hb=ed2108383e59a45c6fa2e9259a27256a93d8aa6a;hp=35c6a378d09d3ede36655be646d39abfa616659b;hpb=b70a564ee2d7bc180b77a05c37ab431ab9c393e7;p=FrontAlgorithms.git diff --git a/lib/fpa/Base/Algorithm.h b/lib/fpa/Base/Algorithm.h index 35c6a37..8750c5f 100644 --- a/lib/fpa/Base/Algorithm.h +++ b/lib/fpa/Base/Algorithm.h @@ -1,152 +1,109 @@ -#ifndef __FPA__BASE__ALGORITHM__H__ -#define __FPA__BASE__ALGORITHM__H__ +// ========================================================================= +// @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 namespace fpa { namespace Base { /** - * Base front propagation algorithm. From a series of start seeds with - * costs, a priority queue is filled and emptied updating costs. Each - * vertex could be marked as "visited", "in the front", "not yet there" - * or "freezed". - * - * @param V Vertex type. - * @param C Vertex value type. - * @param R Result value type. - * @param B Base class for this algorithm. It should be any itk-based - * filter (itk::ProcessObject). - * */ - template< class V, class C, class R, class B > + template< class _TFilter, class _TMarksInterface, class _TSeedsInterface > class Algorithm - : public B + : public _TFilter, + public _TMarksInterface, + public _TSeedsInterface { public: typedef Algorithm Self; - typedef B Superclass; + typedef _TFilter Superclass; + typedef _TMarksInterface TMarksInterface; + typedef _TSeedsInterface TSeedsInterface; typedef itk::SmartPointer< Self > Pointer; typedef itk::SmartPointer< const Self > ConstPointer; - typedef V TVertex; - typedef C TValue; - typedef R TResult; + 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; - fpa_Base_NewEvent( TStartEvent ); - fpa_Base_NewEvent( TStartLoopEvent ); - fpa_Base_NewEvent( TEndEvent ); - fpa_Base_NewEvent( TEndLoopEvent ); - fpa_Base_NewEventWithVertex( TAliveEvent, TVertex ); - fpa_Base_NewEventWithVertex( TFrontEvent, TVertex ); - fpa_Base_NewEventWithVertex( TFreezeEvent, TVertex ); - - protected: - typedef std::vector< TVertex > _TVertices; - typedef std::pair< TVertex, bool > _TCollision; - typedef std::vector< _TCollision > _TCollisionsRow; - typedef std::vector< _TCollisionsRow > _TCollisions; + typedef std::vector< TVertex > TNeighborhood; /** */ - enum _TNodeLabel + class TEvent + : public itk::EventObject { - FarLabel = 0, - FrontLabel, - AliveLabel - }; + public: + typedef TEvent Self; + typedef itk::EventObject Superclass; - /** - */ - class _TNode - { public: - _TNode( ); - virtual ~_TNode( ); + 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; - TVertex Parent; - TResult Result; - long FrontId; - _TNodeLabel Label; + TVertex Vertex; + unsigned long FrontId; + bool IntoQueue; }; - typedef std::vector< _TNode > _TNodes; public: - itkTypeMacro( Algorithm, B ); + itkTypeMacro( fpa::Base::Algorithm, _TFilter ); - itkBooleanMacro( ThrowEvents ); - itkBooleanMacro( StopAtOneFront ); + itkBooleanMacro( VisualDebug ); - itkGetConstMacro( ThrowEvents, bool ); - itkGetConstMacro( StopAtOneFront, bool ); + itkGetConstMacro( InitValue, TOutputValue ); + itkGetConstMacro( VisualDebug, bool ); - itkSetMacro( ThrowEvents, bool ); - itkSetMacro( StopAtOneFront, bool ); + itkSetMacro( InitValue, TOutputValue ); + itkSetMacro( VisualDebug, bool ); public: virtual void InvokeEvent( const itk::EventObject& e ); virtual void InvokeEvent( const itk::EventObject& e ) const; - void AddSeed( const TVertex& s, const TResult& r ); - const TVertex& GetSeed( const unsigned int& id ) const; - void ClearSeeds( ); - unsigned long GetNumberOfSeeds( ) const; - protected: Algorithm( ); virtual ~Algorithm( ); - // Connection with itk's pipeline - virtual void GenerateData( ); - - // Main loop algorithm - virtual void _Loop( ); - - // Supporting methods for loop + virtual void GenerateData( ) override; virtual void _BeforeGenerateData( ); virtual void _AfterGenerateData( ); - virtual void _BeforeLoop( ); - virtual void _AfterLoop( ); - - // Methods to control forced stops - virtual bool _UpdateCollisions( const TVertex& a, const TVertex& b ); - virtual bool _NeedToStop( ) const; - - // Graph-related abstract methods - virtual unsigned long _NumberOfVertices( ) const = 0; - virtual const TValue& _VertexValue( const TVertex& v ) const = 0; - virtual double _Distance( - const TVertex& a, const TVertex& b - ) const = 0; - virtual bool _HasEdge( const TVertex& a, const TVertex& b ) const = 0; - virtual void _Neighborhood( - _TVertices& neighborhood, const TVertex& v - ) const = 0; - - // Results-related abstract methods - virtual bool _ComputeNeighborResult( - TResult& result, const TVertex& neighbor, const TVertex& parent - ) const = 0; - virtual void _InitResults( ) = 0; - virtual const TResult& _Result( const TVertex& v ) const = 0; - virtual void _SetResult( const TVertex& v, const TResult& r ) = 0; - - // Marks-related abstract methods - virtual const _TNode& _Node( const TVertex& v ) const = 0; - virtual void _InitMarks( ) = 0; - virtual void _Mark( const _TNode& node ) = 0; - - // Queue-related abstract methods - virtual void _InitQueue( ); - virtual bool _IsQueueEmpty( ) const = 0; - virtual void _QueuePush( const _TNode& n ) = 0; - virtual _TNode _QueuePop( ) = 0; + + virtual void _QueueInit( ); + + 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 TOutputValue _ComputeOutputValue( const TNode& n ) = 0; + virtual void _UpdateOutputValue( const TNode& n ) = 0; virtual void _QueueClear( ) = 0; + virtual void _QueuePush( const TNode& node ) = 0; + virtual unsigned long _QueueSize( ) const = 0; + virtual TNode _QueuePop( ) = 0; private: // Purposely not implemented @@ -154,18 +111,18 @@ namespace fpa Self& operator=( const Self& other ); protected: - bool m_ThrowEvents; - bool m_StopAtOneFront; - _TNodes m_Seeds; - _TCollisions m_Collisions; + bool m_VisualDebug; + TOutputValue m_InitValue; }; } // ecapseman } // ecapseman -#include +#ifndef ITK_MANUAL_INSTANTIATION +# include +#endif // ITK_MANUAL_INSTANTIATION -#endif // __FPA__BASE__ALGORITHM__H__ +#endif // __fpa__Base__Algorithm__h__ // eof - $RCSfile$