ReUseX  0.0.5
3D Point Cloud Processing for Building Reuse
Loading...
Searching...
No Matches
tile_index.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 Povl Filip Sonne-Frederiksen
2//
3// SPDX-License-Identifier: GPL-3.0-or-later
4
5#pragma once
6
7// Spatial tile index for Morton-ordered clouds (#395, #396).
8//
9// The index is a blob stored beside a `morton_10bit_bitrev` cloud with
10// ProjectDB::save_tile_index(). The web API (ruxd's api/point_lod) reads it to
11// stream a cloud tile by tile. It is BUILT here, by the clouds stage, so every
12// path that runs that stage — `rux create clouds`, the GUI's POST /jobs, any
13// pipeline::run_stage caller — leaves the same index behind.
14
15#include <reusex/core/ProjectDB.hpp>
16
17#include <cstdint>
18#include <string_view>
19#include <utility>
20#include <vector>
21
22namespace reusex::pipeline {
23
25inline constexpr uint32_t kTileIndexMagic = 0x52555854u; // 'RUXT'
26
28inline constexpr std::string_view kMortonStorageOrder = "morton_10bit_bitrev";
29
39 uint32_t magic;
40 uint32_t version;
41 uint32_t tile_bits;
42 uint32_t point_count;
43 float lo[3];
44 float hi[3];
45};
46
48struct TileInfo {
49 float min[3];
50 float max[3];
51 uint32_t count;
52};
53
57uint32_t morton_tile_sort_key(float x, float y, float z, const float lo[3],
58 const float range[3]);
59
68std::vector<uint8_t> compute_tile_index(const ProjectDB &db,
69 std::string_view name,
70 uint32_t tile_bits = 6);
71
74std::pair<TileIndexHeader, std::vector<TileInfo>>
75parse_tile_index(const std::vector<uint8_t> &blob);
76
80std::size_t build_tile_index(ProjectDB &db, std::string_view name);
81
82} // namespace reusex::pipeline
std::pair< TileIndexHeader, std::vector< TileInfo > > parse_tile_index(const std::vector< uint8_t > &blob)
Deserialize the header + tile array from a tile index blob.
std::size_t build_tile_index(ProjectDB &db, std::string_view name)
Build and store the tile index of cloud name when it is Morton-ordered.
constexpr std::string_view kMortonStorageOrder
The storage order a cloud must have for a tile index to make sense.
std::vector< uint8_t > compute_tile_index(const ProjectDB &db, std::string_view name, uint32_t tile_bits=6)
Compute the spatial tile index for a morton_10bit_bitrev cloud.
constexpr uint32_t kTileIndexMagic
Magic number identifying a tile index blob.
uint32_t morton_tile_sort_key(float x, float y, float z, const float lo[3], const float range[3])
30-bit bit-reversed Morton sort key of (x, y, z) quantised to 10 bits per axis over the box starting ...
Header of a serialized tile index blob (version 2).
float lo[3]
Cloud bbox minimum (world coords).
uint32_t tile_bits
log2(K), so K = 2^tile_bits tiles.
float hi[3]
Cloud bbox maximum (world coords).
Per-tile AABB and point count within the tile.