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