QGIS API Documentation  2.14.0-Essen
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 
55 
57 {
58  return mGraphVertexes.size();
59 }
60 
61 int QgsGraph::arcCount() const
62 {
63  return mGraphArc.size();
64 }
65 
66 int QgsGraph::findVertex( const QgsPoint& pt ) const
67 {
68  int i = 0;
69  for ( i = 0; i < mGraphVertexes.size(); ++i )
70  {
71  if ( mGraphVertexes[ i ].point() == pt )
72  {
73  return i;
74  }
75  }
76  return -1;
77 }
78 
80  : mOut( 0 )
81  , mIn( 0 )
82 {
83 
84 }
85 
87 {
88  return mProperties[ i ];
89 }
90 
92 {
93  return mProperties;
94 }
95 
97 {
98  return mIn;
99 }
100 
102 {
103  return mOut;
104 }
105 
107  : mCoordinate( point )
108 {
109 
110 }
111 
113 {
114  return mOutArc;
115 }
116 
118 {
119  return mInArc;
120 }
121 
123 {
124  return mCoordinate;
125 }
QgsGraphArcIdList inArc() const
return incoming edges
Definition: qgsgraph.cpp:117
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:96
QVariant property(int propertyIndex) const
return property value
Definition: qgsgraph.cpp:86
void append(const T &value)
QgsGraphArcIdList outArc() const
return outgoing edges
Definition: qgsgraph.cpp:112
QgsPoint point() const
return vertex point
Definition: qgsgraph.cpp:122
int outVertex() const
return index of outgoing vertex
Definition: qgsgraph.cpp:101
QVector< QVariant > properties() const
get array of properties
Definition: qgsgraph.cpp:91
This class implement a graph edge.
Definition: qgsgraph.h:44
int findVertex(const QgsPoint &pt) const
find vertex by point
Definition: qgsgraph.cpp:66
int arcCount() const
return edge count
Definition: qgsgraph.cpp:61
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:65
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:56
int size() const