Refactored various parts for integration of multi-segment paths
This commit is contained in:
@@ -33,13 +33,16 @@ public:
|
||||
void SetConfig(const _DescriptorConfig& c) { config = c; }
|
||||
void Run(http::Reply& reply, RawRouteData * route, 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 += "<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()) {
|
||||
|
||||
convertInternalLatLonToString(phantomNodes->startCoord.lat, tmp);
|
||||
convertInternalLatLonToString(phantomNodes->startPhantom.location.lat, tmp);
|
||||
reply.content += "<rtept lat=\"" + tmp + "\" ";
|
||||
convertInternalLatLonToString(phantomNodes->startCoord.lon, tmp);
|
||||
convertInternalLatLonToString(phantomNodes->startPhantom.location.lon, tmp);
|
||||
reply.content += "lon=\"" + tmp + "\"></rtept>";
|
||||
|
||||
for(unsigned segmentIdx = 0; segmentIdx < route->routeSegments.size(); segmentIdx++) {
|
||||
@@ -57,9 +60,9 @@ public:
|
||||
reply.content +="</rtept>";
|
||||
}
|
||||
}
|
||||
convertInternalLatLonToString(phantomNodes->targetCoord.lat, tmp);
|
||||
convertInternalLatLonToString(phantomNodes->targetPhantom.location.lat, tmp);
|
||||
reply.content += "<rtept lat=\"" + tmp + "\" ";
|
||||
convertInternalLatLonToString(phantomNodes->targetCoord.lon, tmp);
|
||||
convertInternalLatLonToString(phantomNodes->targetPhantom.location.lon, tmp);
|
||||
reply.content += "lon=\"" + tmp + "\"></rtept>";
|
||||
}
|
||||
reply.content += "</rte></gpx>";
|
||||
|
||||
+28
-22
@@ -47,26 +47,26 @@ public:
|
||||
"\"status_message\": \"Found route between points\",";
|
||||
|
||||
//Put first segment of route into geometry
|
||||
polyline.push_back(phantomNodes->startCoord);
|
||||
polyline.push_back(phantomNodes->startPhantom.location);
|
||||
descriptorState.geometryCounter++;
|
||||
descriptorState.startOfSegmentCoordinate = phantomNodes->startCoord;
|
||||
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->startNode1, phantomNodes->startNode2);
|
||||
descriptorState.lastNameID = sEngine->GetNameIDForOriginDestinationNodeID(phantomNodes->startNode2, phantomNodes->startNode1);
|
||||
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);
|
||||
else
|
||||
descriptorState.tmpCoord = phantomNodes->targetCoord;
|
||||
descriptorState.tmpCoord = phantomNodes->targetPhantom.location;
|
||||
|
||||
descriptorState.previousCoordinate = phantomNodes->startCoord;
|
||||
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->startCoord.lat, phantomNodes->startCoord.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);
|
||||
}
|
||||
@@ -75,7 +75,7 @@ public:
|
||||
const std::vector< _PathData > & path = rawRoute->routeSegments[segmentIdx];
|
||||
|
||||
if ( UINT_MAX == lastNodeID) {
|
||||
lastNodeID = (phantomNodes->startNode1 == (*path.begin()).node ? phantomNodes->startNode2 : phantomNodes->startNode1);
|
||||
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,16 +83,16 @@ public:
|
||||
// appendCoordinateToString(descriptorState.currentCoordinate, descriptorState.routeGeometryString);
|
||||
polyline.push_back(descriptorState.currentCoordinate);
|
||||
descriptorState.geometryCounter++;
|
||||
lastNodeID = (lastNodeID == rawRoute->segmentEndCoordinates[segmentIdx].startNode1 ? rawRoute->segmentEndCoordinates[segmentIdx].startNode2 : rawRoute->segmentEndCoordinates[segmentIdx].startNode1);
|
||||
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].startCoord);
|
||||
polyline.push_back(rawRoute->segmentEndCoordinates[segmentIdx].startPhantom.location);
|
||||
descriptorState.geometryCounter++;
|
||||
descriptorState.currentNameID = sEngine->GetNameIDForOriginDestinationNodeID(rawRoute->segmentEndCoordinates[segmentIdx].startNode1, rawRoute->segmentEndCoordinates[segmentIdx].startNode2);
|
||||
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].startCoord);
|
||||
descriptorState.distanceOfInstruction = ApproximateDistance(descriptorState.currentCoordinate, rawRoute->segmentEndCoordinates[segmentIdx].startPhantom.location);
|
||||
getTurnDirectionOfInstruction(descriptorState.GetAngleBetweenCoordinates(), tmp);
|
||||
appendInstructionNameToString(sEngine->GetEscapedNameForNameID(descriptorState.currentNameID), tmp, descriptorState.routeInstructionString);
|
||||
appendInstructionLengthToString(descriptorState.distanceOfInstruction, descriptorState.routeInstructionString);
|
||||
@@ -105,12 +105,12 @@ public:
|
||||
} 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].startCoord;
|
||||
descriptorState.currentNameID = sEngine->GetNameIDForOriginDestinationNodeID(rawRoute->segmentEndCoordinates[segmentIdx].startNode1, rawRoute->segmentEndCoordinates[segmentIdx].startNode2);
|
||||
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].startCoord);
|
||||
polyline.push_back(rawRoute->segmentEndCoordinates[segmentIdx].startPhantom.location);
|
||||
descriptorState.geometryCounter++;
|
||||
if(config.instructions) {
|
||||
double turnAngle = descriptorState.GetAngleBetweenCoordinates();
|
||||
@@ -155,18 +155,19 @@ public:
|
||||
}
|
||||
descriptorState.distanceOfInstruction += ApproximateDistance(descriptorState.currentCoordinate, descriptorState.nextCoordinate);
|
||||
lastNodeID = it->node;
|
||||
if(it != path.begin()) {
|
||||
if(it != path.begin()-1) {
|
||||
descriptorState.previousCoordinate = descriptorState.currentCoordinate;
|
||||
descriptorState.currentCoordinate = descriptorState.nextCoordinate;
|
||||
}
|
||||
}
|
||||
}
|
||||
descriptorState.currentNameID = sEngine->GetNameIDForOriginDestinationNodeID(phantomNodes->targetNode1, phantomNodes->targetNode2);
|
||||
descriptorState.nextCoordinate = phantomNodes->targetCoord;
|
||||
descriptorState.currentNameID = sEngine->GetNameIDForOriginDestinationNodeID(phantomNodes->targetPhantom.startNode, phantomNodes->targetPhantom.targetNode);
|
||||
descriptorState.nextCoordinate = phantomNodes->targetPhantom.location;
|
||||
|
||||
polyline.push_back(descriptorState.currentCoordinate);
|
||||
descriptorState.geometryCounter++;
|
||||
|
||||
if((false == descriptorState.CurrentAndPreviousNameIDsEqual()) && config.instructions) {
|
||||
polyline.push_back(descriptorState.currentCoordinate);
|
||||
descriptorState.geometryCounter++;
|
||||
appendInstructionLengthToString(descriptorState.distanceOfInstruction, descriptorState.routeInstructionString);
|
||||
descriptorState.routeInstructionString += ",";
|
||||
getTurnDirectionOfInstruction(descriptorState.GetAngleBetweenCoordinates(), tmp);
|
||||
@@ -176,7 +177,7 @@ public:
|
||||
}
|
||||
summary.destName = sEngine->GetEscapedNameForNameID(descriptorState.currentNameID);
|
||||
descriptorState.distanceOfInstruction += ApproximateDistance(descriptorState.currentCoordinate, descriptorState.nextCoordinate);
|
||||
polyline.push_back(phantomNodes->targetCoord);
|
||||
polyline.push_back(phantomNodes->targetPhantom.location);
|
||||
descriptorState.geometryCounter++;
|
||||
appendInstructionLengthToString(descriptorState.distanceOfInstruction, descriptorState.routeInstructionString);
|
||||
summary.BuildDurationAndLengthStrings(descriptorState.entireDistance, distance);
|
||||
@@ -224,7 +225,12 @@ public:
|
||||
if(segmentIdx > 1)
|
||||
reply.content += ",";
|
||||
reply.content += "[";
|
||||
convertInternalReversedCoordinateToString(rawRoute->segmentEndCoordinates[segmentIdx].startCoord, 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]);
|
||||
reply.content += tmp;
|
||||
reply.content += "]";
|
||||
}
|
||||
|
||||
+19
-19
@@ -43,25 +43,25 @@ public:
|
||||
if(distance != UINT_MAX && rawRoute->routeSegments.size() > 0) {
|
||||
|
||||
//Put first segment of route into geometry
|
||||
appendCoordinateToString(phantomNodes->startCoord, descriptorState.routeGeometryString);
|
||||
descriptorState.startOfSegmentCoordinate = phantomNodes->startCoord;
|
||||
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->startNode2, phantomNodes->startNode1);
|
||||
descriptorState.lastNameID = sEngine->GetNameIDForOriginDestinationNodeID(phantomNodes->startNode2, phantomNodes->startNode1);
|
||||
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);
|
||||
else
|
||||
descriptorState.tmpCoord = phantomNodes->targetCoord;
|
||||
descriptorState.tmpCoord = phantomNodes->targetPhantom.location;
|
||||
|
||||
descriptorState.previousCoordinate = phantomNodes->startCoord;
|
||||
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->startCoord.lat, phantomNodes->startCoord.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);
|
||||
}
|
||||
@@ -72,21 +72,21 @@ public:
|
||||
continue;
|
||||
|
||||
if ( UINT_MAX == lastNodeID) {
|
||||
lastNodeID = (phantomNodes->startNode1 == (*path.begin()).node ? phantomNodes->startNode2 : phantomNodes->startNode1);
|
||||
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].startNode1 ? rawRoute->segmentEndCoordinates[segmentIdx].startNode2 : rawRoute->segmentEndCoordinates[segmentIdx].startNode1);
|
||||
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].startCoord, descriptorState.routeGeometryString);
|
||||
descriptorState.currentNameID = sEngine->GetNameIDForOriginDestinationNodeID(rawRoute->segmentEndCoordinates[segmentIdx].startNode1, rawRoute->segmentEndCoordinates[segmentIdx].startNode2);
|
||||
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].startCoord);
|
||||
descriptorState.distanceOfInstruction = ApproximateDistance(descriptorState.currentCoordinate, rawRoute->segmentEndCoordinates[segmentIdx].startPhantom.location);
|
||||
getTurnDirectionOfInstruction(descriptorState.GetAngleBetweenCoordinates(), tmp);
|
||||
appendInstructionNameToString(sEngine->GetEscapedNameForNameID(descriptorState.currentNameID), tmp, descriptorState.routeInstructionString);
|
||||
appendInstructionLengthToString(descriptorState.distanceOfInstruction, descriptorState.routeInstructionString);
|
||||
@@ -98,10 +98,10 @@ public:
|
||||
} 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].startCoord;
|
||||
descriptorState.currentNameID = sEngine->GetNameIDForOriginDestinationNodeID(rawRoute->segmentEndCoordinates[segmentIdx].startNode1, rawRoute->segmentEndCoordinates[segmentIdx].startNode2);
|
||||
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].startCoord, descriptorState.routeGeometryString);
|
||||
appendCoordinateToString(rawRoute->segmentEndCoordinates[segmentIdx].startPhantom.location, descriptorState.routeGeometryString);
|
||||
if(config.instructions) {
|
||||
double turnAngle = descriptorState.GetAngleBetweenCoordinates();
|
||||
appendInstructionLengthToString(descriptorState.distanceOfInstruction, descriptorState.routeInstructionString);
|
||||
@@ -149,8 +149,8 @@ public:
|
||||
}
|
||||
}
|
||||
}
|
||||
descriptorState.currentNameID = sEngine->GetNameIDForOriginDestinationNodeID(phantomNodes->targetNode1, phantomNodes->targetNode2);
|
||||
descriptorState.nextCoordinate = phantomNodes->targetCoord;
|
||||
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) {
|
||||
@@ -161,7 +161,7 @@ public:
|
||||
}
|
||||
summary.destName = sEngine->GetEscapedNameForNameID(descriptorState.currentNameID);
|
||||
descriptorState.distanceOfInstruction += ApproximateDistance(descriptorState.currentCoordinate, descriptorState.nextCoordinate);
|
||||
appendCoordinateToString(phantomNodes->targetCoord, descriptorState.routeGeometryString);
|
||||
appendCoordinateToString(phantomNodes->targetPhantom.location, descriptorState.routeGeometryString);
|
||||
appendInstructionLengthToString(descriptorState.distanceOfInstruction, descriptorState.routeInstructionString);
|
||||
descriptorState.SetStartOfSegment();
|
||||
//compute distance/duration for route summary
|
||||
@@ -197,7 +197,7 @@ public:
|
||||
reply.content += "<name>Via Point 1</name>";
|
||||
reply.content += "<Point>";
|
||||
reply.content += "<coordinates>";
|
||||
appendCoordinateToString(rawRoute->segmentEndCoordinates[segmentIdx].startCoord, reply.content);
|
||||
appendCoordinateToString(rawRoute->segmentEndCoordinates[segmentIdx].startPhantom.location, reply.content);
|
||||
reply.content += "</coordinates>";
|
||||
reply.content += "</Point>";
|
||||
reply.content += "</Placemark>";
|
||||
|
||||
@@ -22,12 +22,14 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
||||
#define RAWROUTEDATA_H_
|
||||
|
||||
struct RawRouteData {
|
||||
RawRouteData(unsigned size) {
|
||||
void Resize() {
|
||||
unsigned size = rawViaNodeCoordinates.size()-1;
|
||||
routeSegments.resize(size);
|
||||
segmentEndCoordinates.resize(size);
|
||||
}
|
||||
std::vector< std::vector< _PathData > > routeSegments;
|
||||
std::vector< PhantomNodes > segmentEndCoordinates;
|
||||
std::vector< _Coordinate > rawViaNodeCoordinates;
|
||||
};
|
||||
|
||||
#endif /* RAWROUTEDATA_H_ */
|
||||
|
||||
@@ -95,7 +95,7 @@ public:
|
||||
_Coordinate targetCoord(lat2, lon2);
|
||||
|
||||
vector< _PathData > * path = new vector< _PathData >();
|
||||
RawRouteData * rawRoute = new RawRouteData(0);
|
||||
RawRouteData * rawRoute = new RawRouteData();
|
||||
PhantomNodes * phantomNodes = new PhantomNodes();
|
||||
sEngine->FindRoutingStarts(startCoord, targetCoord, phantomNodes);
|
||||
unsigned int distance = sEngine->ComputeRoute(phantomNodes, path);
|
||||
|
||||
+35
-23
@@ -32,6 +32,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
||||
#include "BaseDescriptor.h"
|
||||
#include "BasePlugin.h"
|
||||
#include "RouteParameters.h"
|
||||
#include "GPXDescriptor.h"
|
||||
#include "KMLDescriptor.h"
|
||||
#include "JSONDescriptor.h"
|
||||
|
||||
@@ -80,6 +81,7 @@ public:
|
||||
descriptorTable.Set("", 0); //default descriptor
|
||||
descriptorTable.Set("kml", 0);
|
||||
descriptorTable.Set("json", 1);
|
||||
descriptorTable.Set("gpx", 2);
|
||||
}
|
||||
|
||||
~ViaRoutePlugin() {
|
||||
@@ -113,13 +115,13 @@ public:
|
||||
|
||||
_Coordinate startCoord(lat1, lon1);
|
||||
_Coordinate targetCoord(lat2, lon2);
|
||||
std::vector<_Coordinate> viaPointVector;
|
||||
RawRouteData rawRoute;
|
||||
|
||||
if(false == checkCoord(startCoord) || false == checkCoord(targetCoord)) {
|
||||
reply = http::Reply::stockReply(http::Reply::badRequest);
|
||||
return;
|
||||
}
|
||||
viaPointVector.push_back(startCoord);
|
||||
rawRoute.rawViaNodeCoordinates.push_back(startCoord);
|
||||
|
||||
std::cout << "[debug] number of vianodes: " << routeParameters.viaPoints.size() << std::endl;
|
||||
for(unsigned i = 0; i < routeParameters.viaPoints.size(); i++) {
|
||||
@@ -130,53 +132,53 @@ public:
|
||||
}
|
||||
int vialat = static_cast<int>(100000.*atof(textCoord[0].c_str()));
|
||||
int vialon = static_cast<int>(100000.*atof(textCoord[1].c_str()));
|
||||
std::cout << "[debug] via" << i << ": " << vialat << "," << vialon << std::endl;
|
||||
// std::cout << "[debug] via" << i << ": " << vialat << "," << vialon << std::endl;
|
||||
_Coordinate viaCoord(vialat, vialon);
|
||||
if(false == checkCoord(viaCoord)) {
|
||||
reply = http::Reply::stockReply(http::Reply::badRequest);
|
||||
return;
|
||||
}
|
||||
viaPointVector.push_back(viaCoord);
|
||||
rawRoute.rawViaNodeCoordinates.push_back(viaCoord);
|
||||
}
|
||||
rawRoute.rawViaNodeCoordinates.push_back(targetCoord);
|
||||
vector<PhantomNode> phantomNodeVector(rawRoute.rawViaNodeCoordinates.size());
|
||||
#pragma omp parallel for
|
||||
for(unsigned i = 0; i < rawRoute.rawViaNodeCoordinates.size(); i++) {
|
||||
threadData[omp_get_thread_num()]->sEngine->FindPhantomNodeForCoordinate( rawRoute.rawViaNodeCoordinates[i], phantomNodeVector[i]);
|
||||
}
|
||||
viaPointVector.push_back(targetCoord);
|
||||
|
||||
|
||||
RawRouteData * rawRoute = new RawRouteData(viaPointVector.size()-1);
|
||||
rawRoute.Resize();
|
||||
|
||||
unsigned distance = 0;
|
||||
bool errorOccurredFlag = false;
|
||||
double time = get_timestamp();
|
||||
|
||||
//#pragma omp parallel for reduction(+:distance)
|
||||
for(unsigned i = 0; i < viaPointVector.size()-1; i++) {
|
||||
|
||||
//#pragma omp parallel for reduction(+:distance)
|
||||
for(unsigned i = 0; i < phantomNodeVector.size()-1 && !errorOccurredFlag; i++) {
|
||||
PhantomNodes & segmentPhantomNodes = threadData[omp_get_thread_num()]->phantomNodesOfSegment;
|
||||
segmentPhantomNodes.startPhantom = phantomNodeVector[i];
|
||||
segmentPhantomNodes.targetPhantom = phantomNodeVector[i+1];
|
||||
std::vector< _PathData > path;
|
||||
threadData[omp_get_thread_num()]->sEngine->FindRoutingStarts(viaPointVector[i], viaPointVector[i+1], &segmentPhantomNodes);
|
||||
threadData[omp_get_thread_num()]->distanceOfSegment = threadData[omp_get_thread_num()]->sEngine->ComputeRoute(&segmentPhantomNodes, &path);
|
||||
|
||||
if(UINT_MAX == threadData[omp_get_thread_num()]->distanceOfSegment) {
|
||||
errorOccurredFlag = true;
|
||||
cout << "Error occurred, path not found" << endl;
|
||||
distance = UINT_MAX;
|
||||
break;
|
||||
} else {
|
||||
distance += threadData[omp_get_thread_num()]->distanceOfSegment;
|
||||
}
|
||||
|
||||
std::cout << "Computing route segment " << i << std::endl;
|
||||
|
||||
//put segments at correct position of routes raw data
|
||||
rawRoute->segmentEndCoordinates[i] = (segmentPhantomNodes);
|
||||
rawRoute->routeSegments[i] = path;
|
||||
rawRoute.segmentEndCoordinates[i] = (segmentPhantomNodes);
|
||||
rawRoute.routeSegments[i] = path;
|
||||
}
|
||||
|
||||
double time2 = get_timestamp();
|
||||
std::cout << "Finished routing after " << (time2-time) << "s" << std::endl;
|
||||
time = get_timestamp();
|
||||
|
||||
if(errorOccurredFlag) {
|
||||
distance = UINT_MAX;
|
||||
} else {
|
||||
|
||||
|
||||
}
|
||||
reply.status = http::Reply::ok;
|
||||
|
||||
BaseDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> > > * desc;
|
||||
@@ -213,6 +215,10 @@ public:
|
||||
case 1:
|
||||
desc = new JSONDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> > >();
|
||||
|
||||
break;
|
||||
case 2:
|
||||
desc = new GPXDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> > >();
|
||||
|
||||
break;
|
||||
default:
|
||||
desc = new KMLDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> > >();
|
||||
@@ -222,7 +228,7 @@ public:
|
||||
PhantomNodes phantomNodes;
|
||||
threadData[0]->sEngine->FindRoutingStarts(startCoord, targetCoord, &phantomNodes);
|
||||
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";
|
||||
}
|
||||
@@ -253,6 +259,13 @@ public:
|
||||
reply.headers[2].value = "attachment; filename=\"route.json\"";
|
||||
}
|
||||
|
||||
break;
|
||||
case 2:
|
||||
reply.headers[1].name = "Content-Type";
|
||||
reply.headers[1].value = "application/gpx+xml; charset=UTF-8";
|
||||
reply.headers[2].name = "Content-Disposition";
|
||||
reply.headers[2].value = "attachment; filename=\"route.gpx\"";
|
||||
|
||||
break;
|
||||
default:
|
||||
reply.headers[1].name = "Content-Type";
|
||||
@@ -268,7 +281,6 @@ public:
|
||||
|
||||
|
||||
delete desc;
|
||||
delete rawRoute;
|
||||
return;
|
||||
}
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user