]> Creatis software - FrontAlgorithms.git/blobdiff - lib/fpa/Image/Dijkstra.h
...
[FrontAlgorithms.git] / lib / fpa / Image / Dijkstra.h
index 48d7a79b8bf026385a88a35c176033c48439e284..6882bfea2c245c2fb76031361ed0f62e4d66f81d 100644 (file)
-#ifndef __FPA__IMAGE__DIJKSTRA__H__
-#define __FPA__IMAGE__DIJKSTRA__H__
+// =========================================================================
+// @author Leonardo Florez Valencia
+// @email florez-l@javeriana.edu.co
+// =========================================================================
+
+#ifndef __fpa__Image__Dijkstra__h__
+#define __fpa__Image__Dijkstra__h__
 
-#include <itkFunctionBase.h>
-#include <itkImageToImageFilter.h>
 #include <fpa/Base/Dijkstra.h>
+#include <fpa/Base/MarksInterfaceWithCollisions.h>
+#include <fpa/Base/SeedsInterface.h>
 #include <fpa/Image/Algorithm.h>
-#include <fpa/Image/Functors/ImageCostFunction.h>
+#include <fpa/Image/MinimumSpanningTree.h>
+#include <fpa/Image/Functors/Dijkstra/Identity.h>
 
 namespace fpa
 {
   namespace Image
   {
     /**
-     * @param I Input image type
-     * @param O Output image type
      */
-    template< class I, class O >
+    template< class _TInputImage, class _TOutputImage, class _TFrontId = unsigned char >
     class Dijkstra
-      : public Algorithm< I, O, fpa::Base::Dijkstra< typename I::IndexType, typename I::PixelType, typename O::PixelType, itk::Functor::IndexLexicographicCompare< I::ImageDimension >, itk::ImageToImageFilter< I, O > > >
+      : public fpa::Base::Dijkstra< fpa::Image::Algorithm< _TInputImage, _TOutputImage, fpa::Base::MarksInterfaceWithCollisions< typename _TInputImage::IndexType >, fpa::Base::SeedsInterface< typename _TInputImage::IndexType, typename _TInputImage::PointType, typename _TInputImage::PixelType, typename _TOutputImage::PixelType, _TFrontId, typename _TInputImage::IndexType::LexicographicCompare > >, fpa::Image::MinimumSpanningTree< _TInputImage::ImageDimension > >
     {
     public:
-      typedef fpa::Base::Dijkstra< typename I::IndexType, typename I::PixelType, typename O::PixelType, itk::Functor::IndexLexicographicCompare< I::ImageDimension >, itk::ImageToImageFilter< I, O > > TBaseAlgorithm;
-
-      typedef Dijkstra                          Self;
-      typedef Algorithm< I, O, TBaseAlgorithm > Superclass;
-      typedef itk::SmartPointer< Self >         Pointer;
-      typedef itk::SmartPointer< const Self >   ConstPointer;
-
-      typedef typename Superclass::TInputImage  TInputImage;
-      typedef typename Superclass::TOutputImage TOutputImage;
-      typedef typename Superclass::TVertex      TVertex;
-      typedef typename Superclass::TValue       TValue;
-      typedef typename Superclass::TResult      TResult;
-
-      typedef typename Superclass::TStartEvent     TStartEvent;
-      typedef typename Superclass::TStartLoopEvent TStartLoopEvent;
-      typedef typename Superclass::TEndEvent       TEndEvent;
-      typedef typename Superclass::TEndLoopEvent   TEndLoopEvent;
-      typedef typename Superclass::TAliveEvent     TAliveEvent;
-      typedef typename Superclass::TFrontEvent     TFrontEvent;
-      typedef typename Superclass::TFreezeEvent    TFreezeEvent;
-
-      typedef typename Superclass::TStartBacktrackingEvent TStartBacktrackingEvent;
-      typedef typename Superclass::TEndBacktrackingEvent TEndBacktrackingEvent;
-      typedef typename Superclass::TBacktrackingEvent TBacktrackingEvent;
-
-      typedef fpa::Image::Functors::ImageCostFunction< TInputImage, TResult > TCostFunction;
-      typedef itk::FunctionBase< TResult, TResult > TConversionFunction;
+      typedef _TInputImage  TInputImage;
+      typedef _TOutputImage TOutputImage;
+      typedef _TFrontId     TFrontId;
 
-    protected:
-      typedef typename Superclass::_TVertices      _TVertices;
-      typedef typename Superclass::_TCollision     _TCollision;
-      typedef typename Superclass::_TCollisionsRow _TCollisionsRow;
-      typedef typename Superclass::_TCollisions    _TCollisions;
-      typedef typename Superclass::_TNode          _TNode;
-      typedef typename Superclass::_TNodes         _TNodes;
+      typedef typename TInputImage::IndexType        TVertex;
+      typedef typename TInputImage::PointType        TPoint;
+      typedef typename TVertex::LexicographicCompare TVertexCompare;
+      typedef typename TInputImage::PixelType        TInputValue;
+      typedef typename TOutputImage::PixelType       TOutputValue;
 
-    public:
-      itkNewMacro( Self );
-      itkTypeMacro( Dijkstra, Algorithm );
+      typedef fpa::Base::MarksInterfaceWithCollisions< TVertex > TMarksInterface;
+      typedef fpa::Base::SeedsInterface< TVertex, TPoint, TInputValue, TOutputValue, TFrontId, TVertexCompare > TSeedsInterface;
+      typedef fpa::Image::Algorithm< TInputImage, TOutputImage, TMarksInterface, TSeedsInterface > TAlgorithm;
+      typedef fpa::Image::MinimumSpanningTree< TInputImage::ImageDimension > TMST;
 
-      itkGetObjectMacro( CostFunction, TCostFunction );
-      itkGetObjectMacro( ConversionFunction, TConversionFunction );
+      typedef Dijkstra                                Self;
+      typedef fpa::Base::Dijkstra< TAlgorithm, TMST > Superclass;
+      typedef itk::SmartPointer< Self >               Pointer;
+      typedef itk::SmartPointer< const Self >         ConstPointer;
 
-      itkGetConstObjectMacro( CostFunction, TCostFunction );
-      itkGetConstObjectMacro( ConversionFunction, TConversionFunction );
+      typedef fpa::Image::Functors::Dijkstra::Function< TInputImage, TOutputValue > TWeightFunction;
 
-      itkSetObjectMacro( CostFunction, TCostFunction );
-      itkSetObjectMacro( ConversionFunction, TConversionFunction );
+    public:
+      itkNewMacro( Self );
+      itkTypeMacro( fpa::Image::Dijkstra, fpa::Base::Dijkstra );
 
     protected:
-      Dijkstra( );
-      virtual ~Dijkstra( );
-
-      virtual TResult _Cost( const TVertex& v, const TVertex& p ) const;
-
-      virtual void _BeforeGenerateData( );
-      virtual void _InitResults( );
+      Dijkstra( )
+        : Superclass( )
+        {
+          typedef fpa::Image::Functors::Dijkstra::Identity< TInputImage, TOutputValue > _TDefaultFunction;
+          this->SetWeightFunction( _TDefaultFunction::New( ) );
+        }
+      virtual ~Dijkstra( )
+        {
+        }
+
+      virtual void _ConfigureOutput( const TOutputValue& v ) override
+        {
+          this->Superclass::_ConfigureOutput( v );
+          const TInputImage* in = this->GetInput( );
+
+          TMST* mst = this->GetMinimumSpanningTree( );
+          mst->SetLargestPossibleRegion( in->GetLargestPossibleRegion( ) );
+          mst->SetRequestedRegion( in->GetRequestedRegion( ) );
+          mst->SetBufferedRegion( in->GetBufferedRegion( ) );
+          mst->SetSpacing( in->GetSpacing( ) );
+          mst->SetOrigin( in->GetOrigin( ) );
+          mst->SetDirection( in->GetDirection( ) );
+          mst->Allocate( );
+
+          typename TMST::PixelType zero;
+          zero.Fill( 0 );
+          mst->FillBuffer( zero );
+        }
+
+      virtual void _BeforeGenerateData( ) override
+        {
+          this->Superclass::_BeforeGenerateData( );
+          TWeightFunction* wf =
+            dynamic_cast< TWeightFunction* >( this->GetWeightFunction( ) );
+          if( wf != NULL )
+            wf->SetImage( this->GetInput( ) );
+        }
 
     private:
-      // Purposely not implemented
+      // Purposely not implemented.
       Dijkstra( const Self& other );
       Self& operator=( const Self& other );
-
-    protected:
-      typename TCostFunction::Pointer m_CostFunction;
-      typename TConversionFunction::Pointer m_ConversionFunction;
     };
 
   } // ecapseman
 
 } // ecapseman
 
-#include <fpa/Image/Dijkstra.hxx>
-
-#endif // __FPA__IMAGE__DIJKSTRA__H__
+#endif // __fpa__Image__Dijkstra__h__
 
 // eof - $RCSfile$