Implement raster source feature to read data from third-party sources, to be used in lua profiles.
* Adds a data structure, RasterSource, to store parsed + queryable data * Adds bindings for that and relevant data structures as well as source_function and segment_function * Adds relevant unit tests and cucumber tests * Bring-your-own-data feature
This commit is contained in:
@@ -36,10 +36,14 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#include "../util/simple_logger.hpp"
|
||||
#include "../util/timing_util.hpp"
|
||||
#include "../util/fingerprint.hpp"
|
||||
#include "../util/lua_util.hpp"
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/filesystem/fstream.hpp>
|
||||
#include <boost/ref.hpp>
|
||||
|
||||
#include <luabind/luabind.hpp>
|
||||
|
||||
#include <stxxl/sort>
|
||||
|
||||
@@ -76,7 +80,8 @@ ExtractionContainers::~ExtractionContainers()
|
||||
*/
|
||||
void ExtractionContainers::PrepareData(const std::string &output_file_name,
|
||||
const std::string &restrictions_file_name,
|
||||
const std::string &name_file_name)
|
||||
const std::string &name_file_name,
|
||||
lua_State *segment_state)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -87,7 +92,7 @@ void ExtractionContainers::PrepareData(const std::string &output_file_name,
|
||||
|
||||
PrepareNodes();
|
||||
WriteNodes(file_out_stream);
|
||||
PrepareEdges();
|
||||
PrepareEdges(segment_state);
|
||||
WriteEdges(file_out_stream);
|
||||
|
||||
file_out_stream.close();
|
||||
@@ -168,7 +173,7 @@ void ExtractionContainers::PrepareNodes()
|
||||
std::cout << "ok, after " << TIMER_SEC(sorting_nodes) << "s" << std::endl;
|
||||
}
|
||||
|
||||
void ExtractionContainers::PrepareEdges()
|
||||
void ExtractionContainers::PrepareEdges(lua_State *segment_state)
|
||||
{
|
||||
// Sort edges by start.
|
||||
std::cout << "[extractor] Sorting edges by start ... " << std::flush;
|
||||
@@ -264,6 +269,16 @@ void ExtractionContainers::PrepareEdges()
|
||||
edge_iterator->source_coordinate.lat, edge_iterator->source_coordinate.lon,
|
||||
node_iterator->lat, node_iterator->lon);
|
||||
|
||||
if (lua_function_exists(segment_state, "segment_function"))
|
||||
{
|
||||
luabind::call_function<void>(
|
||||
segment_state, "segment_function",
|
||||
boost::cref(edge_iterator->source_coordinate),
|
||||
boost::cref(*node_iterator),
|
||||
distance,
|
||||
boost::ref(edge_iterator->weight_data));
|
||||
}
|
||||
|
||||
const double weight = [distance](const InternalExtractorEdge::WeightData& data) {
|
||||
switch (data.type)
|
||||
{
|
||||
|
||||
@@ -30,6 +30,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include "internal_extractor_edge.hpp"
|
||||
#include "first_and_last_segment_of_way.hpp"
|
||||
#include "scripting_environment.hpp"
|
||||
#include "../data_structures/external_memory_node.hpp"
|
||||
#include "../data_structures/restriction.hpp"
|
||||
|
||||
@@ -53,7 +54,7 @@ class ExtractionContainers
|
||||
#endif
|
||||
void PrepareNodes();
|
||||
void PrepareRestrictions();
|
||||
void PrepareEdges();
|
||||
void PrepareEdges(lua_State *segment_state);
|
||||
|
||||
void WriteNodes(std::ofstream& file_out_stream) const;
|
||||
void WriteRestrictions(const std::string& restrictions_file_name) const;
|
||||
@@ -81,7 +82,8 @@ class ExtractionContainers
|
||||
|
||||
void PrepareData(const std::string &output_file_name,
|
||||
const std::string &restrictions_file_name,
|
||||
const std::string &names_file_name);
|
||||
const std::string &names_file_name,
|
||||
lua_State *segment_state);
|
||||
};
|
||||
|
||||
#endif /* EXTRACTION_CONTAINERS_HPP */
|
||||
|
||||
+16
-1
@@ -34,10 +34,12 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#include "restriction_parser.hpp"
|
||||
#include "scripting_environment.hpp"
|
||||
|
||||
#include "../data_structures/raster_source.hpp"
|
||||
#include "../util/git_sha.hpp"
|
||||
#include "../util/make_unique.hpp"
|
||||
#include "../util/simple_logger.hpp"
|
||||
#include "../util/timing_util.hpp"
|
||||
#include "../util/lua_util.hpp"
|
||||
|
||||
#include "../typedefs.h"
|
||||
|
||||
@@ -116,6 +118,17 @@ int extractor::run()
|
||||
SimpleLogger().Write() << "Parsing in progress..";
|
||||
TIMER_START(parsing);
|
||||
|
||||
lua_State *segment_state = scripting_environment.get_lua_state();
|
||||
|
||||
if (lua_function_exists(segment_state, "source_function"))
|
||||
{
|
||||
// bind a single instance of SourceContainer class to relevant lua state
|
||||
SourceContainer sources;
|
||||
luabind::globals(segment_state)["sources"] = sources;
|
||||
|
||||
luabind::call_function<void>(segment_state, "source_function");
|
||||
}
|
||||
|
||||
std::string generator = header.get("generator");
|
||||
if (generator.empty())
|
||||
{
|
||||
@@ -238,7 +251,9 @@ int extractor::run()
|
||||
|
||||
extraction_containers.PrepareData(config.output_file_name,
|
||||
config.restriction_file_name,
|
||||
config.names_file_name);
|
||||
config.names_file_name,
|
||||
segment_state);
|
||||
|
||||
TIMER_STOP(extracting);
|
||||
SimpleLogger().Write() << "extraction finished after " << TIMER_SEC(extracting) << "s";
|
||||
SimpleLogger().Write() << "To prepare the data for routing, run: "
|
||||
|
||||
@@ -30,13 +30,16 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#include "extraction_helper_functions.hpp"
|
||||
#include "extraction_node.hpp"
|
||||
#include "extraction_way.hpp"
|
||||
#include "internal_extractor_edge.hpp"
|
||||
#include "../data_structures/external_memory_node.hpp"
|
||||
#include "../data_structures/raster_source.hpp"
|
||||
#include "../util/lua_util.hpp"
|
||||
#include "../util/osrm_exception.hpp"
|
||||
#include "../util/simple_logger.hpp"
|
||||
#include "../typedefs.h"
|
||||
|
||||
#include <luabind/tag_function.hpp>
|
||||
#include <luabind/operator.hpp>
|
||||
|
||||
#include <osmium/osm.hpp>
|
||||
|
||||
@@ -80,6 +83,13 @@ void ScriptingEnvironment::init_lua_state(lua_State *lua_state)
|
||||
luabind::def("print", LUA_print<std::string>),
|
||||
luabind::def("durationIsValid", durationIsValid),
|
||||
luabind::def("parseDuration", parseDuration),
|
||||
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_<std::vector<std::string>>("vector")
|
||||
.def("Add", static_cast<void (std::vector<std::string>::*)(const std::string &)>(
|
||||
@@ -121,7 +131,21 @@ void ScriptingEnvironment::init_lua_state(lua_State *lua_state)
|
||||
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("id", &osmium::Way::id),
|
||||
luabind::class_<InternalExtractorEdge>("EdgeSource")
|
||||
.property("source_coordinate", &InternalExtractorEdge::source_coordinate)
|
||||
.property("weight_data", &InternalExtractorEdge::weight_data),
|
||||
luabind::class_<InternalExtractorEdge::WeightData>("WeightData")
|
||||
.def_readwrite("speed", &InternalExtractorEdge::WeightData::speed),
|
||||
luabind::class_<ExternalMemoryNode>("EdgeTarget")
|
||||
.property("lat", &ExternalMemoryNode::lat)
|
||||
.property("lon", &ExternalMemoryNode::lon),
|
||||
luabind::class_<FixedPointCoordinate>("Coordinate")
|
||||
.property("lat", &FixedPointCoordinate::lat)
|
||||
.property("lon", &FixedPointCoordinate::lon),
|
||||
luabind::class_<RasterDatum>("RasterDatum")
|
||||
.property("datum", &RasterDatum::datum)
|
||||
.def("invalid_data", &RasterDatum::get_invalid)
|
||||
];
|
||||
|
||||
if (0 != luaL_dofile(lua_state, file_name.c_str()))
|
||||
|
||||
Reference in New Issue
Block a user