Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortatiana-kondakova <tatiana.kondakova@gmail.com>2018-02-06 16:08:43 +0300
committerVladimir Byko-Ianko <bykoianko@gmail.com>2018-02-08 12:39:21 +0300
commit4bf5605859902a63babefab7e2cf50732bc98f5f (patch)
tree8c59ffc5bd791d975ea448d0f3908872c304d573 /indexer/feature_covering.hpp
parente01c0f206df8bc65cf9632f91c2852fde4701d54 (diff)
Change LocalityIndex depth
Diffstat (limited to 'indexer/feature_covering.hpp')
-rw-r--r--indexer/feature_covering.hpp107
1 files changed, 97 insertions, 10 deletions
diff --git a/indexer/feature_covering.hpp b/indexer/feature_covering.hpp
index 3cdca66957..624f13e3b6 100644
--- a/indexer/feature_covering.hpp
+++ b/indexer/feature_covering.hpp
@@ -1,9 +1,18 @@
#pragma once
+
+#include "indexer/cell_coverer.hpp"
+#include "indexer/cell_id.hpp"
+#include "indexer/scales.hpp"
+
+#include "geometry/mercator.hpp"
#include "geometry/rect2d.hpp"
#include "coding/point_to_integer.hpp"
+#include "base/logging.hpp"
+
#include <cstdint>
+#include <utility>
#include <vector>
class FeatureType;
@@ -25,19 +34,56 @@ std::vector<int64_t> CoverFeature(FeatureType const & feature, int cellDepth,
std::vector<int64_t> CoverLocality(indexer::LocalityObject const & o, int cellDepth,
uint64_t cellPenaltyArea);
-void AppendLowerLevels(RectId id, int cellDepth, Intervals & intervals);
-
-// Cover viewport with RectIds and append their RectIds as well.
-void CoverViewportAndAppendLowerLevels(m2::RectD const & rect, int cellDepth,
- Intervals & intervals);
-
// Given a vector of intervals [a, b), sort them and merge overlapping intervals.
Intervals SortAndMergeIntervals(Intervals const & intervals);
+void SortAndMergeIntervals(Intervals v, Intervals & res);
-RectId GetRectIdAsIs(m2::RectD const & r);
+template <int DEPTH_LEVELS>
+m2::CellId<DEPTH_LEVELS> GetRectIdAsIs(m2::RectD const & r)
+{
+ double const eps = MercatorBounds::GetCellID2PointAbsEpsilon();
+ using Converter = CellIdConverter<MercatorBounds, m2::CellId<DEPTH_LEVELS>>;
+
+ return Converter::Cover2PointsWithCell(
+ MercatorBounds::ClampX(r.minX() + eps), MercatorBounds::ClampY(r.minY() + eps),
+ MercatorBounds::ClampX(r.maxX() - eps), MercatorBounds::ClampY(r.maxY() - eps));
+}
// Calculate cell coding depth according to max visual scale for mwm.
-int GetCodingDepth(int scale);
+template <int DEPTH_LEVELS>
+int GetCodingDepth(int scale)
+{
+ int const delta = scales::GetUpperScale() - scale;
+ ASSERT_GREATER_OR_EQUAL(delta, 0, ());
+ return DEPTH_LEVELS - delta;
+}
+
+template <int DEPTH_LEVELS>
+void AppendLowerLevels(m2::CellId<DEPTH_LEVELS> id, int cellDepth, Intervals & intervals)
+{
+ int64_t idInt64 = id.ToInt64(cellDepth);
+ intervals.push_back(std::make_pair(idInt64, idInt64 + id.SubTreeSize(cellDepth)));
+ while (id.Level() > 0)
+ {
+ id = id.Parent();
+ idInt64 = id.ToInt64(cellDepth);
+ intervals.push_back(make_pair(idInt64, idInt64 + 1));
+ }
+}
+
+template <int DEPTH_LEVELS>
+void CoverViewportAndAppendLowerLevels(m2::RectD const & r, int cellDepth, Intervals & res)
+{
+ std::vector<m2::CellId<DEPTH_LEVELS>> ids;
+ ids.reserve(SPLIT_RECT_CELLS_COUNT);
+ CoverRect<MercatorBounds, m2::CellId<DEPTH_LEVELS>>(r, SPLIT_RECT_CELLS_COUNT, cellDepth, ids);
+
+ Intervals intervals;
+ for (auto const & id : ids)
+ AppendLowerLevels<DEPTH_LEVELS>(id, cellDepth, intervals);
+
+ SortAndMergeIntervals(intervals, res);
+}
enum CoveringMode
{
@@ -56,6 +102,47 @@ class CoveringGetter
public:
CoveringGetter(m2::RectD const & r, CoveringMode mode) : m_rect(r), m_mode(mode) {}
- Intervals const & Get(int scale);
- };
+ template <int DEPTH_LEVELS>
+ Intervals const & Get(int scale)
+ {
+ int const cellDepth = GetCodingDepth<DEPTH_LEVELS>(scale);
+ int const ind = (cellDepth == DEPTH_LEVELS ? 0 : 1);
+
+ if (m_res[ind].empty())
+ {
+ switch (m_mode)
+ {
+ case ViewportWithLowLevels:
+ CoverViewportAndAppendLowerLevels<DEPTH_LEVELS>(m_rect, cellDepth, m_res[ind]);
+ break;
+
+ case LowLevelsOnly:
+ {
+ m2::CellId<DEPTH_LEVELS> id = GetRectIdAsIs<DEPTH_LEVELS>(m_rect);
+ while (id.Level() >= cellDepth)
+ id = id.Parent();
+ AppendLowerLevels<DEPTH_LEVELS>(id, cellDepth, m_res[ind]);
+
+ // Check for optimal result intervals.
+#if 0
+ size_t oldSize = m_res[ind].size();
+ Intervals res;
+ SortAndMergeIntervals(m_res[ind], res);
+ if (res.size() != oldSize)
+ LOG(LINFO, ("Old =", oldSize, "; New =", res.size()));
+ res.swap(m_res[ind]);
+#endif
+ break;
+ }
+
+ case FullCover:
+ m_res[ind].push_back(
+ Intervals::value_type(0, static_cast<int64_t>((uint64_t{1} << 63) - 1)));
+ break;
+ }
+ }
+
+ return m_res[ind];
+ }
+};
}