]> Creatis software - FrontAlgorithms.git/blob - lib/fpa/Base/MinimumSpanningTree.h
40562678d23e2717c8793b32c59b6ec6a60caf8c
[FrontAlgorithms.git] / lib / fpa / Base / MinimumSpanningTree.h
1 #ifndef __FPA__BASE__MINIMUMSPANNINGTREE__H__
2 #define __FPA__BASE__MINIMUMSPANNINGTREE__H__
3
4 #include <map>
5 #include <utility>
6 #include <vector>
7 #include <itkSimpleDataObjectDecorator.h>
8 #include <itkSmartPointer.h>
9
10 namespace fpa
11 {
12   namespace Base
13   {
14     /**
15      */
16     template< class V, class C, class VC >
17     class MinimumSpanningTree
18       : public itk::SimpleDataObjectDecorator< std::map< V, std::pair< V, short >, VC > >
19     {
20     public:
21       typedef std::pair< V, short >                        TNodeInfo;
22       typedef std::map< V, TNodeInfo, VC >                 TDecorated;
23       typedef MinimumSpanningTree                          Self;
24       typedef itk::SimpleDataObjectDecorator< TDecorated > Superclass;
25       typedef itk::SmartPointer< Self >                    Pointer;
26       typedef itk::SmartPointer< const Self >              ConstPointer;
27
28       typedef V  TVertex;
29       typedef C  TCollisions;
30       typedef VC TVertexCompare;
31
32     protected:
33       typedef std::vector< unsigned long > _TRow;
34       typedef std::vector< _TRow >         _TMatrix;
35
36     public:
37       itkNewMacro( Self );
38       itkTypeMacro( MinimumSpanningTree, itkSimpleDataObjectDecorator );
39
40       itkGetConstMacro( Collisions, TCollisions );
41
42     public:
43       void SetCollisions( const TCollisions& collisions );
44       void SetParent( const TVertex& v, const TVertex& p, const short& fid )
45         {
46           this->Get( )[ v ] = TNodeInfo( p, fid );
47           this->Modified( );
48         }
49       void Clear( )
50         {
51           this->Get( ).clear( );
52           this->m_Collisions.clear( );
53           this->m_FrontPaths.clear( );
54         }
55       virtual void GetPath(
56         std::vector< V >& path, const V& a, const V& b
57         ) const;
58
59       template< class I, class P >
60       void GetPathFromImage(
61         std::vector< P >& path, const V& a, const V& b,
62         const I* image, unsigned int kernel = 0
63         ) const;
64
65     protected:
66       MinimumSpanningTree( );
67       virtual ~MinimumSpanningTree( );
68
69       virtual void _Path( std::vector< V >& path, const V& a ) const;
70
71     private:
72       // Purposely not implemented
73       MinimumSpanningTree( const Self& other );
74       Self& operator=( const Self& other );
75
76     protected:
77       TCollisions m_Collisions;
78       _TMatrix    m_FrontPaths;
79       static const unsigned long INF_VALUE;
80     };
81
82   } // ecapseman
83
84 } // ecapseman
85
86 #include <fpa/Base/MinimumSpanningTree.hxx>
87
88 #endif // __FPA__BASE__MINIMUMSPANNINGTREE__H__
89
90 // eof - $RCSfile$