+// =========================================================================
+// @author Leonardo Florez Valencia
+// @email florez-l@javeriana.edu.co
+// =========================================================================
+
#ifndef __fpa__Base__Algorithm__h__
#define __fpa__Base__Algorithm__h__
-#include <vector>
-#include <itkFunctionBase.h>
#include <fpa/Config.h>
-#include <fpa/Base/Events.h>
+
+#include <itkObject.h>
+#include <itkEventObject.h>
namespace fpa
{
{
/**
*/
- template< class _TFilter, class _TVertex, class _TOutput >
+ template< class _TTraits >
class Algorithm
- : public _TFilter
+ : public _TTraits::TFilter,
+ public _TTraits::TMarksInterface,
+ public _TTraits::TSeedsInterface
{
public:
- typedef Algorithm Self;
- typedef _TFilter Superclass;
- 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;
-
- // Minigraph to represent collisions
- typedef std::pair< _TVertex, bool > TCollision;
- typedef std::vector< TCollision > TCollisionsRow;
- typedef std::vector< TCollisionsRow > TCollisions;
-
- protected:
- struct _TQueueNode
+ typedef _TTraits TTraits;
+ typedef typename TTraits::TFilter Superclass;
+ typedef typename TTraits::TMarksInterface TMarksInterface;
+ typedef typename TTraits::TSeedsInterface TSeedsInterface;
+ typedef Algorithm Self;
+ typedef itk::SmartPointer< Self > Pointer;
+ typedef itk::SmartPointer< const Self > ConstPointer;
+
+ typedef typename TTraits::TInputValue TInputValue;
+ typedef typename TTraits::TOutputValue TOutputValue;
+ typedef typename TTraits::TNeighborhood TNeighborhood;
+ typedef typename TTraits::TNode TNode;
+ typedef typename TTraits::TNodes TNodes;
+ typedef typename TTraits::TSeeds TSeeds;
+ typedef typename TTraits::TVertex TVertex;
+
+ /**
+ */
+ 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 );
-
- 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 );
+ itkTypeMacro( fpa::Base::Algorithm, _TFilter );
- itkGetConstMacro( InitResult, _TOutput );
- itkSetMacro( InitResult, _TOutput );
+ itkBooleanMacro( VisualDebug );
- itkBooleanMacro( StopAtOneFront );
- itkGetConstMacro( StopAtOneFront, bool );
- itkSetMacro( StopAtOneFront, bool );
+ itkGetConstMacro( InitValue, TOutputValue );
+ itkGetConstMacro( VisualDebug, 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 void _FinishOneLoop( );
- 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 void _ComputeOutputValue( TNode& n ) = 0;
+ virtual void _UpdateOutputValue( 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 <fpa/Base/Algorithm.hxx>