Open
Graph Drawing
Framework

 v. 2020.02 (Catalpa)
 

Voronoi.h
Go to the documentation of this file.
1 
32 #pragma once
33 
34 #include <ogdf/basic/ArrayBuffer.h>
35 #include <ogdf/graphalg/Dijkstra.h>
36 #include <map>
37 
38 namespace ogdf {
39 
41 
44 template<typename T>
45 class Voronoi {
46 protected:
50  std::map<node, ArrayBuffer<node>> m_nodeList;
51  const Graph &m_graph;
53 
54  void computeVoronoiRegions(const Graph &G, const EdgeArray<T> &weights, const List<node> &seeds);
55 
56 public:
61  Voronoi(const Graph &G, const EdgeArray<T> &weights, const List<node> &seeds)
62  : m_seedOfNode(G)
63  , m_nodeList()
64  , m_graph(G)
65  , m_seeds(seeds)
66  {
67  computeVoronoiRegions(G, weights, seeds);
68  }
69 
71  const Graph &getGraph() const
72  {
73  return m_graph;
74  }
75 
77  const List<node> &getSeeds() const
78  {
79  return m_seeds;
80  }
81 
85  {
86  return m_predecessor[v];
87  }
88 
91  {
92  edge tmp = predecessorEdge(v);
93  return tmp ? tmp->opposite(v) : nullptr;
94  }
95 
97  T distance(node v) const
98  {
99  return m_distance[v];
100  }
101 
103  node seed(node v) const
104  {
105  return m_seedOfNode[v];
106  }
107 
110  {
111  return m_nodeList.find(seed(v))->second;
112  }
113 };
114 
116 
117 template<typename T>
118 void Voronoi<T>::computeVoronoiRegions(const Graph &G, const EdgeArray<T> &weights, const List<node> &seeds)
119 {
120  Dijkstra<T> sssp;
121  sssp.call(G, weights, seeds, m_predecessor, m_distance);
122 
123  // extract Voronoi seeds for each node and Voronoi regions for each seed
124  NodeArray<bool> processed(G, false);
125  for (node seed : seeds) {
126  processed[seed] = true;
128  m_nodeList[seed].push(seed);
129  }
130 
131  for (node u : G.nodes) {
132  ArrayBuffer<node> foundNodes;
133  node v;
134  for (v = u; !processed[v]; v = predecessor(v)) {
135  processed[v] = true;
136  foundNodes.push(v);
137  }
138 
139  for (node passedNode : foundNodes) {
140  m_seedOfNode[passedNode] = m_seedOfNode[v];
141  m_nodeList[m_seedOfNode[v]].push(passedNode);
142  }
143  }
144 }
145 
146 }
Dijkstra&#39;s single source shortest path algorithm.
Definition: Dijkstra.h:52
const List< node > & getSeeds() const
Returns a reference to the list of seeds the Voronoi region has been computed for.
Definition: Voronoi.h:77
Data type for general directed graphs (adjacency list representation).
Definition: Graph_d.h:492
Declaration and implementation of ArrayBuffer class.
NodeArray< node > m_seedOfNode
Definition: Voronoi.h:49
void call(const Graph &G, const EdgeArray< T > &weight, const List< node > &sources, NodeArray< edge > &predecessor, NodeArray< T > &distance, bool directed=false)
Calculates, based on the graph G with corresponding edge costs and source nodes, the shortest paths a...
Definition: Dijkstra.h:61
void push(E e)
Puts a new element in the buffer.
Definition: ArrayBuffer.h:102
An array that keeps track of the number of inserted elements; also usable as an efficient stack...
Definition: Array.h:45
Dynamic arrays indexed with edges.
Definition: EdgeArray.h:112
Voronoi(const Graph &G, const EdgeArray< T > &weights, const List< node > &seeds)
Build data structure to query Voronoi regions of edge-weighted graph G with given Voronoi seeds...
Definition: Voronoi.h:61
void computeVoronoiRegions(const Graph &G, const EdgeArray< T > &weights, const List< node > &seeds)
Definition: Voronoi.h:118
Computes Voronoi regions in an edge-weighted graph.
Definition: Voronoi.h:45
Dynamic arrays indexed with nodes.
Definition: Graph_d.h:438
Implementation of Dijkstra&#39;s single source shortest path algorithm.
const ArrayBuffer< node > & nodesInRegion(node v) const
Returns the list of nodes in the Voronoi region of node v.
Definition: Voronoi.h:109
const List< node > & m_seeds
Definition: Voronoi.h:52
Doubly linked lists (maintaining the length of the list).
Definition: List.h:40
node seed(node v) const
Returns the Voronoi seed of node v.
Definition: Voronoi.h:103
const Graph & getGraph() const
Returns a reference to the graph the Voronoi region has been computed for.
Definition: Voronoi.h:71
Class for the representation of edges.
Definition: Graph_d.h:292
std::map< node, ArrayBuffer< node > > m_nodeList
Definition: Voronoi.h:50
T distance(node v) const
Returns the distance between v and its Voronoi seed.
Definition: Voronoi.h:97
NodeArray< edge > m_predecessor
Definition: Voronoi.h:47
Class for the representation of nodes.
Definition: Graph_d.h:169
node opposite(node v) const
Returns the adjacent node different from v.
Definition: Graph_d.h:338
node predecessor(node v) const
Returns the nearest node to v on the shortest path to its Voronoi seed.
Definition: Voronoi.h:90
NodeArray< T > m_distance
Definition: Voronoi.h:48
The namespace for all OGDF objects.
const Graph & m_graph
Definition: Voronoi.h:51
internal::GraphObjectContainer< NodeElement > nodes
The container containing all node objects.
Definition: Graph_d.h:565
edge predecessorEdge(node v) const
Returns the edge incident to v and its predecessor. Note that the predecessor of a terminal is nullpt...
Definition: Voronoi.h:84