diff options
author | Добрый Ээх <bukharaev@gmail.com> | 2016-11-15 13:25:38 +0300 |
---|---|---|
committer | Добрый Ээх <bukharaev@gmail.com> | 2016-11-25 18:57:21 +0300 |
commit | e73be5c1c78d84c0d3208f25ace17e59f92de349 (patch) | |
tree | a2514877f0bb7840a489f809f5a1c9cf105652e7 /generator | |
parent | df2bd34a17e6efbd9dc6574ee71f3433b6696d69 (diff) |
Pull request #4672 review fixes
Diffstat (limited to 'generator')
-rw-r--r-- | generator/generator_tool/generator_tool.cpp | 4 | ||||
-rw-r--r-- | generator/restriction_generator.cpp | 2 | ||||
-rw-r--r-- | generator/routing_index_generator.cpp | 121 | ||||
-rw-r--r-- | generator/routing_index_generator.hpp | 2 |
4 files changed, 40 insertions, 89 deletions
diff --git a/generator/generator_tool/generator_tool.cpp b/generator/generator_tool/generator_tool.cpp index 3242738bce..6e54cbb911 100644 --- a/generator/generator_tool/generator_tool.cpp +++ b/generator/generator_tool/generator_tool.cpp @@ -240,12 +240,14 @@ int main(int argc, char ** argv) routing::BuildRoadAltitudes(datFile, FLAGS_srtm_path); if (FLAGS_generate_routing) - routing::BuildRoutingIndex(path, country); + routing::BuildRoutingIndex(datFile); if (FLAGS_generate_restrictions) + { routing::BuildRoadRestrictions( datFile, genInfo.GetIntermediateFileName(genInfo.m_restrictions, "" /* extention */), genInfo.GetTargetFileName(country) + OSM2FEATURE_FILE_EXTENSION); + } } string const datFile = my::JoinFoldersToPath(path, FLAGS_output + DATA_FILE_EXTENSION); diff --git a/generator/restriction_generator.cpp b/generator/restriction_generator.cpp index 7ee0a7e3a3..bf672dd81e 100644 --- a/generator/restriction_generator.cpp +++ b/generator/restriction_generator.cpp @@ -39,7 +39,7 @@ bool BuildRoadRestrictions(string const & mwmPath, string const & restrictionPat header.m_onlyRestrictionCount, "of type Only restrictions")); FilesContainerW cont(mwmPath, FileWriter::OP_WRITE_EXISTING); - FileWriter w = cont.GetWriter(ROUTING_FILE_TAG); + FileWriter w = cont.GetWriter(RESTRICTIONS_FILE_TAG); header.Serialize(w); RestrictionSerializer::Serialize(header, restrictions.cbegin(), restrictions.cend(), w); diff --git a/generator/routing_index_generator.cpp b/generator/routing_index_generator.cpp index 392553269b..d301f231a4 100644 --- a/generator/routing_index_generator.cpp +++ b/generator/routing_index_generator.cpp @@ -1,26 +1,17 @@ #include "generator/routing_index_generator.hpp" -#include "routing/bicycle_model.hpp" -#include "routing/car_model.hpp" #include "routing/index_graph.hpp" -#include "routing/pedestrian_model.hpp" -#include "routing/vehicle_model.hpp" +#include "routing/routing_helpers.hpp" #include "indexer/feature.hpp" #include "indexer/feature_processor.hpp" -#include "indexer/index.hpp" +#include "indexer/point_to_int64.hpp" #include "indexer/routing_section.hpp" -#include "indexer/scales.hpp" -#include "coding/file_name_utils.hpp" - -#include "platform/country_file.hpp" -#include "platform/local_country_file.hpp" +#include "coding/file_container.hpp" #include "base/logging.hpp" -#include "std/shared_ptr.hpp" -#include "std/unique_ptr.hpp" #include "std/unordered_map.hpp" #include "std/vector.hpp" @@ -30,116 +21,74 @@ using namespace routing; namespace { -uint32_t constexpr kFixPointFactor = 100000; - -inline m2::PointI PointDToPointI(m2::PointD const & p) { return m2::PointI(p * kFixPointFactor); } - -uint64_t CalcLocationKey(m2::PointD const & point) -{ - m2::PointI const pointI(PointDToPointI(point)); - return (static_cast<uint64_t>(pointI.y) << 32) + static_cast<uint64_t>(pointI.x); -} - class Processor final { public: - Processor(string const & dir, string const & country) - : m_pedestrianModel(make_unique<PedestrianModelFactory>()->GetVehicleModelForCountry(country)) - , m_bicycleModel(make_unique<BicycleModelFactory>()->GetVehicleModelForCountry(country)) - , m_carModel(make_unique<CarModelFactory>()->GetVehicleModelForCountry(country)) + void ProcessAllFeatures(string const & filename) { - LocalCountryFile localCountryFile(dir, CountryFile(country), 1 /* version */); - m_index.RegisterMap(localCountryFile); - vector<shared_ptr<MwmInfo>> info; - m_index.GetMwmsInfo(info); - CHECK_EQUAL(info.size(), 1, ()); - CHECK(info[0], ()); + feature::ForEachFromDat(filename, + [this](FeatureType const & f, uint32_t id) { ProcessFeature(f, id); }); } - void operator()(FeatureType const & f) + void BuildGraph(IndexGraph & graph) const { - if (!IsRoad(f)) - return; - - uint32_t const id = f.GetID().m_index; - f.ParseGeometry(FeatureType::BEST_GEOMETRY); - size_t const pointsCount = f.GetPointsCount(); - if (pointsCount == 0) - return; - - for (size_t fromSegId = 0; fromSegId < pointsCount; ++fromSegId) + vector<Joint> joints; + for (auto const & it : m_posToJoint) { - uint64_t const locationKey = CalcLocationKey(f.GetPoint(fromSegId)); - m_pos2Joint[locationKey].AddEntry(FSegId(id, fromSegId)); + // Need only connected points (2 or more roads) + if (it.second.GetSize() >= 2) + joints.emplace_back(it.second); } - } - void ForEachFeature() { m_index.ForEachInScale(*this, scales::GetUpperScale()); } - - bool IsRoad(FeatureType const & f) const - { - return m_pedestrianModel->IsRoad(f) || m_bicycleModel->IsRoad(f) || m_carModel->IsRoad(f); + graph.Import(joints); } - void RemoveNonCrosses() +private: + void ProcessFeature(FeatureType const & f, uint32_t id) { - for (auto it = m_pos2Joint.begin(); it != m_pos2Joint.end();) - { - if (it->second.GetSize() < 2) - it = m_pos2Joint.erase(it); - else - ++it; - } - } + if (!IsRoad(feature::TypesHolder(f))) + return; - void BuildGraph(IndexGraph & graph) const - { - vector<Joint> joints; - joints.reserve(m_pos2Joint.size()); - for (auto it = m_pos2Joint.begin(); it != m_pos2Joint.end(); ++it) - joints.emplace_back(it->second); + f.ParseGeometry(FeatureType::BEST_GEOMETRY); - graph.Export(joints); + for (size_t i = 0; i < f.GetPointsCount(); ++i) + { + uint64_t const locationKey = PointToInt64(f.GetPoint(i), POINT_COORD_BITS); + m_posToJoint[locationKey].AddPoint(RoadPoint(id, i)); + } } -private: - Index m_index; - shared_ptr<IVehicleModel> m_pedestrianModel; - shared_ptr<IVehicleModel> m_bicycleModel; - shared_ptr<IVehicleModel> m_carModel; - unordered_map<uint64_t, Joint> m_pos2Joint; + unordered_map<uint64_t, Joint> m_posToJoint; }; } // namespace namespace routing { -void BuildRoutingIndex(string const & dir, string const & country) +bool BuildRoutingIndex(string const & filename) { - LOG(LINFO, ("dir =", dir, "country", country)); + LOG(LINFO, ("Building routing index for", filename)); try { - Processor processor(dir, country); - string const datFile = my::JoinFoldersToPath(dir, country + DATA_FILE_EXTENSION); - LOG(LINFO, ("datFile =", datFile)); - processor.ForEachFeature(); - processor.RemoveNonCrosses(); + Processor processor; + processor.ProcessAllFeatures(filename); IndexGraph graph; processor.BuildGraph(graph); - LOG(LINFO, ("roads =", graph.GetRoadsAmount())); - LOG(LINFO, ("joints =", graph.GetJointsAmount())); - LOG(LINFO, ("fsegs =", graph.GetFSegsAmount())); + LOG(LINFO, ("Routing index contains", graph.GetNumRoads(), "roads,", graph.GetNumJoints(), + "joints,", graph.GetNumPoints(), "points")); - FilesContainerW cont(datFile, FileWriter::OP_WRITE_EXISTING); + FilesContainerW cont(filename, FileWriter::OP_WRITE_EXISTING); FileWriter writer = cont.GetWriter(ROUTING_FILE_TAG); - RoutingSectionHeader const header; - header.Serialize(writer); + RoutingSectionHeader const routingHeader; + routingHeader.Serialize(writer); graph.Serialize(writer); + return true; } catch (RootException const & e) { LOG(LERROR, ("An exception happened while creating", ROUTING_FILE_TAG, "section:", e.what())); + return false; } } } // namespace routing diff --git a/generator/routing_index_generator.hpp b/generator/routing_index_generator.hpp index 960ea46d87..439157270a 100644 --- a/generator/routing_index_generator.hpp +++ b/generator/routing_index_generator.hpp @@ -4,5 +4,5 @@ namespace routing { -void BuildRoutingIndex(string const & dir, string const & country); +bool BuildRoutingIndex(string const & filename); } // namespace routing |