ReUseX  0.0.5
3D Point Cloud Processing for Building Reuse
Loading...
Searching...
No Matches
GaussianCloud.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#include <array>
8#include <cstddef>
9#include <cstdint>
10#include <filesystem>
11#include <vector>
12
13#include <reusex/types/point_types.hpp>
14
15namespace reusex::gsplat {
16
21inline constexpr float kShC0 = 0.28209479177387814f;
22
24inline float rgb_to_sh_dc(float c) { return (c - 0.5f) / kShC0; }
25
27inline float sh_dc_to_rgb(float f) { return f * kShC0 + 0.5f; }
28
30float inverse_sigmoid(float x);
31
48 std::vector<std::array<float, 3>> means;
49 std::vector<std::array<float, 3>> scales;
50 std::vector<std::array<float, 4>> quats;
51 std::vector<float> opacities;
52 std::vector<std::array<float, 3>> sh_dc;
54 std::vector<std::vector<float>> sh_rest;
55 int sh_degree = 0;
56
57 std::size_t size() const { return means.size(); }
58 bool empty() const { return means.empty(); }
59
61 void validate() const;
62};
63
69 int knn = 3;
70
72 float initial_opacity = 0.1f;
73
77 float min_scale = 1e-4f;
78 float max_scale = 0.5f;
79
82 int sh_degree = 0;
83
89 std::size_t max_points = 0;
90};
91
98 const GaussianInitOptions &opt = {});
99
111std::vector<std::uint8_t> gaussian_ply_bytes(const GaussianCloud &gaussians);
112
114void save_gaussian_ply(const GaussianCloud &gaussians,
115 const std::filesystem::path &path);
116
118GaussianCloud load_gaussian_ply(const std::filesystem::path &path);
119
120} // namespace reusex::gsplat
GaussianCloud load_gaussian_ply(const std::filesystem::path &path)
Read back a .ply written by save_gaussian_ply.
float sh_dc_to_rgb(float f)
Degree-0 SH coefficient -> RGB in [0,1] (not clamped).
GaussianCloud init_from_point_cloud(const CloudPtr &cloud, const GaussianInitOptions &opt={})
Seed Gaussians from an XYZRGB cloud: means = point positions, DC colour = point colour,...
constexpr float kShC0
The 3D Gaussian Splatting DC spherical-harmonic basis function value, 0.5 * sqrt(1/pi).
float inverse_sigmoid(float x)
Numerically safe logit, the inverse of the sigmoid used for opacity.
std::vector< std::uint8_t > gaussian_ply_bytes(const GaussianCloud &gaussians)
Serialize to a 3DGS-format binary-little-endian .ply in memory (the property names the reference impl...
float rgb_to_sh_dc(float c)
RGB in [0,1] -> degree-0 SH coefficient.
void save_gaussian_ply(const GaussianCloud &gaussians, const std::filesystem::path &path)
Write the bytes of gaussian_ply_bytes() to path.
typename Cloud::Ptr CloudPtr
A set of 3D Gaussians in plain host memory.
std::vector< std::array< float, 3 > > scales
log-scales, per axis
int sh_degree
active SH degree (0 = DC only)
std::vector< float > opacities
logit-opacity
std::vector< std::array< float, 4 > > quats
rotation (w, x, y, z)
void validate() const
Throws std::runtime_error naming the first array whose length disagrees.
std::vector< std::array< float, 3 > > means
world-space centres [m]
std::vector< std::array< float, 3 > > sh_dc
degree-0 SH per channel
std::vector< std::vector< float > > sh_rest
Higher-order SH, [N][(sh_bands-1)*3] flattened; empty when degree 0.
Parameters for seeding Gaussians from a ReUseX point cloud.
int knn
Neighbours used for the nearest-neighbour spacing that sets the initial (isotropic) scale of each Gau...
float initial_opacity
Initial alpha before the logit transform.
float min_scale
Clamp on the initial scale [m].
std::size_t max_points
Uniform stride cap on the number of seeds (0 = use every point).