ReUseX  0.0.5
3D Point Cloud Processing for Building Reuse
Loading...
Searching...
No Matches
reusex::gsplat Namespace Reference

Classes

struct  EvalMetrics
 One held-out evaluation pass. More...
struct  GaussianCloud
 A set of 3D Gaussians in plain host memory. More...
struct  GaussianInitOptions
 Parameters for seeding Gaussians from a ReUseX point cloud. More...
struct  GsplatStageOptions
 End-to-end options for the rux create gsplat stage. More...
struct  MCMCOptions
 3DGS-MCMC density control (Kheradmand et al. More...
struct  TrainingView
 One posed training image for the Gaussian-splatting optimizer. More...
struct  TrainingViewOptions
 Selection and preprocessing knobs for building the training set. More...
struct  TrainMetrics
 One row of the loss history. More...
struct  TrainOptions
 Optimizer / schedule parameters for the 3DGS training loop. More...
struct  TrainResult

Functions

float rgb_to_sh_dc (float c)
 RGB in [0,1] -> degree-0 SH coefficient.
float sh_dc_to_rgb (float f)
 Degree-0 SH coefficient -> RGB in [0,1] (not clamped).
float inverse_sigmoid (float x)
 Numerically safe logit, the inverse of the sigmoid used for opacity.
GaussianCloud init_from_point_cloud (const CloudPtr &cloud, const GaussianInitOptions &opt={})
 Seed Gaussians from an XYZRGB cloud: means = point positions, DC colour = point colour, scale = log of the k-NN mean spacing, rotation = identity, opacity = logit(initial_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 implementation and every common viewer expect: x/y/z, nx/ny/nz, f_dc_*, f_rest_*, opacity, scale_*, rot_*).
void save_gaussian_ply (const GaussianCloud &gaussians, const std::filesystem::path &path)
 Write the bytes of gaussian_ply_bytes() to path.
GaussianCloud load_gaussian_ply (const std::filesystem::path &path)
 Read back a .ply written by save_gaussian_ply.
bool is_available ()
 True when this build actually contains the CUDA trainer.
bool has_cuda_device ()
 True when this process can actually reach a CUDA device right now.
TrainResult train_gaussians (const GaussianCloud &init, const std::vector< TrainingView > &views, const TrainOptions &opt={})
 Train Gaussians against posed views.
cv::Mat render_view (const GaussianCloud &gaussians, const TrainingView &view)
 Rasterize gaussians from view.
TrainResult run_gsplat_stage (ProjectDB &db, const GsplatStageOptions &opt)
 Load the seed cloud and views from db, train, and store the splat.
std::vector< TrainingViewload_training_views (const ProjectDB &db, const TrainingViewOptions &opt={})
 Load posed training views from a project.

Variables

constexpr float kShC0 = 0.28209479177387814f
 The 3D Gaussian Splatting DC spherical-harmonic basis function value, 0.5 * sqrt(1/pi).

Function Documentation

◆ gaussian_ply_bytes()

std::vector< std::uint8_t > reusex::gsplat::gaussian_ply_bytes ( const GaussianCloud & gaussians)

Serialize to a 3DGS-format binary-little-endian .ply in memory (the property names the reference implementation and every common viewer expect: x/y/z, nx/ny/nz, f_dc_*, f_rest_*, opacity, scale_*, rot_*).

Exists as its own function because the trained splat has two destinations and they must be byte-identical: ProjectDB (where the stage stores it, #322) and an optional --out file. Serializing twice would be two chances to diverge; writing the file and re-reading it would be an extra pass over hundreds of megabytes.

Exceptions
std::runtime_errorif gaussians is empty or fails validation.

◆ has_cuda_device()

bool reusex::gsplat::has_cuda_device ( )

True when this process can actually reach a CUDA device right now.

is_available() answers "was the trainer compiled in"; this answers "is there a GPU to run it on", which is what a [gpu]-tagged test needs in order to SKIP honestly instead of failing.

◆ init_from_point_cloud()

GaussianCloud reusex::gsplat::init_from_point_cloud ( const CloudPtr & cloud,
const GaussianInitOptions & opt = {} )

Seed Gaussians from an XYZRGB cloud: means = point positions, DC colour = point colour, scale = log of the k-NN mean spacing, rotation = identity, opacity = logit(initial_opacity).

Exceptions
std::runtime_errorif cloud is null or empty.

◆ inverse_sigmoid()

float reusex::gsplat::inverse_sigmoid ( float x)

Numerically safe logit, the inverse of the sigmoid used for opacity.

◆ is_available()

bool reusex::gsplat::is_available ( )

True when this build actually contains the CUDA trainer.

Always true in a translation unit that can link reusex_gsplat; provided so callers can report the capability without an #ifdef of their own.

◆ load_gaussian_ply()

GaussianCloud reusex::gsplat::load_gaussian_ply ( const std::filesystem::path & path)

Read back a .ply written by save_gaussian_ply.

◆ load_training_views()

std::vector< TrainingView > reusex::gsplat::load_training_views ( const ProjectDB & db,
const TrainingViewOptions & opt = {} )

Load posed training views from a project.

Sensor-frame poses go through the same composition the COLMAP exporter uses: ProjectDB stores pose = T_wb (sensor base in world) and intrinsics carry local_transform = T_bc, so T_wc = T_wb * T_bc and T_cw = (T_wc)^{-1}. Panorama slices use T_w_slice = T_w_pano * [R_pano_from_view | 0].

Frames without a colour image or with degenerate intrinsics are skipped with a debug/warn line rather than silently dropped.

Exceptions
std::runtime_errorif the project yields no usable view.

◆ render_view()

cv::Mat reusex::gsplat::render_view ( const GaussianCloud & gaussians,
const TrainingView & view )

Rasterize gaussians from view.

Returns a BGR8 image the same size as the view, suitable for cv::imwrite. Requires CUDA.

◆ rgb_to_sh_dc()

float reusex::gsplat::rgb_to_sh_dc ( float c)
inline

RGB in [0,1] -> degree-0 SH coefficient.

Definition at line 24 of file GaussianCloud.hpp.

References kShC0.

◆ run_gsplat_stage()

TrainResult reusex::gsplat::run_gsplat_stage ( ProjectDB & db,
const GsplatStageOptions & opt )

Load the seed cloud and views from db, train, and store the splat.

The trained model is written into db under GsplatStageOptions:: splat_name (schema v12), and additionally to out_ply when one is given. Both get the identical bytes, from one call to gaussian_ply_bytes().

db is therefore non-const for two reasons: the splat itself, and the pipeline_log start and finish rows every other create stage writes — rux log is how a user reconstructs what produced a project, and a stage that runs for hours without appearing there is invisible. All project data is read-only.

A run cancelled through TrainOptions::cancel_token still stores its splat — salvaging the model is the entire point of cancelling rather than killing the process — and closes its pipeline_log row as a success carrying a "CANCELLED" note (see the comment at the call site for why not a failure).

Exceptions
std::runtime_errorif splat_name is empty, if checkpointing is enabled with nowhere to put the files, or if the seed cloud is missing — all before any training happens, because a long run whose output is silently discarded is worse than a refusal.

◆ save_gaussian_ply()

void reusex::gsplat::save_gaussian_ply ( const GaussianCloud & gaussians,
const std::filesystem::path & path )

Write the bytes of gaussian_ply_bytes() to path.

◆ sh_dc_to_rgb()

float reusex::gsplat::sh_dc_to_rgb ( float f)
inline

Degree-0 SH coefficient -> RGB in [0,1] (not clamped).

Definition at line 27 of file GaussianCloud.hpp.

References kShC0.

◆ train_gaussians()

TrainResult reusex::gsplat::train_gaussians ( const GaussianCloud & init,
const std::vector< TrainingView > & views,
const TrainOptions & opt = {} )

Train Gaussians against posed views.

Requires a CUDA device. All parameters (means, log-scales, quaternions, logit-opacity, SH DC) are optimized jointly with Adam; the photometric loss is L1 + D-SSIM against one randomly drawn view per iteration.

Exceptions
std::runtime_errorif no CUDA device is available, if views is empty, or if init contains no Gaussians.

Variable Documentation

◆ kShC0

float reusex::gsplat::kShC0 = 0.28209479177387814f
inlineconstexpr

The 3D Gaussian Splatting DC spherical-harmonic basis function value, 0.5 * sqrt(1/pi).

Converting between a linear RGB colour in [0,1] and the degree-0 SH coefficient stored per Gaussian goes through it in both directions (see rgb_to_sh_dc / sh_dc_to_rgb).

Definition at line 21 of file GaussianCloud.hpp.

Referenced by rgb_to_sh_dc(), and sh_dc_to_rgb().