Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
WorkerBase.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>
38#include <ogdf/basic/Math.h>
39#include <ogdf/basic/geometry.h>
40
41#include <limits>
42
43namespace ogdf {
44namespace spring_embedder {
45
47template<class Master, class NodeInfo>
49public:
50 WorkerBase(unsigned int id, Master& master, int vStartIndex, int vStopIndex, node vStart,
51 node vStop)
52 : m_id(id)
53 , m_master(master)
54 , m_vStartIndex(vStartIndex)
55 , m_vStopIndex(vStopIndex)
56 , m_vStart(vStart)
57 , m_vStop(vStop) { }
58
59 virtual ~WorkerBase() = default;
60
61 virtual void operator()() = 0;
62
63protected:
64 unsigned int m_id;
65 Master& m_master;
66
71
72 double m_wsum;
73 double m_hsum;
74 double m_xmin;
75 double m_xmax;
76 double m_ymin;
77 double m_ymax;
78
80 double m_maxForce;
82
83 void finalScaling(Array<NodeInfo>& vInfo, const Array<int>& adjLists) {
84 m_sumLengths = sumUpLengths(vInfo, adjLists);
85
86 m_master.syncThreads();
87
88 if (m_id == 0) {
89 m_master.scaleLayout(m_sumLengths);
90 }
91
92 m_master.syncThreads();
93
94 double s = m_master.scaleFactor();
95
96 const GraphCopy& gc = m_master.getGraph();
97 GraphAttributes& ga = m_master.getAttributes();
98
99 double xmin = std::numeric_limits<double>::max(),
100 xmax = std::numeric_limits<double>::lowest();
101 double ymin = std::numeric_limits<double>::max(),
102 ymax = std::numeric_limits<double>::lowest();
103
104 node v = m_vStart;
105 for (int j = m_vStartIndex; j < m_vStopIndex; ++j) {
106 node vOrig = gc.original(v);
107 NodeInfo& vj = vInfo[j];
108
109 double xv = s * vj.m_pos.m_x;
110 double yv = s * vj.m_pos.m_y;
111 vj.m_pos.m_x = xv;
112 vj.m_pos.m_y = yv;
113
114 double wv = ga.width(vOrig);
115 double hv = ga.height(vOrig);
116
117 Math::updateMin(xmin, xv - 0.5 * wv);
118 Math::updateMax(xmax, xv + 0.5 * wv);
119 Math::updateMin(ymin, yv - 0.5 * hv);
120 Math::updateMax(ymax, yv + 0.5 * hv);
121 }
122
123 m_xmin = xmin;
124 m_xmax = xmax;
125 m_ymin = ymin;
126 m_ymax = ymax;
127
128 m_master.syncThreads();
129 }
130
131 void scaling(Array<NodeInfo>& vInfo, const Array<int>& adjLists) {
132 m_sumLengths = sumUpLengths(vInfo, adjLists);
133
134 m_master.syncThreads();
135
136 if (m_id == 0) {
137 m_master.scaleLayout(m_sumLengths);
138 }
139
140 m_master.syncThreads();
141
142 double s = m_master.scaleFactor();
143 for (int j = m_vStartIndex; j < m_vStopIndex; ++j) {
144 vInfo[j].m_pos *= s;
145 }
146
147 if (m_id == 0) {
148 m_master.initImprovementPhase();
149 }
150
151 m_master.syncThreads();
152 }
153
154 double sumUpLengths(Array<NodeInfo>& vInfo, const Array<int>& adjLists) {
155 double sumLengths = 0.0;
156 for (int j = m_vStartIndex; j < m_vStopIndex; ++j) {
157 const NodeInfo& vj = vInfo[j];
158 for (int k = vj.m_adjBegin; k != vj.m_adjStop; ++k) {
159 int u = adjLists[k];
160 if (u < j) {
161 DPoint dist = vj.m_pos - vInfo[u].m_pos;
162 sumLengths += dist.norm();
163 }
164 }
165 }
166
167 return sumLengths;
168 }
169};
170
171}
172}
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.
Mathematical Helpers.
Declaration of classes GenericPoint, GenericPolyline, GenericLine, GenericSegment,...
The parameterized class Array implements dynamic arrays of type E.
Definition Array.h:219
double norm() const
Returns the norm of the point.
Definition geometry.h:165
Stores additional attributes of a graph (like layout information).
double height(node v) const
Returns the height of the bounding box of node v.
double width(node v) const
Returns the width of the bounding box of node v.
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
Class for the representation of nodes.
Definition Graph_d.h:241
Base class for ogdf::SpringEmbedderGridVariant::Worker.
Definition WorkerBase.h:48
void finalScaling(Array< NodeInfo > &vInfo, const Array< int > &adjLists)
Definition WorkerBase.h:83
void scaling(Array< NodeInfo > &vInfo, const Array< int > &adjLists)
Definition WorkerBase.h:131
double sumUpLengths(Array< NodeInfo > &vInfo, const Array< int > &adjLists)
Definition WorkerBase.h:154
WorkerBase(unsigned int id, Master &master, int vStartIndex, int vStopIndex, node vStart, node vStop)
Definition WorkerBase.h:50
void updateMin(T &min, const T &newValue)
Stores the minimum of min and newValue in min.
Definition Math.h:102
void updateMax(T &max, const T &newValue)
Stores the maximum of max and newValue in max.
Definition Math.h:94
The namespace for all OGDF objects.