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

locality_object.hpp « indexer - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 27c50b5093da03c87a1aaae15c6885c2f076ba73 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#pragma once

#include "geometry/point2d.hpp"
#include "geometry/polygon.hpp"
#include "geometry/rect2d.hpp"

#include "coding/geometry_coding.hpp"

#include "base/buffer_vector.hpp"
#include "base/geo_object_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 base::GeoObjectId FromStoredId(uint64_t storedId)
  {
    return base::GeoObjectId(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]);
  }

  void SetForTesting(uint64_t id, m2::PointD point)
  {
    m_id = id;
    m_points.clear();
    m_points.push_back(point);
  }

  void SetForTesting(uint64_t id, m2::RectD rect)
  {
    m_id = id;

    m_points.clear();
    m_points.push_back(rect.LeftBottom());
    m_points.push_back(rect.RightBottom());
    m_points.push_back(rect.RightTop());
    m_points.push_back(rect.LeftTop());

    buffer_vector<m2::PointD, 32> strip;
    auto const index = FindSingleStrip(
        m_points.size(), IsDiagonalVisibleFunctor<std::vector<m2::PointD>::const_iterator>(
                             m_points.begin(), m_points.end()));
    MakeSingleStripFromIndex(index, m_points.size(),
                             [&](size_t i) { strip.push_back(m_points[i]); });
    serial::StripToTriangles(strip.size(), strip, m_triangles);
  }

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