QGIS API Documentation  2.99.0-Master (6a61179)
qgsgraph.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsgraph.h
3  --------------------------------------
4  Date : 2011-04-01
5  Copyright : (C) 2010 by Yakushev Sergey
6  Email : YakushevS <at> list.ru
7 ****************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15 
16 /*
17  * This file describes the built-in QGIS classes for modeling a mathematical graph.
18  * Vertices are identified by their geographic coordinates and have no additional
19  * properties. Number of strategies for calculating edge cost is not limited.
20  * Graph may have incidence edges.
21  *
22  * \file qgsgraph.h
23  */
24 
25 #ifndef QGSGRAPH_H
26 #define QGSGRAPH_H
27 
28 #include <QList>
29 #include <QVector>
30 #include <QVariant>
31 
32 #include "qgspoint.h"
33 
34 class QgsGraphVertex;
35 
42 class ANALYSIS_EXPORT QgsGraphEdge
43 {
44  public:
45  QgsGraphEdge();
46 
51  QVariant cost( int strategyIndex ) const;
52 
56  QVector< QVariant > strategies() const;
57 
61  int outVertex() const;
62 
66  int inVertex() const;
67 
68  private:
69 
70  QVector< QVariant > mStrategies;
71 
72  int mOut;
73  int mIn;
74 
75  friend class QgsGraph;
76 };
77 
78 
79 typedef QList< int > QgsGraphEdgeIds;
80 
86 class ANALYSIS_EXPORT QgsGraphVertex
87 {
88  public:
89 
94 
99  QgsGraphVertex( const QgsPoint& point );
100 
104  QgsGraphEdgeIds outEdges() const;
105 
109  QgsGraphEdgeIds inEdges() const;
110 
114  QgsPoint point() const;
115 
116  private:
117  QgsPoint mCoordinate;
118  QgsGraphEdgeIds mOutEdges;
119  QgsGraphEdgeIds mInEdges;
120 
121  friend class QgsGraph;
122 };
123 
130 class ANALYSIS_EXPORT QgsGraph
131 {
132  public:
133  QgsGraph();
134 
135  // Graph constructing methods
136 
140  int addVertex( const QgsPoint& pt );
141 
145  int addEdge( int outVertexIdx, int inVertexIdx, const QVector< QVariant >& strategies );
146 
150  int vertexCount() const;
151 
155  const QgsGraphVertex& vertex( int idx ) const;
156 
160  int edgeCount() const;
161 
165  const QgsGraphEdge& edge( int idx ) const;
166 
171  int findVertex( const QgsPoint& pt ) const;
172 
173  private:
174  QVector<QgsGraphVertex> mGraphVertexes;
175 
176  QVector<QgsGraphEdge> mGraphEdges;
177 };
178 
179 #endif // QGSGRAPH_H
A class to represent a point.
Definition: qgspoint.h:111
Mathematical graph representation.
Definition: qgsgraph.h:130
This class implements a graph vertex.
Definition: qgsgraph.h:86
QgsGraphVertex()
Default constructor.
Definition: qgsgraph.h:93
QList< int > QgsGraphEdgeIds
Definition: qgsgraph.h:79
This class implements a graph edge.
Definition: qgsgraph.h:42