Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

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 public:
43  CommonForceModelBase(const Array<NodeInfo>& vInfo, const Array<int>& adjLists,
44  double idealEdgeLength)
45  : m_vInfo(vInfo), m_adjLists(adjLists), m_idealEdgeLength(idealEdgeLength) { }
46 
47  double eps() const { return 0.01 * m_idealEdgeLength; }
48 
49 protected:
52 
54 
55  double normByIdealEdgeLength(double norm) const {
56  return (norm + eps()) / (m_idealEdgeLength + eps());
57  }
58 
59  DPoint computeFruchtermanReingoldAttractiveForce(int j, int idealExponent) const {
60  const NodeInfo& vj = m_vInfo[j];
61 
62  // attractive forces on j: F_attr(d) = -d^2 / iel
63  DPoint force(0, 0);
64  for (int i = vj.m_adjBegin; i != vj.m_adjStop; ++i) {
65  int u = m_adjLists[i];
66 
67  DPoint dist = vj.m_pos - m_vInfo[u].m_pos;
68  double d = dist.norm();
69 
70  dist *= d;
71  force -= dist;
72  }
73 
74  force /= std::pow(m_idealEdgeLength, idealExponent);
75 
76  return force;
77  }
78 };
79 
80 }
81 }
ogdf
The namespace for all OGDF objects.
Definition: AugmentationModule.h:36
ogdf::spring_embedder::CommonForceModelBase::eps
double eps() const
Definition: common.h:47
ogdf::GenericPoint< double >
ogdf::spring_embedder::CommonForceModelBase::m_adjLists
const Array< int > & m_adjLists
Definition: common.h:51
geometry.h
Declaration of classes GenericPoint, GenericPolyline, GenericLine, GenericSegment,...
ogdf::spring_embedder::CommonForceModelBase
Definition: common.h:41
ogdf::spring_embedder::CommonForceModelBase::computeFruchtermanReingoldAttractiveForce
DPoint computeFruchtermanReingoldAttractiveForce(int j, int idealExponent) const
Definition: common.h:59
ogdf::spring_embedder::CommonForceModelBase::normByIdealEdgeLength
double normByIdealEdgeLength(double norm) const
Definition: common.h:55
ogdf::Array< NodeInfo >
ogdf::GenericPoint::norm
double norm() const
Returns the norm of the point.
Definition: geometry.h:158
ogdf::spring_embedder::CommonForceModelBase::m_vInfo
const Array< NodeInfo > & m_vInfo
Definition: common.h:50
basic.h
Basic declarations, included by all source files.
ogdf::spring_embedder::CommonForceModelBase::m_idealEdgeLength
double m_idealEdgeLength
Definition: common.h:53
ogdf::spring_embedder::CommonForceModelBase::CommonForceModelBase
CommonForceModelBase(const Array< NodeInfo > &vInfo, const Array< int > &adjLists, double idealEdgeLength)
Definition: common.h:43