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_seconds("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_times("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 /// Optional choice of whether the text labels should be shown by default.
192 std::optional<ComponentBatch> show_labels;
193
194 /// Optional class Ids for the points.
195 ///
196 /// The `components::ClassId` provides colors and labels if not specified explicitly.
197 std::optional<ComponentBatch> class_ids;
198
199 /// Optional keypoint IDs for the points, identifying them within a class.
200 ///
201 /// If keypoint IDs are passed in but no `components::ClassId`s were specified, the `components::ClassId` will
202 /// default to 0.
203 /// This is useful to identify points within a single classification (which is identified
204 /// with `class_id`).
205 /// E.g. the classification might be 'Person' and the keypoints refer to joints on a
206 /// detected skeleton.
207 std::optional<ComponentBatch> keypoint_ids;
208
209 public:
210 static constexpr const char IndicatorComponentName[] = "rerun.components.Points3DIndicator";
211
212 /// Indicator component, used to identify the archetype when converting to a list of components.
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, "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, "show_labels",
238 );
239 /// `ComponentDescriptor` for the `class_ids` field.
241 ArchetypeName, "class_ids",
243 );
244 /// `ComponentDescriptor` for the `keypoint_ids` field.
246 ArchetypeName, "keypoint_ids",
248 );
249
250 public:
251 Points3D() = default;
252 Points3D(Points3D&& other) = default;
253 Points3D(const Points3D& other) = default;
254 Points3D& operator=(const Points3D& other) = default;
255 Points3D& operator=(Points3D&& other) = default;
256
258 : positions(ComponentBatch::from_loggable(std::move(_positions), Descriptor_positions)
259 .value_or_throw()) {}
260
261 /// Update only some specific fields of a `Points3D`.
263 return Points3D();
264 }
265
266 /// Clear all the fields of a `Points3D`.
268
269 /// All the 3D positions at which the point cloud shows points.
271 positions =
272 ComponentBatch::from_loggable(_positions, Descriptor_positions).value_or_throw();
273 return std::move(*this);
274 }
275
276 /// Optional radii for the points, effectively turning them into circles.
278 radii = ComponentBatch::from_loggable(_radii, Descriptor_radii).value_or_throw();
279 return std::move(*this);
280 }
281
282 /// Optional colors for the points.
284 colors = ComponentBatch::from_loggable(_colors, Descriptor_colors).value_or_throw();
285 return std::move(*this);
286 }
287
288 /// Optional text labels for the points.
289 ///
290 /// If there's a single label present, it will be placed at the center of the entity.
291 /// Otherwise, each instance will have its own label.
293 labels = ComponentBatch::from_loggable(_labels, Descriptor_labels).value_or_throw();
294 return std::move(*this);
295 }
296
297 /// Optional choice of whether the text labels should be shown by default.
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=rerun::Loggable< T >::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:240
std::optional< ComponentBatch > class_ids
Optional class Ids for the points.
Definition points3d.hpp:197
std::optional< ComponentBatch > keypoint_ids
Optional keypoint IDs for the points, identifying them within a class.
Definition points3d.hpp:207
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: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:292
Points3D with_positions(const Collection< rerun::components::Position3D > &_positions) &&
All the 3D positions at which the point cloud shows points.
Definition points3d.hpp:270
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:231
Points3D with_radii(const Collection< rerun::components::Radius > &_radii) &&
Optional radii for the points, effectively turning them into circles.
Definition points3d.hpp:277
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) &&
Optional choice of whether the text labels should be shown by default.
Definition points3d.hpp:298
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:189
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:180
static Points3D update_fields()
Update only some specific fields of a Points3D.
Definition points3d.hpp:262
std::optional< ComponentBatch > show_labels
Optional choice of whether the text labels should be shown by default.
Definition points3d.hpp:192
Points3D with_colors(const Collection< rerun::components::Color > &_colors) &&
Optional colors for the points.
Definition points3d.hpp:283
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:183
static constexpr auto Descriptor_keypoint_ids
ComponentDescriptor for the keypoint_ids field.
Definition points3d.hpp:245
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
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