diff --git a/defines.hpp b/defines.hpp index 7adc3c8c1e..7c00528376 100644 --- a/defines.hpp +++ b/defines.hpp @@ -25,7 +25,7 @@ #define VERSION_FILE_TAG "version" #define METADATA_FILE_TAG "meta" #define METADATA_INDEX_FILE_TAG "metaidx" -#define ALTITUDE_TAG "altitude" +#define ALTITUDE_FILE_TAG "altitude" #define FEATURE_OFFSETS_FILE_TAG "offs" #define RANKS_FILE_TAG "ranks" #define REGION_INFO_FILE_TAG "rgninfo" diff --git a/generator/altitude_generator.cpp b/generator/altitude_generator.cpp index 06ef4941a9..8c9fd4d6e5 100644 --- a/generator/altitude_generator.cpp +++ b/generator/altitude_generator.cpp @@ -1,8 +1,6 @@ #include "generator/routing_generator.hpp" #include "generator/srtm_parser.hpp" -#include "defines.hpp" - #include "routing/routing_helpers.hpp" #include "indexer/feature.hpp" @@ -19,27 +17,31 @@ #include "base/logging.hpp" #include "base/string_utils.hpp" -#include "std/map.hpp" +#include "defines.hpp" + +#include "std/algorithm.hpp" #include "std/type_traits.hpp" +#include "std/utility.hpp" +#include "std/vector.hpp" using namespace feature; namespace { -static_assert(is_same::value, ""); -static_assert(kInvalidAltitude == generator::SrtmTile::kInvalidHeight, ""); - class Processor { public: + using TFeatureAltitude = pair; + using TFeatureAltitudeVec = vector; + Processor(string const & srtmPath) : m_srtmManager(srtmPath) {} - map const & GetFeatureAltitudes() const { return m_featureAltitudes; } + + TFeatureAltitudeVec const & GetFeatureAltitudes() const { return m_featureAltitudes; } void operator()(FeatureType const & f, uint32_t const & id) { - f.ParseTypes(); - f.ParseHeader2(); - if (!routing::IsRoad(feature::TypesHolder(f))) + feature::TypesHolder const & fh = feature::TypesHolder(f); + if (!routing::IsRoad(fh)) return; f.ParseGeometry(FeatureType::BEST_GEOMETRY); @@ -49,31 +51,41 @@ public: Altitudes alts(m_srtmManager.GetHeight(MercatorBounds::ToLatLon(f.GetPoint(0))), m_srtmManager.GetHeight(MercatorBounds::ToLatLon(f.GetPoint(pointsCount - 1)))); - m_featureAltitudes[id] = alts; + m_featureAltitudes.push_back(make_pair(id, alts)); + } + + void SortFeatureAltitudes() + { + sort(m_featureAltitudes.begin(), m_featureAltitudes.end(), + [](Processor::TFeatureAltitude const & f1, Processor::TFeatureAltitude const & f2) + { + return f1.first < f2.first; + }); } private: generator::SrtmTileManager m_srtmManager; - map m_featureAltitudes; + TFeatureAltitudeVec m_featureAltitudes; }; } // namespace namespace routing { -void BuildRoadFeatureAltitude(string const & srtmPath, string const & baseDir, string const & countryName) +void BuildRoadAltitudes(string const & srtmPath, string const & baseDir, string const & countryName) { LOG(LINFO, ("srtmPath =", srtmPath, "baseDir =", baseDir, "countryName =", countryName)); - string const altPath = baseDir + countryName + "." + ALTITUDE_TAG; +// string const altPath = baseDir + countryName + "." + ALTITUDE_FILE_TAG; string const mwmPath = baseDir + countryName + DATA_FILE_EXTENSION; // Writing section with altitude information. { - FilesContainerW altCont(mwmPath, FileWriter::OP_WRITE_EXISTING); - FileWriter w = altCont.GetWriter(ALTITUDE_TAG); + FilesContainerW cont(mwmPath, FileWriter::OP_WRITE_EXISTING); + FileWriter w = cont.GetWriter(ALTITUDE_FILE_TAG); Processor processor(srtmPath); feature::ForEachFromDat(mwmPath, processor); - map const & featureAltitudes = processor.GetFeatureAltitudes(); + processor.SortFeatureAltitudes(); + Processor::TFeatureAltitudeVec const & featureAltitudes = processor.GetFeatureAltitudes(); for (auto const & a : featureAltitudes) { diff --git a/generator/altitude_generator.hpp b/generator/altitude_generator.hpp index 0881724df2..42651b8c59 100644 --- a/generator/altitude_generator.hpp +++ b/generator/altitude_generator.hpp @@ -4,5 +4,5 @@ namespace routing { -void BuildRoadFeatureAltitude(string const & srtmPath, string const & baseDir, string const & countryName); +void BuildRoadAltitudes(string const & srtmPath, string const & baseDir, string const & countryName); } // namespace routing diff --git a/generator/feature_segments_checker/feature_segments_checker.cpp b/generator/feature_segments_checker/feature_segments_checker.cpp index c5d299dcf7..d4ac612a4a 100644 --- a/generator/feature_segments_checker/feature_segments_checker.cpp +++ b/generator/feature_segments_checker/feature_segments_checker.cpp @@ -6,6 +6,7 @@ #include "indexer/classificator_loader.hpp" #include "indexer/feature.hpp" +#include "indexer/feature_altitude.hpp" #include "indexer/feature_processor.hpp" #include "indexer/map_style_reader.hpp" @@ -32,8 +33,7 @@ DEFINE_string(mwm_file_path, "", "Path to an mwm file."); namespace { -using TAltitude = generator::SrtmTile::THeight; -using TAltitudeVec = vector; +using namespace feature; routing::BicycleModel const & GetBicycleModel() { @@ -148,8 +148,8 @@ public: uint32_t m_roadPointCount; /// Number of features for GetBicycleModel().IsRoad(feature) != true. uint32_t m_notRoadCount; - TAltitude m_minAltitude = generator::SrtmTile::kInvalidHeight; - TAltitude m_maxAltitude = generator::SrtmTile::kInvalidHeight; + TAltitude m_minAltitude = kInvalidAltitude; + TAltitude m_maxAltitude = kInvalidAltitude; Processor(generator::SrtmTileManager & manager) : m_srtmManager(manager), m_roadCount(0), m_emptyRoadCount(0), m_roadPointCount(0), m_notRoadCount(0) @@ -188,7 +188,7 @@ public: { // Feature segment altitude. TAltitude altitude = m_srtmManager.GetHeight(MercatorBounds::ToLatLon(f.GetPoint(i))); - pointAltitudes[i] = altitude == generator::SrtmTile::kInvalidHeight ? 0 : altitude; + pointAltitudes[i] = altitude == kInvalidAltitude ? 0 : altitude; if (i == 0) { pointDists[i] = 0; @@ -204,9 +204,9 @@ public: // Min and max altitudes. for (auto const a : pointAltitudes) { - if (m_minAltitude == generator::SrtmTile::kInvalidHeight || a < m_minAltitude) + if (m_minAltitude == kInvalidAltitude || a < m_minAltitude) m_minAltitude = a; - if (m_maxAltitude == generator::SrtmTile::kInvalidHeight || a > m_maxAltitude) + if (m_maxAltitude == kInvalidAltitude || a > m_maxAltitude) m_maxAltitude = a; } @@ -324,7 +324,7 @@ int main(int argc, char ** argv) generator::SrtmTileManager manager(FLAGS_srtm_dir_path); Processor processor(manager); - feature::ForEachFromDat(FLAGS_mwm_file_path, processor); + ForEachFromDat(FLAGS_mwm_file_path, processor); PrintCont(processor.m_altitudeDiffs, "Altitude difference between start and end of features.", " feature(s) with altitude difference ", " meter(s)"); diff --git a/generator/generator_tool/generator_tool.cpp b/generator/generator_tool/generator_tool.cpp index 34298623ac..02da78143d 100644 --- a/generator/generator_tool/generator_tool.cpp +++ b/generator/generator_tool/generator_tool.cpp @@ -71,7 +71,7 @@ DEFINE_string(user_resource_path, "", "User defined resource path for classifica DEFINE_string(booking_data, "", "Path to booking data in .tsv format"); DEFINE_string(booking_reference_path, "", "Path to mwm dataset for match booking addresses"); DEFINE_uint64(planet_version, my::SecondsSinceEpoch(), "Version as seconds since epoch, by default - now"); -DEFINE_string(srtm_path, "", "Path to srtm directory. If it's set generates section with altitude information about road features."); +DEFINE_string(srtm_path, "", "Path to srtm directory. If When set generates section with altitude information about roads."); int main(int argc, char ** argv) { @@ -248,7 +248,7 @@ int main(int argc, char ** argv) feature::DumpFeatureNames(datFile, FLAGS_dump_feature_names); if (!FLAGS_srtm_path.empty()) - routing::BuildRoadFeatureAltitude(FLAGS_srtm_path, path, FLAGS_output); + routing::BuildRoadAltitudes(FLAGS_srtm_path, path, FLAGS_output); if (FLAGS_unpack_mwm) UnpackMwm(datFile); diff --git a/generator/srtm_coverage_checker/srtm_coverage_checker.cpp b/generator/srtm_coverage_checker/srtm_coverage_checker.cpp index fd02999714..dfd033522b 100644 --- a/generator/srtm_coverage_checker/srtm_coverage_checker.cpp +++ b/generator/srtm_coverage_checker/srtm_coverage_checker.cpp @@ -4,6 +4,8 @@ #include "routing/routing_integration_tests/routing_test_tools.hpp" +#include "indexer/feature_altitude.hpp" + #include "coding/file_name_utils.hpp" #include "platform/country_file.hpp" @@ -98,7 +100,7 @@ int main(int argc, char * argv[]) for (auto const & point : path) { auto const height = manager.GetHeight(MercatorBounds::ToLatLon(point)); - if (height != generator::SrtmTile::kInvalidHeight) + if (height != feature::kInvalidAltitude) good++; } } diff --git a/generator/srtm_parser.cpp b/generator/srtm_parser.cpp index 97939570c5..34ba2911b7 100644 --- a/generator/srtm_parser.cpp +++ b/generator/srtm_parser.cpp @@ -84,10 +84,10 @@ void SrtmTile::Init(string const & dir, ms::LatLon const & coord) m_valid = true; } -SrtmTile::THeight SrtmTile::GetHeight(ms::LatLon const & coord) +feature::TAltitude SrtmTile::GetHeight(ms::LatLon const & coord) { if (!IsValid()) - return kInvalidHeight; + return feature::kInvalidAltitude; double ln = coord.lon - static_cast(coord.lon); if (ln < 0) @@ -103,7 +103,7 @@ SrtmTile::THeight SrtmTile::GetHeight(ms::LatLon const & coord) size_t const ix = row * (kArcSecondsInDegree + 1) + col; if (ix >= Size()) - return kInvalidHeight; + return feature::kInvalidAltitude; return ReverseByteOrder(Data()[ix]); } @@ -146,7 +146,7 @@ void SrtmTile::Invalidate() // SrtmTileManager --------------------------------------------------------------------------------- SrtmTileManager::SrtmTileManager(string const & dir) : m_dir(dir) {} -SrtmTile::THeight SrtmTileManager::GetHeight(ms::LatLon const & coord) +feature::TAltitude SrtmTileManager::GetHeight(ms::LatLon const & coord) { string const base = SrtmTile::GetBase(coord); auto it = m_tiles.find(base); diff --git a/generator/srtm_parser.hpp b/generator/srtm_parser.hpp index 74bc14b755..b70bcbface 100644 --- a/generator/srtm_parser.hpp +++ b/generator/srtm_parser.hpp @@ -2,6 +2,8 @@ #include "geometry/latlon.hpp" +#include "indexer/feature_altitude.hpp" + #include "base/macros.hpp" #include "std/cstdint.hpp" @@ -13,10 +15,6 @@ namespace generator class SrtmTile { public: - using THeight = int16_t; - - static THeight constexpr kInvalidHeight = -32768; - SrtmTile(); SrtmTile(SrtmTile && rhs); @@ -24,15 +22,15 @@ public: inline bool IsValid() const { return m_valid; } - // Returns height in meters at |coord|, or kInvalidHeight if is not initialized. - THeight GetHeight(ms::LatLon const & coord); + // Returns height in meters at |coord|, or kInvalidAltitude if is not initialized. + feature::TAltitude GetHeight(ms::LatLon const & coord); static string GetBase(ms::LatLon coord); private: - inline THeight const * Data() const { return reinterpret_cast(m_data.data()); }; + inline feature::TAltitude const * Data() const { return reinterpret_cast(m_data.data()); }; - inline size_t Size() const { return m_data.size() / sizeof(THeight); } + inline size_t Size() const { return m_data.size() / sizeof(feature::TAltitude); } void Invalidate(); @@ -47,7 +45,7 @@ class SrtmTileManager public: SrtmTileManager(string const & dir); - SrtmTile::THeight GetHeight(ms::LatLon const & coord); + feature::TAltitude GetHeight(ms::LatLon const & coord); private: string m_dir; diff --git a/indexer/feature.hpp b/indexer/feature.hpp index 108857dba1..458528b3c1 100644 --- a/indexer/feature.hpp +++ b/indexer/feature.hpp @@ -371,7 +371,7 @@ private: // @TODO |m_altitudes| should be exchanged with vector. // If the vector is empty no altitude information is available for this feature. - mutable feature::Altitudes m_altitudes; + feature::Altitudes m_altitudes; mutable bool m_header2Parsed = false; mutable bool m_pointsParsed = false; diff --git a/indexer/feature_altitude.hpp b/indexer/feature_altitude.hpp index 54894f0047..916e88f04b 100644 --- a/indexer/feature_altitude.hpp +++ b/indexer/feature_altitude.hpp @@ -2,13 +2,14 @@ #include "coding/varint.hpp" +#include "std/limits.hpp" #include "std/vector.hpp" namespace feature { using TAltitude = int16_t; using TAltitudeVec = vector; -static TAltitude constexpr kInvalidAltitude = -32768; +static TAltitude constexpr kInvalidAltitude = numeric_limits::lowest(); struct Altitudes { diff --git a/indexer/feature_loader_base.cpp b/indexer/feature_loader_base.cpp index 349ea8055e..8d13bfca02 100644 --- a/indexer/feature_loader_base.cpp +++ b/indexer/feature_loader_base.cpp @@ -46,7 +46,7 @@ SharedLoadInfo::TReader SharedLoadInfo::GetMetadataIndexReader() const SharedLoadInfo::TReader SharedLoadInfo::GetAltitudeReader() const { - return m_cont.GetReader(ALTITUDE_TAG); + return m_cont.GetReader(ALTITUDE_FILE_TAG); } SharedLoadInfo::TReader SharedLoadInfo::GetGeometryReader(int ind) const