Don't mark all lanes as designated when there are blank lane specifiers in the tag.
This commit is contained in:
parent
f88f51fd98
commit
3dfbf42e61
@ -512,6 +512,31 @@ if(NOT WIN32 AND NOT Boost_USE_STATIC_LIBS)
|
||||
add_dependency_defines(-DBOOST_TEST_DYN_LINK)
|
||||
endif()
|
||||
|
||||
FIND_PACKAGE(Lua 5.2 EXACT)
|
||||
IF (LUA_FOUND)
|
||||
MESSAGE(STATUS "Using Lua ${LUA_VERSION_STRING}")
|
||||
ELSE()
|
||||
FIND_PACKAGE(Lua 5.1 EXACT)
|
||||
IF (LUA_FOUND)
|
||||
MESSAGE(STATUS "Using Lua ${LUA_VERSION_STRING}")
|
||||
ELSE()
|
||||
# Now fall back to a lua verison without exact
|
||||
# in case this cmake version also forces patch versions
|
||||
FIND_PACKAGE(Lua 5.2)
|
||||
IF (LUA_FOUND)
|
||||
MESSAGE(STATUS "Using Lua ${LUA_VERSION_STRING}")
|
||||
ELSE()
|
||||
FIND_PACKAGE(Lua 5.1)
|
||||
IF (LUA_FOUND)
|
||||
MESSAGE(STATUS "Using Lua ${LUA_VERSION_STRING}")
|
||||
ELSE()
|
||||
MESSAGE(FATAL_ERROR "Lua 5.1 or 5.2 was not found.")
|
||||
ENDIF()
|
||||
ENDIF()
|
||||
ENDIF()
|
||||
ENDIF()
|
||||
|
||||
set(USED_LUA_LIBRARIES ${LUA_LIBRARY})
|
||||
|
||||
if(NOT WIN32 AND NOT Boost_USE_STATIC_LIBS)
|
||||
add_dependency_defines(-DBOOST_TEST_DYN_LINK)
|
||||
@ -556,7 +581,6 @@ set(EXTRACTOR_LIBRARIES
|
||||
${BOOST_BASE_LIBRARIES}
|
||||
${CMAKE_THREAD_LIBS_INIT}
|
||||
${EXPAT_LIBRARIES}
|
||||
${LUABIND_LIBRARY}
|
||||
${USED_LUA_LIBRARIES}
|
||||
${OSMIUM_LIBRARIES}
|
||||
${STXXL_LIBRARY}
|
||||
@ -566,7 +590,6 @@ set(EXTRACTOR_LIBRARIES
|
||||
set(CONTRACTOR_LIBRARIES
|
||||
${BOOST_BASE_LIBRARIES}
|
||||
${CMAKE_THREAD_LIBS_INIT}
|
||||
${LUABIND_LIBRARY}
|
||||
${USED_LUA_LIBRARIES}
|
||||
${STXXL_LIBRARY}
|
||||
${TBB_LIBRARIES}
|
||||
|
@ -1,93 +0,0 @@
|
||||
# Locate Luabind library
|
||||
# This module defines
|
||||
# LUABIND_FOUND, if false, do not try to link to Luabind
|
||||
# LUABIND_LIBRARIES
|
||||
# LUABIND_INCLUDE_DIR, where to find luabind.hpp
|
||||
|
||||
# First we try using EXACT but in some verison of
|
||||
# cmake this would also match patch versions
|
||||
FIND_PACKAGE(Lua 5.2 EXACT)
|
||||
IF (LUA_FOUND)
|
||||
MESSAGE(STATUS "Using Lua ${LUA_VERSION_STRING}")
|
||||
ELSE()
|
||||
FIND_PACKAGE(Lua 5.1 EXACT)
|
||||
IF (LUA_FOUND)
|
||||
MESSAGE(STATUS "Using Lua ${LUA_VERSION_STRING}")
|
||||
ELSE()
|
||||
# Now fall back to a lua verison without exact
|
||||
# in case this cmake version also forces patch versions
|
||||
FIND_PACKAGE(Lua 5.2)
|
||||
IF (LUA_FOUND)
|
||||
MESSAGE(STATUS "Using Lua ${LUA_VERSION_STRING}")
|
||||
ELSE()
|
||||
FIND_PACKAGE(Lua 5.1)
|
||||
IF (LUA_FOUND)
|
||||
MESSAGE(STATUS "Using Lua ${LUA_VERSION_STRING}")
|
||||
ELSE()
|
||||
MESSAGE(FATAL_ERROR "Lua 5.1 or 5.2 was not found.")
|
||||
ENDIF()
|
||||
ENDIF()
|
||||
ENDIF()
|
||||
ENDIF()
|
||||
|
||||
|
||||
FIND_PATH(LUABIND_INCLUDE_DIR luabind.hpp
|
||||
HINTS
|
||||
$ENV{LUABIND_DIR}
|
||||
PATH_SUFFIXES luabind include/luabind include
|
||||
PATHS
|
||||
~/Library/Frameworks
|
||||
/Library/Frameworks
|
||||
/usr/local
|
||||
/usr
|
||||
/opt/local # DarwinPorts
|
||||
/opt
|
||||
)
|
||||
|
||||
FIND_LIBRARY(LUABIND_LIBRARY
|
||||
NAMES luabind luabind09
|
||||
HINTS
|
||||
$ENV{LUABIND_DIR}
|
||||
PATH_SUFFIXES lib64 lib
|
||||
PATHS
|
||||
~/Library/Frameworks
|
||||
/Library/Frameworks
|
||||
/usr/local
|
||||
/usr
|
||||
/opt/local
|
||||
/opt
|
||||
)
|
||||
|
||||
FIND_LIBRARY(LUABIND_LIBRARY_DBG
|
||||
NAMES luabindd
|
||||
HINTS
|
||||
$ENV{LUABIND_DIR}
|
||||
PATH_SUFFIXES lib64 lib
|
||||
PATHS
|
||||
~/Library/Frameworks
|
||||
/Library/Frameworks
|
||||
/usr/local
|
||||
/usr
|
||||
/opt/local
|
||||
/opt
|
||||
)
|
||||
|
||||
IF(LUABIND_LIBRARY)
|
||||
SET( LUABIND_LIBRARIES "${LUABIND_LIBRARY}" CACHE STRING "Luabind Libraries")
|
||||
ENDIF(LUABIND_LIBRARY)
|
||||
|
||||
INCLUDE(FindPackageHandleStandardArgs)
|
||||
# handle the QUIETLY and REQUIRED arguments and set LUABIND_FOUND to TRUE if
|
||||
# all listed variables are TRUE
|
||||
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Luabind DEFAULT_MSG LUABIND_LIBRARIES LUABIND_INCLUDE_DIR)
|
||||
|
||||
IF( NOT LUABIND_FIND_QUIETLY )
|
||||
IF( LUABIND_FOUND )
|
||||
MESSAGE(STATUS "Found Luabind: ${LUABIND_LIBRARY}" )
|
||||
ENDIF()
|
||||
IF( LUABIND_LIBRARY_DBG )
|
||||
MESSAGE(STATUS "Luabind debug library availible: ${LUABIND_LIBRARY_DBG}")
|
||||
ENDIF()
|
||||
ENDIF()
|
||||
|
||||
MARK_AS_ADVANCED(LUABIND_INCLUDE_DIR LUABIND_LIBRARIES LUABIND_LIBRARY LUABIND_LIBRARY_DBG)
|
@ -2,7 +2,7 @@ FROM ubuntu:14.04
|
||||
|
||||
RUN apt-get update -y && apt-get install -y software-properties-common
|
||||
RUN add-apt-repository ppa:ubuntu-toolchain-r/test
|
||||
RUN apt-get update -y && apt-get install -y g++-5 libbz2-dev libstxxl-dev libstxxl1 libxml2-dev libzip-dev lua5.1 liblua5.1-0-dev libtbb-dev libgdal-dev libluabind-dev libboost-all-dev ccache
|
||||
RUN apt-get update -y && apt-get install -y g++-5 libbz2-dev libstxxl-dev libstxxl1 libxml2-dev libzip-dev lua5.1 liblua5.1-0-dev libtbb-dev libgdal-dev libboost-all-dev ccache
|
||||
RUN apt-get -y install curl cmake cmake-curses-gui git
|
||||
|
||||
WORKDIR /opt
|
||||
|
@ -1,11 +1,8 @@
|
||||
#ifndef SCRIPTING_ENVIRONMENT_LUA_HPP
|
||||
#define SCRIPTING_ENVIRONMENT_LUA_HPP
|
||||
|
||||
#include "extractor/scripting_environment.hpp"
|
||||
#ifndef SCRIPTING_ENVIRONMENT_SOL2_HPP
|
||||
#define SCRIPTING_ENVIRONMENT_SOL2_HPP
|
||||
|
||||
#include "extractor/raster_source.hpp"
|
||||
|
||||
#include "util/lua_util.hpp"
|
||||
#include "extractor/scripting_environment.hpp"
|
||||
|
||||
#include <tbb/enumerable_thread_specific.h>
|
||||
|
||||
@ -13,21 +10,21 @@
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
|
||||
struct lua_State;
|
||||
#include <sol2/sol.hpp>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace extractor
|
||||
{
|
||||
|
||||
struct LuaScriptingContext final
|
||||
struct Sol2ScriptingContext final
|
||||
{
|
||||
void processNode(const osmium::Node &, ExtractionNode &result);
|
||||
void processWay(const osmium::Way &, ExtractionWay &result);
|
||||
|
||||
ProfileProperties properties;
|
||||
SourceContainer sources;
|
||||
util::LuaState state;
|
||||
sol::state state;
|
||||
|
||||
bool has_turn_penalty_function;
|
||||
bool has_node_function;
|
||||
@ -42,15 +39,15 @@ struct LuaScriptingContext final
|
||||
* Each thread has its own lua state which is implemented with thread specific
|
||||
* storage from TBB.
|
||||
*/
|
||||
class LuaScriptingEnvironment final : public ScriptingEnvironment
|
||||
class Sol2ScriptingEnvironment final : public ScriptingEnvironment
|
||||
{
|
||||
public:
|
||||
explicit LuaScriptingEnvironment(const std::string &file_name);
|
||||
~LuaScriptingEnvironment() override = default;
|
||||
explicit Sol2ScriptingEnvironment(const std::string &file_name);
|
||||
~Sol2ScriptingEnvironment() override = default;
|
||||
|
||||
const ProfileProperties &GetProfileProperties() override;
|
||||
|
||||
LuaScriptingContext &GetLuaContext();
|
||||
Sol2ScriptingContext &GetSol2Context();
|
||||
|
||||
std::vector<std::string> GetNameSuffixList() override;
|
||||
std::vector<std::string> GetRestrictions() override;
|
||||
@ -69,12 +66,12 @@ class LuaScriptingEnvironment final : public ScriptingEnvironment
|
||||
&resulting_restrictions) override;
|
||||
|
||||
private:
|
||||
void InitContext(LuaScriptingContext &context);
|
||||
void InitContext(Sol2ScriptingContext &context);
|
||||
std::mutex init_mutex;
|
||||
std::string file_name;
|
||||
tbb::enumerable_thread_specific<std::unique_ptr<LuaScriptingContext>> script_contexts;
|
||||
tbb::enumerable_thread_specific<std::unique_ptr<Sol2ScriptingContext>> script_contexts;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* SCRIPTING_ENVIRONMENT_LUA_HPP */
|
||||
#endif /* SCRIPTING_ENVIRONMENT_SOL2_HPP */
|
@ -18,25 +18,6 @@ namespace osrm
|
||||
namespace util
|
||||
{
|
||||
|
||||
struct LuaState
|
||||
{
|
||||
LuaState() : handle{::luaL_newstate(), &::lua_close} { luaL_openlibs(*this); }
|
||||
|
||||
operator lua_State *() { return handle.get(); }
|
||||
operator lua_State const *() const { return handle.get(); }
|
||||
|
||||
using handle_type = std::unique_ptr<lua_State, decltype(&::lua_close)>;
|
||||
handle_type handle;
|
||||
};
|
||||
|
||||
// Check if the lua function <name> is defined
|
||||
inline bool luaFunctionExists(lua_State *lua_state, const char *name)
|
||||
{
|
||||
luabind::object globals_table = luabind::globals(lua_state);
|
||||
luabind::object lua_function = globals_table[name];
|
||||
return lua_function && (luabind::type(lua_function) == LUA_TFUNCTION);
|
||||
}
|
||||
|
||||
// Add the folder contain the script to the lua load path, so script can easily require() other lua
|
||||
// scripts inside that folder, or subfolders.
|
||||
// See http://lua-users.org/wiki/PackagePath for details on the package.path syntax.
|
||||
|
@ -17,7 +17,7 @@ sudo apt-get update -qq --yes || true
|
||||
|
||||
|
||||
sudo apt-get install -qq --yes --force-yes g++-4.8-arm-linux-gnueabihf g++-4.8-multilib-arm-linux-gnueabihf gcc-4.8-arm-linux-gnueabihf gcc-4.8-multilib-arm-linux-gnueabihf
|
||||
sudo apt-get install -qq --yes --force-yes libexpat1-dev:armhf zlib1g-dev:armhf libbz2-dev:armhf libboost-date-time-dev:armhf libboost-filesystem-dev:armhf libboost-iostreams-dev:armhf libboost-program-options-dev:armhf libboost-regex-dev:armhf libboost-system-dev:armhf libboost-thread-dev:armhf libtbb-dev:armhf libboost-test-dev:armhf libluabind-dev:armhf
|
||||
sudo apt-get install -qq --yes --force-yes libexpat1-dev:armhf zlib1g-dev:armhf libbz2-dev:armhf libboost-date-time-dev:armhf libboost-filesystem-dev:armhf libboost-iostreams-dev:armhf libboost-program-options-dev:armhf libboost-regex-dev:armhf libboost-system-dev:armhf libboost-thread-dev:armhf libtbb-dev:armhf libboost-test-dev:armhf
|
||||
|
||||
## build libstxxl1v5:armhf from sources, no package in trusty
|
||||
if [ $UBUNTU_RELEASE == trusty ] ; then
|
||||
|
@ -3,4 +3,4 @@
|
||||
sudo dpkg --add-architecture i386
|
||||
sudo add-apt-repository --yes ppa:ubuntu-toolchain-r/test && ( sudo apt-get update -qq --yes || true )
|
||||
|
||||
sudo apt-get install -qq --yes --force-yes g++-6-multilib libxml2-dev:i386 libexpat1-dev:i386 libzip-dev:i386 libbz2-dev:i386 libstxxl-dev:i386 libtbb-dev:i386 lua5.2:i386 liblua5.2-dev:i386 libluabind-dev:i386 libboost-date-time-dev:i386 libboost-filesystem-dev:i386 libboost-iostreams-dev:i386 libboost-program-options-dev:i386 libboost-regex-dev:i386 libboost-system-dev:i386 libboost-thread-dev:i386 libboost-test-dev:i386
|
||||
sudo apt-get install -qq --yes --force-yes g++-6-multilib libxml2-dev:i386 libexpat1-dev:i386 libzip-dev:i386 libbz2-dev:i386 libstxxl-dev:i386 libtbb-dev:i386 lua5.2:i386 liblua5.2-dev:i386 libboost-date-time-dev:i386 libboost-filesystem-dev:i386 libboost-iostreams-dev:i386 libboost-program-options-dev:i386 libboost-regex-dev:i386 libboost-system-dev:i386 libboost-thread-dev:i386 libboost-test-dev:i386
|
||||
|
@ -1,447 +0,0 @@
|
||||
#include "extractor/scripting_environment_lua.hpp"
|
||||
|
||||
#include "extractor/external_memory_node.hpp"
|
||||
#include "extractor/extraction_helper_functions.hpp"
|
||||
#include "extractor/extraction_node.hpp"
|
||||
#include "extractor/extraction_way.hpp"
|
||||
#include "extractor/internal_extractor_edge.hpp"
|
||||
#include "extractor/profile_properties.hpp"
|
||||
#include "extractor/raster_source.hpp"
|
||||
#include "extractor/restriction_parser.hpp"
|
||||
#include "util/exception.hpp"
|
||||
#include "util/exception_utils.hpp"
|
||||
#include "util/log.hpp"
|
||||
#include "util/lua_util.hpp"
|
||||
#include "util/typedefs.hpp"
|
||||
|
||||
#include <luabind/iterator_policy.hpp>
|
||||
#include <luabind/operator.hpp>
|
||||
#include <luabind/tag_function.hpp>
|
||||
|
||||
#include <osmium/osm.hpp>
|
||||
|
||||
#include <tbb/parallel_for.h>
|
||||
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace extractor
|
||||
{
|
||||
namespace
|
||||
{
|
||||
// wrapper method as luabind doesn't automatically overload funcs w/ default parameters
|
||||
template <class T>
|
||||
auto get_value_by_key(T const &object, const char *key) -> decltype(object.get_value_by_key(key))
|
||||
{
|
||||
auto v = object.get_value_by_key(key);
|
||||
if (v && *v)
|
||||
{ // non-empty string?
|
||||
return v;
|
||||
}
|
||||
else
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
template <class T> double latToDouble(T const &object)
|
||||
{
|
||||
return static_cast<double>(util::toFloating(object.lat));
|
||||
}
|
||||
|
||||
template <class T> double lonToDouble(T const &object)
|
||||
{
|
||||
return static_cast<double>(util::toFloating(object.lon));
|
||||
}
|
||||
|
||||
// Luabind does not like memr funs: instead of casting to the function's signature (mem fun ptr) we
|
||||
// simply wrap it
|
||||
auto get_nodes_for_way(const osmium::Way &way) -> decltype(way.nodes()) { return way.nodes(); }
|
||||
|
||||
// Error handler
|
||||
int luaErrorCallback(lua_State *state)
|
||||
{
|
||||
std::string error_msg = lua_tostring(state, -1);
|
||||
std::ostringstream error_stream;
|
||||
error_stream << error_msg;
|
||||
throw util::exception("ERROR occurred in profile script:\n" + error_stream.str() + SOURCE_REF);
|
||||
}
|
||||
}
|
||||
|
||||
LuaScriptingEnvironment::LuaScriptingEnvironment(const std::string &file_name)
|
||||
: file_name(file_name)
|
||||
{
|
||||
util::Log() << "Using script " << file_name;
|
||||
}
|
||||
|
||||
void LuaScriptingEnvironment::InitContext(LuaScriptingContext &context)
|
||||
{
|
||||
typedef double (osmium::Location::*location_member_ptr_type)() const;
|
||||
|
||||
luabind::open(context.state);
|
||||
// open utility libraries string library;
|
||||
luaL_openlibs(context.state);
|
||||
|
||||
util::luaAddScriptFolderToLoadPath(context.state, file_name.c_str());
|
||||
|
||||
// In the following we have to register several char typedefs to Lua which we can't
|
||||
// make proper enums (since enums can't be bit-packed but chars can).
|
||||
//
|
||||
// Luabind crashes hard (sometimes on some platforms) during runtime when registering
|
||||
// the same type (e.g. our char typedefs) multiple times.
|
||||
//
|
||||
// We work around this by creating separate enum types for all typedefs here.
|
||||
// This makes sure they have different typeid()s which Luabind dispatches upon.
|
||||
//
|
||||
// We still bind the typedef values to the enum since the enum is integral by default.
|
||||
enum TravelModeEnumDummyForLuabind
|
||||
{
|
||||
};
|
||||
enum RoadPriorityClassEnumDummyForLuabind
|
||||
{
|
||||
};
|
||||
|
||||
// Add our function to the state's global scope
|
||||
luabind::module(context.state)
|
||||
[luabind::def("durationIsValid", durationIsValid),
|
||||
luabind::def("parseDuration", parseDuration),
|
||||
luabind::def("trimLaneString", trimLaneString),
|
||||
luabind::def("applyAccessTokens", applyAccessTokens),
|
||||
luabind::def("canonicalizeStringList", canonicalizeStringList),
|
||||
luabind::class_<TravelModeEnumDummyForLuabind>("mode").enum_(
|
||||
"enums")[luabind::value("inaccessible", TRAVEL_MODE_INACCESSIBLE),
|
||||
luabind::value("driving", TRAVEL_MODE_DRIVING),
|
||||
luabind::value("cycling", TRAVEL_MODE_CYCLING),
|
||||
luabind::value("walking", TRAVEL_MODE_WALKING),
|
||||
luabind::value("ferry", TRAVEL_MODE_FERRY),
|
||||
luabind::value("train", TRAVEL_MODE_TRAIN),
|
||||
luabind::value("pushing_bike", TRAVEL_MODE_PUSHING_BIKE),
|
||||
luabind::value("steps_up", TRAVEL_MODE_STEPS_UP),
|
||||
luabind::value("steps_down", TRAVEL_MODE_STEPS_DOWN),
|
||||
luabind::value("river_up", TRAVEL_MODE_RIVER_UP),
|
||||
luabind::value("river_down", TRAVEL_MODE_RIVER_DOWN),
|
||||
luabind::value("route", TRAVEL_MODE_ROUTE)],
|
||||
|
||||
luabind::class_<RoadPriorityClassEnumDummyForLuabind>("road_priority_class")
|
||||
.enum_("enums")
|
||||
[luabind::value("motorway", extractor::guidance::RoadPriorityClass::MOTORWAY),
|
||||
luabind::value("trunk", extractor::guidance::RoadPriorityClass::TRUNK),
|
||||
luabind::value("primary", extractor::guidance::RoadPriorityClass::PRIMARY),
|
||||
luabind::value("secondary", extractor::guidance::RoadPriorityClass::SECONDARY),
|
||||
luabind::value("tertiary", extractor::guidance::RoadPriorityClass::TERTIARY),
|
||||
luabind::value("main_residential",
|
||||
extractor::guidance::RoadPriorityClass::MAIN_RESIDENTIAL),
|
||||
luabind::value("side_residential",
|
||||
extractor::guidance::RoadPriorityClass::SIDE_RESIDENTIAL),
|
||||
luabind::value("link_road", extractor::guidance::RoadPriorityClass::LINK_ROAD),
|
||||
luabind::value("bike_path", extractor::guidance::RoadPriorityClass::BIKE_PATH),
|
||||
luabind::value("foot_path", extractor::guidance::RoadPriorityClass::FOOT_PATH),
|
||||
luabind::value("connectivity",
|
||||
extractor::guidance::RoadPriorityClass::CONNECTIVITY)],
|
||||
|
||||
luabind::class_<SourceContainer>("sources")
|
||||
.def(luabind::constructor<>())
|
||||
.def("load", &SourceContainer::LoadRasterSource)
|
||||
.def("query", &SourceContainer::GetRasterDataFromSource)
|
||||
.def("interpolate", &SourceContainer::GetRasterInterpolateFromSource),
|
||||
luabind::class_<const float>("constants")
|
||||
.enum_("enums")[luabind::value("precision", COORDINATE_PRECISION)],
|
||||
|
||||
luabind::class_<ProfileProperties>("ProfileProperties")
|
||||
.def(luabind::constructor<>())
|
||||
.property("traffic_signal_penalty",
|
||||
&ProfileProperties::GetTrafficSignalPenalty,
|
||||
&ProfileProperties::SetTrafficSignalPenalty)
|
||||
.property("u_turn_penalty",
|
||||
&ProfileProperties::GetUturnPenalty,
|
||||
&ProfileProperties::SetUturnPenalty)
|
||||
.property("max_speed_for_map_matching",
|
||||
&ProfileProperties::GetMaxSpeedForMapMatching,
|
||||
&ProfileProperties::SetMaxSpeedForMapMatching)
|
||||
.def_readwrite("use_turn_restrictions", &ProfileProperties::use_turn_restrictions)
|
||||
.def_readwrite("continue_straight_at_waypoint",
|
||||
&ProfileProperties::continue_straight_at_waypoint)
|
||||
.def_readwrite("left_hand_driving", &ProfileProperties::left_hand_driving),
|
||||
|
||||
luabind::class_<std::vector<std::string>>("vector").def(
|
||||
"Add",
|
||||
static_cast<void (std::vector<std::string>::*)(const std::string &)>(
|
||||
&std::vector<std::string>::push_back)),
|
||||
|
||||
luabind::class_<osmium::Location>("Location")
|
||||
.def<location_member_ptr_type>("lat", &osmium::Location::lat)
|
||||
.def<location_member_ptr_type>("lon", &osmium::Location::lon),
|
||||
|
||||
luabind::class_<osmium::Node>("Node")
|
||||
// .def<node_member_ptr_type>("tags", &osmium::Node::tags)
|
||||
.def("location", &osmium::Node::location)
|
||||
.def("get_value_by_key", &osmium::Node::get_value_by_key)
|
||||
.def("get_value_by_key", &get_value_by_key<osmium::Node>)
|
||||
.def("id", &osmium::Node::id),
|
||||
|
||||
luabind::class_<ExtractionNode>("ResultNode")
|
||||
.def_readwrite("traffic_lights", &ExtractionNode::traffic_lights)
|
||||
.def_readwrite("barrier", &ExtractionNode::barrier),
|
||||
|
||||
// road classification to be set in profile
|
||||
luabind::class_<guidance::RoadClassification>("RoadClassification")
|
||||
.property("motorway_class",
|
||||
&guidance::RoadClassification::IsMotorwayClass,
|
||||
&guidance::RoadClassification::SetMotorwayFlag)
|
||||
.property("link_class",
|
||||
&guidance::RoadClassification::IsLinkClass,
|
||||
&guidance::RoadClassification::SetLinkClass)
|
||||
.property("may_be_ignored",
|
||||
&guidance::RoadClassification::IsLowPriorityRoadClass,
|
||||
&guidance::RoadClassification::SetLowPriorityFlag)
|
||||
.property("road_priority_class",
|
||||
&guidance::RoadClassification::GetClass,
|
||||
&guidance::RoadClassification::SetClass)
|
||||
.property("num_lanes",
|
||||
&guidance::RoadClassification::GetNumberOfLanes,
|
||||
&guidance::RoadClassification::SetNumberOfLanes),
|
||||
|
||||
luabind::class_<ExtractionWay>("ResultWay")
|
||||
// .def(luabind::constructor<>())
|
||||
.def_readwrite("forward_speed", &ExtractionWay::forward_speed)
|
||||
.def_readwrite("backward_speed", &ExtractionWay::backward_speed)
|
||||
.property("name", &ExtractionWay::GetName, &ExtractionWay::SetName)
|
||||
.property("ref", &ExtractionWay::GetRef, &ExtractionWay::SetRef)
|
||||
.property("pronunciation",
|
||||
&ExtractionWay::GetPronunciation,
|
||||
&ExtractionWay::SetPronunciation)
|
||||
.property(
|
||||
"destinations", &ExtractionWay::GetDestinations, &ExtractionWay::SetDestinations)
|
||||
.property("turn_lanes_forward",
|
||||
&ExtractionWay::GetTurnLanesForward,
|
||||
&ExtractionWay::SetTurnLanesForward)
|
||||
.property("turn_lanes_backward",
|
||||
&ExtractionWay::GetTurnLanesBackward,
|
||||
&ExtractionWay::SetTurnLanesBackward)
|
||||
.def_readwrite("roundabout", &ExtractionWay::roundabout)
|
||||
.def_readwrite("circular", &ExtractionWay::circular)
|
||||
.def_readwrite("is_startpoint", &ExtractionWay::is_startpoint)
|
||||
.def_readwrite("duration", &ExtractionWay::duration)
|
||||
.def_readwrite("road_classification", &ExtractionWay::road_classification)
|
||||
.property(
|
||||
"forward_mode", &ExtractionWay::get_forward_mode, &ExtractionWay::set_forward_mode)
|
||||
.property("backward_mode",
|
||||
&ExtractionWay::get_backward_mode,
|
||||
&ExtractionWay::set_backward_mode),
|
||||
luabind::class_<osmium::WayNodeList>("WayNodeList").def(luabind::constructor<>()),
|
||||
luabind::class_<osmium::NodeRef>("NodeRef")
|
||||
.def(luabind::constructor<>())
|
||||
// Dear ambitious reader: registering .location() as in:
|
||||
// .def("location", +[](const osmium::NodeRef& nref){ return nref.location(); })
|
||||
// will crash at runtime, since we're not (yet?) using libosnmium's
|
||||
// NodeLocationsForWays cache
|
||||
.def("id", &osmium::NodeRef::ref),
|
||||
luabind::class_<osmium::Way>("Way")
|
||||
.def("get_value_by_key", &osmium::Way::get_value_by_key)
|
||||
.def("get_value_by_key", &get_value_by_key<osmium::Way>)
|
||||
.def("id", &osmium::Way::id)
|
||||
.def("get_nodes", get_nodes_for_way, luabind::return_stl_iterator),
|
||||
luabind::class_<InternalExtractorEdge>("EdgeSource")
|
||||
.def_readonly("source_coordinate", &InternalExtractorEdge::source_coordinate)
|
||||
.def_readwrite("weight_data", &InternalExtractorEdge::weight_data),
|
||||
luabind::class_<InternalExtractorEdge::WeightData>("WeightData")
|
||||
.def_readwrite("speed", &InternalExtractorEdge::WeightData::speed),
|
||||
luabind::class_<ExternalMemoryNode>("EdgeTarget")
|
||||
.property("lon", &lonToDouble<ExternalMemoryNode>)
|
||||
.property("lat", &latToDouble<ExternalMemoryNode>),
|
||||
luabind::class_<util::Coordinate>("Coordinate")
|
||||
.property("lon", &lonToDouble<util::Coordinate>)
|
||||
.property("lat", &latToDouble<util::Coordinate>),
|
||||
luabind::class_<RasterDatum>("RasterDatum")
|
||||
.def_readonly("datum", &RasterDatum::datum)
|
||||
.def("invalid_data", &RasterDatum::get_invalid)];
|
||||
|
||||
luabind::globals(context.state)["properties"] = &context.properties;
|
||||
luabind::globals(context.state)["sources"] = &context.sources;
|
||||
|
||||
if (0 != luaL_dofile(context.state, file_name.c_str()))
|
||||
{
|
||||
luabind::object error_msg(luabind::from_stack(context.state, -1));
|
||||
std::ostringstream error_stream;
|
||||
error_stream << error_msg;
|
||||
throw util::exception("ERROR occurred in profile script:\n" + error_stream.str() +
|
||||
SOURCE_REF);
|
||||
}
|
||||
|
||||
context.has_turn_penalty_function = util::luaFunctionExists(context.state, "turn_function");
|
||||
context.has_node_function = util::luaFunctionExists(context.state, "node_function");
|
||||
context.has_way_function = util::luaFunctionExists(context.state, "way_function");
|
||||
context.has_segment_function = util::luaFunctionExists(context.state, "segment_function");
|
||||
}
|
||||
|
||||
const ProfileProperties &LuaScriptingEnvironment::GetProfileProperties()
|
||||
{
|
||||
return GetLuaContext().properties;
|
||||
}
|
||||
|
||||
LuaScriptingContext &LuaScriptingEnvironment::GetLuaContext()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(init_mutex);
|
||||
bool initialized = false;
|
||||
auto &ref = script_contexts.local(initialized);
|
||||
if (!initialized)
|
||||
{
|
||||
ref = std::make_unique<LuaScriptingContext>();
|
||||
InitContext(*ref);
|
||||
}
|
||||
luabind::set_pcall_callback(&luaErrorCallback);
|
||||
|
||||
return *ref;
|
||||
}
|
||||
|
||||
void LuaScriptingEnvironment::ProcessElements(
|
||||
const std::vector<osmium::memory::Buffer::const_iterator> &osm_elements,
|
||||
const RestrictionParser &restriction_parser,
|
||||
tbb::concurrent_vector<std::pair<std::size_t, ExtractionNode>> &resulting_nodes,
|
||||
tbb::concurrent_vector<std::pair<std::size_t, ExtractionWay>> &resulting_ways,
|
||||
tbb::concurrent_vector<boost::optional<InputRestrictionContainer>> &resulting_restrictions)
|
||||
{
|
||||
// parse OSM entities in parallel, store in resulting vectors
|
||||
tbb::parallel_for(
|
||||
tbb::blocked_range<std::size_t>(0, osm_elements.size()),
|
||||
[&](const tbb::blocked_range<std::size_t> &range) {
|
||||
ExtractionNode result_node;
|
||||
ExtractionWay result_way;
|
||||
auto &local_context = this->GetLuaContext();
|
||||
|
||||
for (auto x = range.begin(), end = range.end(); x != end; ++x)
|
||||
{
|
||||
const auto entity = osm_elements[x];
|
||||
|
||||
switch (entity->type())
|
||||
{
|
||||
case osmium::item_type::node:
|
||||
result_node.clear();
|
||||
if (local_context.has_node_function)
|
||||
{
|
||||
local_context.processNode(static_cast<const osmium::Node &>(*entity),
|
||||
result_node);
|
||||
}
|
||||
resulting_nodes.push_back(std::make_pair(x, std::move(result_node)));
|
||||
break;
|
||||
case osmium::item_type::way:
|
||||
result_way.clear();
|
||||
if (local_context.has_way_function)
|
||||
{
|
||||
local_context.processWay(static_cast<const osmium::Way &>(*entity),
|
||||
result_way);
|
||||
}
|
||||
resulting_ways.push_back(std::make_pair(x, std::move(result_way)));
|
||||
break;
|
||||
case osmium::item_type::relation:
|
||||
resulting_restrictions.push_back(restriction_parser.TryParse(
|
||||
static_cast<const osmium::Relation &>(*entity)));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
std::vector<std::string> LuaScriptingEnvironment::GetNameSuffixList()
|
||||
{
|
||||
auto &context = GetLuaContext();
|
||||
BOOST_ASSERT(context.state != nullptr);
|
||||
if (!util::luaFunctionExists(context.state, "get_name_suffix_list"))
|
||||
return {};
|
||||
|
||||
std::vector<std::string> suffixes_vector;
|
||||
try
|
||||
{
|
||||
// call lua profile to compute turn penalty
|
||||
luabind::call_function<void>(
|
||||
context.state, "get_name_suffix_list", boost::ref(suffixes_vector));
|
||||
}
|
||||
catch (const luabind::error &er)
|
||||
{
|
||||
util::Log(logWARNING) << er.what();
|
||||
}
|
||||
|
||||
return suffixes_vector;
|
||||
}
|
||||
|
||||
std::vector<std::string> LuaScriptingEnvironment::GetRestrictions()
|
||||
{
|
||||
auto &context = GetLuaContext();
|
||||
BOOST_ASSERT(context.state != nullptr);
|
||||
std::vector<std::string> restrictions;
|
||||
if (util::luaFunctionExists(context.state, "get_restrictions"))
|
||||
{
|
||||
// get list of turn restriction exceptions
|
||||
luabind::call_function<void>(context.state, "get_restrictions", boost::ref(restrictions));
|
||||
}
|
||||
return restrictions;
|
||||
}
|
||||
|
||||
void LuaScriptingEnvironment::SetupSources()
|
||||
{
|
||||
auto &context = GetLuaContext();
|
||||
BOOST_ASSERT(context.state != nullptr);
|
||||
if (util::luaFunctionExists(context.state, "source_function"))
|
||||
{
|
||||
luabind::call_function<void>(context.state, "source_function");
|
||||
}
|
||||
}
|
||||
|
||||
int32_t LuaScriptingEnvironment::GetTurnPenalty(const double angle)
|
||||
{
|
||||
auto &context = GetLuaContext();
|
||||
if (context.has_turn_penalty_function)
|
||||
{
|
||||
BOOST_ASSERT(context.state != nullptr);
|
||||
try
|
||||
{
|
||||
// call lua profile to compute turn penalty
|
||||
const double penalty =
|
||||
luabind::call_function<double>(context.state, "turn_function", angle);
|
||||
BOOST_ASSERT(penalty < std::numeric_limits<int32_t>::max());
|
||||
BOOST_ASSERT(penalty > std::numeric_limits<int32_t>::min());
|
||||
return boost::numeric_cast<int32_t>(penalty);
|
||||
}
|
||||
catch (const luabind::error &er)
|
||||
{
|
||||
util::Log(logWARNING) << er.what();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void LuaScriptingEnvironment::ProcessSegment(const osrm::util::Coordinate &source,
|
||||
const osrm::util::Coordinate &target,
|
||||
double distance,
|
||||
InternalExtractorEdge::WeightData &weight)
|
||||
{
|
||||
auto &context = GetLuaContext();
|
||||
if (context.has_segment_function)
|
||||
{
|
||||
BOOST_ASSERT(context.state != nullptr);
|
||||
luabind::call_function<void>(context.state,
|
||||
"segment_function",
|
||||
boost::cref(source),
|
||||
boost::cref(target),
|
||||
distance,
|
||||
boost::ref(weight));
|
||||
}
|
||||
}
|
||||
|
||||
void LuaScriptingContext::processNode(const osmium::Node &node, ExtractionNode &result)
|
||||
{
|
||||
BOOST_ASSERT(state != nullptr);
|
||||
luabind::call_function<void>(state, "node_function", boost::cref(node), boost::ref(result));
|
||||
}
|
||||
|
||||
void LuaScriptingContext::processWay(const osmium::Way &way, ExtractionWay &result)
|
||||
{
|
||||
BOOST_ASSERT(state != nullptr);
|
||||
luabind::call_function<void>(state, "way_function", boost::cref(way), boost::ref(result));
|
||||
}
|
||||
}
|
||||
}
|
171
src/extractor/scripting_environment_sol2.cpp
Normal file
171
src/extractor/scripting_environment_sol2.cpp
Normal file
@ -0,0 +1,171 @@
|
||||
#include "extractor/scripting_environment_sol2.hpp"
|
||||
|
||||
#include "extractor/external_memory_node.hpp"
|
||||
#include "extractor/extraction_helper_functions.hpp"
|
||||
#include "extractor/extraction_node.hpp"
|
||||
#include "extractor/extraction_way.hpp"
|
||||
#include "extractor/internal_extractor_edge.hpp"
|
||||
#include "extractor/profile_properties.hpp"
|
||||
#include "extractor/raster_source.hpp"
|
||||
#include "extractor/restriction_parser.hpp"
|
||||
#include "util/exception.hpp"
|
||||
#include "util/lua_util.hpp"
|
||||
#include "util/simple_logger.hpp"
|
||||
#include "util/typedefs.hpp"
|
||||
|
||||
#include <osmium/osm.hpp>
|
||||
|
||||
#include <tbb/parallel_for.h>
|
||||
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace extractor
|
||||
{
|
||||
|
||||
Sol2ScriptingEnvironment::Sol2ScriptingEnvironment(const std::string &file_name)
|
||||
: file_name(file_name)
|
||||
{
|
||||
util::SimpleLogger().Write() << "Using script " << file_name;
|
||||
}
|
||||
|
||||
void Sol2ScriptingEnvironment::InitContext(Sol2ScriptingContext &context)
|
||||
{
|
||||
context.state.open_libraries();
|
||||
|
||||
// TODO: register things here
|
||||
|
||||
util::luaAddScriptFolderToLoadPath(context.state.lua_state(), file_name.c_str());
|
||||
|
||||
context.has_turn_penalty_function = true;
|
||||
context.has_node_function = true;
|
||||
context.has_way_function = true;
|
||||
context.has_segment_function = true;
|
||||
}
|
||||
|
||||
const ProfileProperties &Sol2ScriptingEnvironment::GetProfileProperties()
|
||||
{
|
||||
return GetSol2Context().properties;
|
||||
}
|
||||
|
||||
Sol2ScriptingContext &Sol2ScriptingEnvironment::GetSol2Context()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(init_mutex);
|
||||
bool initialized = false;
|
||||
auto &ref = script_contexts.local(initialized);
|
||||
if (!initialized)
|
||||
{
|
||||
ref = std::make_unique<Sol2ScriptingContext>();
|
||||
InitContext(*ref);
|
||||
}
|
||||
|
||||
return *ref;
|
||||
}
|
||||
|
||||
void Sol2ScriptingEnvironment::ProcessElements(
|
||||
const std::vector<osmium::memory::Buffer::const_iterator> &osm_elements,
|
||||
const RestrictionParser &restriction_parser,
|
||||
tbb::concurrent_vector<std::pair<std::size_t, ExtractionNode>> &resulting_nodes,
|
||||
tbb::concurrent_vector<std::pair<std::size_t, ExtractionWay>> &resulting_ways,
|
||||
tbb::concurrent_vector<boost::optional<InputRestrictionContainer>> &resulting_restrictions)
|
||||
{
|
||||
// parse OSM entities in parallel, store in resulting vectors
|
||||
tbb::parallel_for(
|
||||
tbb::blocked_range<std::size_t>(0, osm_elements.size()),
|
||||
[&](const tbb::blocked_range<std::size_t> &range) {
|
||||
ExtractionNode result_node;
|
||||
ExtractionWay result_way;
|
||||
auto &local_context = this->GetSol2Context();
|
||||
|
||||
for (auto x = range.begin(), end = range.end(); x != end; ++x)
|
||||
{
|
||||
const auto entity = osm_elements[x];
|
||||
|
||||
switch (entity->type())
|
||||
{
|
||||
case osmium::item_type::node:
|
||||
result_node.clear();
|
||||
if (local_context.has_node_function)
|
||||
{
|
||||
local_context.processNode(static_cast<const osmium::Node &>(*entity),
|
||||
result_node);
|
||||
}
|
||||
resulting_nodes.push_back(std::make_pair(x, std::move(result_node)));
|
||||
break;
|
||||
case osmium::item_type::way:
|
||||
result_way.clear();
|
||||
if (local_context.has_way_function)
|
||||
{
|
||||
local_context.processWay(static_cast<const osmium::Way &>(*entity),
|
||||
result_way);
|
||||
}
|
||||
resulting_ways.push_back(std::make_pair(x, std::move(result_way)));
|
||||
break;
|
||||
case osmium::item_type::relation:
|
||||
resulting_restrictions.push_back(restriction_parser.TryParse(
|
||||
static_cast<const osmium::Relation &>(*entity)));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
std::vector<std::string> Sol2ScriptingEnvironment::GetNameSuffixList()
|
||||
{
|
||||
auto &context = GetSol2Context();
|
||||
BOOST_ASSERT(context.state != nullptr);
|
||||
std::vector<std::string> suffixes_vector;
|
||||
// TODO: fill if get_suff. function exists
|
||||
return suffixes_vector;
|
||||
}
|
||||
|
||||
std::vector<std::string> Sol2ScriptingEnvironment::GetRestrictions()
|
||||
{
|
||||
auto &context = GetSol2Context();
|
||||
BOOST_ASSERT(context.state != nullptr);
|
||||
std::vector<std::string> restrictions;
|
||||
// TODO: fill if get_restrictoins is available
|
||||
return restrictions;
|
||||
}
|
||||
|
||||
void Sol2ScriptingEnvironment::SetupSources()
|
||||
{
|
||||
auto &context = GetSol2Context();
|
||||
BOOST_ASSERT(context.state != nullptr);
|
||||
|
||||
// TODO: call source_function if exists
|
||||
}
|
||||
|
||||
int32_t Sol2ScriptingEnvironment::GetTurnPenalty(const double angle)
|
||||
{
|
||||
auto &context = GetSol2Context();
|
||||
// turn_function(angle) if function exists
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Sol2ScriptingEnvironment::ProcessSegment(const osrm::util::Coordinate &source,
|
||||
const osrm::util::Coordinate &target,
|
||||
double distance,
|
||||
InternalExtractorEdge::WeightData &weight)
|
||||
{
|
||||
auto &context = GetSol2Context();
|
||||
// TODO: call segment_function if exists
|
||||
}
|
||||
|
||||
void Sol2ScriptingContext::processNode(const osmium::Node &node, ExtractionNode &result)
|
||||
{
|
||||
BOOST_ASSERT(state != nullptr);
|
||||
// TODO: node_function
|
||||
}
|
||||
|
||||
void Sol2ScriptingContext::processWay(const osmium::Way &way, ExtractionWay &result)
|
||||
{
|
||||
BOOST_ASSERT(state != nullptr);
|
||||
// TODO: way_function
|
||||
}
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
#include "extractor/extractor.hpp"
|
||||
#include "extractor/extractor_config.hpp"
|
||||
#include "extractor/scripting_environment_lua.hpp"
|
||||
#include "extractor/scripting_environment_sol2.hpp"
|
||||
#include "util/log.hpp"
|
||||
#include "util/version.hpp"
|
||||
|
||||
@ -153,7 +153,7 @@ int main(int argc, char *argv[]) try
|
||||
}
|
||||
|
||||
// setup scripting environment
|
||||
extractor::LuaScriptingEnvironment scripting_environment(
|
||||
extractor::Sol2ScriptingEnvironment scripting_environment(
|
||||
extractor_config.profile_path.string().c_str());
|
||||
auto exitcode = extractor::Extractor(extractor_config).run(scripting_environment);
|
||||
|
||||
@ -166,4 +166,4 @@ catch (const std::bad_alloc &e)
|
||||
util::Log(logERROR) << "[exception] " << e.what();
|
||||
util::Log(logERROR) << "Please provide more memory or consider using a larger swapfile";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
12459
third_party/sol2/sol.hpp
vendored
Normal file
12459
third_party/sol2/sol.hpp
vendored
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user