From 9fdb6eb2c58750170c8e3bf540064ad2c1a2c6ce Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Thu, 1 Mar 2012 19:41:06 +0100 Subject: [PATCH] Refactoring edge based graph generation subrouting into a single function. Should make parallelization much easier. --- Contractor/EdgeBasedGraphFactory.cpp | 31 +++++++++++++++++----------- Contractor/EdgeBasedGraphFactory.h | 4 ++++ 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/Contractor/EdgeBasedGraphFactory.cpp b/Contractor/EdgeBasedGraphFactory.cpp index a3340959c..8c7ecf64a 100644 --- a/Contractor/EdgeBasedGraphFactory.cpp +++ b/Contractor/EdgeBasedGraphFactory.cpp @@ -150,6 +150,23 @@ bool EdgeBasedGraphFactory::CheckIfTurnIsRestricted(const NodeID u, const NodeID return false; } +void EdgeBasedGraphFactory::InsertEdgeBasedNode( + _NodeBasedDynamicGraph::EdgeIterator e1, + _NodeBasedDynamicGraph::NodeIterator u, + _NodeBasedDynamicGraph::NodeIterator v) { + EdgeBasedNode currentNode; + currentNode.nameID = _nodeBasedGraph->GetEdgeData(e1).nameID; + currentNode.lat1 = inputNodeInfoList[u].lat; + currentNode.lon1 = inputNodeInfoList[u].lon; + currentNode.lat2 = inputNodeInfoList[v].lat; + currentNode.lon2 = inputNodeInfoList[v].lon; + currentNode.id = _nodeBasedGraph->GetEdgeData(e1).edgeBasedNodeID; + currentNode.ignoreInGrid = _nodeBasedGraph->GetEdgeData(e1).ignoreInGrid; + currentNode.weight = _nodeBasedGraph->GetEdgeData(e1).distance; + //currentNode.weight += ComputeHeightPenalty(u, v); + edgeBasedNodes.push_back(currentNode); +} + void EdgeBasedGraphFactory::Run() { INFO("Generating edge based representation of input data"); edgeBasedNodes.reserve(_nodeBasedGraph->GetNumberOfEdges()); @@ -163,17 +180,7 @@ void EdgeBasedGraphFactory::Run() { _NodeBasedDynamicGraph::NodeIterator v = _nodeBasedGraph->GetTarget(e1); if(_nodeBasedGraph->GetEdgeData(e1).type != SHRT_MAX) { - EdgeBasedNode currentNode; - currentNode.nameID = _nodeBasedGraph->GetEdgeData(e1).nameID; - currentNode.lat1 = inputNodeInfoList[u].lat; - currentNode.lon1 = inputNodeInfoList[u].lon; - currentNode.lat2 = inputNodeInfoList[v].lat; - currentNode.lon2 = inputNodeInfoList[v].lon; - currentNode.id = _nodeBasedGraph->GetEdgeData(e1).edgeBasedNodeID; - currentNode.ignoreInGrid = _nodeBasedGraph->GetEdgeData(e1).ignoreInGrid; - currentNode.weight = _nodeBasedGraph->GetEdgeData(e1).distance; - //currentNode.weight += ComputeHeightPenalty(u, v); - edgeBasedNodes.push_back(currentNode); + InsertEdgeBasedNode(e1, u, v); } } } @@ -193,7 +200,7 @@ void EdgeBasedGraphFactory::Run() { continue; } bool isBollardNode = (_barrierNodes.find(v) != _barrierNodes.end()); - if( (!isBollardNode && (u != w || 1 == _nodeBasedGraph->GetOutDegree(v))) || (u == w && isBollardNode)) { //only add an edge if turn is not a U-turn except it is the end of dead-end street. + if( (!isBollardNode && (u != w || 1 == _nodeBasedGraph->GetOutDegree(v))) || ((u == w) && isBollardNode)) { //only add an edge if turn is not a U-turn except it is the end of dead-end street. if (!CheckIfTurnIsRestricted(u, v, w) || (onlyToNode != UINT_MAX && w == onlyToNode)) { //only add an edge if turn is not prohibited const _NodeBasedDynamicGraph::EdgeData edgeData1 = _nodeBasedGraph->GetEdgeData(e1); const _NodeBasedDynamicGraph::EdgeData edgeData2 = _nodeBasedGraph->GetEdgeData(e2); diff --git a/Contractor/EdgeBasedGraphFactory.h b/Contractor/EdgeBasedGraphFactory.h index 2a986afb0..19282fa22 100644 --- a/Contractor/EdgeBasedGraphFactory.h +++ b/Contractor/EdgeBasedGraphFactory.h @@ -108,6 +108,10 @@ private: NodeID CheckForEmanatingIsOnlyTurn(const NodeID u, const NodeID v) const; bool CheckIfTurnIsRestricted(const NodeID u, const NodeID v, const NodeID w) const; + void InsertEdgeBasedNode( + _NodeBasedDynamicGraph::EdgeIterator e1, + _NodeBasedDynamicGraph::NodeIterator u, + _NodeBasedDynamicGraph::NodeIterator v); template double GetAngleBetweenTwoEdges(const CoordinateT& A, const CoordinateT& C, const CoordinateT& B) const; // SRTMLookup srtmLookup;