Rerun C++ SDK
Loading...
Searching...
No Matches
points3d.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/points3d.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/class_id.hpp"
11#include "../components/color.hpp"
12#include "../components/keypoint_id.hpp"
13#include "../components/point_shading.hpp"
14#include "../components/position3d.hpp"
15#include "../components/radius.hpp"
16#include "../components/show_labels.hpp"
17#include "../components/text.hpp"
18#include "../result.hpp"
19
20#include <cstdint>
21#include <optional>
22#include <utility>
23#include <vector>
24
25namespace rerun::archetypes {
26 /// **Archetype**: A 3D point cloud with positions and optional colors, radii, labels, etc.
27 ///
28 /// If there are multiple instance poses, the entire point cloud will be repeated for each of the poses.
29 ///
30 /// ## Examples
31 ///
32 /// ### Simple 3D points
33 /// ![image](https://static.rerun.io/point3d_simple/32fb3e9b65bea8bd7ffff95ad839f2f8a157a933/full.png)
34 ///
35 /// ```cpp
36 /// #include <rerun.hpp>
37 ///
38 /// int main(int argc, char* argv[]) {
39 /// const auto rec = rerun::RecordingStream("rerun_example_points3d");
40 /// rec.spawn().exit_on_failure();
41 ///
42 /// rec.log(
43 /// "points",
44 /// rerun::Points3D({{0.0f, 0.0f, 0.0f}, {1.0f, 1.0f, 1.0f}})
45 /// );
46 /// }
47 /// ```
48 ///
49 /// ### Update a point cloud over time
50 /// ![image](https://static.rerun.io/points3d_row_updates/fba056871b1ec3fc6978ab605d9a63e44ef1f6de/full.png)
51 ///
52 /// ```cpp
53 /// #include <rerun.hpp>
54 ///
55 /// #include <algorithm>
56 /// #include <vector>
57 ///
58 /// int main(int argc, char* argv[]) {
59 /// const auto rec =
60 /// rerun::RecordingStream("rerun_example_points3d_row_updates");
61 /// rec.spawn().exit_on_failure();
62 ///
63 /// // Prepare a point cloud that evolves over 5 timesteps, changing the number of points in the process.
64 /// std::vector<std::array<float, 3>> positions[] = {
65 /// // clang-format off
66 /// {{1.0, 0.0, 1.0}, {0.5, 0.5, 2.0}},
67 /// {{1.5, -0.5, 1.5}, {1.0, 1.0, 2.5}, {-0.5, 1.5, 1.0}, {-1.5, 0.0, 2.0}},
68 /// {{2.0, 0.0, 2.0}, {1.5, -1.5, 3.0}, {0.0, -2.0, 2.5}, {1.0, -1.0, 3.5}},
69 /// {{-2.0, 0.0, 2.0}, {-1.5, 1.5, 3.0}, {-1.0, 1.0, 3.5}},
70 /// {{1.0, -1.0, 1.0}, {2.0, -2.0, 2.0}, {3.0, -1.0, 3.0}, {2.0, 0.0, 4.0}},
71 /// // clang-format on
72 /// };
73 ///
74 /// // At each timestep, all points in the cloud share the same but changing color and radius.
75 /// std::vector<uint32_t> colors =
76 /// {0xFF0000FF, 0x00FF00FF, 0x0000FFFF, 0xFFFF00FF, 0x00FFFFFF};
77 /// std::vector<float> radii = {0.05f, 0.01f, 0.2f, 0.1f, 0.3f};
78 ///
79 /// for (size_t i = 0; i <5; i++) {
80 /// rec.set_time_duration_secs("time", 10.0 + static_cast<double>(i));
81 /// rec.log(
82 /// "points",
83 /// rerun::Points3D(positions[i])
84 /// .with_colors(colors[i])
85 /// .with_radii(radii[i])
86 /// );
87 /// }
88 /// }
89 /// ```
90 ///
91 /// ### Update a point cloud over time, in a single operation
92 /// ![image](https://static.rerun.io/points3d_row_updates/fba056871b1ec3fc6978ab605d9a63e44ef1f6de/full.png)
93 ///
94 /// ```cpp
95 /// #include <array>
96 /// #include <rerun.hpp>
97 /// #include <vector>
98 ///
99 /// using namespace std::chrono_literals;
100 ///
101 /// int main(int argc, char* argv[]) {
102 /// const auto rec =
103 /// rerun::RecordingStream("rerun_example_points3d_column_updates");
104 /// rec.spawn().exit_on_failure();
105 ///
106 /// // Prepare a point cloud that evolves over 5 timesteps, changing the number of points in the process.
107 /// std::vector<std::array<float, 3>> positions = {
108 /// // clang-format off
109 /// {1.0, 0.0, 1.0}, {0.5, 0.5, 2.0},
110 /// {1.5, -0.5, 1.5}, {1.0, 1.0, 2.5}, {-0.5, 1.5, 1.0}, {-1.5, 0.0, 2.0},
111 /// {2.0, 0.0, 2.0}, {1.5, -1.5, 3.0}, {0.0, -2.0, 2.5}, {1.0, -1.0, 3.5},
112 /// {-2.0, 0.0, 2.0}, {-1.5, 1.5, 3.0}, {-1.0, 1.0, 3.5},
113 /// {1.0, -1.0, 1.0}, {2.0, -2.0, 2.0}, {3.0, -1.0, 3.0}, {2.0, 0.0, 4.0},
114 /// // clang-format on
115 /// };
116 ///
117 /// // At each timestep, all points in the cloud share the same but changing color and radius.
118 /// std::vector<uint32_t> colors =
119 /// {0xFF0000FF, 0x00FF00FF, 0x0000FFFF, 0xFFFF00FF, 0x00FFFFFF};
120 /// std::vector<float> radii = {0.05f, 0.01f, 0.2f, 0.1f, 0.3f};
121 ///
122 /// // Log at seconds 10-14
123 /// auto times = rerun::Collection{10s, 11s, 12s, 13s, 14s};
124 /// auto time_column =
125 /// rerun::TimeColumn::from_durations("time", std::move(times));
126 ///
127 /// // Partition our data as expected across the 5 timesteps.
128 /// auto position =
129 /// rerun::Points3D().with_positions(positions).columns({2, 4, 4, 3, 4});
130 /// auto color_and_radius =
131 /// rerun::Points3D().with_colors(colors).with_radii(radii).columns();
132 ///
133 /// rec.send_columns("points", time_column, position, color_and_radius);
134 /// }
135 /// ```
136 ///
137 /// ### Update specific properties of a point cloud over time
138 /// ![image](https://static.rerun.io/points3d_partial_updates/d8bec9c3388d2bd0fe59dff01ab8cde0bdda135e/full.png)
139 ///
140 /// ```cpp
141 /// #include <rerun.hpp>
142 ///
143 /// #include <algorithm>
144 /// #include <vector>
145 ///
146 /// int main(int argc, char* argv[]) {
147 /// const auto rec =
148 /// rerun::RecordingStream("rerun_example_points3d_partial_updates");
149 /// rec.spawn().exit_on_failure();
150 ///
151 /// std::vector<rerun::Position3D> positions;
152 /// for (int i = 0; i <10; ++i) {
153 /// positions.emplace_back(static_cast<float>(i), 0.0f, 0.0f);
154 /// }
155 ///
156 /// rec.set_time_sequence("frame", 0);
157 /// rec.log("points", rerun::Points3D(positions));
158 ///
159 /// for (int i = 0; i <10; ++i) {
160 /// std::vector<rerun::Color> colors;
161 /// for (int n = 0; n <10; ++n) {
162 /// if (n <i) {
163 /// colors.emplace_back(rerun::Color(20, 200, 20));
164 /// } else {
165 /// colors.emplace_back(rerun::Color(200, 20, 20));
166 /// }
167 /// }
168 ///
169 /// std::vector<rerun::Radius> radii;
170 /// for (int n = 0; n <10; ++n) {
171 /// if (n <i) {
172 /// radii.emplace_back(rerun::Radius(0.6f));
173 /// } else {
174 /// radii.emplace_back(rerun::Radius(0.2f));
175 /// }
176 /// }
177 ///
178 /// // Update only the colors and radii, leaving everything else as-is.
179 /// rec.set_time_sequence("frame", i);
180 /// rec.log(
181 /// "points",
182 /// rerun::Points3D::update_fields().with_radii(radii).with_colors(
183 /// colors
184 /// )
185 /// );
186 /// }
187 ///
188 /// std::vector<rerun::Radius> radii;
189 /// radii.emplace_back(0.3f);
190 ///
191 /// // Update the positions and radii, and clear everything else in the process.
192 /// rec.set_time_sequence("frame", 20);
193 /// rec.log(
194 /// "points",
195 /// rerun::Points3D::clear_fields().with_positions(positions).with_radii(
196 /// radii
197 /// )
198 /// );
199 /// }
200 /// ```
201 struct Points3D {
202 /// All the 3D positions at which the point cloud shows points.
203 std::optional<ComponentBatch> positions;
204
205 /// Optional radii for the points, effectively turning them into circles.
206 std::optional<ComponentBatch> radii;
207
208 /// Optional colors for the points.
209 ///
210 /// By default, the alpha channel affects brightness rather than transparency.
211 /// TODO(#1611): To use the alpha channel for transparency, enable the experimental "Transparent point clouds" feature flag.
212 std::optional<ComponentBatch> colors;
213
214 /// Optional text labels for the points.
215 ///
216 /// If there's a single label present, it will be placed at the center of the entity.
217 /// Otherwise, each instance will have its own label.
218 std::optional<ComponentBatch> labels;
219
220 /// Whether the text labels should be shown.
221 ///
222 /// If not set, labels will automatically appear when there is exactly one label for this entity
223 /// or the number of instances on this entity is under a certain threshold.
224 std::optional<ComponentBatch> show_labels;
225
226 /// How points should be shaded.
227 ///
228 /// If not set, points are rendered with `components::PointShading::Gradient` by default.
229 std::optional<ComponentBatch> point_shading;
230
231 /// Optional class Ids for the points.
232 ///
233 /// The `components::ClassId` provides colors and labels if not specified explicitly.
234 std::optional<ComponentBatch> class_ids;
235
236 /// Optional keypoint IDs for the points, identifying them within a class.
237 ///
238 /// If keypoint IDs are passed in but no `components::ClassId`s were specified, the `components::ClassId` will
239 /// default to 0.
240 /// This is useful to identify points within a single classification (which is identified
241 /// with `class_id`).
242 /// E.g. the classification might be 'Person' and the keypoints refer to joints on a
243 /// detected skeleton.
244 std::optional<ComponentBatch> keypoint_ids;
245
246 public:
247 /// The name of the archetype as used in `ComponentDescriptor`s.
248 static constexpr const char ArchetypeName[] = "rerun.archetypes.Points3D";
249
250 /// `ComponentDescriptor` for the `positions` field.
252 ArchetypeName, "Points3D:positions",
254 );
255 /// `ComponentDescriptor` for the `radii` field.
256 static constexpr auto Descriptor_radii = ComponentDescriptor(
258 );
259 /// `ComponentDescriptor` for the `colors` field.
260 static constexpr auto Descriptor_colors = ComponentDescriptor(
262 );
263 /// `ComponentDescriptor` for the `labels` field.
264 static constexpr auto Descriptor_labels = ComponentDescriptor(
266 );
267 /// `ComponentDescriptor` for the `show_labels` field.
269 ArchetypeName, "Points3D:show_labels",
271 );
272 /// `ComponentDescriptor` for the `point_shading` field.
274 ArchetypeName, "Points3D:point_shading",
276 );
277 /// `ComponentDescriptor` for the `class_ids` field.
280 );
281 /// `ComponentDescriptor` for the `keypoint_ids` field.
283 ArchetypeName, "Points3D:keypoint_ids",
285 );
286
287 public:
288 Points3D() = default;
289 Points3D(Points3D&& other) = default;
290 Points3D(const Points3D& other) = default;
291 Points3D& operator=(const Points3D& other) = default;
292 Points3D& operator=(Points3D&& other) = default;
293
295 : positions(ComponentBatch::from_loggable(std::move(_positions), Descriptor_positions)
296 .value_or_throw()) {}
297
298 /// Update only some specific fields of a `Points3D`.
300 return Points3D();
301 }
302
303 /// Clear all the fields of a `Points3D`.
305
306 /// All the 3D positions at which the point cloud shows points.
308 positions =
309 ComponentBatch::from_loggable(_positions, Descriptor_positions).value_or_throw();
310 return std::move(*this);
311 }
312
313 /// Optional radii for the points, effectively turning them into circles.
315 radii = ComponentBatch::from_loggable(_radii, Descriptor_radii).value_or_throw();
316 return std::move(*this);
317 }
318
319 /// Optional colors for the points.
320 ///
321 /// By default, the alpha channel affects brightness rather than transparency.
322 /// TODO(#1611): To use the alpha channel for transparency, enable the experimental "Transparent point clouds" feature flag.
324 colors = ComponentBatch::from_loggable(_colors, Descriptor_colors).value_or_throw();
325 return std::move(*this);
326 }
327
328 /// Optional text labels for the points.
329 ///
330 /// If there's a single label present, it will be placed at the center of the entity.
331 /// Otherwise, each instance will have its own label.
333 labels = ComponentBatch::from_loggable(_labels, Descriptor_labels).value_or_throw();
334 return std::move(*this);
335 }
336
337 /// Whether the text labels should be shown.
338 ///
339 /// If not set, labels will automatically appear when there is exactly one label for this entity
340 /// or the number of instances on this entity is under a certain threshold.
343 .value_or_throw();
344 return std::move(*this);
345 }
346
347 /// This method makes it possible to pack multiple `show_labels` in a single component batch.
348 ///
349 /// This only makes sense when used in conjunction with `columns`. `with_show_labels` should
350 /// be used when logging a single row's worth of data.
352 ) && {
354 .value_or_throw();
355 return std::move(*this);
356 }
357
358 /// How points should be shaded.
359 ///
360 /// If not set, points are rendered with `components::PointShading::Gradient` by default.
363 .value_or_throw();
364 return std::move(*this);
365 }
366
367 /// This method makes it possible to pack multiple `point_shading` in a single component batch.
368 ///
369 /// This only makes sense when used in conjunction with `columns`. `with_point_shading` should
370 /// be used when logging a single row's worth of data.
373 ) && {
375 .value_or_throw();
376 return std::move(*this);
377 }
378
379 /// Optional class Ids for the points.
380 ///
381 /// The `components::ClassId` provides colors and labels if not specified explicitly.
383 class_ids =
384 ComponentBatch::from_loggable(_class_ids, Descriptor_class_ids).value_or_throw();
385 return std::move(*this);
386 }
387
388 /// Optional keypoint IDs for the points, identifying them within a class.
389 ///
390 /// If keypoint IDs are passed in but no `components::ClassId`s were specified, the `components::ClassId` will
391 /// default to 0.
392 /// This is useful to identify points within a single classification (which is identified
393 /// with `class_id`).
394 /// E.g. the classification might be 'Person' and the keypoints refer to joints on a
395 /// detected skeleton.
397 ) && {
399 .value_or_throw();
400 return std::move(*this);
401 }
402
403 /// Partitions the component data into multiple sub-batches.
404 ///
405 /// Specifically, this transforms the existing `ComponentBatch` data into `ComponentColumn`s
406 /// instead, via `ComponentBatch::partitioned`.
407 ///
408 /// This makes it possible to use `RecordingStream::send_columns` to send columnar data directly into Rerun.
409 ///
410 /// The specified `lengths` must sum to the total length of the component batch.
412 return detail::partition_batches(
413 {&positions,
414 &radii,
415 &colors,
416 &labels,
419 &class_ids,
420 &keypoint_ids},
421 lengths_
422 )
423 .value_or_throw();
424 }
425
426 /// Partitions the component data into unit-length sub-batches.
427 ///
428 /// This is semantically similar to calling `columns` with `std::vector<uint32_t>(n, 1)`,
429 /// where `n` is automatically guessed.
431 return detail::partition_batches_of_unit_length({&positions,
432 &radii,
433 &colors,
434 &labels,
437 &class_ids,
438 &keypoint_ids})
439 .value_or_throw();
440 }
441 };
442
443} // namespace rerun::archetypes
444
445namespace rerun {
446 /// \private
447 template <typename T>
448 struct AsComponents;
449
450 /// \private
451 template <>
452 struct AsComponents<archetypes::Points3D> {
453 /// Serialize all set component batches.
454 static Result<Collection<ComponentBatch>> as_batches(const archetypes::Points3D& archetype
455 ) {
456 return detail::collect_batches(
457 {&archetype.positions,
458 &archetype.radii,
459 &archetype.colors,
460 &archetype.labels,
461 &archetype.show_labels,
462 &archetype.point_shading,
463 &archetype.class_ids,
464 &archetype.keypoint_ids}
465 );
466 }
467 };
468} // 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
PointShading
Component: Defines how points are shaded.
Definition point_shading.hpp:24
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 3D point cloud with positions and optional colors, radii, labels, etc.
Definition points3d.hpp:201
static constexpr auto Descriptor_class_ids
ComponentDescriptor for the class_ids field.
Definition points3d.hpp:278
Points3D with_many_point_shading(const Collection< rerun::components::PointShading > &_point_shading) &&
This method makes it possible to pack multiple point_shading in a single component batch.
Definition points3d.hpp:371
std::optional< ComponentBatch > class_ids
Optional class Ids for the points.
Definition points3d.hpp:234
std::optional< ComponentBatch > keypoint_ids
Optional keypoint IDs for the points, identifying them within a class.
Definition points3d.hpp:244
Collection< ComponentColumn > columns()
Partitions the component data into unit-length sub-batches.
Definition points3d.hpp:430
std::optional< ComponentBatch > positions
All the 3D positions at which the point cloud shows points.
Definition points3d.hpp:203
static constexpr auto Descriptor_radii
ComponentDescriptor for the radii field.
Definition points3d.hpp:256
static constexpr auto Descriptor_colors
ComponentDescriptor for the colors field.
Definition points3d.hpp:260
Points3D with_labels(const Collection< rerun::components::Text > &_labels) &&
Optional text labels for the points.
Definition points3d.hpp:332
Points3D with_positions(const Collection< rerun::components::Position3D > &_positions) &&
All the 3D positions at which the point cloud shows points.
Definition points3d.hpp:307
Points3D with_point_shading(const rerun::components::PointShading &_point_shading) &&
How points should be shaded.
Definition points3d.hpp:361
Points3D with_many_show_labels(const Collection< rerun::components::ShowLabels > &_show_labels) &&
This method makes it possible to pack multiple show_labels in a single component batch.
Definition points3d.hpp:351
Collection< ComponentColumn > columns(const Collection< uint32_t > &lengths_)
Partitions the component data into multiple sub-batches.
Definition points3d.hpp:411
static constexpr auto Descriptor_labels
ComponentDescriptor for the labels field.
Definition points3d.hpp:264
std::optional< ComponentBatch > point_shading
How points should be shaded.
Definition points3d.hpp:229
Points3D with_radii(const Collection< rerun::components::Radius > &_radii) &&
Optional radii for the points, effectively turning them into circles.
Definition points3d.hpp:314
static constexpr auto Descriptor_point_shading
ComponentDescriptor for the point_shading field.
Definition points3d.hpp:273
static constexpr const char ArchetypeName[]
The name of the archetype as used in ComponentDescriptors.
Definition points3d.hpp:248
static Points3D clear_fields()
Clear all the fields of a Points3D.
Points3D with_show_labels(const rerun::components::ShowLabels &_show_labels) &&
Whether the text labels should be shown.
Definition points3d.hpp:341
static constexpr auto Descriptor_positions
ComponentDescriptor for the positions field.
Definition points3d.hpp:251
std::optional< ComponentBatch > labels
Optional text labels for the points.
Definition points3d.hpp:218
static constexpr auto Descriptor_show_labels
ComponentDescriptor for the show_labels field.
Definition points3d.hpp:268
std::optional< ComponentBatch > radii
Optional radii for the points, effectively turning them into circles.
Definition points3d.hpp:206
static Points3D update_fields()
Update only some specific fields of a Points3D.
Definition points3d.hpp:299
std::optional< ComponentBatch > show_labels
Whether the text labels should be shown.
Definition points3d.hpp:224
Points3D with_colors(const Collection< rerun::components::Color > &_colors) &&
Optional colors for the points.
Definition points3d.hpp:323
Points3D with_class_ids(const Collection< rerun::components::ClassId > &_class_ids) &&
Optional class Ids for the points.
Definition points3d.hpp:382
std::optional< ComponentBatch > colors
Optional colors for the points.
Definition points3d.hpp:212
static constexpr auto Descriptor_keypoint_ids
ComponentDescriptor for the keypoint_ids field.
Definition points3d.hpp:282
Points3D with_keypoint_ids(const Collection< rerun::components::KeypointId > &_keypoint_ids) &&
Optional keypoint IDs for the points, identifying them within a class.
Definition points3d.hpp:396
Component: Whether the entity's components::Text label is shown.
Definition show_labels.hpp:18