QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 {
87 
88 }
89 
90 QVariant QgsGraphArc::property( int i ) const
91 {
92  return mProperties[ i ];
93 }
94 
95 QVector< QVariant > QgsGraphArc::properties() const
96 {
97  return mProperties;
98 }
99 
101 {
102  return mIn;
103 }
104 
106 {
107  return mOut;
108 }
109 
111  : mCoordinate( point )
112 {
113 
114 }
115 
117 {
118  return mOutArc;
119 }
120 
122 {
123  return mInArc;
124 }
125 
127 {
128  return mCoordinate;
129 }
QgsGraphArcIdList inArc() const
return incoming edges
Definition: qgsgraph.cpp:121
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:100
QVector< QgsGraphVertex > mGraphVertexes
Definition: qgsgraph.h:176
QVariant property(int propertyIndex) const
return property value
Definition: qgsgraph.cpp:90
QgsGraphArcIdList outArc() const
return outgoing edges
Definition: qgsgraph.cpp:116
QgsPoint point() const
return vertex point
Definition: qgsgraph.cpp:126
QgsPoint mCoordinate
Definition: qgsgraph.h:118
~QgsGraph()
Definition: qgsgraph.cpp:24
int outVertex() const
return index of outgoing vertex
Definition: qgsgraph.cpp:105
QgsGraphArcIdList mInArc
Definition: qgsgraph.h:120
QVector< QVariant > properties() const
get array of proertyes
Definition: qgsgraph.cpp:95
This class implement a graph edge.
Definition: qgsgraph.h:44
int findVertex(const QgsPoint &pt) const
find vertex by point
Definition: qgsgraph.cpp:72
QgsGraphArcIdList mOutArc
Definition: qgsgraph.h:119
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 geometry.
Definition: qgspoint.h:63
QVector< QVariant > mProperties
Definition: qgsgraph.h:72
QVector< QgsGraphArc > mGraphArc
Definition: qgsgraph.h:178
This class implement a graph vertex.
Definition: qgsgraph.h:88
QgsGraphVertex()
default constructor.
Definition: qgsgraph.h:94
const QgsGraphVertex & vertex(int idx) const
return vertex at index
Definition: qgsgraph.cpp:51
int mOut
Definition: qgsgraph.h:74
int vertexCount() const
return vertex count
Definition: qgsgraph.cpp:62
QList< int > QgsGraphArcIdList
Definition: qgsgraph.h:81