Rerun C++ SDK
Loading...
Searching...
No Matches
transform3d.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/transform3d.fbs".
3
4#pragma once
5
6#include "../collection.hpp"
7#include "../compiler_utils.hpp"
8#include "../component_batch.hpp"
9#include "../component_column.hpp"
10#include "../components/axis_length.hpp"
11#include "../components/rotation_axis_angle.hpp"
12#include "../components/rotation_quat.hpp"
13#include "../components/scale3d.hpp"
14#include "../components/transform_mat3x3.hpp"
15#include "../components/transform_relation.hpp"
16#include "../components/translation3d.hpp"
17#include "../indicator_component.hpp"
18#include "../rerun_sdk_export.hpp"
19#include "../result.hpp"
20#include "../rotation3d.hpp"
21
22#include <cstdint>
23#include <optional>
24#include <utility>
25#include <vector>
26
27namespace rerun::archetypes {
28 /// **Archetype**: A transform between two 3D spaces, i.e. a pose.
29 ///
30 /// From the point of view of the entity's coordinate system,
31 /// all components are applied in the inverse order they are listed here.
32 /// E.g. if both a translation and a max3x3 transform are present,
33 /// the 3x3 matrix is applied first, followed by the translation.
34 ///
35 /// Whenever you log this archetype, it will write all components, even if you do not explicitly set them.
36 /// This means that if you first log a transform with only a translation, and then log one with only a rotation,
37 /// it will be resolved to a transform with only a rotation.
38 ///
39 /// For transforms that affect only a single entity and do not propagate along the entity tree refer to `archetypes::InstancePoses3D`.
40 ///
41 /// ## Examples
42 ///
43 /// ### Variety of 3D transforms
44 /// ![image](https://static.rerun.io/transform3d_simple/141368b07360ce3fcb1553079258ae3f42bdb9ac/full.png)
45 ///
46 /// ```cpp
47 /// #include <rerun.hpp>
48 ///
49 /// constexpr float TAU = 6.28318530717958647692528676655900577f;
50 ///
51 /// int main() {
52 /// const auto rec = rerun::RecordingStream("rerun_example_transform3d");
53 /// rec.spawn().exit_on_failure();
54 ///
55 /// auto arrow =
56 /// rerun::Arrows3D::from_vectors({{0.0f, 1.0f, 0.0f}}).with_origins({{0.0f, 0.0f, 0.0f}});
57 ///
58 /// rec.log("base", arrow);
59 ///
60 /// rec.log("base/translated", rerun::Transform3D::from_translation({1.0f, 0.0f, 0.0f}));
61 /// rec.log("base/translated", arrow);
62 ///
63 /// rec.log(
64 /// "base/rotated_scaled",
65 /// rerun::Transform3D::from_rotation_scale(
66 /// rerun::RotationAxisAngle({0.0f, 0.0f, 1.0f}, rerun::Angle::radians(TAU / 8.0f)),
67 /// 2.0f
68 /// )
69 /// );
70 /// rec.log("base/rotated_scaled", arrow);
71 /// }
72 /// ```
73 ///
74 /// ### Transform hierarchy
75 /// ![image](https://static.rerun.io/transform_hierarchy/cb7be7a5a31fcb2efc02ba38e434849248f87554/full.png)
76 ///
77 /// ```cpp
78 /// #include <rerun.hpp>
79 ///
80 /// constexpr float TAU = 6.28318530717958647692528676655900577f;
81 ///
82 /// int main() {
83 /// const auto rec = rerun::RecordingStream("rerun_example_transform3d_hierarchy");
84 /// rec.spawn().exit_on_failure();
85 ///
86 /// // TODO(#5521): log two views as in the python example
87 ///
88 /// rec.set_time_seconds("sim_time", 0.0);
89 ///
90 /// // Planetary motion is typically in the XY plane.
91 /// rec.log_static("/", rerun::ViewCoordinates::RIGHT_HAND_Z_UP);
92 ///
93 /// // Setup points, all are in the center of their own space:
94 /// rec.log(
95 /// "sun",
96 /// rerun::Points3D({{0.0f, 0.0f, 0.0f}})
97 /// .with_radii({1.0f})
98 /// .with_colors({rerun::Color(255, 200, 10)})
99 /// );
100 /// rec.log(
101 /// "sun/planet",
102 /// rerun::Points3D({{0.0f, 0.0f, 0.0f}})
103 /// .with_radii({0.4f})
104 /// .with_colors({rerun::Color(40, 80, 200)})
105 /// );
106 /// rec.log(
107 /// "sun/planet/moon",
108 /// rerun::Points3D({{0.0f, 0.0f, 0.0f}})
109 /// .with_radii({0.15f})
110 /// .with_colors({rerun::Color(180, 180, 180)})
111 /// );
112 ///
113 /// // Draw fixed paths where the planet & moon move.
114 /// float d_planet = 6.0f;
115 /// float d_moon = 3.0f;
116 /// std::vector<std::array<float, 3>> planet_path, moon_path;
117 /// for (int i = 0; i <= 100; i++) {
118 /// float angle = static_cast<float>(i) * 0.01f * TAU;
119 /// float circle_x = std::sin(angle);
120 /// float circle_y = std::cos(angle);
121 /// planet_path.push_back({circle_x * d_planet, circle_y * d_planet, 0.0f});
122 /// moon_path.push_back({circle_x * d_moon, circle_y * d_moon, 0.0f});
123 /// }
124 /// rec.log("sun/planet_path", rerun::LineStrips3D(rerun::LineStrip3D(planet_path)));
125 /// rec.log("sun/planet/moon_path", rerun::LineStrips3D(rerun::LineStrip3D(moon_path)));
126 ///
127 /// // Movement via transforms.
128 /// for (int i = 0; i <6 * 120; i++) {
129 /// float time = static_cast<float>(i) / 120.0f;
130 /// rec.set_time_seconds("sim_time", time);
131 /// float r_moon = time * 5.0f;
132 /// float r_planet = time * 2.0f;
133 ///
134 /// rec.log(
135 /// "sun/planet",
136 /// rerun::Transform3D::from_translation_rotation(
137 /// {std::sin(r_planet) * d_planet, std::cos(r_planet) * d_planet, 0.0f},
138 /// rerun::RotationAxisAngle{
139 /// {1.0, 0.0f, 0.0f},
140 /// rerun::Angle::degrees(20.0f),
141 /// }
142 /// )
143 /// );
144 /// rec.log(
145 /// "sun/planet/moon",
146 /// rerun::Transform3D::from_translation(
147 /// {std::cos(r_moon) * d_moon, std::sin(r_moon) * d_moon, 0.0f}
148 /// )
149 /// .with_relation(rerun::components::TransformRelation::ChildFromParent)
150 /// );
151 /// }
152 /// }
153 /// ```
154 ///
155 /// ### Update a transform over time
156 /// ![image](https://static.rerun.io/transform3d_column_updates/80634e1c7c7a505387e975f25ea8b6bc1d4eb9db/full.png)
157 ///
158 /// ```cpp
159 /// #include <rerun.hpp>
160 ///
161 /// float truncated_radians(int deg) {
162 /// auto degf = static_cast<float>(deg);
163 /// const auto pi = 3.14159265358979323846f;
164 /// return static_cast<float>(static_cast<int>(degf * pi / 180.0f * 1000.0f)) / 1000.0f;
165 /// }
166 ///
167 /// int main() {
168 /// const auto rec = rerun::RecordingStream("rerun_example_transform3d_row_updates");
169 /// rec.spawn().exit_on_failure();
170 ///
171 /// rec.set_time_sequence("tick", 0);
172 /// rec.log(
173 /// "box",
174 /// rerun::Boxes3D::from_half_sizes({{4.f, 2.f, 1.0f}}).with_fill_mode(rerun::FillMode::Solid),
175 /// rerun::Transform3D().with_axis_length(10.0)
176 /// );
177 ///
178 /// for (int t = 0; t <100; t++) {
179 /// rec.set_time_sequence("tick", t + 1);
180 /// rec.log(
181 /// "box",
182 /// rerun::Transform3D()
183 /// .with_translation({0.0f, 0.0f, static_cast<float>(t) / 10.0f})
184 /// .with_rotation_axis_angle(rerun::RotationAxisAngle(
185 /// {0.0f, 1.0f, 0.0f},
186 /// rerun::Angle::radians(truncated_radians(t * 4))
187 /// ))
188 /// );
189 /// }
190 /// }
191 /// ```
192 ///
193 /// ### Update a transform over time, in a single operation
194 /// ![image](https://static.rerun.io/transform3d_column_updates/80634e1c7c7a505387e975f25ea8b6bc1d4eb9db/full.png)
195 ///
196 /// ```cpp
197 /// #include <cmath>
198 /// #include <numeric>
199 /// #include <vector>
200 ///
201 /// #include <rerun.hpp>
202 ///
203 /// float truncated_radians(int deg) {
204 /// auto degf = static_cast<float>(deg);
205 /// const auto pi = 3.14159265358979323846f;
206 /// return static_cast<float>(static_cast<int>(degf * pi / 180.0f * 1000.0f)) / 1000.0f;
207 /// }
208 ///
209 /// int main() {
210 /// const auto rec = rerun::RecordingStream("rerun_example_transform3d_column_updates");
211 /// rec.spawn().exit_on_failure();
212 ///
213 /// rec.set_time_sequence("tick", 0);
214 /// rec.log(
215 /// "box",
216 /// rerun::Boxes3D::from_half_sizes({{4.f, 2.f, 1.0f}}).with_fill_mode(rerun::FillMode::Solid),
217 /// rerun::Transform3D().with_axis_length(10.0)
218 /// );
219 ///
220 /// std::vector<std::array<float, 3>> translations;
221 /// std::vector<rerun::RotationAxisAngle> rotations;
222 /// for (int t = 0; t <100; t++) {
223 /// translations.push_back({0.0f, 0.0f, static_cast<float>(t) / 10.0f});
224 /// rotations.push_back(rerun::RotationAxisAngle(
225 /// {0.0f, 1.0f, 0.0f},
226 /// rerun::Angle::radians(truncated_radians(t * 4))
227 /// ));
228 /// }
229 ///
230 /// std::vector<int64_t> ticks(100);
231 /// std::iota(ticks.begin(), ticks.end(), 1);
232 ///
233 /// rec.send_columns(
234 /// "box",
235 /// rerun::TimeColumn::from_sequence("tick", ticks),
236 /// rerun::Transform3D()
237 /// .with_many_translation(translations)
238 /// .with_many_rotation_axis_angle(rotations)
239 /// .columns()
240 /// );
241 /// }
242 /// ```
243 ///
244 /// ### Update specific properties of a transform over time
245 /// ![image](https://static.rerun.io/transform3d_partial_updates/11815bebc69ae400847896372b496cdd3e9b19fb/full.png)
246 ///
247 /// ```cpp
248 /// #include <rerun.hpp>
249 ///
250 /// float truncated_radians(int deg) {
251 /// auto degf = static_cast<float>(deg);
252 /// const auto pi = 3.14159265358979323846f;
253 /// return static_cast<float>(static_cast<int>(degf * pi / 180.0f * 1000.0f)) / 1000.0f;
254 /// }
255 ///
256 /// int main() {
257 /// const auto rec = rerun::RecordingStream("rerun_example_transform3d_partial_updates");
258 /// rec.spawn().exit_on_failure();
259 ///
260 /// // Set up a 3D box.
261 /// rec.log(
262 /// "box",
263 /// rerun::Boxes3D::from_half_sizes({{4.f, 2.f, 1.0f}}).with_fill_mode(rerun::FillMode::Solid),
264 /// rerun::Transform3D().with_axis_length(10.0)
265 /// );
266 ///
267 /// // Update only the rotation of the box.
268 /// for (int deg = 0; deg <= 45; deg++) {
269 /// auto rad = truncated_radians(deg * 4);
270 /// rec.log(
271 /// "box",
272 /// rerun::Transform3D::update_fields().with_rotation_axis_angle(
273 /// rerun::RotationAxisAngle({0.0f, 1.0f, 0.0f}, rerun::Angle::radians(rad))
274 /// )
275 /// );
276 /// }
277 ///
278 /// // Update only the position of the box.
279 /// for (int t = 0; t <= 50; t++) {
280 /// rec.log(
281 /// "box",
282 /// rerun::Transform3D::update_fields().with_translation(
283 /// {0.0f, 0.0f, static_cast<float>(t) / 10.0f}
284 /// )
285 /// );
286 /// }
287 ///
288 /// // Update only the rotation of the box.
289 /// for (int deg = 0; deg <= 45; deg++) {
290 /// auto rad = truncated_radians((deg + 45) * 4);
291 /// rec.log(
292 /// "box",
293 /// rerun::Transform3D::update_fields().with_rotation_axis_angle(
294 /// rerun::RotationAxisAngle({0.0f, 1.0f, 0.0f}, rerun::Angle::radians(rad))
295 /// )
296 /// );
297 /// }
298 ///
299 /// // Clear all of the box's attributes, and reset its axis length.
300 /// rec.log("box", rerun::Transform3D::clear_fields().with_axis_length(15.0));
301 /// }
302 /// ```
303 struct Transform3D {
304 /// Translation vector.
305 std::optional<ComponentBatch> translation;
306
307 /// Rotation via axis + angle.
308 std::optional<ComponentBatch> rotation_axis_angle;
309
310 /// Rotation via quaternion.
311 std::optional<ComponentBatch> quaternion;
312
313 /// Scaling factor.
314 std::optional<ComponentBatch> scale;
315
316 /// 3x3 transformation matrix.
317 std::optional<ComponentBatch> mat3x3;
318
319 /// Specifies the relation this transform establishes between this entity and its parent.
320 std::optional<ComponentBatch> relation;
321
322 /// Visual length of the 3 axes.
323 ///
324 /// The length is interpreted in the local coordinate system of the transform.
325 /// If the transform is scaled, the axes will be scaled accordingly.
326 std::optional<ComponentBatch> axis_length;
327
328 public:
329 static constexpr const char IndicatorComponentName[] =
330 "rerun.components.Transform3DIndicator";
331
332 /// Indicator component, used to identify the archetype when converting to a list of components.
334 /// The name of the archetype as used in `ComponentDescriptor`s.
335 static constexpr const char ArchetypeName[] = "rerun.archetypes.Transform3D";
336
337 /// `ComponentDescriptor` for the `translation` field.
339 ArchetypeName, "translation",
341 );
342 /// `ComponentDescriptor` for the `rotation_axis_angle` field.
344 ArchetypeName, "rotation_axis_angle",
346 );
347 /// `ComponentDescriptor` for the `quaternion` field.
349 ArchetypeName, "quaternion",
351 );
352 /// `ComponentDescriptor` for the `scale` field.
353 static constexpr auto Descriptor_scale = ComponentDescriptor(
355 );
356 /// `ComponentDescriptor` for the `mat3x3` field.
357 static constexpr auto Descriptor_mat3x3 = ComponentDescriptor(
358 ArchetypeName, "mat3x3",
360 );
361 /// `ComponentDescriptor` for the `relation` field.
363 ArchetypeName, "relation",
365 );
366 /// `ComponentDescriptor` for the `axis_length` field.
368 ArchetypeName, "axis_length",
370 );
371
372 public: // START of extensions from transform3d_ext.cpp:
373 /// Identity transformation.
374 ///
375 /// Applying this transform does not alter an entity's transformation.
376 RERUN_SDK_EXPORT static const Transform3D IDENTITY;
377
378 /// Invalid transformation.
379 ///
380 /// Applying this transform will cause this entity and the entire subtree not to be visualized.
381 RERUN_SDK_EXPORT static const Transform3D INVALID;
382
383 /// Creates a new 3D transform from translation and matrix provided as 3 columns.
384 /// Clears out all other components like `Transform3D::clear_fields`.
385 ///
386 /// \param translation_ \çopydoc Transform3D::translation
387 /// \param columns Column vectors of 3x3 matrix.
388 /// \param from_parent If true, the transform relation to `TransformRelation::ChildFromParent`.
389 ///
390 /// _Implementation note:_ This overload is necessary, otherwise the array may be
391 /// interpreted as bool and call the wrong overload.
393 const components::Translation3D& translation_, const datatypes::Vec3D (&columns)[3],
394 bool from_parent = false
395 )
396 : Transform3D(translation_, components::TransformMat3x3(columns), from_parent) {}
397
398 /// Creates a new 3D transform from translation/matrix.
399 /// Clears out all other components like `Transform3D::clear_fields`.
400 ///
401 /// \param translation_ \çopydoc Transform3D::translation
402 /// \param mat3x3_ \copydoc Transform3D::mat3x3
403 /// \param from_parent If true, the transform relation to `TransformRelation::ChildFromParent`.
405 const components::Translation3D& translation_,
406 const components::TransformMat3x3& mat3x3_, bool from_parent = false
407 ) {
408 *this = Transform3D::clear_fields().with_translation(translation_).with_mat3x3(mat3x3_);
409 if (from_parent) {
410 *this =
412 }
413 }
414
415 /// From a translation applied after a 3x3 matrix.
416 /// Clears out all other components like `Transform3D::clear_fields`.
417 ///
418 /// \param translation \çopydoc Transform3D::translation
419 /// \param mat3x3 \copydoc Transform3D::mat3x3
422 ) {
423 return Transform3D(translation, mat3x3, false);
424 }
425
426 /// From a translation applied after a 3x3 matrix provided as 3 columns.
427 /// Clears out all other components like `Transform3D::clear_fields`.
428 ///
429 /// \param translation \çopydoc Transform3D::translation
430 /// \param columns Column vectors of 3x3 matrix.
433 ) {
437 );
438 }
439
440 /// From translation only.
441 /// Clears out all other components like `Transform3D::clear_fields`.
442 ///
443 /// \param translation_ \çopydoc Transform3D::translation
444 /// \param from_parent If true, the transform relation to `TransformRelation::ChildFromParent`.
445 Transform3D(const components::Translation3D& translation_, bool from_parent = false) {
446 *this = Transform3D::clear_fields().with_translation(translation_);
447 if (from_parent) {
448 *this =
450 }
451 }
452
453 /// From a translation.
454 /// Clears out all other components like `Transform3D::clear_fields`.
455 ///
456 /// \param translation \çopydoc Transform3D::translation
458 return Transform3D(translation, false);
459 }
460
461 /// From 3x3 matrix only.
462 /// Clears out all other components like `Transform3D::clear_fields`.
463 ///
464 /// \param mat3x3_ \copydoc Transform3D::mat3x3
465 /// \param from_parent If true, the transform relation to `TransformRelation::ChildFromParent`.
466 Transform3D(const components::TransformMat3x3& mat3x3_, bool from_parent = false) {
467 *this = Transform3D::clear_fields().with_mat3x3(mat3x3_);
468 if (from_parent) {
469 *this =
471 }
472 }
473
474 /// From 3x3 matrix only.
475 /// Clears out all other components like `Transform3D::clear_fields`.
476 ///
477 /// \param mat3x3 \copydoc Transform3D::mat3x3
479 return Transform3D(mat3x3, false);
480 }
481
482 /// From 3x3 matrix provided as 3 columns only.
483 /// Clears out all other components like `Transform3D::clear_fields`.
484 ///
485 /// \param columns Column vectors of 3x3 matrix.
486 /// \param from_parent If true, the transform relation to `TransformRelation::ChildFromParent`.
487 Transform3D(const datatypes::Vec3D (&columns)[3], bool from_parent = false)
488 : Transform3D(components::TransformMat3x3(columns), from_parent) {}
489
490 /// From 3x3 matrix provided as 3 columns only.
491 /// Clears out all other components like `Transform3D::clear_fields`.
492 ///
493 /// \param columns Column vectors of 3x3 matrix.
496 }
497
498 /// Creates a new 3D transform from translation/rotation/scale.
499 /// Clears out all other components like `Transform3D::clear_fields`.
500 ///
501 /// \param translation_ \copydoc Transform3D::translation
502 /// \param rotation Rotation represented either as a quaternion or axis + angle rotation.
503 /// \param scale_ \copydoc Transform3D::scale
504 /// \param from_parent If true, the transform relation to `TransformRelation::ChildFromParent`.
506 const components::Translation3D& translation_, const Rotation3D& rotation,
507 const components::Scale3D& scale_, bool from_parent = false
508 ) {
510 .with_translation(translation_)
511 .with_scale(scale_)
512 .with_rotation(rotation);
513 if (from_parent) {
514 *this =
516 }
517 }
518
519 /// Creates a new 3D transform from translation/rotation/uniform-scale.
520 /// Clears out all other components like `Transform3D::clear_fields`.
521 ///
522 /// \param translation_ \copydoc Transform3D::translation
523 /// \param rotation Rotation represented either as a quaternion or axis + angle rotation.
524 /// \param uniform_scale Uniform scale factor that is applied to all axis equally.
525 /// \param from_parent If true, the transform relation to `TransformRelation::ChildFromParent`.
526 ///
527 /// _Implementation note:_ This explicit overload prevents interpretation of the float as
528 /// bool, leading to a call to the wrong overload.
530 const components::Translation3D& translation_, const Rotation3D& rotation,
531 float uniform_scale, bool from_parent = false
532 )
533 : Transform3D(translation_, rotation, components::Scale3D(uniform_scale), from_parent) {
534 }
535
536 /// From a translation, applied after a rotation & scale, known as an affine transformation.
537 /// Clears out all other components like `Transform3D::clear_fields`.
538 ///
539 /// \param translation \copydoc Transform3D::translation
540 /// \param rotation Rotation represented either as a quaternion or axis + angle rotation.
541 /// \param scale \copydoc Transform3D::scale
543 const components::Translation3D& translation, const Rotation3D& rotation,
545 ) {
546 return Transform3D(translation, rotation, scale, false);
547 }
548
549 /// From a translation, applied after a rotation & scale, known as an affine transformation.
550 /// Clears out all other components like `Transform3D::clear_fields`.
551 ///
552 /// \param translation \copydoc Transform3D::translation
553 /// \param rotation Rotation represented either as a quaternion or axis + angle rotation.
554 /// \param uniform_scale Uniform scale factor that is applied to all axis equally.
556 const components::Translation3D& translation, const Rotation3D& rotation,
557 float uniform_scale
558 ) {
559 return Transform3D(translation, rotation, components::Scale3D(uniform_scale), false);
560 }
561
562 /// Creates a new rigid transform (translation & rotation only).
563 /// Clears out all other components like `Transform3D::clear_fields`.
564 ///
565 /// \param translation_ \copydoc Transform3D::translation
566 /// \param rotation Rotation represented either as a quaternion or axis + angle rotation.
567 /// \param from_parent If true, the transform relation to `TransformRelation::ChildFromParent`.
569 const components::Translation3D& translation_, const Rotation3D& rotation,
570 bool from_parent = false
571 ) {
572 *this =
574 if (from_parent) {
575 *this =
577 }
578 }
579
580 /// From a rotation & scale.
581 /// Clears out all other components like `Transform3D::clear_fields`.
582 ///
583 /// \param translation \copydoc Transform3D::translation
584 /// \param rotation Rotation represented either as a quaternion or axis + angle rotation.
586 const components::Translation3D& translation, const Rotation3D& rotation
587 ) {
588 return Transform3D(translation, rotation, false);
589 }
590
591 /// From translation & scale only.
592 /// Clears out all other components like `Transform3D::clear_fields`.
593 ///
594 /// \param translation_ \copydoc Transform3D::translation
595 /// \param scale_ Transform3D::scale
596 /// \param from_parent If true, the transform relation to `TransformRelation::ChildFromParent`.
598 const components::Translation3D& translation_, const components::Scale3D& scale_,
599 bool from_parent = false
600 ) {
601 *this = Transform3D::clear_fields().with_translation(translation_).with_scale(scale_);
602 if (from_parent) {
603 *this =
605 }
606 }
607
608 /// From a translation applied after a scale.
609 /// Clears out all other components like `Transform3D::clear_fields`.
610 ///
611 /// \param translation \copydoc Transform3D::translation
612 /// \param scale Transform3D::scale
615 ) {
616 return Transform3D(translation, scale, false);
617 }
618
619 /// From translation & uniform scale only.
620 /// Clears out all other components like `Transform3D::clear_fields`.
621 ///
622 /// \param translation_ \copydoc Transform3D::translation
623 /// \param uniform_scale Uniform scale factor that is applied to all axis equally.
624 /// \param from_parent If true, the transform relation to `TransformRelation::ChildFromParent`.
625 ///
626 /// _Implementation note:_ This explicit overload prevents interpretation of the float as
627 /// bool, leading to a call to the wrong overload.
629 const components::Translation3D& translation_, float uniform_scale,
630 bool from_parent = false
631 )
632 : Transform3D(translation_, components::Scale3D(uniform_scale), from_parent) {}
633
634 /// From rotation & scale.
635 /// Clears out all other components like `Transform3D::clear_fields`.
636 ///
637 /// \param rotation Rotation represented either as a quaternion or axis + angle rotation.
638 /// \param scale_ Transform3D::scale
639 /// \param from_parent If true, the transform relation to `TransformRelation::ChildFromParent`.
641 const Rotation3D& rotation, const components::Scale3D& scale_, bool from_parent = false
642 ) {
643 *this = Transform3D::clear_fields().with_scale(scale_).with_rotation(rotation);
644 if (from_parent) {
645 *this =
647 }
648 }
649
650 /// From rotation & uniform scale.
651 /// Clears out all other components like `Transform3D::clear_fields`.
652 ///
653 /// \param rotation Rotation represented either as a quaternion or axis + angle rotation.
654 /// \param uniform_scale Uniform scale factor that is applied to all axis equally.
655 /// \param from_parent If true, the transform relation to `TransformRelation::ChildFromParent`.
656 ///
657 /// _Implementation note:_ This explicit overload prevents interpretation of the float as
658 /// bool, leading to a call to the wrong overload.
659 Transform3D(const Rotation3D& rotation, float uniform_scale, bool from_parent = false)
660 : Transform3D(rotation, components::Scale3D(uniform_scale), from_parent) {}
661
662 /// From a rotation & scale.
663 /// Clears out all other components like `Transform3D::clear_fields`.
664 ///
665 /// \param rotation Rotation represented either as a quaternion or axis + angle rotation.
666 /// \param scale Transform3D::scale
668 const Rotation3D& rotation, const components::Scale3D& scale
669 ) {
670 return Transform3D(rotation, scale, false);
671 }
672
673 /// From a rotation & uniform scale.
674 /// Clears out all other components like `Transform3D::clear_fields`.
675 ///
676 /// \param rotation Rotation represented either as a quaternion or axis + angle rotation.
677 /// \param uniform_scale Uniform scale factor that is applied to all axis equally.
678 static Transform3D from_rotation_scale(const Rotation3D& rotation, float uniform_scale) {
679 return Transform3D(rotation, components::Scale3D(uniform_scale), false);
680 }
681
682 /// From rotation only.
683 /// Clears out all other components like `Transform3D::clear_fields`.
684 ///
685 /// \param rotation Rotation represented either as a quaternion or axis + angle rotation.
686 /// \param from_parent If true, the transform relation to `TransformRelation::ChildFromParent`.
687 Transform3D(const Rotation3D& rotation, bool from_parent = false) {
688 *this = Transform3D::clear_fields().with_rotation(rotation);
689 if (from_parent) {
690 *this =
692 }
693 }
694
695 /// From rotation only.
696 /// Clears out all other components like `Transform3D::clear_fields`.
697 ///
698 /// \param rotation Rotation represented either as a quaternion or axis + angle rotation.
699 static Transform3D from_rotation(const Rotation3D& rotation) {
700 return Transform3D(rotation, false);
701 }
702
703 /// From scale only.
704 /// Clears out all other components like `Transform3D::clear_fields`.
705 ///
706 /// \param scale_ If true, the transform relation to `TransformRelation::ChildFromParent`.
707 /// \param from_parent \copydoc Transform3D::scale
708 Transform3D(const components::Scale3D& scale_, bool from_parent = false) {
709 *this = Transform3D::clear_fields().with_scale(scale_);
710 if (from_parent) {
711 *this =
713 }
714 }
715
716 /// From scale only.
717 /// Clears out all other components like `Transform3D::clear_fields`.
718 ///
719 /// \param scale Transform3D::scale
721 return Transform3D(scale, false);
722 }
723
724 /// From scale only.
725 /// Clears out all other components like `Transform3D::clear_fields`.
726 ///
727 /// \param uniform_scale Uniform scale factor that is applied to all axis equally.
728 static Transform3D from_scale(float uniform_scale) {
729 return Transform3D(components::Scale3D(uniform_scale), false);
730 }
731
732 /// Set the rotation component of the transform using the `rerun::Rotation3D` utility.
734 if (rotation.axis_angle.has_value()) {
735 *this = std::move(*this).with_rotation_axis_angle(rotation.axis_angle.value());
736 }
737 if (rotation.quaternion.has_value()) {
738 *this = std::move(*this).with_quaternion(rotation.quaternion.value());
739 }
740 return std::move(*this);
741 }
742
743 // END of extensions from transform3d_ext.cpp, start of generated code:
744
745 public:
746 Transform3D() = default;
747 Transform3D(Transform3D&& other) = default;
748 Transform3D(const Transform3D& other) = default;
749 Transform3D& operator=(const Transform3D& other) = default;
750 Transform3D& operator=(Transform3D&& other) = default;
751
752 /// Update only some specific fields of a `Transform3D`.
754 return Transform3D();
755 }
756
757 /// Clear all the fields of a `Transform3D`.
759
760 /// Translation vector.
763 .value_or_throw();
764 return std::move(*this);
765 }
766
767 /// This method makes it possible to pack multiple `translation` in a single component batch.
768 ///
769 /// This only makes sense when used in conjunction with `columns`. `with_translation` should
770 /// be used when logging a single row's worth of data.
773 ) && {
775 .value_or_throw();
776 return std::move(*this);
777 }
778
779 /// Rotation via axis + angle.
781 const rerun::components::RotationAxisAngle& _rotation_axis_angle
782 ) && {
785 .value_or_throw();
786 return std::move(*this);
787 }
788
789 /// This method makes it possible to pack multiple `rotation_axis_angle` in a single component batch.
790 ///
791 /// This only makes sense when used in conjunction with `columns`. `with_rotation_axis_angle` should
792 /// be used when logging a single row's worth of data.
794 const Collection<rerun::components::RotationAxisAngle>& _rotation_axis_angle
795 ) && {
798 .value_or_throw();
799 return std::move(*this);
800 }
801
802 /// Rotation via quaternion.
804 quaternion =
805 ComponentBatch::from_loggable(_quaternion, Descriptor_quaternion).value_or_throw();
806 return std::move(*this);
807 }
808
809 /// This method makes it possible to pack multiple `quaternion` in a single component batch.
810 ///
811 /// This only makes sense when used in conjunction with `columns`. `with_quaternion` should
812 /// be used when logging a single row's worth of data.
815 ) && {
816 quaternion =
817 ComponentBatch::from_loggable(_quaternion, Descriptor_quaternion).value_or_throw();
818 return std::move(*this);
819 }
820
821 /// Scaling factor.
823 scale = ComponentBatch::from_loggable(_scale, Descriptor_scale).value_or_throw();
824 return std::move(*this);
825 }
826
827 /// This method makes it possible to pack multiple `scale` in a single component batch.
828 ///
829 /// This only makes sense when used in conjunction with `columns`. `with_scale` should
830 /// be used when logging a single row's worth of data.
832 scale = ComponentBatch::from_loggable(_scale, Descriptor_scale).value_or_throw();
833 return std::move(*this);
834 }
835
836 /// 3x3 transformation matrix.
838 mat3x3 = ComponentBatch::from_loggable(_mat3x3, Descriptor_mat3x3).value_or_throw();
839 return std::move(*this);
840 }
841
842 /// This method makes it possible to pack multiple `mat3x3` in a single component batch.
843 ///
844 /// This only makes sense when used in conjunction with `columns`. `with_mat3x3` should
845 /// be used when logging a single row's worth of data.
847 ) && {
848 mat3x3 = ComponentBatch::from_loggable(_mat3x3, Descriptor_mat3x3).value_or_throw();
849 return std::move(*this);
850 }
851
852 /// Specifies the relation this transform establishes between this entity and its parent.
854 relation =
855 ComponentBatch::from_loggable(_relation, Descriptor_relation).value_or_throw();
856 return std::move(*this);
857 }
858
859 /// This method makes it possible to pack multiple `relation` in a single component batch.
860 ///
861 /// This only makes sense when used in conjunction with `columns`. `with_relation` should
862 /// be used when logging a single row's worth of data.
865 ) && {
866 relation =
867 ComponentBatch::from_loggable(_relation, Descriptor_relation).value_or_throw();
868 return std::move(*this);
869 }
870
871 /// Visual length of the 3 axes.
872 ///
873 /// The length is interpreted in the local coordinate system of the transform.
874 /// If the transform is scaled, the axes will be scaled accordingly.
877 .value_or_throw();
878 return std::move(*this);
879 }
880
881 /// This method makes it possible to pack multiple `axis_length` in a single component batch.
882 ///
883 /// This only makes sense when used in conjunction with `columns`. `with_axis_length` should
884 /// be used when logging a single row's worth of data.
887 ) && {
889 .value_or_throw();
890 return std::move(*this);
891 }
892
893 /// Partitions the component data into multiple sub-batches.
894 ///
895 /// Specifically, this transforms the existing `ComponentBatch` data into `ComponentColumn`s
896 /// instead, via `ComponentBatch::partitioned`.
897 ///
898 /// This makes it possible to use `RecordingStream::send_columns` to send columnar data directly into Rerun.
899 ///
900 /// The specified `lengths` must sum to the total length of the component batch.
902
903 /// Partitions the component data into unit-length sub-batches.
904 ///
905 /// This is semantically similar to calling `columns` with `std::vector<uint32_t>(n, 1)`,
906 /// where `n` is automatically guessed.
908 };
909
910} // namespace rerun::archetypes
911
912namespace rerun {
913 /// \private
914 template <typename T>
915 struct AsComponents;
916
917 /// \private
918 template <>
919 struct AsComponents<archetypes::Transform3D> {
920 /// Serialize all set component batches.
921 static Result<Collection<ComponentBatch>> as_batches(
922 const archetypes::Transform3D& archetype
923 );
924 };
925} // 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
TransformRelation
Component: Specifies relation a spatial transform describes.
Definition transform_relation.hpp:25
@ ChildFromParent
The transform describes how to transform into the child entity's space.
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=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
Utility for representing a single 3D rotation, agnostic to the underlying representation.
Definition rotation3d.hpp:14
Archetype: A transform between two 3D spaces, i.e.
Definition transform3d.hpp:303
static constexpr auto Descriptor_rotation_axis_angle
ComponentDescriptor for the rotation_axis_angle field.
Definition transform3d.hpp:343
static RERUN_SDK_EXPORT const Transform3D IDENTITY
Identity transformation.
Definition transform3d.hpp:376
std::optional< ComponentBatch > mat3x3
3x3 transformation matrix.
Definition transform3d.hpp:317
Transform3D with_many_axis_length(const Collection< rerun::components::AxisLength > &_axis_length) &&
This method makes it possible to pack multiple axis_length in a single component batch.
Definition transform3d.hpp:885
Transform3D(const datatypes::Vec3D(&columns)[3], bool from_parent=false)
From 3x3 matrix provided as 3 columns only.
Definition transform3d.hpp:487
Transform3D(const components::Translation3D &translation_, const components::TransformMat3x3 &mat3x3_, bool from_parent=false)
Creates a new 3D transform from translation/matrix.
Definition transform3d.hpp:404
static Transform3D from_translation_scale(const components::Translation3D &translation, const components::Scale3D &scale)
From a translation applied after a scale.
Definition transform3d.hpp:613
Transform3D with_relation(const rerun::components::TransformRelation &_relation) &&
Specifies the relation this transform establishes between this entity and its parent.
Definition transform3d.hpp:853
Transform3D(const components::Translation3D &translation_, const Rotation3D &rotation, float uniform_scale, bool from_parent=false)
Creates a new 3D transform from translation/rotation/uniform-scale.
Definition transform3d.hpp:529
std::optional< ComponentBatch > axis_length
Visual length of the 3 axes.
Definition transform3d.hpp:326
static Transform3D from_mat3x3(const components::TransformMat3x3 &mat3x3)
From 3x3 matrix only.
Definition transform3d.hpp:478
Transform3D(const components::Translation3D &translation_, const Rotation3D &rotation, const components::Scale3D &scale_, bool from_parent=false)
Creates a new 3D transform from translation/rotation/scale.
Definition transform3d.hpp:505
Transform3D(const Rotation3D &rotation, float uniform_scale, bool from_parent=false)
From rotation & uniform scale.
Definition transform3d.hpp:659
Transform3D(const components::Translation3D &translation_, float uniform_scale, bool from_parent=false)
From translation & uniform scale only.
Definition transform3d.hpp:628
Transform3D with_scale(const rerun::components::Scale3D &_scale) &&
Scaling factor.
Definition transform3d.hpp:822
Collection< ComponentColumn > columns(const Collection< uint32_t > &lengths_)
Partitions the component data into multiple sub-batches.
static RERUN_SDK_EXPORT const Transform3D INVALID
Invalid transformation.
Definition transform3d.hpp:381
Transform3D with_quaternion(const rerun::components::RotationQuat &_quaternion) &&
Rotation via quaternion.
Definition transform3d.hpp:803
std::optional< ComponentBatch > translation
Translation vector.
Definition transform3d.hpp:305
Transform3D(const components::Translation3D &translation_, const Rotation3D &rotation, bool from_parent=false)
Creates a new rigid transform (translation & rotation only).
Definition transform3d.hpp:568
Transform3D(const components::Translation3D &translation_, const datatypes::Vec3D(&columns)[3], bool from_parent=false)
Creates a new 3D transform from translation and matrix provided as 3 columns.
Definition transform3d.hpp:392
Transform3D with_translation(const rerun::components::Translation3D &_translation) &&
Translation vector.
Definition transform3d.hpp:761
Transform3D(const Rotation3D &rotation, bool from_parent=false)
From rotation only.
Definition transform3d.hpp:687
Transform3D(const components::TransformMat3x3 &mat3x3_, bool from_parent=false)
From 3x3 matrix only.
Definition transform3d.hpp:466
Transform3D with_axis_length(const rerun::components::AxisLength &_axis_length) &&
Visual length of the 3 axes.
Definition transform3d.hpp:875
static Transform3D update_fields()
Update only some specific fields of a Transform3D.
Definition transform3d.hpp:753
static Transform3D from_rotation_scale(const Rotation3D &rotation, float uniform_scale)
From a rotation & uniform scale.
Definition transform3d.hpp:678
static Transform3D from_translation_mat3x3(const components::Translation3D &translation, const components::TransformMat3x3 &mat3x3)
From a translation applied after a 3x3 matrix.
Definition transform3d.hpp:420
static Transform3D from_rotation_scale(const Rotation3D &rotation, const components::Scale3D &scale)
From a rotation & scale.
Definition transform3d.hpp:667
static Transform3D from_translation(const components::Translation3D &translation)
From a translation.
Definition transform3d.hpp:457
static constexpr auto Descriptor_axis_length
ComponentDescriptor for the axis_length field.
Definition transform3d.hpp:367
Transform3D with_rotation(const Rotation3D &rotation) &&
Set the rotation component of the transform using the rerun::Rotation3D utility.
Definition transform3d.hpp:733
static Transform3D from_scale(float uniform_scale)
From scale only.
Definition transform3d.hpp:728
std::optional< ComponentBatch > rotation_axis_angle
Rotation via axis + angle.
Definition transform3d.hpp:308
Transform3D with_many_mat3x3(const Collection< rerun::components::TransformMat3x3 > &_mat3x3) &&
This method makes it possible to pack multiple mat3x3 in a single component batch.
Definition transform3d.hpp:846
static constexpr auto Descriptor_translation
ComponentDescriptor for the translation field.
Definition transform3d.hpp:338
Transform3D with_many_rotation_axis_angle(const Collection< rerun::components::RotationAxisAngle > &_rotation_axis_angle) &&
This method makes it possible to pack multiple rotation_axis_angle in a single component batch.
Definition transform3d.hpp:793
static constexpr auto Descriptor_quaternion
ComponentDescriptor for the quaternion field.
Definition transform3d.hpp:348
static Transform3D from_translation_rotation_scale(const components::Translation3D &translation, const Rotation3D &rotation, const components::Scale3D &scale)
From a translation, applied after a rotation & scale, known as an affine transformation.
Definition transform3d.hpp:542
static constexpr const char ArchetypeName[]
The name of the archetype as used in ComponentDescriptors.
Definition transform3d.hpp:335
static constexpr auto Descriptor_scale
ComponentDescriptor for the scale field.
Definition transform3d.hpp:353
Transform3D(const components::Scale3D &scale_, bool from_parent=false)
From scale only.
Definition transform3d.hpp:708
static constexpr auto Descriptor_mat3x3
ComponentDescriptor for the mat3x3 field.
Definition transform3d.hpp:357
static Transform3D from_translation_mat3x3(const components::Translation3D &translation, const datatypes::Vec3D(&columns)[3])
From a translation applied after a 3x3 matrix provided as 3 columns.
Definition transform3d.hpp:431
static Transform3D from_translation_rotation(const components::Translation3D &translation, const Rotation3D &rotation)
From a rotation & scale.
Definition transform3d.hpp:585
Collection< ComponentColumn > columns()
Partitions the component data into unit-length sub-batches.
std::optional< ComponentBatch > quaternion
Rotation via quaternion.
Definition transform3d.hpp:311
Transform3D(const Rotation3D &rotation, const components::Scale3D &scale_, bool from_parent=false)
From rotation & scale.
Definition transform3d.hpp:640
Transform3D with_many_relation(const Collection< rerun::components::TransformRelation > &_relation) &&
This method makes it possible to pack multiple relation in a single component batch.
Definition transform3d.hpp:863
Transform3D(const components::Translation3D &translation_, bool from_parent=false)
From translation only.
Definition transform3d.hpp:445
Transform3D with_many_quaternion(const Collection< rerun::components::RotationQuat > &_quaternion) &&
This method makes it possible to pack multiple quaternion in a single component batch.
Definition transform3d.hpp:813
Transform3D with_rotation_axis_angle(const rerun::components::RotationAxisAngle &_rotation_axis_angle) &&
Rotation via axis + angle.
Definition transform3d.hpp:780
Transform3D with_many_translation(const Collection< rerun::components::Translation3D > &_translation) &&
This method makes it possible to pack multiple translation in a single component batch.
Definition transform3d.hpp:771
Transform3D(const components::Translation3D &translation_, const components::Scale3D &scale_, bool from_parent=false)
From translation & scale only.
Definition transform3d.hpp:597
std::optional< ComponentBatch > relation
Specifies the relation this transform establishes between this entity and its parent.
Definition transform3d.hpp:320
static Transform3D clear_fields()
Clear all the fields of a Transform3D.
Transform3D with_many_scale(const Collection< rerun::components::Scale3D > &_scale) &&
This method makes it possible to pack multiple scale in a single component batch.
Definition transform3d.hpp:831
static Transform3D from_translation_rotation_scale(const components::Translation3D &translation, const Rotation3D &rotation, float uniform_scale)
From a translation, applied after a rotation & scale, known as an affine transformation.
Definition transform3d.hpp:555
Transform3D with_mat3x3(const rerun::components::TransformMat3x3 &_mat3x3) &&
3x3 transformation matrix.
Definition transform3d.hpp:837
static constexpr auto Descriptor_relation
ComponentDescriptor for the relation field.
Definition transform3d.hpp:362
static Transform3D from_scale(const components::Scale3D &scale)
From scale only.
Definition transform3d.hpp:720
static Transform3D from_mat3x3(const datatypes::Vec3D(&columns)[3])
From 3x3 matrix provided as 3 columns only.
Definition transform3d.hpp:494
std::optional< ComponentBatch > scale
Scaling factor.
Definition transform3d.hpp:314
static Transform3D from_rotation(const Rotation3D &rotation)
From rotation only.
Definition transform3d.hpp:699
Component: The length of an axis in local units of the space.
Definition axis_length.hpp:15
Indicator component used by archetypes when converting them to component lists.
Definition indicator_component.hpp:32
Component: 3D rotation represented by a rotation around a given axis.
Definition rotation_axis_angle.hpp:18
Component: A 3D rotation expressed as a quaternion.
Definition rotation_quat.hpp:19
Component: A 3D scale factor.
Definition scale3d.hpp:20
Component: A 3x3 transformation matrix Matrix.
Definition transform_mat3x3.hpp:28
Component: A translation vector in 3D space.
Definition translation3d.hpp:16
Datatype: A vector in 3D space.
Definition vec3d.hpp:21