Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
common.h
Go to the documentation of this file.
1
32#pragma once
33
34#include <ogdf/basic/Array.h>
35#include <ogdf/basic/geometry.h>
36
37#include <cmath>
38
39namespace ogdf {
40namespace spring_embedder {
41
42template<typename NodeInfo>
44public:
45 CommonForceModelBase(const Array<NodeInfo>& vInfo, const Array<int>& adjLists,
46 double idealEdgeLength)
47 : m_vInfo(vInfo), m_adjLists(adjLists), m_idealEdgeLength(idealEdgeLength) { }
48
49 double eps() const { return 0.01 * m_idealEdgeLength; }
50
51protected:
54
56
57 double normByIdealEdgeLength(double norm) const {
58 return (norm + eps()) / (m_idealEdgeLength + eps());
59 }
60
61 DPoint computeFruchtermanReingoldAttractiveForce(int j, int idealExponent) const {
62 const NodeInfo& vj = m_vInfo[j];
63
64 // attractive forces on j: F_attr(d) = -d^2 / iel
65 DPoint force(0, 0);
66 for (int i = vj.m_adjBegin; i != vj.m_adjStop; ++i) {
67 int u = m_adjLists[i];
68
69 DPoint dist = vj.m_pos - m_vInfo[u].m_pos;
70 double d = dist.norm();
71
72 dist *= d;
73 force -= dist;
74 }
75
76 force /= std::pow(m_idealEdgeLength, idealExponent);
77
78 return force;
79 }
80};
81
82}
83}
Declaration and implementation of Array class and Array algorithms.
Declaration of classes GenericPoint, GenericPolyline, GenericLine, GenericSegment,...
The parameterized class Array implements dynamic arrays of type E.
Definition Array.h:219
double norm() const
Returns the norm of the point.
Definition geometry.h:165
double normByIdealEdgeLength(double norm) const
Definition common.h:57
CommonForceModelBase(const Array< NodeInfo > &vInfo, const Array< int > &adjLists, double idealEdgeLength)
Definition common.h:45
DPoint computeFruchtermanReingoldAttractiveForce(int j, int idealExponent) const
Definition common.h:61
const Array< NodeInfo > & m_vInfo
Definition common.h:52
The namespace for all OGDF objects.