]> Creatis software - FrontAlgorithms.git/blob - lib/fpa/Image/Dijkstra.h
7992842295bb400e78461cb18f2e1255047d3d5f
[FrontAlgorithms.git] / lib / fpa / Image / Dijkstra.h
1 // =========================================================================
2 // @author Leonardo Florez Valencia
3 // @email florez-l@javeriana.edu.co
4 // =========================================================================
5
6 #ifndef __fpa__Image__Dijkstra__h__
7 #define __fpa__Image__Dijkstra__h__
8
9 #include <fpa/Base/Dijkstra.h>
10 #include <fpa/Base/SeedsInterface.h>
11 #include <fpa/Image/MarksInterface.h>
12 #include <fpa/Image/Filter.h>
13 #include <fpa/Image/MinimumSpanningTree.h>
14 #include <fpa/Image/Functors/VertexParentBase.h>
15 #include <fpa/Image/Functors/VertexIdentity.h>
16
17 namespace fpa
18 {
19   namespace Image
20   {
21     /**
22      */
23     template< class _TInputImage, class _TOutputImage >
24     class Dijkstra
25       : public fpa::Base::Dijkstra< fpa::Image::Filter< _TInputImage, _TOutputImage >, fpa::Image::MarksInterface< _TInputImage::ImageDimension >, fpa::Base::SeedsInterface< typename _TInputImage::IndexType, typename _TInputImage::IndexType::LexicographicCompare >, fpa::Image::MinimumSpanningTree< _TInputImage::ImageDimension > >
26     {
27     public:
28       // Interfaces
29       typedef fpa::Image::Filter< _TInputImage, _TOutputImage > TFilter;
30       typedef fpa::Image::MarksInterface< _TInputImage::ImageDimension > TMarksInterface;
31       typedef fpa::Base::SeedsInterface< typename _TInputImage::IndexType, typename _TInputImage::IndexType::LexicographicCompare > TSeedsInterface;
32       typedef fpa::Image::MinimumSpanningTree< _TInputImage::ImageDimension > TMST;
33
34       // Smart pointers
35       typedef Dijkstra Self;
36       typedef fpa::Base::Dijkstra< TFilter, TMarksInterface, TSeedsInterface, TMST > Superclass;
37       typedef itk::SmartPointer< Self > Pointer;
38       typedef itk::SmartPointer< const Self > ConstPointer;
39
40       typedef typename TFilter::TInputImage TInputImage;
41       typedef typename TFilter::TOutputValue TOutputValue;
42       typedef typename TFilter::TVertex TVertex;
43
44     public:
45       itkNewMacro( Self );
46       itkTypeMacro( fpa::Image::Dijkstra, fpa::Base::Dijkstra );
47
48     protected:
49       Dijkstra( )
50         : Superclass( )
51         {
52           this->SetFunctor(
53             fpa::Image::Functors::
54             VertexIdentity< _TInputImage, typename TFilter::TOutputValue >::
55             New( )
56             );
57         }
58       virtual ~Dijkstra( )        { }
59
60       virtual void _ConfigureOutputs( const TOutputValue& init_value ) override
61         {
62           this->Superclass::_ConfigureOutputs( init_value );
63
64           typename TVertex::OffsetType o;
65           o.Fill( 0 );
66           const TInputImage* input = this->GetInput( );
67           TMST* mst = this->GetMinimumSpanningTree( );
68           mst->CopyInformation( input );
69           mst->SetBufferedRegion( input->GetRequestedRegion( ) );
70           mst->Allocate( );
71           mst->FillBuffer( o );
72         }
73
74       virtual void GenerateData( ) override
75         {
76           // Configure functors with input image
77           typedef typename TFilter::TOutputValue _TOutputValue;
78           typedef fpa::Image::Functors::VertexParentBase< _TInputImage, _TOutputValue > _TVFunc;
79           _TVFunc* vfunc =
80             dynamic_cast< _TVFunc* >( this->m_VertexFunctor.GetPointer( ) );
81           if( vfunc != NULL )
82             vfunc->SetImage( this->GetInput( ) );
83
84           // Ok, continue
85           this->Superclass::GenerateData( );
86         }
87
88     private:
89       Dijkstra( const Self& other );
90       Self& operator=( const Self& other );
91     };
92
93   } // ecapseman
94
95 } // ecapseman
96
97 #endif // __fpa__Image__Dijkstra__h__
98
99 // eof - $RCSfile$