Medical Imaging Interaction Toolkit  2023.04.00
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 mitkUndirectedGraph_h
14 #define mitkUndirectedGraph_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 
99 
101  void SetVertex(const VertexDescriptorType &vertex, const VertexType &vertexData);
102 
104  VertexDescriptorType GetVertexDescriptor(const VertexType &vertexData) const;
105 
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 
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::operator=
UndirectedGraph< VertexType, EdgeType > & operator=(const UndirectedGraph< VertexType, EdgeType > &rhs)
mitk::UndirectedGraph::GetVertex
VertexType GetVertex(const VertexDescriptorType &vertex)
mitk::UndirectedGraph::GetEdge
EdgeType GetEdge(const EdgeDescriptorType &edge)
boost::BOOST_INSTALL_PROPERTY
BOOST_INSTALL_PROPERTY(vertex, properties)
mitk::TubeGraphVertex
Base Class for Tube Graph Vertices.
Definition: mitkTubeGraphVertex.h:25
mitk::UndirectedGraph::RemoveVertex
void RemoveVertex(const VertexDescriptorType &vertex)
mitk::UndirectedGraph::RequestedRegionIsOutsideOfTheBufferedRegion
bool RequestedRegionIsOutsideOfTheBufferedRegion() override
Determine whether the RequestedRegion is outside of the BufferedRegion.
Definition: mitkUndirectedGraph.h:88
mitk::UndirectedGraph::GetGraph
const GraphType & GetGraph() const
mitk::UndirectedGraph::GetEdgeDescriptorByVerices
EdgeDescriptorType GetEdgeDescriptorByVerices(const VertexDescriptorType &vertexA, const VertexDescriptorType &vertexB) const
mitk::UndirectedGraph::UndirectedGraph
UndirectedGraph()
boost
Definition: mitkLexicalCast.h:50
mitk::UndirectedGraph
Template class for undirected graphs.Paramters should be the vertex and edge classes,...
Definition: mitkUndirectedGraph.h:45
mitk::UndirectedGraph::SetEdge
void SetEdge(const EdgeDescriptorType &edge, const EdgeType &edgeData)
mitk::UndirectedGraph::SetRequestedRegionToLargestPossibleRegion
void SetRequestedRegionToLargestPossibleRegion() override
Set the RequestedRegion to the LargestPossibleRegion.
Definition: mitkUndirectedGraph.h:87
mitk::BaseData::GetSource
itk::SmartPointer< mitk::BaseDataSource > GetSource() const
Get the process object that generated this data object.
edge_properties
@ edge_properties
Definition: mitkUndirectedGraph.h:29
vertex_properties
@ vertex_properties
Definition: mitkUndirectedGraph.h:25
mitk::UndirectedGraph::EdgeType
TEdge EdgeType
Definition: mitkUndirectedGraph.h:51
mitk::UndirectedGraph::UpdateOutputInformation
void UpdateOutputInformation() override
Definition: mitkUndirectedGraph.h:82
mitk
DataCollection - Class to facilitate loading/accessing structured data.
Definition: RenderingTests.dox:1
mitk::UndirectedGraph::VerifyRequestedRegion
bool VerifyRequestedRegion() override
Verify that the RequestedRegion is within the LargestPossibleRegion.
Definition: mitkUndirectedGraph.h:89
mitk::UndirectedGraph::EdgeIteratorType
boost::graph_traits< GraphType >::edge_iterator EdgeIteratorType
Definition: mitkUndirectedGraph.h:72
mitk::UndirectedGraph::GetAllEdgesOfAVertex
std::vector< EdgeType > GetAllEdgesOfAVertex(const VertexDescriptorType &vertex) const
mitk::UndirectedGraph::OutEdgeIteratorType
boost::graph_traits< GraphType >::out_edge_iterator OutEdgeIteratorType
Definition: mitkUndirectedGraph.h:74
mitk::UndirectedGraph::~UndirectedGraph
~UndirectedGraph() override
mitk::TubeGraphEdge
Base Class for Tube Graph Edges.
Definition: mitkTubeGraphEdge.h:27
mitk::UndirectedGraph::GetNumberOfVertices
int GetNumberOfVertices() const
mitk::UndirectedGraph::EdgeDescriptorType
boost::graph_traits< GraphType >::edge_descriptor EdgeDescriptorType
Definition: mitkUndirectedGraph.h:69
mitk::UndirectedGraph::m_Graph
GraphType m_Graph
Definition: mitkUndirectedGraph.h:157
mitk::UndirectedGraph::SetRequestedRegion
void SetRequestedRegion(const itk::DataObject *) override
Set the requested region from this data object to match the requested region of the data object passe...
Definition: mitkUndirectedGraph.h:90
edge_properties_t
edge_properties_t
Definition: mitkUndirectedGraph.h:27
mitk::UndirectedGraph::GraphType
boost::adjacency_list< boost::listS, boost::vecS, boost::undirectedS, boost::property< vertex_properties_t, VertexType >, boost::property< edge_properties_t, EdgeType > > GraphType
Definition: mitkUndirectedGraph.h:65
vertex_properties_t
vertex_properties_t
Definition: mitkUndirectedGraph.h:23
mitk::UndirectedGraph::GetEdgeDescriptor
EdgeDescriptorType GetEdgeDescriptor(const EdgeType &edgeData) const
mitk::UndirectedGraph::GetVectorOfAllEdges
std::vector< EdgeType > GetVectorOfAllEdges() const
mitk::BaseData
Base of all data objects.
Definition: mitkBaseData.h:42
mitk::UndirectedGraph::SetVertex
void SetVertex(const VertexDescriptorType &vertex, const VertexType &vertexData)
mitk::UndirectedGraph::RemoveEdge
void RemoveEdge(const EdgeDescriptorType &edge)
mitk::UndirectedGraph::InEdgeIteratorType
boost::graph_traits< GraphType >::in_edge_iterator InEdgeIteratorType
Definition: mitkUndirectedGraph.h:75
mitk::UndirectedGraph::mitkClassMacro
mitkClassMacro(UndirectedGraph, BaseData)
mitk::UndirectedGraph::GetVertexDescriptor
VertexDescriptorType GetVertexDescriptor(const VertexType &vertexData) const
mitkBaseData.h
mitk::UndirectedGraph::GetNumberOfEdges
int GetNumberOfEdges() const
mitk::UndirectedGraph::AdjacenyIteratorType
boost::graph_traits< GraphType >::adjacency_iterator AdjacenyIteratorType
Definition: mitkUndirectedGraph.h:73
mitk::UndirectedGraph::GetVectorOfAllVertices
std::vector< VertexType > GetVectorOfAllVertices() const
mitk::UndirectedGraph::AddEdge
EdgeDescriptorType AddEdge(const VertexDescriptorType &vertexA, const VertexDescriptorType &vertexB, const EdgeType &edgeData)
mitk::UndirectedGraph::GetVerticesOfAnEdge
std::pair< VertexType, VertexType > GetVerticesOfAnEdge(const EdgeDescriptorType &edge) const
mitk::UndirectedGraph::VertexType
TVertex VertexType
Definition: mitkUndirectedGraph.h:50
mitk::UndirectedGraph::AddVertex
VertexDescriptorType AddVertex(const VertexType &vertexData)
mitk::UndirectedGraph::VertexIteratorType
boost::graph_traits< GraphType >::vertex_iterator VertexIteratorType
Definition: mitkUndirectedGraph.h:71
mitk::UndirectedGraph::Clear
void Clear() override
mitk::UndirectedGraph::VertexDescriptorType
boost::graph_traits< GraphType >::vertex_descriptor VertexDescriptorType
Definition: mitkUndirectedGraph.h:68