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