Merge branch 'master' of https://github.com/DennisOSRM/Project-OSRM
Conflicts: Algorithms/DouglasPeucker.h
This commit is contained in:
commit
e45b7b4b14
@ -29,7 +29,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
||||
#include "../DataStructures/Coordinate.h"
|
||||
|
||||
/*This class object computes the bitvector of indicating generalized input points
|
||||
* according to the (Ramer-)Douglas-Peucker algorithm. Runtime n\log n calls to fastDistance
|
||||
* according to the (Ramer-)Douglas-Peucker algorithm.
|
||||
*
|
||||
* Input is vector of pairs. Each pair consists of the point information and a bit
|
||||
* indicating if the points is present in the generalization.
|
||||
@ -37,7 +37,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
||||
|
||||
//These thresholds are more or less heuristically chosen.
|
||||
// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
||||
static double DouglasPeuckerThresholds[19] = { 32000000, 16240000, 80240000, 40240000, 20000000, 10000000, 500000, 240000, 120000, 60000, 30000, 19000, 5000, 2000, 200, 16, 6, 3, 3 };
|
||||
static double DouglasPeuckerThresholds[19] = { 32000000., 16240000., 80240000., 40240000., 20000000., 10000000., 500000., 240000., 120000., 60000., 30000., 19000., 5000., 2000., 200, 16, 6, 3. , 3. };
|
||||
|
||||
template<class PointT>
|
||||
class DouglasPeucker {
|
||||
@ -45,57 +45,6 @@ private:
|
||||
typedef std::pair<std::size_t, std::size_t> PairOfPoints;
|
||||
//Stack to simulate the recursion
|
||||
std::stack<PairOfPoints > recursionStack;
|
||||
public:
|
||||
void Run(std::vector<PointT> & inputVector, const unsigned zoomLevel) {
|
||||
const unsigned sizeOfInputVector = inputVector.size();
|
||||
{
|
||||
assert(zoomLevel < 19);
|
||||
assert(1 < inputVector.size());
|
||||
std::size_t leftBorderOfRange = 0;
|
||||
std::size_t rightBorderOfRange = 1;
|
||||
|
||||
//Sweep linerarily over array and identify those ranges that need to be checked
|
||||
//decision points have been previously marked
|
||||
do {
|
||||
assert(inputVector[leftBorderOfRange].necessary);
|
||||
assert(inputVector.back().necessary);
|
||||
|
||||
if(inputVector[rightBorderOfRange].necessary) {
|
||||
recursionStack.push(std::make_pair(leftBorderOfRange, rightBorderOfRange));
|
||||
leftBorderOfRange = rightBorderOfRange;
|
||||
}
|
||||
++rightBorderOfRange;
|
||||
} while( rightBorderOfRange < sizeOfInputVector);
|
||||
}
|
||||
while(!recursionStack.empty()) {
|
||||
//pop next element
|
||||
const PairOfPoints pair = recursionStack.top();
|
||||
recursionStack.pop();
|
||||
assert(inputVector[pair.first].necessary);
|
||||
assert(inputVector[pair.second].necessary);
|
||||
assert(pair.second < sizeOfInputVector);
|
||||
assert(pair.first < pair.second);
|
||||
int maxDistance = INT_MIN;
|
||||
std::size_t indexOfFarthestElement = pair.second;
|
||||
//find index idx of element with maxDistance
|
||||
for(std::size_t i = pair.first+1; i < pair.second; ++i){
|
||||
const int distance = fastDistance(inputVector[i].location, inputVector[pair.first].location, inputVector[pair.second].location);
|
||||
if(distance > DouglasPeuckerThresholds[zoomLevel] && distance > maxDistance) {
|
||||
indexOfFarthestElement = i;
|
||||
maxDistance = distance;
|
||||
}
|
||||
}
|
||||
if (maxDistance > DouglasPeuckerThresholds[zoomLevel]) {
|
||||
// mark idx as necessary
|
||||
inputVector[indexOfFarthestElement].necessary = true;
|
||||
if (1 < indexOfFarthestElement - pair.first) {
|
||||
recursionStack.push(std::make_pair(pair.first, indexOfFarthestElement) );
|
||||
}
|
||||
if (1 < pair.second - indexOfFarthestElement)
|
||||
recursionStack.push(std::make_pair(indexOfFarthestElement, pair.second) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This distance computation does integer arithmetic only and is about twice as fast as
|
||||
@ -124,6 +73,57 @@ public:
|
||||
return dist;
|
||||
}
|
||||
|
||||
|
||||
public:
|
||||
void Run(std::vector<PointT> & inputVector, const unsigned zoomLevel) {
|
||||
{
|
||||
assert(zoomLevel < 19);
|
||||
assert(1 < inputVector.size());
|
||||
std::size_t leftBorderOfRange = 0;
|
||||
std::size_t rightBorderOfRange = 1;
|
||||
//Sweep linerarily over array and identify those ranges that need to be checked
|
||||
// recursionStack.hint(inputVector.size());
|
||||
do {
|
||||
assert(inputVector[leftBorderOfRange].necessary);
|
||||
assert(inputVector.back().necessary);
|
||||
|
||||
if(inputVector[rightBorderOfRange].necessary) {
|
||||
recursionStack.push(std::make_pair(leftBorderOfRange, rightBorderOfRange));
|
||||
leftBorderOfRange = rightBorderOfRange;
|
||||
}
|
||||
++rightBorderOfRange;
|
||||
} while( rightBorderOfRange < inputVector.size());
|
||||
}
|
||||
while(!recursionStack.empty()) {
|
||||
//pop next element
|
||||
const PairOfPoints pair = recursionStack.top();
|
||||
recursionStack.pop();
|
||||
assert(inputVector[pair.first].necessary);
|
||||
assert(inputVector[pair.second].necessary);
|
||||
assert(pair.second < inputVector.size());
|
||||
assert(pair.first < pair.second);
|
||||
int maxDistance = INT_MIN;
|
||||
|
||||
std::size_t indexOfFarthestElement = pair.second;
|
||||
//find index idx of element with maxDistance
|
||||
for(std::size_t i = pair.first+1; i < pair.second; ++i){
|
||||
const double distance = std::fabs(fastDistance(inputVector[i].location, inputVector[pair.first].location, inputVector[pair.second].location));
|
||||
if(distance > DouglasPeuckerThresholds[zoomLevel] && distance > maxDistance) {
|
||||
indexOfFarthestElement = i;
|
||||
maxDistance = distance;
|
||||
}
|
||||
}
|
||||
if (maxDistance > DouglasPeuckerThresholds[zoomLevel]) {
|
||||
// mark idx as necessary
|
||||
inputVector[indexOfFarthestElement].necessary = true;
|
||||
if (1 < indexOfFarthestElement - pair.first) {
|
||||
recursionStack.push(std::make_pair(pair.first, indexOfFarthestElement) );
|
||||
}
|
||||
if (1 < pair.second - indexOfFarthestElement)
|
||||
recursionStack.push(std::make_pair(indexOfFarthestElement, pair.second) );
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* DOUGLASPEUCKER_H_ */
|
||||
|
@ -1 +0,0 @@
|
||||
profiles/car.lua
|
222
profile.lua
Normal file
222
profile.lua
Normal file
@ -0,0 +1,222 @@
|
||||
-- Begin of globals
|
||||
|
||||
barrier_whitelist = { ["cattle_grid"] = true, ["border_control"] = true, ["toll_booth"] = true, ["sally_port"] = true, ["gate"] = true}
|
||||
access_tag_whitelist = { ["yes"] = true, ["motorcar"] = true, ["motor_vehicle"] = true, ["vehicle"] = true, ["permissive"] = true, ["designated"] = true }
|
||||
access_tag_blacklist = { ["no"] = true, ["private"] = true, ["agricultural"] = true, ["forestery"] = true }
|
||||
access_tag_restricted = { ["destination"] = true, ["delivery"] = true }
|
||||
access_tags = { "motorcar", "motor_vehicle", "vehicle" }
|
||||
access_tags_hierachy = { "motorcar", "motor_vehicle", "vehicle", "access" }
|
||||
service_tag_restricted = { ["parking_aisle"] = true }
|
||||
ignore_in_grid = { ["ferry"] = true }
|
||||
|
||||
speed_profile = {
|
||||
["motorway"] = 90,
|
||||
["motorway_link"] = 75,
|
||||
["trunk"] = 85,
|
||||
["trunk_link"] = 70,
|
||||
["primary"] = 65,
|
||||
["primary_link"] = 60,
|
||||
["secondary"] = 55,
|
||||
["secondary_link"] = 50,
|
||||
["tertiary"] = 40,
|
||||
["tertiary_link"] = 30,
|
||||
["unclassified"] = 25,
|
||||
["residential"] = 25,
|
||||
["living_street"] = 10,
|
||||
["service"] = 15,
|
||||
-- ["track"] = 5,
|
||||
["ferry"] = 5,
|
||||
["default"] = 50
|
||||
}
|
||||
|
||||
take_minimum_of_speeds = false
|
||||
obey_oneway = true
|
||||
obey_bollards = true
|
||||
use_restrictions = true
|
||||
ignore_areas = true -- future feature
|
||||
traffic_signal_penalty = 2
|
||||
u_turn_penalty = 20
|
||||
|
||||
-- End of globals
|
||||
|
||||
--find first tag in access hierachy which is set
|
||||
local function find_access_tag(source)
|
||||
for i,v in ipairs(access_tags_hierachy) do
|
||||
if source.tags:Holds(v) then
|
||||
local tag = source.tags:Find(v)
|
||||
if tag ~= '' then --and tag ~= "" then
|
||||
return tag
|
||||
end
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
local function find_in_keyvals(keyvals, tag)
|
||||
if keyvals:Holds(tag) then
|
||||
return keyvals:Find(tag)
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
local function parse_maxspeed(source)
|
||||
if source == nil then
|
||||
return 0
|
||||
end
|
||||
local n = tonumber(source)
|
||||
if n == nil then
|
||||
n = 0
|
||||
end
|
||||
if string.match(source, "mph") or string.match(source, "mp/h") then
|
||||
n = (n*1609)/1000;
|
||||
end
|
||||
return math.abs(n)
|
||||
end
|
||||
|
||||
function node_function (node)
|
||||
local barrier = node.tags:Find ("barrier")
|
||||
local access = find_access_tag(node)
|
||||
local traffic_signal = node.tags:Find("highway")
|
||||
|
||||
--flag node if it carries a traffic light
|
||||
|
||||
if traffic_signal == "traffic_signals" then
|
||||
node.traffic_light = true;
|
||||
end
|
||||
|
||||
-- parse access and barrier tags
|
||||
if access and access ~= "" then
|
||||
if access_tag_blacklist[access] then
|
||||
node.bollard = true
|
||||
end
|
||||
elseif barrier and barrier ~= "" then
|
||||
if barrier_whitelist[barrier] then
|
||||
return
|
||||
else
|
||||
node.bollard = true
|
||||
end
|
||||
end
|
||||
return 1
|
||||
end
|
||||
|
||||
|
||||
function way_function (way, numberOfNodesInWay)
|
||||
|
||||
-- A way must have two nodes or more
|
||||
if(numberOfNodesInWay < 2) then
|
||||
return 0;
|
||||
end
|
||||
|
||||
-- First, get the properties of each way that we come across
|
||||
local highway = way.tags:Find("highway")
|
||||
local name = way.tags:Find("name")
|
||||
local ref = way.tags:Find("ref")
|
||||
local junction = way.tags:Find("junction")
|
||||
local route = way.tags:Find("route")
|
||||
local maxspeed = parse_maxspeed(way.tags:Find ( "maxspeed") )
|
||||
local barrier = way.tags:Find("barrier")
|
||||
local oneway = way.tags:Find("oneway")
|
||||
local cycleway = way.tags:Find("cycleway")
|
||||
local duration = way.tags:Find("duration")
|
||||
local service = way.tags:Find("service")
|
||||
local area = way.tags:Find("area")
|
||||
local access = find_access_tag(way)
|
||||
|
||||
-- Second, parse the way according to these properties
|
||||
|
||||
if ignore_areas and ("yes" == area) then
|
||||
return 0
|
||||
end
|
||||
|
||||
-- Check if we are allowed to access the way
|
||||
if access_tag_blacklist[access] then
|
||||
return 0
|
||||
end
|
||||
|
||||
-- Set the name that will be used for instructions
|
||||
if "" ~= ref then
|
||||
way.name = ref
|
||||
elseif "" ~= name then
|
||||
way.name = name
|
||||
-- else
|
||||
-- way.name = highway -- if no name exists, use way type
|
||||
end
|
||||
|
||||
if "roundabout" == junction then
|
||||
way.roundabout = true;
|
||||
end
|
||||
|
||||
-- Handling ferries and piers
|
||||
if (speed_profile[route] ~= nil and speed_profile[route] > 0)
|
||||
then
|
||||
if durationIsValid(duration) then
|
||||
way.speed = math.max( parseDuration(duration) / math.max(1, numberOfNodesInWay-1) );
|
||||
way.is_duration_set = true
|
||||
end
|
||||
way.direction = Way.bidirectional
|
||||
if speed_profile[route] ~= nil then
|
||||
highway = route;
|
||||
end
|
||||
if not way.is_duration_set then
|
||||
way.speed = speed_profile[highway]
|
||||
end
|
||||
end
|
||||
|
||||
-- Set the avg speed on the way if it is accessible by road class
|
||||
if (speed_profile[highway] ~= nil and way.speed == -1 ) then
|
||||
if 0 == maxspeed then
|
||||
maxspeed = math.huge
|
||||
end
|
||||
way.speed = math.min(speed_profile[highway], maxspeed)
|
||||
end
|
||||
|
||||
-- Set the avg speed on ways that are marked accessible
|
||||
if "" ~= highway and access_tag_whitelist[access] and way.speed == -1 then
|
||||
if 0 == maxspeed then
|
||||
maxspeed = math.huge
|
||||
end
|
||||
way.speed = math.min(speed_profile["default"], maxspeed)
|
||||
end
|
||||
|
||||
-- Set access restriction flag if access is allowed under certain restrictions only
|
||||
if access ~= "" and access_tag_restricted[access] then
|
||||
way.is_access_restricted = true
|
||||
end
|
||||
|
||||
-- Set access restriction flag if service is allowed under certain restrictions only
|
||||
if service ~= "" and service_tag_restricted[service] then
|
||||
way.is_access_restricted = true
|
||||
end
|
||||
|
||||
-- Set direction according to tags on way
|
||||
if obey_oneway then
|
||||
if oneway == "no" or oneway == "0" or oneway == "false" then
|
||||
way.direction = Way.bidirectional
|
||||
elseif oneway == "-1" then
|
||||
way.direction = Way.opposite
|
||||
elseif oneway == "yes" or oneway == "1" or oneway == "true" or junction == "roundabout" or highway == "motorway_link" or highway == "motorway" then
|
||||
way.direction = Way.oneway
|
||||
else
|
||||
way.direction = Way.bidirectional
|
||||
end
|
||||
else
|
||||
way.direction = Way.bidirectional
|
||||
end
|
||||
|
||||
-- Override general direction settings of there is a specific one for our mode of travel
|
||||
|
||||
if ignore_in_grid[highway] ~= nil and ignore_in_grid[highway] then
|
||||
way.ignore_in_grid = true
|
||||
end
|
||||
way.type = 1
|
||||
return 1
|
||||
end
|
||||
|
||||
-- These are wrappers to parse vectors of nodes and ways and thus to speed up any tracing JIT
|
||||
|
||||
function node_vector_function(vector)
|
||||
for v in vector.nodes do
|
||||
node_function(v)
|
||||
end
|
||||
end
|
14
server.ini
14
server.ini
@ -2,10 +2,10 @@ Threads = 8
|
||||
IP = 0.0.0.0
|
||||
Port = 5000
|
||||
|
||||
hsgrData=/opt/osm/baden-wuerttemberg.osrm.hsgr
|
||||
nodesData=/opt/osm/baden-wuerttemberg.osrm.nodes
|
||||
edgesData=/opt/osm/baden-wuerttemberg.osrm.edges
|
||||
ramIndex=/opt/osm/baden-wuerttemberg.osrm.ramIndex
|
||||
fileIndex=/opt/osm/baden-wuerttemberg.osrm.fileIndex
|
||||
namesData=/opt/osm/baden-wuerttemberg.osrm.names
|
||||
timestamp=/opt/osm/baden-wuerttemberg.osrm.timestamp
|
||||
hsgrData=/opt/osm/berlin.osrm.hsgr
|
||||
nodesData=/opt/osm/berlin.osrm.nodes
|
||||
edgesData=/opt/osm/berlin.osrm.edges
|
||||
ramIndex=/opt/osm/berlin.osrm.ramIndex
|
||||
fileIndex=/opt/osm/berlin.osrm.fileIndex
|
||||
namesData=/opt/osm/berlin.osrm.names
|
||||
timestamp=/opt/osm/berlin.osrm.timestamp
|
||||
|
Loading…
Reference in New Issue
Block a user