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