QGIS API Documentation  2.15.0-Master (02a0ebe)
qgsgraph.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2011 by Sergey Yakushev *
3  * yakushevs <at >list.ru *
4  * *
5  * *
6  * This program is free software; you can redistribute it and/or modify *
7  * it under the terms of the GNU General Public License as published by *
8  * the Free Software Foundation; either version 2 of the License, or *
9  * (at your option) any later version. *
10  ***************************************************************************/
11 
17 #include "qgsgraph.h"
18 
20 {
21 }
22 
23 int QgsGraph::addVertex( const QgsPoint& pt )
24 {
25  mGraphVertexes.append( QgsGraphVertex( pt ) );
26  return mGraphVertexes.size() - 1;
27 }
28 
29 int QgsGraph::addArc( int outVertexIdx, int inVertexIdx, const QVector< QVariant >& properties )
30 {
31  QgsGraphArc e;
32 
33  e.mProperties = properties;
34  e.mOut = outVertexIdx;
35  e.mIn = inVertexIdx;
36  mGraphArc.push_back( e );
37  int edgeIdx = mGraphArc.size() - 1;
38 
39  mGraphVertexes[ outVertexIdx ].mOutArc.push_back( edgeIdx );
40  mGraphVertexes[ inVertexIdx ].mInArc.push_back( edgeIdx );
41 
42  return mGraphArc.size() - 1;
43 }
44 
45 const QgsGraphVertex& QgsGraph::vertex( int idx ) const
46 {
47  return mGraphVertexes[ idx ];
48 }
49 
50 const QgsGraphArc& QgsGraph::arc( int idx ) const
51 {
52  return mGraphArc[ idx ];
53 }
54 
56 {
57  return mGraphVertexes.size();
58 }
59 
60 int QgsGraph::arcCount() const
61 {
62  return mGraphArc.size();
63 }
64 
65 int QgsGraph::findVertex( const QgsPoint& pt ) const
66 {
67  int i = 0;
68  for ( i = 0; i < mGraphVertexes.size(); ++i )
69  {
70  if ( mGraphVertexes[ i ].point() == pt )
71  {
72  return i;
73  }
74  }
75  return -1;
76 }
77 
79  : mOut( 0 )
80  , mIn( 0 )
81 {
82 
83 }
84 
86 {
87  return mProperties[ i ];
88 }
89 
91 {
92  return mProperties;
93 }
94 
96 {
97  return mIn;
98 }
99 
101 {
102  return mOut;
103 }
104 
106  : mCoordinate( point )
107 {
108 
109 }
110 
112 {
113  return mOutArc;
114 }
115 
117 {
118  return mInArc;
119 }
120 
122 {
123  return mCoordinate;
124 }
QgsGraphArcIdList inArc() const
return incoming edges
Definition: qgsgraph.cpp:116
const QgsGraphArc & arc(int idx) const
return edge at index
Definition: qgsgraph.cpp:50
QgsGraph()
Definition: qgsgraph.cpp:19
int inVertex() const
return index of incoming vertex
Definition: qgsgraph.cpp:95
QVariant property(int propertyIndex) const
return property value
Definition: qgsgraph.cpp:85
void append(const T &value)
QgsGraphArcIdList outArc() const
return outgoing edges
Definition: qgsgraph.cpp:111
QgsPoint point() const
return vertex point
Definition: qgsgraph.cpp:121
int outVertex() const
return index of outgoing vertex
Definition: qgsgraph.cpp:100
QVector< QVariant > properties() const
get array of properties
Definition: qgsgraph.cpp:90
This class implement a graph edge.
Definition: qgsgraph.h:44
int findVertex(const QgsPoint &pt) const
find vertex by point
Definition: qgsgraph.cpp:65
int arcCount() const
return edge count
Definition: qgsgraph.cpp:60
int addArc(int outVertexIdx, int inVertexIdx, const QVector< QVariant > &properties)
add edge to a graph
Definition: qgsgraph.cpp:29
int addVertex(const QgsPoint &pt)
add vertex to a grap
Definition: qgsgraph.cpp:23
A class to represent a point.
Definition: qgspoint.h:117
This class implement a graph vertex.
Definition: qgsgraph.h:88
QgsGraphVertex()
default constructor.
Definition: qgsgraph.h:94
void push_back(const T &value)
const QgsGraphVertex & vertex(int idx) const
return vertex at index
Definition: qgsgraph.cpp:45
int vertexCount() const
return vertex count
Definition: qgsgraph.cpp:55
int size() const