Open
Graph Drawing
Framework

 v. 2020.02 (Catalpa)
 

WorkerBase.h
Go to the documentation of this file.
1 
32 #pragma once
33 
34 #include <ogdf/basic/GraphCopy.h>
36 #include <ogdf/basic/Barrier.h>
38 #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, node vStop)
48  : m_id(id), m_master(master), m_vStartIndex(vStartIndex), m_vStopIndex(vStopIndex), m_vStart(vStart), m_vStop(vStop) { }
49 
50  virtual ~WorkerBase() = default;
51 
52  virtual void operator()() = 0;
53 
54 protected:
55  unsigned int m_id;
56  Master &m_master;
57 
62 
63  double m_wsum;
64  double m_hsum;
65  double m_xmin;
66  double m_xmax;
67  double m_ymin;
68  double m_ymax;
69 
70  double m_sumForces;
71  double m_maxForce;
72  double m_sumLengths;
73 
74  void finalScaling(Array<NodeInfo> &vInfo, const Array<int> &adjLists) {
75  m_sumLengths = sumUpLengths(vInfo, adjLists);
76 
77  m_master.syncThreads();
78 
79  if(m_id == 0)
80  m_master.scaleLayout(m_sumLengths);
81 
82  m_master.syncThreads();
83 
84  double s = m_master.scaleFactor();
85 
86  const GraphCopy &gc = m_master.getGraph();
87  GraphAttributes &ga = m_master.getAttributes();
88 
89  double xmin = std::numeric_limits<double>::max(), xmax = std::numeric_limits<double>::lowest();
90  double ymin = std::numeric_limits<double>::max(), ymax = std::numeric_limits<double>::lowest();
91 
92  node v = m_vStart;
93  for(int j = m_vStartIndex; j < m_vStopIndex; ++j) {
94  node vOrig = gc.original(v);
95  NodeInfo &vj = vInfo[j];
96 
97  double xv = s * vj.m_pos.m_x;
98  double yv = s * vj.m_pos.m_y;
99  vj.m_pos.m_x = xv;
100  vj.m_pos.m_y = yv;
101 
102  double wv = ga.width(vOrig);
103  double hv = ga.height(vOrig);
104 
105  Math::updateMin(xmin, xv-0.5*wv);
106  Math::updateMax(xmax, xv+0.5*wv);
107  Math::updateMin(ymin, yv-0.5*hv);
108  Math::updateMax(ymax, yv+0.5*hv);
109  }
110 
111  m_xmin = xmin; m_xmax = xmax;
112  m_ymin = ymin; m_ymax = ymax;
113 
114  m_master.syncThreads();
115  }
116 
117  void scaling(Array<NodeInfo> &vInfo, const Array<int> &adjLists) {
118  m_sumLengths = sumUpLengths(vInfo, adjLists);
119 
120  m_master.syncThreads();
121 
122  if(m_id == 0)
123  m_master.scaleLayout(m_sumLengths);
124 
125  m_master.syncThreads();
126 
127  double s = m_master.scaleFactor();
128  for(int j = m_vStartIndex; j < m_vStopIndex; ++j)
129  vInfo[j].m_pos *= s;
130 
131  if(m_id == 0)
132  m_master.initImprovementPhase();
133 
134  m_master.syncThreads();
135  }
136 
137  double sumUpLengths(Array<NodeInfo> &vInfo, const Array<int> &adjLists) {
138  double sumLengths = 0.0;
139  for(int j = m_vStartIndex; j < m_vStopIndex; ++j) {
140  const NodeInfo &vj = vInfo[j];
141  for(int k = vj.m_adjBegin; k != vj.m_adjStop; ++k) {
142  int u = adjLists[k];
143  if(u < j) {
144  DPoint dist = vj.m_pos - vInfo[u].m_pos;
145  sumLengths += dist.norm();
146  }
147  }
148  }
149 
150  return sumLengths;
151  }
152 };
153 
154 }
155 }
double width(node v) const
Returns the width of the bounding box of node v.
Declaration of class GraphAttributes which extends a Graph by additional attributes.
double height(node v) const
Returns the height of the bounding box of node v.
void updateMin(T &min, const T &newValue)
Stores the minimum of min and newValue in min.
Definition: Math.h:101
Mathematical Helpers.
Implementation of a thread barrier.
Stores additional attributes of a graph (like layout information).
Declaration of graph copy classes.
double sumUpLengths(Array< NodeInfo > &vInfo, const Array< int > &adjLists)
Definition: WorkerBase.h:137
Copies of graphs supporting edge splitting.
Definition: GraphCopy.h:249
void finalScaling(Array< NodeInfo > &vInfo, const Array< int > &adjLists)
Definition: WorkerBase.h:74
Class for the representation of nodes.
Definition: Graph_d.h:169
const Graph & original() const
Returns a reference to the original graph.
Definition: GraphCopy.h:286
void scaling(Array< NodeInfo > &vInfo, const Array< int > &adjLists)
Definition: WorkerBase.h:117
The namespace for all OGDF objects.
WorkerBase(unsigned int id, Master &master, int vStartIndex, int vStopIndex, node vStart, node vStop)
Definition: WorkerBase.h:47
Declaration and definition of ogdf::SpringEmbedderBase.
Base class for ogdf::SpringEmbedderGridVariant::Worker.
Definition: WorkerBase.h:45
void updateMax(T &max, const T &newValue)
Stores the maximum of max and newValue in max.
Definition: Math.h:93
double norm() const
Returns the norm of the point.
Definition: geometry.h:159