diff --git a/Contractor/SearchEngine.h b/Contractor/SearchEngine.h index 4762c4288..56fe5401e 100644 --- a/Contractor/SearchEngine.h +++ b/Contractor/SearchEngine.h @@ -34,6 +34,12 @@ struct _HeapData { _HeapData( NodeID p ) : parent(p), stalled(false) { } }; +struct _PathData { + _PathData(NodeID n, bool t) : node(n), turn(t) { } + NodeID node:31; + bool turn:1; +}; + typedef BinaryHeap< NodeID, int, int, _HeapData, DenseStorage< NodeID, unsigned > > _Heap; template @@ -57,7 +63,7 @@ public: return nodeHelpDesk->getNumberOfNodes(); } - unsigned int ComputeRoute(PhantomNodes * phantomNodes, vector * path, _Coordinate& startCoord, _Coordinate& targetCoord) + unsigned int ComputeRoute(PhantomNodes * phantomNodes, vector<_PathData > * path, _Coordinate& startCoord, _Coordinate& targetCoord) { bool onSameEdge = false; bool onSameEdgeReversed = false; @@ -192,7 +198,8 @@ public: packedPath.push_back( pathNode ); } - path->push_back(packedPath[0] ); + + path->push_back( _PathData(packedPath[0], false) ); { for(deque::size_type i = 0; i < packedPath.size()-1; i++) { @@ -307,9 +314,10 @@ private: } } - bool _UnpackEdge( const NodeID source, const NodeID target, std::vector< NodeID >* path ) { + bool _UnpackEdge( const NodeID source, const NodeID target, std::vector< _PathData >* path ) { assert(source != target); //find edge first. + bool forward = true; typename GraphT::EdgeIterator smallestEdge = SPECIAL_EDGEID; EdgeWeight smallestWeight = UINT_MAX; for(typename GraphT::EdgeIterator eit = _graph->BeginEdges(source); eit < _graph->EndEdges(source); eit++) @@ -331,6 +339,7 @@ private: if(_graph->GetTarget(eit) == source && weight < smallestWeight && _graph->GetEdgeData(eit).backward) { smallestEdge = eit; smallestWeight = weight; + forward = false; } } } @@ -347,7 +356,7 @@ private: return false; } else { assert(!ed.shortcut); - path->push_back(target); + path->push_back(_PathData(target, (forward ? ed.forwardTurn : ed.backwardTurn) ) ); return true; } } diff --git a/HttpServer/request_handler.h b/HttpServer/request_handler.h index bb0c1416d..e4cdf29e7 100644 --- a/HttpServer/request_handler.h +++ b/HttpServer/request_handler.h @@ -104,7 +104,7 @@ public: _Coordinate startCoord(lat1, lon1); _Coordinate targetCoord(lat2, lon2); - vector * path = new vector(); + vector< _PathData > * path = new vector< _PathData >(); PhantomNodes * phantomNodes = new PhantomNodes(); sEngine->FindRoutingStarts(startCoord, targetCoord, phantomNodes); unsigned int distance = sEngine->ComputeRoute(phantomNodes, path, startCoord, targetCoord); @@ -118,7 +118,7 @@ public: if(distance != std::numeric_limits::max()) computeDescription(tmp, path, phantomNodes); - +// cout << tmp << endl; // rep.content += tmp; rep.content += (""); rep.content += ("OSM Routing Engine (c) Dennis Luxen and others "); @@ -152,9 +152,9 @@ public: rep.content += tmp; rep.content += (" "); _Coordinate result; - for(vector::iterator it = path->begin(); it != path->end(); it++) + for(vector< _PathData >::iterator it = path->begin(); it != path->end(); it++) { - sEngine->getNodeInfo(*it, result); + sEngine->getNodeInfo(it->node, result); convertLatLon(result.lon, tmp); rep.content += tmp; rep.content += (","); @@ -263,7 +263,7 @@ private: return buffer; } - void computeDescription(string &tmp, vector * path, PhantomNodes * phantomNodes) + void computeDescription(string &tmp, vector< _PathData > * path, PhantomNodes * phantomNodes) { _Coordinate previous(phantomNodes->startCoord.lat, phantomNodes->startCoord.lon); _Coordinate next, current, lastPlace; @@ -277,18 +277,18 @@ private: lastPlace.lon = phantomNodes->startCoord.lon; short nextType = SHRT_MAX; short prevType = SHRT_MAX; - tmp += ""; - for(vector::iterator it = path->begin(); it != path->end(); it++) + tmp += "\n "; + for(vector< _PathData >::iterator it = path->begin(); it != path->end(); it++) { - sEngine->getNodeInfo(*it, current); + sEngine->getNodeInfo(it->node, current); if(it==path->end()-1){ next = _Coordinate(phantomNodes->targetCoord.lat, phantomNodes->targetCoord.lon); nextID = sEngine->GetNameIDForOriginDestinationNodeID(phantomNodes->targetNode1, phantomNodes->targetNode2); nextType = sEngine->GetTypeOfEdgeForOriginDestinationNodeID(phantomNodes->targetNode1, phantomNodes->targetNode2); } else { - sEngine->getNodeInfo(*(it+1), next); - nextID = sEngine->GetNameIDForOriginDestinationNodeID(*it, *(it+1)); - nextType = sEngine->GetTypeOfEdgeForOriginDestinationNodeID(*it, *(it+1)); + sEngine->getNodeInfo((it+1)->node, next); + nextID = sEngine->GetNameIDForOriginDestinationNodeID(it->node, (it+1)->node); + nextType = sEngine->GetTypeOfEdgeForOriginDestinationNodeID(it->node, (it+1)->node); } if(nextID == nameID) { tempDist += ApproximateDistance(previous.lat, previous.lon, current.lat, current.lon); @@ -299,13 +299,20 @@ private: tmp += "leave motorway and "; double angle = GetAngleBetweenTwoEdges(previous, current, next); + if(it->turn) + tmp += " turn! "; tmp += "follow road "; - tmp += sEngine->GetNameForNameID(nameID); + if(nameID != 0) + tmp += sEngine->GetNameForNameID(nameID); tmp += " (type: "; numberString << type; tmp += numberString.str(); numberString.str(""); - tmp += ")drive for "; + tmp += ", id: "; + numberString << nameID; + tmp += numberString.str(); + numberString.str(""); + tmp += ")\n drive for "; numberString << ApproximateDistance(previous.lat, previous.lon, current.lat, current.lon)+tempDist; tmp += numberString.str(); numberString.str(""); @@ -314,13 +321,17 @@ private: convertLatLon(lastPlace.lon, lon); convertLatLon(lastPlace.lat, lat); lastPlace = current; - tmp += ""; + tmp += "\n "; tmp += lon; tmp += ","; tmp += lat; tmp += ""; - tmp += ""; - tmp += ""; + tmp += "\n\n"; + tmp += "\n ("; + numberString << angle; + tmp += numberString.str(); + numberString.str(""); + tmp +=") "; if(angle > 160 && angle < 200) { tmp += /* " (" << angle << ")*/"drive ahead, "; } else if (angle > 290 && angle <= 360) { @@ -351,11 +362,11 @@ private: numberString << type; tmp += numberString.str(); numberString.str(""); - tmp += ") drive for "; + tmp += ")\n drive for "; numberString << (previous.lat, previous.lon, phantomNodes->targetCoord.lat, phantomNodes->targetCoord.lon) + tempDist; tmp += numberString.str(); numberString.str(""); - tmp += "m"; + tmp += "m\n "; string lat; string lon; convertLatLon(lastPlace.lon, lon); convertLatLon(lastPlace.lat, lat); @@ -364,16 +375,16 @@ private: tmp += ","; tmp += lat; tmp += ""; - tmp += ""; - tmp += "you have reached your destination"; + tmp += "\n"; + tmp += "\n you have reached your destination\n "; tmp += "End of Route"; convertLatLon(phantomNodes->targetCoord.lon, lon); convertLatLon(phantomNodes->targetCoord.lat, lat); - tmp += ""; + tmp += "\n "; tmp += lon; tmp += ","; tmp += lat; - tmp +=""; + tmp +="\n"; tmp += ""; }