34 #include "libcola/cola.h" 36 #include "libdialect/util.h" 37 #include "libdialect/commontypes.h" 38 #include "libdialect/constraints.h" 39 #include "libdialect/graphs.h" 74 ACASepFlag negateSepFlag(ACASepFlag sf);
75 ACAFlag sepToAlignFlag(ACASepFlag sf);
76 ACAFlag perpAlignFlag(ACAFlag af);
77 ACASepFlag vectorToSepFlag(
double dx,
double dy);
78 bool propsedSepConflictsWithExistingPosition(ACASepFlag pro, ACASepFlag ex);
80 struct OrderedAlignment {
82 af(ACACONN), sf(ACANOSEP), src(-1), tgt(-1),
83 offsetSrc(0), offsetTgt(0),
84 separation(nullptr), alignment(nullptr), edgeIndex(-1) {}
95 ~OrderedAlignment() {}
109 bool sortOrdAlignsByPenalty(
const OrderedAlignment *lhs,
const OrderedAlignment *rhs);
111 typedef std::vector<OrderedAlignment*> OrderedAlignments;
112 typedef std::pair<double,double> EdgeOffset;
113 typedef std::vector<EdgeOffset> EdgeOffsets;
114 typedef std::vector<ACASepFlag> ACASepFlags;
162 const std::vector<cola::Edge>& es,
164 const double idealLength,
173 ACALayout(std::shared_ptr<dialect::Graph> G);
242 void updateSepMatrix(SepMatrix &M,
const std::map<size_t, id_type> &ix2id);
244 void outputInstanceToSVG(std::string filename);
397 bool nodesAreAligned(
int i,
int j)
const;
399 void layoutPeriod(
unsigned p);
400 void doFinalLayout(
bool b);
402 void addOrderedAlignments(OrderedAlignments oas);
403 OrderedAlignment *initOrdAlign(
int j, ACASepFlag sf)
const;
404 OrderedAlignment *initOrdAlign(
int s,
int t, ACASepFlag sf,
int edgeIndex=-1)
const;
407 OrderedAlignment *mostRecentOA(
void);
408 std::string writeAlignmentTable(
void)
const;
409 std::string aStateBeforeChop;
410 std::string writeStateForNodeIds(id_type id1, id_type id2);
418 void computeDegrees(
void);
424 void generateVPSCConstraints(
void);
429 int adjustVarNumForExtraVars(
vpsc::Dim dim,
int k);
435 void initStateTables(
void);
445 void recordAlignmentWithClosure(
int i,
int j, ACAFlag af,
int numCols = 0);
449 bool acaLoopOnce(
void);
450 void acaLoopOneByOne(
void);
451 void acaLoopAllAtOnce(
void);
453 bool layoutIfAppropriate(
void);
457 void updateStateTables(OrderedAlignment *oa);
463 void updateNodeRectsFromVars(
void);
464 void updateVarsFromNodeRects(
void);
465 void pushState(
void);
467 void dropState(
void);
468 void pushRectCoords(
void);
469 void popRectCoords(
void);
470 void dropRectCoords(
void);
471 void removeNewEdgeShapesAccordingToStateStack(
void);
472 std::set<unsigned> exemptionSetForEdge(
int j);
473 OrderedAlignment *chooseOA(
void);
474 bool createsOverlap(OrderedAlignment *oa);
475 bool allOrNothing(OrderedAlignments oas);
476 bool applyIfFeasible(OrderedAlignment *oa);
480 void completeOrdAlign(OrderedAlignment *oa);
481 bool badSeparation(
int j, ACASepFlag sf);
482 bool badSeparation(
int l,
int r, ACASepFlag sf);
484 double computePenalty(
int j, ACASepFlag sf);
485 double lengthPenaltyForEdge(
int j);
486 double deflectionForEdge(
int j, ACASepFlag sf);
487 double deflection(
double sx,
double sy,
double tx,
double ty, ACASepFlag sf);
488 double bendPointPenalty(
int src,
int tgt, ACASepFlag sf);
489 double leafPenalty(
int src,
int tgt);
491 EdgeOffset getEdgeOffsetForCompassDirection(
int j, ACASepFlag sf);
500 static const double BP_PENALTY;
501 static const double LEAF_PENALTY;
502 static const double PENALTY_BOUND;
504 static const double EDGE_SHAPE_HALF_THICKNESS;
505 static const double EDGE_SHAPE_BUFFER;
514 std::vector<cola::Edge> m_es;
518 std::vector<bool> m_ignoreEdge;
519 std::vector<bool> m_ignoreNodeForOPWithOffsets;
520 std::map<ACASepFlag,EdgeOffsets> m_edgeOffsets;
521 ACASepFlags m_allowedSeps;
522 std::map<int,int> m_nodeAliases;
537 cola::NonOverlapConstraints *m_xnocs =
nullptr;
538 cola::NonOverlapConstraints *m_ynocs =
nullptr;
541 std::map<int,int> m_xAuxRectIndexInExtendedRS;
542 std::map<int,int> m_yAuxRectIndexInExtendedRS;
544 double m_idealLength;
545 bool m_preventOverlaps;
551 bool m_addBendPointPenalty;
552 bool m_favourLongEdges;
553 bool m_postponeLeaves;
554 bool m_useNonLeafDegree;
556 bool m_aggressiveOrdering;
558 std::multimap<int,int> m_incidentEdges;
559 std::multimap<int,int> m_nlincidentEdges;
560 std::multimap<int,int> m_nbrs;
561 std::multimap<int,int> m_nlnbrs;
562 std::set<int> m_leaves;
563 std::set<int> m_deg2Nodes;
564 std::set<int> m_nldeg2Nodes;
568 std::vector<OrderedAlignment*> m_ordAligns;
569 std::set<int> m_alignedEdges;
573 double m_lengthUpperBound;
575 std::vector<unsigned> m_sizeStack;
576 std::vector<double> m_rectXStack;
577 std::vector<double> m_rectYStack;
578 std::map<int,int> m_edgeIndexToGuidelineIndex;
579 std::map<int,int> m_guidelineIndexToEdgeIndex;
581 std::map<int,int> m_xGuidelineIndexToEdgeIndex;
582 std::map<int,int> m_yGuidelineIndexToEdgeIndex;
584 bool m_didLayoutForLastAlignment;
585 bool m_doFinalFDLayout;
587 std::vector < std::vector<unsigned> > m_nocExemptRects;
588 cola::NonOverlapConstraintExemptions *m_nocExemptions =
nullptr;
589 bool m_nocsInitialised;
592 std::multimap<unsigned,unsigned> m_nocExemptionSets;
594 unsigned m_layoutPeriod;
void useNonLeafDegree(bool b)
Say whether leaves should be counted when computing node degrees.
Definition: aca.cpp:333
void setAvoidNodeOverlaps(bool avoidOverlaps)
Specifies whether non-overlap constraints should be automatically generated between all nodes...
Definition: aca.cpp:348
Incremental solver for Variable Placement with Separation Constraints problem instance.
Definition: solve_VPSC.h:105
void addBendPointPenalty(bool b)
Control whether we avoid making bend points.
Definition: aca.cpp:318
void setClusterHierarchy(cola::RootCluster *rc)
sets the cluster hierarchy of the underlying FDLayout.
Definition: aca.cpp:381
void layout(void)
Do an initial stress-minimising layout, and then create alignments.
Definition: aca.cpp:297
A default functor that is called after each iteration of the layout algorithm.
Definition: cola.h:216
ACALayout(const vpsc::Rectangles &rs, const std::vector< cola::Edge > &es, cola::CompoundConstraints &ccs, const double idealLength, const cola::EdgeLengths &eLengths=cola::StandardEdgeLengths, cola::TestConvergence *doneTest=nullptr, cola::PreIteration *preIteration=nullptr)
Constructs an adaptive constrained alignment layout instance.
bool createOneAlignment(void)
Creates one alignment.
Definition: aca.cpp:284
libdialect: A library for computing human-like orthogonal network (DiAlEcT) layouts.
Definition: cola.h:44
void ignoreEdges(std::vector< bool > ignore)
Specify that certain edges are never to be aligned.
Definition: aca.cpp:353
An alignment constraint specifies a alignment line that a set of nodes must be constrained to by an e...
Definition: compound_constraints.h:345
void createAlignments(void)
Creates alignments.
Definition: aca.cpp:274
void favourLongEdges(bool b)
Prefer long edges instead of ones that are close to aligned.
Definition: aca.cpp:323
void ignoreNodesForOPWithOffsets(std::vector< bool > ignore)
Say that certain nodes may be crossed by edges.
Definition: aca.cpp:359
Implements the Adaptive Constrained Alignment (ACA) algorithm.
Definition: aca.h:124
std::vector< Variable * > Variables
A vector of pointers to Variable objects.
Definition: constraint.h:38
std::vector< double > EdgeLengths
Definition: cola.h:72
void postponeLeaves(bool b)
Say whether alignment of leaf edges should be saved for last.
Definition: aca.cpp:328
void updateGraph(void)
For forward compatibility (i.e. with Graphs), we offer a convenience method to update the Graph (when...
Definition: aca.cpp:1295
std::vector< Constraint * > Constraints
A vector of pointers to Constraint objects.
Definition: constraint.h:125
std::vector< Rectangle * > Rectangles
A vector of pointers to Rectangle objects.
Definition: rectangle.h:246
A default functor that is called before each iteration in the main loop of the ConstrainedFDLayout::r...
Definition: cola.h:168
Holds the cluster hierarchy specification for a diagram.
Definition: cluster.h:172
void allAtOnce(bool b)
Say whether alignment choices should alternate with stress minimisation steps.
Definition: aca.cpp:338
void addGroupOfNonOverlapExemptRectangles(std::vector< unsigned > rs)
Stop non-overlap constraints from being generated between certain nodes.
Definition: aca.cpp:410
bool applyOAsAllOrNothing(OrderedAlignments oas)
Creates all the requested alignments, or none if any is infeasible.
Definition: aca.cpp:290
void removeOverlaps(void)
Do an FD layout with overlap prevention, then stop.
Definition: aca.cpp:304
void setAllowedDirections(ACASepFlags seps)
Say which separations are allowed for the source and target of each edge.
Definition: aca.cpp:456
void setAlignmentOffsetsForCompassDirection(ACASepFlag sf, EdgeOffsets offsets)
Say how to offset nodes when edges are aligned in a certain direction.
Definition: aca.cpp:450
A rectangle represents a fixed-size shape in the diagram that may be moved to prevent overlaps and sa...
Definition: rectangle.h:78
Dim
Indicates the x- or y-dimension.
Definition: rectangle.h:41
Implements a constrained force-directed layout algorithm.
Definition: cola.h:622
void setNodeAliases(std::map< int, int > aliases)
Set certain nodes to be used in place of others.
Definition: aca.cpp:365
std::vector< CompoundConstraint * > CompoundConstraints
A vector of pointers to CompoundConstraint objects.
Definition: compound_constraints.h:259
bool edgeIsAligned(int j) const
Check whether an edge is aligned.
Definition: aca.cpp:386
A separation constraint specifies a simple horizontal or vertical spacing constraint between 2 nodes ...
Definition: compound_constraints.h:432
void layoutWithCurrentConstraints(void)
Run layout with current constraints, and with or without overlap prevention, as per the current setti...
Definition: aca.cpp:772
void updateSepMatrix(void)
Update the SepMatrix of the Graph on which this ACALayout was built (if any).
Definition: aca.cpp:1301
void aggressiveOrdering(bool b)
Say whether to consider changing orthogonal ordering of nodes.
Definition: aca.cpp:343