-#ifndef __FPA__BASE__ALGORITHM__H__
-#define __FPA__BASE__ALGORITHM__H__
+#ifndef __fpa__Base__Algorithm__h__
+#define __fpa__Base__Algorithm__h__
-#include <map>
-#include <utility>
#include <vector>
+#include <itkFunctionBase.h>
+#include <fpa/Config.h>
#include <fpa/Base/Events.h>
-#include <fpa/Base/MinimumSpanningTree.h>
+#include <fpa/Base/Functors/VertexCostFunctionBase.h>
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 S Space type where vertices are.
- * @param VC Vertex lexicographical compare.
- * @param B Base class for this algorithm. It should be any itk-based
- * filter (itk::ProcessObject).
- *
*/
- template< class V, class C, class R, class S, class VC, class B >
+ template< class _TFilter, class _TVertex, class _TOutput >
class Algorithm
- : public B
+ : public _TFilter
{
public:
typedef Algorithm Self;
- typedef B Superclass;
+ typedef _TFilter Superclass;
typedef itk::SmartPointer< Self > Pointer;
typedef itk::SmartPointer< const Self > ConstPointer;
- typedef V TVertex;
- typedef C TValue;
- typedef R TResult;
- typedef S TSpace;
- typedef VC TVertexCompare;
+ typedef _TVertex TVertex;
+ typedef _TOutput TOutput;
+ typedef unsigned long TFrontId;
- fpa_Base_NewEvent( TStartEvent );
- fpa_Base_NewEvent( TStartLoopEvent );
- fpa_Base_NewEvent( TStartBacktrackingEvent );
- fpa_Base_NewEvent( TEndEvent );
- fpa_Base_NewEvent( TEndLoopEvent );
- fpa_Base_NewEvent( TEndBacktrackingEvent );
- fpa_Base_NewEventWithVertex( TAliveEvent, TVertex );
- fpa_Base_NewEventWithVertex( TFrontEvent, TVertex );
- fpa_Base_NewEventWithVertex( TFreezeEvent, TVertex );
- fpa_Base_NewEventWithVertex( TBacktrackingEvent, TVertex );
+ // Different functions
+ typedef std::vector< TVertex > TNeighborhood;
+ typedef itk::FunctionBase< TVertex, TNeighborhood > TNeighborhoodFunction;
+ typedef itk::FunctionBase< TOutput, TOutput > TConversionFunction;
+ typedef fpa::Base::Functors::VertexCostFunctionBase< TVertex, TOutput > TVertexFunction;
- protected:
- typedef std::vector< TVertex > _TVertices;
- typedef std::pair< TVertex, bool > _TCollision;
- typedef std::vector< _TCollision > _TCollisionsRow;
- typedef std::vector< _TCollisionsRow > _TCollisions;
-
- /**
- */
- enum _TNodeLabel
- {
- FarLabel = 0,
- FrontLabel,
- AliveLabel
- };
+ // Minigraph to represent collisions
+ typedef std::pair< _TVertex, bool > TCollision;
+ typedef std::vector< TCollision > TCollisionsRow;
+ typedef std::vector< TCollisionsRow > TCollisions;
- /**
- */
- class _TNode
+ protected:
+ struct _TQueueNode
{
- public:
- _TNode( );
- virtual ~_TNode( );
-
- public:
- TVertex Parent;
- TResult Result;
- short FrontId;
- char Label;
+ TVertex Vertex;
+ TVertex Parent;
+ TOutput Result;
+ TFrontId FrontId;
+ _TQueueNode( );
+ _TQueueNode( const TVertex& v );
+ _TQueueNode( const TVertex& v, const _TQueueNode& n );
};
- typedef std::map< TVertex, _TNode, TVertexCompare > _TNodes;
public:
- typedef
- fpa::Base::MinimumSpanningTree< V, _TCollisions, VC >
- TMinimumSpanningTree;
+ itkTypeMacro( Self, _TFilter );
- public:
- itkTypeMacro( Algorithm, B );
+ 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( ThrowEvents );
- itkBooleanMacro( StopAtOneFront );
+ itkGetConstMacro( InitResult, _TOutput );
+ itkSetMacro( InitResult, _TOutput );
- itkGetConstMacro( ThrowEvents, bool );
+ itkBooleanMacro( StopAtOneFront );
itkGetConstMacro( StopAtOneFront, bool );
-
- itkSetMacro( ThrowEvents, bool );
itkSetMacro( StopAtOneFront, bool );
- public:
- TMinimumSpanningTree* GetMinimumSpanningTree( );
- const TMinimumSpanningTree* GetMinimumSpanningTree( ) const;
- void GraftMinimumSpanningTree( itk::DataObject* obj );
+ itkGetObjectMacro( NeighborhoodFunction, TNeighborhoodFunction );
+ itkGetObjectMacro( ConversionFunction, TConversionFunction );
+ itkGetObjectMacro( VertexFunction, TVertexFunction );
+
+ itkGetConstObjectMacro( NeighborhoodFunction, TNeighborhoodFunction );
+ itkGetConstObjectMacro( ConversionFunction, TConversionFunction );
+ itkGetConstObjectMacro( VertexFunction, TVertexFunction );
- virtual void InvokeEvent( const itk::EventObject& e );
- virtual void InvokeEvent( const itk::EventObject& e ) const;
+ itkSetObjectMacro( NeighborhoodFunction, TNeighborhoodFunction );
+ itkSetObjectMacro( ConversionFunction, TConversionFunction );
+ itkSetObjectMacro( VertexFunction, TVertexFunction );
- void AddSeed( const TVertex& s, const TResult& r );
- const TVertex& GetSeed( const unsigned int& id ) const;
+ public:
void ClearSeeds( );
- unsigned long GetNumberOfSeeds( ) const;
+ void AddSeed( const TVertex& seed, const TOutput& value );
protected:
Algorithm( );
virtual ~Algorithm( );
- // Connection with itk's pipeline
- virtual void GenerateData( );
+ virtual void GenerateData( ) override;
- // Main loop algorithm
+ // Particular methods
+ virtual bool _ContinueGenerateData( );
virtual void _Loop( );
- // Supporting methods for loop
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 _TNode& n ) = 0;
-
- // Marks-related abstract methods
- virtual _TNode& _Node( const TVertex& v );
- virtual const _TNode& _Node( const TVertex& v ) const;
- virtual void _InitMarks( );
- virtual void _Mark( const TVertex& v, const _TNode& node );
-
- // Queue-related abstract methods
- virtual void _InitQueue( );
- virtual bool _IsQueueEmpty( ) const = 0;
- virtual void _QueuePush( const TVertex& v, const _TNode& n ) = 0;
- virtual void _QueuePop( TVertex& v, _TNode& n ) = 0;
+ virtual bool _ValidLoop( ) const;
+ virtual void _UpdateCollisions( const TVertex& a, const TVertex& b );
+
+ virtual _TOutput _GetInputValue( const _TQueueNode& v, const _TQueueNode& p );
+
+ 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 TOutput _GetResult( const _TVertex& v ) const = 0;
+ virtual unsigned int _GetNumberOfDimensions( ) const = 0;
+
+ virtual bool _UpdateValue( _TQueueNode& v, const _TQueueNode& p ) = 0;
+ virtual unsigned long _QueueSize( ) const = 0;
virtual void _QueueClear( ) = 0;
+ virtual void _QueuePush( const _TQueueNode& node ) = 0;
+ virtual _TQueueNode _QueuePop( ) = 0;
private:
- // Purposely not implemented
+ // Purposely not implemented.
Algorithm( const Self& other );
Self& operator=( const Self& other );
protected:
- bool m_ThrowEvents;
- bool m_StopAtOneFront;
- _TNodes m_Seeds;
- _TVertices m_SeedVertices;
- _TNodes m_Marks;
- _TCollisions m_Collisions;
-
- unsigned int m_MinimumSpanningTreeIndex;
+ _TOutput m_InitResult;
+ bool m_StopAtOneFront;
+
+ typename TNeighborhoodFunction::Pointer m_NeighborhoodFunction;
+ typename TConversionFunction::Pointer m_ConversionFunction;
+ typename TVertexFunction::Pointer m_VertexFunction;
+
+ std::vector< _TQueueNode > m_Seeds;
+ TCollisions m_Collisions;
+ unsigned int m_NumberOfFronts;
};
- } // ecapseman
+ } // ecaseman
-} // ecapseman
+} // ecaseman
-#include <fpa/Base/Algorithm.hxx>
+#ifndef ITK_MANUAL_INSTANTIATION
+# include <fpa/Base/Algorithm.hxx>
+#endif // ITK_MANUAL_INSTANTIATION
-#endif // __FPA__BASE__ALGORITHM__H__
+#endif // __fpa__Base__Algorithm__h__
// eof - $RCSfile$