QGIS API Documentation  3.6.0-Noosa (5873452)
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 "qgspointxy.h"
33 #include "qgis_analysis.h"
34 
35 class QgsGraphVertex;
36 
43 class ANALYSIS_EXPORT QgsGraphEdge
44 {
45  public:
46 
50  QgsGraphEdge() = default;
51 
56  QVariant cost( int strategyIndex ) const;
57 
61  QVector< QVariant > strategies() const;
62 
67  int toVertex() const;
68 
73  int fromVertex() const;
74 
75  private:
76 
77  QVector< QVariant > mStrategies;
78 
79  int mToIdx = 0;
80  int mFromIdx = 0;
81 
82  friend class QgsGraph;
83 };
84 
85 
86 typedef QList< int > QgsGraphEdgeIds;
87 
94 class ANALYSIS_EXPORT QgsGraphVertex
95 {
96  public:
97 
101  QgsGraphVertex() = default;
102 
107  QgsGraphVertex( const QgsPointXY &point );
108 
113  QgsGraphEdgeIds incomingEdges() const;
114 
119  QgsGraphEdgeIds outgoingEdges() const;
120 
124  QgsPointXY point() const;
125 
126  private:
127  QgsPointXY mCoordinate;
128  QgsGraphEdgeIds mIncomingEdges;
129  QgsGraphEdgeIds mOutgoingEdges;
130 
131  friend class QgsGraph;
132 };
133 
141 class ANALYSIS_EXPORT QgsGraph
142 {
143  public:
144 
148  QgsGraph() = default;
149 
150  // Graph constructing methods
151 
155  int addVertex( const QgsPointXY &pt );
156 
161  int addEdge( int fromVertexIdx, int toVertexIdx, const QVector< QVariant > &strategies );
162 
166  int vertexCount() const;
167 
171  const QgsGraphVertex &vertex( int idx ) const;
172 
176  int edgeCount() const;
177 
181  const QgsGraphEdge &edge( int idx ) const;
182 
187  int findVertex( const QgsPointXY &pt ) const;
188 
189  private:
190  QVector<QgsGraphVertex> mGraphVertices;
191 
192  QVector<QgsGraphEdge> mGraphEdges;
193 };
194 
195 #endif // QGSGRAPH_H
A class to represent a 2D point.
Definition: qgspointxy.h:43
Mathematical graph representation.
Definition: qgsgraph.h:141
This class implements a graph vertex.
Definition: qgsgraph.h:94
QList< int > QgsGraphEdgeIds
Definition: qgsgraph.h:86
This class implements a graph edge.
Definition: qgsgraph.h:43