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