Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
vertices.h
Go to the documentation of this file.
1/*
2 * vim: ts=4 sw=4 et tw=0 wm=0
3 *
4 * libavoid - Fast, Incremental, Object-avoiding Line Router
5 *
6 * Copyright (C) 2004-2013 Monash University
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 * See the file LICENSE.LGPL distributed with the library.
13 *
14 * Licensees holding a valid commercial license may use this file in
15 * accordance with the commercial license agreement provided with the
16 * 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): Michael Wybrow
23*/
24
25
26#ifndef AVOID_VERTICES_H
27#define AVOID_VERTICES_H
28
29#include <list>
30#include <set>
31#include <map>
32#include <iostream>
33#include <cstdio>
34#include <utility>
35
36#include "libavoid/geomtypes.h"
37
38namespace Avoid {
39
40class EdgeInf;
41class VertInf;
42class Router;
43
44typedef std::list<EdgeInf *> EdgeInfList;
45typedef std::pair<VertInf *, VertInf *> VertexPair;
46
47typedef unsigned int ConnDirFlags;
48typedef unsigned short VertIDProps;
49
50
51class VertID
52{
53 public:
54 unsigned int objID;
55 unsigned short vn;
56 // Properties:
58
59 static const unsigned short src;
60 static const unsigned short tar;
61
67
68 VertID();
69 VertID(unsigned int id, unsigned short n, VertIDProps p = 0);
70 VertID(const VertID& other);
71 VertID& operator= (const VertID& rhs);
72 bool operator==(const VertID& rhs) const;
73 bool operator!=(const VertID& rhs) const;
74 bool operator<(const VertID& rhs) const;
75 VertID operator+(const int& rhs) const;
76 VertID operator-(const int& rhs) const;
77 VertID& operator++(int);
78 void print(FILE *file = stdout) const;
79 void db_print(void) const;
80 friend std::ostream& operator<<(std::ostream& os, const VertID& vID);
81
82 // Property tests:
83 inline bool isOrthShapeEdge(void) const
84 {
85 return (props & PROP_OrthShapeEdge) ? true : false;
86 }
87 inline bool isConnPt(void) const
88 {
89 return (props & PROP_ConnPoint) ? true : false;
90 }
91 inline bool isConnectionPin(void) const
92 {
93 return (props & PROP_ConnectionPin) ? true : false;
94 }
95 inline bool isConnCheckpoint(void) const
96 {
97 return (props & PROP_ConnCheckpoint) ? true : false;
98 }
99 inline bool isDummyPinHelper(void) const
100 {
101 return (props & PROP_DummyPinHelper) ? true : false;
102 }
103};
104
105
106// An ID given to all dummy vertices inserted to allow creation of the
107// orthogonal visibility graph since the vertices in the orthogonal graph
108// mostly do not correspond to shape corners or connector endpoints.
109//
110static const VertID dummyOrthogID(0, 0);
112
113class ANode;
114
116{
117 public:
118 VertInf(Router *router, const VertID& vid, const Point& vpoint,
119 const bool addToRouter = true);
120 ~VertInf();
121 void Reset(const VertID& vid, const Point& vpoint);
122 void Reset(const Point& vpoint);
123 void removeFromGraph(const bool isConnVert = true);
124 bool orphaned(void);
125
126 unsigned int pathLeadsBackTo(const VertInf *start) const;
127 void setVisibleDirections(const ConnDirFlags directions);
128 ConnDirFlags directionFrom(const VertInf *other) const;
129 // Checks if this vertex has the target as a visibility neighbour.
130 EdgeInf *hasNeighbour(VertInf *target, bool orthogonal) const;
131 void orphan(void);
132
134 VertInf *treeRoot(void) const;
135 VertInf **treeRootPointer(void) const;
136 void setTreeRootPointer(VertInf **pointer);
137 void clearTreeRootPointer(void);
138
139 void setSPTFRoot(VertInf *root);
140 VertInf *sptfRoot(void) const;
141
150 unsigned int visListSize;
152 unsigned int orthogVisListSize;
154 unsigned int invisListSize;
156
157 // The tree root and distance value used when computing MTSTs.
158 // XXX: Maybe these should be allocated as a separate struct
159 // and referenced via a pointer. This would be slower due
160 // to memory allocation, but would save 2 x 8 = 24 bytes per
161 // VertInf on 64-bit machines.
164 double sptfDist;
165
167 std::list<ANode *> aStarDoneNodes;
168 std::list<ANode *> aStarPendingNodes;
169 // Flags for orthogonal visibility properties, i.e., whether the
170 // line points to a shape edge, connection point or an obstacle.
171 unsigned int orthogVisPropFlags;
172};
173
174
175// Orthogonal visibility property flags
176static const unsigned int XL_EDGE = 1;
177static const unsigned int XL_CONN = 2;
178static const unsigned int XH_EDGE = 4;
179static const unsigned int XH_CONN = 8;
180static const unsigned int YL_EDGE = 16;
181static const unsigned int YL_CONN = 32;
182static const unsigned int YH_EDGE = 64;
183static const unsigned int YH_CONN = 128;
184
185
186bool directVis(VertInf *src, VertInf *dst);
187
188
189// A linked list of all the vertices in the router instance. All the
190// connector endpoints are listed first, then all the shape vertices.
191// Dummy vertices inserted for orthogonal routing are classed as shape
192// vertices but have VertID(0, 0).
193//
195{
196 public:
197 VertInfList();
198 void addVertex(VertInf *vert);
200 VertInf *getVertexByID(const VertID& id);
201 VertInf *getVertexByPos(const Point& p);
202 VertInf *shapesBegin(void);
203 VertInf *connsBegin(void);
204 VertInf *end(void);
205 unsigned int connsSize(void) const;
206 unsigned int shapesSize(void) const;
207 private:
212 unsigned int _shapeVertices;
213 unsigned int _connVertices;
214};
215
216
217typedef std::set<unsigned int> ShapeSet;
218typedef std::map<VertID, ShapeSet> ContainsMap;
219
220
221}
222
223
224#endif
225
226
The Point class defines a point in the plane.
Definition geomtypes.h:53
The Router class represents a libavoid router instance.
Definition router.h:386
static const unsigned short tar
Definition vertices.h:60
VertID operator+(const int &rhs) const
Definition vertices.cpp:108
static const VertIDProps PROP_DummyPinHelper
Definition vertices.h:66
static const VertIDProps PROP_ConnCheckpoint
Definition vertices.h:65
static const VertIDProps PROP_OrthShapeEdge
Definition vertices.h:63
bool isOrthShapeEdge(void) const
Definition vertices.h:83
VertID & operator++(int)
Definition vertices.cpp:120
VertIDProps props
Definition vertices.h:57
VertID operator-(const int &rhs) const
Definition vertices.cpp:114
static const unsigned short src
Definition vertices.h:59
bool operator==(const VertID &rhs) const
Definition vertices.cpp:77
void db_print(void) const
Definition vertices.cpp:132
friend std::ostream & operator<<(std::ostream &os, const VertID &vID)
Definition vertices.cpp:149
unsigned short vn
Definition vertices.h:55
bool isConnPt(void) const
Definition vertices.h:87
bool operator<(const VertID &rhs) const
Definition vertices.cpp:97
void print(FILE *file=stdout) const
Definition vertices.cpp:127
VertID & operator=(const VertID &rhs)
Definition vertices.cpp:64
static const VertIDProps PROP_ConnectionPin
Definition vertices.h:64
bool isDummyPinHelper(void) const
Definition vertices.h:99
bool operator!=(const VertID &rhs) const
Definition vertices.cpp:87
bool isConnCheckpoint(void) const
Definition vertices.h:95
bool isConnectionPin(void) const
Definition vertices.h:91
unsigned int objID
Definition vertices.h:54
static const VertIDProps PROP_ConnPoint
Definition vertices.h:62
VertInf * getVertexByPos(const Point &p)
Definition vertices.cpp:688
unsigned int connsSize(void) const
Definition vertices.cpp:725
unsigned int _connVertices
Definition vertices.h:213
VertInf * _lastConnVert
Definition vertices.h:211
VertInf * _firstShapeVert
Definition vertices.h:208
VertInf * _firstConnVert
Definition vertices.h:209
unsigned int _shapeVertices
Definition vertices.h:212
unsigned int shapesSize(void) const
Definition vertices.cpp:731
VertInf * _lastShapeVert
Definition vertices.h:210
VertInf * end(void)
Definition vertices.cpp:719
VertInf * shapesBegin(void)
Definition vertices.cpp:702
void addVertex(VertInf *vert)
Definition vertices.cpp:494
VertInf * getVertexByID(const VertID &id)
Definition vertices.cpp:660
VertInf * removeVertex(VertInf *vert)
Definition vertices.cpp:557
VertInf * connsBegin(void)
Definition vertices.cpp:708
VertInf * sptfRoot(void) const
Definition vertices.cpp:415
EdgeInfList visList
Definition vertices.h:149
VertInf * shNext
Definition vertices.h:148
unsigned int visListSize
Definition vertices.h:150
VertInf * pathNext
Definition vertices.h:155
void setVisibleDirections(const ConnDirFlags directions)
Definition vertices.cpp:320
void clearTreeRootPointer(void)
Definition vertices.cpp:398
void setSPTFRoot(VertInf *root)
Definition vertices.cpp:408
Router * _router
Definition vertices.h:142
std::list< ANode * > aStarPendingNodes
Definition vertices.h:168
unsigned int orthogVisListSize
Definition vertices.h:152
void setTreeRootPointer(VertInf **pointer)
Definition vertices.cpp:403
VertInf * lstPrev
Definition vertices.h:145
VertInf ** makeTreeRootPointer(VertInf *root)
Definition vertices.cpp:381
ConnDirFlags visDirections
Definition vertices.h:166
double sptfDist
Definition vertices.h:164
void removeFromGraph(const bool isConnVert=true)
Definition vertices.cpp:228
unsigned int invisListSize
Definition vertices.h:154
VertInf * shPrev
Definition vertices.h:147
ConnDirFlags directionFrom(const VertInf *other) const
Definition vertices.cpp:290
bool orphaned(void)
Definition vertices.cpp:222
std::list< ANode * > aStarDoneNodes
Definition vertices.h:167
VertInf * m_orthogonalPartner
Definition vertices.h:162
VertInf ** m_treeRoot
Definition vertices.h:163
unsigned int pathLeadsBackTo(const VertInf *start) const
Definition vertices.cpp:357
unsigned int orthogVisPropFlags
Definition vertices.h:171
EdgeInf * hasNeighbour(VertInf *target, bool orthogonal) const
Definition vertices.cpp:190
VertInf ** treeRootPointer(void) const
Definition vertices.cpp:393
EdgeInfList orthogVisList
Definition vertices.h:151
VertInf * lstNext
Definition vertices.h:146
void orphan(void)
Definition vertices.cpp:262
VertInf * treeRoot(void) const
Definition vertices.cpp:388
void Reset(const VertID &vid, const Point &vpoint)
Definition vertices.cpp:204
EdgeInfList invisList
Definition vertices.h:153
RootCluster root
Contains the interface for various geometry types and classes.
Geom::Point start
libavoid: Object-avoiding orthogonal and polyline connector routing library.
static const unsigned int YL_EDGE
Definition vertices.h:180
std::map< VertID, ShapeSet > ContainsMap
Definition vertices.h:218
static const unsigned int XL_EDGE
Definition vertices.h:176
static const unsigned int YL_CONN
Definition vertices.h:181
std::list< EdgeInf * > EdgeInfList
Definition vertices.h:44
unsigned short VertIDProps
Definition vertices.h:48
bool directVis(VertInf *src, VertInf *dst)
Definition vertices.cpp:422
static const VertID dummyOrthogID(0, 0)
static const unsigned int XH_CONN
Definition vertices.h:179
static const unsigned int YH_CONN
Definition vertices.h:183
static const unsigned int YH_EDGE
Definition vertices.h:182
std::pair< VertInf *, VertInf * > VertexPair
Definition vertices.h:45
static const VertID dummyOrthogShapeID(0, 0, VertID::PROP_OrthShapeEdge)
std::set< unsigned int > ShapeSet
Definition vertices.h:217
static const unsigned int XH_EDGE
Definition vertices.h:178
static const unsigned int XL_CONN
Definition vertices.h:177
unsigned int ConnDirFlags
One or more Avoid::ConnDirFlag options.
Definition connend.h:83