Formats all the files we touch..

This commit is contained in:
Daniel J. Hofmann 2016-02-26 12:29:57 +01:00 committed by Patrick Niklaus
parent 8126793b18
commit aeee565115
15 changed files with 228 additions and 217 deletions

View File

@ -76,8 +76,8 @@ template <class EdgeDataT> class BaseDataFacade
virtual extractor::TravelMode GetTravelModeForEdgeID(const unsigned id) const = 0;
virtual std::vector<RTreeLeaf> GetEdgesInBox(const util::FixedPointCoordinate & south_west,
const util::FixedPointCoordinate & north_east) = 0;
virtual std::vector<RTreeLeaf> GetEdgesInBox(const util::FixedPointCoordinate &south_west,
const util::FixedPointCoordinate &north_east) = 0;
virtual std::vector<PhantomNodeWithDistance>
NearestPhantomNodesInRange(const util::FixedPointCoordinate input_coordinate,

View File

@ -358,17 +358,17 @@ template <class EdgeDataT> class InternalDataFacade final : public BaseDataFacad
return m_travel_mode_list.at(id);
}
std::vector<RTreeLeaf> GetEdgesInBox(const util::FixedPointCoordinate & south_west,
const util::FixedPointCoordinate & north_east)
override final
std::vector<RTreeLeaf>
GetEdgesInBox(const util::FixedPointCoordinate &south_west,
const util::FixedPointCoordinate &north_east) override final
{
if (!m_static_rtree.get())
{
LoadRTree();
BOOST_ASSERT(m_geospatial_query.get());
}
util::RectangleInt2D bbox = {south_west.lon, north_east.lon,
south_west.lat, north_east.lat};
util::RectangleInt2D bbox = {
south_west.lon, north_east.lon, south_west.lat, north_east.lat};
return m_geospatial_query->Search(bbox);
}

View File

@ -408,17 +408,17 @@ template <class EdgeDataT> class SharedDataFacade final : public BaseDataFacade<
return m_travel_mode_list.at(id);
}
std::vector<RTreeLeaf> GetEdgesInBox(const util::FixedPointCoordinate & south_west,
const util::FixedPointCoordinate & north_east)
override final
std::vector<RTreeLeaf>
GetEdgesInBox(const util::FixedPointCoordinate &south_west,
const util::FixedPointCoordinate &north_east) override final
{
if (!m_static_rtree.get() || CURRENT_TIMESTAMP != m_static_rtree->first)
{
LoadRTree();
BOOST_ASSERT(m_geospatial_query.get());
}
util::RectangleInt2D bbox = {south_west.lon, north_east.lon,
south_west.lat, north_east.lat};
util::RectangleInt2D bbox = {
south_west.lon, north_east.lon, south_west.lat, north_east.lat};
return m_geospatial_query->Search(bbox);
}

View File

@ -33,14 +33,11 @@ template <typename RTreeT> class GeospatialQuery
{
}
std::vector<EdgeData>
Search(const util::RectangleInt2D & bbox)
std::vector<EdgeData> Search(const util::RectangleInt2D &bbox)
{
return rtree.SearchInBox(bbox);
}
// Returns nearest PhantomNodes in the given bearing range within max_distance.
// Does not filter by small/big component!
std::vector<PhantomNodeWithDistance>

View File

@ -38,24 +38,25 @@ static const double M_PIby360 = M_PI / 360.0;
static const double MAXEXTENTby180 = MAXEXTENT / 180.0;
static const double MAX_LATITUDE = R2D * (2.0 * std::atan(std::exp(180.0 * D2R)) - M_PI_by2);
// from mapnik-vector-tile
namespace detail_pbf {
namespace detail_pbf
{
inline unsigned encode_length(unsigned len)
{
return (len << 3u) | 2u;
}
inline unsigned encode_length(unsigned len) { return (len << 3u) | 2u; }
}
// Converts a regular WSG84 lon/lat pair into
// a mercator coordinate
inline void lonlat2merc(double & x, double & y)
inline void lonlat2merc(double &x, double &y)
{
if (x > 180) x = 180;
else if (x < -180) x = -180;
if (y > MAX_LATITUDE) y = MAX_LATITUDE;
else if (y < -MAX_LATITUDE) y = -MAX_LATITUDE;
if (x > 180)
x = 180;
else if (x < -180)
x = -180;
if (y > MAX_LATITUDE)
y = MAX_LATITUDE;
else if (y < -MAX_LATITUDE)
y = -MAX_LATITUDE;
x = x * MAXEXTENTby180;
y = std::log(std::tan((90 + y) * M_PIby360)) * R2D;
y = y * MAXEXTENTby180;
@ -65,97 +66,75 @@ inline void lonlat2merc(double & x, double & y)
const static double tile_size_ = 256.0;
//
void from_pixels(double shift, double & x, double & y)
void from_pixels(double shift, double &x, double &y)
{
double b = shift/2.0;
x = (x - b)/(shift/360.0);
double g = (y - b)/-(shift/(2 * M_PI));
double b = shift / 2.0;
x = (x - b) / (shift / 360.0);
double g = (y - b) / -(shift / (2 * M_PI));
y = R2D * (2.0 * std::atan(std::exp(g)) - M_PI_by2);
}
// Converts a WMS tile coordinate (z,x,y) into a mercator bounding box
void xyz2mercator(int x,
int y,
int z,
double & minx,
double & miny,
double & maxx,
double & maxy)
void xyz2mercator(int x, int y, int z, double &minx, double &miny, double &maxx, double &maxy)
{
minx = x * tile_size_;
miny = (y + 1.0) * tile_size_;
maxx = (x + 1.0) * tile_size_;
maxy = y * tile_size_;
double shift = std::pow(2.0,z) * tile_size_;
from_pixels(shift,minx,miny);
from_pixels(shift,maxx,maxy);
lonlat2merc(minx,miny);
lonlat2merc(maxx,maxy);
double shift = std::pow(2.0, z) * tile_size_;
from_pixels(shift, minx, miny);
from_pixels(shift, maxx, maxy);
lonlat2merc(minx, miny);
lonlat2merc(maxx, maxy);
}
// Converts a WMS tile coordinate (z,x,y) into a wsg84 bounding box
void xyz2wsg84(int x,
int y,
int z,
double & minx,
double & miny,
double & maxx,
double & maxy)
void xyz2wsg84(int x, int y, int z, double &minx, double &miny, double &maxx, double &maxy)
{
minx = x * tile_size_;
miny = (y + 1.0) * tile_size_;
maxx = (x + 1.0) * tile_size_;
maxy = y * tile_size_;
double shift = std::pow(2.0,z) * tile_size_;
from_pixels(shift,minx,miny);
from_pixels(shift,maxx,maxy);
double shift = std::pow(2.0, z) * tile_size_;
from_pixels(shift, minx, miny);
from_pixels(shift, maxx, maxy);
}
// emulates mapbox::box2d, just a simple container for
// a box
class bbox {
public:
class bbox
{
public:
double minx;
double miny;
double maxx;
double maxy;
bbox(double _minx,double _miny,double _maxx,double _maxy) :
minx(_minx),
miny(_miny),
maxx(_maxx),
maxy(_maxy) { }
double width() const {
return maxx - minx;
bbox(double _minx, double _miny, double _maxx, double _maxy)
: minx(_minx), miny(_miny), maxx(_maxx), maxy(_maxy)
{
}
double height() const {
return maxy - miny;
}
double width() const { return maxx - minx; }
double height() const { return maxy - miny; }
};
// Simple container class for WSG84 coordinates
class point_type_d {
public:
class point_type_d
{
public:
double x;
double y;
point_type_d(double _x, double _y) :
x(_x),
y(_y) {
}
point_type_d(double _x, double _y) : x(_x), y(_y) {}
};
// Simple container for integer coordinates (i.e. pixel coords)
class point_type_i {
public:
class point_type_i
{
public:
std::int64_t x;
std::int64_t y;
point_type_i(std::int64_t _x, std::int64_t _y) :
x(_x),
y(_y) {
}
point_type_i(std::int64_t _x, std::int64_t _y) : x(_x), y(_y) {}
};
using line_type = std::vector<point_type_i>;
@ -164,11 +143,12 @@ using line_typed = std::vector<point_type_d>;
// from mapnik-vector-tile
// Encodes a linestring using protobuf zigzag encoding
inline bool encode_linestring(line_type line,
protozero::packed_field_uint32 & geometry,
int32_t & start_x,
int32_t & start_y) {
protozero::packed_field_uint32 &geometry,
int32_t &start_x,
int32_t &start_y)
{
std::size_t line_size = line.size();
//line_size -= detail_pbf::repeated_point_count(line);
// line_size -= detail_pbf::repeated_point_count(line);
if (line_size < 2)
{
return false;
@ -215,10 +195,13 @@ template <class DataFacadeT> class TilePlugin final : public BasePlugin
double min_lon, min_lat, max_lon, max_lat;
// Convert the z,x,y mercator tile coordinates into WSG84 lon/lat values
xyz2wsg84(route_parameters.x, route_parameters.y, route_parameters.z, min_lon, min_lat, max_lon, max_lat);
xyz2wsg84(route_parameters.x, route_parameters.y, route_parameters.z, min_lon, min_lat,
max_lon, max_lat);
FixedPointCoordinate southwest = { static_cast<int32_t>(min_lat * COORDINATE_PRECISION), static_cast<int32_t>(min_lon * COORDINATE_PRECISION) };
FixedPointCoordinate northeast = { static_cast<int32_t>(max_lat * COORDINATE_PRECISION), static_cast<int32_t>(max_lon * COORDINATE_PRECISION) };
FixedPointCoordinate southwest = {static_cast<int32_t>(min_lat * COORDINATE_PRECISION),
static_cast<int32_t>(min_lon * COORDINATE_PRECISION)};
FixedPointCoordinate northeast = {static_cast<int32_t>(max_lat * COORDINATE_PRECISION),
static_cast<int32_t>(max_lon * COORDINATE_PRECISION)};
// Fetch all the segments that are in our bounding box.
// This hits the OSRM StaticRTree
@ -227,7 +210,8 @@ template <class DataFacadeT> class TilePlugin final : public BasePlugin
// TODO: extract speed values for compressed and uncompressed geometries
// Convert tile coordinates into mercator coordinates
xyz2mercator(route_parameters.x, route_parameters.y, route_parameters.z, min_lon, min_lat, max_lon, max_lat);
xyz2mercator(route_parameters.x, route_parameters.y, route_parameters.z, min_lon, min_lat,
max_lon, max_lat);
bbox tile_bbox(min_lon, min_lat, max_lon, max_lat);
// Protobuf serialized blocks when objects go out of scope, hence
@ -236,58 +220,71 @@ template <class DataFacadeT> class TilePlugin final : public BasePlugin
protozero::pbf_writer tile_writer(buffer);
{
// Add a layer object to the PBF stream. 3=='layer' from the vector tile spec (2.1)
protozero::pbf_writer layer_writer(tile_writer,3);
protozero::pbf_writer layer_writer(tile_writer, 3);
// TODO: don't write a layer if there are no features
// Field 15 is the "version field, and it's a uint32
layer_writer.add_uint32(15,2); // version
layer_writer.add_uint32(15, 2); // version
// Field 1 is the "layer name" field, it's a string
layer_writer.add_string(1,"speeds"); // name
layer_writer.add_string(1, "speeds"); // name
// Field 5 is the tile extent. It's a uint32 and should be set to 4096
// for normal vector tiles.
layer_writer.add_uint32(5,4096); // extent
layer_writer.add_uint32(5, 4096); // extent
// Begin the layer features block
{
// Each feature gets a unique id, starting at 1
unsigned id = 1;
for (const auto & edge : edges)
for (const auto &edge : edges)
{
// Get coordinates for start/end nodes of segmet (NodeIDs u and v)
const auto a = facade->GetCoordinateOfNode(edge.u);
const auto b = facade->GetCoordinateOfNode(edge.v);
// Calculate the length in meters
double length = osrm::util::coordinate_calculation::haversineDistance( a.lon, a.lat, b.lon, b.lat );
double length = osrm::util::coordinate_calculation::haversineDistance(
a.lon, a.lat, b.lon, b.lat);
// If this is a valid forward edge, go ahead and add it to the tile
if (edge.forward_weight != 0 && edge.forward_edge_based_node_id != SPECIAL_NODEID) {
if (edge.forward_weight != 0 &&
edge.forward_edge_based_node_id != SPECIAL_NODEID)
{
std::int32_t start_x = 0;
std::int32_t start_y = 0;
line_typed geo_line;
geo_line.emplace_back(a.lon / COORDINATE_PRECISION, a.lat / COORDINATE_PRECISION);
geo_line.emplace_back(b.lon / COORDINATE_PRECISION, b.lat / COORDINATE_PRECISION);
geo_line.emplace_back(a.lon / COORDINATE_PRECISION,
a.lat / COORDINATE_PRECISION);
geo_line.emplace_back(b.lon / COORDINATE_PRECISION,
b.lat / COORDINATE_PRECISION);
// Calculate the speed for this line
uint32_t speed = static_cast<uint32_t>(round(length / edge.forward_weight * 10 *3.6));
uint32_t speed =
static_cast<uint32_t>(round(length / edge.forward_weight * 10 * 3.6));
line_type tile_line;
for (auto const & pt : geo_line) {
for (auto const &pt : geo_line)
{
double px_merc = pt.x;
double py_merc = pt.y;
lonlat2merc(px_merc,py_merc);
lonlat2merc(px_merc, py_merc);
// convert lon/lat to tile coordinates
const auto px = std::round(((px_merc - tile_bbox.minx) * tile_extent/16.0 / tile_bbox.width())*tile_extent/256.0);
const auto py = std::round(((tile_bbox.maxy - py_merc) * tile_extent/16.0 / tile_bbox.height())*tile_extent/256.0);
tile_line.emplace_back(px,py);
const auto px = std::round(((px_merc - tile_bbox.minx) * tile_extent /
16.0 / tile_bbox.width()) *
tile_extent / 256.0);
const auto py = std::round(((tile_bbox.maxy - py_merc) * tile_extent /
16.0 / tile_bbox.height()) *
tile_extent / 256.0);
tile_line.emplace_back(px, py);
}
// Here, we save the two attributes for our feature: the speed and the is_small
// boolean. We onl serve up speeds from 0-139, so all we do is save the first
protozero::pbf_writer feature_writer(layer_writer,2);
// Here, we save the two attributes for our feature: the speed and the
// is_small
// boolean. We onl serve up speeds from 0-139, so all we do is save the
// first
protozero::pbf_writer feature_writer(layer_writer, 2);
// Field 3 is the "geometry type" field. Value 2 is "line"
feature_writer.add_enum(3,2); // geometry type
feature_writer.add_enum(3, 2); // geometry type
// Field 1 for the feature is the "id" field.
feature_writer.add_uint64(1,id++); // id
feature_writer.add_uint64(1, id++); // id
{
// When adding attributes to a feature, we have to write
// pairs of numbers. The first value is the index in the
@ -299,82 +296,95 @@ template <class DataFacadeT> class TilePlugin final : public BasePlugin
protozero::packed_field_uint32 field(feature_writer, 2);
field.add_element(0); // "speed" tag key offset
field.add_element(std::min(speed, 127u)); // save the speed value, capped at 127
field.add_element(1); // "is_small" tag key offset
field.add_element(
std::min(speed, 127u)); // save the speed value, capped at 127
field.add_element(1); // "is_small" tag key offset
field.add_element(edge.component.is_tiny ? 0 : 1); // is_small feature
}
{
// Encode the geometry for the feature
protozero::packed_field_uint32 geometry(feature_writer,4);
encode_linestring(tile_line,geometry,start_x,start_y);
protozero::packed_field_uint32 geometry(feature_writer, 4);
encode_linestring(tile_line, geometry, start_x, start_y);
}
}
// Repeat the above for the coordinates reversed and using the `reverse` properties
if (edge.reverse_weight != 0 && edge.reverse_edge_based_node_id != SPECIAL_NODEID) {
// Repeat the above for the coordinates reversed and using the `reverse`
// properties
if (edge.reverse_weight != 0 &&
edge.reverse_edge_based_node_id != SPECIAL_NODEID)
{
std::int32_t start_x = 0;
std::int32_t start_y = 0;
line_typed geo_line;
geo_line.emplace_back(b.lon / COORDINATE_PRECISION, b.lat / COORDINATE_PRECISION);
geo_line.emplace_back(a.lon / COORDINATE_PRECISION, a.lat / COORDINATE_PRECISION);
geo_line.emplace_back(b.lon / COORDINATE_PRECISION,
b.lat / COORDINATE_PRECISION);
geo_line.emplace_back(a.lon / COORDINATE_PRECISION,
a.lat / COORDINATE_PRECISION);
uint32_t speed = static_cast<uint32_t>(round(length / edge.forward_weight * 10 *3.6));
uint32_t speed =
static_cast<uint32_t>(round(length / edge.forward_weight * 10 * 3.6));
line_type tile_line;
for (auto const & pt : geo_line) {
for (auto const &pt : geo_line)
{
double px_merc = pt.x;
double py_merc = pt.y;
lonlat2merc(px_merc,py_merc);
lonlat2merc(px_merc, py_merc);
// convert to integer tile coordinat
const auto px = std::round(((px_merc - tile_bbox.minx) * tile_extent/16.0 / tile_bbox.width())*tile_extent/256.0);
const auto py = std::round(((tile_bbox.maxy - py_merc) * tile_extent/16.0 / tile_bbox.height())*tile_extent/256.0);
tile_line.emplace_back(px,py);
const auto px = std::round(((px_merc - tile_bbox.minx) * tile_extent /
16.0 / tile_bbox.width()) *
tile_extent / 256.0);
const auto py = std::round(((tile_bbox.maxy - py_merc) * tile_extent /
16.0 / tile_bbox.height()) *
tile_extent / 256.0);
tile_line.emplace_back(px, py);
}
protozero::pbf_writer feature_writer(layer_writer,2);
feature_writer.add_enum(3,2); // geometry type
feature_writer.add_uint64(1,id++); // id
protozero::pbf_writer feature_writer(layer_writer, 2);
feature_writer.add_enum(3, 2); // geometry type
feature_writer.add_uint64(1, id++); // id
{
protozero::packed_field_uint32 field(feature_writer, 2);
field.add_element(0); // "speed" tag key offset
field.add_element(std::min(speed, 127u)); // save the speed value, capped at 127
field.add_element(1); // "is_small" tag key offset
field.add_element(
std::min(speed, 127u)); // save the speed value, capped at 127
field.add_element(1); // "is_small" tag key offset
field.add_element(edge.component.is_tiny ? 0 : 1); // is_small feature
}
{
protozero::packed_field_uint32 geometry(feature_writer,4);
encode_linestring(tile_line,geometry,start_x,start_y);
protozero::packed_field_uint32 geometry(feature_writer, 4);
encode_linestring(tile_line, geometry, start_x, start_y);
}
}
}
}
// Field id 3 is the "keys" attribute
// We need two "key" fields, these are referred to with 0 and 1 (their array indexes)
// earlier
layer_writer.add_string(3,"speed");
layer_writer.add_string(3,"is_small");
layer_writer.add_string(3, "speed");
layer_writer.add_string(3, "is_small");
// Now, we write out the possible speed value arrays and possible is_tiny
// values. Field type 4 is the "values" field. It's a variable type field,
// so requires a two-step write (create the field, then write its value)
for (size_t i=0; i<128; i++) {
for (size_t i = 0; i < 128; i++)
{
{
// Writing field type 4 == variant type
protozero::pbf_writer values_writer(layer_writer,4);
protozero::pbf_writer values_writer(layer_writer, 4);
// Attribute value 5 == uin64 type
values_writer.add_uint64(5, i);
}
}
{
protozero::pbf_writer values_writer(layer_writer,4);
protozero::pbf_writer values_writer(layer_writer, 4);
// Attribute value 7 == bool type
values_writer.add_bool(7, true);
}
{
protozero::pbf_writer values_writer(layer_writer,4);
protozero::pbf_writer values_writer(layer_writer, 4);
// Attribute value 7 == bool type
values_writer.add_bool(7, false);
}

View File

@ -110,10 +110,12 @@ template <typename Iterator, class HandlerT> struct APIGrammar : qi::grammar<Ite
locs = (-qi::lit('&')) >> qi::lit("locs") >> '=' >>
stringforPolyline[boost::bind(&HandlerT::SetCoordinatesFromGeometry, handler, ::_1)];
z = (-qi::lit('&')) >> qi::lit("tz") >> '=' >> qi::int_[boost::bind<void>(&HandlerT::SetZ, handler, ::_1)];
x = (-qi::lit('&')) >> qi::lit("tx") >> '=' >> qi::int_[boost::bind<void>(&HandlerT::SetX, handler, ::_1)];
y = (-qi::lit('&')) >> qi::lit("ty") >> '=' >> qi::int_[boost::bind<void>(&HandlerT::SetY, handler, ::_1)];
z = (-qi::lit('&')) >> qi::lit("tz") >> '=' >>
qi::int_[boost::bind<void>(&HandlerT::SetZ, handler, ::_1)];
x = (-qi::lit('&')) >> qi::lit("tx") >> '=' >>
qi::int_[boost::bind<void>(&HandlerT::SetX, handler, ::_1)];
y = (-qi::lit('&')) >> qi::lit("ty") >> '=' >>
qi::int_[boost::bind<void>(&HandlerT::SetY, handler, ::_1)];
string = +(qi::char_("a-zA-Z"));
stringwithDot = +(qi::char_("a-zA-Z0-9_.-"));

View File

@ -26,9 +26,10 @@ struct RectangleInt2D
{
}
RectangleInt2D(int32_t min_lon_, int32_t max_lon_, int32_t min_lat_, int32_t max_lat_) :
min_lon(min_lon_), max_lon(max_lon_),
min_lat(min_lat_), max_lat(max_lat_) {}
RectangleInt2D(int32_t min_lon_, int32_t max_lon_, int32_t min_lat_, int32_t max_lat_)
: min_lon(min_lon_), max_lon(max_lon_), min_lat(min_lat_), max_lat(max_lat_)
{
}
int32_t min_lon, max_lon;
int32_t min_lat, max_lat;
@ -59,8 +60,8 @@ struct RectangleInt2D
{
// Standard box intersection test - check if boxes *don't* overlap,
// and return the negative of that
return ! (max_lon < other.min_lon || min_lon > other.max_lon
|| max_lat < other.min_lat || min_lat > other.max_lat);
return !(max_lon < other.min_lon || min_lon > other.max_lon || max_lat < other.min_lat ||
min_lat > other.max_lat);
}
double GetMinDist(const FixedPointCoordinate location) const

View File

@ -322,7 +322,7 @@ class StaticRTree
}
/* Returns all features inside the bounding box */
std::vector<EdgeDataT> SearchInBox(const Rectangle & search_rectangle)
std::vector<EdgeDataT> SearchInBox(const Rectangle &search_rectangle)
{
std::vector<EdgeDataT> results;
@ -345,11 +345,14 @@ class StaticRTree
{
const auto &current_edge = current_leaf_node.objects[i];
Rectangle bbox =
{std::min((*m_coordinate_list)[current_edge.u].lon, (*m_coordinate_list)[current_edge.v].lon),
std::max((*m_coordinate_list)[current_edge.u].lon, (*m_coordinate_list)[current_edge.v].lon),
std::min((*m_coordinate_list)[current_edge.u].lat, (*m_coordinate_list)[current_edge.v].lat),
std::max((*m_coordinate_list)[current_edge.u].lat, (*m_coordinate_list)[current_edge.v].lat)};
Rectangle bbox = {std::min((*m_coordinate_list)[current_edge.u].lon,
(*m_coordinate_list)[current_edge.v].lon),
std::max((*m_coordinate_list)[current_edge.u].lon,
(*m_coordinate_list)[current_edge.v].lon),
std::min((*m_coordinate_list)[current_edge.u].lat,
(*m_coordinate_list)[current_edge.v].lat),
std::max((*m_coordinate_list)[current_edge.u].lat,
(*m_coordinate_list)[current_edge.v].lat)};
if (bbox.Intersects(search_rectangle))
{

View File

@ -291,7 +291,7 @@ void Contractor::WriteCoreNodeMarker(std::vector<bool> &&in_is_core_node) const
std::size_t
Contractor::WriteContractedGraph(unsigned max_node_id,
const util::DeallocatingVector<QueryEdge> &contracted_edge_list)
const util::DeallocatingVector<QueryEdge> &contracted_edge_list)
{
// Sorting contracted edges in a way that the static query graph can read some in in-place.
tbb::parallel_sort(contracted_edge_list.begin(), contracted_edge_list.end());
@ -423,7 +423,7 @@ void Contractor::ContractGraph(
node_levels.swap(inout_node_levels);
GraphContractor graph_contractor(max_edge_id + 1, edge_based_edge_list, std::move(node_levels),
std::move(node_weights));
std::move(node_weights));
graph_contractor.Run(config.core_factor);
graph_contractor.GetEdges(contracted_edge_list);
graph_contractor.GetCoreMarker(is_core_node);

View File

@ -57,11 +57,11 @@ Engine::Engine(EngineConfig &config)
query_data_facade, config.max_locations_distance_table));
RegisterPlugin(new plugins::HelloWorldPlugin());
RegisterPlugin(new plugins::NearestPlugin<DataFacade>(query_data_facade));
RegisterPlugin(new plugins::MapMatchingPlugin<DataFacade>(
query_data_facade, config.max_locations_map_matching));
RegisterPlugin(new plugins::MapMatchingPlugin<DataFacade>(query_data_facade,
config.max_locations_map_matching));
RegisterPlugin(new plugins::TimestampPlugin<DataFacade>(query_data_facade));
RegisterPlugin(new plugins::ViaRoutePlugin<DataFacade>(query_data_facade,
config.max_locations_viaroute));
RegisterPlugin(
new plugins::ViaRoutePlugin<DataFacade>(query_data_facade, config.max_locations_viaroute));
RegisterPlugin(
new plugins::RoundTripPlugin<DataFacade>(query_data_facade, config.max_locations_trip));
RegisterPlugin(new plugins::TilePlugin<DataFacade>(query_data_facade));
@ -74,8 +74,7 @@ void Engine::RegisterPlugin(plugins::BasePlugin *raw_plugin_ptr)
plugin_map[plugin_ptr->GetDescriptor()] = std::move(plugin_ptr);
}
int Engine::RunQuery(const RouteParameters &route_parameters,
util::json::Object &json_result)
int Engine::RunQuery(const RouteParameters &route_parameters, util::json::Object &json_result)
{
const auto &plugin_iterator = plugin_map.find(route_parameters.service);
@ -87,14 +86,17 @@ int Engine::RunQuery(const RouteParameters &route_parameters,
osrm::engine::plugins::BasePlugin::Status return_code;
increase_concurrent_query_count();
if (barrier) {
if (barrier)
{
// Get a shared data lock so that other threads won't update
// things while the query is running
boost::shared_lock<boost::shared_mutex> data_lock{
(static_cast<datafacade::SharedDataFacade<contractor::QueryEdge::EdgeData> *>(
query_data_facade))->data_mutex};
(static_cast<datafacade::SharedDataFacade<contractor::QueryEdge::EdgeData> *>(
query_data_facade))->data_mutex};
return_code = plugin_iterator->second->HandleRequest(route_parameters, json_result);
} else {
}
else
{
return_code = plugin_iterator->second->HandleRequest(route_parameters, json_result);
}
decrease_concurrent_query_count();
@ -146,9 +148,7 @@ void Engine::increase_concurrent_query_count()
++(barrier->number_of_queries);
(static_cast<datafacade::SharedDataFacade<contractor::QueryEdge::EdgeData> *>(
query_data_facade))
->CheckAndReloadFacade();
}
query_data_facade))->CheckAndReloadFacade();
}
}
}

View File

@ -114,9 +114,8 @@ void RouteParameters::SetCompressionFlag(const bool flag) { compression = flag;
void RouteParameters::AddCoordinate(const double latitude, const double longitude)
{
coordinates.emplace_back(
static_cast<int>(COORDINATE_PRECISION * latitude),
static_cast<int>(COORDINATE_PRECISION * longitude));
coordinates.emplace_back(static_cast<int>(COORDINATE_PRECISION * latitude),
static_cast<int>(COORDINATE_PRECISION * longitude));
is_source.push_back(true);
is_destination.push_back(true);
uturns.push_back(uturn_default);
@ -124,9 +123,8 @@ void RouteParameters::AddCoordinate(const double latitude, const double longitud
void RouteParameters::AddDestination(const double latitude, const double longitude)
{
coordinates.emplace_back(
static_cast<int>(COORDINATE_PRECISION * latitude),
static_cast<int>(COORDINATE_PRECISION * longitude));
coordinates.emplace_back(static_cast<int>(COORDINATE_PRECISION * latitude),
static_cast<int>(COORDINATE_PRECISION * longitude));
is_source.push_back(false);
is_destination.push_back(true);
uturns.push_back(uturn_default);
@ -134,9 +132,8 @@ void RouteParameters::AddDestination(const double latitude, const double longitu
void RouteParameters::AddSource(const double latitude, const double longitude)
{
coordinates.emplace_back(
static_cast<int>(COORDINATE_PRECISION * latitude),
static_cast<int>(COORDINATE_PRECISION * longitude));
coordinates.emplace_back(static_cast<int>(COORDINATE_PRECISION * latitude),
static_cast<int>(COORDINATE_PRECISION * longitude));
is_source.push_back(true);
is_destination.push_back(false);
uturns.push_back(uturn_default);
@ -150,6 +147,5 @@ void RouteParameters::SetCoordinatesFromGeometry(const std::string &geometry_str
void RouteParameters::SetX(const int &x_) { x = x_; }
void RouteParameters::SetZ(const int &z_) { z = z_; }
void RouteParameters::SetY(const int &y_) { y = y_; }
}
}

View File

@ -645,18 +645,20 @@ EdgeBasedGraphFactory::optimizeCandidates(NodeID via_eid,
instruction_right_of_begin != TurnInstruction::TurnSlightRight)
{
std::int32_t resolved_count = 0;
//uses side-effects in resolve
// uses side-effects in resolve
if (!keepStraight(candidate_at_end.angle) &&
!resolve(candidate_at_end.instruction, instruction_left_of_end,
RESOLVE_TO_LEFT))
util::SimpleLogger().Write(logDEBUG) << "[warning] failed to resolve conflict";
util::SimpleLogger().Write(logDEBUG)
<< "[warning] failed to resolve conflict";
else
++resolved_count;
//uses side-effects in resolve
// uses side-effects in resolve
if (!keepStraight(candidate_at_begin.angle) &&
!resolve(candidate_at_begin.instruction, instruction_right_of_begin,
RESOLVE_TO_RIGHT))
util::SimpleLogger().Write(logDEBUG) << "[warning] failed to resolve conflict";
util::SimpleLogger().Write(logDEBUG)
<< "[warning] failed to resolve conflict";
else
++resolved_count;
if (resolved_count >= 1 &&
@ -772,8 +774,8 @@ bool EdgeBasedGraphFactory::isObviousChoice(EdgeID via_eid,
const auto &candidate_to_the_right = turn_candidates[getRight(turn_index)];
const auto hasValidRatio = [](const TurnCandidate &left, const TurnCandidate &center,
const TurnCandidate &right)
const auto hasValidRatio =
[](const TurnCandidate &left, const TurnCandidate &center, const TurnCandidate &right)
{
auto angle_left = (left.angle > 180) ? angularDeviation(left.angle, STRAIGHT_ANGLE) : 180;
auto angle_right =
@ -1107,9 +1109,9 @@ QueryNode EdgeBasedGraphFactory::getRepresentativeCoordinate(const NodeID src,
double this_dist = 0;
NodeID prev_id = INVERTED ? tgt : src;
const auto selectBestCandidate = [this](const NodeID current, const double current_distance,
const NodeID previous,
const double previous_distance)
const auto selectBestCandidate =
[this](const NodeID current, const double current_distance, const NodeID previous,
const double previous_distance)
{
if (current_distance < DESIRED_SEGMENT_LENGTH ||
current_distance - DESIRED_SEGMENT_LENGTH <

View File

@ -123,8 +123,7 @@ void RequestHandler::handle_request(const http::request &current_request,
json_result.values["pbf"].get<osrm::util::json::Buffer>().value.cend(),
std::back_inserter(current_reply.content));
current_reply.headers.emplace_back("Content-Type",
"application/x-protobuf");
current_reply.headers.emplace_back("Content-Type", "application/x-protobuf");
}
else if (route_parameters.jsonp_parameter.empty())
{ // json file

View File

@ -29,11 +29,10 @@ return_code parseArguments(int argc, char *argv[], extractor::ExtractorConfig &e
// declare a group of options that will be allowed both on command line
boost::program_options::options_description config_options("Configuration");
config_options.add_options()(
"profile,p",
boost::program_options::value<boost::filesystem::path>(&extractor_config.profile_path)
->default_value("profile.lua"),
"Path to LUA routing profile")(
config_options.add_options()("profile,p",
boost::program_options::value<boost::filesystem::path>(
&extractor_config.profile_path)->default_value("profile.lua"),
"Path to LUA routing profile")(
"threads,t",
boost::program_options::value<unsigned int>(&extractor_config.requested_num_threads)
->default_value(tbb::task_scheduler_init::default_num_threads()),
@ -43,9 +42,8 @@ return_code parseArguments(int argc, char *argv[], extractor::ExtractorConfig &e
->implicit_value(true)
->default_value(false),
"Generate a lookup table for internal edge-expanded-edge IDs to OSM node pairs")(
"small-component-size",
boost::program_options::value<unsigned int>(&extractor_config.small_component_size)
->default_value(1000),
"small-component-size", boost::program_options::value<unsigned int>(
&extractor_config.small_component_size)->default_value(1000),
"Number of nodes required before a strongly-connected-componennt is considered big "
"(affects nearest neighbor snapping)");

View File

@ -308,15 +308,20 @@ BOOST_AUTO_TEST_CASE(regression_test)
using Edge = std::pair<unsigned, unsigned>;
GraphFixture fixture(
{
Coord(40.0, 0.0), Coord(35.0, 5.0),
Coord(40.0, 0.0),
Coord(35.0, 5.0),
Coord(5.0, 5.0), Coord(0.0, 10.0),
Coord(5.0, 5.0),
Coord(0.0, 10.0),
Coord(20.0, 10.0), Coord(20.0, 5.0),
Coord(20.0, 10.0),
Coord(20.0, 5.0),
Coord(40.0, 100.0), Coord(35.0, 105.0),
Coord(40.0, 100.0),
Coord(35.0, 105.0),
Coord(5.0, 105.0), Coord(0.0, 110.0),
Coord(5.0, 105.0),
Coord(0.0, 110.0),
},
{Edge(0, 1), Edge(2, 3), Edge(4, 5), Edge(6, 7), Edge(8, 9)});
@ -404,7 +409,7 @@ BOOST_AUTO_TEST_CASE(bearing_tests)
using Edge = std::pair<unsigned, unsigned>;
GraphFixture fixture(
{
Coord(0.0, 0.0), Coord(10.0, 10.0),
Coord(0.0, 0.0), Coord(10.0, 10.0),
},
{Edge(0, 1), Edge(1, 0)});
@ -463,14 +468,10 @@ BOOST_AUTO_TEST_CASE(bbox_search_tests)
using Edge = std::pair<unsigned, unsigned>;
GraphFixture fixture(
{
Coord(0.0,0.0),
Coord(1.0,1.0),
Coord(2.0,2.0),
Coord(3.0,3.0),
Coord(4.0,4.0),
},
{Edge(0,1), Edge(1,2), Edge(2,3), Edge(3,4)});
{
Coord(0.0, 0.0), Coord(1.0, 1.0), Coord(2.0, 2.0), Coord(3.0, 3.0), Coord(4.0, 4.0),
},
{Edge(0, 1), Edge(1, 2), Edge(2, 3), Edge(3, 4)});
std::string leaves_path;
std::string nodes_path;
@ -479,20 +480,22 @@ BOOST_AUTO_TEST_CASE(bbox_search_tests)
engine::GeospatialQuery<MiniStaticRTree> query(rtree, fixture.coords);
{
RectangleInt2D bbox = {static_cast<uint32_t>(0.5 * COORDINATE_PRECISION), static_cast<uint32_t>(1.5 * COORDINATE_PRECISION),
static_cast<uint32_t>(0.5 * COORDINATE_PRECISION), static_cast<uint32_t>(1.5 * COORDINATE_PRECISION)};
RectangleInt2D bbox = {static_cast<uint32_t>(0.5 * COORDINATE_PRECISION),
static_cast<uint32_t>(1.5 * COORDINATE_PRECISION),
static_cast<uint32_t>(0.5 * COORDINATE_PRECISION),
static_cast<uint32_t>(1.5 * COORDINATE_PRECISION)};
auto results = query.Search(bbox);
BOOST_CHECK_EQUAL(results.size(), 2);
}
{
RectangleInt2D bbox = {static_cast<uint32_t>(1.5 * COORDINATE_PRECISION), static_cast<uint32_t>(3.5 * COORDINATE_PRECISION),
static_cast<uint32_t>(1.5 * COORDINATE_PRECISION), static_cast<uint32_t>(3.5 * COORDINATE_PRECISION)};
RectangleInt2D bbox = {static_cast<uint32_t>(1.5 * COORDINATE_PRECISION),
static_cast<uint32_t>(3.5 * COORDINATE_PRECISION),
static_cast<uint32_t>(1.5 * COORDINATE_PRECISION),
static_cast<uint32_t>(3.5 * COORDINATE_PRECISION)};
auto results = query.Search(bbox);
BOOST_CHECK_EQUAL(results.size(), 3);
}
}
BOOST_AUTO_TEST_SUITE_END()