Skip to content

Commit

Permalink
Picks up Stop Signs and Give Ways in Profiles
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-j-h committed Oct 19, 2016
1 parent ab1a927 commit d1b9dff
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 3 deletions.
49 changes: 47 additions & 2 deletions include/extractor/extraction_node.hpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,62 @@
#ifndef EXTRACTION_NODE_HPP
#define EXTRACTION_NODE_HPP

#include <cstdint>

namespace osrm
{
namespace extractor
{

// Stop Signs tagged on nodes can be present or not. In addition Stop Signs have
// an optional way direction they apply to. If the direction is unknown from the
// data we have to compute by checking the distance to the next intersection.
//
// Impl. detail: namespace + enum instead of enum class to make Luabind happy
namespace StopSign
{
enum State : std::uint8_t
{
No = 1 << 0,
YesUnknownDirection = 1 << 1,
YesForward = 1 << 2,
YesBackward = 1 << 3,
};
}

// Give Way is the complement to priority roads. Tagging is the same as Stop Signs.
// See explanation above.
namespace GiveWay
{
enum State : std::uint8_t
{
No = 1 << 0,
YesUnknownDirection = 1 << 1,
YesForward = 1 << 2,
YesBackward = 1 << 3,
};
}

struct ExtractionNode
{
ExtractionNode() : traffic_lights(false), barrier(false) {}
void clear() { traffic_lights = barrier = false; }
ExtractionNode()
: traffic_lights(false), barrier(false), stop_sign(StopSign::No), give_way(GiveWay::No)
{
}

void clear()
{
traffic_lights = false;
barrier = false;
stop_sign = StopSign::No;
give_way = GiveWay::No;
}

bool traffic_lights;
bool barrier;

StopSign::State stop_sign;
GiveWay::State give_way;
};
}
}
Expand Down
29 changes: 29 additions & 0 deletions profiles/car.lua
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,35 @@ function node_function (node, result)
if tag and "traffic_signals" == tag then
result.traffic_lights = true
end

-- Stop Signs and Give Way priority proeperties are tagged on nodes but
-- apply to a specific way direction; if the direction is unknown from
-- the data we have check the distance to the next intersection later.

local direction = node:get_value_by_key("direction")
local forward = direction and "forward" == direction
local backward = direction and "backward" == direction

if tag and "stop" == tag then
if forward then
result.stop_sign = stop_sign.forward
elseif backward then
result.stop_sign = stop_sign.backward
else
result.stop_sign = stop_sign.unknown_direction
end
end

if tag and "give_way" == tag then
if forward then
result.give_way = give_way.forward
elseif backward then
result.give_way = give_way.backward
else
result.give_way = give_way.unknown_direction
end
end

end

function way_function (way, result)
Expand Down
16 changes: 15 additions & 1 deletion src/extractor/scripting_environment_lua.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,21 @@ void LuaScriptingEnvironment::InitContext(LuaScriptingContext &context)

luabind::class_<ExtractionNode>("ResultNode")
.def_readwrite("traffic_lights", &ExtractionNode::traffic_lights)
.def_readwrite("barrier", &ExtractionNode::barrier),
.def_readwrite("barrier", &ExtractionNode::barrier)
.def_readwrite("stop_sign", &ExtractionNode::stop_sign)
.def_readwrite("give_way", &ExtractionNode::give_way),

luabind::class_<TravelMode>("stop_sign")
.enum_("enums")[luabind::value("no", StopSign::No),
luabind::value("forward", StopSign::YesForward),
luabind::value("backward", StopSign::YesBackward),
luabind::value("unknown_direction", StopSign::YesUnknownDirection)],

luabind::class_<TravelMode>("give_way")
.enum_("enums")[luabind::value("no", GiveWay::No),
luabind::value("forward", GiveWay::YesForward),
luabind::value("backward", GiveWay::YesBackward),
luabind::value("unknown_direction", GiveWay::YesUnknownDirection)],

// road classification to be set in profile
luabind::class_<guidance::RoadClassification>("RoadClassification")
Expand Down

0 comments on commit d1b9dff

Please sign in to comment.