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/Barrier.h>
36 #include <ogdf/basic/GraphCopy.h>
37 #include <ogdf/basic/Math.h>
39 
40 namespace ogdf {
41 namespace spring_embedder {
42 
44 template<class Master, class NodeInfo>
45 class WorkerBase {
46 public:
47  WorkerBase(unsigned int id, Master& master, int vStartIndex, int vStopIndex, node vStart,
48  node vStop)
49  : m_id(id)
50  , m_master(master)
51  , m_vStartIndex(vStartIndex)
52  , m_vStopIndex(vStopIndex)
53  , m_vStart(vStart)
54  , m_vStop(vStop) { }
55 
56  virtual ~WorkerBase() = default;
57 
58  virtual void operator()() = 0;
59 
60 protected:
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 
76  double m_sumForces;
77  double m_maxForce;
78  double m_sumLengths;
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 }
ogdf
The namespace for all OGDF objects.
Definition: AugmentationModule.h:36
ogdf::GraphAttributes
Stores additional attributes of a graph (like layout information).
Definition: GraphAttributes.h:66
GraphAttributes.h
Declaration of class GraphAttributes which extends a Graph by additional attributes.
ogdf::GenericPoint< double >
ogdf::spring_embedder::WorkerBase::~WorkerBase
virtual ~WorkerBase()=default
ogdf::spring_embedder::WorkerBase::m_sumForces
double m_sumForces
Definition: WorkerBase.h:76
ogdf::spring_embedder::WorkerBase::m_vStartIndex
int m_vStartIndex
Definition: WorkerBase.h:64
ogdf::GraphCopy
Copies of graphs supporting edge splitting.
Definition: GraphCopy.h:384
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:151
ogdf::spring_embedder::WorkerBase::m_maxForce
double m_maxForce
Definition: WorkerBase.h:77
ogdf::spring_embedder::WorkerBase::m_xmin
double m_xmin
Definition: WorkerBase.h:71
ogdf::spring_embedder::WorkerBase::m_ymax
double m_ymax
Definition: WorkerBase.h:74
ogdf::spring_embedder::WorkerBase::m_vStart
node m_vStart
Definition: WorkerBase.h:66
ogdf::spring_embedder::WorkerBase::m_hsum
double m_hsum
Definition: WorkerBase.h:70
ogdf::spring_embedder::WorkerBase::m_id
unsigned int m_id
Definition: WorkerBase.h:61
ogdf::spring_embedder::WorkerBase::m_master
Master & m_master
Definition: WorkerBase.h:62
Barrier.h
Implementation of a thread barrier.
ogdf::spring_embedder::WorkerBase::WorkerBase
WorkerBase(unsigned int id, Master &master, int vStartIndex, int vStopIndex, node vStart, node vStop)
Definition: WorkerBase.h:47
ogdf::Array< NodeInfo >
ogdf::spring_embedder::WorkerBase::m_vStopIndex
int m_vStopIndex
Definition: WorkerBase.h:65
ogdf::GenericPoint::norm
double norm() const
Returns the norm of the point.
Definition: geometry.h:158
ogdf::Math::updateMin
void updateMin(T &min, const T &newValue)
Stores the minimum of min and newValue in min.
Definition: Math.h:98
GraphCopy.h
Declaration of graph copy classes.
ogdf::spring_embedder::WorkerBase::scaling
void scaling(Array< NodeInfo > &vInfo, const Array< int > &adjLists)
Definition: WorkerBase.h:128
ogdf::GraphAttributes::height
double height(node v) const
Returns the height of the bounding box of node v.
Definition: GraphAttributes.h:387
Math.h
Mathematical Helpers.
ogdf::spring_embedder::WorkerBase::m_wsum
double m_wsum
Definition: WorkerBase.h:69
ogdf::spring_embedder::WorkerBase::finalScaling
void finalScaling(Array< NodeInfo > &vInfo, const Array< int > &adjLists)
Definition: WorkerBase.h:80
ogdf::Math::updateMax
void updateMax(T &max, const T &newValue)
Stores the maximum of max and newValue in max.
Definition: Math.h:90
ogdf::spring_embedder::WorkerBase::m_sumLengths
double m_sumLengths
Definition: WorkerBase.h:78
ogdf::spring_embedder::WorkerBase::m_vStop
node m_vStop
Definition: WorkerBase.h:67
ogdf::spring_embedder::WorkerBase::m_ymin
double m_ymin
Definition: WorkerBase.h:73
SpringEmbedderBase.h
Declaration and definition of ogdf::SpringEmbedderBase.
ogdf::NodeElement
Class for the representation of nodes.
Definition: Graph_d.h:233
ogdf::spring_embedder::WorkerBase
Base class for ogdf::SpringEmbedderGridVariant::Worker.
Definition: WorkerBase.h:45
ogdf::spring_embedder::WorkerBase::m_xmax
double m_xmax
Definition: WorkerBase.h:72
ogdf::GraphCopyBase::original
const Graph & original() const
Returns a reference to the original graph.
Definition: GraphCopy.h:98
ogdf::GraphAttributes::width
double width(node v) const
Returns the width of the bounding box of node v.
Definition: GraphAttributes.h:351