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