X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2Ffpa%2FBase%2FAlgorithm.h;h=8750c5f7fb2360e2ac3afc44df84ec01d6414bb0;hb=ed2108383e59a45c6fa2e9259a27256a93d8aa6a;hp=c9b2e1aff5fb564306ab6369a3a905c6b7b98b69;hpb=b63dc485b7255d1ab70ff72096beafe13a71f1be;p=FrontAlgorithms.git diff --git a/lib/fpa/Base/Algorithm.h b/lib/fpa/Base/Algorithm.h index c9b2e1a..8750c5f 100644 --- a/lib/fpa/Base/Algorithm.h +++ b/lib/fpa/Base/Algorithm.h @@ -1,157 +1,128 @@ -#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 +#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 T Traits used for this algorithm */ - template< class T, class B > + template< class _TFilter, class _TMarksInterface, class _TSeedsInterface > class Algorithm - : public B + : public _TFilter, + public _TMarksInterface, + public _TSeedsInterface { public: - // Standard class typdedefs 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; - /// Templated types - typedef T TTraits; - typedef B TBaseFilter; - typedef typename T::TCost TCost; - typedef typename T::TResult TResult; - typedef typename T::TVertex TVertex; - typedef typename T::TVertexValue TVertexValue; - - protected: - typedef typename T::TFrontId _TFrontId; - typedef typename T::TNode _TNode; - typedef typename T::TNodes _TNodes; - typedef typename T::TVertexCmp _TVertexCmp; - - typedef std::map< TVertex, _TNode, _TVertexCmp > _TMarks; - - typedef std::pair< TVertex, bool > _TCollision; - typedef std::vector< _TCollision > _TCollisionSitesRow; - typedef std::vector< _TCollisionSitesRow > _TCollisionSites; - - public: - typedef BaseEvent< _TNode > TEvent; - typedef FrontEvent< _TNode > TFrontEvent; - typedef MarkEvent< _TNode > TMarkEvent; - typedef CollisionEvent< _TNode > TCollisionEvent; - typedef EndEvent< _TNode > TEndEvent; - typedef BacktrackingEvent< TVertex > TBacktrackingEvent; - typedef EndBacktrackingEvent< TVertex > TEndBacktrackingEvent; + 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; + + typedef std::vector< TVertex > TNeighborhood; + + /** + */ + class TEvent + : public itk::EventObject + { + 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( Algorithm, itkProcessObject ); + itkTypeMacro( fpa::Base::Algorithm, _TFilter ); - itkBooleanMacro( StopAtOneFront ); - itkBooleanMacro( ThrowEvents ); + itkBooleanMacro( VisualDebug ); - itkGetConstMacro( StopAtOneFront, bool ); - itkGetConstMacro( ThrowEvents, bool ); + itkGetConstMacro( InitValue, TOutputValue ); + itkGetConstMacro( VisualDebug, bool ); - itkSetMacro( StopAtOneFront, bool ); - itkSetMacro( ThrowEvents, bool ); + itkSetMacro( InitValue, TOutputValue ); + itkSetMacro( VisualDebug, bool ); public: virtual void InvokeEvent( const itk::EventObject& e ); virtual void InvokeEvent( const itk::EventObject& e ) const; - /// Seeds manipulation - void AddSeed( const TVertex& s, const TResult& v ); - const TVertex& GetSeed( const unsigned long& i ) const; - void ClearSeeds( ); - unsigned long GetNumberOfSeeds( ) const; - protected: Algorithm( ); virtual ~Algorithm( ); - /// itk::ProcessObject - virtual void GenerateData( ); - - /// Base interface - virtual void _BeforeMainLoop ( ); - virtual void _AfterMainLoop ( ); - virtual void _BeforeLoop ( ); - virtual void _AfterLoop ( ); - virtual void _Loop ( ); - virtual bool _CheckCollisions ( const _TNode& a, const _TNode& b ); - virtual bool _CheckStopCondition ( ); - virtual bool _UpdateResult ( _TNode& n ); - - /// Marks management - virtual void _InitializeMarks ( ); - virtual bool _IsMarked ( const TVertex& v ) const; - virtual _TFrontId _FrontId ( const TVertex& v ) const; - virtual TVertex _Parent ( const TVertex& v ) const; - virtual void _Mark ( const _TNode& n ); - - /// Pure virtual interface: vertices - virtual unsigned long _NumberOfVertices ( ) const = 0; - virtual TVertexValue _Value ( const TVertex& v ) const = 0; - virtual TResult _Result ( const TVertex& v ) const = 0; - - /// Pure virtual interface: edges - virtual double _Norm ( const TVertex& a, const TVertex& b ) const = 0; - virtual bool _Edge ( const TVertex& a, const TVertex& b ) const = 0; - virtual TCost _Cost ( const TVertex& a, const TVertex& b ) const = 0; - - /// Pure virtual interface: neighborhood - virtual void _Neighs ( const _TNode& n, _TNodes& N ) const = 0; - virtual bool _UpdateNeigh ( _TNode& nn, const _TNode& n ) = 0; - virtual void _NeighsInDim ( const _TNode& n, - const unsigned int& d, - _TNodes& N ) = 0; - - /// Pure virtual interface: queue - virtual void _InitializeQueue ( ) = 0; - virtual bool _IsQueueEmpty ( ) const = 0; - virtual void _QueuePush ( const _TNode& n ) = 0; - virtual _TNode _QueuePop ( ) = 0; - virtual void _QueueClear ( ) = 0; - - /// Pure virtual interface: results - virtual void _InitializeResults ( ) = 0; + virtual void GenerateData( ) override; + virtual void _BeforeGenerateData( ); + virtual void _AfterGenerateData( ); + + 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 - Algorithm( const Self& ); - void operator=( const Self& ); + Algorithm( const Self& other ); + Self& operator=( const Self& other ); protected: - bool m_StopAtOneFront; - bool m_ThrowEvents; - - _TNodes m_Seeds; - _TMarks m_Marks; - - _TCollisionSites m_CollisionSites; + 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$