Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
SpringEmbedderBase.h
Go to the documentation of this file.
1
32#pragma once
33
34#include <ogdf/basic/Array.h>
35#include <ogdf/basic/Graph.h>
41#include <ogdf/basic/List.h>
42#include <ogdf/basic/System.h>
43#include <ogdf/basic/geometry.h>
47
48#include <cmath>
49
50namespace ogdf {
51namespace spring_embedder {
52
55public:
63
96
97 virtual void call(GraphAttributes& GA) override {
98 const Graph& G = GA.constGraph();
99 if (G.empty()) {
100 return;
101 }
102
103 // all edges straight-line
104 GA.clearAllBends();
105
106 GraphCopy GC;
107 GC.setOriginalGraph(G);
108
109 // compute connected component of G
110 NodeArray<int> component(G);
111 int numCC = connectedComponents(G, component);
112
113 // intialize the array of lists of nodes contained in a CC
114 Array<List<node>> nodesInCC(numCC);
115
116 for (node v : G.nodes) {
117 nodesInCC[component[v]].pushBack(v);
118 }
119
120 NodeArray<node> nodeCopy(G);
121 EdgeArray<edge> auxCopy(G);
122 Array<DPoint> boundingBox(numCC);
123
124 for (int i = 0; i < numCC; ++i) {
125 nodeCopy.init(G);
126 auxCopy.init(G);
127 GC.clear();
128 GC.insert(nodesInCC[i].begin(), nodesInCC[i].end(), filter_any_edge, nodeCopy, auxCopy);
130
131 const int n = GC.numberOfNodes();
132
133 // special case: just one node
134 if (n == 1) {
135 node vOrig = GC.original(GC.firstNode());
136 GA.x(vOrig) = GA.y(vOrig) = 0;
137 boundingBox[i] = DPoint(0, 0);
138 continue;
139 }
140
141 callMaster(GC, GA, boundingBox[i]);
142 //std::cout << "avg. force: " << master.avgDisplacement() << std::endl;
143 //std::cout << "max. force: " << master.maxDisplacement() << std::endl;
144 }
145
146 Array<DPoint> offset(numCC);
147 TileToRowsCCPacker packer;
148 packer.call(boundingBox, offset, m_pageRatio);
149
150 // The arrangement is given by offset to the origin of the coordinate
151 // system. We still have to shift each node and edge by the offset
152 // of its connected component.
153
154 for (int i = 0; i < numCC; ++i) {
155 const List<node>& nodes = nodesInCC[i];
156
157 const double dx = offset[i].m_x;
158 const double dy = offset[i].m_y;
159
160 // iterate over all nodes in ith CC
162 for (node v : nodes) {
163 GA.x(v) += dx;
164 GA.y(v) += dy;
165 }
166 }
167 }
168
171
174
177
180
182
188
190 void avgConvergenceFactor(double f) {
191 if (f >= 0) {
193 }
194 }
195
197
203
205 void maxConvergenceFactor(double f) {
206 if (f >= 0) {
208 }
209 }
210
212
216 int iterations() const { return m_iterations; }
217
219 void iterations(int i) {
220 if (i >= 0) {
221 m_iterations = i;
222 }
223 }
224
227
229 void iterationsImprove(int i) {
230 if (i >= 0) {
232 }
233 }
234
235 double coolDownFactor() const { return m_coolDownFactor; }
236
237 double forceLimitStep() const { return m_forceLimitStep; }
238
240 double idealEdgeLength() const { return m_idealEdgeLength; }
241
243
247 void idealEdgeLength(double len) { m_idealEdgeLength = len; }
248
250 bool noise() const { return m_noise; }
251
253 void noise(bool on) { m_noise = on; }
254
256 double minDistCC() const { return m_minDistCC; }
257
259 void minDistCC(double x) { m_minDistCC = x; }
260
262 double pageRatio() { return m_pageRatio; }
263
265 void pageRatio(double x) { m_pageRatio = x; }
266
268 Scaling scaling() const { return m_scaling; }
269
271 void scaling(Scaling sc) { m_scaling = sc; }
272
274 double scaleFunctionFactor() const { return m_scaleFactor; }
275
277 void scaleFunctionFactor(double f) { m_scaleFactor = f; }
278
280 void userBoundingBox(double xmin, double ymin, double xmax, double ymax) {
281 m_userBoundingBox = DRect(xmin, ymin, xmax, ymax);
282 }
283
286
288 unsigned int maxThreads() const { return m_maxThreads; }
289
291 void maxThreads(unsigned int n) { m_maxThreads = n; }
292
293protected:
294 virtual void callMaster(const GraphCopy& copy, GraphAttributes& attr, DPoint& box) = 0;
295
301
303
306 bool m_noise;
307
310
312
313 double m_minDistCC;
314 double m_pageRatio;
315
318
319 unsigned int m_maxThreads;
320};
321
322}
323}
Declaration and implementation of Array class and Array algorithms.
Includes declaration of graph class.
Declaration of class GraphAttributes which extends a Graph by additional attributes.
Declaration of graph copy classes.
Decralation of GraphElement and GraphList classes.
Declaration of interface for layout algorithms (class LayoutModule)
Declares class LayoutStandards which specifies default / standard values used in graph layouts.
Declaration of doubly linked lists and iterators.
Declaration of SpringForceModel enumeration.
Decalration of System class which provides unified access to system information.
Declaration of class TileToRowsCCPacker.
Declaration of classes GenericPoint, GenericPolyline, GenericLine, GenericSegment,...
The parameterized class Array implements dynamic arrays of type E.
Definition Array.h:219
Rectangles with real coordinates.
Definition geometry.h:798
Stores additional attributes of a graph (like layout information).
double y(node v) const
Returns the y-coordinate of node v.
double x(node v) const
Returns the x-coordinate of node v.
const Graph & constGraph() const
Returns a reference to the associated graph.
void clearAllBends()
Removes all edge bends.
const Graph & original() const
Returns a reference to the original graph.
Definition GraphCopy.h:104
Copies of graphs supporting edge splitting.
Definition GraphCopy.h:390
void setOriginalGraph(const Graph *G) override
Associates the graph copy with G, but does not create any nodes or edges.
void clear() override
Removes all nodes and edges from this copy but does not break the link with the original graph.
Data type for general directed graphs (adjacency list representation).
Definition Graph_d.h:866
int numberOfNodes() const
Returns the number of nodes in the graph.
Definition Graph_d.h:979
node firstNode() const
Returns the first node in the list of all nodes.
Definition Graph_d.h:994
std::pair< int, int > insert(const NI &nodesBegin, const NI &nodesEnd, const EI &edgesBegin, const EI &edgesEnd, NodeArray< node > &nodeMap, EdgeArray< edge > &edgeMap)
Inserts a copy of a given subgraph into this graph.
Interface of general layout algorithms.
static double defaultNodeSeparation()
Returns the global default node separation.
static double defaultNodeWidth()
Returns the global default width for nodes.
static double defaultNodeHeight()
Returns the global default height for nodes.
static double defaultCCSeparation()
Returns the global default separation between connected components.
Doubly linked lists (maintaining the length of the list).
Definition List.h:1451
Encapsulates a pointer to a list element.
Definition List.h:113
Class for the representation of nodes.
Definition Graph_d.h:241
void init(const Base *base=nullptr)
Reinitializes the array. Associates the array with the matching registry of base.
static int numberOfProcessors()
Returns the number of processors (cores) available on the current system.
Definition System.h:275
The tile-to-rows algorithm for packing drawings of connected components.
virtual void call(Array< DPoint > &box, Array< DPoint > &offset, double pageRatio=1.0) override
Arranges the rectangles given by box.
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
Common base class for ogdf::SpringEmbedderBase and ogdf::SpringEmbedderGridVariant.
double maxConvergenceFactor() const
Returns the currently used maximum convergence factor.
void forceModel(SpringForceModel fm)
Sets the used force model to fm.
virtual void callMaster(const GraphCopy &copy, GraphAttributes &attr, DPoint &box)=0
int m_iterationsImprove
The number of iterations for the improvement phase.
SpringForceModel m_forceModelImprove
The used force model.
void userBoundingBox(double xmin, double ymin, double xmax, double ymax)
Sets the user bounding box (used if scaling method is scUserBoundingBox).
double scaleFunctionFactor() const
Returns the current scale function factor.
void forceModelImprove(SpringForceModel fm)
Sets the used force model for the improvement step to fm.
void scaleFunctionFactor(double f)
Sets the scale function factor to f.
Scaling scaling() const
Returns the current scaling method.
void noise(bool on)
Sets the parameter noise to on.
virtual void call(GraphAttributes &GA) override
Computes a layout of graph GA.
SpringForceModel forceModelImprove() const
Returns the currently used force model for the improvement step.
DRect userBoundingBox() const
Gets the user bounding box.
unsigned int m_maxThreads
The maximal number of used threads.
void maxConvergenceFactor(double f)
Sets the maximum convergence factor to f.
bool noise() const
Returns the current setting of noise.
void idealEdgeLength(double len)
Sets the ideal edge length to len.
void minDistCC(double x)
Sets the minimum distance between connected components to x.
bool m_noise
The used force model for the improvement phase.
double m_minDistCC
The minimal distance between connected components.
void avgConvergenceFactor(double f)
Sets the average convergence factor to f.
void iterationsImprove(int i)
Sets the number of iterations for the improvement phase to i.
SpringForceModel forceModel() const
Returns the currently used force model.
void scaling(Scaling sc)
Sets the method for scaling the inital layout to sc.
int iterationsImprove() const
Returns the current setting of iterations for the improvement phase.
double idealEdgeLength() const
Returns the current setting of ideal edge length.
int iterations() const
Returns the current setting of iterations.
unsigned int maxThreads() const
Returns the maximal number of used threads.
double m_idealEdgeLength
The ideal edge length.
double avgConvergenceFactor() const
Returns the currently used average convergence factor.
void maxThreads(unsigned int n)
Sets the maximal number of used threads to n.
double pageRatio()
Returns the page ratio.
void iterations(int i)
Sets the number of iterations to i.
double m_scaleFactor
The factor used if scaling type is scScaleFunction.
void pageRatio(double x)
Sets the page ration to x.
Scaling
The scaling method used by the algorithm.
@ useIdealEdgeLength
use the given ideal edge length to scale the layout suitably.
@ userBoundingBox
bounding box set by userBoundingBox() is used.
@ scaleFunction
automatic scaling is used with parameter set by scaleFunctionFactor() (larger factor,...
double minDistCC() const
Returns the minimum distance between connected components.
int connectedComponents(const Graph &G, NodeArray< int > &component, List< node > *isolated=nullptr, ArrayBuffer< node > *reprs=nullptr)
Computes the connected components of G and optionally generates a list of isolated nodes.
void makeSimpleUndirected(Graph &G)
Removes all self-loops and all but one edge of each bundle of undirected parallel edges.
SpringForceModel
The force model used for computing forces on nodes.
@ FruchtermanReingold
the force model proposed by Fruchterman and Reingold.
The namespace for all OGDF objects.
GenericPoint< double > DPoint
Representing two-dimensional point with real coordinates.
Definition geometry.h:244
HypergraphRegistry< HypernodeElement >::iterator begin(const HypergraphRegistry< HypernodeElement > &self)
bool filter_any_edge(edge e)
std::function<bool(edge)> that returns true for any edge e
HypergraphRegistry< HypernodeElement >::iterator end(const HypergraphRegistry< HypernodeElement > &self)
Declaration of simple graph algorithms.