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