diff --git a/indexer/data_header.cpp b/indexer/data_header.cpp index 184e7ce5d3..dc5fd28e8e 100644 --- a/indexer/data_header.cpp +++ b/indexer/data_header.cpp @@ -1,6 +1,6 @@ #include "data_header.hpp" - -#include "../indexer/point_to_int64.hpp" +#include "point_to_int64.hpp" +#include "scales.hpp" #include "../coding/file_reader.hpp" #include "../coding/file_writer.hpp" @@ -42,6 +42,20 @@ namespace feature m_scales[i] = static_cast(arr[i]); } + pair DataHeader::GetScaleRange() const + { + pair ret(0, scales::GetUpperScale()); + + int const bound = scales::GetUpperWorldScale(); + + if (m_scales.front() > bound) + ret.first = bound+1; + if (m_scales.back() <= bound) + ret.second = bound; + + return ret; + } + void DataHeader::Save(FileWriter & w) const { WriteToSink(w, m_base); diff --git a/indexer/data_header.hpp b/indexer/data_header.hpp index 979b258c39..d985fb1b6d 100644 --- a/indexer/data_header.hpp +++ b/indexer/data_header.hpp @@ -36,6 +36,7 @@ namespace feature void SetScales(int * arr); size_t GetScalesCount() const { return m_scales.size(); } int GetScale(int i) const { return m_scales[i]; } + pair GetScaleRange() const; /// @name Serialization //@{ diff --git a/indexer/feature_impl.hpp b/indexer/feature_impl.hpp index 0b18c2beb6..6f37b3ce75 100644 --- a/indexer/feature_impl.hpp +++ b/indexer/feature_impl.hpp @@ -22,7 +22,7 @@ namespace feature } - static int g_arrWorldScales[] = { 2, 4, 5, 6 }; // 6 = upper scale for world.mwm visibility + static int g_arrWorldScales[] = { 2, 4, 5, 6 }; // 6 = scales::GetUpperWorldScale() static int g_arrCountryScales[] = { 7, 10, 14, 17 }; // 17 = scales::GetUpperScale() inline string GetTagForIndex(char const * prefix, int ind) diff --git a/indexer/index.hpp b/indexer/index.hpp index 70a0a9f125..d8172ea4fb 100644 --- a/indexer/index.hpp +++ b/indexer/index.hpp @@ -219,14 +219,16 @@ private: // TODO: If path is cellid-style-square, make rect from cellid and don't open the file. feature::DataHeader header; header.Load(FilesContainerR(path).GetReader(HEADER_FILE_TAG)); + m_Rect = header.GetBounds(); + m_scaleRange = header.GetScaleRange(); } // TODO: GetIndex(), Open() and Close() make Index single-threaded! - IndexT * GetIndex(uint32_t /*scale*/, m2::RectD const & occlusionRect) + IndexT * GetIndex(uint32_t scale, m2::RectD const & occlusionRect) { - // TODO: Scale should also be taken into account, to skip irrelevant mwm files. - if (m_Rect.IsIntersect(occlusionRect)) + if ((m_scaleRange.first <= scale && scale <= m_scaleRange.second) && + m_Rect.IsIntersect(occlusionRect)) { Open(); m_QueriesSkipped = 0; @@ -278,8 +280,10 @@ private: } } - m2::RectD m_Rect; string m_Path; // TODO: Store prefix and suffix of path in MultiIndexAdapter. + m2::RectD m_Rect; + pair m_scaleRange; + IndexT * m_pIndex; uint8_t m_QueriesSkipped; }; diff --git a/indexer/scales.hpp b/indexer/scales.hpp index 0d862ef10c..6fd46a9ee8 100644 --- a/indexer/scales.hpp +++ b/indexer/scales.hpp @@ -5,6 +5,7 @@ namespace scales { inline int GetUpperScale() { return 17; } + inline int GetUpperWorldScale() { return 6; } double GetM2PFactor(int level); int GetScaleLevel(double ratio);