Rerun C++ SDK
Loading...
Searching...
No Matches
boxes2d.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/boxes2d.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/half_size2d.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**: 2D boxes with half-extents and optional center, colors etc.
27 ///
28 /// ## Example
29 ///
30 /// ### Simple 2D boxes
31 /// ![image](https://static.rerun.io/box2d_simple/ac4424f3cf747382867649610cbd749c45b2020b/full.png)
32 ///
33 /// ```cpp
34 /// #include <rerun.hpp>
35 ///
36 /// int main() {
37 /// const auto rec = rerun::RecordingStream("rerun_example_box2d");
38 /// rec.spawn().exit_on_failure();
39 ///
40 /// rec.log("simple", rerun::Boxes2D::from_mins_and_sizes({{-1.f, -1.f}}, {{2.f, 2.f}}));
41 /// }
42 /// ```
43 struct Boxes2D {
44 /// All half-extents that make up the batch of boxes.
45 std::optional<ComponentBatch> half_sizes;
46
47 /// Optional center positions of the boxes.
48 std::optional<ComponentBatch> centers;
49
50 /// Optional colors for the boxes.
51 std::optional<ComponentBatch> colors;
52
53 /// Optional radii for the lines that make up the boxes.
54 std::optional<ComponentBatch> radii;
55
56 /// Optional text labels for the boxes.
57 ///
58 /// If there's a single label present, it will be placed at the center of the entity.
59 /// Otherwise, each instance will have its own label.
60 std::optional<ComponentBatch> labels;
61
62 /// Whether the text labels should be shown.
63 ///
64 /// If not set, labels will automatically appear when there is exactly one label for this entity
65 /// or the number of instances on this entity is under a certain threshold.
66 std::optional<ComponentBatch> show_labels;
67
68 /// An optional floating point value that specifies the 2D drawing order.
69 ///
70 /// Objects with higher values are drawn on top of those with lower values.
71 /// Defaults to `10.0`.
72 std::optional<ComponentBatch> draw_order;
73
74 /// Optional `components::ClassId`s for the boxes.
75 ///
76 /// The `components::ClassId` provides colors and labels if not specified explicitly.
77 std::optional<ComponentBatch> class_ids;
78
79 public:
80 static constexpr const char IndicatorComponentName[] = "rerun.components.Boxes2DIndicator";
81
82 /// Indicator component, used to identify the archetype when converting to a list of components.
84 /// The name of the archetype as used in `ComponentDescriptor`s.
85 static constexpr const char ArchetypeName[] = "rerun.archetypes.Boxes2D";
86
87 /// `ComponentDescriptor` for the `half_sizes` field.
89 ArchetypeName, "half_sizes",
91 );
92 /// `ComponentDescriptor` for the `centers` field.
93 static constexpr auto Descriptor_centers = ComponentDescriptor(
94 ArchetypeName, "centers",
96 );
97 /// `ComponentDescriptor` for the `colors` field.
98 static constexpr auto Descriptor_colors = ComponentDescriptor(
100 );
101 /// `ComponentDescriptor` for the `radii` field.
102 static constexpr auto Descriptor_radii = ComponentDescriptor(
104 );
105 /// `ComponentDescriptor` for the `labels` field.
106 static constexpr auto Descriptor_labels = ComponentDescriptor(
108 );
109 /// `ComponentDescriptor` for the `show_labels` field.
111 ArchetypeName, "show_labels",
113 );
114 /// `ComponentDescriptor` for the `draw_order` field.
116 ArchetypeName, "draw_order",
118 );
119 /// `ComponentDescriptor` for the `class_ids` field.
121 ArchetypeName, "class_ids",
123 );
124
125 public: // START of extensions from boxes2d_ext.cpp:
126 /// Creates new `Boxes2D` with `half_sizes` centered around the local origin.
128 return Boxes2D().with_half_sizes(std::move(half_sizes));
129 }
130
131 /// Creates new `Boxes2D` with `centers` and `half_sizes`.
135 ) {
136 return Boxes2D()
137 .with_half_sizes(std::move(half_sizes))
138 .with_centers(std::move(centers));
139 }
140
141 /// Creates new `Boxes2D` with `half_sizes` created from (full) sizes.
142 ///
143 /// TODO(#3285): Does *not* preserve data as-is and instead creates half-sizes from the
144 /// input data.
145 static Boxes2D from_sizes(const std::vector<datatypes::Vec2D>& sizes);
146
147 /// Creates new `Boxes2D` with `centers` and `half_sizes` created from centers and (full)
148 /// sizes.
149 ///
150 /// TODO(#3285): Does *not* preserve data as-is and instead creates centers and half-sizes
151 /// from the input data.
153 Collection<components::Position2D> centers, const std::vector<datatypes::Vec2D>& sizes
154 ) {
155 return from_sizes(std::move(sizes)).with_centers(std::move(centers));
156 }
157
158 /// Creates new `Boxes2D` with `half_sizes` and `centers` created from minimums and (full)
159 /// sizes.
160 ///
161 /// TODO(#3285): Does *not* preserve data as-is and instead creates centers and half-sizes
162 /// from the input data.
164 const std::vector<datatypes::Vec2D>& mins, const std::vector<datatypes::Vec2D>& sizes
165 );
166
167 // END of extensions from boxes2d_ext.cpp, start of generated code:
168
169 public:
170 Boxes2D() = default;
171 Boxes2D(Boxes2D&& other) = default;
172 Boxes2D(const Boxes2D& other) = default;
173 Boxes2D& operator=(const Boxes2D& other) = default;
174 Boxes2D& operator=(Boxes2D&& other) = default;
175
176 /// Update only some specific fields of a `Boxes2D`.
178 return Boxes2D();
179 }
180
181 /// Clear all the fields of a `Boxes2D`.
183
184 /// All half-extents that make up the batch of boxes.
186 half_sizes =
187 ComponentBatch::from_loggable(_half_sizes, Descriptor_half_sizes).value_or_throw();
188 return std::move(*this);
189 }
190
191 /// Optional center positions of the boxes.
193 centers = ComponentBatch::from_loggable(_centers, Descriptor_centers).value_or_throw();
194 return std::move(*this);
195 }
196
197 /// Optional colors for the boxes.
199 colors = ComponentBatch::from_loggable(_colors, Descriptor_colors).value_or_throw();
200 return std::move(*this);
201 }
202
203 /// Optional radii for the lines that make up the boxes.
205 radii = ComponentBatch::from_loggable(_radii, Descriptor_radii).value_or_throw();
206 return std::move(*this);
207 }
208
209 /// Optional text labels for the boxes.
210 ///
211 /// If there's a single label present, it will be placed at the center of the entity.
212 /// Otherwise, each instance will have its own label.
214 labels = ComponentBatch::from_loggable(_labels, Descriptor_labels).value_or_throw();
215 return std::move(*this);
216 }
217
218 /// Whether the text labels should be shown.
219 ///
220 /// If not set, labels will automatically appear when there is exactly one label for this entity
221 /// or the number of instances on this entity is under a certain threshold.
224 .value_or_throw();
225 return std::move(*this);
226 }
227
228 /// This method makes it possible to pack multiple `show_labels` in a single component batch.
229 ///
230 /// This only makes sense when used in conjunction with `columns`. `with_show_labels` should
231 /// be used when logging a single row's worth of data.
233 ) && {
235 .value_or_throw();
236 return std::move(*this);
237 }
238
239 /// An optional floating point value that specifies the 2D drawing order.
240 ///
241 /// Objects with higher values are drawn on top of those with lower values.
242 /// Defaults to `10.0`.
244 draw_order =
245 ComponentBatch::from_loggable(_draw_order, Descriptor_draw_order).value_or_throw();
246 return std::move(*this);
247 }
248
249 /// This method makes it possible to pack multiple `draw_order` in a single component batch.
250 ///
251 /// This only makes sense when used in conjunction with `columns`. `with_draw_order` should
252 /// be used when logging a single row's worth of data.
254 ) && {
255 draw_order =
256 ComponentBatch::from_loggable(_draw_order, Descriptor_draw_order).value_or_throw();
257 return std::move(*this);
258 }
259
260 /// Optional `components::ClassId`s for the boxes.
261 ///
262 /// The `components::ClassId` provides colors and labels if not specified explicitly.
264 class_ids =
265 ComponentBatch::from_loggable(_class_ids, Descriptor_class_ids).value_or_throw();
266 return std::move(*this);
267 }
268
269 /// Partitions the component data into multiple sub-batches.
270 ///
271 /// Specifically, this transforms the existing `ComponentBatch` data into `ComponentColumn`s
272 /// instead, via `ComponentBatch::partitioned`.
273 ///
274 /// This makes it possible to use `RecordingStream::send_columns` to send columnar data directly into Rerun.
275 ///
276 /// The specified `lengths` must sum to the total length of the component batch.
278
279 /// Partitions the component data into unit-length sub-batches.
280 ///
281 /// This is semantically similar to calling `columns` with `std::vector<uint32_t>(n, 1)`,
282 /// where `n` is automatically guessed.
284 };
285
286} // namespace rerun::archetypes
287
288namespace rerun {
289 /// \private
290 template <typename T>
291 struct AsComponents;
292
293 /// \private
294 template <>
295 struct AsComponents<archetypes::Boxes2D> {
296 /// Serialize all set component batches.
297 static Result<Collection<ComponentBatch>> as_batches(const archetypes::Boxes2D& archetype);
298 };
299} // 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
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: 2D boxes with half-extents and optional center, colors etc.
Definition boxes2d.hpp:43
static Boxes2D clear_fields()
Clear all the fields of a Boxes2D.
Boxes2D with_class_ids(const Collection< rerun::components::ClassId > &_class_ids) &&
Optional components::ClassIds for the boxes.
Definition boxes2d.hpp:263
static constexpr auto Descriptor_show_labels
ComponentDescriptor for the show_labels field.
Definition boxes2d.hpp:110
std::optional< ComponentBatch > centers
Optional center positions of the boxes.
Definition boxes2d.hpp:48
static Boxes2D update_fields()
Update only some specific fields of a Boxes2D.
Definition boxes2d.hpp:177
std::optional< ComponentBatch > draw_order
An optional floating point value that specifies the 2D drawing order.
Definition boxes2d.hpp:72
std::optional< ComponentBatch > show_labels
Whether the text labels should be shown.
Definition boxes2d.hpp:66
Boxes2D with_draw_order(const rerun::components::DrawOrder &_draw_order) &&
An optional floating point value that specifies the 2D drawing order.
Definition boxes2d.hpp:243
std::optional< ComponentBatch > radii
Optional radii for the lines that make up the boxes.
Definition boxes2d.hpp:54
std::optional< ComponentBatch > half_sizes
All half-extents that make up the batch of boxes.
Definition boxes2d.hpp:45
Boxes2D with_labels(const Collection< rerun::components::Text > &_labels) &&
Optional text labels for the boxes.
Definition boxes2d.hpp:213
Boxes2D with_colors(const Collection< rerun::components::Color > &_colors) &&
Optional colors for the boxes.
Definition boxes2d.hpp:198
static constexpr const char ArchetypeName[]
The name of the archetype as used in ComponentDescriptors.
Definition boxes2d.hpp:85
Collection< ComponentColumn > columns()
Partitions the component data into unit-length sub-batches.
Boxes2D with_half_sizes(const Collection< rerun::components::HalfSize2D > &_half_sizes) &&
All half-extents that make up the batch of boxes.
Definition boxes2d.hpp:185
static constexpr auto Descriptor_class_ids
ComponentDescriptor for the class_ids field.
Definition boxes2d.hpp:120
static constexpr auto Descriptor_radii
ComponentDescriptor for the radii field.
Definition boxes2d.hpp:102
static constexpr auto Descriptor_colors
ComponentDescriptor for the colors field.
Definition boxes2d.hpp:98
Boxes2D with_centers(const Collection< rerun::components::Position2D > &_centers) &&
Optional center positions of the boxes.
Definition boxes2d.hpp:192
static constexpr auto Descriptor_draw_order
ComponentDescriptor for the draw_order field.
Definition boxes2d.hpp:115
static Boxes2D from_centers_and_sizes(Collection< components::Position2D > centers, const std::vector< datatypes::Vec2D > &sizes)
Creates new Boxes2D with centers and half_sizes created from centers and (full) sizes.
Definition boxes2d.hpp:152
Collection< ComponentColumn > columns(const Collection< uint32_t > &lengths_)
Partitions the component data into multiple sub-batches.
Boxes2D 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 boxes2d.hpp:232
static Boxes2D from_sizes(const std::vector< datatypes::Vec2D > &sizes)
Creates new Boxes2D with half_sizes created from (full) sizes.
static Boxes2D from_centers_and_half_sizes(Collection< components::Position2D > centers, Collection< components::HalfSize2D > half_sizes)
Creates new Boxes2D with centers and half_sizes.
Definition boxes2d.hpp:132
static constexpr auto Descriptor_labels
ComponentDescriptor for the labels field.
Definition boxes2d.hpp:106
static constexpr auto Descriptor_half_sizes
ComponentDescriptor for the half_sizes field.
Definition boxes2d.hpp:88
Boxes2D 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 boxes2d.hpp:253
std::optional< ComponentBatch > labels
Optional text labels for the boxes.
Definition boxes2d.hpp:60
std::optional< ComponentBatch > colors
Optional colors for the boxes.
Definition boxes2d.hpp:51
Boxes2D with_radii(const Collection< rerun::components::Radius > &_radii) &&
Optional radii for the lines that make up the boxes.
Definition boxes2d.hpp:204
static constexpr auto Descriptor_centers
ComponentDescriptor for the centers field.
Definition boxes2d.hpp:93
static Boxes2D from_half_sizes(Collection< components::HalfSize2D > half_sizes)
Creates new Boxes2D with half_sizes centered around the local origin.
Definition boxes2d.hpp:127
static Boxes2D from_mins_and_sizes(const std::vector< datatypes::Vec2D > &mins, const std::vector< datatypes::Vec2D > &sizes)
Creates new Boxes2D with half_sizes and centers created from minimums and (full) sizes.
Boxes2D with_show_labels(const rerun::components::ShowLabels &_show_labels) &&
Whether the text labels should be shown.
Definition boxes2d.hpp:222
std::optional< ComponentBatch > class_ids
Optional components::ClassIds for the boxes.
Definition boxes2d.hpp:77
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