Rerun C++ SDK
Loading...
Searching...
No Matches
gaussian_splats3d.hpp
1// DO NOT EDIT! This file was auto-generated by crates/build/re_types_builder/src/codegen/cpp/mod.rs
2// Based on "crates/build/re_type_definitions/rerun/archetypes/gaussian_splats3d.def.rs".
3
4#pragma once
5
6#include "../archetype_utils.hpp"
7#include "../collection.hpp"
8#include "../component_batch.hpp"
9#include "../component_column.hpp"
10#include "../components/color.hpp"
11#include "../components/position3d.hpp"
12#include "../components/rotation_quat.hpp"
13#include "../components/scale3d.hpp"
14#include "../components/spherical_harmonics3rgb.hpp"
15#include "../components/spherical_harmonics_degree.hpp"
16#include "../result.hpp"
17
18#include <cstdint>
19#include <optional>
20#include <utility>
21#include <vector>
22
23namespace rerun::archetypes {
24 /// **Archetype**: 3D gaussian splats, e.g. from a 3D Gaussian Splatting (3DGS) reconstruction.
25 ///
26 /// Each gaussian is an anisotropic 3D gaussian distribution:
27 /// a unit isotropic gaussian scaled per-axis, rotated, and translated.
28 /// The scales are the standard deviations along the principal axes, in scene units.
29 ///
30 /// Note that unlike 3DGS training checkpoints (e.g. PLY files), all values are stored
31 /// in their natural form: linear scales, and base colors with opacity as RGBA.
32 ///
33 /// ## Examples
34 ///
35 /// ### Log a few gaussian splats
36 /// ```cpp
37 /// #include <rerun.hpp>
38 ///
39 /// int main(int argc, char* argv[]) {
40 /// const auto rec = rerun::RecordingStream("rerun_example_gaussian_splats3d");
41 /// rec.spawn().exit_on_failure();
42 ///
43 /// // 15 view-dependent RGB coefficients (degrees 1-3) per splat, coefficient-major:
44 /// std::array<std::array<float, 3>, 15> red_sh, green_sh, blue_sh;
45 /// red_sh.fill({0.5f, 0.0f, 0.0f});
46 /// green_sh.fill({0.0f, 0.5f, 0.0f});
47 /// blue_sh.fill({0.0f, 0.0f, 0.5f});
48 ///
49 /// rec.log(
50 /// "gaussians",
51 /// rerun::GaussianSplats3D(
52 /// {{0.0f, 0.0f, 0.0f}, {2.0f, 0.0f, 0.0f}, {4.0f, 0.0f, 0.0f}}
53 /// )
54 /// .with_scales(
55 /// {{1.0f, 0.5f, 0.25f}, {0.5f, 1.0f, 0.5f}, {0.25f, 0.5f, 1.0f}}
56 /// )
57 /// .with_quaternions({
58 /// rerun::Quaternion::IDENTITY,
59 /// // 45 degrees around Z
60 /// rerun::Quaternion::from_xyzw(0.0f, 0.0f, 0.382683f, 0.923880f),
61 /// rerun::Quaternion::IDENTITY,
62 /// })
63 /// .with_colors({
64 /// rerun::Rgba32(255, 0, 0, 128),
65 /// rerun::Rgba32(0, 255, 0, 200),
66 /// rerun::Rgba32(0, 0, 255, 255),
67 /// })
68 /// .with_sh_coefficients({
69 /// rerun::encodings::SphericalHarmonics3Rgb(red_sh),
70 /// rerun::encodings::SphericalHarmonics3Rgb(green_sh),
71 /// rerun::encodings::SphericalHarmonics3Rgb(blue_sh),
72 /// })
73 /// );
74 /// }
75 /// ```
76 ///
77 /// ### Log a 3D gaussian splatting (3DGS) PLY file
78 /// ```cpp
79 /// #include <rerun.hpp>
80 ///
81 /// #include <iostream>
82 ///
83 /// int main(int argc, char* argv[]) {
84 /// if (argc <2) {
85 /// std::cerr <<"Usage: " <<argv[0] <<" <path_to_splats.ply>"
86 /// <<std::endl;
87 /// return 1;
88 /// }
89 ///
90 /// const auto path = argv[1];
91 ///
92 /// const auto rec =
93 /// rerun::RecordingStream("rerun_example_gaussian_splats3d_ply");
94 /// rec.spawn().exit_on_failure();
95 ///
96 /// rec.log_file_from_path(path);
97 /// }
98 /// ```
99 ///
100 /// ⚠ **This type is _unstable_ and may change significantly in a way that the data won't be backwards compatible.**
101 ///
103 /// The centers (means) of the gaussians.
104 std::optional<ComponentBatch> centers;
105
106 /// Per-axis standard deviations of the gaussians, in scene units.
107 std::optional<ComponentBatch> scales;
108
109 /// The orientations of the gaussians.
110 std::optional<ComponentBatch> quaternions;
111
112 /// The base colors and opacities of the gaussians.
113 ///
114 /// The RGB part is the view-independent base color, i.e. the degree-0 (DC) term of the spherical harmonics.
115 /// The alpha part is the peak opacity of the gaussian; the gaussian falloff further modulates it spatially.
116 std::optional<ComponentBatch> colors;
117
118 /// Higher-order spherical harmonics coefficients for view-dependent color.
119 std::optional<ComponentBatch> sh_coefficients;
120
121 /// The highest spherical harmonics degree to evaluate when rendering, 0-3.
122 ///
123 /// Lower values render faster; `0` disables view-dependent color entirely.
124 /// If not set, defaults to 3, i.e. all coefficients present in the data are used.
125 std::optional<ComponentBatch> spherical_harmonics_degree;
126
127 public:
128 /// The name of the archetype as used in `ComponentDescriptor`s.
129 static constexpr const char ArchetypeName[] = "rerun.archetypes.GaussianSplats3D";
130
131 /// `ComponentDescriptor` for the `centers` field.
133 ArchetypeName, "GaussianSplats3D:centers",
135 );
136 /// `ComponentDescriptor` for the `scales` field.
137 static constexpr auto Descriptor_scales = ComponentDescriptor(
138 ArchetypeName, "GaussianSplats3D:scales",
140 );
141 /// `ComponentDescriptor` for the `quaternions` field.
143 ArchetypeName, "GaussianSplats3D:quaternions",
145 );
146 /// `ComponentDescriptor` for the `colors` field.
147 static constexpr auto Descriptor_colors = ComponentDescriptor(
148 ArchetypeName, "GaussianSplats3D:colors",
150 );
151 /// `ComponentDescriptor` for the `sh_coefficients` field.
153 ArchetypeName, "GaussianSplats3D:sh_coefficients",
155 );
156 /// `ComponentDescriptor` for the `spherical_harmonics_degree` field.
158 ArchetypeName, "GaussianSplats3D:spherical_harmonics_degree",
160 );
161
162 public:
163 GaussianSplats3D() = default;
164 GaussianSplats3D(GaussianSplats3D&& other) = default;
165 GaussianSplats3D(const GaussianSplats3D& other) = default;
166 GaussianSplats3D& operator=(const GaussianSplats3D& other) = default;
167 GaussianSplats3D& operator=(GaussianSplats3D&& other) = default;
168
170 : centers(ComponentBatch::from_loggable(std::move(_centers), Descriptor_centers)
171 .value_or_throw()) {}
172
173 /// Update only some specific fields of a `GaussianSplats3D`.
175 return GaussianSplats3D();
176 }
177
178 /// Clear all the fields of a `GaussianSplats3D`.
180
181 /// The centers (means) of the gaussians.
183 ) && {
184 centers = ComponentBatch::from_loggable(_centers, Descriptor_centers).value_or_throw();
185 return std::move(*this);
186 }
187
188 /// Per-axis standard deviations of the gaussians, in scene units.
190 scales = ComponentBatch::from_loggable(_scales, Descriptor_scales).value_or_throw();
191 return std::move(*this);
192 }
193
194 /// The orientations of the gaussians.
197 ) && {
199 .value_or_throw();
200 return std::move(*this);
201 }
202
203 /// The base colors and opacities of the gaussians.
204 ///
205 /// The RGB part is the view-independent base color, i.e. the degree-0 (DC) term of the spherical harmonics.
206 /// The alpha part is the peak opacity of the gaussian; the gaussian falloff further modulates it spatially.
208 colors = ComponentBatch::from_loggable(_colors, Descriptor_colors).value_or_throw();
209 return std::move(*this);
210 }
211
212 /// Higher-order spherical harmonics coefficients for view-dependent color.
215 ) && {
218 .value_or_throw();
219 return std::move(*this);
220 }
221
222 /// The highest spherical harmonics degree to evaluate when rendering, 0-3.
223 ///
224 /// Lower values render faster; `0` disables view-dependent color entirely.
225 /// If not set, defaults to 3, i.e. all coefficients present in the data are used.
227 const rerun::components::SphericalHarmonicsDegree& _spherical_harmonics_degree
228 ) && {
230 _spherical_harmonics_degree,
232 )
233 .value_or_throw();
234 return std::move(*this);
235 }
236
237 /// This method makes it possible to pack multiple `spherical_harmonics_degree` in a single component batch.
238 ///
239 /// This only makes sense when used in conjunction with `columns`. `with_spherical_harmonics_degree` should
240 /// be used when logging a single row's worth of data.
243 _spherical_harmonics_degree
244 ) && {
246 _spherical_harmonics_degree,
248 )
249 .value_or_throw();
250 return std::move(*this);
251 }
252
253 /// Partitions the component data into multiple sub-batches.
254 ///
255 /// Specifically, this transforms the existing `ComponentBatch` data into `ComponentColumn`s
256 /// instead, via `ComponentBatch::partitioned`.
257 ///
258 /// This makes it possible to use `RecordingStream::send_columns` to send columnar data directly into Rerun.
259 ///
260 /// The specified `lengths` must sum to the total length of the component batch.
262 return detail::partition_batches(
263 {&centers,
264 &scales,
266 &colors,
269 lengths_
270 )
271 .value_or_throw();
272 }
273
274 /// Partitions the component data into unit-length sub-batches.
275 ///
276 /// This is semantically similar to calling `columns` with `std::vector<uint32_t>(n, 1)`,
277 /// where `n` is automatically guessed.
279 return detail::partition_batches_of_unit_length({&centers,
280 &scales,
282 &colors,
285 .value_or_throw();
286 }
287 };
288
289} // namespace rerun::archetypes
290
291namespace rerun {
292 /// \private
293 template <typename T>
294 struct AsComponents;
295
296 /// \private
297 template <>
298 struct AsComponents<archetypes::GaussianSplats3D> {
299 /// Serialize all set component batches.
300 static Result<Collection<ComponentBatch>> as_batches(
301 const archetypes::GaussianSplats3D& archetype
302 ) {
303 return detail::collect_batches(
304 {&archetype.centers,
305 &archetype.scales,
306 &archetype.quaternions,
307 &archetype.colors,
308 &archetype.sh_coefficients,
309 &archetype.spherical_harmonics_degree}
310 );
311 }
312 };
313} // namespace rerun
Generic collection of elements that are roughly contiguous in memory.
Definition collection.hpp:49
All built-in archetypes. See Types in the Rerun manual.
Definition rerun.hpp:90
All Rerun C++ types and functions are in the rerun namespace or one of its nested namespaces.
Definition rerun.hpp:26
Arrow-encoded data of a single batch of components together with a component descriptor.
Definition component_batch.hpp:28
static Result< ComponentBatch > from_loggable(const rerun::Collection< T > &components, const ComponentDescriptor &descriptor)
Creates a new component batch from a collection of component instances.
Definition component_batch.hpp:46
A ComponentDescriptor fully describes the semantics of a column of data.
Definition component_descriptor.hpp:16
The Loggable trait is used by all built-in implementation of rerun::AsComponents to serialize a colle...
Definition loggable.hpp:11
Archetype: 3D gaussian splats, e.g.
Definition gaussian_splats3d.hpp:102
GaussianSplats3D with_centers(const Collection< rerun::components::Position3D > &_centers) &&
The centers (means) of the gaussians.
Definition gaussian_splats3d.hpp:182
static GaussianSplats3D update_fields()
Update only some specific fields of a GaussianSplats3D.
Definition gaussian_splats3d.hpp:174
std::optional< ComponentBatch > centers
The centers (means) of the gaussians.
Definition gaussian_splats3d.hpp:104
std::optional< ComponentBatch > colors
The base colors and opacities of the gaussians.
Definition gaussian_splats3d.hpp:116
std::optional< ComponentBatch > sh_coefficients
Higher-order spherical harmonics coefficients for view-dependent color.
Definition gaussian_splats3d.hpp:119
GaussianSplats3D with_colors(const Collection< rerun::components::Color > &_colors) &&
The base colors and opacities of the gaussians.
Definition gaussian_splats3d.hpp:207
std::optional< ComponentBatch > spherical_harmonics_degree
The highest spherical harmonics degree to evaluate when rendering, 0-3.
Definition gaussian_splats3d.hpp:125
static constexpr const char ArchetypeName[]
The name of the archetype as used in ComponentDescriptors.
Definition gaussian_splats3d.hpp:129
static constexpr auto Descriptor_sh_coefficients
ComponentDescriptor for the sh_coefficients field.
Definition gaussian_splats3d.hpp:152
std::optional< ComponentBatch > scales
Per-axis standard deviations of the gaussians, in scene units.
Definition gaussian_splats3d.hpp:107
GaussianSplats3D with_spherical_harmonics_degree(const rerun::components::SphericalHarmonicsDegree &_spherical_harmonics_degree) &&
The highest spherical harmonics degree to evaluate when rendering, 0-3.
Definition gaussian_splats3d.hpp:226
static constexpr auto Descriptor_colors
ComponentDescriptor for the colors field.
Definition gaussian_splats3d.hpp:147
Collection< ComponentColumn > columns()
Partitions the component data into unit-length sub-batches.
Definition gaussian_splats3d.hpp:278
static constexpr auto Descriptor_quaternions
ComponentDescriptor for the quaternions field.
Definition gaussian_splats3d.hpp:142
static constexpr auto Descriptor_spherical_harmonics_degree
ComponentDescriptor for the spherical_harmonics_degree field.
Definition gaussian_splats3d.hpp:157
GaussianSplats3D with_sh_coefficients(const Collection< rerun::components::SphericalHarmonics3Rgb > &_sh_coefficients) &&
Higher-order spherical harmonics coefficients for view-dependent color.
Definition gaussian_splats3d.hpp:213
GaussianSplats3D with_scales(const Collection< rerun::components::Scale3D > &_scales) &&
Per-axis standard deviations of the gaussians, in scene units.
Definition gaussian_splats3d.hpp:189
static GaussianSplats3D clear_fields()
Clear all the fields of a GaussianSplats3D.
static constexpr auto Descriptor_centers
ComponentDescriptor for the centers field.
Definition gaussian_splats3d.hpp:132
Collection< ComponentColumn > columns(const Collection< uint32_t > &lengths_)
Partitions the component data into multiple sub-batches.
Definition gaussian_splats3d.hpp:261
GaussianSplats3D with_many_spherical_harmonics_degree(const Collection< rerun::components::SphericalHarmonicsDegree > &_spherical_harmonics_degree) &&
This method makes it possible to pack multiple spherical_harmonics_degree in a single component batch...
Definition gaussian_splats3d.hpp:241
static constexpr auto Descriptor_scales
ComponentDescriptor for the scales field.
Definition gaussian_splats3d.hpp:137
GaussianSplats3D with_quaternions(const Collection< rerun::components::RotationQuat > &_quaternions) &&
The orientations of the gaussians.
Definition gaussian_splats3d.hpp:195
std::optional< ComponentBatch > quaternions
The orientations of the gaussians.
Definition gaussian_splats3d.hpp:110
Component: The highest spherical harmonics degree to evaluate when rendering, 0-3.
Definition spherical_harmonics_degree.hpp:26