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
39
40namespace ogdf {
41namespace spring_embedder {
42
45public:
53
86
87 virtual void call(GraphAttributes& GA) override {
88 const Graph& G = GA.constGraph();
89 if (G.empty()) {
90 return;
91 }
92
93 // all edges straight-line
94 GA.clearAllBends();
95
97 GC.createEmpty(G);
98
99 // compute connected component of G
100 NodeArray<int> component(G);
101 int numCC = connectedComponents(G, component);
102
103 // intialize the array of lists of nodes contained in a CC
104 Array<List<node>> nodesInCC(numCC);
105
106 for (node v : G.nodes) {
107 nodesInCC[component[v]].pushBack(v);
108 }
109
111 Array<DPoint> boundingBox(numCC);
112
113 for (int i = 0; i < numCC; ++i) {
114 GC.initByNodes(nodesInCC[i], auxCopy);
116
117 const int n = GC.numberOfNodes();
118
119 // special case: just one node
120 if (n == 1) {
121 node vOrig = GC.original(GC.firstNode());
122 GA.x(vOrig) = GA.y(vOrig) = 0;
123 boundingBox[i] = DPoint(0, 0);
124 continue;
125 }
126
127 callMaster(GC, GA, boundingBox[i]);
128 //std::cout << "avg. force: " << master.avgDisplacement() << std::endl;
129 //std::cout << "max. force: " << master.maxDisplacement() << std::endl;
130 }
131
132 Array<DPoint> offset(numCC);
134 packer.call(boundingBox, offset, m_pageRatio);
135
136 // The arrangement is given by offset to the origin of the coordinate
137 // system. We still have to shift each node and edge by the offset
138 // of its connected component.
139
140 for (int i = 0; i < numCC; ++i) {
141 const List<node>& nodes = nodesInCC[i];
142
143 const double dx = offset[i].m_x;
144 const double dy = offset[i].m_y;
145
146 // iterate over all nodes in ith CC
148 for (node v : nodes) {
149 GA.x(v) += dx;
150 GA.y(v) += dy;
151 }
152 }
153 }
154
157
160
163
166
168
174
176 void avgConvergenceFactor(double f) {
177 if (f >= 0) {
179 }
180 }
181
183
189
191 void maxConvergenceFactor(double f) {
192 if (f >= 0) {
194 }
195 }
196
198
202 int iterations() const { return m_iterations; }
203
205 void iterations(int i) {
206 if (i >= 0) {
207 m_iterations = i;
208 }
209 }
210
213
215 void iterationsImprove(int i) {
216 if (i >= 0) {
218 }
219 }
220
221 double coolDownFactor() const { return m_coolDownFactor; }
222
223 double forceLimitStep() const { return m_forceLimitStep; }
224
226 double idealEdgeLength() const { return m_idealEdgeLength; }
227
229
233 void idealEdgeLength(double len) { m_idealEdgeLength = len; }
234
236 bool noise() const { return m_noise; }
237
239 void noise(bool on) { m_noise = on; }
240
242 double minDistCC() const { return m_minDistCC; }
243
245 void minDistCC(double x) { m_minDistCC = x; }
246
248 double pageRatio() { return m_pageRatio; }
249
251 void pageRatio(double x) { m_pageRatio = x; }
252
254 Scaling scaling() const { return m_scaling; }
255
258
260 double scaleFunctionFactor() const { return m_scaleFactor; }
261
264
266 void userBoundingBox(double xmin, double ymin, double xmax, double ymax) {
268 }
269
272
274 unsigned int maxThreads() const { return m_maxThreads; }
275
277 void maxThreads(unsigned int n) { m_maxThreads = n; }
278
279protected:
280 virtual void callMaster(const GraphCopy& copy, GraphAttributes& attr, DPoint& box) = 0;
281
287
289
292 bool m_noise;
293
296
298
299 double m_minDistCC;
300 double m_pageRatio;
301
304
305 unsigned int m_maxThreads;
306};
307
308}
309}
Declaration of graph copy classes.
Declaration of interface for layout algorithms (class LayoutModule)
Declaration of SpringForceModel enumeration.
Declaration of class TileToRowsCCPacker.
The parameterized class Array implements dynamic arrays of type E.
Definition Array.h:214
Rectangles with real coordinates.
Definition geometry.h:790
Dynamic arrays indexed with edges.
Definition EdgeArray.h:125
Stores additional attributes of a graph (like layout information).
Copies of graphs supporting edge splitting.
Definition GraphCopy.h:254
void createEmpty(const Graph &G)
Associates the graph copy with G, but does not create any nodes or edges.
Data type for general directed graphs (adjacency list representation).
Definition Graph_d.h:521
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:1435
Encapsulates a pointer to a list element.
Definition List.h:103
Dynamic arrays indexed with nodes.
Definition NodeArray.h:125
Class for the representation of nodes.
Definition Graph_d.h:177
static int numberOfProcessors()
Returns the number of processors (cores) available on the current system.
Definition System.h:273
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.
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)
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.
static MultilevelBuilder * getDoubleFactoredZeroAdjustedMerger()
The namespace for all OGDF objects.
GenericPoint< double > DPoint
Representing two-dimensional point with real coordinates.
Definition geometry.h:236
Declaration of simple graph algorithms.