Force Directed Edge Bundling
 All Classes Functions Pages
graph.h
1 #pragma once
2 #include <QList>
3 #include <QPoint>
4 #include <QString>
5 #include <QVector2D>
6 #include <QPolygon>
7 
11 class Node: public QVector2D {
12 protected:
13  int degree;
14  int group;
15  QString description;
16 public:
20  Node(): QVector2D(), degree(0), group(-1) {};
26  Node(double x, double y): QVector2D(x, y), degree(0), group(-1) {};
27  ~Node(void) {};
28  operator QVector2D() {return QVector2D(x(), y());};
29  void set(double x, double y) {setX(x); setY(y);};
30  void set(QPointF p) {setX(p.x()); setY(p.y());};
31  void set(QVector2D p) {setX(p.x()); setY(p.y());};
32 
37  void setGroup(int g) {group = g;};
42  int getGroup(void) {return group;};
43 
45  void increment(void) {degree++;};
47  int getDegree(void) {return degree;};
49  void setInfo(QString s) {description = s;};
51  QString info() {return description;};
52  QString toString() {return QString("[") += QString::number(x()) += QString(",") += QString::number(y())+= QString("]");};
53 };
54 
58 class Edge {
59 protected:
60  Node* node_start;
61  Node* node_end;
62  QPolygonF subdivisionPoints;
63  QPolygonF newSubdivisionPoints;
64 
65 public:
66  Edge() {};
72  Edge(Node* n1, Node* n2) {
73  node_start = n1;
74  node_end = n2;
75  subdivisionPoints << n1->toPointF() << n2->toPointF();
76  };
77 
78  ~Edge(void){};
79 
84  void setNewSubdivisionPoints(QPolygonF p){newSubdivisionPoints = p;};
86  void updateSubdivisionPoints(){subdivisionPoints = newSubdivisionPoints; newSubdivisionPoints = QPolygonF();};
87 
89  QPolygonF getSubdivisionPoints() {return subdivisionPoints;};
90  void clearSubdivisionPoints() {subdivisionPoints.clear();};
91 
92  Node* start(void) {return node_start;};
93  Node* end(void) {return node_end;};
94  QVector2D midPoint(void) {return (*start() + *end())/2.0;};
95  QVector2D vector(void) {return *end() - *start();};
96  double length(void) {return vector().length();};
97 
98  void increaseSubdivisions(void);
99  void increaseSubdivisions(int numSubdivisions);
100  double compatibility(Edge* other);
101  QString toString(void) {return this->start()->toString() + " -> " + this->end()->toString();};
102 protected:
103  /* COMPATIBILITY CALCULATION FUNCTIONS */
104  double compatibility_angular(Edge* other);
105  double compatibility_scale(Edge* other);
106  double compatibility_positional(Edge* other);
107  double compatibility_visibility(Edge* other);
108  double visibilityFactor(Edge* other);
109  QPair<QVector2D,QVector2D> bandOfSight(Edge* other);
110 };
111 
112 /*
113  * Datastructure for one Graph instance
114 **/
115 class Graph {
116 public:
117  Graph(void) {};
118  ~Graph(void) {
119  qDeleteAll(edges.begin(), edges.end());
120  edges.clear();
121 
122  qDeleteAll(nodes.begin(), nodes.end());
123  nodes.clear();
124  };
125  void clear(void) {
126  for (int i=0; i<edges.count(); i++)
127  delete (edges.takeAt(0));
128  edges.clear();
129 
130  for (int i=0; i<nodes.count(); i++)
131  delete (nodes.takeAt(0));
132  nodes.clear();
133  }
134 
136  QList<Node*>* getNodes() {return &nodes;};
138  QList<Edge*>* getEdges() {return &edges;};
140  void addNode(Node* n) {nodes<<n;};
142  void addEdge(Edge* e) {edges<<e;};
143 
144 protected:
145  QList<Node*> nodes;
146  QList<Edge*> edges;
147 
148 public:
150  static QVector2D midPoint(QVector2D a, QVector2D b) {return (a + b) / 2.0;};
152  static QPointF midPoint(QPointF a, QPointF b) {return (a + b) / 2.0;};
153 };
QPair< QVector2D, QVector2D > bandOfSight(Edge *other)
Definition: graph.cpp:150
QList< Node * > * getNodes()
Definition: graph.h:136
double compatibility_angular(Edge *other)
Definition: graph.cpp:71
QString info()
Definition: graph.h:51
Definition: graph.h:11
void setInfo(QString s)
Definition: graph.h:49
double compatibility(Edge *other)
Definition: graph.cpp:57
double visibilityFactor(Edge *other)
Definition: graph.cpp:136
static QVector2D midPoint(QVector2D a, QVector2D b)
Definition: graph.h:150
double compatibility_positional(Edge *other)
Definition: graph.cpp:102
void setNewSubdivisionPoints(QPolygonF p)
Definition: graph.h:84
Definition: graph.h:115
Definition: graph.h:58
int getDegree(void)
Definition: graph.h:47
void increaseSubdivisions(void)
Definition: graph.cpp:7
void addEdge(Edge *e)
Definition: graph.h:142
void setGroup(int g)
Definition: graph.h:37
int getGroup(void)
Definition: graph.h:42
double compatibility_visibility(Edge *other)
Definition: graph.cpp:119
void updateSubdivisionPoints()
Definition: graph.h:86
void increment(void)
Definition: graph.h:45
Node(double x, double y)
Definition: graph.h:26
static QPointF midPoint(QPointF a, QPointF b)
Definition: graph.h:152
QPolygonF getSubdivisionPoints()
Definition: graph.h:89
double compatibility_scale(Edge *other)
Definition: graph.cpp:86
QList< Edge * > * getEdges()
Definition: graph.h:138
Edge(Node *n1, Node *n2)
Definition: graph.h:72
Node()
Definition: graph.h:20
void addNode(Node *n)
Definition: graph.h:140