Cogs.Core
OGC3DTiles.h
1#pragma once
2
3#include <array>
4#include <vector>
5#include <string>
6#include <cstdint>
7
8namespace Cogs::Core::OGC3DTiles {
9 struct Coord {
10 int32_t level = 0;
11 int32_t x = 0;
12 int32_t y = 0;
13 int32_t z = -1; // -1 => This is a quad-subtree. Ignore the 'z'
14
15 bool operator==(OGC3DTiles::Coord const& other) const = default;
16
17 std::string toString() const {
18 std::string s = std::to_string(this->level);
19 s += ":";
20 s += std::to_string(this->x);
21 s += "|";
22 s += std::to_string(this->y);
23 if (this->z >= 0) {
24 s += "|";
25 s += std::to_string(this->z);
26 }
27 return s;
28 }
29
30 uint64_t toHash() const {
31 // X, Y, Z gets 19 bits each, LEVEL gets 7 bits.
32 uint64_t result =
33 (uint64_t(this->level) << (64 - 7)) +
34 (uint64_t(this->x) << (19 << 1)) +
35 (uint64_t(this->y) << 19);
36
37 result += this->z >= 0 ? uint64_t(this->z) : 0b1111111111111111111;
38
39 return result;
40 }
41
42 static Coord fromHash(uint64_t h) {
43 Coord c;
44 c.level = int32_t(h >> (64 - 7));
45 c.x = int32_t(h >> (19 * 2)) & 0b1111111111111111111;
46 c.y = int32_t(h >> 19) & 0b1111111111111111111;
47 const int32_t z = int32_t(h & 0b1111111111111111111);
48 c.z = z == 0b1111111111111111111 ? -1 : z;
49
50 return c;
51 }
52 };
53
54 enum class BoundingVolumeType { UNKNOWN, BOX, REGION, SPHERE };
55
57 BoundingVolumeType type;
58 std::array<double, 12> values;
59
60 std::string toString() const {
61 int num = 0;
62 std::string s;
63 if (this->type == BoundingVolumeType::BOX) {
64 s = "Box:[";
65 num = 12;
66 }
67 else if (this->type == BoundingVolumeType::REGION) {
68 s = "Region:[";
69 num = 6;
70 }
71 else if (this->type == BoundingVolumeType::SPHERE) {
72 s = "Sphere:[";
73 num = 4;
74 }
75
76 if (num != 0) {
77 for (int i = 0; i < num; ++i) {
78 s += std::to_string(this->values[i]) + ", ";
79 }
80 return s + "]";
81 }
82
83 return "Invalid BoundingVolume";
84 }
85 };
86}