Skip to content

Commit b66dfb5

Browse files
committed
optimization hit
1 parent 4eccdea commit b66dfb5

File tree

2 files changed

+43
-16
lines changed

2 files changed

+43
-16
lines changed

src/analysis/network/qgslinevectorlayerdirector.cpp

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,22 @@ template <typename RandIter, typename Type, typename CompareOp > RandIter my_bin
8383
return not_found;
8484
}
8585

86+
struct TiePointInfo
87+
{
88+
QgsPoint mTiedPoint;
89+
double mLength;
90+
QgsPoint mFirstPoint;
91+
QgsPoint mLastPoint;
92+
};
93+
94+
bool TiePointInfoCompare( const TiePointInfo& a, const TiePointInfo& b )
95+
{
96+
if ( a.mFirstPoint == b.mFirstPoint )
97+
return a.mLastPoint.x() == b.mLastPoint.x() ? a.mLastPoint.y() < b.mLastPoint.y() : a.mLastPoint.x() < b.mLastPoint.x();
98+
99+
return a.mFirstPoint.x() == b.mFirstPoint.x() ? a.mFirstPoint.y() < b.mFirstPoint.y() : a.mFirstPoint.x() < b.mFirstPoint.x();
100+
}
101+
86102
QgsLineVectorLayerDirector::QgsLineVectorLayerDirector( QgsVectorLayer *myLayer,
87103
int directionFieldId,
88104
const QString& directDirectionValue,
@@ -208,19 +224,22 @@ void QgsLineVectorLayerDirector::makeGraph( QgsGraphBuilderInterface *builder, c
208224
points.push_back( tiedPoint [ i ] );
209225
}
210226
}
211-
227+
212228
QgsPointCompare pointCompare( builder->topologyTolerance() );
213229

214230
qSort( points.begin(), points.end(), pointCompare );
215231
QVector< QgsPoint >::iterator tmp = std::unique( points.begin(), points.end() );
216232
points.resize( tmp - points.begin() );
217-
233+
234+
218235
for (i=0;i<points.size();++i)
219236
builder->addVertex( i, points[ i ] );
220237

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

241+
qSort( pointLengthMap.begin(), pointLengthMap.end(), TiePointInfoCompare );
242+
224243
{ // fill attribute list 'la'
225244
QgsAttributeList tmpAttr;
226245
if ( mDirectionFieldId != -1 )
@@ -254,7 +273,7 @@ void QgsLineVectorLayerDirector::makeGraph( QgsGraphBuilderInterface *builder, c
254273
lastAttrId = *it2;
255274
}
256275
} // end fill attribute list 'la'
257-
276+
258277
// begin graph construction
259278
vl->select( la );
260279
while ( vl->nextFeature( feature ) )
@@ -307,13 +326,28 @@ void QgsLineVectorLayerDirector::makeGraph( QgsGraphBuilderInterface *builder, c
307326
std::map< double, QgsPoint > pointsOnArc;
308327
pointsOnArc[ 0.0 ] = pt1;
309328
pointsOnArc[ pt1.sqrDist( pt2 )] = pt2;
310-
311-
for ( pointLengthIt = pointLengthMap.begin(); pointLengthIt != pointLengthMap.end(); ++pointLengthIt )
329+
330+
TiePointInfo t;
331+
t.mFirstPoint = pt1;
332+
t.mLastPoint = pt2;
333+
pointLengthIt = my_binary_search( pointLengthMap.begin(), pointLengthMap.end(), t, TiePointInfoCompare );
334+
335+
if ( pointLengthIt != pointLengthMap.end() )
312336
{
313-
if ( pointLengthIt->mFirstPoint == pt1 && pointLengthIt->mLastPoint == pt2 )
337+
QVector< TiePointInfo >::iterator it;
338+
for ( it = pointLengthIt; it - pointLengthMap.begin() > 0; --it )
314339
{
315-
QgsPoint tiedPoint = pointLengthIt->mTiedPoint;
316-
pointsOnArc[ pt1.sqrDist( tiedPoint )] = tiedPoint;
340+
if ( it->mFirstPoint == pt1 && it->mLastPoint == pt2 )
341+
{
342+
pointsOnArc[ pt1.sqrDist( it->mTiedPoint ) ] = it->mTiedPoint;
343+
}
344+
}
345+
for ( it = pointLengthIt+1; it != pointLengthMap.end(); ++it )
346+
{
347+
if ( it->mFirstPoint == pt1 && it->mLastPoint == pt2 )
348+
{
349+
pointsOnArc[ pt2.sqrDist( it->mTiedPoint ) ] = it->mTiedPoint;
350+
}
317351
}
318352
}
319353

src/analysis/network/qgslinevectorlayerdirector.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,6 @@ class QgsVectorLayer;
3333
*/
3434
class QgsLineVectorLayerDirector : public QgsGraphDirector
3535
{
36-
private:
37-
struct TiePointInfo
38-
{
39-
QgsPoint mTiedPoint;
40-
double mLength;
41-
QgsPoint mFirstPoint;
42-
QgsPoint mLastPoint;
43-
};
4436
public:
4537
/**
4638
* @param vl source vector layer
@@ -86,4 +78,5 @@ class QgsLineVectorLayerDirector : public QgsGraphDirector
8678
//FIXME: need enum
8779
int mDefaultDirection;
8880
};
81+
8982
#endif //QGSLINEVECTORLAYERGRAPHDIRECTORH

0 commit comments

Comments
 (0)