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