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