Rerun C++ SDK
Loading...
Searching...
No Matches
voxel_grid_map.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/voxel_grid_map.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/colormap.hpp"
12#include "../components/opacity.hpp"
13#include "../components/rotation_axis_angle.hpp"
14#include "../components/rotation_quat.hpp"
15#include "../components/translation3d.hpp"
16#include "../components/value_range.hpp"
17#include "../components/voxel_index.hpp"
18#include "../components/voxel_size.hpp"
19#include "../components/voxel_value.hpp"
20#include "../result.hpp"
21
22#include <cstdint>
23#include <optional>
24#include <utility>
25#include <vector>
26
27namespace rerun::archetypes {
28 /// **Archetype**: A sparse 3D voxel grid map with grid indices and voxel dimensions.
29 ///
30 /// This archetype is intended for 3D occupancy maps and other volumetric data
31 /// represented as a sparse grid of voxels with scene-unit dimensions along the local X/Y/Z axes.
32 ///
33 /// The minimum corner of the voxel with `[0, 0, 0]` index is located at the origin of the entity's coordinate frame
34 /// and can have an additional offset from there through the optional translation and rotation fields.
35 ///
36 /// A voxel center is at `(index + 0.5) * voxel_size` in local grid coordinates (i.e. relative to the minimum corner).
37 ///
38 /// ## Example
39 ///
40 /// ### Simple sparse voxel grid map
41 /// ```cpp
42 /// #include <rerun.hpp>
43 ///
44 /// #include <array>
45 /// #include <vector>
46 ///
47 /// int main(int argc, char* argv[]) {
48 /// const auto rec =
49 /// rerun::RecordingStream("rerun_example_voxel_grid_map_simple");
50 /// rec.spawn().exit_on_failure();
51 ///
52 /// const std::vector<rerun::components::VoxelIndex> voxel_indices = {
53 /// rerun::components::VoxelIndex(-1, 0, 0),
54 /// rerun::components::VoxelIndex(1, 0, 0),
55 /// rerun::components::VoxelIndex(1, 1, 0),
56 /// rerun::components::VoxelIndex(3, 0, 0),
57 /// rerun::components::VoxelIndex(3, 0, 1),
58 /// rerun::components::VoxelIndex(4, 0, 1),
59 /// };
60 /// const std::vector<rerun::components::VoxelValue> values = {
61 /// 0.0f,
62 /// 0.2f,
63 /// 0.4f,
64 /// 0.6f,
65 /// 0.8f,
66 /// 1.0f,
67 /// };
68 ///
69 /// rec.log(
70 /// "world/voxels",
71 /// rerun::archetypes::VoxelGridMap(
72 /// voxel_indices,
73 /// std::array<float, 3>{0.25f, 0.25f, 0.25f}
74 /// )
75 /// .with_values(values)
76 /// .with_value_range(
77 /// rerun::components::ValueRange(std::array<double, 2>{0.0, 1.0})
78 /// )
79 /// .with_colormap(rerun::components::Colormap::Turbo)
80 /// .with_translation({-0.5f, -0.5f, 0.0f})
81 /// );
82 /// }
83 /// ```
84 ///
85 /// ⚠ **This type is _unstable_ and may change significantly in a way that the data won't be backwards compatible.**
86 ///
87 struct VoxelGridMap {
88 /// Indices of the voxels within the grid volume.
89 std::optional<ComponentBatch> voxel_indices;
90
91 /// The scene-unit dimensions of a single voxel cell.
92 ///
93 /// This defines the voxel size along the local grid X/Y/Z axes.
94 /// Each dimension must be finite and positive.
95 std::optional<ComponentBatch> voxel_size;
96
97 /// Optional scalar occupancy or value data for each voxel.
98 ///
99 /// If explicit colors are not provided, values are mapped through `colormap` and `value_range`.
100 std::optional<ComponentBatch> values;
101
102 /// Optional colors for each voxel.
103 ///
104 /// If set, these colors take precedence over color-mapped scalar values.
105 std::optional<ComponentBatch> colors;
106
107 /// Translation of the minimum corner of voxel `[0, 0, 0]`.
108 ///
109 /// Together with `components::RotationAxisAngle` or `components::RotationQuat`, this defines the pose of the
110 /// grid relative to the map's parent coordinate frame.
111 ///
112 /// If not set, the minimum corner is placed at the origin of the map's parent coordinate frame.
113 std::optional<ComponentBatch> translation;
114
115 /// Rotation of the grid via axis + angle.
116 ///
117 /// Together with `components::Translation3D`, this defines the pose of the grid relative to the
118 /// map's parent coordinate frame.
119 ///
120 /// Note: either this or `components::RotationQuat` can be set to specify the grid's rotation, but not both.
121 /// If both this and `components::RotationQuat` are set, this is ignored in favor of the quaternion.
122 std::optional<ComponentBatch> rotation_axis_angle;
123
124 /// Rotation of the grid via quaternion.
125 ///
126 /// Together with `components::Translation3D`, this defines the pose of the grid relative to the
127 /// map's parent coordinate frame.
128 std::optional<ComponentBatch> quaternion;
129
130 /// Opacity of the voxels after color or colormap application.
131 ///
132 /// Defaults to 1.0 (fully opaque).
133 std::optional<ComponentBatch> opacity;
134
135 /// Scalar value range for color-mapping.
136 ///
137 /// Defaults to `[0.0, 1.0]`.
138 std::optional<ComponentBatch> value_range;
139
140 /// Colormap to use when `values` are present and explicit `colors` are not provided.
141 ///
142 /// Defaults to Turbo.
143 std::optional<ComponentBatch> colormap;
144
145 public:
146 /// The name of the archetype as used in `ComponentDescriptor`s.
147 static constexpr const char ArchetypeName[] = "rerun.archetypes.VoxelGridMap";
148
149 /// `ComponentDescriptor` for the `voxel_indices` field.
151 ArchetypeName, "VoxelGridMap:voxel_indices",
153 );
154 /// `ComponentDescriptor` for the `voxel_size` field.
156 ArchetypeName, "VoxelGridMap:voxel_size",
158 );
159 /// `ComponentDescriptor` for the `values` field.
160 static constexpr auto Descriptor_values = ComponentDescriptor(
161 ArchetypeName, "VoxelGridMap:values",
163 );
164 /// `ComponentDescriptor` for the `colors` field.
165 static constexpr auto Descriptor_colors = ComponentDescriptor(
167 );
168 /// `ComponentDescriptor` for the `translation` field.
170 ArchetypeName, "VoxelGridMap:translation",
172 );
173 /// `ComponentDescriptor` for the `rotation_axis_angle` field.
175 ArchetypeName, "VoxelGridMap:rotation_axis_angle",
177 );
178 /// `ComponentDescriptor` for the `quaternion` field.
180 ArchetypeName, "VoxelGridMap:quaternion",
182 );
183 /// `ComponentDescriptor` for the `opacity` field.
185 ArchetypeName, "VoxelGridMap:opacity",
187 );
188 /// `ComponentDescriptor` for the `value_range` field.
190 ArchetypeName, "VoxelGridMap:value_range",
192 );
193 /// `ComponentDescriptor` for the `colormap` field.
195 ArchetypeName, "VoxelGridMap:colormap",
197 );
198
199 public:
200 VoxelGridMap() = default;
201 VoxelGridMap(VoxelGridMap&& other) = default;
202 VoxelGridMap(const VoxelGridMap& other) = default;
203 VoxelGridMap& operator=(const VoxelGridMap& other) = default;
204 VoxelGridMap& operator=(VoxelGridMap&& other) = default;
205
206 explicit VoxelGridMap(
209 )
211 ComponentBatch::from_loggable(std::move(_voxel_indices), Descriptor_voxel_indices)
212 .value_or_throw()
213 ),
215 ComponentBatch::from_loggable(std::move(_voxel_size), Descriptor_voxel_size)
216 .value_or_throw()
217 ) {}
218
219 /// Update only some specific fields of a `VoxelGridMap`.
221 return VoxelGridMap();
222 }
223
224 /// Clear all the fields of a `VoxelGridMap`.
226
227 /// Indices of the voxels within the grid volume.
230 ) && {
232 .value_or_throw();
233 return std::move(*this);
234 }
235
236 /// The scene-unit dimensions of a single voxel cell.
237 ///
238 /// This defines the voxel size along the local grid X/Y/Z axes.
239 /// Each dimension must be finite and positive.
241 voxel_size =
242 ComponentBatch::from_loggable(_voxel_size, Descriptor_voxel_size).value_or_throw();
243 return std::move(*this);
244 }
245
246 /// This method makes it possible to pack multiple `voxel_size` in a single component batch.
247 ///
248 /// This only makes sense when used in conjunction with `columns`. `with_voxel_size` should
249 /// be used when logging a single row's worth of data.
252 ) && {
253 voxel_size =
254 ComponentBatch::from_loggable(_voxel_size, Descriptor_voxel_size).value_or_throw();
255 return std::move(*this);
256 }
257
258 /// Optional scalar occupancy or value data for each voxel.
259 ///
260 /// If explicit colors are not provided, values are mapped through `colormap` and `value_range`.
262 values = ComponentBatch::from_loggable(_values, Descriptor_values).value_or_throw();
263 return std::move(*this);
264 }
265
266 /// Optional colors for each voxel.
267 ///
268 /// If set, these colors take precedence over color-mapped scalar values.
270 colors = ComponentBatch::from_loggable(_colors, Descriptor_colors).value_or_throw();
271 return std::move(*this);
272 }
273
274 /// Translation of the minimum corner of voxel `[0, 0, 0]`.
275 ///
276 /// Together with `components::RotationAxisAngle` or `components::RotationQuat`, this defines the pose of the
277 /// grid relative to the map's parent coordinate frame.
278 ///
279 /// If not set, the minimum corner is placed at the origin of the map's parent coordinate frame.
282 .value_or_throw();
283 return std::move(*this);
284 }
285
286 /// This method makes it possible to pack multiple `translation` in a single component batch.
287 ///
288 /// This only makes sense when used in conjunction with `columns`. `with_translation` should
289 /// be used when logging a single row's worth of data.
292 ) && {
294 .value_or_throw();
295 return std::move(*this);
296 }
297
298 /// Rotation of the grid via axis + angle.
299 ///
300 /// Together with `components::Translation3D`, this defines the pose of the grid relative to the
301 /// map's parent coordinate frame.
302 ///
303 /// Note: either this or `components::RotationQuat` can be set to specify the grid's rotation, but not both.
304 /// If both this and `components::RotationQuat` are set, this is ignored in favor of the quaternion.
306 const rerun::components::RotationAxisAngle& _rotation_axis_angle
307 ) && {
310 .value_or_throw();
311 return std::move(*this);
312 }
313
314 /// This method makes it possible to pack multiple `rotation_axis_angle` in a single component batch.
315 ///
316 /// This only makes sense when used in conjunction with `columns`. `with_rotation_axis_angle` should
317 /// be used when logging a single row's worth of data.
319 const Collection<rerun::components::RotationAxisAngle>& _rotation_axis_angle
320 ) && {
323 .value_or_throw();
324 return std::move(*this);
325 }
326
327 /// Rotation of the grid via quaternion.
328 ///
329 /// Together with `components::Translation3D`, this defines the pose of the grid relative to the
330 /// map's parent coordinate frame.
332 quaternion =
333 ComponentBatch::from_loggable(_quaternion, Descriptor_quaternion).value_or_throw();
334 return std::move(*this);
335 }
336
337 /// This method makes it possible to pack multiple `quaternion` in a single component batch.
338 ///
339 /// This only makes sense when used in conjunction with `columns`. `with_quaternion` should
340 /// be used when logging a single row's worth of data.
343 ) && {
344 quaternion =
345 ComponentBatch::from_loggable(_quaternion, Descriptor_quaternion).value_or_throw();
346 return std::move(*this);
347 }
348
349 /// Opacity of the voxels after color or colormap application.
350 ///
351 /// Defaults to 1.0 (fully opaque).
353 opacity = ComponentBatch::from_loggable(_opacity, Descriptor_opacity).value_or_throw();
354 return std::move(*this);
355 }
356
357 /// This method makes it possible to pack multiple `opacity` in a single component batch.
358 ///
359 /// This only makes sense when used in conjunction with `columns`. `with_opacity` should
360 /// be used when logging a single row's worth of data.
362 opacity = ComponentBatch::from_loggable(_opacity, Descriptor_opacity).value_or_throw();
363 return std::move(*this);
364 }
365
366 /// Scalar value range for color-mapping.
367 ///
368 /// Defaults to `[0.0, 1.0]`.
371 .value_or_throw();
372 return std::move(*this);
373 }
374
375 /// This method makes it possible to pack multiple `value_range` in a single component batch.
376 ///
377 /// This only makes sense when used in conjunction with `columns`. `with_value_range` should
378 /// be used when logging a single row's worth of data.
381 ) && {
383 .value_or_throw();
384 return std::move(*this);
385 }
386
387 /// Colormap to use when `values` are present and explicit `colors` are not provided.
388 ///
389 /// Defaults to Turbo.
391 colormap =
392 ComponentBatch::from_loggable(_colormap, Descriptor_colormap).value_or_throw();
393 return std::move(*this);
394 }
395
396 /// This method makes it possible to pack multiple `colormap` in a single component batch.
397 ///
398 /// This only makes sense when used in conjunction with `columns`. `with_colormap` should
399 /// be used when logging a single row's worth of data.
401 ) && {
402 colormap =
403 ComponentBatch::from_loggable(_colormap, Descriptor_colormap).value_or_throw();
404 return std::move(*this);
405 }
406
407 /// Partitions the component data into multiple sub-batches.
408 ///
409 /// Specifically, this transforms the existing `ComponentBatch` data into `ComponentColumn`s
410 /// instead, via `ComponentBatch::partitioned`.
411 ///
412 /// This makes it possible to use `RecordingStream::send_columns` to send columnar data directly into Rerun.
413 ///
414 /// The specified `lengths` must sum to the total length of the component batch.
416 return detail::partition_batches(
418 &voxel_size,
419 &values,
420 &colors,
423 &quaternion,
424 &opacity,
426 &colormap},
427 lengths_
428 )
429 .value_or_throw();
430 }
431
432 /// Partitions the component data into unit-length sub-batches.
433 ///
434 /// This is semantically similar to calling `columns` with `std::vector<uint32_t>(n, 1)`,
435 /// where `n` is automatically guessed.
437 return detail::partition_batches_of_unit_length({&voxel_indices,
438 &voxel_size,
439 &values,
440 &colors,
443 &quaternion,
444 &opacity,
446 &colormap})
447 .value_or_throw();
448 }
449 };
450
451} // namespace rerun::archetypes
452
453namespace rerun {
454 /// \private
455 template <typename T>
456 struct AsComponents;
457
458 /// \private
459 template <>
460 struct AsComponents<archetypes::VoxelGridMap> {
461 /// Serialize all set component batches.
462 static Result<Collection<ComponentBatch>> as_batches(
463 const archetypes::VoxelGridMap& archetype
464 ) {
465 return detail::collect_batches(
466 {&archetype.voxel_indices,
467 &archetype.voxel_size,
468 &archetype.values,
469 &archetype.colors,
470 &archetype.translation,
471 &archetype.rotation_axis_angle,
472 &archetype.quaternion,
473 &archetype.opacity,
474 &archetype.value_range,
475 &archetype.colormap}
476 );
477 }
478 };
479} // 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
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 sparse 3D voxel grid map with grid indices and voxel dimensions.
Definition voxel_grid_map.hpp:87
static constexpr auto Descriptor_voxel_size
ComponentDescriptor for the voxel_size field.
Definition voxel_grid_map.hpp:155
VoxelGridMap with_many_colormap(const Collection< rerun::components::Colormap > &_colormap) &&
This method makes it possible to pack multiple colormap in a single component batch.
Definition voxel_grid_map.hpp:400
VoxelGridMap with_many_quaternion(const Collection< rerun::components::RotationQuat > &_quaternion) &&
This method makes it possible to pack multiple quaternion in a single component batch.
Definition voxel_grid_map.hpp:341
VoxelGridMap with_colormap(const rerun::components::Colormap &_colormap) &&
Colormap to use when values are present and explicit colors are not provided.
Definition voxel_grid_map.hpp:390
static constexpr auto Descriptor_translation
ComponentDescriptor for the translation field.
Definition voxel_grid_map.hpp:169
std::optional< ComponentBatch > translation
Translation of the minimum corner of voxel [0, 0, 0].
Definition voxel_grid_map.hpp:113
std::optional< ComponentBatch > value_range
Scalar value range for color-mapping.
Definition voxel_grid_map.hpp:138
std::optional< ComponentBatch > voxel_indices
Indices of the voxels within the grid volume.
Definition voxel_grid_map.hpp:89
VoxelGridMap with_many_rotation_axis_angle(const Collection< rerun::components::RotationAxisAngle > &_rotation_axis_angle) &&
This method makes it possible to pack multiple rotation_axis_angle in a single component batch.
Definition voxel_grid_map.hpp:318
std::optional< ComponentBatch > voxel_size
The scene-unit dimensions of a single voxel cell.
Definition voxel_grid_map.hpp:95
VoxelGridMap with_translation(const rerun::components::Translation3D &_translation) &&
Translation of the minimum corner of voxel [0, 0, 0].
Definition voxel_grid_map.hpp:280
static constexpr const char ArchetypeName[]
The name of the archetype as used in ComponentDescriptors.
Definition voxel_grid_map.hpp:147
VoxelGridMap with_quaternion(const rerun::components::RotationQuat &_quaternion) &&
Rotation of the grid via quaternion.
Definition voxel_grid_map.hpp:331
VoxelGridMap with_colors(const Collection< rerun::components::Color > &_colors) &&
Optional colors for each voxel.
Definition voxel_grid_map.hpp:269
static constexpr auto Descriptor_colormap
ComponentDescriptor for the colormap field.
Definition voxel_grid_map.hpp:194
static constexpr auto Descriptor_values
ComponentDescriptor for the values field.
Definition voxel_grid_map.hpp:160
std::optional< ComponentBatch > rotation_axis_angle
Rotation of the grid via axis + angle.
Definition voxel_grid_map.hpp:122
VoxelGridMap with_voxel_size(const rerun::components::VoxelSize &_voxel_size) &&
The scene-unit dimensions of a single voxel cell.
Definition voxel_grid_map.hpp:240
static constexpr auto Descriptor_quaternion
ComponentDescriptor for the quaternion field.
Definition voxel_grid_map.hpp:179
VoxelGridMap with_values(const Collection< rerun::components::VoxelValue > &_values) &&
Optional scalar occupancy or value data for each voxel.
Definition voxel_grid_map.hpp:261
VoxelGridMap with_rotation_axis_angle(const rerun::components::RotationAxisAngle &_rotation_axis_angle) &&
Rotation of the grid via axis + angle.
Definition voxel_grid_map.hpp:305
VoxelGridMap with_many_translation(const Collection< rerun::components::Translation3D > &_translation) &&
This method makes it possible to pack multiple translation in a single component batch.
Definition voxel_grid_map.hpp:290
std::optional< ComponentBatch > colors
Optional colors for each voxel.
Definition voxel_grid_map.hpp:105
static constexpr auto Descriptor_value_range
ComponentDescriptor for the value_range field.
Definition voxel_grid_map.hpp:189
Collection< ComponentColumn > columns(const Collection< uint32_t > &lengths_)
Partitions the component data into multiple sub-batches.
Definition voxel_grid_map.hpp:415
std::optional< ComponentBatch > quaternion
Rotation of the grid via quaternion.
Definition voxel_grid_map.hpp:128
static constexpr auto Descriptor_opacity
ComponentDescriptor for the opacity field.
Definition voxel_grid_map.hpp:184
VoxelGridMap 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 voxel_grid_map.hpp:379
Collection< ComponentColumn > columns()
Partitions the component data into unit-length sub-batches.
Definition voxel_grid_map.hpp:436
VoxelGridMap with_many_opacity(const Collection< rerun::components::Opacity > &_opacity) &&
This method makes it possible to pack multiple opacity in a single component batch.
Definition voxel_grid_map.hpp:361
std::optional< ComponentBatch > values
Optional scalar occupancy or value data for each voxel.
Definition voxel_grid_map.hpp:100
std::optional< ComponentBatch > opacity
Opacity of the voxels after color or colormap application.
Definition voxel_grid_map.hpp:133
VoxelGridMap 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 voxel_grid_map.hpp:250
static constexpr auto Descriptor_rotation_axis_angle
ComponentDescriptor for the rotation_axis_angle field.
Definition voxel_grid_map.hpp:174
std::optional< ComponentBatch > colormap
Colormap to use when values are present and explicit colors are not provided.
Definition voxel_grid_map.hpp:143
VoxelGridMap with_voxel_indices(const Collection< rerun::components::VoxelIndex > &_voxel_indices) &&
Indices of the voxels within the grid volume.
Definition voxel_grid_map.hpp:228
static constexpr auto Descriptor_voxel_indices
ComponentDescriptor for the voxel_indices field.
Definition voxel_grid_map.hpp:150
static constexpr auto Descriptor_colors
ComponentDescriptor for the colors field.
Definition voxel_grid_map.hpp:165
static VoxelGridMap update_fields()
Update only some specific fields of a VoxelGridMap.
Definition voxel_grid_map.hpp:220
VoxelGridMap with_opacity(const rerun::components::Opacity &_opacity) &&
Opacity of the voxels after color or colormap application.
Definition voxel_grid_map.hpp:352
VoxelGridMap with_value_range(const rerun::components::ValueRange &_value_range) &&
Scalar value range for color-mapping.
Definition voxel_grid_map.hpp:369
static VoxelGridMap clear_fields()
Clear all the fields of a VoxelGridMap.
Component: Degree of transparency ranging from 0.0 (fully transparent) to 1.0 (fully opaque).
Definition opacity.hpp:17
Component: 3D rotation represented by a rotation around a given axis.
Definition rotation_axis_angle.hpp:17
Component: A 3D rotation expressed as a quaternion.
Definition rotation_quat.hpp:18
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