26 #ifndef TOPOLOGY_GRAPH_H 27 #define TOPOLOGY_GRAPH_H 31 #include "libvpsc/assertions.h" 32 #include "libvpsc/rectangle.h" 34 #include "libtopology/util.h" 44 class TopologyConstraint;
46 class StraightConstraint;
71 void setDesiredPos(
double d,
double weight=1.0);
72 double initialPos(
vpsc::Dim scanDim)
const;
73 double finalPos()
const;
74 double posOnLine(
vpsc::Dim scanDim,
double alpha)
const;
82 typedef std::vector<Node *>
Nodes;
87 void setNodeVariables(
Nodes& ns, std::vector<vpsc::Variable*>& vs);
112 BendConstraint* bendConstraint;
114 void getBendConstraint(std::vector<TopologyConstraint*>* ts);
116 bool createBendConstraint(
vpsc::Dim scanDim);
118 void deleteBendConstraint();
123 EdgePoint(Node* n, RectIntersect i)
124 : node(n), rectIntersect(i)
125 , inSegment(nullptr), outSegment(nullptr)
126 , bendConstraint(nullptr)
144 unsigned short rectIntersectAsVertexNumber(
void)
const 146 switch(rectIntersect) {
147 case topology::EdgePoint::BR:
149 case topology::EdgePoint::TR:
151 case topology::EdgePoint::TL:
153 case topology::EdgePoint::BL:
163 bool uniqueCheck(
const EdgePoint* e)
const {
164 COLA_ASSERT(
this!=e);
165 return node==e->node && rectIntersect==e->rectIntersect;
182 bool assertConvexBend()
const;
197 typedef std::vector<EdgePoint *> EdgePoints;
198 typedef std::vector<const EdgePoint *> ConstEdgePoints;
213 Segment(Edge* edge, EdgePoint* start, EdgePoint* end)
214 : edge(edge), start(start), end(end)
217 COLA_ASSERT(start!=end);
219 COLA_ASSERT(!start->uniqueCheck(end));
220 start->outSegment=
this;
230 bool createStraightConstraint(
vpsc::Dim dim, Node* node,
double pos);
237 void transferStraightConstraint(StraightConstraint* s);
242 typedef std::binder1st<
243 std::mem_fun1_t<void, Segment, StraightConstraint*>
244 > TransferStraightConstraint;
249 template <
typename T>
250 void forEachStraightConstraint(T f) {
251 for_each(straightConstraints.begin(),straightConstraints.end(),f);
256 void getStraightConstraints(std::vector<TopologyConstraint*>* ts)
261 void deleteStraightConstraints();
274 EdgePoint* getMin(
vpsc::Dim scanDim)
const 276 if (start->pos(vpsc::conjugate(scanDim)) <=
277 end->pos(vpsc::conjugate(scanDim)))
287 EdgePoint* getMax(
vpsc::Dim scanDim)
const 289 if (start->pos(vpsc::conjugate(scanDim)) >
290 end->pos(vpsc::conjugate(scanDim)))
307 double forwardIntersection(
vpsc::Dim scanDim,
double pos,
double &p)
const {
308 return intersection(scanDim, pos, start, end, p);
310 double reverseIntersection(
vpsc::Dim scanDim,
double pos,
double &p)
const {
311 return intersection(scanDim, pos, end, start, p);
313 double forwardIntersection(
vpsc::Dim scanDim,
double pos)
const {
315 return forwardIntersection(scanDim, pos,p);
317 double intersection(
vpsc::Dim scanDim,
const double pos,
318 const EdgePoint* s,
const EdgePoint* e,
double& p)
const 320 double ux=s->pos(scanDim);
321 double vx=e->pos(scanDim);
322 double uy=s->pos(vpsc::conjugate(scanDim));
323 double vy=e->pos(vpsc::conjugate(scanDim));
324 double denom = vy - uy;
325 COLA_ASSERT(denom!=0);
326 p = (pos - uy)/denom;
327 return ux + p * (vx-ux);
329 std::string toString()
const;
337 double length()
const;
338 void assertNonZeroLength()
const;
342 bool connectedToNode(
const Node* v)
const;
346 std::vector<StraightConstraint*> straightConstraints;
349 template <
typename T>
351 void operator() (T t)
366 template <
typename PEdge,
369 void ForEach(PEdge e, PointOp po, SegmentOp so,
bool noCycle=
false) {
370 Segment* s=e->firstSegment;
371 if(!(e->cycle()&&noCycle)) {
378 if(s==e->lastSegment) {
416 Edge(
unsigned id,
double idealLength, EdgePoints &vs)
418 , idealLength(idealLength)
419 , firstSegment(nullptr), lastSegment(nullptr)
422 EdgePoints::iterator
a=vs.begin();
423 for(EdgePoints::iterator
b=
a+1;
b!=vs.end();++
a,++
b) {
424 Segment* s =
new Segment(
this,*
a,*
b);
426 if(firstSegment==
nullptr) {
438 template <
typename Po
intOp,
typename SegmentOp>
439 void forEach(PointOp po, SegmentOp so,
bool noCycle=
false) {
440 ForEach<Edge*,PointOp,SegmentOp>(
this,po,so,noCycle);
448 template <
typename Po
intOp,
typename SegmentOp>
449 void forEach(PointOp po, SegmentOp so,
bool noCycle=
false)
const {
450 ForEach<const Edge*,PointOp,SegmentOp>(
this,po,so,noCycle);
457 template <
typename T>
458 void forEachSegment(T o) {
459 forEach(NoOp<EdgePoint*>(),o);
465 template <
typename T>
466 void forEachSegment(T o)
const {
467 forEach(NoOp<const EdgePoint*>(),o);
476 template <
typename T>
477 void forEachEdgePoint(T o,
bool noCycle=
false) {
478 forEach(o,NoOp<Segment*>(),noCycle);
486 template <
typename T>
487 void forEachEdgePoint(T o,
bool noCycle=
false)
const {
488 forEach(o,NoOp<const Segment*>(),noCycle);
499 forEach(delete_object(),delete_object(),
true);
506 double pathLength()
const;
510 void getPath(ConstEdgePoints& vs)
const;
514 straightener::Route* getRoute()
const;
515 void getTopologyConstraints(std::vector<TopologyConstraint*>* ts)
519 std::mem_fun(&EdgePoint::getBendConstraint),ts),
521 std::mem_fun(&Segment::getStraightConstraints),ts),
524 bool assertConvexBends()
const;
526 return firstSegment->start==lastSegment->end;
528 std::string toString()
const;
534 double compute_stress(
const Edges&);
535 void printEdges(
const Edges&);
541 inline double crossProduct(
542 double x0,
double y0,
543 double x1,
double y1,
544 double x2,
double y2) {
545 return (x1-x0)*(y2-y0)-(x2-x0)*(y1-y0);
549 bool assertConvexBends(
const Edges&);
557 bool assertNoSegmentRectIntersection(
const Nodes&,
const Edges&);
558 bool assertNoZeroLengthEdgeSegments(
const Edges& es);
561 #endif // TOPOLOGY_GRAPH_H A line between two points.
Definition: geomtypes.h:188
A variable is comprised of an ideal position, final position and a weight.
Definition: variable.h:44
libtopology: Extensions for topology preservation for libcola and libavoid libraries.
Definition: shape.h:41
Segment * lastSegment
Definition: topology_graph.h:410
Edge(unsigned id, double idealLength, EdgePoints &vs)
Definition: topology_graph.h:416
Definition: gradient_projection.h:40
std::pair< unsigned, unsigned > Edge
Edges are simply a pair of indices to entries in the Node vector.
Definition: cola.h:68
libvpsc: Variable Placement with Separation Constraints quadratic program solver library.
Definition: assertions.h:61
Point a
The first point.
Definition: geomtypes.h:192
Point b
The second point.
Definition: geomtypes.h:194
std::vector< Node * > Nodes
A vector of pointers to Node objects.
Definition: topology_graph.h:82
A rectangle represents a fixed-size shape in the diagram that may be moved to prevent overlaps and sa...
Definition: rectangle.h:78
The y-dimension (1).
Definition: rectangle.h:47
std::vector< Edge * > Edges
A vector of pointers to Edge objects.
Definition: topology_graph.h:533
The x-dimension (0).
Definition: rectangle.h:43
double idealLength
the ideal length which the layout should try to obtain for this edge
Definition: topology_graph.h:401
Dim
Indicates the x- or y-dimension.
Definition: rectangle.h:41
Segment * firstSegment
Definition: topology_graph.h:406
unsigned id
id specified by user. Can be used to match to external edge.
Definition: topology_graph.h:399