Skip to content

Commit

Permalink
New topology tolerance implementation. Some bug fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
stopa85milk committed May 26, 2011
1 parent dd01e40 commit 0564e47
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 26 deletions.
34 changes: 13 additions & 21 deletions src/analysis/network/qgsgraphbuilder.cpp
Expand Up @@ -39,19 +39,15 @@ QgsPoint QgsGraphBuilder::addVertex( const QgsPoint& pt )
if ( id != -1 )
return mGraph->vertex( id ).point();

QgsPoint newPoint = pt;
if ( topologyTolerance() > 0 )
{
int newId = mGraph->addVertex( pt );

QgsFeature f( newId );
f.setGeometry( QgsGeometry::fromPoint( pt ) );
mPointIndex.insertFeature( f );

return pt;
newPoint = QgsPoint( ceil( pt.x() / topologyTolerance() ) * topologyTolerance(),
ceil( pt.y() / topologyTolerance() ) * topologyTolerance() );
}
int newId = mGraph->addVertex( pt );

mPointMap[ pt ] = newId;
mPointMap[ newPoint ] = newId;
return pt;
}

Expand Down Expand Up @@ -82,22 +78,18 @@ QgsGraph* QgsGraphBuilder::graph()

int QgsGraphBuilder::pointId( const QgsPoint& pt )
{
QgsPoint findPoint = pt;
if ( topologyTolerance() > 0.0 )
{
QgsRectangle r( pt.x() - topologyTolerance(), pt.y() - topologyTolerance(), pt.x() + topologyTolerance(), pt.y() + topologyTolerance() );
QList< int > searchResult = mPointIndex.intersects( r );
if ( !searchResult.empty() )
{
return searchResult.front();
}

}else
findPoint = QgsPoint( ceil( pt.x() / topologyTolerance() ) * topologyTolerance() ,
ceil( pt.y() / topologyTolerance() ) * topologyTolerance() ) ;
}

std::map< QgsPoint, int, QgsPointCompare >::iterator it = mPointMap.find( findPoint );
if ( it != mPointMap.end() )
{
std::map< QgsPoint, int, QgsPointCompare >::iterator it = mPointMap.find( pt );
if ( it != mPointMap.end() )
{
return it->second;
}
return it->second;
}

return -1;
}
2 changes: 1 addition & 1 deletion src/analysis/network/qgsgraphbuilderintr.h
Expand Up @@ -66,7 +66,7 @@ class ANALYSIS_EXPORT QgsGraphBuilderInterface
}

//! get topology tolerance
bool topologyTolerance()
double topologyTolerance()
{
return mTopologyTolerance;
}
Expand Down
12 changes: 10 additions & 2 deletions src/analysis/network/qgslinevectorlayerdirector.cpp
Expand Up @@ -98,14 +98,22 @@ void QgsLineVectorLayerDirector::makeGraph( QgsGraphBuilderInterface *builder, c
QgsPolyline::iterator pointIt;
for ( pointIt = pl.begin(); pointIt != pl.end(); ++pointIt )
{
pt2 = ct.transform( *pointIt );
pt2 = builder->addVertex( ct.transform( *pointIt ) );
if ( !isFirstPoint )
{
int i = 0;
for ( i = 0; i != additionalPoints.size(); ++i )
{
TiePointInfo info;
info.mLength = additionalPoints[ i ].sqrDistToSegment( pt1.x(), pt1.y(), pt2.x(), pt2.y(), info.mTiedPoint );
if ( pt1 == pt2 )
{
info.mLength = additionalPoints[ i ].sqrDist( pt1 );
info.mTiedPoint = pt1;
}else
{
info.mLength = additionalPoints[ i ].sqrDistToSegment( pt1.x(), pt1.y(),
pt2.x(), pt2.y(), info.mTiedPoint );
}

if ( pointLengthMap[ i ].mLength > info.mLength )
{
Expand Down
5 changes: 3 additions & 2 deletions src/plugins/roadgraph/shortestpathwidget.cpp
Expand Up @@ -264,7 +264,7 @@ bool RgShortestPathWidget::getPath( QgsGraph* shortestTree, QgsPoint& p1, QgsPoi
// not need
delete director;
}

if ( p1 == QgsPoint( 0.0, 0.0 ) )
{
QMessageBox::critical( this, tr( "Tie point failed" ), tr( "Start point doesn't tie to the road!" ) );
Expand All @@ -275,11 +275,12 @@ bool RgShortestPathWidget::getPath( QgsGraph* shortestTree, QgsPoint& p1, QgsPoi
QMessageBox::critical( this, tr( "Tie point failed" ), tr( "Stop point doesn't tie to the road!" ) );
return false;
}
QgsGraph* graph = builder.graph();

QVector< int > pointIdx(0,0);
QVector< double > pointCost(0,0.0);

int startVertexIdx = graph->findVertex( p1 );
std::cout << " startVertexIdx " << startVertexIdx << "\n";
int criterionNum = 0;
if ( mCriterionName->currentIndex() > 0 )
criterionNum = 1;
Expand Down

0 comments on commit 0564e47

Please sign in to comment.