Adaptagrams
|
The Graph class represents graphs consisting of nodes and edges. More...
#include <graphs.h>
Public Member Functions | |
Graph (void) | |
Default constructor. | |
Graph (const Graph &G) | |
Copy constructor. | |
~Graph (void) | |
Destructor. | |
Graph & | operator= (const Graph other) |
Copy-assignment operator. More... | |
unsigned | getMaxDegree (void) const |
Reports the maximum degree of any Node in this Graph. More... | |
void | addNode (Node_SP node, bool takeOwnership=true) |
Add a Node to this Graph. More... | |
Node_SP | addNode (void) |
Add a new Node to this Graph. More... | |
Node_SP | addNode (double w, double h) |
Add a new Node to this Graph, setting dimensions. More... | |
Node_SP | addNode (double cx, double cy, double w, double h) |
Add a new Node to this Graph, setting position and dimensions. More... | |
void | addEdge (Edge_SP edge, bool takeOwnership=true) |
Add an Edge to this Graph. More... | |
Edge_SP | addEdge (Node_SP src, Node_SP tgt) |
Add a new Edge to this Graph. More... | |
Edge_SP | addEdge (const id_type &srcID, const id_type &tgtID) |
Add an Edge by specifying the IDs of its endpoint Nodes. More... | |
bool | hasNode (const id_type &id) const |
Say whether this Graph has a Node of the given ID. More... | |
bool | hasEdge (const id_type &id) const |
Say whether this Graph has an Edge of the given ID. More... | |
void | severEdge (dialect::Edge &edge) |
Sever an Edge in this Graph. More... | |
void | severNode (const dialect::Node &node) |
Sever all the Edges incident to a Node in this Graph. More... | |
std::vector< Node_SP > | severNodeNotingNeighbours (const dialect::Node &node) |
Like severNode but also returns a vector of all Nodes that were neighbours before severing. More... | |
void | removeNode (const dialect::Node &node) |
Remove a Node from this Graph. More... | |
void | removeNodes (const NodesById &nodes) |
Remove several Nodes from this Graph. More... | |
void | severAndRemoveNode (const dialect::Node &node) |
Convenience method to completely remove a Node from the Graph. More... | |
void | severAndRemoveNode (id_type nodeID) |
Convenience method to completely remove a Node from the Graph. More... | |
Nodes | cloneNode (id_type id) |
Clone a node completely. There will be as many copies of the original node as it had edges, and each clone will be a leaf. More... | |
Node_SP | getNode (const id_type &id) const |
Look up a Node by ID. More... | |
const NodesById & | getNodeLookup (void) const |
Read-only access to this Graph's lookup map for Nodes by their ID. | |
NodesById | getNodeLookupWithIgnore (const Nodes &ignore) const |
Build a NodesById lookup with some Nodes omitted. | |
NodesById | getNodeLookupWithIgnore (const NodesById &ignore) const |
Build a NodesById lookup with some Nodes omitted. | |
const EdgesById & | getEdgeLookup (void) const |
Read-only access to this Graph's lookup map for Edges by their ID. | |
size_t | getNumNodes (void) const |
Say how many Nodes there are in this Graph. | |
size_t | getNumEdges (void) const |
Say how many Edges there are in this Graph. | |
bool | isEmpty (void) const |
Say whether the Graph is empty, meaning that it has no Nodes. | |
bool | isTree (void) const |
Say whether the Graph is a tree. | |
double | computeAvgNodeDim (void) const |
Compute the average of all heights and widths of Nodes in this Graph. More... | |
double | getIEL (void) |
Read the ideal edge length of this Graph. More... | |
double | recomputeIEL (void) |
Recompute, store, and return the Graph's ideal edge length. More... | |
BoundingBox | getBoundingBox (const NodesById &ignore=NodesById(), bool includeBends=false) const |
Get the bounding box for this Graph. More... | |
std::vector< Graph_SP > | getConnComps (void) const |
Get the connected components of this Graph. More... | |
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. More... | |
std::string | writeTglf (bool useExternalIds=false) const |
Write TGLF to represent this Graph. More... | |
std::string | writeSvg (bool useExternalIds=false) const |
Write SVG to represent this Graph. More... | |
std::string | writeId2Ix (void) const |
Write the Node ID –> Rectangle Index map. Useful for debugging. More... | |
std::string | writeIx2Id (void) const |
Write the Rectangle Index –> Node ID map. Useful for debugging. More... | |
void | rotate90cw (ColaOptions *opts=nullptr) |
Rotate the layout – and the constraints – 90 degrees clockwise. More... | |
void | rotate90acw (ColaOptions *opts=nullptr) |
Rotate the layout – and the constraints – 90 degrees anticlockwise. More... | |
void | rotate180 (void) |
Rotate the layout – and the constraints – 180 degrees. More... | |
void | translate (double dx, double dy) |
Translate the entire layout by a given amount in each dimension. More... | |
void | putInBasePosition (void) |
Put the Graph into a basic position useful for making unit test inputs. The Nodes are put in a row, all Edge routes are cleared, and all constraints are cleared. More... | |
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. More... | |
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. | |
void | destress (const ColaOptions &opts) |
Reduce stress via libcola's gradient-descent procedures. More... | |
void | destress (void) |
Convenience method to destress with default options. | |
void | solidifyAlignedEdges (vpsc::Dim dim, const ColaOptions &opts) |
Add Nodes to represent aligned Edges in one dimension, constraining them to stay aligned. More... | |
void | makeFeasible (const ColaOptions &opts) |
Make feasible. This means that, among those constraints that offer alternatives, we look for satisfiable alternatives in order of increasing cost (cost = separation violation). This is useful with nonoverlap constraints. More... | |
int | project (const ColaOptions &opts, vpsc::Dim dim, int accept=0) |
Project onto cola constraints. More... | |
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 value are as for the ordinary project method. More... | |
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. More... | |
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 internal vpsc Rectangles that were used in the layout operation. More... | |
ColaGraphRep & | updateColaGraphRep (void) |
Refresh, as needed, the data structures necessary for applying the methods of libcola to this Graph. More... | |
cola::RootCluster * | buildRootCluster (const ColaOptions &opts) |
Build a cola::RootCluster based on the node clusters specified in a ColaOptions object. More... | |
ColaGraphRep & | getColaGraphRep (void) |
Access the cola graph rep for this Graph. | |
SepMatrix & | getSepMatrix (void) |
Access the separation matrix for this Graph. | |
NodesById | buildUniqueBendPoints (void) |
Build and return Nodes representing every point at which any Edge has a bend in its connector route. Importantly, for any given point in the plane, at most one Node will built to represent that point, even if different edges have a bend there. While perhaps counterintuitive, this is most helpful in the operation of planarising a given Graph. More... | |
void | pushNodePositions (void) |
Save node positions on internal stack. | |
bool | popNodePositions (void) |
Restore node positions from internal stack. More... | |
void | setEdgeThickness (double t) |
Set the edge thickness. | |
double | getEdgeThickness (void) |
Get the edge thickness. | |
void | padAllNodes (double dw, double dh) |
Add padding to all ndoes. | |
void | setPosesInCorrespNodes (Graph &H) |
Update positions of Nodes in a given Graph to equal those of the corresponding Nodes (same ID) in this Graph. More... | |
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 target) in this Graph. More... | |
void | route (Avoid::RouterFlag routingType) |
Do a libavoid connector routing on all Edges in the Graph. More... | |
void | clearAllRoutes (void) |
Clear all Edge routes. | |
void | buildRoutes (void) |
Ask all Edges to build their routes based on their bend nodes. | |
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. More... | |
void | clearAllConstraints (void) |
Clear all constraints in this Graph's SepMatrix. | |
void | setCorrespondingConstraints (Graph &H) |
Set corresponding constraints in another Graph. This means that for each constraint between nodes of IDs id1 and id2 in this Graph's SepMatrix, we set that constraint in the other Graph if and only if it too contains Nodes of IDs id1 and id2. More... | |
Friends | |
void | swap (Graph &first, Graph &second) |
Swap operator. | |
The Graph class represents graphs consisting of nodes and edges.
void Graph::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.
[out] | ra | The RoutingAdapter to which the Nodes and Edges are to be added. |
References dialect::RoutingAdapter::addEdges(), and dialect::RoutingAdapter::addNodes().
void Graph::addEdge | ( | Edge_SP | edge, |
bool | takeOwnership = true |
||
) |
Edge_SP Graph::addEdge | ( | Node_SP | src, |
Node_SP | tgt | ||
) |
Edge_SP Graph::addEdge | ( | const id_type & | srcID, |
const id_type & | tgtID | ||
) |
Add an Edge by specifying the IDs of its endpoint Nodes.
[in] | srcID | The ID of the Node that is to sit at the source end of the new Edge. |
[in] | tgtID | The ID of the Node that is to sit at the target end of the new Edge. |
References addEdge(), and getNode().
void Graph::addNode | ( | Node_SP | node, |
bool | takeOwnership = true |
||
) |
Node_SP Graph::addNode | ( | void | ) |
References dialect::Node::allocate().
Referenced by addNode(), and cloneNode().
Node_SP Graph::addNode | ( | double | w, |
double | h | ||
) |
Node_SP Graph::addNode | ( | double | cx, |
double | cy, | ||
double | w, | ||
double | h | ||
) |
Add a new Node to this Graph, setting position and dimensions.
[in] | cx | Centre x-coordinate of Node. |
[in] | cy | Centre y-coordinate of Node. |
[in] | w | Width of Node. |
[in] | h | Height of Node. |
References addNode(), and dialect::Node::allocate().
bool Graph::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.
[in] | opts | Options. |
[in] | ps | The ProjSeq to be applied. |
[in] | accept | Acceptance level. See doctext for cola::projectOntoCCs. |
References dialect::ColaOptions::ccs, getIEL(), dialect::ColaOptions::idealEdgeLength, dialect::ProjSeq::nextProjection(), dialect::ProjSeq::noteStresschange(), project(), and updateColaGraphRep().
cola::RootCluster * Graph::buildRootCluster | ( | const ColaOptions & | opts | ) |
Build a cola::RootCluster based on the node clusters specified in a ColaOptions object.
References cola::Cluster::addChildCluster(), cola::RectangularCluster::addChildNode(), dialect::ColaGraphRep::id2ix, and dialect::ColaOptions::nodeClusters.
NodesById Graph::buildUniqueBendPoints | ( | void | ) |
Build and return Nodes representing every point at which any Edge has a bend in its connector route. Importantly, for any given point in the plane, at most one Node will built to represent that point, even if different edges have a bend there. While perhaps counterintuitive, this is most helpful in the operation of planarising a given Graph.
References dialect::NearbyObjectFinder< T >::addObject(), dialect::Node::allocate(), dialect::NearbyObjectFinder< T >::findObject(), getIEL(), route(), Avoid::Point::x, and Avoid::Point::y.
Nodes Graph::cloneNode | ( | id_type | id | ) |
Clone a node completely. There will be as many copies of the original node as it had edges, and each clone will be a leaf.
[in] | id | The ID of the node to be cloned. |
References addEdge(), addNode(), dialect::Node::allocate(), dialect::Edge::allocate(), getNode(), and severEdge().
double Graph::computeAvgNodeDim | ( | void | ) | const |
Compute the average of all heights and widths of Nodes in this Graph.
void Graph::destress | ( | const ColaOptions & | opts | ) |
Reduce stress via libcola's gradient-descent procedures.
[in] | opts | options to control the layout. |
References dialect::ColaOptions::logger.
BoundingBox Graph::getBoundingBox | ( | const NodesById & | ignore = NodesById() , |
bool | includeBends = false |
||
) | const |
Get the bounding box for this Graph.
[in] | ignore | Optional set of Nodes (as NodesByID) to leave out of the box. |
[in] | includeBends | Say whether bend points of connector routes should be included in the box. |
Referenced by writeSvg().
void Graph::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.
[out] | chains | Vector of deques of Nodes, where each identified "chain" will be recorded. A "chain" is a consecutive sequence of "links" whose endpoints are distinct. |
[out] | cycles | Vector of deques of Nodes, where each identified "cycle" will be recorded. A "cycles" is a consecutive sequence of "links" that forms a closed loop. |
vector< Graph_SP > Graph::getConnComps | ( | void | ) | const |
double Graph::getIEL | ( | void | ) |
Read the ideal edge length of this Graph.
Referenced by applyProjSeq(), buildUniqueBendPoints(), and dialect::doHOLA().
unsigned Graph::getMaxDegree | ( | void | ) | const |
Node_SP Graph::getNode | ( | const id_type & | id | ) | const |
Look up a Node by ID.
out_of_range | exception if there is no Node by the given ID. |
Referenced by addEdge(), cloneNode(), dialect::identifyRootNode(), dialect::peel(), and severAndRemoveNode().
bool Graph::hasEdge | ( | const id_type & | id | ) | const |
bool Graph::hasNode | ( | const id_type & | id | ) | const |
Say whether this Graph has a Node of the given ID.
Referenced by dialect::TreePlacement::insertTreeIntoGraph().
bool Graph::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.
[in] | other | The other Graph. |
[in] | tol | Tolerance for checking equality of floats. |
[in] | idMap | Optional mapping from the IDs of the other Graph to the IDs of the corresponding Nodes of this Graph. If not provided, the correspondence is by the Nodes' external IDs. |
References getEdgeBySrcIdTgtIdLookup(), getNodeLookup(), Avoid::Point::x, and Avoid::Point::y.
void Graph::makeFeasible | ( | const ColaOptions & | opts | ) |
Make feasible. This means that, among those constraints that offer alternatives, we look for satisfiable alternatives in order of increasing cost (cost = separation violation). This is useful with nonoverlap constraints.
[in] | opts | The usual ColaOptions. |
References dialect::ColaOptions::logger.
Copy-assignment operator.
References swap.
bool Graph::popNodePositions | ( | void | ) |
Restore node positions from internal stack.
References Avoid::Point::x, and Avoid::Point::y.
int Graph::project | ( | const ColaOptions & | opts, |
vpsc::Dim | dim, | ||
int | accept = 0 |
||
) |
Project onto cola constraints.
[in] | opts | Options, including any additional constraints onto which to project (in addition to the Graph's existing SepMatrix). |
[in] | dim | The dimension in which to project. |
[in] | accept | Acceptance level. See doctext for cola::projectOntoCCs. |
References dialect::ColaOptions::solidifyAlignedEdges.
Referenced by applyProjSeq(), and projectOntoSepCo().
int Graph::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 value are as for the ordinary project method.
References dialect::ColaOptions::ccs, project(), and updateColaGraphRep().
void Graph::putInBasePosition | ( | void | ) |
Put the Graph into a basic position useful for making unit test inputs. The Nodes are put in a row, all Edge routes are cleared, and all constraints are cleared.
The criteria are: (1) all nodes have distinct positions, and (2) the layout is a bad one. Condition (1) is needed so that Cola doesn't generate random starting positions.
References clearAllConstraints(), and clearAllRoutes().
double Graph::recomputeIEL | ( | void | ) |
Recompute, store, and return the Graph's ideal edge length.
void Graph::removeNode | ( | const dialect::Node & | node | ) |
Remove a Node from this Graph.
References dialect::Node::id().
Referenced by severAndRemoveNode().
void Graph::removeNodes | ( | const NodesById & | nodes | ) |
Remove several Nodes from this Graph.
[in] | nodes | The Nodes to be removed from the Graph. |
Referenced by dialect::NodeBuckets::severNodes().
void Graph::rotate180 | ( | void | ) |
Rotate the layout – and the constraints – 180 degrees.
References dialect::EAST.
void Graph::rotate90acw | ( | ColaOptions * | opts = nullptr | ) |
Rotate the layout – and the constraints – 90 degrees anticlockwise.
[in] | opts | ColaOptions to control destressing operation after rotation. This is optional; pass nullptr if you do not want to destress. |
References dialect::EAST.
void Graph::rotate90cw | ( | ColaOptions * | opts = nullptr | ) |
Rotate the layout – and the constraints – 90 degrees clockwise.
[in] | opts | ColaOptions to control destressing operation after rotation. This is optional; pass nullptr if you do not want to destress. |
References dialect::EAST.
void Graph::route | ( | Avoid::RouterFlag | routingType | ) |
Do a libavoid connector routing on all Edges in the Graph.
[in] | routingType | The type of routing you want (orthogonal or polyline). |
References dialect::RoutingAdapter::addEdges(), dialect::RoutingAdapter::addNodes(), clearAllRoutes(), and dialect::RoutingAdapter::route().
Referenced by buildUniqueBendPoints().
void Graph::setCorrespondingConstraints | ( | Graph & | H | ) |
void Graph::setPosesInCorrespNodes | ( | Graph & | H | ) |
void Graph::setRoutesInCorrespEdges | ( | Graph & | H, |
bool | directed = false |
||
) |
Update routes of Edges in a given Graph to equal those of the corresponding Edges (same source and target) in this Graph.
[out] | H | The Graph whose Edge routes are to be updated. |
[in] | directed | Set true if Edges are to be understood as directed, i.e. if in order to match the Edges have to have the same source and the same target. Otherwise only the set {source ID, target ID} has to be the same. Default: false (i.e. undirected edges). |
void Graph::severAndRemoveNode | ( | const dialect::Node & | node | ) |
Convenience method to completely remove a Node from the Graph.
References removeNode(), and severNode().
Referenced by dialect::TreePlacement::insertTreeIntoGraph(), and severAndRemoveNode().
void Graph::severAndRemoveNode | ( | id_type | nodeID | ) |
Convenience method to completely remove a Node from the Graph.
References getNode(), and severAndRemoveNode().
void Graph::severEdge | ( | dialect::Edge & | edge | ) |
The Edge is removed from the Graph, and from both of its endpoint Nodes as well.
References dialect::Edge::id(), and dialect::Edge::sever().
Referenced by cloneNode(), severNode(), and severNodeNotingNeighbours().
void Graph::severNode | ( | const dialect::Node & | node | ) |
Sever all the Edges incident to a Node in this Graph.
[in] | node | The Node whose Edges are to be severed. |
References dialect::Node::getCopyOfEdgeLookup(), and severEdge().
Referenced by severAndRemoveNode().
vector< Node_SP > Graph::severNodeNotingNeighbours | ( | const dialect::Node & | node | ) |
Like severNode but also returns a vector of all Nodes that were neighbours before severing.
References dialect::Node::getEdgeLookup(), and severEdge().
Referenced by dialect::NodeBuckets::severNodes().
void Graph::solidifyAlignedEdges | ( | vpsc::Dim | dim, |
const ColaOptions & | opts | ||
) |
Add Nodes to represent aligned Edges in one dimension, constraining them to stay aligned.
[in] | dim | Solidify only those aligned Edges whose variable coordinate is in this dimension. Thus, horizontally aligned edges for XDIM; vertically aligned for YDIM. |
[in] | opts | Here you can set Edge exemptions, i.e. a set of Edges that should not be solidified. |
References dialect::Node::allocate(), vpsc::HORIZONTAL, Avoid::Point::id, dialect::ColaOptions::solidEdgeExemptions, vpsc::VERTICAL, Avoid::Point::x, and Avoid::Point::y.
void Graph::translate | ( | double | dx, |
double | dy | ||
) |
Translate the entire layout by a given amount in each dimension.
[in] | dx | The amount by which to translate in the x-dimension. |
[in] | dy | The amount by which to translate in the y-dimension. |
ColaGraphRep & Graph::updateColaGraphRep | ( | void | ) |
Refresh, as needed, the data structures necessary for applying the methods of libcola to this Graph.
Clients are therefore advised to utilise methods like Graph::destress instead of creating their own instances of ConstrainedFDLayout. At the least, they must not reuse layout objects that were created before adding or removing Nodes from the Graph (which makes sense anyway).
References dialect::ColaGraphRep::id2ix, and dialect::ColaGraphRep::ix2id.
Referenced by applyProjSeq(), and projectOntoSepCo().
void Graph::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 internal vpsc Rectangles that were used in the layout operation.
[in] | xAxis | Set true iff the x-coordinates of the nodes should be updated. |
[in] | yAxis | Set true iff the y-coordinates of the nodes should be updated. |
References dialect::ColaGraphRep::id2ix.
string Graph::writeId2Ix | ( | void | ) | const |
Write the Node ID –> Rectangle Index map. Useful for debugging.
References dialect::ColaGraphRep::id2ix.
string Graph::writeIx2Id | ( | void | ) | const |
Write the Rectangle Index –> Node ID map. Useful for debugging.
References dialect::ColaGraphRep::ix2id.
string Graph::writeSvg | ( | bool | useExternalIds = false | ) | const |
Write SVG to represent this Graph.
[in] | useExternalIds | When a Graph is built from TGLF its Nodes store the IDs that were used there. Set true if you want these same IDs to be written out as well. Otherwise the internal unique Node IDs are used. |
References getBoundingBox(), dialect::BoundingBox::h(), dialect::string_format(), and dialect::BoundingBox::w().
string Graph::writeTglf | ( | bool | useExternalIds = false | ) | const |
Write TGLF to represent this Graph.
[in] | useExternalIds | When a Graph is built from TGLF its Nodes store the IDs that were used there. Set true if you want these same IDs to be written out as well. Otherwise the internal unique Node IDs are used. |
References Avoid::Point::x, and Avoid::Point::y.