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