QGIS API Documentation  2.12.0-Lyon
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 
25 {
26 
27 }
28 
29 int QgsGraph::addVertex( const QgsPoint& pt )
30 {
31  mGraphVertexes.append( QgsGraphVertex( pt ) );
32  return mGraphVertexes.size() - 1;
33 }
34 
35 int QgsGraph::addArc( int outVertexIdx, int inVertexIdx, const QVector< QVariant >& properties )
36 {
37  QgsGraphArc e;
38 
39  e.mProperties = properties;
40  e.mOut = outVertexIdx;
41  e.mIn = inVertexIdx;
42  mGraphArc.push_back( e );
43  int edgeIdx = mGraphArc.size() - 1;
44 
45  mGraphVertexes[ outVertexIdx ].mOutArc.push_back( edgeIdx );
46  mGraphVertexes[ inVertexIdx ].mInArc.push_back( edgeIdx );
47 
48  return mGraphArc.size() - 1;
49 }
50 
51 const QgsGraphVertex& QgsGraph::vertex( int idx ) const
52 {
53  return mGraphVertexes[ idx ];
54 }
55 
56 const QgsGraphArc& QgsGraph::arc( int idx ) const
57 {
58  return mGraphArc[ idx ];
59 }
60 
61 
63 {
64  return mGraphVertexes.size();
65 }
66 
67 int QgsGraph::arcCount() const
68 {
69  return mGraphArc.size();
70 }
71 
72 int QgsGraph::findVertex( const QgsPoint& pt ) const
73 {
74  int i = 0;
75  for ( i = 0; i < mGraphVertexes.size(); ++i )
76  {
77  if ( mGraphVertexes[ i ].point() == pt )
78  {
79  return i;
80  }
81  }
82  return -1;
83 }
84 
86  : mOut( 0 )
87  , mIn( 0 )
88 {
89 
90 }
91 
93 {
94  return mProperties[ i ];
95 }
96 
98 {
99  return mProperties;
100 }
101 
103 {
104  return mIn;
105 }
106 
108 {
109  return mOut;
110 }
111 
113  : mCoordinate( point )
114 {
115 
116 }
117 
119 {
120  return mOutArc;
121 }
122 
124 {
125  return mInArc;
126 }
127 
129 {
130  return mCoordinate;
131 }
QgsGraphArcIdList inArc() const
return incoming edges
Definition: qgsgraph.cpp:123
const QgsGraphArc & arc(int idx) const
return edge at index
Definition: qgsgraph.cpp:56
QgsGraph()
Definition: qgsgraph.cpp:19
int inVertex() const
return index of incoming vertex
Definition: qgsgraph.cpp:102
QVariant property(int propertyIndex) const
return property value
Definition: qgsgraph.cpp:92
void append(const T &value)
QgsGraphArcIdList outArc() const
return outgoing edges
Definition: qgsgraph.cpp:118
QgsPoint point() const
return vertex point
Definition: qgsgraph.cpp:128
~QgsGraph()
Definition: qgsgraph.cpp:24
int outVertex() const
return index of outgoing vertex
Definition: qgsgraph.cpp:107
QVector< QVariant > properties() const
get array of proertyes
Definition: qgsgraph.cpp:97
This class implement a graph edge.
Definition: qgsgraph.h:44
int findVertex(const QgsPoint &pt) const
find vertex by point
Definition: qgsgraph.cpp:72
int arcCount() const
return edge count
Definition: qgsgraph.cpp:67
int addArc(int outVertexIdx, int inVertexIdx, const QVector< QVariant > &properties)
add edge to a graph
Definition: qgsgraph.cpp:35
int addVertex(const QgsPoint &pt)
add vertex to a grap
Definition: qgsgraph.cpp:29
A class to represent a point.
Definition: qgspoint.h:63
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:51
int vertexCount() const
return vertex count
Definition: qgsgraph.cpp:62
int size() const