Adaptagrams
graphs.h
1 /*
2  * vim: ts=4 sw=4 et tw=0 wm=0
3  *
4  * libdialect - A library for computing DiAlEcT layouts:
5  * D = Decompose/Distribute
6  * A = Arrange
7  * E = Expand/Emend
8  * T = Transform
9  *
10  * Copyright (C) 2018 Monash University
11  *
12  * This library is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU Lesser General Public
14  * License as published by the Free Software Foundation; either
15  * version 2.1 of the License, or (at your option) any later version.
16  * See the file LICENSE.LGPL distributed with the library.
17  *
18  * This library is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
21  *
22  * Author(s): Steve Kieffer <http://skieffer.info>
23 */
24 
25 #ifndef DIALECT_GRAPHS_H
26 #define DIALECT_GRAPHS_H
27 
28 #include <vector>
29 #include <cfloat>
30 #include <string>
31 #include <map>
32 #include <utility>
33 #include <stack>
34 #include <deque>
35 #include <functional>
36 
37 #include "libvpsc/rectangle.h"
38 #include "libcola/compound_constraints.h"
39 #include "libcola/cluster.h"
40 #include "libcola/cola.h"
41 #include "libavoid/libavoid.h"
42 
43 #include "libdialect/commontypes.h"
44 #include "libdialect/constraints.h"
45 #include "libdialect/routing.h"
46 #include "libdialect/ortho.h"
47 #include "libdialect/logging.h"
48 
49 namespace dialect {
50 
52 struct BoundingBox {
53 
60  BoundingBox(double x, double X, double y, double Y) :
61  x(x), X(X), y(y), Y(Y) {}
62 
68  BoundingBox(void) :
69  x(DBL_MAX), X(-DBL_MAX), y(DBL_MAX), Y(-DBL_MAX) {}
70 
72  BoundingBox &operator+=(const BoundingBox &rhs);
73 
75  std::string repr(void) const;
76 
78  double w(void) const { return X - x; }
79 
81  double h(void) const { return Y - y; }
82 
86  interval getInterval(vpsc::Dim dim) { return dim == vpsc::XDIM ? std::make_pair(x, X) : std::make_pair(y, Y); }
87 
89  Avoid::Point centre(void) const { return Avoid::Point((x+X)/2.0, (y+Y)/2.0); }
90 
92  LineSegment_SP buildSideSegment(CardinalDir side) const;
93 
95  double perimeter(void) const { return 2*(w() + h()); }
96 
97  double x;
98  double X;
99  double y;
100  double Y;
101 };
102 
105 struct ColaOptions {
108  double idealEdgeLength = 0;
110  bool preventOverlaps = false;
113  bool solidifyAlignedEdges = false;
117  bool xAxis = true;
119  bool yAxis = true;
121  bool makeFeasible = false;
125  double makeFeasible_yBorder = 0;
128  bool useNeighbourStress = false;
132  double nbrStressIELScalar = 1/20.0;
135  bool useMajorization = false;
137  bool useScaling = false;
143  std::vector<NodesById> nodeClusters;
147  cola::EdgeLengths eLengths = cola::StandardEdgeLengths;
148  cola::TestConvergence* doneTest = nullptr;
149  cola::PreIteration* preIteration = nullptr;
151  Logger *logger = nullptr;
152 };
153 
157 struct ColaGraphRep {
158  vpsc::Rectangles rs;
159  std::vector<cola::Edge> es;
160  cola::RootCluster *rc = nullptr;
162  std::map<id_type, size_t> id2ix;
164  std::map<size_t, id_type> ix2id;
165 };
166 
169 struct NodeIdCmp {
170  bool operator()(id_type i, const std::pair<id_type, Node_SP> &p) const {
171  return i < p.first;
172  }
173  bool operator()(const std::pair<id_type, Node_SP> &p, id_type i) const {
174  return p.first < i;
175  }
176 };
177 
180 class Graph {
181 public:
183  Graph(void) : m_sepMatrix(this) {}
184 
186  Graph(const Graph &G);
187 
189  ~Graph(void);
190 
192  friend void swap(Graph &first, Graph &second) {
193  using std::swap;
194  swap(first.m_debugOutputPath, second.m_debugOutputPath);
195  swap(first.m_projectionDebugLevel, second.m_projectionDebugLevel);
196  swap(first.m_sepMatrix, second.m_sepMatrix);
197  swap(first.m_iel, second.m_iel);
198  swap(first.m_cgr, second.m_cgr);
199  swap(first.m_needNewRectangles, second.m_needNewRectangles);
200  swap(first.m_cfdl, second.m_cfdl);
201  swap(first.m_nodes, second.m_nodes);
202  swap(first.m_edges, second.m_edges);
203  swap(first.m_maxDeg, second.m_maxDeg);
204  }
205 
208  Graph &operator=(const Graph other);
209 
217  unsigned getMaxDegree(void) const;
218 
224  void addNode(Node_SP node, bool takeOwnership = true);
225 
228  Node_SP addNode(void);
229 
234  Node_SP addNode(double w, double h);
235 
242  Node_SP addNode(double cx, double cy, double w, double h);
243 
249  void addEdge(Edge_SP edge, bool takeOwnership = true);
250 
256  Edge_SP addEdge(Node_SP src, Node_SP tgt);
257 
263  Edge_SP addEdge(const id_type &srcID, const id_type &tgtID);
264 
268  bool hasNode(const id_type &id) const;
269 
273  bool hasEdge(const id_type &id) const;
274 
281  void severEdge(dialect::Edge &edge);
282 
291  void severNode(const dialect::Node &node);
292 
297  std::vector<Node_SP> severNodeNotingNeighbours(const dialect::Node &node);
298 
307  void removeNode(const dialect::Node &node);
308 
314  void removeNodes(const NodesById &nodes);
315 
320  void severAndRemoveNode(const dialect::Node &node);
321 
326  void severAndRemoveNode(id_type nodeID);
327 
332  Nodes cloneNode(id_type id);
333 
339  Node_SP getNode(const id_type &id) const;
340 
342  const NodesById &getNodeLookup(void) const { return m_nodes; }
343 
345  NodesById getNodeLookupWithIgnore(const Nodes &ignore) const;
346 
348  NodesById getNodeLookupWithIgnore(const NodesById &ignore) const;
349 
351  const EdgesById &getEdgeLookup(void) const { return m_edges; }
352 
354  size_t getNumNodes(void) const { return m_nodes.size(); }
355 
357  size_t getNumEdges(void) const { return m_edges.size(); }
358 
360  bool isEmpty(void) const { return m_nodes.empty(); }
361 
363  bool isTree(void) const { return getNumEdges() == getNumNodes() - 1; }
364 
369  double computeAvgNodeDim(void) const;
370 
381  double getIEL(void);
382 
389  double recomputeIEL(void);
390 
401  const NodesById &ignore = NodesById(),
402  bool includeBends = false
403  ) const;
404 
411  std::vector<Graph_SP> getConnComps(void) const;
412 
418  void getChainsAndCycles(std::vector<std::deque<Node_SP>> &chains, std::vector<std::deque<Node_SP>> &cycles);
419 
425  std::string writeTglf(bool useExternalIds = false) const;
426 
432  std::string writeSvg(bool useExternalIds = false) const;
433 
437  std::string writeId2Ix(void) const;
438 
442  std::string writeIx2Id(void) const;
443 
452  void rotate90cw(ColaOptions *opts=nullptr);
453 
462  void rotate90acw(ColaOptions *opts=nullptr);
463 
469  void rotate180(void);
470 
474  void translate(double dx, double dy);
475 
483  void putInBasePosition(void);
484 
493  bool hasSameLayoutAs(const Graph &other, double tol=0.001, id_map *idMap = nullptr) const;
494 
497  SparseIdMatrix2d<Edge_SP>::type getEdgeBySrcIdTgtIdLookup(void) const;
498 
505  void destress(const ColaOptions &opts);
506 
508  void destress(void);
509 
514  void solidifyAlignedEdges(vpsc::Dim dim, const ColaOptions &opts);
515 
522  void makeFeasible(const ColaOptions &opts);
523 
531  int project(const ColaOptions &opts, vpsc::Dim dim, int accept=0);
532 
536  int projectOntoSepCo(const ColaOptions &opts, SepCo_SP sepco, int accept=0);
537 
550  bool applyProjSeq(const ColaOptions &opts, ProjSeq &ps, int accept=0);
551 
552 
558  void updateNodesFromRects(bool xAxis=true, bool yAxis=true);
559 
574 
581 
583  ColaGraphRep &getColaGraphRep(void) { return m_cgr; }
584 
586  SepMatrix &getSepMatrix(void) { return m_sepMatrix; }
587 
598  NodesById buildUniqueBendPoints(void);
599 
601  void pushNodePositions(void);
602 
605  bool popNodePositions(void);
606 
608  void setEdgeThickness(double t) { m_edge_thickness = t; }
609 
611  double getEdgeThickness(void) { return m_edge_thickness; }
612 
614  void padAllNodes(double dw, double dh);
615 
619  void setPosesInCorrespNodes(Graph &H);
620 
628  void setRoutesInCorrespEdges(Graph &H, bool directed=false);
629 
632  void route(Avoid::RouterFlag routingType);
633 
635  void clearAllRoutes(void);
636 
638  void buildRoutes(void);
639 
645 
647  void clearAllConstraints(void);
648 
655 
656  // For debugging:
657  std::string m_debugOutputPath = "";
658  unsigned m_projectionDebugLevel = 0;
659 
660 private:
661  SepMatrix m_sepMatrix;
662 
664  double m_iel = 0;
665 
668  double m_edge_thickness = 10;
669 
678  double autoInferIEL(void);
679 
682  void recomputeMaxDegree(void);
683 
685  double computeStress(void);
686 
688  void rotate90(PlaneMap nodeMap, std::function<void(Edge_SP)> edgeMap, SepTransform st, ColaOptions *opts=nullptr);
689 
691  ColaGraphRep m_cgr;
694  bool m_needNewRectangles = true;
696  cola::ConstrainedFDLayout *m_cfdl = nullptr;
697 
699  NodesById m_nodes;
701  EdgesById m_edges;
703  unsigned m_maxDeg = 0;
704 
707  std::stack<std::map<id_type, Avoid::Point>> m_posStack;
708 
709 };
710 
713 class Node {
714 public:
719  static Node_SP allocate(void);
720 
722  static Node_SP allocate(double w, double h);
723 
725  static Node_SP allocate(double cx, double dy, double w, double h);
726 
728  GhostNode_SP makeGhost(void) const;
729 
731  dialect::Node &operator=(const dialect::Node&) = default;
732 
734  virtual ~Node(void) = default;
735 
739  virtual id_type id(void) const { return m_ID; }
740 
744  unsigned getDegree(void) const { return m_degree; }
745 
749  void setGraph(Graph &graph) { m_graph = &graph; }
750 
752  Graph *getGraph(void) { return m_graph; }
753 
755  void addEdge(const Edge_SP &edge);
756 
758  void removeEdge(const dialect::Edge &edge);
759 
761  const EdgesById &getEdgeLookup(void) const { return m_edges; }
762 
764  EdgesById getCopyOfEdgeLookup(void) const { return m_edges; }
765 
767  void copyGeometry(const dialect::Node &other);
768 
772  void copyOtherGhostProperties(const dialect::Node &other);
773 
775  dimensions getHalfDimensions(void) const;
776 
778  dimensions getDimensions(void) const;
779 
781  BoundingBox getBoundingBox(void) const;
782 
785  Avoid::Point getBoundaryCompassPt(CompassDir dir) const;
786 
788  void setCentre(double cx, double cy);
789 
791  void translate(double dx, double dy);
792 
794  void applyPlaneMap(PlaneMap map);
795 
797  Avoid::Point getCentre(void) const;
798 
801  void setExternalId(unsigned id) { m_externalID = id; }
802 
804  int getExternalId(void) { return m_externalID; }
805 
807  dialect::Nodes getNeighbours(void) const;
808 
812  dialect::Nodes getNeighboursCwCyclic(void) const;
813 
818  virtual dialect::Nodes getChildren(void) const;
819 
821  void setDims(double w, double h);
822 
828  void setBoundingBox(double x, double X, double y, double Y);
829 
832  void addPadding(double dw, double dh);
833 
836 
839 
842 
845 
849  bool isRoot(void) const { return m_isRoot; }
850 
853  void setIsRoot(bool isRoot) { m_isRoot = isRoot; }
854 
863  bool liesOppositeSegment(const LineSegment &seg, bool openInterval=false);
864 
869  std::string writeSvg(bool useExternalId = false) const;
870 
871 protected:
872 
877  Node(void) : m_ID(nextID++) {}
878 
880  Node(double w, double h) : m_ID(nextID++), m_w(w), m_h(h) {}
881 
883  Node(double cx, double cy, double w, double h) : m_ID(nextID++), m_cx(cx), m_cy(cy), m_w(w), m_h(h) {}
884 
886  Node(const dialect::Node&) = default;
887 
889  const id_type m_ID;
890 
894  int m_externalID = -1;
895 
897  EdgesById m_edges;
898 
899 private:
901  static id_type nextID;
902 
905  Graph *m_graph = nullptr;
906 
908  EdgesById m_edges_by_opp_id;
909 
911  unsigned m_degree = 0;
912 
914  double m_cx = 0.0;
915  double m_cy = 0.0;
916 
922  double m_w = 100.0;
923  double m_h = 60.0;
924 
928  bool m_isRoot = false;
929 
930 };
931 
939 class GhostNode : public Node {
940 public:
941 
945  static GhostNode_SP allocate(const Node &node) { return GhostNode_SP(new GhostNode(node)); }
946 
951  virtual id_type id(void) const {
952  return m_doMasquerade ? m_originalNodeId : m_ID;
953  }
954 
957  id_type trueID(void) const { return m_ID; }
958 
965  virtual Nodes getChildren(void) const;
966 
968  void setMasquerade(bool doMasquerade) { m_doMasquerade = doMasquerade; }
969 
970 protected:
971 
973  GhostNode(const Node &node)
974  : Node(),
975  m_doMasquerade(false),
976  m_originalNodeId(node.id())
977  {
978  // We also copy the given Node's geometry.
979  copyGeometry(node);
980  // And copy other properties.
982  }
983 
984 private:
985 
987  GhostNode(void) = delete;
988 
990  GhostNode(const GhostNode&) = delete;
991 
994  bool m_doMasquerade;
995 
999  id_type m_originalNodeId;
1000 
1001 };
1002 
1003 
1006 class Edge {
1007 public:
1015  static Edge_SP allocate(const Node_SP &src, const Node_SP &tgt);
1016 
1018  Edge &operator=(const dialect::Edge&) = default;
1019 
1021  ~Edge(void) = default;
1022 
1026  id_type id(void) const { return m_ID; }
1027 
1033  Node_SP getOtherEnd(const dialect::Node &end1) const;
1034 
1036  Node_SP getSourceEnd(void) const { return Node_SP(m_src); }
1037 
1039  Node_SP getTargetEnd(void) const { return Node_SP(m_tgt); }
1040 
1042  std::pair<id_type, id_type> getEndIds(void) const { return {Node_SP(m_src)->id(), Node_SP(m_tgt)->id()}; }
1043 
1047  void setGraph(Graph &graph) { m_graph = &graph; }
1048 
1051  void sever(void);
1052 
1055  BoundingBox getBoundingBox(void) const;
1056 
1058  void addRoutePoint(double x, double y);
1059 
1061  void setRoute(std::vector<Avoid::Point> route);
1062 
1066  std::vector<Avoid::Point> getRoute(void) const { return m_route; }
1067 
1074  std::vector<Avoid::Point> getRoutePoints(void) const;
1075 
1079  std::string writeRouteTglf(void) const;
1080 
1083  std::pair<Avoid::ConnEnd, Avoid::ConnEnd> makeLibavoidConnEnds(
1085 
1088  void setBendNodes(Nodes bends) { m_bendNodes = bends; }
1089 
1091  void addBendNode(Node_SP bn) { m_bendNodes.push_back(bn); }
1092 
1094  Nodes getBendNodes(void) { return m_bendNodes; }
1095 
1097  bool hasBendNodes(void) { return !m_bendNodes.empty(); }
1098 
1100  void rotate90cw(void);
1101 
1103  void rotate90acw(void);
1104 
1106  void rotate180(void);
1107 
1111  void translate(double dx, double dy);
1112 
1114  void clearRouteAndBends(void);
1115 
1117  void buildRouteFromBends(void);
1118 
1121  std::string writeSvg(void) const;
1122 
1124  std::string writePolylineConnectorData(void) const;
1125 
1128  std::string writeRoundedOrthoConnectorData(void) const;
1129 
1130 private:
1136  Edge(const Node_SP &src, const Node_SP &tgt);
1137 
1140  Edge(void) = delete;
1141 
1143  static id_type nextID;
1144 
1146  const id_type m_ID;
1147 
1150  Graph *m_graph = nullptr;
1151 
1158  Node_WP m_src;
1159  Node_WP m_tgt;
1160 
1162  std::vector<Avoid::Point> m_route;
1163 
1165  Nodes m_bendNodes;
1166 };
1167 
1168 
1169 } // namespace dialect
1170 
1171 // Global Operators
1172 dialect::BoundingBox operator+(const dialect::BoundingBox &lhs, const dialect::BoundingBox &rhs);
1173 bool operator==(const dialect::BoundingBox &lhs, const dialect::BoundingBox &rhs);
1174 bool operator!=(const dialect::BoundingBox &lhs, const dialect::BoundingBox &rhs);
1175 
1176 #endif // DIALECT_GRAPHS_H
bool makeFeasible
When using a ConstrainedFDLayout, do makeFeasible before running?
Definition: graphs.h:121
void removeEdge(const dialect::Edge &edge)
Remove an incident Edge.
Definition: nodes.cpp:71
bool hasNode(const id_type &id) const
Say whether this Graph has a Node of the given ID.
Definition: graphs.cpp:203
void setDims(double w, double h)
Set the dimensions of the node.
Definition: nodes.cpp:98
BoundingBox(double x, double X, double y, double Y)
Standard constructor.
Definition: graphs.h:60
unsigned getDegree(void) const
Check the degree (number of incident Edges) of the Node.
Definition: graphs.h:744
std::vector< Node_SP > severNodeNotingNeighbours(const dialect::Node &node)
Like severNode but also returns a vector of all Nodes that were neighbours before severing...
Definition: graphs.cpp:228
void removeNodes(const NodesById &nodes)
Remove several Nodes from this Graph.
Definition: graphs.cpp:249
The Graph class represents graphs consisting of nodes and edges.
Definition: graphs.h:180
unsigned int ConnDirFlags
One or more Avoid::ConnDirFlag options.
Definition: connend.h:83
std::string writeSvg(bool useExternalIds=false) const
Write SVG to represent this Graph.
Definition: graphs.cpp:573
double w(void) const
Get the width of the box.
Definition: graphs.h:78
void setCorrespondingConstraints(Graph &H)
Set corresponding constraints in another Graph. This means that for each constraint between nodes of ...
Definition: graphs.cpp:1379
void severEdge(dialect::Edge &edge)
Sever an Edge in this Graph.
Definition: graphs.cpp:211
bool hasSameLayoutAs(const Graph &other, double tol=0.001, id_map *idMap=nullptr) const
Check whether this Graph has the same layout as another, up to a given tolerance. ...
Definition: graphs.cpp:777
std::map< size_t, id_type > ix2id
The inverse mapping, from indices in the rs Rectangles vector to Node IDs:
Definition: graphs.h:164
void translate(double dx, double dy)
Translate the entire layout by a given amount in each dimension.
Definition: graphs.cpp:759
The x-dimension (0).
Definition: rectangle.h:45
std::string writeIx2Id(void) const
Write the Rectangle Index –> Node ID map. Useful for debugging.
Definition: graphs.cpp:947
void padAllNodes(double dw, double dh)
Add padding to all ndoes.
Definition: graphs.cpp:1284
static GhostNode_SP allocate(const Node &node)
Factory function.
Definition: graphs.h:945
Graph(void)
Default constructor.
Definition: graphs.h:183
Node_SP getSourceEnd(void) const
Get read-only access to the Node at the source end of this Edge.
Definition: graphs.h:1036
Node(double cx, double cy, double w, double h)
Construct with position and dimensions.
Definition: graphs.h:883
void rotate180(void)
Rotate the connector route 180 degrees.
Definition: edges.cpp:279
Standard libavoid include file which includes all libavoid header files.
Nodes getBendNodes(void)
Access the Edge&#39;s bend nodes.
Definition: graphs.h:1094
size_t getNumEdges(void) const
Say how many Edges there are in this Graph.
Definition: graphs.h:357
double h(void) const
Get the height of the box.
Definition: graphs.h:81
void addRoutePoint(double x, double y)
Add a point to the route.
Definition: edges.cpp:101
void updateYCoordFromRect(vpsc::Rectangle *r)
Update the y-coordinate of this Node to equal that of the given Rectangle.
Definition: nodes.cpp:156
id_type id(void) const
Access the unique ID of this instance.
Definition: graphs.h:1026
void setIsRoot(bool isRoot)
Say whether this Node is a root. This is useful when working with trees, and can be safely ignored wh...
Definition: graphs.h:853
std::string writeRouteTglf(void) const
Write TGLF to represent the route for this Edge.
Definition: edges.cpp:105
int getExternalId(void)
Get the external ID.
Definition: graphs.h:804
void addEdge(const Edge_SP &edge)
Add an incident Edge.
Definition: nodes.cpp:60
A bounding box, given by the extreme coordinates.
Definition: graphs.h:52
double idealEdgeLength
Definition: graphs.h:108
bool xAxis
Work in the x-dimension?
Definition: graphs.h:117
LineSegment_SP buildSideSegment(CardinalDir side) const
Build a LineSegment representing a side of the box.
Definition: graphs.cpp:103
dialect::Nodes getNeighboursCwCyclic(void) const
Get the neighbours of this Node, listed in clockwise cyclic order (assuming the usual graphics conven...
Definition: nodes.cpp:169
A default functor that is called after each iteration of the layout algorithm.
Definition: cola.h:216
~Graph(void)
Destructor.
Definition: graphs.cpp:134
cola::CompoundConstraints ccs
Definition: graphs.h:141
A dynamic Polygon, to which points can be easily added and removed.
Definition: geomtypes.h:207
bool liesOppositeSegment(const LineSegment &seg, bool openInterval=false)
Check whether this Node lies opposite a LineSegment, i.e. whether the sides of the Node lying paralle...
Definition: nodes.cpp:240
void applyPlaneMap(PlaneMap map)
Apply a mapping from libavoid Points to libavoid Points, to this Node&#39;s centre.
Definition: nodes.cpp:92
Avoid::Point centre(void) const
Get the centre of the box.
Definition: graphs.h:89
Provides a simple way to set any or all of the various optional arguments to libcola layout methods...
Definition: graphs.h:105
void setPosesInCorrespNodes(Graph &H)
Update positions of Nodes in a given Graph to equal those of the corresponding Nodes (same ID) in thi...
Definition: graphs.cpp:1291
NodesById getNodeLookupWithIgnore(const Nodes &ignore) const
Build a NodesById lookup with some Nodes omitted.
Definition: graphs.cpp:321
dimensions getHalfDimensions(void) const
Get an ordered pair (half-width, half-height) for this Node.
Definition: nodes.cpp:127
libdialect: A library for computing human-like orthogonal network (DiAlEcT) layouts.
Definition: cola.h:44
Graph * getGraph(void)
Access the Graph to which the Node belongs.
Definition: graphs.h:752
EdgesById solidEdgeExemptions
Specify edges that should not be solidified.
Definition: graphs.h:115
std::string writeRoundedOrthoConnectorData(void) const
Write the data for an orthogonal SVG path for this Edge&#39;s connector route, using rounded bends...
Definition: edges.cpp:167
std::string writeSvg(void) const
Write SVG to represent this Edge.
Definition: edges.cpp:131
const EdgesById & getEdgeLookup(void) const
Read-only access to this Graph&#39;s lookup map for Edges by their ID.
Definition: graphs.h:351
id_type trueID(void) const
Simple way to get the true ID of this GhostNode, even if it is currently set to masquerade as the Nod...
Definition: graphs.h:957
std::vector< Graph_SP > getConnComps(void) const
Get the connected components of this Graph.
Definition: graphs.cpp:378
bool yAxis
Work in the y-dimension?
Definition: graphs.h:119
void translate(double dx, double dy)
Update the position of the node, by adding to its centre coordinates.
Definition: nodes.cpp:87
SepMatrix & getSepMatrix(void)
Access the separation matrix for this Graph.
Definition: graphs.h:586
bool useScaling
If using a ConstrainedMajorizationLayout, say whether you want scaling.
Definition: graphs.h:137
double nbrStressIELScalar
Definition: graphs.h:132
std::string writeSvg(bool useExternalId=false) const
Write SVG to represent this Node.
Definition: nodes.cpp:212
unsigned getMaxDegree(void) const
Reports the maximum degree of any Node in this Graph.
Definition: graphs.cpp:145
void setGraph(Graph &graph)
Tell the Edge which Graph it belongs to.
Definition: graphs.h:1047
virtual ~Node(void)=default
Destructor.
double makeFeasible_xBorder
Definition: graphs.h:124
Edge & operator=(const dialect::Edge &)=default
Copy-assignment operator.
Definition: constraints.h:492
This option, provided for convenience, specifies the point should be given visibility to all four sid...
Definition: connend.h:79
void putInBasePosition(void)
Put the Graph into a basic position useful for making unit test inputs. The Nodes are put in a row...
Definition: graphs.cpp:766
EdgesById m_edges
Lookup table for incident Edges by Edge&#39;s ID:
Definition: graphs.h:897
const EdgesById & getEdgeLookup(void) const
Read-only access to this Node&#39;s lookup map for Edges by their ID.
Definition: graphs.h:761
std::map< id_type, size_t > id2ix
A mapping from Node IDs to indices in the rs Rectangles vector:
Definition: graphs.h:162
bool popNodePositions(void)
Restore node positions from internal stack.
Definition: graphs.cpp:1268
void sever(void)
"Sever" this Edge, i.e. remove it from the Nodes to which it is attached.
Definition: edges.cpp:74
void setExternalId(unsigned id)
Set an externally-determined ID. (This is useful for TGLF and other interfacing operations.)
Definition: graphs.h:801
BoundingBox getBoundingBox(const NodesById &ignore=NodesById(), bool includeBends=false) const
Get the bounding box for this Graph.
Definition: graphs.cpp:355
SepTransform
Definition: constraints.h:83
virtual id_type id(void) const
Return an appropriate ID number.
Definition: graphs.h:951
void getChainsAndCycles(std::vector< std::deque< Node_SP >> &chains, std::vector< std::deque< Node_SP >> &cycles)
Identify all sequences of consecutive "links" (degree-2 nodes) in this graph.
Definition: graphs.cpp:442
std::vector< double > EdgeLengths
Definition: cola.h:72
void setBoundingBox(double x, double X, double y, double Y)
Set the bounding box of the node. This sets both the dimensions and the centre point.
Definition: nodes.cpp:108
bool isEmpty(void) const
Say whether the Graph is empty, meaning that it has no Nodes.
Definition: graphs.h:360
bool solidifyAlignedEdges
Definition: graphs.h:113
void rotate180(void)
Rotate the layout – and the constraints – 180 degrees.
Definition: graphs.cpp:744
double perimeter(void) const
Compute the perimeter of the box.
Definition: graphs.h:95
double getIEL(void)
Read the ideal edge length of this Graph.
Definition: graphs.cpp:608
std::pair< id_type, id_type > getEndIds(void) const
Get a pair {srcID, tgtID} giving the IDs of the source and target Nodes.
Definition: graphs.h:1042
virtual id_type id(void) const
Access the unique ID of a given instance.
Definition: graphs.h:739
void pushNodePositions(void)
Save node positions on internal stack.
Definition: graphs.cpp:1257
bool hasEdge(const id_type &id) const
Say whether this Graph has an Edge of the given ID.
Definition: graphs.cpp:207
const id_type m_ID
An instance&#39;s own unique ID:
Definition: graphs.h:889
Node(void)
Default constructor.
Definition: graphs.h:877
const NodesById & getNodeLookup(void) const
Read-only access to this Graph&#39;s lookup map for Nodes by their ID.
Definition: graphs.h:342
ColaGraphRep & updateColaGraphRep(void)
Refresh, as needed, the data structures necessary for applying the methods of libcola to this Graph...
Definition: graphs.cpp:631
void severAndRemoveNode(const dialect::Node &node)
Convenience method to completely remove a Node from the Graph.
Definition: graphs.cpp:276
std::vector< Rectangle * > Rectangles
A vector of pointers to Rectangle objects.
Definition: rectangle.h:246
static Node_SP allocate(void)
Factory function, to get a shared pointer to a Node allocated on the heap. We make the constructors p...
Definition: nodes.cpp:43
void updatePosnFromRect(vpsc::Rectangle *r)
Update the position of this Node to equal that of the given Rectangle.
Definition: nodes.cpp:147
void clearAllRoutes(void)
Clear all Edge routes.
Definition: graphs.cpp:1346
void setRoutesInCorrespEdges(Graph &H, bool directed=false)
Update routes of Edges in a given Graph to equal those of the corresponding Edges (same source and ta...
Definition: graphs.cpp:1311
GhostNode(const Node &node)
We always make a GhostNode as a copy of a plain Node.
Definition: graphs.h:973
bool preventOverlaps
Prevent overlaps between nodes?
Definition: graphs.h:110
Avoid::Polygon makeLibavoidPolygon(void) const
Build and return a Polygon to represent this Node in libavoid.
Definition: nodes.cpp:230
A default functor that is called before each iteration in the main loop of the ConstrainedFDLayout::r...
Definition: cola.h:168
Node_SP getNode(const id_type &id) const
Look up a Node by ID.
Definition: graphs.cpp:314
Holds the cluster hierarchy specification for a diagram.
Definition: cluster.h:172
void setBendNodes(Nodes bends)
Set the bend nodes. These should be Nodes representing the bend points in the Edge&#39;s route...
Definition: graphs.h:1088
bool applyProjSeq(const ColaOptions &opts, ProjSeq &ps, int accept=0)
Attempt to apply the projections given by a ProjSeq object. Give up as soon as any of them fails...
Definition: graphs.cpp:1052
Node(double w, double h)
Construct with dimensions.
Definition: graphs.h:880
std::pair< Avoid::ConnEnd, Avoid::ConnEnd > makeLibavoidConnEnds(Avoid::ConnDirFlags srcDirs=Avoid::ConnDirAll, Avoid::ConnDirFlags tgtDirs=Avoid::ConnDirAll)
Build and return a pair of libavoid ConnEnds to represent the endpoints of this Edge.
Definition: edges.cpp:113
EdgesById getCopyOfEdgeLookup(void) const
Get a copy of this Node&#39;s lookup map for Edges by their ID.
Definition: graphs.h:764
RouterFlag
Flags that can be passed to the router during initialisation to specify options.
Definition: router.h:70
The Point class defines a point in the plane.
Definition: geomtypes.h:52
interval getInterval(vpsc::Dim dim)
Get the interval in a given dimension.
Definition: graphs.h:86
void destress(void)
Convenience method to destress with default options.
Definition: graphs.cpp:849
void setMasquerade(bool doMasquerade)
Say whether the GhostNode should masquerade as the original Node.
Definition: graphs.h:968
ColaGraphRep & getColaGraphRep(void)
Access the cola graph rep for this Graph.
Definition: graphs.h:583
BoundingBox getBoundingBox(void) const
Get the bounding box for the edge, including its end points and route points.
Definition: edges.cpp:81
The Edge class represents edges in a graph.
Definition: graphs.h:1006
virtual dialect::Nodes getChildren(void) const
Get the neighbours of this Node that sit as the target end of the connecting Edge.
Definition: nodes.cpp:181
BoundingBox & operator+=(const BoundingBox &rhs)
Adding two bounding boxes returns the bounding box of their union.
Definition: graphs.cpp:91
Node_SP getTargetEnd(void) const
Get read-only access to the Node at the target end of this Edge.
Definition: graphs.h:1039
double computeAvgNodeDim(void) const
Compute the average of all heights and widths of Nodes in this Graph.
Definition: graphs.cpp:343
Avoid::Point getCentre(void) const
Get the centre coordinates of the node.
Definition: nodes.cpp:135
dialect::Node & operator=(const dialect::Node &)=default
Copy-assignment operator.
void rotate90cw(void)
Rotate the connector route 90 degrees clockwise.
Definition: edges.cpp:269
bool isRoot(void) const
Check whether this Node has been marked as being a root. This is useful when working with trees...
Definition: graphs.h:849
void updateXCoordFromRect(vpsc::Rectangle *r)
Update the x-coordinate of this Node to equal that of the given Rectangle.
Definition: nodes.cpp:152
dialect::Nodes getNeighbours(void) const
Get the neighbours of this Node.
Definition: nodes.cpp:160
A rectangle represents a fixed-size shape in the diagram that may be moved to prevent overlaps and sa...
Definition: rectangle.h:78
std::string writeId2Ix(void) const
Write the Node ID –> Rectangle Index map. Useful for debugging.
Definition: graphs.cpp:941
void solidifyAlignedEdges(vpsc::Dim dim, const ColaOptions &opts)
Add Nodes to represent aligned Edges in one dimension, constraining them to stay aligned.
Definition: graphs.cpp:1094
void rotate90acw(ColaOptions *opts=nullptr)
Rotate the layout – and the constraints – 90 degrees anticlockwise.
Definition: graphs.cpp:703
std::string repr(void) const
Write a simple representation of the bounding box.
Definition: graphs.cpp:99
void buildRouteFromBends(void)
Build a connector route based on the bend nodes.
Definition: edges.cpp:297
SparseIdMatrix2d< Edge_SP >::type getEdgeBySrcIdTgtIdLookup(void) const
Get a lookup for the Edges of this Graph by the IDs of their source and target Nodes, in that order.
Definition: graphs.cpp:838
BoundingBox(void)
Default constructor.
Definition: graphs.h:68
BoundingBox getBoundingBox(void) const
Get the bounding box for this Node.
Definition: nodes.cpp:139
void setRoute(std::vector< Avoid::Point > route)
Set (overwriting) the entire route.
void buildRoutes(void)
Ask all Edges to build their routes based on their bend nodes.
Definition: graphs.cpp:1353
NodesById buildUniqueBendPoints(void)
Build and return Nodes representing every point at which any Edge has a bend in its connector route...
Definition: graphs.cpp:1211
void rotate90acw(void)
Rotate the connector route 90 degrees anticlockwise.
Definition: edges.cpp:274
Dim
Indicates the x- or y-dimension.
Definition: rectangle.h:41
A GhostNode represents another Node.
Definition: graphs.h:939
Implements a constrained force-directed layout algorithm.
Definition: cola.h:622
Avoid::Point getBoundaryCompassPt(CompassDir dir) const
Get the point on the boundary of this Node in a given direction from its centre.
Definition: nodes.cpp:248
void translate(double dx, double dy)
Translate the connector route by a given amount in each dimension.
Definition: edges.cpp:284
void addBendlessSubnetworkToRoutingAdapter(RoutingAdapter &ra)
Add all Nodes, and all those Edges having no bend nodes within them, to a given RoutingAdapter. This is useful when precisely those Edges are viewed as needing a route which do not already have any bend nodes.
Definition: graphs.cpp:1368
void setCentre(double cx, double cy)
Set the position of the node, by setting its centre coordinates.
Definition: nodes.cpp:82
std::string writeTglf(bool useExternalIds=false) const
Write TGLF to represent this Graph.
Definition: graphs.cpp:510
cola::RootCluster * buildRootCluster(const ColaOptions &opts)
Build a cola::RootCluster based on the node clusters specified in a ColaOptions object.
Definition: graphs.cpp:667
Nodes cloneNode(id_type id)
Clone a node completely. There will be as many copies of the original node as it had edges...
Definition: graphs.cpp:286
void copyOtherGhostProperties(const dialect::Node &other)
Besides copying geometry, there may be other properties we wish to copy; in particular, properties that are suitable to be copied by a GhostNode.
Definition: nodes.cpp:123
void addEdge(Edge_SP edge, bool takeOwnership=true)
Add an Edge to this Graph.
Definition: graphs.cpp:179
double getEdgeThickness(void)
Get the edge thickness.
Definition: graphs.h:611
int projectOntoSepCo(const ColaOptions &opts, SepCo_SP sepco, int accept=0)
Convenience method to project onto a single SepCo object. Apart from the SepCo, parameters and return...
Definition: graphs.cpp:1045
The Node class represents nodes in a graph.
Definition: graphs.h:713
std::vector< NodesById > nodeClusters
Collection of Node lookups, in which to register clusters.
Definition: graphs.h:143
void addBendNode(Node_SP bn)
Add a single bend node.
Definition: graphs.h:1091
static Edge_SP allocate(const Node_SP &src, const Node_SP &tgt)
Factory function.
Definition: edges.cpp:49
double recomputeIEL(void)
Recompute, store, and return the Graph&#39;s ideal edge length.
Definition: graphs.cpp:613
int m_externalID
Definition: graphs.h:894
void makeFeasible(const ColaOptions &opts)
Make feasible. This means that, among those constraints that offer alternatives, we look for satisfia...
Definition: graphs.cpp:953
void clearRouteAndBends(void)
Clear the connector route and drop all bend nodes.
Definition: edges.cpp:291
bool isTree(void) const
Say whether the Graph is a tree.
Definition: graphs.h:363
Adapter to easily apply libavoid::Routers to libdialect::Graphs.
Definition: routing.h:57
void copyGeometry(const dialect::Node &other)
Give this Node the same coordinates and dimensions as another.
Definition: nodes.cpp:116
std::string writePolylineConnectorData(void) const
Write the data for a polyline SVG path for this Edge&#39;s connector route.
Definition: edges.cpp:154
void severNode(const dialect::Node &node)
Sever all the Edges incident to a Node in this Graph.
Definition: graphs.cpp:221
virtual Nodes getChildren(void) const
As in the Node class, get the neighbours of this Node that sit as the target end of the connecting Ed...
Definition: nodes.cpp:195
Node_SP addNode(void)
Add a new Node to this Graph.
Definition: graphs.cpp:161
std::vector< Avoid::Point > getRoutePoints(void) const
Get route points.
Definition: edges.cpp:123
Useful for set operations on Node lookups.
Definition: graphs.h:169
std::vector< CompoundConstraint * > CompoundConstraints
A vector of pointers to CompoundConstraint objects.
Definition: compound_constraints.h:259
bool useMajorization
Definition: graphs.h:135
void rotate90cw(ColaOptions *opts=nullptr)
Rotate the layout – and the constraints – 90 degrees clockwise.
Definition: graphs.cpp:695
void addPadding(double dw, double dh)
Add padding to the node&#39;s dimensions.
Definition: nodes.cpp:103
cola::EdgeLengths eLengths
Definition: graphs.h:147
void route(Avoid::RouterFlag routingType)
Do a libavoid connector routing on all Edges in the Graph.
Definition: graphs.cpp:1360
Logger * logger
Optional logger.
Definition: graphs.h:151
Bundles those data structures required in order to represent a Graph in libcola, and to map infomrati...
Definition: graphs.h:157
dimensions getDimensions(void) const
Get an ordered pair (width, height) for this Node.
Definition: nodes.cpp:131
friend void swap(Graph &first, Graph &second)
Swap operator.
Definition: graphs.h:192
bool hasBendNodes(void)
Check whether this Edge has any bend nodes.
Definition: graphs.h:1097
Node_SP getOtherEnd(const dialect::Node &end1) const
Get the opposite endpt, from a given one.
Definition: edges.cpp:60
void setEdgeThickness(double t)
Set the edge thickness.
Definition: graphs.h:608
void clearAllConstraints(void)
Clear all constraints in this Graph&#39;s SepMatrix.
Definition: graphs.cpp:1375
void updateNodesFromRects(bool xAxis=true, bool yAxis=true)
For use with various layout actions, this method asks the Graph to update Node positions based on its...
Definition: graphs.cpp:686
void setGraph(Graph &graph)
Tell the Node which Graph it belongs to.
Definition: graphs.h:749
bool useNeighbourStress
Definition: graphs.h:128
Graph & operator=(const Graph other)
Copy-assignment operator.
Definition: graphs.cpp:139
int project(const ColaOptions &opts, vpsc::Dim dim, int accept=0)
Project onto cola constraints.
Definition: graphs.cpp:1003
~Edge(void)=default
Destructor.
void removeNode(const dialect::Node &node)
Remove a Node from this Graph.
Definition: graphs.cpp:239
GhostNode_SP makeGhost(void) const
Allocate a GhostNode of this Node.
Definition: nodes.cpp:56
std::vector< Avoid::Point > getRoute(void) const
Get a copy of the Edge&#39;s route member. May be empty.
Definition: graphs.h:1066
size_t getNumNodes(void) const
Say how many Nodes there are in this Graph.
Definition: graphs.h:354