Rerun C++ SDK
Loading...
Searching...
No Matches
transform3d.hpp
1// DO NOT EDIT! This file was auto-generated by crates/re_types_builder/src/codegen/cpp/mod.rs
2// Based on "crates/re_types/definitions/rerun/datatypes/transform3d.fbs".
3
4#pragma once
5
6#include "../result.hpp"
7#include "translation_and_mat3x3.hpp"
8#include "translation_rotation_scale3d.hpp"
9
10#include <cstdint>
11#include <cstring>
12#include <memory>
13#include <new>
14#include <utility>
15
16namespace arrow {
17 class Array;
18 class DataType;
19 class DenseUnionBuilder;
20} // namespace arrow
21
22namespace rerun::datatypes {
23 namespace detail {
24 /// \private
25 enum class Transform3DTag : uint8_t {
26 /// Having a special empty state makes it possible to implement move-semantics. We need to be able to leave the object in a state which we can run the destructor on.
27 None = 0,
28 TranslationAndMat3x3,
29 TranslationRotationScale,
30 };
31
32 /// \private
33 union Transform3DData {
34 rerun::datatypes::TranslationAndMat3x3 translation_and_mat3x3;
35
36 rerun::datatypes::TranslationRotationScale3D translation_rotation_scale;
37
38 Transform3DData() {
39 std::memset(reinterpret_cast<void*>(this), 0, sizeof(Transform3DData));
40 }
41
42 ~Transform3DData() {}
43
44 void swap(Transform3DData& other) noexcept {
45 // This bitwise swap would fail for self-referential types, but we don't have any of those.
46 char temp[sizeof(Transform3DData)];
47 void* otherbytes = reinterpret_cast<void*>(&other);
48 void* thisbytes = reinterpret_cast<void*>(this);
49 std::memcpy(temp, thisbytes, sizeof(Transform3DData));
50 std::memcpy(thisbytes, otherbytes, sizeof(Transform3DData));
51 std::memcpy(otherbytes, temp, sizeof(Transform3DData));
52 }
53 };
54 } // namespace detail
55
56 /// **Datatype**: Representation of a 3D affine transform.
57 struct Transform3D {
58 Transform3D() : _tag(detail::Transform3DTag::None) {}
59
60 /// Copy constructor
61 Transform3D(const Transform3D& other) : _tag(other._tag) {
62 const void* otherbytes = reinterpret_cast<const void*>(&other._data);
63 void* thisbytes = reinterpret_cast<void*>(&this->_data);
64 std::memcpy(thisbytes, otherbytes, sizeof(detail::Transform3DData));
65 }
66
67 Transform3D& operator=(const Transform3D& other) noexcept {
68 Transform3D tmp(other);
69 this->swap(tmp);
70 return *this;
71 }
72
73 Transform3D(Transform3D&& other) noexcept : Transform3D() {
74 this->swap(other);
75 }
76
77 Transform3D& operator=(Transform3D&& other) noexcept {
78 this->swap(other);
79 return *this;
80 }
81
82 void swap(Transform3D& other) noexcept {
83 std::swap(this->_tag, other._tag);
84 this->_data.swap(other._data);
85 }
86
87 Transform3D(rerun::datatypes::TranslationAndMat3x3 translation_and_mat3x3) : Transform3D() {
88 *this = Transform3D::translation_and_mat3x3(std::move(translation_and_mat3x3));
89 }
90
91 Transform3D(rerun::datatypes::TranslationRotationScale3D translation_rotation_scale)
92 : Transform3D() {
93 *this = Transform3D::translation_rotation_scale(std::move(translation_rotation_scale));
94 }
95
96 static Transform3D translation_and_mat3x3(
97 rerun::datatypes::TranslationAndMat3x3 translation_and_mat3x3
98 ) {
99 Transform3D self;
100 self._tag = detail::Transform3DTag::TranslationAndMat3x3;
101 new (&self._data.translation_and_mat3x3)
102 rerun::datatypes::TranslationAndMat3x3(std::move(translation_and_mat3x3));
103 return self;
104 }
105
106 static Transform3D translation_rotation_scale(
107 rerun::datatypes::TranslationRotationScale3D translation_rotation_scale
108 ) {
109 Transform3D self;
110 self._tag = detail::Transform3DTag::TranslationRotationScale;
111 new (&self._data.translation_rotation_scale)
112 rerun::datatypes::TranslationRotationScale3D(std::move(translation_rotation_scale));
113 return self;
114 }
115
116 /// Return a pointer to translation_and_mat3x3 if the union is in that state, otherwise `nullptr`.
118 if (_tag == detail::Transform3DTag::TranslationAndMat3x3) {
119 return &_data.translation_and_mat3x3;
120 } else {
121 return nullptr;
122 }
123 }
124
125 /// Return a pointer to translation_rotation_scale if the union is in that state, otherwise `nullptr`.
127 if (_tag == detail::Transform3DTag::TranslationRotationScale) {
128 return &_data.translation_rotation_scale;
129 } else {
130 return nullptr;
131 }
132 }
133
134 /// \private
135 const detail::Transform3DData& get_union_data() const {
136 return _data;
137 }
138
139 /// \private
140 detail::Transform3DTag get_union_tag() const {
141 return _tag;
142 }
143
144 private:
145 detail::Transform3DTag _tag;
146 detail::Transform3DData _data;
147 };
148} // namespace rerun::datatypes
149
150namespace rerun {
151 template <typename T>
152 struct Loggable;
153
154 /// \private
155 template <>
156 struct Loggable<datatypes::Transform3D> {
157 static constexpr const char Name[] = "rerun.datatypes.Transform3D";
158
159 /// Returns the arrow data type this type corresponds to.
160 static const std::shared_ptr<arrow::DataType>& arrow_datatype();
161
162 /// Fills an arrow array builder with an array of this type.
163 static rerun::Error fill_arrow_array_builder(
164 arrow::DenseUnionBuilder* builder, const datatypes::Transform3D* elements,
165 size_t num_elements
166 );
167
168 /// Serializes an array of `rerun::datatypes::Transform3D` into an arrow array.
169 static Result<std::shared_ptr<arrow::Array>> to_arrow(
170 const datatypes::Transform3D* instances, size_t num_instances
171 );
172 };
173} // namespace rerun
Status outcome object (success or error) returned for fallible operations.
Definition error.hpp:87
All built-in datatypes. See Types in the Rerun manual.
Definition rerun.hpp:72
All Rerun C++ types and functions are in the rerun namespace or one of its nested namespaces.
Definition rerun.hpp:20
Archetype: A 3D transform.
Definition transform3d.hpp:51
Datatype: Representation of a 3D affine transform.
Definition transform3d.hpp:57
const rerun::datatypes::TranslationAndMat3x3 * get_translation_and_mat3x3() const
Return a pointer to translation_and_mat3x3 if the union is in that state, otherwise nullptr.
Definition transform3d.hpp:117
Transform3D(const Transform3D &other)
Copy constructor.
Definition transform3d.hpp:61
const rerun::datatypes::TranslationRotationScale3D * get_translation_rotation_scale() const
Return a pointer to translation_rotation_scale if the union is in that state, otherwise nullptr.
Definition transform3d.hpp:126
Datatype: Representation of an affine transform via a 3x3 affine matrix paired with a translation.
Definition translation_and_mat3x3.hpp:24
Datatype: Representation of an affine transform via separate translation, rotation & scale.
Definition translation_rotation_scale3d.hpp:24