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 /// Optional choice of whether the text labels should be shown by default.
124 std::optional<ComponentBatch> show_labels;
125
126 /// An optional floating point value that specifies the 2D drawing order.
127 ///
128 /// Objects with higher values are drawn on top of those with lower values.
129 std::optional<ComponentBatch> draw_order;
130
131 /// Optional class Ids for the points.
132 ///
133 /// The `components::ClassId` provides colors and labels if not specified explicitly.
134 std::optional<ComponentBatch> class_ids;
135
136 /// Optional keypoint IDs for the points, identifying them within a class.
137 ///
138 /// If keypoint IDs are passed in but no `components::ClassId`s were specified, the `components::ClassId` will
139 /// default to 0.
140 /// This is useful to identify points within a single classification (which is identified
141 /// with `class_id`).
142 /// E.g. the classification might be 'Person' and the keypoints refer to joints on a
143 /// detected skeleton.
144 std::optional<ComponentBatch> keypoint_ids;
145
146 public:
147 static constexpr const char IndicatorComponentName[] = "rerun.components.Points2DIndicator";
148
149 /// Indicator component, used to identify the archetype when converting to a list of components.
151 /// The name of the archetype as used in `ComponentDescriptor`s.
152 static constexpr const char ArchetypeName[] = "rerun.archetypes.Points2D";
153
154 /// `ComponentDescriptor` for the `positions` field.
156 ArchetypeName, "positions",
158 );
159 /// `ComponentDescriptor` for the `radii` field.
160 static constexpr auto Descriptor_radii = ComponentDescriptor(
162 );
163 /// `ComponentDescriptor` for the `colors` field.
164 static constexpr auto Descriptor_colors = ComponentDescriptor(
166 );
167 /// `ComponentDescriptor` for the `labels` field.
168 static constexpr auto Descriptor_labels = ComponentDescriptor(
170 );
171 /// `ComponentDescriptor` for the `show_labels` field.
173 ArchetypeName, "show_labels",
175 );
176 /// `ComponentDescriptor` for the `draw_order` field.
178 ArchetypeName, "draw_order",
180 );
181 /// `ComponentDescriptor` for the `class_ids` field.
183 ArchetypeName, "class_ids",
185 );
186 /// `ComponentDescriptor` for the `keypoint_ids` field.
188 ArchetypeName, "keypoint_ids",
190 );
191
192 public:
193 Points2D() = default;
194 Points2D(Points2D&& other) = default;
195 Points2D(const Points2D& other) = default;
196 Points2D& operator=(const Points2D& other) = default;
197 Points2D& operator=(Points2D&& other) = default;
198
200 : positions(ComponentBatch::from_loggable(std::move(_positions), Descriptor_positions)
201 .value_or_throw()) {}
202
203 /// Update only some specific fields of a `Points2D`.
205 return Points2D();
206 }
207
208 /// Clear all the fields of a `Points2D`.
210
211 /// All the 2D positions at which the point cloud shows points.
213 positions =
214 ComponentBatch::from_loggable(_positions, Descriptor_positions).value_or_throw();
215 return std::move(*this);
216 }
217
218 /// Optional radii for the points, effectively turning them into circles.
220 radii = ComponentBatch::from_loggable(_radii, Descriptor_radii).value_or_throw();
221 return std::move(*this);
222 }
223
224 /// Optional colors for the points.
226 colors = ComponentBatch::from_loggable(_colors, Descriptor_colors).value_or_throw();
227 return std::move(*this);
228 }
229
230 /// Optional text labels for the points.
231 ///
232 /// If there's a single label present, it will be placed at the center of the entity.
233 /// Otherwise, each instance will have its own label.
235 labels = ComponentBatch::from_loggable(_labels, Descriptor_labels).value_or_throw();
236 return std::move(*this);
237 }
238
239 /// Optional choice of whether the text labels should be shown by default.
242 .value_or_throw();
243 return std::move(*this);
244 }
245
246 /// This method makes it possible to pack multiple `show_labels` in a single component batch.
247 ///
248 /// This only makes sense when used in conjunction with `columns`. `with_show_labels` should
249 /// be used when logging a single row's worth of data.
251 ) && {
253 .value_or_throw();
254 return std::move(*this);
255 }
256
257 /// An optional floating point value that specifies the 2D drawing order.
258 ///
259 /// Objects with higher values are drawn on top of those with lower values.
261 draw_order =
262 ComponentBatch::from_loggable(_draw_order, Descriptor_draw_order).value_or_throw();
263 return std::move(*this);
264 }
265
266 /// This method makes it possible to pack multiple `draw_order` in a single component batch.
267 ///
268 /// This only makes sense when used in conjunction with `columns`. `with_draw_order` should
269 /// be used when logging a single row's worth of data.
271 ) && {
272 draw_order =
273 ComponentBatch::from_loggable(_draw_order, Descriptor_draw_order).value_or_throw();
274 return std::move(*this);
275 }
276
277 /// Optional class Ids for the points.
278 ///
279 /// The `components::ClassId` provides colors and labels if not specified explicitly.
281 class_ids =
282 ComponentBatch::from_loggable(_class_ids, Descriptor_class_ids).value_or_throw();
283 return std::move(*this);
284 }
285
286 /// Optional keypoint IDs for the points, identifying them within a class.
287 ///
288 /// If keypoint IDs are passed in but no `components::ClassId`s were specified, the `components::ClassId` will
289 /// default to 0.
290 /// This is useful to identify points within a single classification (which is identified
291 /// with `class_id`).
292 /// E.g. the classification might be 'Person' and the keypoints refer to joints on a
293 /// detected skeleton.
295 ) && {
297 .value_or_throw();
298 return std::move(*this);
299 }
300
301 /// Partitions the component data into multiple sub-batches.
302 ///
303 /// Specifically, this transforms the existing `ComponentBatch` data into `ComponentColumn`s
304 /// instead, via `ComponentBatch::partitioned`.
305 ///
306 /// This makes it possible to use `RecordingStream::send_columns` to send columnar data directly into Rerun.
307 ///
308 /// The specified `lengths` must sum to the total length of the component batch.
310
311 /// Partitions the component data into unit-length sub-batches.
312 ///
313 /// This is semantically similar to calling `columns` with `std::vector<uint32_t>(n, 1)`,
314 /// where `n` is automatically guessed.
316 };
317
318} // namespace rerun::archetypes
319
320namespace rerun {
321 /// \private
322 template <typename T>
323 struct AsComponents;
324
325 /// \private
326 template <>
327 struct AsComponents<archetypes::Points2D> {
328 /// Serialize all set component batches.
329 static Result<Collection<ComponentBatch>> as_batches(const archetypes::Points2D& archetype);
330 };
331} // 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 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:177
std::optional< ComponentBatch > show_labels
Optional choice of whether the text labels should be shown by default.
Definition points2d.hpp:124
Points2D with_labels(const Collection< rerun::components::Text > &_labels) &&
Optional text labels for the points.
Definition points2d.hpp:234
static constexpr auto Descriptor_class_ids
ComponentDescriptor for the class_ids field.
Definition points2d.hpp:182
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:225
static constexpr auto Descriptor_radii
ComponentDescriptor for the radii field.
Definition points2d.hpp:160
static constexpr auto Descriptor_keypoint_ids
ComponentDescriptor for the keypoint_ids field.
Definition points2d.hpp:187
Points2D with_positions(const Collection< rerun::components::Position2D > &_positions) &&
All the 2D positions at which the point cloud shows points.
Definition points2d.hpp:212
static constexpr auto Descriptor_labels
ComponentDescriptor for the labels field.
Definition points2d.hpp:168
Points2D with_show_labels(const rerun::components::ShowLabels &_show_labels) &&
Optional choice of whether the text labels should be shown by default.
Definition points2d.hpp:240
static constexpr const char ArchetypeName[]
The name of the archetype as used in ComponentDescriptors.
Definition points2d.hpp:152
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:294
Points2D with_radii(const Collection< rerun::components::Radius > &_radii) &&
Optional radii for the points, effectively turning them into circles.
Definition points2d.hpp:219
std::optional< ComponentBatch > draw_order
An optional floating point value that specifies the 2D drawing order.
Definition points2d.hpp:129
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:280
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:250
std::optional< ComponentBatch > keypoint_ids
Optional keypoint IDs for the points, identifying them within a class.
Definition points2d.hpp:144
std::optional< ComponentBatch > class_ids
Optional class Ids for the points.
Definition points2d.hpp:134
static constexpr auto Descriptor_positions
ComponentDescriptor for the positions field.
Definition points2d.hpp:155
Points2D with_draw_order(const rerun::components::DrawOrder &_draw_order) &&
An optional floating point value that specifies the 2D drawing order.
Definition points2d.hpp:260
static constexpr auto Descriptor_show_labels
ComponentDescriptor for the show_labels field.
Definition points2d.hpp:172
static constexpr auto Descriptor_colors
ComponentDescriptor for the colors field.
Definition points2d.hpp:164
static Points2D update_fields()
Update only some specific fields of a Points2D.
Definition points2d.hpp:204
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:270
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