X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2Ffpa%2FImage%2FAlgorithm.h;h=2fd40bc1c242cef832e920189a844a63263a43dc;hb=56b8bb48cc05a297a3faa264f8f2a88de21ef203;hp=e23a1084c3a585826adb7f9e54ac44bf233f6767;hpb=d3bb16bf060b7249a9ed1a49e6b118ca9394a22a;p=FrontAlgorithms.git diff --git a/lib/fpa/Image/Algorithm.h b/lib/fpa/Image/Algorithm.h index e23a108..2fd40bc 100644 --- a/lib/fpa/Image/Algorithm.h +++ b/lib/fpa/Image/Algorithm.h @@ -1,176 +1,95 @@ #ifndef __FPA__IMAGE__ALGORITHM__H__ #define __FPA__IMAGE__ALGORITHM__H__ +#include #include -#include +#include namespace fpa { namespace Image { - namespace Functors - { - /** - */ - template< class VV, class C > - class CastVertexValueToCost - : public itk::FunctionBase< VV, C > - { - public: - // Type-related and pointers - typedef CastVertexValueToCost Self; - typedef itk::FunctionBase< VV, C > Superclass; - typedef itk::SmartPointer< Self > Pointer; - typedef itk::SmartPointer< const Self > ConstPointer; - - public: - itkNewMacro( Self ); - itkTypeMacro( CastVertexValueToCost, itkFunctionBase ); - - public: - virtual C Evaluate( const VV& v ) const - { return( C( v ) ); } - - protected: - CastVertexValueToCost( ) - : Superclass( ) - { } - virtual ~CastVertexValueToCost( ) - { } - - private: - // Purposely not implemented - CastVertexValueToCost( const Self& ); - void operator=( const Self& ); - }; - - /** - */ - template< class VV, class C > - class CastVertexValueToConstantCost - : public itk::FunctionBase< VV, C > - { - public: - // Type-related and pointers - typedef CastVertexValueToConstantCost Self; - typedef itk::FunctionBase< VV, C > Superclass; - typedef itk::SmartPointer< Self > Pointer; - typedef itk::SmartPointer< const Self > ConstPointer; - - public: - itkNewMacro( Self ); - itkTypeMacro( CastVertexValueToConstantCost, itkFunctionBase ); - - public: - virtual C Evaluate( const VV& v ) const - { return( C( 1 ) ); } - - protected: - CastVertexValueToConstantCost( ) - : Superclass( ) - { } - virtual ~CastVertexValueToConstantCost( ) - { } - - private: - // Purposely not implemented - CastVertexValueToConstantCost( const Self& ); - void operator=( const Self& ); - }; - - } // ecapseman - /** - * A generic front propagation algorithm were vertices are image pixels. - * - * @param I Input image type - * @param A Base algorithm (RegionGrow, Dijkstra or FastMarching) */ - template< class I, class A, class CC > + template< class _TInputImage, class _TOutputImage > class Algorithm - : public A + : public fpa::Base::Algorithm< typename _TInputImage::IndexType, typename _TOutputImage::PixelType, itk::ImageToImageFilter< _TInputImage, _TOutputImage >, typename _TInputImage::IndexType::LexicographicCompare > { public: - /// Standard class typdedefs + typedef fpa::Base::Algorithm< typename _TInputImage::IndexType, typename _TOutputImage::PixelType, itk::ImageToImageFilter< _TInputImage, _TOutputImage >, typename _TInputImage::IndexType::LexicographicCompare > Superclass; typedef Algorithm Self; - typedef A Superclass; typedef itk::SmartPointer< Self > Pointer; typedef itk::SmartPointer< const Self > ConstPointer; - /// Template input values - typedef I TInputImage; - typedef A TBaseAlgorithm; - typedef CC TCostConversionFunction; - - typedef typename A::TTraits TTraits; - typedef typename TTraits::TCost TCost; - typedef typename TTraits::TResult TResult; - typedef typename TTraits::TVertex TVertex; - typedef typename TTraits::TVertexValue TVertexValue; - - typedef itk::Image< TResult, I::ImageDimension > TOutputImage; - - protected: - typedef typename TTraits::TFrontId _TFrontId; - typedef typename TTraits::TNode _TNode; - typedef typename TTraits::TNodes _TNodes; - - private: - typedef itk::Image< bool, I::ImageDimension > _TMarks; - typedef itk::Image< _TFrontId, I::ImageDimension > _TFrontsIds; - typedef itk::Image< TVertex, I::ImageDimension > _TParents; + // Input types + typedef _TInputImage TInputImage; + typedef _TOutputImage TOutputImage; + itkConceptMacro( + ImagesSameDimension, + ( + itk::Concept:: + SameDimension< + TInputImage::ImageDimension, + TOutputImage::ImageDimension + > + ) + ); + + // Template arguments + typedef typename Superclass::TVertex TVertex; + typedef typename Superclass::TScalar TScalar; + typedef typename Superclass::TFilter TFilter; + typedef typename Superclass::TVertexCompare TVertexCompare; + typedef typename Superclass::TFrontId TFrontId; + typedef typename Superclass::TCollision TCollision; + typedef typename Superclass::TCollisionsRow TCollisionsRow; + typedef typename Superclass::TCollisions TCollisions; + typedef typename Superclass::TNodeLabel TNodeLabel; + typedef typename Superclass::TNode TNode; + typedef typename Superclass::TNodes TNodes; + typedef typename Superclass::TVertices TVertices; + + typedef itk::Image< TFrontId, TInputImage::ImageDimension > TMarkImage; public: - itkTypeMacro( Algorithm, TAlgorithm ); - - /// Set/Get - itkGetConstMacro( NeighborhoodOrder, unsigned int ); - itkGetConstObjectMacro( CostConversion, TCostConversionFunction ); - itkGetObjectMacro( CostConversion, TCostConversionFunction ); + itkTypeMacro( Algorithm, _TFilter ); - itkSetMacro( NeighborhoodOrder, unsigned int ); - itkSetObjectMacro( CostConversion, TCostConversionFunction ); + itkGetConstMacro( NeighborhoodOrder, unsigned short ); + itkSetMacro( NeighborhoodOrder, unsigned short ); protected: + // Methods to extend itk-imaged architecture Algorithm( ); virtual ~Algorithm( ); - /// Base interface - virtual bool _UpdateResult( _TNode& n ); - - /// Pure virtual interface: vertices - virtual unsigned long _NumberOfVertices ( ) const; - virtual TVertexValue _Value ( const TVertex& v ) const; - virtual TResult _Result ( const TVertex& v ) const; - - /// Pure virtual interface: edges - virtual double _Norm ( const TVertex& a, const TVertex& b ) const; - virtual bool _Edge ( const TVertex& a, const TVertex& b ) const; - virtual TCost _Cost ( const TVertex& a, const TVertex& b ) const; - - /// Pure virtual interface: neighborhood - virtual void _Neighs ( const _TNode& n, _TNodes& N ) const; - virtual void _NeighsInDim ( const _TNode& n, - const unsigned int& d, - _TNodes& N ); - - /// Pure virtual interface: results - virtual void _InitializeResults ( ); + // Front propagation methods to be overloaded + virtual void _BeforeGenerateData( ) fpa_OVERRIDE; + virtual void _InitMarks( ) fpa_OVERRIDE; + virtual void _InitResults( ) fpa_OVERRIDE; + virtual void _DeallocateAuxiliary( ) fpa_OVERRIDE; + virtual TFrontId _GetMark( const TVertex& v ) fpa_OVERRIDE; + virtual void _Visit( const TNode& n ) fpa_OVERRIDE; + virtual TVertices _GetNeighborhood( + const TVertex& v + ) const fpa_OVERRIDE; private: - Algorithm( const Self& ); // Not impl. - void operator=( const Self& ); // Not impl. + // Purposely not implemented + Algorithm( const Self& other ); + Self& operator=( const Self& other ); protected: - unsigned int m_NeighborhoodOrder; - typename TCostConversionFunction::Pointer m_CostConversion; + unsigned short m_NeighborhoodOrder; + typename TMarkImage::Pointer m_Marks; }; } // ecapseman } // ecapseman -#include +#ifndef ITK_MANUAL_INSTANTIATION +# include +#endif #endif // __FPA__IMAGE__ALGORITHM__H__