X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcpExtensions%2FDataStructures%2FGraph.h;h=d9e913d579b326a535d2ebcc8cb59261cea9874f;hb=aee3cafa7e93f996580777976636ed625dbc43f5;hp=75bdd6821aef2a1be03cce89b7ce627b8ceff72c;hpb=201c5026430f9bcc33f9db6a39f5d03db096c860;p=cpPlugins.git diff --git a/lib/cpExtensions/DataStructures/Graph.h b/lib/cpExtensions/DataStructures/Graph.h index 75bdd68..d9e913d 100644 --- a/lib/cpExtensions/DataStructures/Graph.h +++ b/lib/cpExtensions/DataStructures/Graph.h @@ -1,10 +1,11 @@ -#ifndef __CPEXTENSIONS__DATASTRUCTURES__GRAPH__H__ -#define __CPEXTENSIONS__DATASTRUCTURES__GRAPH__H__ +#ifndef __cpExtensions__DataStructures__Graph__h__ +#define __cpExtensions__DataStructures__Graph__h__ +#include #include #include #include -#include +#include #include namespace cpExtensions @@ -13,33 +14,34 @@ namespace cpExtensions { /** \brief A generic graph with templated index types. * - * @param V Vertex type. - * @param C Cost type. - * @param I Index type (it should be a strict weak ordering type). + * @param _TVertex Vertex type. + * @param _TCost Cost type. + * @param _TIndex Index type (it should be a strict weak ordering type). */ - template< class V, class C, class I = unsigned long > + template< class _TVertex, class _TCost, class _TIndex = unsigned long, class _TIndexCompare = std::less< _TIndex > > class Graph - : public itk::LightObject + : public itk::DataObject { public: typedef Graph Self; - typedef itk::LightObject Superclass; + typedef itk::DataObject Superclass; typedef itk::SmartPointer< Self > Pointer; typedef itk::SmartPointer< const Self > ConstPointer; - typedef V TVertex; - typedef C TCost; - typedef I TIndex; + typedef _TVertex TVertex; + typedef _TCost TCost; + typedef _TIndex TIndex; + typedef _TIndexCompare TIndexCompare; // Base types - typedef std::map< TIndex, TVertex > TVertices; - typedef std::vector< TCost > TEdges; - typedef std::map< TIndex, TEdges > TMatrixRow; - typedef std::map< TIndex, TMatrixRow > TMatrix; + typedef std::map< TIndex, TVertex, TIndexCompare > TVertices; + typedef std::vector< TCost > TEdges; + typedef std::map< TIndex, TEdges, TIndexCompare > TMatrixRow; + typedef std::map< TIndex, TMatrixRow, TIndexCompare > TMatrix; public: itkNewMacro( Self ); - itkTypeMacro( Graph, itk::LightObject ); + itkTypeMacro( Graph, itk::DataObject ); public: /*! \brief Iterators over vertices. @@ -107,29 +109,27 @@ namespace cpExtensions /*! \brief Vertex manipulation methods. * Names are self-explanatory. */ - inline bool HasVertexIndex( const I& i ) const + inline bool HasVertexIndex( const TIndex& i ) const { return( this->m_Vertices.find( i ) != this->m_Vertices.end( ) ); } - inline void SetVertex( const I& index, V& vertex ) + inline void SetVertex( const TIndex& index, TVertex& vertex ) { this->m_Vertices[ index ] = vertex; } - inline V& GetVertex( const I& index ) + inline TVertex& GetVertex( const TIndex& index ) { return( this->m_Vertices[ index ] ); } - inline const V& GetVertex( const I& index ) const + inline const TVertex& GetVertex( const TIndex& index ) const { return( this->m_Vertices[ index ] ); } - bool RenameVertex( const I& old_index, const I& new_index ); - void RemoveVertex( const I& index ); + bool RenameVertex( const TIndex& old_index, const TIndex& new_index ); + void RemoveVertex( const TIndex& index ); /*! \brief Edge manipulation methods. * Names are self-explanatory. */ - inline void AddEdge( const I& orig, const I& dest, const C& cost ) + inline void AddEdge( const TIndex& orig, const TIndex& dest, const TCost& cost ) { this->m_Matrix[ orig ][ dest ].push_back( cost ); } - inline TEdges& GetEdges( const I& orig, const I& dest ) - { return( this->m_Matrix[ orig ][ dest ] ); } - inline const TEdges& GetEdges( const I& orig, const I& dest ) const - { return( this->m_Matrix[ orig ][ dest ] ); } - bool HasEdge( const I& orig, const I& dest ) const; - void RemoveEdge( const I& orig, const I& dest, const C& cost ); - void RemoveEdges( const I& orig, const I& dest ); + TEdges& GetEdges( const TIndex& orig, const TIndex& dest ); + const TEdges& GetEdges( const TIndex& orig, const TIndex& dest ) const; + bool HasEdge( const TIndex& orig, const TIndex& dest ) const; + void RemoveEdge( const TIndex& orig, const TIndex& dest, const TCost& cost ); + void RemoveEdges( const TIndex& orig, const TIndex& dest ); /*! \brief Returns graph's sinks. * @@ -137,7 +137,7 @@ namespace cpExtensions * * @return Sinks ordered by their index. */ - std::set< I > GetSinks( ) const; + std::set< TIndex, TIndexCompare > GetSinks( ) const; protected: Graph( ); @@ -158,9 +158,9 @@ namespace cpExtensions } // ecapseman #ifndef ITK_MANUAL_INSTANTIATION -#include +# include #endif // ITK_MANUAL_INSTANTIATION -#endif // __CPEXTENSIONS__DATASTRUCTURES__GRAPH__H__ +#endif // __cpExtensions__DataStructures__Graph__h__ // eof - $RCSfile$