Bugfixes, plus safe delete, less pointers and speed back on track
This commit is contained in:
@@ -118,7 +118,7 @@ public:
|
||||
BaseDescriptor() { }
|
||||
//Maybe someone can explain the pure virtual destructor thing to me (dennis)
|
||||
virtual ~BaseDescriptor() { }
|
||||
virtual void Run(http::Reply& reply, RawRouteData * route, PhantomNodes * phantomNodes, SearchEngineT * sEngine, unsigned distance) = 0;
|
||||
virtual void Run(http::Reply & reply, RawRouteData &rawRoute, PhantomNodes &phantomNodes, SearchEngineT &sEngine, unsigned distance) = 0;
|
||||
virtual void SetConfig(const _DescriptorConfig & config) = 0;
|
||||
};
|
||||
|
||||
|
||||
@@ -31,26 +31,26 @@ private:
|
||||
_Coordinate current;
|
||||
public:
|
||||
void SetConfig(const _DescriptorConfig& c) { config = c; }
|
||||
void Run(http::Reply& reply, RawRouteData * route, PhantomNodes * phantomNodes, SearchEngineT * sEngine, unsigned distance) {
|
||||
void Run(http::Reply & reply, RawRouteData &rawRoute, PhantomNodes &phantomNodes, SearchEngineT &sEngine, unsigned distance) {
|
||||
reply.content += ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
|
||||
reply.content += "<gpx xmlns=\"http://www.topografix.com/GPX/1/1\" "
|
||||
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
|
||||
"xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 gpx.xsd"
|
||||
"\">";
|
||||
reply.content += "<rte>";
|
||||
if(distance != UINT_MAX && route->routeSegments.size()) {
|
||||
if(distance != UINT_MAX && rawRoute.routeSegments.size()) {
|
||||
|
||||
convertInternalLatLonToString(phantomNodes->startPhantom.location.lat, tmp);
|
||||
convertInternalLatLonToString(phantomNodes.startPhantom.location.lat, tmp);
|
||||
reply.content += "<rtept lat=\"" + tmp + "\" ";
|
||||
convertInternalLatLonToString(phantomNodes->startPhantom.location.lon, tmp);
|
||||
convertInternalLatLonToString(phantomNodes.startPhantom.location.lon, tmp);
|
||||
reply.content += "lon=\"" + tmp + "\"></rtept>";
|
||||
|
||||
for(unsigned segmentIdx = 0; segmentIdx < route->routeSegments.size(); segmentIdx++) {
|
||||
const std::vector< _PathData > & path = route->routeSegments[segmentIdx];
|
||||
for(unsigned segmentIdx = 0; segmentIdx < rawRoute.routeSegments.size(); segmentIdx++) {
|
||||
const std::vector< _PathData > & path = rawRoute.routeSegments[segmentIdx];
|
||||
if( ! path.size() )
|
||||
continue;
|
||||
for(vector< _PathData >::const_iterator it = path.begin(); it != path.end(); it++) {
|
||||
sEngine->getCoordinatesForNodeID(it->node, current);
|
||||
sEngine.getCoordinatesForNodeID(it->node, current);
|
||||
|
||||
convertInternalLatLonToString(current.lat, tmp);
|
||||
reply.content += "<rtept lat=\"" + tmp + "\" ";
|
||||
@@ -60,9 +60,9 @@ public:
|
||||
reply.content +="</rtept>";
|
||||
}
|
||||
}
|
||||
convertInternalLatLonToString(phantomNodes->targetPhantom.location.lat, tmp);
|
||||
convertInternalLatLonToString(phantomNodes.targetPhantom.location.lat, tmp);
|
||||
reply.content += "<rtept lat=\"" + tmp + "\" ";
|
||||
convertInternalLatLonToString(phantomNodes->targetPhantom.location.lon, tmp);
|
||||
convertInternalLatLonToString(phantomNodes.targetPhantom.location.lon, tmp);
|
||||
reply.content += "lon=\"" + tmp + "\"></rtept>";
|
||||
}
|
||||
reply.content += "</rte></gpx>";
|
||||
|
||||
+41
-41
@@ -38,44 +38,46 @@ public:
|
||||
JSONDescriptor() {}
|
||||
void SetConfig(const _DescriptorConfig & c) { config = c; }
|
||||
|
||||
void Run(http::Reply & reply, RawRouteData *rawRoute, PhantomNodes *phantomNodes, SearchEngineT *sEngine, unsigned distance) {
|
||||
void Run(http::Reply & reply, RawRouteData &rawRoute, PhantomNodes &phantomNodes, SearchEngineT &sEngine, unsigned distance) {
|
||||
WriteHeaderToOutput(reply.content);
|
||||
|
||||
//We do not need to do much, if there is no route ;-)
|
||||
if(distance != UINT_MAX && rawRoute->routeSegments.size() > 0) {
|
||||
|
||||
if(distance != UINT_MAX && rawRoute.routeSegments.size() > 0) {
|
||||
reply.content += "0,"
|
||||
"\"status_message\": \"Found route between points\",";
|
||||
|
||||
//Put first segment of route into geometry
|
||||
polyline.push_back(phantomNodes->startPhantom.location);
|
||||
polyline.push_back(phantomNodes.startPhantom.location);
|
||||
descriptorState.geometryCounter++;
|
||||
descriptorState.startOfSegmentCoordinate = phantomNodes->startPhantom.location;
|
||||
descriptorState.startOfSegmentCoordinate = phantomNodes.startPhantom.location;
|
||||
//Generate initial instruction for start of route (order of NodeIDs does not matter, its the same name anyway)
|
||||
summary.startName = sEngine->GetEscapedNameForOriginDestinationNodeID(phantomNodes->startPhantom.startNode, phantomNodes->startPhantom.targetNode);
|
||||
descriptorState.lastNameID = sEngine->GetNameIDForOriginDestinationNodeID(phantomNodes->startPhantom.startNode, phantomNodes->startPhantom.targetNode);
|
||||
summary.startName = sEngine.GetEscapedNameForOriginDestinationNodeID(phantomNodes.startPhantom.startNode, phantomNodes.startPhantom.targetNode);
|
||||
descriptorState.lastNameID = sEngine.GetNameIDForOriginDestinationNodeID(phantomNodes.startPhantom.startNode, phantomNodes.startPhantom.targetNode);
|
||||
|
||||
//If we have a route, i.e. start and dest not on same edge, than get it
|
||||
if(rawRoute->routeSegments[0].size() > 0)
|
||||
sEngine->getCoordinatesForNodeID(rawRoute->routeSegments[0].begin()->node, descriptorState.tmpCoord);
|
||||
if(rawRoute.routeSegments[0].size() > 0)
|
||||
sEngine.getCoordinatesForNodeID(rawRoute.routeSegments[0].begin()->node, descriptorState.tmpCoord);
|
||||
else
|
||||
descriptorState.tmpCoord = phantomNodes->targetPhantom.location;
|
||||
descriptorState.tmpCoord = phantomNodes.targetPhantom.location;
|
||||
|
||||
descriptorState.previousCoordinate = phantomNodes->startPhantom.location;
|
||||
descriptorState.previousCoordinate = phantomNodes.startPhantom.location;
|
||||
descriptorState.currentCoordinate = descriptorState.tmpCoord;
|
||||
descriptorState.distanceOfInstruction += ApproximateDistance(descriptorState.previousCoordinate, descriptorState.currentCoordinate);
|
||||
|
||||
if(config.instructions) {
|
||||
//Get Heading
|
||||
double angle = GetAngleBetweenTwoEdges(_Coordinate(phantomNodes->startPhantom.location.lat, phantomNodes->startPhantom.location.lon), descriptorState.tmpCoord, _Coordinate(descriptorState.tmpCoord.lat, descriptorState.tmpCoord.lon-1000));
|
||||
double angle = GetAngleBetweenTwoEdges(_Coordinate(phantomNodes.startPhantom.location.lat, phantomNodes.startPhantom.location.lon), descriptorState.tmpCoord, _Coordinate(descriptorState.tmpCoord.lat, descriptorState.tmpCoord.lon-1000));
|
||||
getDirectionOfInstruction(angle, directionOfInstruction);
|
||||
appendInstructionNameToString(summary.startName, directionOfInstruction.direction, descriptorState.routeInstructionString, true);
|
||||
}
|
||||
NodeID lastNodeID = UINT_MAX;
|
||||
for(unsigned segmentIdx = 0; segmentIdx < rawRoute->routeSegments.size(); segmentIdx++) {
|
||||
const std::vector< _PathData > & path = rawRoute->routeSegments[segmentIdx];
|
||||
|
||||
for(unsigned segmentIdx = 0; segmentIdx < rawRoute.routeSegments.size(); segmentIdx++) {
|
||||
const std::vector< _PathData > & path = rawRoute.routeSegments[segmentIdx];
|
||||
if(path.empty())
|
||||
continue;
|
||||
if ( UINT_MAX == lastNodeID) {
|
||||
lastNodeID = (phantomNodes->startPhantom.startNode == (*path.begin()).node ? phantomNodes->startPhantom.targetNode : phantomNodes->startPhantom.startNode);
|
||||
lastNodeID = (phantomNodes.startPhantom.startNode == (*path.begin()).node ? phantomNodes.startPhantom.targetNode : phantomNodes.startPhantom.startNode);
|
||||
}
|
||||
//Check, if there is overlap between current and previous route segment
|
||||
//if not, than we are fine and can route over this edge without paying any special attention.
|
||||
@@ -83,34 +85,34 @@ public:
|
||||
// appendCoordinateToString(descriptorState.currentCoordinate, descriptorState.routeGeometryString);
|
||||
polyline.push_back(descriptorState.currentCoordinate);
|
||||
descriptorState.geometryCounter++;
|
||||
lastNodeID = (lastNodeID == rawRoute->segmentEndCoordinates[segmentIdx].startPhantom.startNode ? rawRoute->segmentEndCoordinates[segmentIdx].targetPhantom.startNode : rawRoute->segmentEndCoordinates[segmentIdx].startPhantom.startNode);
|
||||
lastNodeID = (lastNodeID == rawRoute.segmentEndCoordinates[segmentIdx].startPhantom.startNode ? rawRoute.segmentEndCoordinates[segmentIdx].targetPhantom.startNode : rawRoute.segmentEndCoordinates[segmentIdx].startPhantom.startNode);
|
||||
|
||||
//output of the via nodes coordinates
|
||||
polyline.push_back(rawRoute->segmentEndCoordinates[segmentIdx].startPhantom.location);
|
||||
polyline.push_back(rawRoute.segmentEndCoordinates[segmentIdx].startPhantom.location);
|
||||
descriptorState.geometryCounter++;
|
||||
descriptorState.currentNameID = sEngine->GetNameIDForOriginDestinationNodeID(rawRoute->segmentEndCoordinates[segmentIdx].startPhantom.startNode, rawRoute->segmentEndCoordinates[segmentIdx].startPhantom.targetNode);
|
||||
descriptorState.currentNameID = sEngine.GetNameIDForOriginDestinationNodeID(rawRoute.segmentEndCoordinates[segmentIdx].startPhantom.startNode, rawRoute.segmentEndCoordinates[segmentIdx].startPhantom.targetNode);
|
||||
//Make a special announement to do a U-Turn.
|
||||
appendInstructionLengthToString(descriptorState.distanceOfInstruction, descriptorState.routeInstructionString);
|
||||
descriptorState.routeInstructionString += ",";
|
||||
descriptorState.distanceOfInstruction = ApproximateDistance(descriptorState.currentCoordinate, rawRoute->segmentEndCoordinates[segmentIdx].startPhantom.location);
|
||||
descriptorState.distanceOfInstruction = ApproximateDistance(descriptorState.currentCoordinate, rawRoute.segmentEndCoordinates[segmentIdx].startPhantom.location);
|
||||
getTurnDirectionOfInstruction(descriptorState.GetAngleBetweenCoordinates(), tmp);
|
||||
appendInstructionNameToString(sEngine->GetEscapedNameForNameID(descriptorState.currentNameID), tmp, descriptorState.routeInstructionString);
|
||||
appendInstructionNameToString(sEngine.GetEscapedNameForNameID(descriptorState.currentNameID), tmp, descriptorState.routeInstructionString);
|
||||
appendInstructionLengthToString(descriptorState.distanceOfInstruction, descriptorState.routeInstructionString);
|
||||
descriptorState.routeInstructionString += ",";
|
||||
tmp = "U-turn at via point";
|
||||
appendInstructionNameToString(sEngine->GetEscapedNameForNameID(descriptorState.currentNameID), tmp, descriptorState.routeInstructionString);
|
||||
appendInstructionNameToString(sEngine.GetEscapedNameForNameID(descriptorState.currentNameID), tmp, descriptorState.routeInstructionString);
|
||||
double tmpDistance = descriptorState.distanceOfInstruction;
|
||||
descriptorState.SetStartOfSegment(); //Set start of segment but save distance information.
|
||||
descriptorState.distanceOfInstruction = tmpDistance;
|
||||
} else if(segmentIdx > 0) { //We are going straight through an edge which is carrying the via point.
|
||||
assert(segmentIdx != 0);
|
||||
//routeInstructionString += "reaching via node: ";
|
||||
descriptorState.nextCoordinate = rawRoute->segmentEndCoordinates[segmentIdx].startPhantom.location;
|
||||
descriptorState.currentNameID = sEngine->GetNameIDForOriginDestinationNodeID(rawRoute->segmentEndCoordinates[segmentIdx].startPhantom.startNode, rawRoute->segmentEndCoordinates[segmentIdx].startPhantom.targetNode);
|
||||
descriptorState.nextCoordinate = rawRoute.segmentEndCoordinates[segmentIdx].startPhantom.location;
|
||||
descriptorState.currentNameID = sEngine.GetNameIDForOriginDestinationNodeID(rawRoute.segmentEndCoordinates[segmentIdx].startPhantom.startNode, rawRoute.segmentEndCoordinates[segmentIdx].startPhantom.targetNode);
|
||||
|
||||
polyline.push_back(descriptorState.currentCoordinate);
|
||||
descriptorState.geometryCounter++;
|
||||
polyline.push_back(rawRoute->segmentEndCoordinates[segmentIdx].startPhantom.location);
|
||||
polyline.push_back(rawRoute.segmentEndCoordinates[segmentIdx].startPhantom.location);
|
||||
descriptorState.geometryCounter++;
|
||||
if(config.instructions) {
|
||||
double turnAngle = descriptorState.GetAngleBetweenCoordinates();
|
||||
@@ -119,12 +121,12 @@ public:
|
||||
descriptorState.routeInstructionString += ",";
|
||||
getTurnDirectionOfInstruction(turnAngle, tmp);
|
||||
tmp += " and reach via point";
|
||||
appendInstructionNameToString(sEngine->GetEscapedNameForNameID(descriptorState.currentNameID), tmp, descriptorState.routeInstructionString);
|
||||
appendInstructionNameToString(sEngine.GetEscapedNameForNameID(descriptorState.currentNameID), tmp, descriptorState.routeInstructionString);
|
||||
|
||||
//instruction to continue on the segment
|
||||
appendInstructionLengthToString(ApproximateDistance(descriptorState.currentCoordinate, descriptorState.nextCoordinate), descriptorState.routeInstructionString);
|
||||
descriptorState.routeInstructionString += ",";
|
||||
appendInstructionNameToString(sEngine->GetEscapedNameForNameID(descriptorState.currentNameID), "Continue on", descriptorState.routeInstructionString);
|
||||
appendInstructionNameToString(sEngine.GetEscapedNameForNameID(descriptorState.currentNameID), "Continue on", descriptorState.routeInstructionString);
|
||||
|
||||
//note the new segment starting coordinates
|
||||
descriptorState.SetStartOfSegment();
|
||||
@@ -133,8 +135,8 @@ public:
|
||||
}
|
||||
}
|
||||
for(vector< _PathData >::const_iterator it = path.begin(); it != path.end(); it++) {
|
||||
sEngine->getCoordinatesForNodeID(it->node, descriptorState.nextCoordinate);
|
||||
descriptorState.currentNameID = sEngine->GetNameIDForOriginDestinationNodeID(lastNodeID, it->node);
|
||||
sEngine.getCoordinatesForNodeID(it->node, descriptorState.nextCoordinate);
|
||||
descriptorState.currentNameID = sEngine.GetNameIDForOriginDestinationNodeID(lastNodeID, it->node);
|
||||
|
||||
double area = fabs(0.5*( descriptorState.startOfSegmentCoordinate.lon*(descriptorState.nextCoordinate.lat - descriptorState.currentCoordinate.lat) + descriptorState.nextCoordinate.lon*(descriptorState.currentCoordinate.lat - descriptorState.startOfSegmentCoordinate.lat) + descriptorState.currentCoordinate.lon*(descriptorState.startOfSegmentCoordinate.lat - descriptorState.nextCoordinate.lat) ) );
|
||||
//if route is generalization does not skip this point, add it to description
|
||||
@@ -147,7 +149,7 @@ public:
|
||||
appendInstructionLengthToString(descriptorState.distanceOfInstruction, descriptorState.routeInstructionString);
|
||||
descriptorState.routeInstructionString += ",";
|
||||
getTurnDirectionOfInstruction(descriptorState.GetAngleBetweenCoordinates(), tmp);
|
||||
appendInstructionNameToString(sEngine->GetEscapedNameForNameID(descriptorState.currentNameID), tmp, descriptorState.routeInstructionString);
|
||||
appendInstructionNameToString(sEngine.GetEscapedNameForNameID(descriptorState.currentNameID), tmp, descriptorState.routeInstructionString);
|
||||
|
||||
//note the new segment starting coordinates
|
||||
descriptorState.SetStartOfSegment();
|
||||
@@ -161,8 +163,9 @@ public:
|
||||
}
|
||||
}
|
||||
}
|
||||
descriptorState.currentNameID = sEngine->GetNameIDForOriginDestinationNodeID(phantomNodes->targetPhantom.startNode, phantomNodes->targetPhantom.targetNode);
|
||||
descriptorState.nextCoordinate = phantomNodes->targetPhantom.location;
|
||||
|
||||
descriptorState.currentNameID = sEngine.GetNameIDForOriginDestinationNodeID(phantomNodes.targetPhantom.startNode, phantomNodes.targetPhantom.targetNode);
|
||||
descriptorState.nextCoordinate = phantomNodes.targetPhantom.location;
|
||||
|
||||
polyline.push_back(descriptorState.currentCoordinate);
|
||||
descriptorState.geometryCounter++;
|
||||
@@ -171,13 +174,13 @@ public:
|
||||
appendInstructionLengthToString(descriptorState.distanceOfInstruction, descriptorState.routeInstructionString);
|
||||
descriptorState.routeInstructionString += ",";
|
||||
getTurnDirectionOfInstruction(descriptorState.GetAngleBetweenCoordinates(), tmp);
|
||||
appendInstructionNameToString(sEngine->GetEscapedNameForNameID(descriptorState.currentNameID), tmp, descriptorState.routeInstructionString);
|
||||
appendInstructionNameToString(sEngine.GetEscapedNameForNameID(descriptorState.currentNameID), tmp, descriptorState.routeInstructionString);
|
||||
descriptorState.distanceOfInstruction = 0;
|
||||
descriptorState.SetStartOfSegment();
|
||||
}
|
||||
summary.destName = sEngine->GetEscapedNameForNameID(descriptorState.currentNameID);
|
||||
summary.destName = sEngine.GetEscapedNameForNameID(descriptorState.currentNameID);
|
||||
descriptorState.distanceOfInstruction += ApproximateDistance(descriptorState.currentCoordinate, descriptorState.nextCoordinate);
|
||||
polyline.push_back(phantomNodes->targetPhantom.location);
|
||||
polyline.push_back(phantomNodes.targetPhantom.location);
|
||||
descriptorState.geometryCounter++;
|
||||
appendInstructionLengthToString(descriptorState.distanceOfInstruction, descriptorState.routeInstructionString);
|
||||
summary.BuildDurationAndLengthStrings(descriptorState.entireDistance, distance);
|
||||
@@ -221,23 +224,20 @@ public:
|
||||
reply.content += "],";
|
||||
//list all viapoints so that the client may display it
|
||||
reply.content += "\"via_points\":[";
|
||||
for(unsigned segmentIdx = 1; (true == config.geometry) && (segmentIdx < rawRoute->segmentEndCoordinates.size()); segmentIdx++) {
|
||||
for(unsigned segmentIdx = 1; (true == config.geometry) && (segmentIdx < rawRoute.segmentEndCoordinates.size()); segmentIdx++) {
|
||||
if(segmentIdx > 1)
|
||||
reply.content += ",";
|
||||
reply.content += "[";
|
||||
if(rawRoute->segmentEndCoordinates[segmentIdx].startPhantom.location.isSet())
|
||||
convertInternalReversedCoordinateToString(rawRoute->segmentEndCoordinates[segmentIdx].startPhantom.location, tmp);
|
||||
if(rawRoute.segmentEndCoordinates[segmentIdx].startPhantom.location.isSet())
|
||||
convertInternalReversedCoordinateToString(rawRoute.segmentEndCoordinates[segmentIdx].startPhantom.location, tmp);
|
||||
else
|
||||
convertInternalReversedCoordinateToString(rawRoute->rawViaNodeCoordinates[segmentIdx], tmp);
|
||||
// INFO(rawRoute->segmentEndCoordinates[segmentIdx].startPhantom.location);
|
||||
// INFO(rawRoute->rawViaNodeCoordinates[segmentIdx]);
|
||||
convertInternalReversedCoordinateToString(rawRoute.rawViaNodeCoordinates[segmentIdx], tmp);
|
||||
reply.content += tmp;
|
||||
reply.content += "]";
|
||||
}
|
||||
reply.content += "],"
|
||||
"\"transactionId\": \"OSRM Routing Engine JSON Descriptor (v0.2)\"";
|
||||
reply.content += "}";
|
||||
// std::cout << reply.content << std::endl;
|
||||
}
|
||||
private:
|
||||
void appendInstructionNameToString(const std::string & nameOfStreet, const std::string & instructionOrDirection, std::string &output, bool firstAdvice = false) {
|
||||
|
||||
+36
-36
@@ -36,83 +36,83 @@ public:
|
||||
KMLDescriptor() {}
|
||||
void SetConfig(const _DescriptorConfig & c) { config = c; }
|
||||
|
||||
void Run(http::Reply & reply, RawRouteData *rawRoute, PhantomNodes *phantomNodes, SearchEngineT *sEngine, unsigned distance) {
|
||||
void Run(http::Reply & reply, RawRouteData &rawRoute, PhantomNodes &phantomNodes, SearchEngineT &sEngine, unsigned distance) {
|
||||
WriteHeaderToOutput(reply.content);
|
||||
|
||||
//We do not need to do much, if there is no route ;-)
|
||||
if(distance != UINT_MAX && rawRoute->routeSegments.size() > 0) {
|
||||
if(distance != UINT_MAX && rawRoute.routeSegments.size() > 0) {
|
||||
|
||||
//Put first segment of route into geometry
|
||||
appendCoordinateToString(phantomNodes->startPhantom.location, descriptorState.routeGeometryString);
|
||||
descriptorState.startOfSegmentCoordinate = phantomNodes->startPhantom.location;
|
||||
appendCoordinateToString(phantomNodes.startPhantom.location, descriptorState.routeGeometryString);
|
||||
descriptorState.startOfSegmentCoordinate = phantomNodes.startPhantom.location;
|
||||
//Generate initial instruction for start of route (order of NodeIDs does not matter, its the same name anyway)
|
||||
summary.startName = sEngine->GetEscapedNameForOriginDestinationNodeID(phantomNodes->targetPhantom.startNode, phantomNodes->startPhantom.startNode);
|
||||
descriptorState.lastNameID = sEngine->GetNameIDForOriginDestinationNodeID(phantomNodes->targetPhantom.startNode, phantomNodes->startPhantom.startNode);
|
||||
summary.startName = sEngine.GetEscapedNameForOriginDestinationNodeID(phantomNodes.targetPhantom.startNode, phantomNodes.startPhantom.startNode);
|
||||
descriptorState.lastNameID = sEngine.GetNameIDForOriginDestinationNodeID(phantomNodes.targetPhantom.startNode, phantomNodes.startPhantom.startNode);
|
||||
|
||||
//If we have a route, i.e. start and dest not on same edge, than get it
|
||||
if(rawRoute->routeSegments[0].size() > 0)
|
||||
sEngine->getCoordinatesForNodeID(rawRoute->routeSegments[0].begin()->node, descriptorState.tmpCoord);
|
||||
if(rawRoute.routeSegments[0].size() > 0)
|
||||
sEngine.getCoordinatesForNodeID(rawRoute.routeSegments[0].begin()->node, descriptorState.tmpCoord);
|
||||
else
|
||||
descriptorState.tmpCoord = phantomNodes->targetPhantom.location;
|
||||
descriptorState.tmpCoord = phantomNodes.targetPhantom.location;
|
||||
|
||||
descriptorState.previousCoordinate = phantomNodes->startPhantom.location;
|
||||
descriptorState.previousCoordinate = phantomNodes.startPhantom.location;
|
||||
descriptorState.currentCoordinate = descriptorState.tmpCoord;
|
||||
descriptorState.distanceOfInstruction += ApproximateDistance(descriptorState.previousCoordinate, descriptorState.currentCoordinate);
|
||||
|
||||
if(config.instructions) {
|
||||
//Get Heading
|
||||
double angle = GetAngleBetweenTwoEdges(_Coordinate(phantomNodes->startPhantom.location.lat, phantomNodes->startPhantom.location.lon), descriptorState.tmpCoord, _Coordinate(descriptorState.tmpCoord.lat, descriptorState.tmpCoord.lon-1000));
|
||||
double angle = GetAngleBetweenTwoEdges(_Coordinate(phantomNodes.startPhantom.location.lat, phantomNodes.startPhantom.location.lon), descriptorState.tmpCoord, _Coordinate(descriptorState.tmpCoord.lat, descriptorState.tmpCoord.lon-1000));
|
||||
getDirectionOfInstruction(angle, directionOfInstruction);
|
||||
appendInstructionNameToString(summary.startName, directionOfInstruction.direction, descriptorState.routeInstructionString, true);
|
||||
}
|
||||
NodeID lastNodeID = UINT_MAX;
|
||||
for(unsigned segmentIdx = 0; segmentIdx < rawRoute->routeSegments.size(); segmentIdx++) {
|
||||
const std::vector< _PathData > & path = rawRoute->routeSegments[segmentIdx];
|
||||
for(unsigned segmentIdx = 0; segmentIdx < rawRoute.routeSegments.size(); segmentIdx++) {
|
||||
const std::vector< _PathData > & path = rawRoute.routeSegments[segmentIdx];
|
||||
if( ! path.size() )
|
||||
continue;
|
||||
|
||||
if ( UINT_MAX == lastNodeID) {
|
||||
lastNodeID = (phantomNodes->startPhantom.startNode == (*path.begin()).node ? phantomNodes->targetPhantom.startNode : phantomNodes->startPhantom.startNode);
|
||||
lastNodeID = (phantomNodes.startPhantom.startNode == (*path.begin()).node ? phantomNodes.targetPhantom.startNode : phantomNodes.startPhantom.startNode);
|
||||
}
|
||||
//Check, if there is overlap between current and previous route segment
|
||||
//if not, than we are fine and can route over this edge without paying any special attention.
|
||||
if(lastNodeID == (*path.begin()).node) {
|
||||
appendCoordinateToString(descriptorState.currentCoordinate, descriptorState.routeGeometryString);
|
||||
lastNodeID = (lastNodeID == rawRoute->segmentEndCoordinates[segmentIdx].startPhantom.startNode ? rawRoute->segmentEndCoordinates[segmentIdx].targetPhantom.startNode : rawRoute->segmentEndCoordinates[segmentIdx].startPhantom.startNode);
|
||||
lastNodeID = (lastNodeID == rawRoute.segmentEndCoordinates[segmentIdx].startPhantom.startNode ? rawRoute.segmentEndCoordinates[segmentIdx].targetPhantom.startNode : rawRoute.segmentEndCoordinates[segmentIdx].startPhantom.startNode);
|
||||
|
||||
//output of the via nodes coordinates
|
||||
appendCoordinateToString(rawRoute->segmentEndCoordinates[segmentIdx].startPhantom.location, descriptorState.routeGeometryString);
|
||||
descriptorState.currentNameID = sEngine->GetNameIDForOriginDestinationNodeID(rawRoute->segmentEndCoordinates[segmentIdx].startPhantom.startNode, rawRoute->segmentEndCoordinates[segmentIdx].targetPhantom.startNode);
|
||||
appendCoordinateToString(rawRoute.segmentEndCoordinates[segmentIdx].startPhantom.location, descriptorState.routeGeometryString);
|
||||
descriptorState.currentNameID = sEngine.GetNameIDForOriginDestinationNodeID(rawRoute.segmentEndCoordinates[segmentIdx].startPhantom.startNode, rawRoute.segmentEndCoordinates[segmentIdx].targetPhantom.startNode);
|
||||
//Make a special announement to do a U-Turn.
|
||||
appendInstructionLengthToString(descriptorState.distanceOfInstruction, descriptorState.routeInstructionString);
|
||||
|
||||
descriptorState.distanceOfInstruction = ApproximateDistance(descriptorState.currentCoordinate, rawRoute->segmentEndCoordinates[segmentIdx].startPhantom.location);
|
||||
descriptorState.distanceOfInstruction = ApproximateDistance(descriptorState.currentCoordinate, rawRoute.segmentEndCoordinates[segmentIdx].startPhantom.location);
|
||||
getTurnDirectionOfInstruction(descriptorState.GetAngleBetweenCoordinates(), tmp);
|
||||
appendInstructionNameToString(sEngine->GetEscapedNameForNameID(descriptorState.currentNameID), tmp, descriptorState.routeInstructionString);
|
||||
appendInstructionNameToString(sEngine.GetEscapedNameForNameID(descriptorState.currentNameID), tmp, descriptorState.routeInstructionString);
|
||||
appendInstructionLengthToString(descriptorState.distanceOfInstruction, descriptorState.routeInstructionString);
|
||||
tmp = "U-turn at via point";
|
||||
appendInstructionNameToString(sEngine->GetEscapedNameForNameID(descriptorState.currentNameID), tmp, descriptorState.routeInstructionString);
|
||||
appendInstructionNameToString(sEngine.GetEscapedNameForNameID(descriptorState.currentNameID), tmp, descriptorState.routeInstructionString);
|
||||
double tmpDistance = descriptorState.distanceOfInstruction;
|
||||
descriptorState.SetStartOfSegment(); //Set start of segment but save distance information.
|
||||
descriptorState.distanceOfInstruction = tmpDistance;
|
||||
} else if(segmentIdx > 0) { //We are going straight through an edge which is carrying the via point.
|
||||
assert(segmentIdx != 0);
|
||||
//routeInstructionString += "\nreaching via node: \n";
|
||||
descriptorState.nextCoordinate = rawRoute->segmentEndCoordinates[segmentIdx].startPhantom.location;
|
||||
descriptorState.currentNameID = sEngine->GetNameIDForOriginDestinationNodeID(rawRoute->segmentEndCoordinates[segmentIdx].startPhantom.startNode, rawRoute->segmentEndCoordinates[segmentIdx].targetPhantom.startNode);
|
||||
descriptorState.nextCoordinate = rawRoute.segmentEndCoordinates[segmentIdx].startPhantom.location;
|
||||
descriptorState.currentNameID = sEngine.GetNameIDForOriginDestinationNodeID(rawRoute.segmentEndCoordinates[segmentIdx].startPhantom.startNode, rawRoute.segmentEndCoordinates[segmentIdx].targetPhantom.startNode);
|
||||
appendCoordinateToString(descriptorState.currentCoordinate, descriptorState.routeGeometryString);
|
||||
appendCoordinateToString(rawRoute->segmentEndCoordinates[segmentIdx].startPhantom.location, descriptorState.routeGeometryString);
|
||||
appendCoordinateToString(rawRoute.segmentEndCoordinates[segmentIdx].startPhantom.location, descriptorState.routeGeometryString);
|
||||
if(config.instructions) {
|
||||
double turnAngle = descriptorState.GetAngleBetweenCoordinates();
|
||||
appendInstructionLengthToString(descriptorState.distanceOfInstruction, descriptorState.routeInstructionString);
|
||||
|
||||
getTurnDirectionOfInstruction(turnAngle, tmp);
|
||||
tmp += " and reach via point";
|
||||
appendInstructionNameToString(sEngine->GetEscapedNameForNameID(descriptorState.currentNameID), tmp, descriptorState.routeInstructionString);
|
||||
appendInstructionNameToString(sEngine.GetEscapedNameForNameID(descriptorState.currentNameID), tmp, descriptorState.routeInstructionString);
|
||||
|
||||
//instruction to continue on the segment
|
||||
appendInstructionLengthToString(ApproximateDistance(descriptorState.currentCoordinate, descriptorState.nextCoordinate), descriptorState.routeInstructionString);
|
||||
appendInstructionNameToString(sEngine->GetEscapedNameForNameID(descriptorState.currentNameID), "Continue on", descriptorState.routeInstructionString);
|
||||
appendInstructionNameToString(sEngine.GetEscapedNameForNameID(descriptorState.currentNameID), "Continue on", descriptorState.routeInstructionString);
|
||||
|
||||
//note the new segment starting coordinates
|
||||
descriptorState.SetStartOfSegment();
|
||||
@@ -124,8 +124,8 @@ public:
|
||||
}
|
||||
|
||||
for(vector< _PathData >::const_iterator it = path.begin(); it != path.end(); it++) {
|
||||
sEngine->getCoordinatesForNodeID(it->node, descriptorState.nextCoordinate);
|
||||
descriptorState.currentNameID = sEngine->GetNameIDForOriginDestinationNodeID(lastNodeID, it->node);
|
||||
sEngine.getCoordinatesForNodeID(it->node, descriptorState.nextCoordinate);
|
||||
descriptorState.currentNameID = sEngine.GetNameIDForOriginDestinationNodeID(lastNodeID, it->node);
|
||||
|
||||
double area = fabs(0.5*( descriptorState.startOfSegmentCoordinate.lon*(descriptorState.nextCoordinate.lat - descriptorState.currentCoordinate.lat) + descriptorState.nextCoordinate.lon*(descriptorState.currentCoordinate.lat - descriptorState.startOfSegmentCoordinate.lat) + descriptorState.currentCoordinate.lon*(descriptorState.startOfSegmentCoordinate.lat - descriptorState.nextCoordinate.lat) ) );
|
||||
//if route is generalization does not skip this point, add it to description
|
||||
@@ -135,7 +135,7 @@ public:
|
||||
if( ( false == descriptorState.CurrentAndPreviousNameIDsEqual() ) && config.instructions) {
|
||||
appendInstructionLengthToString(descriptorState.distanceOfInstruction, descriptorState.routeInstructionString);
|
||||
getTurnDirectionOfInstruction(descriptorState.GetAngleBetweenCoordinates(), tmp);
|
||||
appendInstructionNameToString(sEngine->GetEscapedNameForNameID(descriptorState.currentNameID), tmp, descriptorState.routeInstructionString);
|
||||
appendInstructionNameToString(sEngine.GetEscapedNameForNameID(descriptorState.currentNameID), tmp, descriptorState.routeInstructionString);
|
||||
|
||||
//note the new segment starting coordinates
|
||||
descriptorState.SetStartOfSegment();
|
||||
@@ -149,19 +149,19 @@ public:
|
||||
}
|
||||
}
|
||||
}
|
||||
descriptorState.currentNameID = sEngine->GetNameIDForOriginDestinationNodeID(phantomNodes->startPhantom.targetNode, phantomNodes->targetPhantom.targetNode);
|
||||
descriptorState.nextCoordinate = phantomNodes->targetPhantom.location;
|
||||
descriptorState.currentNameID = sEngine.GetNameIDForOriginDestinationNodeID(phantomNodes.startPhantom.targetNode, phantomNodes.targetPhantom.targetNode);
|
||||
descriptorState.nextCoordinate = phantomNodes.targetPhantom.location;
|
||||
appendCoordinateToString(descriptorState.currentCoordinate, descriptorState.routeGeometryString);
|
||||
|
||||
if((false == descriptorState.CurrentAndPreviousNameIDsEqual()) && config.instructions) {
|
||||
appendInstructionLengthToString(descriptorState.distanceOfInstruction, descriptorState.routeInstructionString);
|
||||
getTurnDirectionOfInstruction(descriptorState.GetAngleBetweenCoordinates(), tmp);
|
||||
appendInstructionNameToString(sEngine->GetEscapedNameForNameID(descriptorState.currentNameID), tmp, descriptorState.routeInstructionString);
|
||||
appendInstructionNameToString(sEngine.GetEscapedNameForNameID(descriptorState.currentNameID), tmp, descriptorState.routeInstructionString);
|
||||
descriptorState.distanceOfInstruction = 0;
|
||||
}
|
||||
summary.destName = sEngine->GetEscapedNameForNameID(descriptorState.currentNameID);
|
||||
summary.destName = sEngine.GetEscapedNameForNameID(descriptorState.currentNameID);
|
||||
descriptorState.distanceOfInstruction += ApproximateDistance(descriptorState.currentCoordinate, descriptorState.nextCoordinate);
|
||||
appendCoordinateToString(phantomNodes->targetPhantom.location, descriptorState.routeGeometryString);
|
||||
appendCoordinateToString(phantomNodes.targetPhantom.location, descriptorState.routeGeometryString);
|
||||
appendInstructionLengthToString(descriptorState.distanceOfInstruction, descriptorState.routeInstructionString);
|
||||
descriptorState.SetStartOfSegment();
|
||||
//compute distance/duration for route summary
|
||||
@@ -191,13 +191,13 @@ public:
|
||||
reply.content += "</Placemark>";
|
||||
|
||||
//list all viapoints so that the client may display it
|
||||
std::cout << "number of segment endpoints in route: " << rawRoute->segmentEndCoordinates.size() << std::endl;
|
||||
for(unsigned segmentIdx = 1; (true == config.geometry) && (segmentIdx < rawRoute->segmentEndCoordinates.size()); segmentIdx++) {
|
||||
std::cout << "number of segment endpoints in route: " << rawRoute.segmentEndCoordinates.size() << std::endl;
|
||||
for(unsigned segmentIdx = 1; (true == config.geometry) && (segmentIdx < rawRoute.segmentEndCoordinates.size()); segmentIdx++) {
|
||||
reply.content += "<Placemark>";
|
||||
reply.content += "<name>Via Point 1</name>";
|
||||
reply.content += "<Point>";
|
||||
reply.content += "<coordinates>";
|
||||
appendCoordinateToString(rawRoute->segmentEndCoordinates[segmentIdx].startPhantom.location, reply.content);
|
||||
appendCoordinateToString(rawRoute.segmentEndCoordinates[segmentIdx].startPhantom.location, reply.content);
|
||||
reply.content += "</coordinates>";
|
||||
reply.content += "</Point>";
|
||||
reply.content += "</Placemark>";
|
||||
|
||||
+7
-10
@@ -94,12 +94,12 @@ public:
|
||||
_Coordinate startCoord(lat1, lon1);
|
||||
_Coordinate targetCoord(lat2, lon2);
|
||||
|
||||
vector< _PathData > * path = new vector< _PathData >();
|
||||
RawRouteData * rawRoute = new RawRouteData();
|
||||
PhantomNodes * phantomNodes = new PhantomNodes();
|
||||
vector< _PathData > path;
|
||||
RawRouteData rawRoute;
|
||||
PhantomNodes phantomNodes;
|
||||
sEngine->FindRoutingStarts(startCoord, targetCoord, phantomNodes);
|
||||
unsigned int distance = sEngine->ComputeRoute(phantomNodes, path);
|
||||
rawRoute->routeSegments.push_back(*path);
|
||||
rawRoute.routeSegments.push_back(path);
|
||||
reply.status = http::Reply::ok;
|
||||
BaseDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> > > * desc;
|
||||
std::string JSONParameter = routeParameters.options.Find("jsonp");
|
||||
@@ -145,7 +145,7 @@ public:
|
||||
break;
|
||||
}
|
||||
desc->SetConfig(descriptorConfig);
|
||||
desc->Run(reply, rawRoute, phantomNodes, sEngine, distance);
|
||||
desc->Run(reply, rawRoute, phantomNodes, *sEngine, distance);
|
||||
if("" != JSONParameter) {
|
||||
reply.content += ")\n";
|
||||
}
|
||||
@@ -193,15 +193,12 @@ public:
|
||||
break;
|
||||
}
|
||||
|
||||
delete desc;
|
||||
delete path;
|
||||
delete rawRoute;
|
||||
delete phantomNodes;
|
||||
DELETE( desc );
|
||||
return;
|
||||
}
|
||||
private:
|
||||
NodeInformationHelpDesk * nodeHelpDesk;
|
||||
SearchEngine<EdgeData, StaticGraph<EdgeData> > * sEngine;
|
||||
SearchEngine<EdgeData, StaticGraph<EdgeData> > *sEngine;
|
||||
std::vector<std::string> * names;
|
||||
StaticGraph<EdgeData> * graph;
|
||||
HashTable<std::string, unsigned> descriptorTable;
|
||||
|
||||
@@ -151,8 +151,6 @@ public:
|
||||
|
||||
unsigned distance = 0;
|
||||
bool errorOccurredFlag = false;
|
||||
double time = get_timestamp();
|
||||
|
||||
|
||||
//#pragma omp parallel for reduction(+:distance)
|
||||
for(unsigned i = 0; i < phantomNodeVector.size()-1 && !errorOccurredFlag; i++) {
|
||||
@@ -160,15 +158,15 @@ public:
|
||||
segmentPhantomNodes.startPhantom = phantomNodeVector[i];
|
||||
segmentPhantomNodes.targetPhantom = phantomNodeVector[i+1];
|
||||
std::vector< _PathData > path;
|
||||
threadData[omp_get_thread_num()]->distanceOfSegment = threadData[omp_get_thread_num()]->sEngine->ComputeRoute(&segmentPhantomNodes, &path);
|
||||
int distanceOfSegment = threadData[omp_get_thread_num()]->sEngine->ComputeRoute(segmentPhantomNodes, path);
|
||||
|
||||
if(UINT_MAX == threadData[omp_get_thread_num()]->distanceOfSegment) {
|
||||
if(UINT_MAX == threadData[omp_get_thread_num()]->distanceOfSegment || path.empty()) {
|
||||
errorOccurredFlag = true;
|
||||
cout << "Error occurred, path not found" << endl;
|
||||
distance = UINT_MAX;
|
||||
break;
|
||||
} else {
|
||||
distance += threadData[omp_get_thread_num()]->distanceOfSegment;
|
||||
distance += distanceOfSegment;
|
||||
}
|
||||
|
||||
//put segments at correct position of routes raw data
|
||||
@@ -176,9 +174,6 @@ public:
|
||||
rawRoute.routeSegments[i] = path;
|
||||
}
|
||||
|
||||
double time2 = get_timestamp();
|
||||
// std::cout << "Finished routing after " << (time2-time) << "s" << std::endl;
|
||||
time = get_timestamp();
|
||||
reply.status = http::Reply::ok;
|
||||
|
||||
BaseDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> > > * desc;
|
||||
@@ -225,14 +220,15 @@ public:
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
PhantomNodes phantomNodes;
|
||||
threadData[0]->sEngine->FindRoutingStarts(startCoord, targetCoord, &phantomNodes);
|
||||
phantomNodes.startPhantom = rawRoute.segmentEndCoordinates[0].startPhantom;
|
||||
phantomNodes.targetPhantom = rawRoute.segmentEndCoordinates[rawRoute.segmentEndCoordinates.size()-1].targetPhantom;
|
||||
desc->SetConfig(descriptorConfig);
|
||||
desc->Run(reply, &rawRoute, &phantomNodes, threadData[0]->sEngine, distance);
|
||||
desc->Run(reply, rawRoute, phantomNodes, *threadData[0]->sEngine, distance);
|
||||
if("" != JSONParameter) {
|
||||
reply.content += ")\n";
|
||||
}
|
||||
|
||||
reply.headers.resize(3);
|
||||
reply.headers[0].name = "Content-Length";
|
||||
std::string tmp;
|
||||
@@ -276,9 +272,6 @@ public:
|
||||
break;
|
||||
}
|
||||
|
||||
time2 = get_timestamp();
|
||||
// std::cout << "Finished everything after " << (time2-time) << "s" << std::endl;
|
||||
|
||||
delete desc;
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user