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-01-29 13:02:24 +0300
committermpimenov <mpimenov@users.noreply.github.com>2018-02-01 18:13:38 +0300
commite2db212ab16e5af127981d778834548a7dbe56b8 (patch)
tree8a4d43017f93a393505ceaac077df7ffb43bfe61 /indexer/locality_object.hpp
parent78d0770c040289e6a0e96792c8a933418d7ebbad (diff)
Add LocalityIndexBuilder
Diffstat (limited to 'indexer/locality_object.hpp')
-rw-r--r--indexer/locality_object.hpp47
1 files changed, 47 insertions, 0 deletions
diff --git a/indexer/locality_object.hpp b/indexer/locality_object.hpp
new file mode 100644
index 0000000000..b89b030ec2
--- /dev/null
+++ b/indexer/locality_object.hpp
@@ -0,0 +1,47 @@
+#pragma once
+
+#include "geometry/point2d.hpp"
+
+#include "base/buffer_vector.hpp"
+#include "base/osm_id.hpp"
+
+#include <cstdint>
+#include <vector>
+
+namespace indexer
+{
+// Class for intermediate objects used to build LocalityIndex.
+class LocalityObject
+{
+public:
+ // Decodes id stored in LocalityIndex. See GetStoredId().
+ static osm::Id FromStoredId(uint64_t storedId) { return osm::Id(storedId >> 2 | storedId << 62); }
+
+ // We need LocalityIndex object id to be at most numeric_limits<int64_t>::max().
+ // We use incremental encoding for ids and need to keep ids of close object close if it is possible.
+ // To ensure it we move two leading bits which encodes object type to the end of id.
+ uint64_t GetStoredId() const { return m_id << 2 | m_id >> 62; }
+
+ void Deserialize(char const * data);
+
+ template <typename ToDo>
+ void ForEachPoint(ToDo && toDo) const
+ {
+ for (auto const & p : m_points)
+ toDo(p);
+ }
+
+ template <typename ToDo>
+ void ForEachTriangle(ToDo && toDo) const
+ {
+ for (size_t i = 2; i < m_triangles.size(); i += 3)
+ toDo(m_triangles[i - 2], m_triangles[i - 1], m_triangles[i]);
+ }
+
+private:
+ uint64_t m_id = 0;
+ std::vector<m2::PointD> m_points;
+ // m_triangles[3 * i], m_triangles[3 * i + 1], m_triangles[3 * i + 2] form the i-th triangle.
+ buffer_vector<m2::PointD, 32> m_triangles;
+};
+} // namespace indexer