Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
mitkUndirectedGraph.h
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 Copyright (c) German Cancer Research Center,
5 Division of Medical and Biological Informatics.
6 All rights reserved.
7 
8 This software is distributed WITHOUT ANY WARRANTY; without
9 even the implied warranty of MERCHANTABILITY or FITNESS FOR
10 A PARTICULAR PURPOSE.
11 
12 See LICENSE.txt or http://www.mitk.org for details.
13 
14 ===================================================================*/
15 
16 #ifndef _MITK_UndirectedGraph_H
17 #define _MITK_UndirectedGraph_H
18 
19 #include <mitkBaseData.h>
20 
21 #ifndef Q_MOC_RUN
22 #include <boost/graph/adjacency_list.hpp>
23 #endif
24 
25 /* definition of basic boost::graph properties */
27 {
29 };
31 {
33 };
34 
35 namespace boost
36 {
37  BOOST_INSTALL_PROPERTY(vertex, properties);
38  BOOST_INSTALL_PROPERTY(edge, properties);
39 }
40 
41 namespace mitk
42 {
47  template <class TVertex, class TEdge>
48  class UndirectedGraph : public BaseData
49  {
50  public:
51  //--- Typedefs ---//
52 
53  typedef TVertex VertexType;
54  typedef TEdge EdgeType;
63  typedef boost::adjacency_list<boost::listS,
64  boost::vecS,
65  boost::undirectedS, // undirected graph
66  boost::property<vertex_properties_t, VertexType>,
67  boost::property<edge_properties_t, EdgeType>>
69 
70  /* a bunch of graph-specific typedefs */
71  typedef typename boost::graph_traits<GraphType>::vertex_descriptor VertexDescriptorType;
72  typedef typename boost::graph_traits<GraphType>::edge_descriptor EdgeDescriptorType;
73 
74  typedef typename boost::graph_traits<GraphType>::vertex_iterator VertexIteratorType;
75  typedef typename boost::graph_traits<GraphType>::edge_iterator EdgeIteratorType;
76  typedef typename boost::graph_traits<GraphType>::adjacency_iterator AdjacenyIteratorType;
77  typedef typename boost::graph_traits<GraphType>::out_edge_iterator OutEdgeIteratorType;
78  typedef typename boost::graph_traits<GraphType>::in_edge_iterator InEdgeIteratorType;
79 
80  //--- Macros ---//
82  itkNewMacro(Self);
83 
84  // virtual methods that need to be implemented
85  virtual void UpdateOutputInformation() override
86  {
87  if (this->GetSource())
88  this->GetSource()->UpdateOutputInformation();
89  }
90  virtual void SetRequestedRegionToLargestPossibleRegion() override {}
91  virtual bool RequestedRegionIsOutsideOfTheBufferedRegion() override { return false; }
92  virtual bool VerifyRequestedRegion() override { return true; }
93  virtual void SetRequestedRegion(const itk::DataObject *data) override {}
95  VertexDescriptorType AddVertex(const VertexType &vertexData);
96 
98  void RemoveVertex(const VertexDescriptorType &vertex);
99 
101  VertexType GetVertex(const VertexDescriptorType &vertex);
102 
104  void SetVertex(const VertexDescriptorType &vertex, const VertexType &vertexData);
105 
107  VertexDescriptorType GetVertexDescriptor(const VertexType &vertexData) const;
108 
110  EdgeDescriptorType AddEdge(const VertexDescriptorType &vertexA,
111  const VertexDescriptorType &vertexB,
112  const EdgeType &edgeData);
113 
115  void RemoveEdge(const EdgeDescriptorType &edge);
116 
118  EdgeType GetEdge(const EdgeDescriptorType &edge);
119 
121  void SetEdge(const EdgeDescriptorType &edge, const EdgeType &edgeData);
122 
124  EdgeDescriptorType GetEdgeDescriptor(const EdgeType &edgeData) const;
125 
127  std::pair<VertexType, VertexType> GetVerticesOfAnEdge(const EdgeDescriptorType &edge) const;
128 
130  EdgeDescriptorType GetEdgeDescriptorByVerices(const VertexDescriptorType &vertexA,
131  const VertexDescriptorType &vertexB) const;
132 
134  std::vector<EdgeType> GetAllEdgesOfAVertex(const VertexDescriptorType &vertex) const;
135 
137  int GetNumberOfVertices() const;
138 
140  int GetNumberOfEdges() const;
141 
143  std::vector<VertexType> GetVectorOfAllVertices() const;
144 
146  std::vector<EdgeType> GetVectorOfAllEdges() const;
147 
149  void Clear() override;
150 
152  const GraphType &GetGraph() const;
153 
155 
156  protected:
157  UndirectedGraph();
159  virtual ~UndirectedGraph();
160 
162 
163  private:
165  VertexType &properties(const VertexDescriptorType &vertex);
167  const VertexType &properties(const VertexDescriptorType &vertex) const;
169  EdgeType &properties(const EdgeDescriptorType &edge);
171  const EdgeType &properties(const EdgeDescriptorType &edge) const;
172  };
173 
174 } // namespace mitk
175 
176 #include "mitkUndirectedGraph.txx"
177 
178 #endif /* _MITK_UndirectedGraph_H */
VertexDescriptorType AddVertex(const VertexType &vertexData)
void Clear() override
int GetNumberOfEdges() const
virtual void SetRequestedRegionToLargestPossibleRegion() override
Set the RequestedRegion to the LargestPossibleRegion.
mitkClassMacro(UndirectedGraph, BaseData)
Base of all data objects.
Definition: mitkBaseData.h:39
boost::graph_traits< GraphType >::vertex_iterator VertexIteratorType
void RemoveVertex(const VertexDescriptorType &vertex)
virtual void SetRequestedRegion(const itk::DataObject *data) override
Set the requested region from this data object to match the requested region of the data object passe...
DataCollection - Class to facilitate loading/accessing structured data.
std::vector< EdgeType > GetVectorOfAllEdges() const
void SetVertex(const VertexDescriptorType &vertex, const VertexType &vertexData)
int GetNumberOfVertices() const
std::pair< VertexType, VertexType > GetVerticesOfAnEdge(const EdgeDescriptorType &edge) const
VertexType GetVertex(const VertexDescriptorType &vertex)
EdgeDescriptorType AddEdge(const VertexDescriptorType &vertexA, const VertexDescriptorType &vertexB, const EdgeType &edgeData)
VertexDescriptorType GetVertexDescriptor(const VertexType &vertexData) const
boost::graph_traits< GraphType >::adjacency_iterator AdjacenyIteratorType
void SetEdge(const EdgeDescriptorType &edge, const EdgeType &edgeData)
void RemoveEdge(const EdgeDescriptorType &edge)
boost::graph_traits< GraphType >::edge_descriptor EdgeDescriptorType
virtual void UpdateOutputInformation() override
EdgeType GetEdge(const EdgeDescriptorType &edge)
boost::adjacency_list< boost::listS, boost::vecS, boost::undirectedS, boost::property< vertex_properties_t, VertexType >, boost::property< edge_properties_t, EdgeType > > GraphType
vertex_properties_t
boost::graph_traits< GraphType >::edge_iterator EdgeIteratorType
boost::graph_traits< GraphType >::out_edge_iterator OutEdgeIteratorType
itk::SmartPointer< mitk::BaseDataSource > GetSource() const
Get the process object that generated this data object.
edge_properties_t
std::vector< EdgeType > GetAllEdgesOfAVertex(const VertexDescriptorType &vertex) const
EdgeDescriptorType GetEdgeDescriptor(const EdgeType &edgeData) const
Template class for undirected graphs.Paramters should be the vertex and edge classes, which contains the information.
boost::graph_traits< GraphType >::vertex_descriptor VertexDescriptorType
UndirectedGraph< VertexType, EdgeType > & operator=(const UndirectedGraph< VertexType, EdgeType > &rhs)
BOOST_INSTALL_PROPERTY(vertex, properties)
virtual ~UndirectedGraph()
virtual bool RequestedRegionIsOutsideOfTheBufferedRegion() override
Determine whether the RequestedRegion is outside of the BufferedRegion.
EdgeDescriptorType GetEdgeDescriptorByVerices(const VertexDescriptorType &vertexA, const VertexDescriptorType &vertexB) const
const GraphType & GetGraph() const
boost::graph_traits< GraphType >::in_edge_iterator InEdgeIteratorType
virtual bool VerifyRequestedRegion() override
Verify that the RequestedRegion is within the LargestPossibleRegion.
std::vector< VertexType > GetVectorOfAllVertices() const