From 93dcd65744b6af1e405d77aa50f53fa20a8fb633 Mon Sep 17 00:00:00 2001 From: Maxim Pimenov Date: Wed, 10 Jun 2015 20:39:04 +0300 Subject: [PATCH] [omim] [indexer] Skip the buckets that are not allowed by classificator. --- indexer/feature_visibility.cpp | 26 ++++++++++++++++++++++++++ indexer/feature_visibility.hpp | 3 +++ indexer/scale_index_builder.hpp | 17 +++++++++++------ 3 files changed, 40 insertions(+), 6 deletions(-) diff --git a/indexer/feature_visibility.cpp b/indexer/feature_visibility.cpp index 7531bb9c87..2c06ca5eb8 100644 --- a/indexer/feature_visibility.cpp +++ b/indexer/feature_visibility.cpp @@ -288,6 +288,20 @@ bool IsDrawableForIndex(FeatureBase const & f, int level) return false; } +bool IsDrawableForIndexClassifOnly(FeatureBase const & f, int level) +{ + Classificator const & c = classif(); + + TypesHolder const types(f); + + IsDrawableChecker doCheck(level); + for (uint32_t t : types) + if (c.ProcessObjects(t, doCheck)) + return true; + + return false; +} + namespace { class IsNonDrawableType @@ -339,6 +353,18 @@ int GetMinDrawableScale(FeatureBase const & f) return -1; } +int GetMinDrawableScaleClassifOnly(FeatureBase const & f) +{ + int const upBound = scales::GetUpperStyleScale(); + + for (int level = 0; level <= upBound; ++level) + if (IsDrawableForIndexClassifOnly(f, level)) + return level; + + ASSERT(false, ("Feature is never visible.")); + return -1; +} + namespace { void AddRange(pair & dest, pair const & src) diff --git a/indexer/feature_visibility.hpp b/indexer/feature_visibility.hpp index 7d48d5c96d..20de212e8c 100644 --- a/indexer/feature_visibility.hpp +++ b/indexer/feature_visibility.hpp @@ -19,6 +19,7 @@ namespace feature bool IsDrawableAny(uint32_t type); bool IsDrawableForIndex(FeatureBase const & f, int level); + bool IsDrawableForIndexClassifOnly(FeatureBase const & f, int level); /// For FEATURE_TYPE_AREA need to have at least one area-filling type. bool IsDrawableLike(vector const & types, EGeomType ft); @@ -28,6 +29,8 @@ namespace feature int GetMinDrawableScale(FeatureBase const & f); + int GetMinDrawableScaleClassifOnly(FeatureBase const & f); + /// @return [-1, -1] if range is not drawable //@{ /// @name Get scale range when feature is visible. diff --git a/indexer/scale_index_builder.hpp b/indexer/scale_index_builder.hpp index 0be10e08aa..3a9090287d 100644 --- a/indexer/scale_index_builder.hpp +++ b/indexer/scale_index_builder.hpp @@ -100,13 +100,17 @@ public: { uint32_t minScale = 0; m_scalesIdx = 0; - for (uint32_t bucket = 0; bucket < m_bucketsCount; ++bucket) + uint32_t minScaleClassif = feature::GetMinDrawableScaleClassifOnly(f); + // The classificator won't allow this feature to be drawable for smaller + // scales so the first buckets can be safely skipped. + for (uint32_t bucket = minScaleClassif; bucket < m_bucketsCount; ++bucket) { // There is a one-to-one correspondence between buckets and scales. // This is not immediately obvious and in fact there was an idea to map // a bucket to a contiguous range of scales. // todo(@pimenov): We probably should remove scale_index.hpp altogether. - if (!FeatureShouldBeIndexed(f, offset, bucket, minScale)) + if (!FeatureShouldBeIndexed(f, offset, bucket, bucket == minScaleClassif /* needReset */, + minScale)) continue; vector const cells = covering::CoverFeature(f, m_codingDepth, 250); @@ -121,14 +125,15 @@ public: } private: - // Every feature should be indexed at most once: for the smallest possible scale where - // its geometry is non-empty, where it is visible and where the classificator allows. + // Every feature should be indexed at most once, namely for the smallest possible scale where + // -- its geometry is non-empty; + // -- it is visible; + // -- the classificator allows. // If the feature is invisible at all scales, do not index it. template - bool FeatureShouldBeIndexed(TFeature const & f, uint32_t offset, uint32_t scale, + bool FeatureShouldBeIndexed(TFeature const & f, uint32_t offset, uint32_t scale, bool needReset, uint32_t & minScale) const { - bool needReset = (scale == 0); while (m_scalesIdx < m_header.GetScalesCount() && m_header.GetScale(m_scalesIdx) < scale) { ++m_scalesIdx;