Rerun C++ SDK
Loading...
Searching...
No Matches
volume3d.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/volume_3d.def.rs".
3
4#pragma once
5
6#include "../collection.hpp"
7#include "../component_batch.hpp"
8#include "../component_column.hpp"
9#include "../components/colormap.hpp"
10#include "../components/gamma_correction.hpp"
11#include "../components/optical_density.hpp"
12#include "../components/rotation_quat.hpp"
13#include "../components/tensor_data.hpp"
14#include "../components/translation3d.hpp"
15#include "../components/value_range.hpp"
16#include "../components/voxel_size.hpp"
17#include "../result.hpp"
18
19#include <cstdint>
20#include <optional>
21#include <utility>
22#include <vector>
23
24namespace rerun::archetypes {
25 /// **Archetype**: A dense 3D scalar field, rendered by ray marching.
26 ///
27 /// This archetype is intended for volumetric scans and simulations, e.g. CT/MRI scans,
28 /// signed distance fields, or occupancy probabilities sampled on a regular grid.
29 ///
30 /// The values are a 3D tensor with dimensions ordered `[z, y, x]`, i.e. the last dimension varies
31 /// fastest and runs along the local X axis. This matches the row-major layout of
32 /// `archetypes::Image`, with slices stacked along the local Z axis.
33 /// The tensor element at `[k, j, i]` is thus the voxel with grid index `[i, j, k]`.
34 ///
35 /// Voxels are positioned exactly like those of `archetypes::VoxelGridMap`:
36 /// the minimum corner of the voxel with `[0, 0, 0]` index is located at the origin of the entity's
37 /// coordinate frame and can have an additional offset from there through the optional translation
38 /// and rotation fields, and a voxel center is at `(index + 0.5) * voxel_size` in local grid
39 /// coordinates (i.e. relative to the minimum corner).
40 /// This archetype and a `archetypes::VoxelGridMap` with the same `voxel_size` and pose
41 /// therefore agree voxel for voxel, the dense volume covering indices `[0, 0, 0]` up to
42 /// `[width - 1, height - 1, depth - 1]`.
43 ///
44 /// **WebGL limitation:** The viewer is not able to clip volumes against opaque scene geometry.
45 /// Parts of a volume can therefore appear in front of objects that should hide them.
46 ///
47 /// ## Example
48 ///
49 /// ### Simple volume
50 /// ```cpp
51 /// #include <rerun.hpp>
52 ///
53 /// #include <algorithm> // std::max
54 /// #include <vector>
55 ///
56 /// constexpr size_t SIZE = 32;
57 /// constexpr float RADIUS = 14.0f;
58 ///
59 /// int main(int argc, char* argv[]) {
60 /// const auto rec = rerun::RecordingStream("rerun_example_volume3d_simple");
61 /// rec.spawn().exit_on_failure();
62 ///
63 /// // Dimensions are ordered `[z, y, x]`. Only `f16` values are supported for now.
64 /// std::vector<rerun::half> values;
65 /// values.reserve(SIZE * SIZE * SIZE);
66 /// for (size_t z = 0; z <SIZE; ++z) {
67 /// for (size_t y = 0; y <SIZE; ++y) {
68 /// for (size_t x = 0; x <SIZE; ++x) {
69 /// // Squared distance from the center of the grid, in voxel units.
70 /// const float center = 0.5f * static_cast<float>(SIZE - 1);
71 /// const float dx = static_cast<float>(x) - center;
72 /// const float dy = static_cast<float>(y) - center;
73 /// const float dz = static_cast<float>(z) - center;
74 /// const float distance_sq = dx * dx + dy * dy + dz * dz;
75 ///
76 /// // A soft sphere: 1 at the center, falling off to 0 at `RADIUS`.
77 /// values.push_back(rerun::half::from_float(
78 /// std::max(0.0f, 1.0f - distance_sq / (RADIUS * RADIUS))
79 /// ));
80 /// }
81 /// }
82 /// }
83 ///
84 /// rec.log(
85 /// "volume",
86 /// rerun::Volume3D({SIZE, SIZE, SIZE}, values)
87 /// .with_voxel_size(rerun::Vec3D(0.1f, 0.1f, 0.1f))
88 /// );
89 /// }
90 /// ```
91 ///
92 /// ⚠ **This type is _unstable_ and may change significantly in a way that the data won't be backwards compatible.**
93 ///
94 struct Volume3D {
95 /// The scalar value of each voxel, as a 3D tensor with dimensions ordered `[z, y, x]`.
96 ///
97 /// Currently only `f16` are supported.
98 std::optional<ComponentBatch> values;
99
100 /// The scene-unit dimensions of a single voxel cell.
101 ///
102 /// This defines the voxel size along the local grid X/Y/Z axes, and thus the total extent of the
103 /// volume: `[width, height, depth] * voxel_size`.
104 /// Anisotropic spacing (as is common for medical scans) is expressed here.
105 /// Each dimension must be finite and positive.
106 ///
107 /// Defaults to `[1.0, 1.0, 1.0]`.
108 std::optional<ComponentBatch> voxel_size;
109
110 /// Translation of the minimum corner of voxel `[0, 0, 0]`.
111 ///
112 /// Together with `components::RotationQuat`, this defines the pose of the volume
113 /// relative to the entity's coordinate frame.
114 ///
115 /// If not set, the minimum corner is placed at the origin of the entity's coordinate frame.
116 std::optional<ComponentBatch> translation;
117
118 /// Rotation of the volume via quaternion.
119 ///
120 /// Together with `components::Translation3D`, this defines the pose of the volume
121 /// relative to the entity's coordinate frame.
122 /// The rotation is around the minimum corner of voxel `[0, 0, 0]`, and is applied before the
123 /// translation.
124 std::optional<ComponentBatch> quaternion;
125
126 /// The inclusive range of voxel values to render.
127 ///
128 /// Values outside the range are ignored.
129 ///
130 /// If not specified, the range is automatically estimated from the data.
131 std::optional<ComponentBatch> value_range;
132
133 /// Gamma correction applied to normalized voxel values before colormapping and opacity calculation.
134 ///
135 /// The corrected density is `normalized_value ^ gamma`.
136 /// Must be finite and positive.
137 /// Defaults to 3.0, suppressing low-density material and emphasizing dense structures.
138 std::optional<ComponentBatch> gamma;
139
140 /// Colormap applied to the values after mapping them through `value_range` and gamma correction.
141 ///
142 /// Defaults to Turbo.
143 std::optional<ComponentBatch> colormap;
144
145 /// Dimensionless optical depth for the volume.
146 ///
147 /// For a uniform volume at the upper bound of `value_range`, this is the optical depth across one full volume-local axis.
148 /// Zero is transparent, one is about 63% opaque, and larger values are denser.
149 ///
150 /// Defaults to 1.0.
151 std::optional<ComponentBatch> optical_density;
152
153 public:
154 /// The name of the archetype as used in `ComponentDescriptor`s.
155 static constexpr const char ArchetypeName[] = "rerun.archetypes.Volume3D";
156
157 /// `ComponentDescriptor` for the `values` field.
158 static constexpr auto Descriptor_values = ComponentDescriptor(
160 );
161 /// `ComponentDescriptor` for the `voxel_size` field.
163 ArchetypeName, "Volume3D:voxel_size",
165 );
166 /// `ComponentDescriptor` for the `translation` field.
168 ArchetypeName, "Volume3D:translation",
170 );
171 /// `ComponentDescriptor` for the `quaternion` field.
173 ArchetypeName, "Volume3D:quaternion",
175 );
176 /// `ComponentDescriptor` for the `value_range` field.
178 ArchetypeName, "Volume3D:value_range",
180 );
181 /// `ComponentDescriptor` for the `gamma` field.
182 static constexpr auto Descriptor_gamma = ComponentDescriptor(
183 ArchetypeName, "Volume3D:gamma",
185 );
186 /// `ComponentDescriptor` for the `colormap` field.
189 );
190 /// `ComponentDescriptor` for the `optical_density` field.
192 ArchetypeName, "Volume3D:optical_density",
194 );
195
196 public: // START of extensions from volume3d_ext.cpp:
197 RR_DISABLE_MAYBE_UNINITIALIZED_PUSH
198
199 /// New Volume3D from dimensions and tensor buffer.
201 : Volume3D(encodings::TensorData(std::move(shape), std::move(buffer))) {}
202
203 RR_DISABLE_MAYBE_UNINITIALIZED_POP
204
205 // END of extensions from volume3d_ext.cpp, start of generated code:
206
207 public:
208 Volume3D() = default;
209 Volume3D(Volume3D&& other) = default;
210 Volume3D(const Volume3D& other) = default;
211 Volume3D& operator=(const Volume3D& other) = default;
212 Volume3D& operator=(Volume3D&& other) = default;
213
215 : values(ComponentBatch::from_loggable(std::move(_values), Descriptor_values)
216 .value_or_throw()) {}
217
218 /// Update only some specific fields of a `Volume3D`.
220 return Volume3D();
221 }
222
223 /// Clear all the fields of a `Volume3D`.
225
226 /// The scalar value of each voxel, as a 3D tensor with dimensions ordered `[z, y, x]`.
227 ///
228 /// Currently only `f16` are supported.
230 values = ComponentBatch::from_loggable(_values, Descriptor_values).value_or_throw();
231 return std::move(*this);
232 }
233
234 /// This method makes it possible to pack multiple `values` in a single component batch.
235 ///
236 /// This only makes sense when used in conjunction with `columns`. `with_values` should
237 /// be used when logging a single row's worth of data.
239 values = ComponentBatch::from_loggable(_values, Descriptor_values).value_or_throw();
240 return std::move(*this);
241 }
242
243 /// The scene-unit dimensions of a single voxel cell.
244 ///
245 /// This defines the voxel size along the local grid X/Y/Z axes, and thus the total extent of the
246 /// volume: `[width, height, depth] * voxel_size`.
247 /// Anisotropic spacing (as is common for medical scans) is expressed here.
248 /// Each dimension must be finite and positive.
249 ///
250 /// Defaults to `[1.0, 1.0, 1.0]`.
252 voxel_size =
253 ComponentBatch::from_loggable(_voxel_size, Descriptor_voxel_size).value_or_throw();
254 return std::move(*this);
255 }
256
257 /// This method makes it possible to pack multiple `voxel_size` in a single component batch.
258 ///
259 /// This only makes sense when used in conjunction with `columns`. `with_voxel_size` should
260 /// be used when logging a single row's worth of data.
262 ) && {
263 voxel_size =
264 ComponentBatch::from_loggable(_voxel_size, Descriptor_voxel_size).value_or_throw();
265 return std::move(*this);
266 }
267
268 /// Translation of the minimum corner of voxel `[0, 0, 0]`.
269 ///
270 /// Together with `components::RotationQuat`, this defines the pose of the volume
271 /// relative to the entity's coordinate frame.
272 ///
273 /// If not set, the minimum corner is placed at the origin of the entity's coordinate frame.
276 .value_or_throw();
277 return std::move(*this);
278 }
279
280 /// This method makes it possible to pack multiple `translation` in a single component batch.
281 ///
282 /// This only makes sense when used in conjunction with `columns`. `with_translation` should
283 /// be used when logging a single row's worth of data.
286 ) && {
288 .value_or_throw();
289 return std::move(*this);
290 }
291
292 /// Rotation of the volume via quaternion.
293 ///
294 /// Together with `components::Translation3D`, this defines the pose of the volume
295 /// relative to the entity's coordinate frame.
296 /// The rotation is around the minimum corner of voxel `[0, 0, 0]`, and is applied before the
297 /// translation.
299 quaternion =
300 ComponentBatch::from_loggable(_quaternion, Descriptor_quaternion).value_or_throw();
301 return std::move(*this);
302 }
303
304 /// This method makes it possible to pack multiple `quaternion` in a single component batch.
305 ///
306 /// This only makes sense when used in conjunction with `columns`. `with_quaternion` should
307 /// be used when logging a single row's worth of data.
309 ) && {
310 quaternion =
311 ComponentBatch::from_loggable(_quaternion, Descriptor_quaternion).value_or_throw();
312 return std::move(*this);
313 }
314
315 /// The inclusive range of voxel values to render.
316 ///
317 /// Values outside the range are ignored.
318 ///
319 /// If not specified, the range is automatically estimated from the data.
322 .value_or_throw();
323 return std::move(*this);
324 }
325
326 /// This method makes it possible to pack multiple `value_range` in a single component batch.
327 ///
328 /// This only makes sense when used in conjunction with `columns`. `with_value_range` should
329 /// be used when logging a single row's worth of data.
331 ) && {
333 .value_or_throw();
334 return std::move(*this);
335 }
336
337 /// Gamma correction applied to normalized voxel values before colormapping and opacity calculation.
338 ///
339 /// The corrected density is `normalized_value ^ gamma`.
340 /// Must be finite and positive.
341 /// Defaults to 3.0, suppressing low-density material and emphasizing dense structures.
343 gamma = ComponentBatch::from_loggable(_gamma, Descriptor_gamma).value_or_throw();
344 return std::move(*this);
345 }
346
347 /// This method makes it possible to pack multiple `gamma` in a single component batch.
348 ///
349 /// This only makes sense when used in conjunction with `columns`. `with_gamma` should
350 /// be used when logging a single row's worth of data.
352 gamma = ComponentBatch::from_loggable(_gamma, Descriptor_gamma).value_or_throw();
353 return std::move(*this);
354 }
355
356 /// Colormap applied to the values after mapping them through `value_range` and gamma correction.
357 ///
358 /// Defaults to Turbo.
360 colormap =
361 ComponentBatch::from_loggable(_colormap, Descriptor_colormap).value_or_throw();
362 return std::move(*this);
363 }
364
365 /// This method makes it possible to pack multiple `colormap` in a single component batch.
366 ///
367 /// This only makes sense when used in conjunction with `columns`. `with_colormap` should
368 /// be used when logging a single row's worth of data.
370 colormap =
371 ComponentBatch::from_loggable(_colormap, Descriptor_colormap).value_or_throw();
372 return std::move(*this);
373 }
374
375 /// Dimensionless optical depth for the volume.
376 ///
377 /// For a uniform volume at the upper bound of `value_range`, this is the optical depth across one full volume-local axis.
378 /// Zero is transparent, one is about 63% opaque, and larger values are denser.
379 ///
380 /// Defaults to 1.0.
382 ) && {
385 .value_or_throw();
386 return std::move(*this);
387 }
388
389 /// This method makes it possible to pack multiple `optical_density` in a single component batch.
390 ///
391 /// This only makes sense when used in conjunction with `columns`. `with_optical_density` should
392 /// be used when logging a single row's worth of data.
395 ) && {
398 .value_or_throw();
399 return std::move(*this);
400 }
401
402 /// Partitions the component data into multiple sub-batches.
403 ///
404 /// Specifically, this transforms the existing `ComponentBatch` data into `ComponentColumn`s
405 /// instead, via `ComponentBatch::partitioned`.
406 ///
407 /// This makes it possible to use `RecordingStream::send_columns` to send columnar data directly into Rerun.
408 ///
409 /// The specified `lengths` must sum to the total length of the component batch.
411
412 /// Partitions the component data into unit-length sub-batches.
413 ///
414 /// This is semantically similar to calling `columns` with `std::vector<uint32_t>(n, 1)`,
415 /// where `n` is automatically guessed.
417 };
418
419} // namespace rerun::archetypes
420
421namespace rerun {
422 /// \private
423 template <typename T>
424 struct AsComponents;
425
426 /// \private
427 template <>
428 struct AsComponents<archetypes::Volume3D> {
429 /// Serialize all set component batches.
430 static Result<Collection<ComponentBatch>> as_batches(const archetypes::Volume3D& archetype);
431 };
432} // 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:90
Colormap
Component: Colormap for mapping scalar values within a given range to a color.
Definition colormap.hpp:28
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: A dense 3D scalar field, rendered by ray marching.
Definition volume3d.hpp:94
static Volume3D update_fields()
Update only some specific fields of a Volume3D.
Definition volume3d.hpp:219
Collection< ComponentColumn > columns(const Collection< uint32_t > &lengths_)
Partitions the component data into multiple sub-batches.
static constexpr auto Descriptor_gamma
ComponentDescriptor for the gamma field.
Definition volume3d.hpp:182
static constexpr auto Descriptor_translation
ComponentDescriptor for the translation field.
Definition volume3d.hpp:167
Volume3D with_many_gamma(const Collection< rerun::components::GammaCorrection > &_gamma) &&
This method makes it possible to pack multiple gamma in a single component batch.
Definition volume3d.hpp:351
Collection< ComponentColumn > columns()
Partitions the component data into unit-length sub-batches.
Volume3D with_optical_density(const rerun::components::OpticalDensity &_optical_density) &&
Dimensionless optical depth for the volume.
Definition volume3d.hpp:381
static constexpr const char ArchetypeName[]
The name of the archetype as used in ComponentDescriptors.
Definition volume3d.hpp:155
Volume3D with_voxel_size(const rerun::components::VoxelSize &_voxel_size) &&
The scene-unit dimensions of a single voxel cell.
Definition volume3d.hpp:251
Volume3D with_colormap(const rerun::components::Colormap &_colormap) &&
Colormap applied to the values after mapping them through value_range and gamma correction.
Definition volume3d.hpp:359
static constexpr auto Descriptor_colormap
ComponentDescriptor for the colormap field.
Definition volume3d.hpp:187
std::optional< ComponentBatch > quaternion
Rotation of the volume via quaternion.
Definition volume3d.hpp:124
Volume3D with_many_translation(const Collection< rerun::components::Translation3D > &_translation) &&
This method makes it possible to pack multiple translation in a single component batch.
Definition volume3d.hpp:284
Volume3D with_quaternion(const rerun::components::RotationQuat &_quaternion) &&
Rotation of the volume via quaternion.
Definition volume3d.hpp:298
Volume3D with_many_voxel_size(const Collection< rerun::components::VoxelSize > &_voxel_size) &&
This method makes it possible to pack multiple voxel_size in a single component batch.
Definition volume3d.hpp:261
Volume3D with_translation(const rerun::components::Translation3D &_translation) &&
Translation of the minimum corner of voxel [0, 0, 0].
Definition volume3d.hpp:274
static Volume3D clear_fields()
Clear all the fields of a Volume3D.
Volume3D with_many_value_range(const Collection< rerun::components::ValueRange > &_value_range) &&
This method makes it possible to pack multiple value_range in a single component batch.
Definition volume3d.hpp:330
Volume3D with_many_quaternion(const Collection< rerun::components::RotationQuat > &_quaternion) &&
This method makes it possible to pack multiple quaternion in a single component batch.
Definition volume3d.hpp:308
std::optional< ComponentBatch > voxel_size
The scene-unit dimensions of a single voxel cell.
Definition volume3d.hpp:108
std::optional< ComponentBatch > values
The scalar value of each voxel, as a 3D tensor with dimensions ordered [z, y, x].
Definition volume3d.hpp:98
static constexpr auto Descriptor_value_range
ComponentDescriptor for the value_range field.
Definition volume3d.hpp:177
std::optional< ComponentBatch > colormap
Colormap applied to the values after mapping them through value_range and gamma correction.
Definition volume3d.hpp:143
Volume3D with_many_colormap(const Collection< rerun::components::Colormap > &_colormap) &&
This method makes it possible to pack multiple colormap in a single component batch.
Definition volume3d.hpp:369
std::optional< ComponentBatch > optical_density
Dimensionless optical depth for the volume.
Definition volume3d.hpp:151
std::optional< ComponentBatch > value_range
The inclusive range of voxel values to render.
Definition volume3d.hpp:131
static constexpr auto Descriptor_values
ComponentDescriptor for the values field.
Definition volume3d.hpp:158
Volume3D with_many_values(const Collection< rerun::components::TensorData > &_values) &&
This method makes it possible to pack multiple values in a single component batch.
Definition volume3d.hpp:238
Volume3D with_gamma(const rerun::components::GammaCorrection &_gamma) &&
Gamma correction applied to normalized voxel values before colormapping and opacity calculation.
Definition volume3d.hpp:342
RR_DISABLE_MAYBE_UNINITIALIZED_PUSH Volume3D(Collection< uint64_t > shape, encodings::TensorBuffer buffer)
New Volume3D from dimensions and tensor buffer.
Definition volume3d.hpp:200
Volume3D with_values(const rerun::components::TensorData &_values) &&
The scalar value of each voxel, as a 3D tensor with dimensions ordered [z, y, x].
Definition volume3d.hpp:229
static constexpr auto Descriptor_optical_density
ComponentDescriptor for the optical_density field.
Definition volume3d.hpp:191
Volume3D with_many_optical_density(const Collection< rerun::components::OpticalDensity > &_optical_density) &&
This method makes it possible to pack multiple optical_density in a single component batch.
Definition volume3d.hpp:393
std::optional< ComponentBatch > translation
Translation of the minimum corner of voxel [0, 0, 0].
Definition volume3d.hpp:116
std::optional< ComponentBatch > gamma
Gamma correction applied to normalized voxel values before colormapping and opacity calculation.
Definition volume3d.hpp:138
static constexpr auto Descriptor_quaternion
ComponentDescriptor for the quaternion field.
Definition volume3d.hpp:172
Volume3D with_value_range(const rerun::components::ValueRange &_value_range) &&
The inclusive range of voxel values to render.
Definition volume3d.hpp:320
static constexpr auto Descriptor_voxel_size
ComponentDescriptor for the voxel_size field.
Definition volume3d.hpp:162
Component: A gamma correction value to be used with a scalar value or color.
Definition gamma_correction.hpp:20
Component: Dimensionless natural-log optical depth.
Definition optical_density.hpp:17
Component: A 3D rotation expressed as a quaternion.
Definition rotation_quat.hpp:18
Component: An N-dimensional array of numbers.
Definition tensor_data.hpp:22
Component: A translation vector in 3D space.
Definition translation3d.hpp:15
Component: Range of expected or valid values, specifying a lower and upper bound.
Definition value_range.hpp:18
Component: The scene-unit dimensions of one voxel in a sparse 3D voxel grid.
Definition voxel_size.hpp:18
Encoding: The underlying storage for archetypes::Tensor.
Definition tensor_buffer.hpp:98
Encoding: An N-dimensional array of numbers.
Definition tensor_data.hpp:30