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/opacity.hpp"
11#include "../components/rotation_quat.hpp"
12#include "../components/tensor_data.hpp"
13#include "../components/translation3d.hpp"
14#include "../components/value_range.hpp"
15#include "../components/voxel_size.hpp"
16#include "../result.hpp"
17
18#include <cstdint>
19#include <optional>
20#include <utility>
21#include <vector>
22
23namespace rerun::archetypes {
24 /// **Archetype**: A dense 3D scalar field, rendered by ray marching.
25 ///
26 /// This archetype is intended for volumetric scans and simulations, e.g. CT/MRI scans,
27 /// signed distance fields, or occupancy probabilities sampled on a regular grid.
28 ///
29 /// The values are a 3D tensor with dimensions ordered `[z, y, x]`, i.e. the last dimension varies
30 /// fastest and runs along the local X axis. This matches the row-major layout of
31 /// `archetypes::Image`, with slices stacked along the local Z axis.
32 /// The tensor element at `[k, j, i]` is thus the voxel with grid index `[i, j, k]`.
33 ///
34 /// Voxels are positioned exactly like those of `archetypes::VoxelGridMap`:
35 /// the minimum corner of the voxel with `[0, 0, 0]` index is located at the origin of the entity's
36 /// coordinate frame and can have an additional offset from there through the optional translation
37 /// and rotation fields, and a voxel center is at `(index + 0.5) * voxel_size` in local grid
38 /// coordinates (i.e. relative to the minimum corner).
39 /// This archetype and a `archetypes::VoxelGridMap` with the same `voxel_size` and pose
40 /// therefore agree voxel for voxel, the dense volume covering indices `[0, 0, 0]` up to
41 /// `[width - 1, height - 1, depth - 1]`.
42 ///
43 /// ## Example
44 ///
45 /// ### Simple volume
46 /// ```cpp
47 /// #include <rerun.hpp>
48 ///
49 /// #include <algorithm> // std::max
50 /// #include <vector>
51 ///
52 /// constexpr size_t SIZE = 32;
53 /// constexpr float RADIUS = 14.0f;
54 ///
55 /// int main(int argc, char* argv[]) {
56 /// const auto rec = rerun::RecordingStream("rerun_example_volume3d_simple");
57 /// rec.spawn().exit_on_failure();
58 ///
59 /// // Dimensions are ordered `[z, y, x]`. Only `f16` values are supported for now.
60 /// std::vector<rerun::half> values;
61 /// values.reserve(SIZE * SIZE * SIZE);
62 /// for (size_t z = 0; z <SIZE; ++z) {
63 /// for (size_t y = 0; y <SIZE; ++y) {
64 /// for (size_t x = 0; x <SIZE; ++x) {
65 /// // Squared distance from the center of the grid, in voxel units.
66 /// const float center = 0.5f * static_cast<float>(SIZE - 1);
67 /// const float dx = static_cast<float>(x) - center;
68 /// const float dy = static_cast<float>(y) - center;
69 /// const float dz = static_cast<float>(z) - center;
70 /// const float distance_sq = dx * dx + dy * dy + dz * dz;
71 ///
72 /// // A soft sphere: 1 at the center, falling off to 0 at `RADIUS`.
73 /// values.push_back(rerun::half::from_float(
74 /// std::max(0.0f, 1.0f - distance_sq / (RADIUS * RADIUS))
75 /// ));
76 /// }
77 /// }
78 /// }
79 ///
80 /// rec.log(
81 /// "volume",
82 /// rerun::Volume3D({SIZE, SIZE, SIZE}, values)
83 /// .with_voxel_size(rerun::Vec3D(0.1f, 0.1f, 0.1f))
84 /// );
85 /// }
86 /// ```
87 ///
88 /// ⚠ **This type is _unstable_ and may change significantly in a way that the data won't be backwards compatible.**
89 ///
90 struct Volume3D {
91 /// The scalar value of each voxel, as a 3D tensor with dimensions ordered `[z, y, x]`.
92 ///
93 /// Currently only `f16` are supported.
94 std::optional<ComponentBatch> values;
95
96 /// The scene-unit dimensions of a single voxel cell.
97 ///
98 /// This defines the voxel size along the local grid X/Y/Z axes, and thus the total extent of the
99 /// volume: `[width, height, depth] * voxel_size`.
100 /// Anisotropic spacing (as is common for medical scans) is expressed here.
101 /// Each dimension must be finite and positive.
102 ///
103 /// Defaults to `[1.0, 1.0, 1.0]`.
104 std::optional<ComponentBatch> voxel_size;
105
106 /// Translation of the minimum corner of voxel `[0, 0, 0]`.
107 ///
108 /// Together with `components::RotationQuat`, this defines the pose of the volume
109 /// relative to the entity's coordinate frame.
110 ///
111 /// If not set, the minimum corner is placed at the origin of the entity's coordinate frame.
112 std::optional<ComponentBatch> translation;
113
114 /// Rotation of the volume via quaternion.
115 ///
116 /// Together with `components::Translation3D`, this defines the pose of the volume
117 /// relative to the entity's coordinate frame.
118 /// The rotation is around the minimum corner of voxel `[0, 0, 0]`, and is applied before the
119 /// translation.
120 std::optional<ComponentBatch> quaternion;
121
122 /// How to map `values` to opacity and color.
123 ///
124 /// If not specified, the range is estimated from the data.
125 std::optional<ComponentBatch> value_range;
126
127 /// Colormap applied to the values after mapping them through `value_range`.
128 ///
129 /// Defaults to Turbo.
130 std::optional<ComponentBatch> colormap;
131
132 /// Overall opacity of the volume.
133 ///
134 /// The opacity of a single voxel is its value (normalized through `value_range`) scaled by
135 /// this, i.e. a linear ramp: low values are transparent, high values are opaque.
136 /// Lowering this makes the interior of the volume visible.
137 ///
138 /// Defaults to 1.0.
139 std::optional<ComponentBatch> opacity;
140
141 public:
142 /// The name of the archetype as used in `ComponentDescriptor`s.
143 static constexpr const char ArchetypeName[] = "rerun.archetypes.Volume3D";
144
145 /// `ComponentDescriptor` for the `values` field.
146 static constexpr auto Descriptor_values = ComponentDescriptor(
148 );
149 /// `ComponentDescriptor` for the `voxel_size` field.
151 ArchetypeName, "Volume3D:voxel_size",
153 );
154 /// `ComponentDescriptor` for the `translation` field.
156 ArchetypeName, "Volume3D:translation",
158 );
159 /// `ComponentDescriptor` for the `quaternion` field.
161 ArchetypeName, "Volume3D:quaternion",
163 );
164 /// `ComponentDescriptor` for the `value_range` field.
166 ArchetypeName, "Volume3D:value_range",
168 );
169 /// `ComponentDescriptor` for the `colormap` field.
172 );
173 /// `ComponentDescriptor` for the `opacity` field.
176 );
177
178 public: // START of extensions from volume3d_ext.cpp:
179 RR_DISABLE_MAYBE_UNINITIALIZED_PUSH
180
181 /// New Volume3D from dimensions and tensor buffer.
183 : Volume3D(encodings::TensorData(std::move(shape), std::move(buffer))) {}
184
185 RR_DISABLE_MAYBE_UNINITIALIZED_POP
186
187 // END of extensions from volume3d_ext.cpp, start of generated code:
188
189 public:
190 Volume3D() = default;
191 Volume3D(Volume3D&& other) = default;
192 Volume3D(const Volume3D& other) = default;
193 Volume3D& operator=(const Volume3D& other) = default;
194 Volume3D& operator=(Volume3D&& other) = default;
195
197 : values(ComponentBatch::from_loggable(std::move(_values), Descriptor_values)
198 .value_or_throw()) {}
199
200 /// Update only some specific fields of a `Volume3D`.
202 return Volume3D();
203 }
204
205 /// Clear all the fields of a `Volume3D`.
207
208 /// The scalar value of each voxel, as a 3D tensor with dimensions ordered `[z, y, x]`.
209 ///
210 /// Currently only `f16` are supported.
212 values = ComponentBatch::from_loggable(_values, Descriptor_values).value_or_throw();
213 return std::move(*this);
214 }
215
216 /// This method makes it possible to pack multiple `values` in a single component batch.
217 ///
218 /// This only makes sense when used in conjunction with `columns`. `with_values` should
219 /// be used when logging a single row's worth of data.
221 values = ComponentBatch::from_loggable(_values, Descriptor_values).value_or_throw();
222 return std::move(*this);
223 }
224
225 /// The scene-unit dimensions of a single voxel cell.
226 ///
227 /// This defines the voxel size along the local grid X/Y/Z axes, and thus the total extent of the
228 /// volume: `[width, height, depth] * voxel_size`.
229 /// Anisotropic spacing (as is common for medical scans) is expressed here.
230 /// Each dimension must be finite and positive.
231 ///
232 /// Defaults to `[1.0, 1.0, 1.0]`.
234 voxel_size =
235 ComponentBatch::from_loggable(_voxel_size, Descriptor_voxel_size).value_or_throw();
236 return std::move(*this);
237 }
238
239 /// This method makes it possible to pack multiple `voxel_size` in a single component batch.
240 ///
241 /// This only makes sense when used in conjunction with `columns`. `with_voxel_size` should
242 /// be used when logging a single row's worth of data.
244 ) && {
245 voxel_size =
246 ComponentBatch::from_loggable(_voxel_size, Descriptor_voxel_size).value_or_throw();
247 return std::move(*this);
248 }
249
250 /// Translation of the minimum corner of voxel `[0, 0, 0]`.
251 ///
252 /// Together with `components::RotationQuat`, this defines the pose of the volume
253 /// relative to the entity's coordinate frame.
254 ///
255 /// If not set, the minimum corner is placed at the origin of the entity's coordinate frame.
258 .value_or_throw();
259 return std::move(*this);
260 }
261
262 /// This method makes it possible to pack multiple `translation` in a single component batch.
263 ///
264 /// This only makes sense when used in conjunction with `columns`. `with_translation` should
265 /// be used when logging a single row's worth of data.
268 ) && {
270 .value_or_throw();
271 return std::move(*this);
272 }
273
274 /// Rotation of the volume via quaternion.
275 ///
276 /// Together with `components::Translation3D`, this defines the pose of the volume
277 /// relative to the entity's coordinate frame.
278 /// The rotation is around the minimum corner of voxel `[0, 0, 0]`, and is applied before the
279 /// translation.
281 quaternion =
282 ComponentBatch::from_loggable(_quaternion, Descriptor_quaternion).value_or_throw();
283 return std::move(*this);
284 }
285
286 /// This method makes it possible to pack multiple `quaternion` in a single component batch.
287 ///
288 /// This only makes sense when used in conjunction with `columns`. `with_quaternion` should
289 /// be used when logging a single row's worth of data.
291 ) && {
292 quaternion =
293 ComponentBatch::from_loggable(_quaternion, Descriptor_quaternion).value_or_throw();
294 return std::move(*this);
295 }
296
297 /// How to map `values` to opacity and color.
298 ///
299 /// If not specified, the range is estimated from the data.
302 .value_or_throw();
303 return std::move(*this);
304 }
305
306 /// This method makes it possible to pack multiple `value_range` in a single component batch.
307 ///
308 /// This only makes sense when used in conjunction with `columns`. `with_value_range` should
309 /// be used when logging a single row's worth of data.
311 ) && {
313 .value_or_throw();
314 return std::move(*this);
315 }
316
317 /// Colormap applied to the values after mapping them through `value_range`.
318 ///
319 /// Defaults to Turbo.
321 colormap =
322 ComponentBatch::from_loggable(_colormap, Descriptor_colormap).value_or_throw();
323 return std::move(*this);
324 }
325
326 /// This method makes it possible to pack multiple `colormap` in a single component batch.
327 ///
328 /// This only makes sense when used in conjunction with `columns`. `with_colormap` should
329 /// be used when logging a single row's worth of data.
331 colormap =
332 ComponentBatch::from_loggable(_colormap, Descriptor_colormap).value_or_throw();
333 return std::move(*this);
334 }
335
336 /// Overall opacity of the volume.
337 ///
338 /// The opacity of a single voxel is its value (normalized through `value_range`) scaled by
339 /// this, i.e. a linear ramp: low values are transparent, high values are opaque.
340 /// Lowering this makes the interior of the volume visible.
341 ///
342 /// Defaults to 1.0.
344 opacity = ComponentBatch::from_loggable(_opacity, Descriptor_opacity).value_or_throw();
345 return std::move(*this);
346 }
347
348 /// This method makes it possible to pack multiple `opacity` in a single component batch.
349 ///
350 /// This only makes sense when used in conjunction with `columns`. `with_opacity` should
351 /// be used when logging a single row's worth of data.
353 opacity = ComponentBatch::from_loggable(_opacity, Descriptor_opacity).value_or_throw();
354 return std::move(*this);
355 }
356
357 /// Partitions the component data into multiple sub-batches.
358 ///
359 /// Specifically, this transforms the existing `ComponentBatch` data into `ComponentColumn`s
360 /// instead, via `ComponentBatch::partitioned`.
361 ///
362 /// This makes it possible to use `RecordingStream::send_columns` to send columnar data directly into Rerun.
363 ///
364 /// The specified `lengths` must sum to the total length of the component batch.
366
367 /// Partitions the component data into unit-length sub-batches.
368 ///
369 /// This is semantically similar to calling `columns` with `std::vector<uint32_t>(n, 1)`,
370 /// where `n` is automatically guessed.
372 };
373
374} // namespace rerun::archetypes
375
376namespace rerun {
377 /// \private
378 template <typename T>
379 struct AsComponents;
380
381 /// \private
382 template <>
383 struct AsComponents<archetypes::Volume3D> {
384 /// Serialize all set component batches.
385 static Result<Collection<ComponentBatch>> as_batches(const archetypes::Volume3D& archetype);
386 };
387} // 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:90
static Volume3D update_fields()
Update only some specific fields of a Volume3D.
Definition volume3d.hpp:201
Volume3D with_many_opacity(const Collection< rerun::components::Opacity > &_opacity) &&
This method makes it possible to pack multiple opacity in a single component batch.
Definition volume3d.hpp:352
Collection< ComponentColumn > columns(const Collection< uint32_t > &lengths_)
Partitions the component data into multiple sub-batches.
static constexpr auto Descriptor_translation
ComponentDescriptor for the translation field.
Definition volume3d.hpp:155
Collection< ComponentColumn > columns()
Partitions the component data into unit-length sub-batches.
static constexpr const char ArchetypeName[]
The name of the archetype as used in ComponentDescriptors.
Definition volume3d.hpp:143
Volume3D with_voxel_size(const rerun::components::VoxelSize &_voxel_size) &&
The scene-unit dimensions of a single voxel cell.
Definition volume3d.hpp:233
Volume3D with_colormap(const rerun::components::Colormap &_colormap) &&
Colormap applied to the values after mapping them through value_range.
Definition volume3d.hpp:320
static constexpr auto Descriptor_colormap
ComponentDescriptor for the colormap field.
Definition volume3d.hpp:170
std::optional< ComponentBatch > quaternion
Rotation of the volume via quaternion.
Definition volume3d.hpp:120
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:266
Volume3D with_quaternion(const rerun::components::RotationQuat &_quaternion) &&
Rotation of the volume via quaternion.
Definition volume3d.hpp:280
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:243
std::optional< ComponentBatch > opacity
Overall opacity of the volume.
Definition volume3d.hpp:139
Volume3D with_translation(const rerun::components::Translation3D &_translation) &&
Translation of the minimum corner of voxel [0, 0, 0].
Definition volume3d.hpp:256
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:310
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:290
std::optional< ComponentBatch > voxel_size
The scene-unit dimensions of a single voxel cell.
Definition volume3d.hpp:104
std::optional< ComponentBatch > values
The scalar value of each voxel, as a 3D tensor with dimensions ordered [z, y, x].
Definition volume3d.hpp:94
static constexpr auto Descriptor_value_range
ComponentDescriptor for the value_range field.
Definition volume3d.hpp:165
std::optional< ComponentBatch > colormap
Colormap applied to the values after mapping them through value_range.
Definition volume3d.hpp:130
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:330
std::optional< ComponentBatch > value_range
How to map values to opacity and color.
Definition volume3d.hpp:125
static constexpr auto Descriptor_values
ComponentDescriptor for the values field.
Definition volume3d.hpp:146
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:220
RR_DISABLE_MAYBE_UNINITIALIZED_PUSH Volume3D(Collection< uint64_t > shape, encodings::TensorBuffer buffer)
New Volume3D from dimensions and tensor buffer.
Definition volume3d.hpp:182
static constexpr auto Descriptor_opacity
ComponentDescriptor for the opacity field.
Definition volume3d.hpp:174
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:211
std::optional< ComponentBatch > translation
Translation of the minimum corner of voxel [0, 0, 0].
Definition volume3d.hpp:112
Volume3D with_opacity(const rerun::components::Opacity &_opacity) &&
Overall opacity of the volume.
Definition volume3d.hpp:343
static constexpr auto Descriptor_quaternion
ComponentDescriptor for the quaternion field.
Definition volume3d.hpp:160
Volume3D with_value_range(const rerun::components::ValueRange &_value_range) &&
How to map values to opacity and color.
Definition volume3d.hpp:300
static constexpr auto Descriptor_voxel_size
ComponentDescriptor for the voxel_size field.
Definition volume3d.hpp:150
Component: Degree of transparency ranging from 0.0 (fully transparent) to 1.0 (fully opaque).
Definition opacity.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