Rerun C++ SDK
Loading...
Searching...
No Matches
arrows2d.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/build/re_type_definitions/rerun/archetypes/arrows2d.def.rs".
3
4#pragma once
5
6#include "../archetype_utils.hpp"
7#include "../collection.hpp"
8#include "../component_batch.hpp"
9#include "../component_column.hpp"
10#include "../components/class_id.hpp"
11#include "../components/color.hpp"
12#include "../components/draw_order.hpp"
13#include "../components/position2d.hpp"
14#include "../components/radius.hpp"
15#include "../components/show_labels.hpp"
16#include "../components/text.hpp"
17#include "../components/vector2d.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 arrows with optional colors, radii, labels, etc.
27 ///
28 /// ## Example
29 ///
30 /// ### Simple batch of 2D arrows
31 /// ![image](https://static.rerun.io/arrow2d_simple/59f044ccc03f7bc66ee802288f75706618b29a6e/full.png)
32 ///
33 /// ```cpp
34 /// #include <rerun.hpp>
35 ///
36 /// int main(int argc, char* argv[]) {
37 /// const auto rec = rerun::RecordingStream("rerun_example_arrow2d");
38 /// rec.spawn().exit_on_failure();
39 ///
40 /// rec.log(
41 /// "arrows",
42 /// rerun::Arrows2D::from_vectors(
43 /// {{1.0f, 0.0f}, {0.0f, -1.0f}, {-0.7f, 0.7f}}
44 /// )
45 /// .with_radii(0.025f)
46 /// .with_origins({{0.25f, 0.0f}, {0.25f, 0.0f}, {-0.1f, -0.1f}})
47 /// .with_colors({{255, 0, 0}, {0, 255, 0}, {127, 0, 255}})
48 /// .with_labels({"right", "up", "left-down"})
49 /// );
50 /// }
51 /// ```
52 struct Arrows2D {
53 /// All the vectors for each arrow in the batch.
54 std::optional<ComponentBatch> vectors;
55
56 /// All the origin (base) positions for each arrow in the batch.
57 ///
58 /// If no origins are set, (0, 0) is used as the origin for each arrow.
59 std::optional<ComponentBatch> origins;
60
61 /// Optional radii for the arrows.
62 ///
63 /// The shaft is rendered as a line with `radius = 0.5 * radius`.
64 /// The tip is rendered with `height = 2.0 * radius` and `radius = 1.0 * radius`.
65 std::optional<ComponentBatch> radii;
66
67 /// Optional colors for the points.
68 std::optional<ComponentBatch> colors;
69
70 /// Optional text labels for the arrows.
71 ///
72 /// If there's a single label present, it will be placed at the center of the entity.
73 /// Otherwise, each instance will have its own label.
74 std::optional<ComponentBatch> labels;
75
76 /// Whether the text labels should be shown.
77 ///
78 /// If not set, labels will automatically appear when there is exactly one label for this entity
79 /// or the number of instances on this entity is under a certain threshold.
80 std::optional<ComponentBatch> show_labels;
81
82 /// An optional floating point value that specifies the 2D drawing order.
83 ///
84 /// Objects with higher values are drawn on top of those with lower values.
85 std::optional<ComponentBatch> draw_order;
86
87 /// Optional class Ids for the points.
88 ///
89 /// The `components::ClassId` provides colors and labels if not specified explicitly.
90 std::optional<ComponentBatch> class_ids;
91
92 public:
93 /// The name of the archetype as used in `ComponentDescriptor`s.
94 static constexpr const char ArchetypeName[] = "rerun.archetypes.Arrows2D";
95
96 /// `ComponentDescriptor` for the `vectors` field.
97 static constexpr auto Descriptor_vectors = ComponentDescriptor(
99 );
100 /// `ComponentDescriptor` for the `origins` field.
102 ArchetypeName, "Arrows2D:origins",
104 );
105 /// `ComponentDescriptor` for the `radii` field.
106 static constexpr auto Descriptor_radii = ComponentDescriptor(
108 );
109 /// `ComponentDescriptor` for the `colors` field.
110 static constexpr auto Descriptor_colors = ComponentDescriptor(
112 );
113 /// `ComponentDescriptor` for the `labels` field.
114 static constexpr auto Descriptor_labels = ComponentDescriptor(
116 );
117 /// `ComponentDescriptor` for the `show_labels` field.
119 ArchetypeName, "Arrows2D:show_labels",
121 );
122 /// `ComponentDescriptor` for the `draw_order` field.
124 ArchetypeName, "Arrows2D:draw_order",
126 );
127 /// `ComponentDescriptor` for the `class_ids` field.
130 );
131
132 public: // START of extensions from arrows2d_ext.cpp:
133 /// Creates new 2D arrows pointing in the given directions, with a base at the origin (0, 0).
135 return Arrows2D().with_vectors(vectors_);
136 }
137
138 // END of extensions from arrows2d_ext.cpp, start of generated code:
139
140 public:
141 Arrows2D() = default;
142 Arrows2D(Arrows2D&& other) = default;
143 Arrows2D(const Arrows2D& other) = default;
144 Arrows2D& operator=(const Arrows2D& other) = default;
145 Arrows2D& operator=(Arrows2D&& other) = default;
146
147 /// Update only some specific fields of a `Arrows2D`.
149 return Arrows2D();
150 }
151
152 /// Clear all the fields of a `Arrows2D`.
154
155 /// All the vectors for each arrow in the batch.
157 vectors = ComponentBatch::from_loggable(_vectors, Descriptor_vectors).value_or_throw();
158 return std::move(*this);
159 }
160
161 /// All the origin (base) positions for each arrow in the batch.
162 ///
163 /// If no origins are set, (0, 0) is used as the origin for each arrow.
165 origins = ComponentBatch::from_loggable(_origins, Descriptor_origins).value_or_throw();
166 return std::move(*this);
167 }
168
169 /// Optional radii for the arrows.
170 ///
171 /// The shaft is rendered as a line with `radius = 0.5 * radius`.
172 /// The tip is rendered with `height = 2.0 * radius` and `radius = 1.0 * radius`.
174 radii = ComponentBatch::from_loggable(_radii, Descriptor_radii).value_or_throw();
175 return std::move(*this);
176 }
177
178 /// Optional colors for the points.
180 colors = ComponentBatch::from_loggable(_colors, Descriptor_colors).value_or_throw();
181 return std::move(*this);
182 }
183
184 /// Optional text labels for the arrows.
185 ///
186 /// If there's a single label present, it will be placed at the center of the entity.
187 /// Otherwise, each instance will have its own label.
189 labels = ComponentBatch::from_loggable(_labels, Descriptor_labels).value_or_throw();
190 return std::move(*this);
191 }
192
193 /// Whether the text labels should be shown.
194 ///
195 /// If not set, labels will automatically appear when there is exactly one label for this entity
196 /// or the number of instances on this entity is under a certain threshold.
199 .value_or_throw();
200 return std::move(*this);
201 }
202
203 /// This method makes it possible to pack multiple `show_labels` in a single component batch.
204 ///
205 /// This only makes sense when used in conjunction with `columns`. `with_show_labels` should
206 /// be used when logging a single row's worth of data.
208 ) && {
210 .value_or_throw();
211 return std::move(*this);
212 }
213
214 /// An optional floating point value that specifies the 2D drawing order.
215 ///
216 /// Objects with higher values are drawn on top of those with lower values.
218 draw_order =
219 ComponentBatch::from_loggable(_draw_order, Descriptor_draw_order).value_or_throw();
220 return std::move(*this);
221 }
222
223 /// This method makes it possible to pack multiple `draw_order` in a single component batch.
224 ///
225 /// This only makes sense when used in conjunction with `columns`. `with_draw_order` should
226 /// be used when logging a single row's worth of data.
228 ) && {
229 draw_order =
230 ComponentBatch::from_loggable(_draw_order, Descriptor_draw_order).value_or_throw();
231 return std::move(*this);
232 }
233
234 /// Optional class Ids for the points.
235 ///
236 /// The `components::ClassId` provides colors and labels if not specified explicitly.
238 class_ids =
239 ComponentBatch::from_loggable(_class_ids, Descriptor_class_ids).value_or_throw();
240 return std::move(*this);
241 }
242
243 /// Partitions the component data into multiple sub-batches.
244 ///
245 /// Specifically, this transforms the existing `ComponentBatch` data into `ComponentColumn`s
246 /// instead, via `ComponentBatch::partitioned`.
247 ///
248 /// This makes it possible to use `RecordingStream::send_columns` to send columnar data directly into Rerun.
249 ///
250 /// The specified `lengths` must sum to the total length of the component batch.
252 return detail::partition_batches(
253 {&vectors,
254 &origins,
255 &radii,
256 &colors,
257 &labels,
259 &draw_order,
260 &class_ids},
261 lengths_
262 )
263 .value_or_throw();
264 }
265
266 /// Partitions the component data into unit-length sub-batches.
267 ///
268 /// This is semantically similar to calling `columns` with `std::vector<uint32_t>(n, 1)`,
269 /// where `n` is automatically guessed.
271 return detail::partition_batches_of_unit_length({&vectors,
272 &origins,
273 &radii,
274 &colors,
275 &labels,
277 &draw_order,
278 &class_ids})
279 .value_or_throw();
280 }
281 };
282
283} // namespace rerun::archetypes
284
285namespace rerun {
286 /// \private
287 template <typename T>
288 struct AsComponents;
289
290 /// \private
291 template <>
292 struct AsComponents<archetypes::Arrows2D> {
293 /// Serialize all set component batches.
294 static Result<Collection<ComponentBatch>> as_batches(const archetypes::Arrows2D& archetype
295 ) {
296 return detail::collect_batches(
297 {&archetype.vectors,
298 &archetype.origins,
299 &archetype.radii,
300 &archetype.colors,
301 &archetype.labels,
302 &archetype.show_labels,
303 &archetype.draw_order,
304 &archetype.class_ids}
305 );
306 }
307 };
308} // namespace rerun
Generic collection of elements that are roughly contiguous in memory.
Definition collection.hpp:49
All built-in archetypes. See Types in the Rerun manual.
Definition rerun.hpp:90
All Rerun C++ types and functions are in the rerun namespace or one of its nested namespaces.
Definition rerun.hpp:26
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 arrows with optional colors, radii, labels, etc.
Definition arrows2d.hpp:52
Arrows2D with_colors(const Collection< rerun::components::Color > &_colors) &&
Optional colors for the points.
Definition arrows2d.hpp:179
static Arrows2D clear_fields()
Clear all the fields of a Arrows2D.
Arrows2D with_draw_order(const rerun::components::DrawOrder &_draw_order) &&
An optional floating point value that specifies the 2D drawing order.
Definition arrows2d.hpp:217
static constexpr auto Descriptor_radii
ComponentDescriptor for the radii field.
Definition arrows2d.hpp:106
static constexpr const char ArchetypeName[]
The name of the archetype as used in ComponentDescriptors.
Definition arrows2d.hpp:94
static constexpr auto Descriptor_vectors
ComponentDescriptor for the vectors field.
Definition arrows2d.hpp:97
std::optional< ComponentBatch > labels
Optional text labels for the arrows.
Definition arrows2d.hpp:74
static constexpr auto Descriptor_show_labels
ComponentDescriptor for the show_labels field.
Definition arrows2d.hpp:118
static Arrows2D from_vectors(Collection< components::Vector2D > vectors_)
Creates new 2D arrows pointing in the given directions, with a base at the origin (0,...
Definition arrows2d.hpp:134
Arrows2D with_show_labels(const rerun::components::ShowLabels &_show_labels) &&
Whether the text labels should be shown.
Definition arrows2d.hpp:197
Arrows2D with_vectors(const Collection< rerun::components::Vector2D > &_vectors) &&
All the vectors for each arrow in the batch.
Definition arrows2d.hpp:156
Collection< ComponentColumn > columns(const Collection< uint32_t > &lengths_)
Partitions the component data into multiple sub-batches.
Definition arrows2d.hpp:251
static constexpr auto Descriptor_labels
ComponentDescriptor for the labels field.
Definition arrows2d.hpp:114
static constexpr auto Descriptor_origins
ComponentDescriptor for the origins field.
Definition arrows2d.hpp:101
std::optional< ComponentBatch > radii
Optional radii for the arrows.
Definition arrows2d.hpp:65
static Arrows2D update_fields()
Update only some specific fields of a Arrows2D.
Definition arrows2d.hpp:148
std::optional< ComponentBatch > class_ids
Optional class Ids for the points.
Definition arrows2d.hpp:90
static constexpr auto Descriptor_colors
ComponentDescriptor for the colors field.
Definition arrows2d.hpp:110
std::optional< ComponentBatch > origins
All the origin (base) positions for each arrow in the batch.
Definition arrows2d.hpp:59
Arrows2D with_class_ids(const Collection< rerun::components::ClassId > &_class_ids) &&
Optional class Ids for the points.
Definition arrows2d.hpp:237
Arrows2D 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 arrows2d.hpp:207
std::optional< ComponentBatch > colors
Optional colors for the points.
Definition arrows2d.hpp:68
std::optional< ComponentBatch > draw_order
An optional floating point value that specifies the 2D drawing order.
Definition arrows2d.hpp:85
Arrows2D 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 arrows2d.hpp:227
Collection< ComponentColumn > columns()
Partitions the component data into unit-length sub-batches.
Definition arrows2d.hpp:270
Arrows2D with_labels(const Collection< rerun::components::Text > &_labels) &&
Optional text labels for the arrows.
Definition arrows2d.hpp:188
std::optional< ComponentBatch > vectors
All the vectors for each arrow in the batch.
Definition arrows2d.hpp:54
static constexpr auto Descriptor_draw_order
ComponentDescriptor for the draw_order field.
Definition arrows2d.hpp:123
static constexpr auto Descriptor_class_ids
ComponentDescriptor for the class_ids field.
Definition arrows2d.hpp:128
std::optional< ComponentBatch > show_labels
Whether the text labels should be shown.
Definition arrows2d.hpp:80
Arrows2D with_radii(const Collection< rerun::components::Radius > &_radii) &&
Optional radii for the arrows.
Definition arrows2d.hpp:173
Arrows2D with_origins(const Collection< rerun::components::Position2D > &_origins) &&
All the origin (base) positions for each arrow in the batch.
Definition arrows2d.hpp:164
Component: Draw order of 2D elements.
Definition draw_order.hpp:30
Component: Whether the entity's components::Text label is shown.
Definition show_labels.hpp:18