]> Creatis software - cpPlugins.git/blob - lib/cpExtensions/DataStructures/Graph.h
Pipeline editor added.
[cpPlugins.git] / lib / cpExtensions / DataStructures / Graph.h
1 #ifndef __CPEXTENSIONS__DATASTRUCTURES__GRAPH__H__
2 #define __CPEXTENSIONS__DATASTRUCTURES__GRAPH__H__
3
4 #include <map>
5 #include <set>
6 #include <vector>
7 #include <itkLightObject.h>
8 #include <itkObjectFactory.h>
9
10 namespace cpExtensions
11 {
12   namespace DataStructures
13   {
14     /**
15      */
16     template< class V, class C, class I = unsigned long >
17     class Graph
18       : public itk::LightObject
19     {
20     public:
21       typedef Graph                           Self;
22       typedef itk::LightObject                Superclass;
23       typedef itk::SmartPointer< Self >       Pointer;
24       typedef itk::SmartPointer< const Self > ConstPointer;
25
26       typedef V TVertex;
27       typedef C TCost;
28       typedef I TIndex;
29
30       // Graph types
31       typedef std::map< I, V >          TVertices;
32       typedef std::vector< C >          TEdges;
33       typedef std::map< I, TEdges >     TMatrixRow;
34       typedef std::map< I, TMatrixRow > TMatrix;
35
36     public:
37       itkNewMacro( Self );
38       itkTypeMacro( Graph, itk::LightObject );
39
40     public:
41       typename TVertices::iterator BeginVertices( );
42       typename TVertices::iterator EndVertices( );
43       typename TVertices::const_iterator BeginVertices( ) const;
44       typename TVertices::const_iterator EndVertices( ) const;
45
46       typename TMatrix::iterator BeginEdgesRows( );
47       typename TMatrix::iterator EndEdgetsRows( );
48       typename TMatrix::const_iterator BeginEdgesRows( ) const;
49       typename TMatrix::const_iterator EndEdgesRows( ) const;
50
51       bool HasVertexIndex( const I& index ) const;
52       void InsertVertex( const I& index, V& vertex );
53       V& GetVertex( const I& index );
54       const V& GetVertex( const I& index ) const;
55
56       void AddConnection( const I& orig, const I& dest, const C& cost );
57
58       std::set< I > GetSinks( ) const;
59
60     protected:
61       Graph( );
62       virtual ~Graph( );
63
64     private:
65       // Purposely not implemented
66       Graph( const Self& other );
67       Self& operator=( const Self& other );
68
69     protected:
70       TVertices m_Vertices;
71       TMatrix   m_Matrix;
72     };
73
74   } // ecapseman
75
76 } // ecapseman
77
78 #ifndef ITK_MANUAL_INSTANTIATION
79 #include <cpExtensions/DataStructures/Graph.hxx>
80 #endif // ITK_MANUAL_INSTANTIATION
81
82 #endif // __CPEXTENSIONS__DATASTRUCTURES__GRAPH__H__
83
84 // eof - $RCSfile$