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