Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

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>
37 #include <ogdf/basic/GraphCopy.h>
38 #include <ogdf/basic/Math.h>
39 #include <ogdf/basic/geometry.h>
40 
41 #include <limits>
42 
43 namespace ogdf {
44 namespace spring_embedder {
45 
47 template<class Master, class NodeInfo>
48 class WorkerBase {
49 public:
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 
63 protected:
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 
79  double m_sumForces;
80  double m_maxForce;
81  double m_sumLengths;
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 }
ogdf
The namespace for all OGDF objects.
Definition: multilevelmixer.cpp:39
ogdf::GraphAttributes
Stores additional attributes of a graph (like layout information).
Definition: GraphAttributes.h:72
GraphAttributes.h
Declaration of class GraphAttributes which extends a Graph by additional attributes.
Graph.h
Includes declaration of graph class.
ogdf::GenericPoint< double >
ogdf::spring_embedder::WorkerBase::~WorkerBase
virtual ~WorkerBase()=default
geometry.h
Declaration of classes GenericPoint, GenericPolyline, GenericLine, GenericSegment,...
ogdf::spring_embedder::WorkerBase::m_sumForces
double m_sumForces
Definition: WorkerBase.h:79
ogdf::spring_embedder::WorkerBase::m_vStartIndex
int m_vStartIndex
Definition: WorkerBase.h:67
ogdf::GraphCopy
Copies of graphs supporting edge splitting.
Definition: GraphCopy.h:391
ogdf::spring_embedder::WorkerBase::operator()
virtual void operator()()=0
ogdf::spring_embedder::WorkerBase::sumUpLengths
double sumUpLengths(Array< NodeInfo > &vInfo, const Array< int > &adjLists)
Definition: WorkerBase.h:154
ogdf::spring_embedder::WorkerBase::m_maxForce
double m_maxForce
Definition: WorkerBase.h:80
ogdf::spring_embedder::WorkerBase::m_xmin
double m_xmin
Definition: WorkerBase.h:74
ogdf::spring_embedder::WorkerBase::m_ymax
double m_ymax
Definition: WorkerBase.h:77
ogdf::spring_embedder::WorkerBase::m_vStart
node m_vStart
Definition: WorkerBase.h:69
ogdf::spring_embedder::WorkerBase::m_hsum
double m_hsum
Definition: WorkerBase.h:73
ogdf::spring_embedder::WorkerBase::m_id
unsigned int m_id
Definition: WorkerBase.h:64
ogdf::spring_embedder::WorkerBase::m_master
Master & m_master
Definition: WorkerBase.h:65
ogdf::spring_embedder::WorkerBase::WorkerBase
WorkerBase(unsigned int id, Master &master, int vStartIndex, int vStopIndex, node vStart, node vStop)
Definition: WorkerBase.h:50
ogdf::Array< NodeInfo >
ogdf::spring_embedder::WorkerBase::m_vStopIndex
int m_vStopIndex
Definition: WorkerBase.h:68
ogdf::GenericPoint::norm
double norm() const
Returns the norm of the point.
Definition: geometry.h:165
ogdf::Math::updateMin
void updateMin(T &min, const T &newValue)
Stores the minimum of min and newValue in min.
Definition: Math.h:102
GraphCopy.h
Declaration of graph copy classes.
ogdf::spring_embedder::WorkerBase::scaling
void scaling(Array< NodeInfo > &vInfo, const Array< int > &adjLists)
Definition: WorkerBase.h:131
ogdf::GraphAttributes::height
double height(node v) const
Returns the height of the bounding box of node v.
Definition: GraphAttributes.h:393
Math.h
Mathematical Helpers.
ogdf::spring_embedder::WorkerBase::m_wsum
double m_wsum
Definition: WorkerBase.h:72
ogdf::spring_embedder::WorkerBase::finalScaling
void finalScaling(Array< NodeInfo > &vInfo, const Array< int > &adjLists)
Definition: WorkerBase.h:83
ogdf::Math::updateMax
void updateMax(T &max, const T &newValue)
Stores the maximum of max and newValue in max.
Definition: Math.h:94
Array.h
Declaration and implementation of Array class and Array algorithms.
ogdf::spring_embedder::WorkerBase::m_sumLengths
double m_sumLengths
Definition: WorkerBase.h:81
ogdf::spring_embedder::WorkerBase::m_vStop
node m_vStop
Definition: WorkerBase.h:70
ogdf::spring_embedder::WorkerBase::m_ymin
double m_ymin
Definition: WorkerBase.h:76
ogdf::NodeElement
Class for the representation of nodes.
Definition: Graph_d.h:240
ogdf::spring_embedder::WorkerBase
Base class for ogdf::SpringEmbedderGridVariant::Worker.
Definition: WorkerBase.h:48
ogdf::spring_embedder::WorkerBase::m_xmax
double m_xmax
Definition: WorkerBase.h:75
ogdf::GraphCopyBase::original
const Graph & original() const
Returns a reference to the original graph.
Definition: GraphCopy.h:105
ogdf::GraphAttributes::width
double width(node v) const
Returns the width of the bounding box of node v.
Definition: GraphAttributes.h:357