KanoopCommonQt 2.1.1
Kanoop foundational Qt utility library
Loading...
Searching...
No Matches
treepathvertice.h
1/**
2 * @brief A vertex in a spanning-tree path graph used by PathRouter.
3 */
4#ifndef TREEPATHVERTICE_H
5#define TREEPATHVERTICE_H
6
7#include <QMap>
8#include <QPointF>
9#include <QString>
10#include "Kanoop/kanoopcommon.h"
11
12class SpanningTree;
13
14/**
15 * @brief Represents a single vertex in the spanning-tree graph used by PathRouter.
16 *
17 * Each vertice holds a 2D position, a type (standard, ad-hoc origin/destination, or proximal),
18 * a visitation state for graph traversal, and a map of neighbouring vertices.
19 */
20class KANOOP_EXPORT TreePathVertice
21{
22public:
23 /**
24 * @brief Classifies a vertice's role in the path graph.
25 */
27 {
28 Standard, ///< Ordinary obstacle-corner vertex
29 AdHocOrigin, ///< Synthetic origin vertex
30 AdHocDestination, ///< Synthetic destination vertex
31 AdHocOriginProximal, ///< Vertex proximal to the origin
32 AdHocDestinationProximal, ///< Vertex proximal to the destination
33 };
34
35 /**
36 * @brief Tracks whether this vertex has been visited during traversal.
37 */
39 {
40 Unvisited, ///< Not yet visited
41 Visited ///< Already processed by the traversal algorithm
42 };
43
44 /**
45 * @brief Construct a vertice at the given position with a type and parent tree.
46 * @param position 2D position of this vertex
47 * @param type Role of this vertex in the path graph
48 * @param parent Owning SpanningTree
49 */
50 TreePathVertice(const QPointF &position, VerticeType type, SpanningTree* parent);
51
52 /** @brief A map from hash-name string to TreePathVertice pointer. */
53 class Map : public QMap<QString, TreePathVertice*>
54 {
55 };
56
57 /** @brief A list of TreePathVertice pointers. */
58 class List : public QList<TreePathVertice*>
59 {
60 public:
61 /** @brief Default constructor. */
62 List() :
63 QList<TreePathVertice*>() {}
64 /** @brief Construct from a QList of TreePathVertice pointers.
65 * @param source Source list to copy */
66 List(const QList<TreePathVertice*> source) {
67 append(source);
68 }
69 };
70
71 /**
72 * @brief Add a neighbour if not already present.
73 * @param neighbor Vertice to add as a neighbour
74 */
76
77 /**
78 * @brief Replace an existing neighbour with a different vertice.
79 * @param neighbor Neighbour to replace
80 * @param newNeighbor Replacement vertice
81 */
82 void tryReplaceNeighbor(TreePathVertice* neighbor, TreePathVertice* newNeighbor);
83
84 /**
85 * @brief Return the role of this vertex.
86 * @return VerticeType value
87 */
88 VerticeType type() const { return _type; }
89
90 /**
91 * @brief Return the 2D position of this vertex.
92 * @return Position as a QPointF
93 */
94 QPointF position() const { return _position; }
95
96 /**
97 * @brief Return the accumulated path distance to this vertex.
98 * @return Distance value used by shortest-path traversal
99 */
100 double distance() const { return _distance; }
101
102 /**
103 * @brief Set the accumulated path distance.
104 * @param value New distance value
105 */
106 void setDistance(double value) { _distance = value; }
107
108 /**
109 * @brief Return the visitation state.
110 * @return VerticeState value
111 */
112 VerticeState state() const { return _state; }
113
114 /**
115 * @brief Set the visitation state.
116 * @param value New VerticeState
117 */
118 void setState(VerticeState value) { _state = value; }
119
120 /**
121 * @brief Return the human-readable name of this vertex.
122 * @return Name string
123 */
124 QString name() const { return _name; }
125
126 /**
127 * @brief Set the human-readable name of this vertex.
128 * @param value New name string
129 */
130 void setName(const QString& value) { _name = value; }
131
132 /**
133 * @brief Return the predecessor vertex in the shortest path.
134 * @return Pointer to the source vertex, or nullptr if this is the origin
135 */
136 TreePathVertice* source() const { return _source; }
137
138 /**
139 * @brief Set the predecessor vertex in the shortest path.
140 * @param value Pointer to the new source vertex
141 */
142 void setSource(TreePathVertice* value) { _source = value; }
143
144 /**
145 * @brief Return the map of neighbouring vertices.
146 * @return Map of neighbours keyed by hash name
147 */
148 Map neighbors() const { return _neighbors; }
149
150 /**
151 * @brief Return the hash key used to identify this vertex in the graph map.
152 * @return Hash name string
153 */
154 QString hashName() const { return _hashName; }
155
156 /** @brief Return the human-readable name (alias for name()).
157 * @return Name string */
158 QString toString() const { return _name; }
159
160 /**
161 * @brief Create a canonical hash name for a point.
162 * @param point Point to hash
163 * @return String uniquely identifying the point's position
164 */
165 static QString makeHashName(const QPointF &point);
166
167private:
168 VerticeType _type;
169 QPointF _position;
170 double _distance;
171 VerticeState _state;
172 QString _name;
173 QString _hashName;
174 SpanningTree* _spanningTree;
175
176 TreePathVertice* _source;
177 Map _neighbors;
178};
179
180#endif // TREEPATHVERTICE_H
A Dijkstra-based spanning tree for finding shortest paths through a line network.
A list of TreePathVertice pointers.
List(const QList< TreePathVertice * > source)
Construct from a QList of TreePathVertice pointers.
List()
Default constructor.
A map from hash-name string to TreePathVertice pointer.
Represents a single vertex in the spanning-tree graph used by PathRouter.
void setState(VerticeState value)
Set the visitation state.
TreePathVertice * source() const
Return the predecessor vertex in the shortest path.
static QString makeHashName(const QPointF &point)
Create a canonical hash name for a point.
TreePathVertice(const QPointF &position, VerticeType type, SpanningTree *parent)
Construct a vertice at the given position with a type and parent tree.
QString name() const
Return the human-readable name of this vertex.
QString hashName() const
Return the hash key used to identify this vertex in the graph map.
void setName(const QString &value)
Set the human-readable name of this vertex.
VerticeType type() const
Return the role of this vertex.
void setDistance(double value)
Set the accumulated path distance.
void setSource(TreePathVertice *value)
Set the predecessor vertex in the shortest path.
void tryReplaceNeighbor(TreePathVertice *neighbor, TreePathVertice *newNeighbor)
Replace an existing neighbour with a different vertice.
QPointF position() const
Return the 2D position of this vertex.
QString toString() const
Return the human-readable name (alias for name()).
VerticeState state() const
Return the visitation state.
void tryAddNeighbor(TreePathVertice *neighbor)
Add a neighbour if not already present.
Map neighbors() const
Return the map of neighbouring vertices.
double distance() const
Return the accumulated path distance to this vertex.
VerticeState
Tracks whether this vertex has been visited during traversal.
@ Unvisited
Not yet visited.
VerticeType
Classifies a vertice's role in the path graph.
@ AdHocDestination
Synthetic destination vertex.
@ Standard
Ordinary obstacle-corner vertex.
@ AdHocDestinationProximal
Vertex proximal to the destination.
@ AdHocOrigin
Synthetic origin vertex.
@ AdHocOriginProximal
Vertex proximal to the origin.