QGIS API Documentation  2.99.0-Master (cb63e82)
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 #include "qgis_analysis.h"
34 
35 class QgsGraphVertex;
36 
43 class ANALYSIS_EXPORT QgsGraphEdge
44 {
45  public:
46  QgsGraphEdge();
47 
52  QVariant cost( int strategyIndex ) const;
53 
57  QVector< QVariant > strategies() const;
58 
62  int outVertex() const;
63 
67  int inVertex() const;
68 
69  private:
70 
71  QVector< QVariant > mStrategies;
72 
73  int mOut;
74  int mIn;
75 
76  friend class QgsGraph;
77 };
78 
79 
80 typedef QList< int > QgsGraphEdgeIds;
81 
87 class ANALYSIS_EXPORT QgsGraphVertex
88 {
89  public:
90 
95 
100  QgsGraphVertex( const QgsPoint &point );
101 
105  QgsGraphEdgeIds outEdges() const;
106 
110  QgsGraphEdgeIds inEdges() const;
111 
115  QgsPoint point() const;
116 
117  private:
118  QgsPoint mCoordinate;
119  QgsGraphEdgeIds mOutEdges;
120  QgsGraphEdgeIds mInEdges;
121 
122  friend class QgsGraph;
123 };
124 
131 class ANALYSIS_EXPORT QgsGraph
132 {
133  public:
134  QgsGraph();
135 
136  // Graph constructing methods
137 
141  int addVertex( const QgsPoint &pt );
142 
146  int addEdge( int outVertexIdx, int inVertexIdx, const QVector< QVariant > &strategies );
147 
151  int vertexCount() const;
152 
156  const QgsGraphVertex &vertex( int idx ) const;
157 
161  int edgeCount() const;
162 
166  const QgsGraphEdge &edge( int idx ) const;
167 
172  int findVertex( const QgsPoint &pt ) const;
173 
174  private:
175  QVector<QgsGraphVertex> mGraphVertexes;
176 
177  QVector<QgsGraphEdge> mGraphEdges;
178 };
179 
180 #endif // QGSGRAPH_H
A class to represent a point.
Definition: qgspoint.h:37
Mathematical graph representation.
Definition: qgsgraph.h:131
This class implements a graph vertex.
Definition: qgsgraph.h:87
QgsGraphVertex()
Default constructor.
Definition: qgsgraph.h:94
QList< int > QgsGraphEdgeIds
Definition: qgsgraph.h:80
This class implements a graph edge.
Definition: qgsgraph.h:43