Quantum GIS API Documentation  1.8
src/analysis/network/qgsgraph.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2011 by Sergey Yakushev                                 *
00003  *   yakushevs <at >list.ru                                                *
00004  *                                                                         *
00005  *                                                                         *
00006  *   This program is free software; you can redistribute it and/or modify  *
00007  *   it under the terms of the GNU General Public License as published by  *
00008  *   the Free Software Foundation; either version 2 of the License, or     *
00009  *   (at your option) any later version.                                   *
00010  ***************************************************************************/
00011 
00017 #include "qgsgraph.h"
00018 
00019 QgsGraph::QgsGraph()
00020 {
00021 }
00022 
00023 
00024 QgsGraph::~QgsGraph()
00025 {
00026 
00027 }
00028 
00029 int QgsGraph::addVertex( const QgsPoint& pt )
00030 {
00031   mGraphVertexes.append( QgsGraphVertex( pt ) );
00032   return mGraphVertexes.size() - 1;
00033 }
00034 
00035 int QgsGraph::addArc( int outVertexIdx, int inVertexIdx, const QVector< QVariant >& properties )
00036 {
00037   QgsGraphArc e;
00038 
00039   e.mProperties = properties;
00040   e.mOut = outVertexIdx;
00041   e.mIn  = inVertexIdx;
00042   mGraphArc.push_back( e );
00043   int edgeIdx = mGraphArc.size() - 1;
00044 
00045   mGraphVertexes[ outVertexIdx ].mOutArc.push_back( edgeIdx );
00046   mGraphVertexes[ inVertexIdx ].mInArc.push_back( edgeIdx );
00047 
00048   return mGraphArc.size() - 1;
00049 }
00050 
00051 const QgsGraphVertex& QgsGraph::vertex( int idx ) const
00052 {
00053   return mGraphVertexes[ idx ];
00054 }
00055 
00056 const QgsGraphArc& QgsGraph::arc( int idx ) const
00057 {
00058   return mGraphArc[ idx ];
00059 }
00060 
00061 
00062 int QgsGraph::vertexCount() const
00063 {
00064   return mGraphVertexes.size();
00065 }
00066 
00067 int QgsGraph::arcCount() const
00068 {
00069   return mGraphArc.size();
00070 }
00071 
00072 int QgsGraph::findVertex( const QgsPoint& pt ) const
00073 {
00074   int i = 0;
00075   for ( i = 0; i < mGraphVertexes.size(); ++i )
00076   {
00077     if ( mGraphVertexes[ i ].point() == pt )
00078     {
00079       return i;
00080     }
00081   }
00082   return -1;
00083 }
00084 
00085 QgsGraphArc::QgsGraphArc()
00086 {
00087 
00088 }
00089 
00090 QVariant QgsGraphArc::property( int i ) const
00091 {
00092   return mProperties[ i ];
00093 }
00094 
00095 QVector< QVariant > QgsGraphArc::properties() const
00096 {
00097   return mProperties;
00098 }
00099 
00100 int QgsGraphArc::inVertex() const
00101 {
00102   return mIn;
00103 }
00104 
00105 int QgsGraphArc::outVertex() const
00106 {
00107   return mOut;
00108 }
00109 
00110 QgsGraphVertex::QgsGraphVertex( const QgsPoint& point )
00111     : mCoordinate( point )
00112 {
00113 
00114 }
00115 
00116 QgsGraphArcIdList QgsGraphVertex::outArc() const
00117 {
00118   return mOutArc;
00119 }
00120 
00121 QgsGraphArcIdList QgsGraphVertex::inArc() const
00122 {
00123   return mInArc;
00124 }
00125 
00126 QgsPoint QgsGraphVertex::point() const
00127 {
00128   return mCoordinate;
00129 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines