diff options
author | Denis Koronchik <denis@mapswithme.com> | 2014-09-03 17:08:28 +0400 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 02:28:08 +0300 |
commit | a7bf5cf36f5120684602faea6f1c8806b53d2cca (patch) | |
tree | 712111c590f2a6a24654376562621dac487fd6ce /generator | |
parent | 59214f805d3e9f8a6ed70b5dcb5bac2d7c2268cd (diff) |
[generator] Add mapping from Fid to graph node id (not finished)
Diffstat (limited to 'generator')
-rw-r--r-- | generator/routing_generator.cpp | 178 | ||||
-rw-r--r-- | generator/routing_generator.hpp | 2 |
2 files changed, 105 insertions, 75 deletions
diff --git a/generator/routing_generator.cpp b/generator/routing_generator.cpp index 1f09c27bba..d1a6fa1bf8 100644 --- a/generator/routing_generator.cpp +++ b/generator/routing_generator.cpp @@ -1,39 +1,30 @@ #include "routing_generator.hpp" +#include "gen_mwm_info.hpp" #include "../indexer/index.hpp" #include "../indexer/classificator_loader.hpp" #include "../indexer/feature.hpp" #include "../indexer/ftypes_matcher.hpp" +#include "../indexer/mercator.hpp" -#include "../3party/osrm/osrm-backend/DataStructures/QueryEdge.h" -#include "../3party/osrm/osrm-backend/Server/DataStructures/InternalDataFacade.h" +#include "../geometry/distance_on_sphere.hpp" -namespace routing -{ +#include "../routing/osrm_data_facade_types.hpp" -uint32_t const MAX_SCALE = 15; // max scale for roads +#include "../platform/platform.hpp" -struct Node2Feature -{ - NodeID m_nodeId; - FeatureID m_FID; - uint32_t m_start; - uint32_t m_len; +#include "../base/logging.hpp" - Node2Feature(NodeID nodeId, FeatureID fid, uint32_t start, uint32_t len) - : m_nodeId(nodeId), m_FID(fid), m_start(start), m_len(len) - { - } -}; +#include "../std/fstream.hpp" + +#include "../3party/osrm/osrm-backend/DataStructures/EdgeBasedNodeData.h" -struct Node2FeatureSetComp + +namespace routing { - bool operator() (Node2Feature const & a, Node2Feature const & b) - { - return a.m_nodeId < b.m_nodeId; - } -}; -typedef std::set<Node2Feature, Node2FeatureSetComp> Node2FeatureSet; + + +double const EQUAL_POINT_RADIUS_M = 1; void GenerateNodesInfo(string const & mwmName, string const & osrmName) { @@ -47,73 +38,110 @@ void GenerateNodesInfo(string const & mwmName, string const & osrmName) return; } - ServerPaths server_paths; - server_paths["hsgrdata"] = boost::filesystem::path(osrmName + ".hsgr"); - server_paths["ramindex"] = boost::filesystem::path(osrmName + ".ramIndex"); - server_paths["fileindex"] = boost::filesystem::path(osrmName + ".fileIndex"); - server_paths["geometries"] = boost::filesystem::path(osrmName + ".geometry"); - server_paths["nodesdata"] = boost::filesystem::path(osrmName + ".nodes"); - server_paths["edgesdata"] = boost::filesystem::path(osrmName + ".edges"); - server_paths["namesdata"] = boost::filesystem::path(osrmName + ".names"); - server_paths["timestamp"] = boost::filesystem::path(osrmName + ".timestamp"); - - InternalDataFacade<QueryEdge::EdgeData> facade(server_paths); - - Node2FeatureSet nodesSet; - uint32_t processed = 0; - auto fn = [&](FeatureType const & ft) + Platform & pl = GetPlatform(); + + gen::OsmID2FeatureID osm2ft; { - processed++; + ReaderSource<ModelReaderPtr> src(pl.GetReader(mwmName + OSM2FEATURE_FILE_EXTENSION)); + osm2ft.Read(src); + } - if (processed % 1000 == 0) - { - if (processed % 10000 == 0) - std::cout << "[" << processed / 1000 << "k]"; - else - std::cout << "."; - std::cout.flush(); - } + string nodeFileName = osrmName + ".nodeData"; - feature::TypesHolder types(ft); - if (types.GetGeoType() != feature::GEOM_LINE) - return; + OsrmFtSegMapping mapping; - if (!ftypes::IsStreetChecker::Instance()(ft)) - return; + ifstream input; + input.open(nodeFileName); + if (!input.is_open()) + { + LOG(LERROR, ("Can't open file ", nodeFileName)); + return; + } - std::cout << "------------ FID: " << ft.GetID().m_offset << std::endl; + osrm::NodeDataVectorT nodeData; + if (!osrm::LoadNodeDataFromFile(nodeFileName, nodeData)) + { + LOG(LERROR, ("Can't load node data")); + return; + } - ft.ParseGeometry(FeatureType::BEST_GEOMETRY); - uint32_t lastId = std::numeric_limits<uint32_t>::max(); - uint32_t start = 0; - for (uint32_t i = 1; i < ft.GetPointsCount(); ++i) + uint32_t found = 0, all = 0; + uint32_t nodeId = 0; + for (osrm::NodeData data : nodeData) + { + uint32_t segId = 0; + OsrmFtSegMapping::FtSegVectorT vec; + vec.resize(data.m_segments.size()); + + for (auto seg : data.m_segments) { - m2::PointD p = ft.GetPoint(i -1).mid(ft.GetPoint(i)); - FixedPointCoordinate fp(static_cast<int>(p.x * COORDINATE_PRECISION), - static_cast<int>(p.y * COORDINATE_PRECISION)); + m2::PointD pts[2] = {{seg.lon1, seg.lat1}, {seg.lon2, seg.lat2}}; + + all++; - PhantomNode node; - if (facade.FindPhantomNodeForCoordinate(fp, node, 18)) + // now need to determine feature id and segments in it + uint32_t const fID = osm2ft.GetFeatureID(seg.wayId); + if (fID == 0) { - if (node.forward_node_id != lastId) + LOG(LWARNING, ("No feature id for way:", seg.wayId)); + continue; + } + + FeatureType ft; + Index::FeaturesLoaderGuard loader(index, 0); + loader.GetFeature(fID, ft); + + ft.ParseGeometry(FeatureType::BEST_GEOMETRY); + int32_t indicies[2] = {-1, -1}; + + for (uint32_t j = 0; j < ft.GetPointsCount(); ++j) + { + double lon = MercatorBounds::XToLon(ft.GetPoint(j).x); + double lat = MercatorBounds::YToLat(ft.GetPoint(j).y); + for (uint32_t k = 0; k < 2; ++k) { - if (lastId != std::numeric_limits<uint32_t>::max()) + double const dist = ms::DistanceOnEarth(pts[k].y, pts[k].x, lat, lon); + //LOG(LINFO, ("Distance: ", dist)); + + if (dist <= EQUAL_POINT_RADIUS_M) { - bool added = nodesSet.insert(Node2Feature(node.forward_node_id, ft.GetID(), start, i - 1)).second; - assert(added); + //ASSERT_EQUAL(indicies[k], -1, ()); + indicies[k] = j; } - lastId = node.forward_node_id; - start = i - 1; - std::cout << "LastID: " << lastId << " ForwardID: " << node.forward_node_id << " Offset: " << node.forward_offset << std::endl; } - } else - break; - } - }; - index.ForEachInRect(fn, MercatorBounds::FullRect(), MAX_SCALE); + } + + // Check if indicies found + if (indicies[0] != -1 && indicies[1] != -1) + { + found++; + ASSERT_NOT_EQUAL(indicies[0], indicies[1], ()); + OsrmFtSegMapping::FtSeg & segData = vec[segId++]; + segData.m_fid = fID; + segData.m_pointEnd = indicies[1]; + segData.m_pointStart = indicies[0]; + mapping.Append(nodeId++, vec); + } + else + { + LOG(LINFO, ("----------------- Way ID: ", seg.wayId, "--- Segments: ", data.m_segments.size(), " SegId: ", segId)); + LOG(LINFO, ("P1: ", pts[0].y, " ", pts[0].x, " P2: ", pts[1].y, " ", pts[1].x)); + for (uint32_t j = 0; j < ft.GetPointsCount(); ++j) + { + double lon = MercatorBounds::XToLon(ft.GetPoint(j).x); + double lat = MercatorBounds::YToLat(ft.GetPoint(j).y); + double const dist1 = ms::DistanceOnEarth(pts[0].y, pts[0].x, lat, lon); + double const dist2 = ms::DistanceOnEarth(pts[1].y, pts[1].x, lat, lon); + LOG(LINFO, ("p", j, ": ", lat, ", ", lon, " Dist1: ", dist1, " Dist2: ", dist2)); + } + } + - std::cout << "Nodes: " << facade.GetNumberOfNodes() << " Set: " << nodesSet.size() << std::endl; + } + } + LOG(LINFO, ("Found: ", found, " All: ", all)); + mapping.Save(osrmName + ".ftseg"); } } diff --git a/generator/routing_generator.hpp b/generator/routing_generator.hpp index d32f287184..6e63317cdd 100644 --- a/generator/routing_generator.hpp +++ b/generator/routing_generator.hpp @@ -1,9 +1,11 @@ #pragma once #include "../std/string.hpp" +#include "../std/vector.hpp" namespace routing { void GenerateNodesInfo(string const & mwmName, string const & osrmName); + } |