80 changes: 41 additions & 39 deletions src/analysis/network/qgslinevectorlayerdirector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,40 +36,40 @@ class QgsPointCompare
{
public:
QgsPointCompare( double tolerance ) :
mTolerance( tolerance )
mTolerance( tolerance )
{ }

bool operator()( const QgsPoint& p1, const QgsPoint& p2 ) const
{
if ( mTolerance <= 0 )
return p1.x() == p2.x() ? p1.y() < p2.y() : p1.x() < p2.x();

double tx1 = ceil( p1.x()/mTolerance );
double tx2 = ceil( p2.x()/mTolerance );
double tx1 = ceil( p1.x() / mTolerance );
double tx2 = ceil( p2.x() / mTolerance );
if ( tx1 == tx2 )
return ceil( p1.y()/mTolerance ) < ceil( p2.y()/mTolerance );
return ceil( p1.y() / mTolerance ) < ceil( p2.y() / mTolerance );
return tx1 < tx2;
}

private:
double mTolerance;
};

template <typename RandIter, typename Type, typename CompareOp > RandIter my_binary_search( RandIter begin, RandIter end, Type val, CompareOp comp)
template <typename RandIter, typename Type, typename CompareOp > RandIter my_binary_search( RandIter begin, RandIter end, Type val, CompareOp comp )
{
// result if not found
RandIter not_found = end;

while ( true )
{
RandIter avg = begin + (end-begin)/2;
RandIter avg = begin + ( end - begin ) / 2;
if ( begin == avg || end == avg )
{
if ( !comp( *begin, val ) && !comp( val, *begin ) )
return begin;
if ( !comp( *end, val ) && !comp( val, *end ) )
return end;

return not_found;
}
if ( comp( val, *avg ) )
Expand All @@ -88,7 +88,7 @@ struct TiePointInfo
QgsPoint mTiedPoint;
double mLength;
QgsPoint mFirstPoint;
QgsPoint mLastPoint;
QgsPoint mLastPoint;
};

bool TiePointInfoCompare( const TiePointInfo& a, const TiePointInfo& b )
Expand All @@ -105,7 +105,7 @@ QgsLineVectorLayerDirector::QgsLineVectorLayerDirector( QgsVectorLayer *myLayer,
const QString& reverseDirectionValue,
const QString& bothDirectionValue,
int defaultDirection
)
)
{
mVectorLayer = myLayer;
mDirectionFieldId = directionFieldId;
Expand Down Expand Up @@ -141,19 +141,20 @@ void QgsLineVectorLayerDirector::makeGraph( QgsGraphBuilderInterface *builder, c
if ( builder->coordinateTransformationEnabled() )
{
ct.setDestCRS( builder->destinationCrs() );
}else
}
else
{
ct.setDestCRS( vl->crs() );
}

tiedPoint = QVector< QgsPoint >( additionalPoints.size(), QgsPoint( 0.0, 0.0 ) );

TiePointInfo tmpInfo;
tmpInfo.mLength = std::numeric_limits<double>::infinity();

QVector< TiePointInfo > pointLengthMap( additionalPoints.size(), tmpInfo );
QVector< TiePointInfo >::iterator pointLengthIt;

//Graph's points;
QVector< QgsPoint > points;

Expand All @@ -168,7 +169,7 @@ void QgsLineVectorLayerDirector::makeGraph( QgsGraphBuilderInterface *builder, c
mpl = feature.geometry()->asMultiPolyline();
else if ( feature.geometry()->wkbType() == QGis::WKBLineString )
mpl.push_back( feature.geometry()->asPolyline() );

QgsMultiPolyline::iterator mplIt;
for ( mplIt = mpl.begin(); mplIt != mpl.end(); ++mplIt )
{
Expand All @@ -190,10 +191,11 @@ void QgsLineVectorLayerDirector::makeGraph( QgsGraphBuilderInterface *builder, c
{
info.mLength = additionalPoints[ i ].sqrDist( pt1 );
info.mTiedPoint = pt1;
}else
}
else
{
info.mLength = additionalPoints[ i ].sqrDistToSegment( pt1.x(), pt1.y(),
pt2.x(), pt2.y(), info.mTiedPoint );
info.mLength = additionalPoints[ i ].sqrDistToSegment( pt1.x(), pt1.y(),
pt2.x(), pt2.y(), info.mTiedPoint );
}

if ( pointLengthMap[ i ].mLength > info.mLength )
Expand All @@ -215,7 +217,7 @@ void QgsLineVectorLayerDirector::makeGraph( QgsGraphBuilderInterface *builder, c
}
// end: tie points to graph

// add tied point to graph
// add tied point to graph
int i = 0;
for ( i = 0; i < tiedPoint.size(); ++i )
{
Expand All @@ -224,19 +226,19 @@ void QgsLineVectorLayerDirector::makeGraph( QgsGraphBuilderInterface *builder, c
points.push_back( tiedPoint [ i ] );
}
}

QgsPointCompare pointCompare( builder->topologyTolerance() );

qSort( points.begin(), points.end(), pointCompare );
QVector< QgsPoint >::iterator tmp = std::unique( points.begin(), points.end() );
QVector< QgsPoint >::iterator tmp = std::unique( points.begin(), points.end() );
points.resize( tmp - points.begin() );


for (i=0;i<points.size();++i)
for ( i = 0;i < points.size();++i )
builder->addVertex( i, points[ i ] );
for ( i = 0; i < tiedPoint.size() ; ++i)
tiedPoint[ i ] = *(my_binary_search( points.begin(), points.end(), tiedPoint[ i ], pointCompare ) );

for ( i = 0; i < tiedPoint.size() ; ++i )
tiedPoint[ i ] = *( my_binary_search( points.begin(), points.end(), tiedPoint[ i ], pointCompare ) );

qSort( pointLengthMap.begin(), pointLengthMap.end(), TiePointInfoCompare );

Expand All @@ -252,16 +254,16 @@ void QgsLineVectorLayerDirector::makeGraph( QgsGraphBuilderInterface *builder, c

for ( it = mProperterList.begin(); it != mProperterList.end(); ++it )
{
QgsAttributeList tmp = (*it)->requiredAttributes();
QgsAttributeList tmp = ( *it )->requiredAttributes();
for ( it2 = tmp.begin(); it2 != tmp.end(); ++it2 )
{
tmpAttr.push_back( *it2 );
}
}
qSort( tmpAttr.begin(), tmpAttr.end() );

int lastAttrId = -1;
for ( it2 = tmpAttr.begin(); it2 != tmpAttr.end(); ++it2 )
for ( it2 = tmpAttr.begin(); it2 != tmpAttr.end(); ++it2 )
{
if ( *it2 == lastAttrId )
{
Expand All @@ -273,7 +275,7 @@ void QgsLineVectorLayerDirector::makeGraph( QgsGraphBuilderInterface *builder, c
lastAttrId = *it2;
}
} // end fill attribute list 'la'

// begin graph construction
vl->select( la );
while ( vl->nextFeature( feature ) )
Expand Down Expand Up @@ -309,7 +311,7 @@ void QgsLineVectorLayerDirector::makeGraph( QgsGraphBuilderInterface *builder, c
mpl = feature.geometry()->asMultiPolyline();
else if ( feature.geometry()->wkbType() == QGis::WKBLineString )
mpl.push_back( feature.geometry()->asPolyline() );

QgsMultiPolyline::iterator mplIt;
for ( mplIt = mpl.begin(); mplIt != mpl.end(); ++mplIt )
{
Expand All @@ -320,33 +322,33 @@ void QgsLineVectorLayerDirector::makeGraph( QgsGraphBuilderInterface *builder, c
for ( pointIt = mplIt->begin(); pointIt != mplIt->end(); ++pointIt )
{
pt2 = ct.transform( *pointIt );

if ( !isFirstPoint )
{
std::map< double, QgsPoint > pointsOnArc;
pointsOnArc[ 0.0 ] = pt1;
pointsOnArc[ pt1.sqrDist( pt2 )] = pt2;

TiePointInfo t;
t.mFirstPoint = pt1;
t.mLastPoint = pt2;
pointLengthIt = my_binary_search( pointLengthMap.begin(), pointLengthMap.end(), t, TiePointInfoCompare );

if ( pointLengthIt != pointLengthMap.end() )
{
QVector< TiePointInfo >::iterator it;
for ( it = pointLengthIt; it - pointLengthMap.begin() >= 0; --it )
{
if ( it->mFirstPoint == pt1 && it->mLastPoint == pt2 )
{
pointsOnArc[ pt1.sqrDist( it->mTiedPoint ) ] = it->mTiedPoint;
pointsOnArc[ pt1.sqrDist( it->mTiedPoint )] = it->mTiedPoint;
}
}
for ( it = pointLengthIt+1; it != pointLengthMap.end(); ++it )
for ( it = pointLengthIt + 1; it != pointLengthMap.end(); ++it )
{
if ( it->mFirstPoint == pt1 && it->mLastPoint == pt2 )
{
pointsOnArc[ pt1.sqrDist( it->mTiedPoint ) ] = it->mTiedPoint;
pointsOnArc[ pt1.sqrDist( it->mTiedPoint )] = it->mTiedPoint;
}
}
}
Expand All @@ -370,9 +372,9 @@ void QgsLineVectorLayerDirector::makeGraph( QgsGraphBuilderInterface *builder, c
QList< QgsArcProperter* >::const_iterator it;
for ( it = mProperterList.begin(); it != mProperterList.end(); ++it )
{
prop.push_back( (*it)->property( distance, feature ) );
prop.push_back(( *it )->property( distance, feature ) );
}

if ( directionType == 1 ||
directionType == 3 )
{
Expand Down
14 changes: 7 additions & 7 deletions src/analysis/network/qgslinevectorlayerdirector.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,16 @@ class QgsLineVectorLayerDirector : public QgsGraphDirector
* @param defaultDirection 1 - direct direction, 2 - reverse direction, 3 - both direction
*/
QgsLineVectorLayerDirector( QgsVectorLayer* vl,
int directionFieldId,
const QString& directDirectionValue,
const QString& reverseDirectionValue,
const QString& bothDirectionValue,
int defaultDirection
);
int directionFieldId,
const QString& directDirectionValue,
const QString& reverseDirectionValue,
const QString& bothDirectionValue,
int defaultDirection
);

//! Destructor
virtual ~QgsLineVectorLayerDirector();

/*
* MANDATORY DIRECTOR PROPERTY DECLARATION
*/
Expand Down
8 changes: 4 additions & 4 deletions src/core/symbology-ng/qgsellipsesymbollayerv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,9 @@ void QgsEllipseSymbolLayerV2::preparePath( const QString& symbolName, QgsSymbolV
{
width = context.outputLineWidth( f->attributeMap()[mWidthField.first].toDouble() );
}
else if( context.renderHints() & QgsSymbolV2::DataDefinedSizeScale ) //2. priority: is data defined size on symbol level
else if ( context.renderHints() & QgsSymbolV2::DataDefinedSizeScale ) //2. priority: is data defined size on symbol level
{
width = context.outputLineWidth( mSize );
width = context.outputLineWidth( mSize );
}
else //3. priority: global width setting
{
Expand All @@ -230,9 +230,9 @@ void QgsEllipseSymbolLayerV2::preparePath( const QString& symbolName, QgsSymbolV
{
height = context.outputLineWidth( f->attributeMap()[mHeightField.first].toDouble() );
}
else if( context.renderHints() & QgsSymbolV2::DataDefinedSizeScale ) //2. priority: is data defined size on symbol level
else if ( context.renderHints() & QgsSymbolV2::DataDefinedSizeScale ) //2. priority: is data defined size on symbol level
{
height = context.outputLineWidth( mSize );
height = context.outputLineWidth( mSize );
}
else //3. priority: global height setting
{
Expand Down
22 changes: 11 additions & 11 deletions src/plugins/roadgraph/roadgraphplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ void RoadGraphPlugin::initGui()

// Set the what's this text
mQSettingsAction->setWhatsThis( tr( "Road graph plugin settings" ) );
mInfoAction->setWhatsThis( tr( "About Road graph plugin" ) );
mInfoAction->setWhatsThis( tr( "About Road graph plugin" ) );

setGuiElementsToDefault();

Expand All @@ -131,7 +131,7 @@ void RoadGraphPlugin::unload()
// remove the GUI
mQGisIface->removePluginMenu( tr( "Road graph" ), mQSettingsAction );
mQGisIface->removePluginMenu( tr( "Road graph" ), mInfoAction );

// disconnect
disconnect( mQGisIface->mainWindow(), SIGNAL( projectRead() ), this, SLOT( projectRead() ) );
disconnect( mQGisIface->mainWindow(), SIGNAL( newProject() ), this, SLOT( newProject() ) );
Expand Down Expand Up @@ -271,18 +271,18 @@ const QgsGraphDirector* RoadGraphPlugin::director() const
if ( provider == NULL )
return NULL;
SpeedUnit speedUnit = SpeedUnit::byName( mSettings->mSpeedUnitName );

QgsLineVectorLayerDirector * director =
new QgsLineVectorLayerDirector( layer,
provider->fieldNameIndex( mSettings->mDirection ),
mSettings->mFirstPointToLastPointDirectionVal,
mSettings->mLastPointToFirstPointDirectionVal,
mSettings->mBothDirectionVal,
mSettings->mDefaultDirection
);
provider->fieldNameIndex( mSettings->mDirection ),
mSettings->mFirstPointToLastPointDirectionVal,
mSettings->mLastPointToFirstPointDirectionVal,
mSettings->mBothDirectionVal,
mSettings->mDefaultDirection
);
director->addProperter( new QgsDistanceArcProperter() );
director->addProperter( new RgSpeedProperter( provider->fieldNameIndex( mSettings->mSpeed ),
mSettings->mDefaultSpeed, speedUnit.multipler() ) );
director->addProperter( new RgSpeedProperter( provider->fieldNameIndex( mSettings->mSpeed ),
mSettings->mDefaultSpeed, speedUnit.multipler() ) );
return director;
}
return NULL;
Expand Down
96 changes: 48 additions & 48 deletions src/plugins/roadgraph/shortestpathwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,9 @@ bool RgShortestPathWidget::getPath( QgsGraph* shortestTree, QgsPoint& p1, QgsPoi
return false;
}

QgsGraphBuilder builder(
mPlugin->iface()->mapCanvas()->mapRenderer()->destinationCrs(),
mPlugin->iface()->mapCanvas()->mapRenderer()->hasCrsTransformEnabled(),
QgsGraphBuilder builder(
mPlugin->iface()->mapCanvas()->mapRenderer()->destinationCrs(),
mPlugin->iface()->mapCanvas()->mapRenderer()->hasCrsTransformEnabled(),
mPlugin->topologyToleranceFactor() );
{
const QgsGraphDirector *director = mPlugin->director();
Expand All @@ -258,13 +258,13 @@ bool RgShortestPathWidget::getPath( QgsGraph* shortestTree, QgsPoint& p1, QgsPoi
points.push_back( mFrontPoint );
points.push_back( mBackPoint );
director->makeGraph( &builder, points, tiedPoint );

p1 = tiedPoint[ 0 ];
p2 = tiedPoint[ 1 ];
// 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 @@ -278,19 +278,19 @@ bool RgShortestPathWidget::getPath( QgsGraph* shortestTree, QgsPoint& p1, QgsPoi

QgsGraph *graph = builder.graph();

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

int startVertexIdx = graph->findVertex( p1 );

int criterionNum = 0;
if ( mCriterionName->currentIndex() > 0 )
criterionNum = 1;

QgsGraphAnalyzer::shortestpath( graph, startVertexIdx, criterionNum, pointIdx, pointCost, shortestTree );

delete graph;

if ( shortestTree->findVertex( p2 ) == -1 )
{
QMessageBox::critical( this, tr( "Path not found" ), tr( "Path not found" ) );
Expand All @@ -303,29 +303,29 @@ void RgShortestPathWidget::findingPath()
{
QgsPoint p1, p2;
QgsGraph path;
if ( !getPath( &path, p1, p2) )

if ( !getPath( &path, p1, p2 ) )
return;

mrbPath->reset( false );
double time = 0.0;
double cost = 0.0;

int startVertexIdx = path.findVertex( p1 );
int stopVertexIdx = path.findVertex( p2 );
QList< QgsPoint > p;
while( startVertexIdx != stopVertexIdx )
while ( startVertexIdx != stopVertexIdx )
{
QgsGraphArcIdList l = path.vertex( stopVertexIdx ).inArc();
if ( l.empty() )
break;
const QgsGraphArc& e = path.arc( l.front() );
cost += e.property(0).toDouble();
time += e.property(1).toDouble();

cost += e.property( 0 ).toDouble();
time += e.property( 1 ).toDouble();

p.push_front( path.vertex( e.in() ).point() );

stopVertexIdx = e.out();
}
p.push_front( p1 );
Expand All @@ -334,7 +334,7 @@ void RgShortestPathWidget::findingPath()
{
mrbPath->addPoint( *it );
}

Unit timeUnit = Unit::byName( mPlugin->timeUnitName() );
Unit distanceUnit = Unit::byName( mPlugin->distanceUnitName() );

Expand All @@ -357,39 +357,39 @@ void RgShortestPathWidget::clear()

void RgShortestPathWidget::exportPath()
{
/* RgExportDlg dlg( this );
if ( !dlg.exec() )
return;
/* RgExportDlg dlg( this );
if ( !dlg.exec() )
return;
QgsPoint p1, p2;
QgsGraph path;
if ( !getPath( path, p1, p2 ) )
return;
QgsPoint p1, p2;
QgsGraph path;
if ( !getPath( path, p1, p2 ) )
return;
QgsVectorLayer *vl = dlg.mapLayer();
if ( vl == NULL )
return;
QgsVectorLayer *vl = dlg.mapLayer();
if ( vl == NULL )
return;
QgsCoordinateTransform ct( mPlugin->iface()->mapCanvas()->mapRenderer()->destinationCrs(),
vl->crs() );
QgsCoordinateTransform ct( mPlugin->iface()->mapCanvas()->mapRenderer()->destinationCrs(),
vl->crs() );
while ( it != path.end() )
{
AdjacencyMatrixString::iterator it2 = it->second.begin();
if ( it2 == it->second.end() )
break;
points.append( ct.transform( it2->first ) );
it = path.find( it2->first );
}
while ( it != path.end() )
{
AdjacencyMatrixString::iterator it2 = it->second.begin();
if ( it2 == it->second.end() )
break;
points.append( ct.transform( it2->first ) );
it = path.find( it2->first );
}
vl->startEditing();
QgsFeature f;
f.setGeometry( QgsGeometry::fromPolyline( points ) );
vl->addFeature( f );
vl->updateExtents();
vl->startEditing();
QgsFeature f;
f.setGeometry( QgsGeometry::fromPolyline( points ) );
vl->addFeature( f );
vl->updateExtents();
mPlugin->iface()->mapCanvas()->update();
*/
mPlugin->iface()->mapCanvas()->update();
*/
}

void RgShortestPathWidget::helpRequested()
Expand Down
8 changes: 4 additions & 4 deletions src/plugins/roadgraph/speedproperter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ QVariant RgSpeedProperter::property( double distance, const QgsFeature& f ) cons
QgsAttributeMap::const_iterator it = map.find( mAttributeId );

if ( it == map.end() )
return QVariant( distance/(mDefaultValue*mToMetricFactor) );
return QVariant( distance / ( mDefaultValue*mToMetricFactor ) );

double val = distance/(it->toDouble()*mToMetricFactor);
double val = distance / ( it->toDouble() * mToMetricFactor );
if ( val <= 0.0 )
return QVariant( distance/(mDefaultValue/mToMetricFactor) );
return QVariant( distance / ( mDefaultValue / mToMetricFactor ) );

return QVariant( val );
}

Expand Down
4 changes: 2 additions & 2 deletions src/plugins/roadgraph/speedproperter.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ class RgSpeedProperter : public QgsArcProperter
{
public:
RgSpeedProperter( int attributeId, double defaultValue, double toMetricFactor );

QVariant property( double distance, const QgsFeature& f ) const;

QgsAttributeList requiredAttributes() const;
private:
int mAttributeId;
Expand Down