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