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