]> Creatis software - FrontAlgorithms.git/blob - lib/fpa/Image/Dijkstra.h
d5a1bb9e6f2026b9038dcbda532aaea24dbbe9c7
[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/MarksInterfaceWithCollisions.h>
11 #include <fpa/Base/SeedsInterface.h>
12 #include <fpa/Image/Algorithm.h>
13 #include <fpa/Image/MinimumSpanningTree.h>
14 #include <fpa/Image/Functors/Dijkstra/Identity.h>
15
16 namespace fpa
17 {
18   namespace Image
19   {
20     /**
21      */
22     template< class _TInputImage, class _TOutputImage, class _TFrontId = unsigned char >
23     class Dijkstra
24       : public fpa::Base::Dijkstra< fpa::Image::Algorithm< _TInputImage, _TOutputImage, fpa::Base::MarksInterfaceWithCollisions< typename _TInputImage::IndexType >, fpa::Base::SeedsInterface< typename _TInputImage::IndexType, typename _TInputImage::PixelType, typename _TOutputImage::PixelType, _TFrontId, typename _TInputImage::IndexType::LexicographicCompare > >, fpa::Image::MinimumSpanningTree< _TInputImage::ImageDimension > >
25     {
26     public:
27       typedef _TInputImage  TInputImage;
28       typedef _TOutputImage TOutputImage;
29       typedef _TFrontId     TFrontId;
30
31       typedef typename TInputImage::IndexType        TVertex;
32       typedef typename TVertex::LexicographicCompare TVertexCompare;
33       typedef typename TInputImage::PixelType        TInputValue;
34       typedef typename TOutputImage::PixelType       TOutputValue;
35
36       typedef fpa::Base::MarksInterfaceWithCollisions< TVertex > TMarksInterface;
37       typedef fpa::Base::SeedsInterface< TVertex, TInputValue, TOutputValue, TFrontId, TVertexCompare > TSeedsInterface;
38       typedef fpa::Image::Algorithm< TInputImage, TOutputImage, TMarksInterface, TSeedsInterface > TAlgorithm;
39       typedef fpa::Image::MinimumSpanningTree< TInputImage::ImageDimension > TMST;
40
41       typedef Dijkstra                                Self;
42       typedef fpa::Base::Dijkstra< TAlgorithm, TMST > Superclass;
43       typedef itk::SmartPointer< Self >               Pointer;
44       typedef itk::SmartPointer< const Self >         ConstPointer;
45
46       typedef fpa::Image::Functors::Dijkstra::Function< TInputImage, TOutputValue > TWeightFunction;
47
48     public:
49       itkNewMacro( Self );
50       itkTypeMacro( fpa::Image::Dijkstra, fpa::Base::Dijkstra );
51
52     protected:
53       Dijkstra( )
54         : Superclass( )
55         {
56           typedef fpa::Image::Functors::Dijkstra::Identity< TInputImage, TOutputValue > _TDefaultFunction;
57           this->SetWeightFunction( _TDefaultFunction::New( ) );
58         }
59       virtual ~Dijkstra( )
60         {
61         }
62
63       virtual void _ConfigureOutput( const TOutputValue& v ) override
64         {
65           this->Superclass::_ConfigureOutput( v );
66           const TInputImage* in = this->GetInput( );
67
68           TMST* mst = this->GetMinimumSpanningTree( );
69           mst->SetLargestPossibleRegion( in->GetLargestPossibleRegion( ) );
70           mst->SetRequestedRegion( in->GetRequestedRegion( ) );
71           mst->SetBufferedRegion( in->GetBufferedRegion( ) );
72           mst->SetSpacing( in->GetSpacing( ) );
73           mst->SetOrigin( in->GetOrigin( ) );
74           mst->SetDirection( in->GetDirection( ) );
75           mst->Allocate( );
76
77           typename TMST::PixelType zero;
78           zero.Fill( 0 );
79           mst->FillBuffer( zero );
80         }
81
82       virtual void _BeforeGenerateData( ) override
83         {
84           this->Superclass::_BeforeGenerateData( );
85           TWeightFunction* wf =
86             dynamic_cast< TWeightFunction* >( this->GetWeightFunction( ) );
87           if( wf != NULL )
88             wf->SetImage( this->GetInput( ) );
89         }
90
91     private:
92       // Purposely not implemented.
93       Dijkstra( const Self& other );
94       Self& operator=( const Self& other );
95     };
96
97   } // ecapseman
98
99 } // ecapseman
100
101 #endif // __fpa__Image__Dijkstra__h__
102
103 // eof - $RCSfile$