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 std::optional<ComponentBatch> colors;
209
210 /// Optional text labels for the points.
211 ///
212 /// If there's a single label present, it will be placed at the center of the entity.
213 /// Otherwise, each instance will have its own label.
214 std::optional<ComponentBatch> labels;
215
216 /// Whether the text labels should be shown.
217 ///
218 /// If not set, labels will automatically appear when there is exactly one label for this entity
219 /// or the number of instances on this entity is under a certain threshold.
220 std::optional<ComponentBatch> show_labels;
221
222 /// How points should be shaded.
223 ///
224 /// If not set, points are rendered with `components::PointShading::Gradient` by default.
225 std::optional<ComponentBatch> point_shading;
226
227 /// Optional class Ids for the points.
228 ///
229 /// The `components::ClassId` provides colors and labels if not specified explicitly.
230 std::optional<ComponentBatch> class_ids;
231
232 /// Optional keypoint IDs for the points, identifying them within a class.
233 ///
234 /// If keypoint IDs are passed in but no `components::ClassId`s were specified, the `components::ClassId` will
235 /// default to 0.
236 /// This is useful to identify points within a single classification (which is identified
237 /// with `class_id`).
238 /// E.g. the classification might be 'Person' and the keypoints refer to joints on a
239 /// detected skeleton.
240 std::optional<ComponentBatch> keypoint_ids;
241
242 public:
243 /// The name of the archetype as used in `ComponentDescriptor`s.
244 static constexpr const char ArchetypeName[] = "rerun.archetypes.Points3D";
245
246 /// `ComponentDescriptor` for the `positions` field.
248 ArchetypeName, "Points3D:positions",
250 );
251 /// `ComponentDescriptor` for the `radii` field.
252 static constexpr auto Descriptor_radii = ComponentDescriptor(
254 );
255 /// `ComponentDescriptor` for the `colors` field.
256 static constexpr auto Descriptor_colors = ComponentDescriptor(
258 );
259 /// `ComponentDescriptor` for the `labels` field.
260 static constexpr auto Descriptor_labels = ComponentDescriptor(
262 );
263 /// `ComponentDescriptor` for the `show_labels` field.
265 ArchetypeName, "Points3D:show_labels",
267 );
268 /// `ComponentDescriptor` for the `point_shading` field.
270 ArchetypeName, "Points3D:point_shading",
272 );
273 /// `ComponentDescriptor` for the `class_ids` field.
276 );
277 /// `ComponentDescriptor` for the `keypoint_ids` field.
279 ArchetypeName, "Points3D:keypoint_ids",
281 );
282
283 public:
284 Points3D() = default;
285 Points3D(Points3D&& other) = default;
286 Points3D(const Points3D& other) = default;
287 Points3D& operator=(const Points3D& other) = default;
288 Points3D& operator=(Points3D&& other) = default;
289
291 : positions(ComponentBatch::from_loggable(std::move(_positions), Descriptor_positions)
292 .value_or_throw()) {}
293
294 /// Update only some specific fields of a `Points3D`.
296 return Points3D();
297 }
298
299 /// Clear all the fields of a `Points3D`.
301
302 /// All the 3D positions at which the point cloud shows points.
304 positions =
305 ComponentBatch::from_loggable(_positions, Descriptor_positions).value_or_throw();
306 return std::move(*this);
307 }
308
309 /// Optional radii for the points, effectively turning them into circles.
311 radii = ComponentBatch::from_loggable(_radii, Descriptor_radii).value_or_throw();
312 return std::move(*this);
313 }
314
315 /// Optional colors for the points.
317 colors = ComponentBatch::from_loggable(_colors, Descriptor_colors).value_or_throw();
318 return std::move(*this);
319 }
320
321 /// Optional text labels for the points.
322 ///
323 /// If there's a single label present, it will be placed at the center of the entity.
324 /// Otherwise, each instance will have its own label.
326 labels = ComponentBatch::from_loggable(_labels, Descriptor_labels).value_or_throw();
327 return std::move(*this);
328 }
329
330 /// Whether the text labels should be shown.
331 ///
332 /// If not set, labels will automatically appear when there is exactly one label for this entity
333 /// or the number of instances on this entity is under a certain threshold.
336 .value_or_throw();
337 return std::move(*this);
338 }
339
340 /// This method makes it possible to pack multiple `show_labels` in a single component batch.
341 ///
342 /// This only makes sense when used in conjunction with `columns`. `with_show_labels` should
343 /// be used when logging a single row's worth of data.
345 ) && {
347 .value_or_throw();
348 return std::move(*this);
349 }
350
351 /// How points should be shaded.
352 ///
353 /// If not set, points are rendered with `components::PointShading::Gradient` by default.
356 .value_or_throw();
357 return std::move(*this);
358 }
359
360 /// This method makes it possible to pack multiple `point_shading` in a single component batch.
361 ///
362 /// This only makes sense when used in conjunction with `columns`. `with_point_shading` should
363 /// be used when logging a single row's worth of data.
366 ) && {
368 .value_or_throw();
369 return std::move(*this);
370 }
371
372 /// Optional class Ids for the points.
373 ///
374 /// The `components::ClassId` provides colors and labels if not specified explicitly.
376 class_ids =
377 ComponentBatch::from_loggable(_class_ids, Descriptor_class_ids).value_or_throw();
378 return std::move(*this);
379 }
380
381 /// Optional keypoint IDs for the points, identifying them within a class.
382 ///
383 /// If keypoint IDs are passed in but no `components::ClassId`s were specified, the `components::ClassId` will
384 /// default to 0.
385 /// This is useful to identify points within a single classification (which is identified
386 /// with `class_id`).
387 /// E.g. the classification might be 'Person' and the keypoints refer to joints on a
388 /// detected skeleton.
390 ) && {
392 .value_or_throw();
393 return std::move(*this);
394 }
395
396 /// Partitions the component data into multiple sub-batches.
397 ///
398 /// Specifically, this transforms the existing `ComponentBatch` data into `ComponentColumn`s
399 /// instead, via `ComponentBatch::partitioned`.
400 ///
401 /// This makes it possible to use `RecordingStream::send_columns` to send columnar data directly into Rerun.
402 ///
403 /// The specified `lengths` must sum to the total length of the component batch.
405
406 /// Partitions the component data into unit-length sub-batches.
407 ///
408 /// This is semantically similar to calling `columns` with `std::vector<uint32_t>(n, 1)`,
409 /// where `n` is automatically guessed.
411 };
412
413} // namespace rerun::archetypes
414
415namespace rerun {
416 /// \private
417 template <typename T>
418 struct AsComponents;
419
420 /// \private
421 template <>
422 struct AsComponents<archetypes::Points3D> {
423 /// Serialize all set component batches.
424 static Result<Collection<ComponentBatch>> as_batches(const archetypes::Points3D& archetype);
425 };
426} // 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:274
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:364
std::optional< ComponentBatch > class_ids
Optional class Ids for the points.
Definition points3d.hpp:230
std::optional< ComponentBatch > keypoint_ids
Optional keypoint IDs for the points, identifying them within a class.
Definition points3d.hpp:240
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:252
static constexpr auto Descriptor_colors
ComponentDescriptor for the colors field.
Definition points3d.hpp:256
Points3D with_labels(const Collection< rerun::components::Text > &_labels) &&
Optional text labels for the points.
Definition points3d.hpp:325
Points3D with_positions(const Collection< rerun::components::Position3D > &_positions) &&
All the 3D positions at which the point cloud shows points.
Definition points3d.hpp:303
Points3D with_point_shading(const rerun::components::PointShading &_point_shading) &&
How points should be shaded.
Definition points3d.hpp:354
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:344
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:260
std::optional< ComponentBatch > point_shading
How points should be shaded.
Definition points3d.hpp:225
Points3D with_radii(const Collection< rerun::components::Radius > &_radii) &&
Optional radii for the points, effectively turning them into circles.
Definition points3d.hpp:310
static constexpr auto Descriptor_point_shading
ComponentDescriptor for the point_shading field.
Definition points3d.hpp:269
static constexpr const char ArchetypeName[]
The name of the archetype as used in ComponentDescriptors.
Definition points3d.hpp:244
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:334
static constexpr auto Descriptor_positions
ComponentDescriptor for the positions field.
Definition points3d.hpp:247
std::optional< ComponentBatch > labels
Optional text labels for the points.
Definition points3d.hpp:214
static constexpr auto Descriptor_show_labels
ComponentDescriptor for the show_labels field.
Definition points3d.hpp:264
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:295
std::optional< ComponentBatch > show_labels
Whether the text labels should be shown.
Definition points3d.hpp:220
Points3D with_colors(const Collection< rerun::components::Color > &_colors) &&
Optional colors for the points.
Definition points3d.hpp:316
Points3D with_class_ids(const Collection< rerun::components::ClassId > &_class_ids) &&
Optional class Ids for the points.
Definition points3d.hpp:375
std::optional< ComponentBatch > colors
Optional colors for the points.
Definition points3d.hpp:208
static constexpr auto Descriptor_keypoint_ids
ComponentDescriptor for the keypoint_ids field.
Definition points3d.hpp:278
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:389
Component: Whether the entity's components::Text label is shown.
Definition show_labels.hpp:18