]> Creatis software - FrontAlgorithms.git/blob - lib/fpa/Image/DijkstraWithEndPointDetection.h
b32d68a2bbb5f8dc0cc6db563968a1321f8f654e
[FrontAlgorithms.git] / lib / fpa / Image / DijkstraWithEndPointDetection.h
1 #ifndef __FPA__IMAGE__DIJKSTRAWITHENDPOINTDETECTION__H__
2 #define __FPA__IMAGE__DIJKSTRAWITHENDPOINTDETECTION__H__
3
4 #include <map>
5 #include <itkImage.h>
6 #include <fpa/Image/Dijkstra.h>
7 #include <fpa/Base/MatrixValuesContainer.h>
8 #include <fpa/Base/UniqueValuesContainer.h>
9
10 namespace fpa
11 {
12   namespace Image
13   {
14     /**
15      * @param I Input image type
16      * @param O Output image type
17      */
18     template< class I, class O >
19     class DijkstraWithEndPointDetection
20       : public Dijkstra< I, O >
21     {
22     public:
23       typedef DijkstraWithEndPointDetection   Self;
24       typedef Dijkstra< I, O >                Superclass;
25       typedef itk::SmartPointer< Self >       Pointer;
26       typedef itk::SmartPointer< const Self > ConstPointer;
27
28       typedef typename Superclass::TInputImage          TInputImage;
29       typedef typename Superclass::TOutputImage         TOutputImage;
30       typedef typename Superclass::TVertex              TVertex;
31       typedef typename Superclass::TVertexCompare       TVertexCompare;
32       typedef typename Superclass::TValue               TValue;
33       typedef typename Superclass::TResult              TResult;
34       typedef typename Superclass::TMinimumSpanningTree TMinimumSpanningTree;
35       typedef typename Superclass::TCostFunction        TCostFunction;
36       typedef typename Superclass::TConversionFunction  TConversionFunction;
37       typedef typename Superclass::_TVertices           TVertices;
38
39       typedef typename Superclass::TStartEvent     TStartEvent;
40       typedef typename Superclass::TStartLoopEvent TStartLoopEvent;
41       typedef typename Superclass::TEndEvent       TEndEvent;
42       typedef typename Superclass::TEndLoopEvent   TEndLoopEvent;
43       typedef typename Superclass::TAliveEvent     TAliveEvent;
44       typedef typename Superclass::TFrontEvent     TFrontEvent;
45       typedef typename Superclass::TFreezeEvent    TFreezeEvent;
46
47       typedef typename
48       Superclass::TStartBacktrackingEvent TStartBacktrackingEvent;
49       typedef typename
50       Superclass::TEndBacktrackingEvent TEndBacktrackingEvent;
51       typedef typename
52       Superclass::TBacktrackingEvent TBacktrackingEvent;
53
54       typedef unsigned short                          TLabel;
55       typedef itk::Image< TLabel, I::ImageDimension > TLabelImage;
56
57       typedef fpa::Base::UniqueValuesContainer< TVertex, TVertexCompare > TUniqueVertices;
58       typedef fpa::Base::MatrixValuesContainer< TVertex, TLabel, TVertexCompare > TBranches;
59
60     protected:
61       typedef typename Superclass::_TVertices      _TVertices;
62       typedef typename Superclass::_TCollision     _TCollision;
63       typedef typename Superclass::_TCollisionsRow _TCollisionsRow;
64       typedef typename Superclass::_TCollisions    _TCollisions;
65       typedef typename Superclass::_TNode          _TNode;
66       typedef typename Superclass::_TNodes         _TNodes;
67
68       typedef typename I::PixelType  _TPixel;
69       typedef typename I::RegionType _TRegion;
70       typedef typename I::SizeType   _TSize;
71
72       typedef std::pair< TResult, TVertex >     _TCandidate;
73       typedef std::multimap< TResult, TVertex > _TCandidates;
74
75     public:
76       itkNewMacro( Self );
77       itkTypeMacro( DijkstraWithEndPointDetection, Dijkstra );
78
79       itkBooleanMacro( CorrectSeeds );
80       itkBooleanMacro( CorrectEndPoints );
81
82       itkGetConstMacro( CorrectSeeds, bool );
83       itkGetConstMacro( CorrectEndPoints, bool );
84       itkGetConstMacro( SafetyNeighborhoodSize, unsigned int );
85
86       itkGetConstMacro( NumberOfBranches, unsigned long );
87
88       itkSetMacro( CorrectSeeds, bool );
89       itkSetMacro( CorrectEndPoints, bool );
90       itkSetMacro( SafetyNeighborhoodSize, unsigned int );
91
92     public:
93       TLabelImage* GetLabelImage( );
94       const TLabelImage* GetLabelImage( ) const;
95       void GraftLabelImage( itk::DataObject* obj );
96
97       TUniqueVertices* GetEndPoints( );
98       const TUniqueVertices* GetEndPoints( ) const;
99       void GraftEndPoints( itk::DataObject* obj );
100
101       TUniqueVertices* GetBifurcations( );
102       const TUniqueVertices* GetBifurcations( ) const;
103       void GraftBifurcations( itk::DataObject* obj );
104
105       TBranches* GetBranches( );
106       const TBranches* GetBranches( ) const;
107       void GraftBranches( itk::DataObject* obj );
108
109     protected:
110       DijkstraWithEndPointDetection( );
111       virtual ~DijkstraWithEndPointDetection( );
112
113       virtual void _BeforeGenerateData( );
114       virtual void _AfterGenerateData( );
115       virtual void _SetResult( const TVertex& v, const _TNode& n );
116
117       void _EndPointsAndBifurcations( );
118       void _FindBranches( );
119       void _LabelAll( );
120
121       _TRegion _Region( const TVertex& c, const double& r );
122
123       template< class _T >
124       TVertex _MaxInRegion(
125         const _T* image, const TVertex& v, const double& r
126         );
127
128     private:
129       // Purposely not implemented
130       DijkstraWithEndPointDetection( const Self& other );
131       Self& operator=( const Self& other );
132
133     protected:
134       unsigned int m_LabelImageIndex;
135       unsigned int m_BifurcationsIndex;
136       unsigned int m_EndPointsIndex;
137       unsigned int m_BranchesIndex;
138
139       bool m_CorrectSeeds;
140       bool m_CorrectEndPoints;
141       unsigned int m_SafetyNeighborhoodSize;
142
143       _TCandidates  m_Candidates;
144       unsigned long m_NumberOfBranches;
145     };
146
147   } // ecapseman
148
149 } // ecapseman
150
151 #include <fpa/Image/DijkstraWithEndPointDetection.hxx>
152
153 #endif // __FPA__IMAGE__DIJKSTRAWITHENDPOINTDETECTION__H__
154
155 // eof - $RCSfile$