Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
Voronoi.h
Go to the documentation of this file.
1
32#pragma once
33
35#include <ogdf/basic/Graph.h>
37#include <ogdf/basic/List.h>
39
40#include <map>
41
42namespace ogdf {
43
45
48template<typename T>
49class Voronoi {
50protected:
54 std::map<node, ArrayBuffer<node>> m_nodeList;
55 const Graph& m_graph;
57
58 void computeVoronoiRegions(const Graph& G, const EdgeArray<T>& weights, const List<node>& seeds);
59
60public:
65 Voronoi(const Graph& G, const EdgeArray<T>& weights, const List<node>& seeds)
66 : m_seedOfNode(G), m_nodeList(), m_graph(G), m_seeds(seeds) {
67 computeVoronoiRegions(G, weights, seeds);
68 }
69
71 const Graph& getGraph() const { return m_graph; }
72
74 const List<node>& getSeeds() const { return m_seeds; }
75
78 edge predecessorEdge(node v) const { return m_predecessor[v]; }
79
82 edge tmp = predecessorEdge(v);
83 return tmp ? tmp->opposite(v) : nullptr;
84 }
85
87 T distance(node v) const { return m_distance[v]; }
88
90 node seed(node v) const { return m_seedOfNode[v]; }
91
94 return m_nodeList.find(seed(v))->second;
95 }
96};
97
99
100template<typename T>
102 const List<node>& seeds) {
103 Dijkstra<T> sssp;
104 sssp.call(G, weights, seeds, m_predecessor, m_distance);
105
106 // extract Voronoi seeds for each node and Voronoi regions for each seed
107 NodeArray<bool> processed(G, false);
108 for (node seed : seeds) {
109 processed[seed] = true;
110 m_seedOfNode[seed] = seed;
111 m_nodeList[seed].push(seed);
112 }
113
114 for (node u : G.nodes) {
115 ArrayBuffer<node> foundNodes;
116 node v;
117 for (v = u; !processed[v]; v = predecessor(v)) {
118 processed[v] = true;
119 foundNodes.push(v);
120 }
121
122 for (node passedNode : foundNodes) {
123 m_seedOfNode[passedNode] = m_seedOfNode[v];
124 m_nodeList[m_seedOfNode[v]].push(passedNode);
125 }
126 }
127}
128
129}
Declaration and implementation of ArrayBuffer class.
Includes declaration of graph class.
Decralation of GraphElement and GraphList classes.
Declaration of doubly linked lists and iterators.
An array that keeps track of the number of inserted elements; also usable as an efficient stack.
Definition ArrayBuffer.h:64
void push(E e)
Puts a new element in the buffer.
Dijkstra's single source shortest path algorithm.
Definition Dijkstra.h:60
void call(const Graph &G, const EdgeArray< T > &weight, const List< node > &sources, NodeArray< edge > &predecessor, NodeArray< T > &distance, bool directed=false, bool arcsReversed=false, node target=nullptr, T maxLength=std::numeric_limits< T >::max())
Calculates, based on the graph G with corresponding edge costs and source nodes, the shortest paths a...
Definition Dijkstra.h:253
Class for the representation of edges.
Definition Graph_d.h:364
node opposite(node v) const
Returns the adjacent node different from v.
Definition Graph_d.h:414
Data type for general directed graphs (adjacency list representation).
Definition Graph_d.h:866
Doubly linked lists (maintaining the length of the list).
Definition List.h:1451
Class for the representation of nodes.
Definition Graph_d.h:241
Computes Voronoi regions in an edge-weighted graph.
Definition Voronoi.h:49
NodeArray< edge > m_predecessor
Definition Voronoi.h:51
void computeVoronoiRegions(const Graph &G, const EdgeArray< T > &weights, const List< node > &seeds)
Definition Voronoi.h:101
std::map< node, ArrayBuffer< node > > m_nodeList
Definition Voronoi.h:54
const List< node > & m_seeds
Definition Voronoi.h:56
const Graph & getGraph() const
Returns a reference to the graph the Voronoi region has been computed for.
Definition Voronoi.h:71
T distance(node v) const
Returns the distance between v and its Voronoi seed.
Definition Voronoi.h:87
NodeArray< node > m_seedOfNode
Definition Voronoi.h:53
node predecessor(node v) const
Returns the nearest node to v on the shortest path to its Voronoi seed.
Definition Voronoi.h:81
node seed(node v) const
Returns the Voronoi seed of node v.
Definition Voronoi.h:90
NodeArray< T > m_distance
Definition Voronoi.h:52
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:65
const ArrayBuffer< node > & nodesInRegion(node v) const
Returns the list of nodes in the Voronoi region of node v.
Definition Voronoi.h:93
const List< node > & getSeeds() const
Returns a reference to the list of seeds the Voronoi region has been computed for.
Definition Voronoi.h:74
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:78
const Graph & m_graph
Definition Voronoi.h:55
RegisteredArray for edges of a graph, specialized for EdgeArray<edge>.
Definition Graph_d.h:717
RegisteredArray for nodes, edges and adjEntries of a graph.
Definition Graph_d.h:659
Implementation of Dijkstra's single source shortest path algorithm.
The namespace for all OGDF objects.