Open
Graph Drawing
Framework

 v. snapshot-2017-02-16
 

common.h
Go to the documentation of this file.
1 
32 #pragma once
33 
34 #include <ogdf/basic/basic.h>
35 #include <ogdf/basic/geometry.h>
36 
37 namespace ogdf {
38 namespace spring_embedder {
39 
40 template<typename NodeInfo>
42 {
43 public:
44  CommonForceModelBase(const Array<NodeInfo> &vInfo, const Array<int> &adjLists, double idealEdgeLength) :
45  m_vInfo(vInfo),
46  m_adjLists(adjLists),
47  m_idealEdgeLength(idealEdgeLength)
48  {
49  }
50 
51  double eps() const { return 0.01*m_idealEdgeLength; }
52 
53 protected:
56 
58 
59  double normByIdealEdgeLength(double norm) const
60  {
61  return (norm + eps()) / (m_idealEdgeLength + eps());
62  }
63 
64  DPoint computeFruchtermanReingoldAttractiveForce(int j, int idealExponent) const
65  {
66  const NodeInfo &vj = m_vInfo[j];
67 
68  // attractive forces on j: F_attr(d) = -d^2 / iel
69  DPoint force(0, 0);
70  for (int i = vj.m_adjBegin; i != vj.m_adjStop; ++i) {
71  int u = m_adjLists[i];
72 
73  DPoint dist = vj.m_pos - m_vInfo[u].m_pos;
74  double d = dist.norm();
75 
76  dist *= d;
77  force -= dist;
78  }
79 
80  force /= std::pow(m_idealEdgeLength, idealExponent);
81 
82  return force;
83  }
84 };
85 
86 }
87 }
double norm() const
Returns the norm of the point.
Definition: geometry.h:237
Real points.
Definition: geometry.h:219
DPoint computeFruchtermanReingoldAttractiveForce(int j, int idealExponent) const
Definition: common.h:64
CommonForceModelBase(const Array< NodeInfo > &vInfo, const Array< int > &adjLists, double idealEdgeLength)
Definition: common.h:44
Basic declarations, included by all source files.
double normByIdealEdgeLength(double norm) const
Definition: common.h:59
The namespace for all OGDF objects.
Declaration of classes DPoint, DPolyline, DLine, DRect, DIntersectableRect, DScaler.
const Array< NodeInfo > & m_vInfo
Definition: common.h:54