Rerun C++ SDK
Loading...
Searching...
No Matches
points2d.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/build/re_type_definitions/rerun/archetypes/points2d.def.rs".
3
4#pragma once
5
6#include "../archetype_utils.hpp"
7#include "../collection.hpp"
8#include "../component_batch.hpp"
9#include "../component_column.hpp"
10#include "../components/class_id.hpp"
11#include "../components/color.hpp"
12#include "../components/draw_order.hpp"
13#include "../components/keypoint_id.hpp"
14#include "../components/position2d.hpp"
15#include "../components/radius.hpp"
16#include "../components/show_labels.hpp"
17#include "../components/text.hpp"
18#include "../result.hpp"
19
20#include <cstdint>
21#include <optional>
22#include <utility>
23#include <vector>
24
25namespace rerun::archetypes {
26 /// **Archetype**: A 2D point cloud with positions and optional colors, radii, labels, etc.
27 ///
28 /// ## Examples
29 ///
30 /// ### Randomly distributed 2D points with varying color and radius
31 /// ![image](https://static.rerun.io/point2d_random/8e8ac75373677bd72bd3f56a15e44fcab309a168/full.png)
32 ///
33 /// ```cpp
34 /// #include <rerun.hpp>
35 ///
36 /// #include <algorithm>
37 /// #include <random>
38 /// #include <vector>
39 ///
40 /// int main(int argc, char* argv[]) {
41 /// const auto rec = rerun::RecordingStream("rerun_example_points2d_random");
42 /// rec.spawn().exit_on_failure();
43 ///
44 /// std::default_random_engine gen;
45 /// std::uniform_real_distribution<float> dist_pos(-3.0f, 3.0f);
46 /// std::uniform_real_distribution<float> dist_radius(0.1f, 1.0f);
47 /// // On MSVC uint8_t distributions are not supported.
48 /// std::uniform_int_distribution<int> dist_color(0, 255);
49 ///
50 /// std::vector<rerun::Position2D> points2d(10);
51 /// std::generate(points2d.begin(), points2d.end(), [&] {
52 /// return rerun::Position2D(dist_pos(gen), dist_pos(gen));
53 /// });
54 /// std::vector<rerun::Color> colors(10);
55 /// std::generate(colors.begin(), colors.end(), [&] {
56 /// return rerun::Color(
57 /// static_cast<uint8_t>(dist_color(gen)),
58 /// static_cast<uint8_t>(dist_color(gen)),
59 /// static_cast<uint8_t>(dist_color(gen))
60 /// );
61 /// });
62 /// std::vector<rerun::Radius> radii(10);
63 /// std::generate(radii.begin(), radii.end(), [&] { return dist_radius(gen); });
64 ///
65 /// rec.log(
66 /// "random",
67 /// rerun::Points2D(points2d).with_colors(colors).with_radii(radii)
68 /// );
69 ///
70 /// // TODO(#5520): log VisualBounds2D
71 /// }
72 /// ```
73 ///
74 /// ### Log points with radii given in UI points
75 /// ![image](https://static.rerun.io/point2d_ui_radius/ce804fc77300d89c348b4ab5960395171497b7ac/full.png)
76 ///
77 /// ```cpp
78 /// #include <rerun.hpp>
79 ///
80 /// int main(int argc, char* argv[]) {
81 /// const auto rec = rerun::RecordingStream("rerun_example_points2d_ui_radius");
82 /// rec.spawn().exit_on_failure();
83 ///
84 /// // Two blue points with scene unit radii of 0.1 and 0.3.
85 /// rec.log(
86 /// "scene_units",
87 /// rerun::Points2D({{0.0f, 0.0f}, {0.0f, 1.0f}})
88 /// // By default, radii are interpreted as world-space units.
89 /// .with_radii({0.1f, 0.3f})
90 /// .with_colors(rerun::Color(0, 0, 255))
91 /// );
92 ///
93 /// // Two red points with ui point radii of 40 and 60.
94 /// // UI points are independent of zooming in Views, but are sensitive to the application UI scaling.
95 /// // For 100% ui scaling, UI points are equal to pixels.
96 /// rec.log(
97 /// "ui_points",
98 /// rerun::Points2D({{1.0f, 0.0f}, {1.0f, 1.0f}})
99 /// // rerun::Radius::ui_points produces radii that the viewer interprets as given in ui points.
100 /// .with_radii({
101 /// rerun::Radius::ui_points(40.0f),
102 /// rerun::Radius::ui_points(60.0f),
103 /// })
104 /// .with_colors(rerun::Color(255, 0, 0))
105 /// );
106 ///
107 /// // TODO(#5521): log VisualBounds2D
108 /// }
109 /// ```
110 struct Points2D {
111 /// All the 2D positions at which the point cloud shows points.
112 std::optional<ComponentBatch> positions;
113
114 /// Optional radii for the points, effectively turning them into circles.
115 std::optional<ComponentBatch> radii;
116
117 /// Optional colors for the points.
118 std::optional<ComponentBatch> colors;
119
120 /// Optional text labels for the points.
121 ///
122 /// If there's a single label present, it will be placed at the center of the entity.
123 /// Otherwise, each instance will have its own label.
124 std::optional<ComponentBatch> labels;
125
126 /// Whether the text labels should be shown.
127 ///
128 /// If not set, labels will automatically appear when there is exactly one label for this entity
129 /// or the number of instances on this entity is under a certain threshold.
130 std::optional<ComponentBatch> show_labels;
131
132 /// An optional floating point value that specifies the 2D drawing order.
133 ///
134 /// Objects with higher values are drawn on top of those with lower values.
135 /// Defaults to `30.0`.
136 std::optional<ComponentBatch> draw_order;
137
138 /// Optional class Ids for the points.
139 ///
140 /// The `components::ClassId` provides colors and labels if not specified explicitly.
141 std::optional<ComponentBatch> class_ids;
142
143 /// Optional keypoint IDs for the points, identifying them within a class.
144 ///
145 /// If keypoint IDs are passed in but no `components::ClassId`s were specified, the `components::ClassId` will
146 /// default to 0.
147 /// This is useful to identify points within a single classification (which is identified
148 /// with `class_id`).
149 /// E.g. the classification might be 'Person' and the keypoints refer to joints on a
150 /// detected skeleton.
151 std::optional<ComponentBatch> keypoint_ids;
152
153 public:
154 /// The name of the archetype as used in `ComponentDescriptor`s.
155 static constexpr const char ArchetypeName[] = "rerun.archetypes.Points2D";
156
157 /// `ComponentDescriptor` for the `positions` field.
159 ArchetypeName, "Points2D:positions",
161 );
162 /// `ComponentDescriptor` for the `radii` field.
163 static constexpr auto Descriptor_radii = ComponentDescriptor(
165 );
166 /// `ComponentDescriptor` for the `colors` field.
167 static constexpr auto Descriptor_colors = ComponentDescriptor(
169 );
170 /// `ComponentDescriptor` for the `labels` field.
171 static constexpr auto Descriptor_labels = ComponentDescriptor(
173 );
174 /// `ComponentDescriptor` for the `show_labels` field.
176 ArchetypeName, "Points2D:show_labels",
178 );
179 /// `ComponentDescriptor` for the `draw_order` field.
181 ArchetypeName, "Points2D:draw_order",
183 );
184 /// `ComponentDescriptor` for the `class_ids` field.
187 );
188 /// `ComponentDescriptor` for the `keypoint_ids` field.
190 ArchetypeName, "Points2D:keypoint_ids",
192 );
193
194 public:
195 Points2D() = default;
196 Points2D(Points2D&& other) = default;
197 Points2D(const Points2D& other) = default;
198 Points2D& operator=(const Points2D& other) = default;
199 Points2D& operator=(Points2D&& other) = default;
200
202 : positions(ComponentBatch::from_loggable(std::move(_positions), Descriptor_positions)
203 .value_or_throw()) {}
204
205 /// Update only some specific fields of a `Points2D`.
207 return Points2D();
208 }
209
210 /// Clear all the fields of a `Points2D`.
212
213 /// All the 2D positions at which the point cloud shows points.
215 positions =
216 ComponentBatch::from_loggable(_positions, Descriptor_positions).value_or_throw();
217 return std::move(*this);
218 }
219
220 /// Optional radii for the points, effectively turning them into circles.
222 radii = ComponentBatch::from_loggable(_radii, Descriptor_radii).value_or_throw();
223 return std::move(*this);
224 }
225
226 /// Optional colors for the points.
228 colors = ComponentBatch::from_loggable(_colors, Descriptor_colors).value_or_throw();
229 return std::move(*this);
230 }
231
232 /// Optional text labels for the points.
233 ///
234 /// If there's a single label present, it will be placed at the center of the entity.
235 /// Otherwise, each instance will have its own label.
237 labels = ComponentBatch::from_loggable(_labels, Descriptor_labels).value_or_throw();
238 return std::move(*this);
239 }
240
241 /// Whether the text labels should be shown.
242 ///
243 /// If not set, labels will automatically appear when there is exactly one label for this entity
244 /// or the number of instances on this entity is under a certain threshold.
247 .value_or_throw();
248 return std::move(*this);
249 }
250
251 /// This method makes it possible to pack multiple `show_labels` in a single component batch.
252 ///
253 /// This only makes sense when used in conjunction with `columns`. `with_show_labels` should
254 /// be used when logging a single row's worth of data.
256 ) && {
258 .value_or_throw();
259 return std::move(*this);
260 }
261
262 /// An optional floating point value that specifies the 2D drawing order.
263 ///
264 /// Objects with higher values are drawn on top of those with lower values.
265 /// Defaults to `30.0`.
267 draw_order =
268 ComponentBatch::from_loggable(_draw_order, Descriptor_draw_order).value_or_throw();
269 return std::move(*this);
270 }
271
272 /// This method makes it possible to pack multiple `draw_order` in a single component batch.
273 ///
274 /// This only makes sense when used in conjunction with `columns`. `with_draw_order` should
275 /// be used when logging a single row's worth of data.
277 ) && {
278 draw_order =
279 ComponentBatch::from_loggable(_draw_order, Descriptor_draw_order).value_or_throw();
280 return std::move(*this);
281 }
282
283 /// Optional class Ids for the points.
284 ///
285 /// The `components::ClassId` provides colors and labels if not specified explicitly.
287 class_ids =
288 ComponentBatch::from_loggable(_class_ids, Descriptor_class_ids).value_or_throw();
289 return std::move(*this);
290 }
291
292 /// Optional keypoint IDs for the points, identifying them within a class.
293 ///
294 /// If keypoint IDs are passed in but no `components::ClassId`s were specified, the `components::ClassId` will
295 /// default to 0.
296 /// This is useful to identify points within a single classification (which is identified
297 /// with `class_id`).
298 /// E.g. the classification might be 'Person' and the keypoints refer to joints on a
299 /// detected skeleton.
301 ) && {
303 .value_or_throw();
304 return std::move(*this);
305 }
306
307 /// Partitions the component data into multiple sub-batches.
308 ///
309 /// Specifically, this transforms the existing `ComponentBatch` data into `ComponentColumn`s
310 /// instead, via `ComponentBatch::partitioned`.
311 ///
312 /// This makes it possible to use `RecordingStream::send_columns` to send columnar data directly into Rerun.
313 ///
314 /// The specified `lengths` must sum to the total length of the component batch.
316 return detail::partition_batches(
317 {&positions,
318 &radii,
319 &colors,
320 &labels,
322 &draw_order,
323 &class_ids,
324 &keypoint_ids},
325 lengths_
326 )
327 .value_or_throw();
328 }
329
330 /// Partitions the component data into unit-length sub-batches.
331 ///
332 /// This is semantically similar to calling `columns` with `std::vector<uint32_t>(n, 1)`,
333 /// where `n` is automatically guessed.
335 return detail::partition_batches_of_unit_length({&positions,
336 &radii,
337 &colors,
338 &labels,
340 &draw_order,
341 &class_ids,
342 &keypoint_ids})
343 .value_or_throw();
344 }
345 };
346
347} // namespace rerun::archetypes
348
349namespace rerun {
350 /// \private
351 template <typename T>
352 struct AsComponents;
353
354 /// \private
355 template <>
356 struct AsComponents<archetypes::Points2D> {
357 /// Serialize all set component batches.
358 static Result<Collection<ComponentBatch>> as_batches(const archetypes::Points2D& archetype
359 ) {
360 return detail::collect_batches(
361 {&archetype.positions,
362 &archetype.radii,
363 &archetype.colors,
364 &archetype.labels,
365 &archetype.show_labels,
366 &archetype.draw_order,
367 &archetype.class_ids,
368 &archetype.keypoint_ids}
369 );
370 }
371 };
372} // namespace rerun
Generic collection of elements that are roughly contiguous in memory.
Definition collection.hpp:49
All built-in archetypes. See Types in the Rerun manual.
Definition rerun.hpp:90
All Rerun C++ types and functions are in the rerun namespace or one of its nested namespaces.
Definition rerun.hpp:26
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 2D point cloud with positions and optional colors, radii, labels, etc.
Definition points2d.hpp:110
static constexpr auto Descriptor_draw_order
ComponentDescriptor for the draw_order field.
Definition points2d.hpp:180
std::optional< ComponentBatch > show_labels
Whether the text labels should be shown.
Definition points2d.hpp:130
Points2D with_labels(const Collection< rerun::components::Text > &_labels) &&
Optional text labels for the points.
Definition points2d.hpp:236
static constexpr auto Descriptor_class_ids
ComponentDescriptor for the class_ids field.
Definition points2d.hpp:185
Collection< ComponentColumn > columns()
Partitions the component data into unit-length sub-batches.
Definition points2d.hpp:334
std::optional< ComponentBatch > colors
Optional colors for the points.
Definition points2d.hpp:118
static Points2D clear_fields()
Clear all the fields of a Points2D.
std::optional< ComponentBatch > positions
All the 2D positions at which the point cloud shows points.
Definition points2d.hpp:112
Points2D with_colors(const Collection< rerun::components::Color > &_colors) &&
Optional colors for the points.
Definition points2d.hpp:227
static constexpr auto Descriptor_radii
ComponentDescriptor for the radii field.
Definition points2d.hpp:163
static constexpr auto Descriptor_keypoint_ids
ComponentDescriptor for the keypoint_ids field.
Definition points2d.hpp:189
Points2D with_positions(const Collection< rerun::components::Position2D > &_positions) &&
All the 2D positions at which the point cloud shows points.
Definition points2d.hpp:214
static constexpr auto Descriptor_labels
ComponentDescriptor for the labels field.
Definition points2d.hpp:171
Points2D with_show_labels(const rerun::components::ShowLabels &_show_labels) &&
Whether the text labels should be shown.
Definition points2d.hpp:245
static constexpr const char ArchetypeName[]
The name of the archetype as used in ComponentDescriptors.
Definition points2d.hpp:155
Collection< ComponentColumn > columns(const Collection< uint32_t > &lengths_)
Partitions the component data into multiple sub-batches.
Definition points2d.hpp:315
Points2D with_keypoint_ids(const Collection< rerun::components::KeypointId > &_keypoint_ids) &&
Optional keypoint IDs for the points, identifying them within a class.
Definition points2d.hpp:300
Points2D with_radii(const Collection< rerun::components::Radius > &_radii) &&
Optional radii for the points, effectively turning them into circles.
Definition points2d.hpp:221
std::optional< ComponentBatch > draw_order
An optional floating point value that specifies the 2D drawing order.
Definition points2d.hpp:136
std::optional< ComponentBatch > radii
Optional radii for the points, effectively turning them into circles.
Definition points2d.hpp:115
Points2D with_class_ids(const Collection< rerun::components::ClassId > &_class_ids) &&
Optional class Ids for the points.
Definition points2d.hpp:286
Points2D 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 points2d.hpp:255
std::optional< ComponentBatch > keypoint_ids
Optional keypoint IDs for the points, identifying them within a class.
Definition points2d.hpp:151
std::optional< ComponentBatch > class_ids
Optional class Ids for the points.
Definition points2d.hpp:141
static constexpr auto Descriptor_positions
ComponentDescriptor for the positions field.
Definition points2d.hpp:158
Points2D with_draw_order(const rerun::components::DrawOrder &_draw_order) &&
An optional floating point value that specifies the 2D drawing order.
Definition points2d.hpp:266
static constexpr auto Descriptor_show_labels
ComponentDescriptor for the show_labels field.
Definition points2d.hpp:175
static constexpr auto Descriptor_colors
ComponentDescriptor for the colors field.
Definition points2d.hpp:167
static Points2D update_fields()
Update only some specific fields of a Points2D.
Definition points2d.hpp:206
std::optional< ComponentBatch > labels
Optional text labels for the points.
Definition points2d.hpp:124
Points2D with_many_draw_order(const Collection< rerun::components::DrawOrder > &_draw_order) &&
This method makes it possible to pack multiple draw_order in a single component batch.
Definition points2d.hpp:276
Component: Draw order of 2D elements.
Definition draw_order.hpp:30
Component: Whether the entity's components::Text label is shown.
Definition show_labels.hpp:18