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