Medical Imaging Interaction Toolkit  2018.4.99-1640525a
Medical Imaging Interaction Toolkit
mitkUndirectedGraph.h
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #ifndef _MITK_UndirectedGraph_H
14 #define _MITK_UndirectedGraph_H
15 
16 #include <mitkBaseData.h>
17 
18 #ifndef Q_MOC_RUN
19 #include <boost/graph/adjacency_list.hpp>
20 #endif
21 
22 /* definition of basic boost::graph properties */
24 {
26 };
28 {
30 };
31 
32 namespace boost
33 {
34  BOOST_INSTALL_PROPERTY(vertex, properties);
35  BOOST_INSTALL_PROPERTY(edge, properties);
36 }
37 
38 namespace mitk
39 {
44  template <class TVertex, class TEdge>
45  class UndirectedGraph : public BaseData
46  {
47  public:
48  //--- Typedefs ---//
49 
50  typedef TVertex VertexType;
51  typedef TEdge EdgeType;
60  typedef boost::adjacency_list<boost::listS,
61  boost::vecS,
62  boost::undirectedS, // undirected graph
63  boost::property<vertex_properties_t, VertexType>,
64  boost::property<edge_properties_t, EdgeType>>
66 
67  /* a bunch of graph-specific typedefs */
68  typedef typename boost::graph_traits<GraphType>::vertex_descriptor VertexDescriptorType;
69  typedef typename boost::graph_traits<GraphType>::edge_descriptor EdgeDescriptorType;
70 
71  typedef typename boost::graph_traits<GraphType>::vertex_iterator VertexIteratorType;
72  typedef typename boost::graph_traits<GraphType>::edge_iterator EdgeIteratorType;
73  typedef typename boost::graph_traits<GraphType>::adjacency_iterator AdjacenyIteratorType;
74  typedef typename boost::graph_traits<GraphType>::out_edge_iterator OutEdgeIteratorType;
75  typedef typename boost::graph_traits<GraphType>::in_edge_iterator InEdgeIteratorType;
76 
77  //--- Macros ---//
79  itkNewMacro(Self);
80 
81  // virtual methods that need to be implemented
82  void UpdateOutputInformation() override
83  {
84  if (this->GetSource())
85  this->GetSource()->UpdateOutputInformation();
86  }
88  bool RequestedRegionIsOutsideOfTheBufferedRegion() override { return false; }
89  bool VerifyRequestedRegion() override { return true; }
90  void SetRequestedRegion(const itk::DataObject *) override {}
92  VertexDescriptorType AddVertex(const VertexType &vertexData);
93 
95  void RemoveVertex(const VertexDescriptorType &vertex);
96 
98  VertexType GetVertex(const VertexDescriptorType &vertex);
99 
101  void SetVertex(const VertexDescriptorType &vertex, const VertexType &vertexData);
102 
104  VertexDescriptorType GetVertexDescriptor(const VertexType &vertexData) const;
105 
107  EdgeDescriptorType AddEdge(const VertexDescriptorType &vertexA,
108  const VertexDescriptorType &vertexB,
109  const EdgeType &edgeData);
110 
112  void RemoveEdge(const EdgeDescriptorType &edge);
113 
115  EdgeType GetEdge(const EdgeDescriptorType &edge);
116 
118  void SetEdge(const EdgeDescriptorType &edge, const EdgeType &edgeData);
119 
121  EdgeDescriptorType GetEdgeDescriptor(const EdgeType &edgeData) const;
122 
124  std::pair<VertexType, VertexType> GetVerticesOfAnEdge(const EdgeDescriptorType &edge) const;
125 
127  EdgeDescriptorType GetEdgeDescriptorByVerices(const VertexDescriptorType &vertexA,
128  const VertexDescriptorType &vertexB) const;
129 
131  std::vector<EdgeType> GetAllEdgesOfAVertex(const VertexDescriptorType &vertex) const;
132 
134  int GetNumberOfVertices() const;
135 
137  int GetNumberOfEdges() const;
138 
140  std::vector<VertexType> GetVectorOfAllVertices() const;
141 
143  std::vector<EdgeType> GetVectorOfAllEdges() const;
144 
146  void Clear() override;
147 
149  const GraphType &GetGraph() const;
150 
152 
153  protected:
154  UndirectedGraph();
155  ~UndirectedGraph() override;
156 
158 
159  private:
161  VertexType &properties(const VertexDescriptorType &vertex);
163  const VertexType &properties(const VertexDescriptorType &vertex) const;
165  EdgeType &properties(const EdgeDescriptorType &edge);
167  const EdgeType &properties(const EdgeDescriptorType &edge) const;
168  };
169 
170 } // namespace mitk
171 
172 #include "mitkUndirectedGraph.txx"
173 
174 #endif /* _MITK_UndirectedGraph_H */
Base of all data objects.
Definition: mitkBaseData.h:42
boost::graph_traits< GraphType >::vertex_iterator VertexIteratorType
DataCollection - Class to facilitate loading/accessing structured data.
void SetRequestedRegionToLargestPossibleRegion() override
Set the RequestedRegion to the LargestPossibleRegion.
boost::graph_traits< GraphType >::adjacency_iterator AdjacenyIteratorType
bool VerifyRequestedRegion() override
Verify that the RequestedRegion is within the LargestPossibleRegion.
boost::graph_traits< GraphType >::edge_descriptor EdgeDescriptorType
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
void UpdateOutputInformation() override
#define mitkClassMacro(className, SuperClassName)
Definition: mitkCommon.h:40
boost::graph_traits< GraphType >::edge_iterator EdgeIteratorType
boost::graph_traits< GraphType >::out_edge_iterator OutEdgeIteratorType
bool RequestedRegionIsOutsideOfTheBufferedRegion() override
Determine whether the RequestedRegion is outside of the BufferedRegion.
void SetRequestedRegion(const itk::DataObject *) override
Set the requested region from this data object to match the requested region of the data object passe...
edge_properties_t
Template class for undirected graphs.Paramters should be the vertex and edge classes, which contains the information.
boost::graph_traits< GraphType >::vertex_descriptor VertexDescriptorType
BOOST_INSTALL_PROPERTY(vertex, properties)
boost::graph_traits< GraphType >::in_edge_iterator InEdgeIteratorType