Rerun C++ SDK
Loading...
Searching...
No Matches
rotation3d.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/rotation3d.fbs".
3
4#pragma once
5
6#include "../result.hpp"
7#include "quaternion.hpp"
8#include "rotation_axis_angle.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 Rotation3DTag : 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 Quaternion,
29 AxisAngle,
30 };
31
32 /// \private
33 union Rotation3DData {
34 /// Rotation defined by a quaternion.
36
37 /// Rotation defined with an axis and an angle.
39
40 Rotation3DData() {
41 std::memset(reinterpret_cast<void*>(this), 0, sizeof(Rotation3DData));
42 }
43
44 ~Rotation3DData() {}
45
46 void swap(Rotation3DData& other) noexcept {
47 // This bitwise swap would fail for self-referential types, but we don't have any of those.
48 char temp[sizeof(Rotation3DData)];
49 void* otherbytes = reinterpret_cast<void*>(&other);
50 void* thisbytes = reinterpret_cast<void*>(this);
51 std::memcpy(temp, thisbytes, sizeof(Rotation3DData));
52 std::memcpy(thisbytes, otherbytes, sizeof(Rotation3DData));
53 std::memcpy(otherbytes, temp, sizeof(Rotation3DData));
54 }
55 };
56 } // namespace detail
57
58 /// **Datatype**: A 3D rotation.
59 struct Rotation3D {
60 Rotation3D() : _tag(detail::Rotation3DTag::None) {}
61
62 /// Copy constructor
63 Rotation3D(const Rotation3D& other) : _tag(other._tag) {
64 const void* otherbytes = reinterpret_cast<const void*>(&other._data);
65 void* thisbytes = reinterpret_cast<void*>(&this->_data);
66 std::memcpy(thisbytes, otherbytes, sizeof(detail::Rotation3DData));
67 }
68
69 Rotation3D& operator=(const Rotation3D& other) noexcept {
70 Rotation3D tmp(other);
71 this->swap(tmp);
72 return *this;
73 }
74
75 Rotation3D(Rotation3D&& other) noexcept : Rotation3D() {
76 this->swap(other);
77 }
78
79 Rotation3D& operator=(Rotation3D&& other) noexcept {
80 this->swap(other);
81 return *this;
82 }
83
84 public:
85 // Extensions to generated type defined in 'rotation3d_ext.cpp'
86
87 static const Rotation3D IDENTITY;
88
89 void swap(Rotation3D& other) noexcept {
90 std::swap(this->_tag, other._tag);
91 this->_data.swap(other._data);
92 }
93
94 /// Rotation defined by a quaternion.
96 *this = Rotation3D::quaternion(std::move(quaternion));
97 }
98
99 /// Rotation defined with an axis and an angle.
101 *this = Rotation3D::axis_angle(std::move(axis_angle));
102 }
103
104 /// Rotation defined by a quaternion.
106 Rotation3D self;
107 self._tag = detail::Rotation3DTag::Quaternion;
108 new (&self._data.quaternion) rerun::datatypes::Quaternion(std::move(quaternion));
109 return self;
110 }
111
112 /// Rotation defined with an axis and an angle.
114 Rotation3D self;
115 self._tag = detail::Rotation3DTag::AxisAngle;
116 new (&self._data.axis_angle) rerun::datatypes::RotationAxisAngle(std::move(axis_angle));
117 return self;
118 }
119
120 /// Return a pointer to quaternion if the union is in that state, otherwise `nullptr`.
122 if (_tag == detail::Rotation3DTag::Quaternion) {
123 return &_data.quaternion;
124 } else {
125 return nullptr;
126 }
127 }
128
129 /// Return a pointer to axis_angle if the union is in that state, otherwise `nullptr`.
131 if (_tag == detail::Rotation3DTag::AxisAngle) {
132 return &_data.axis_angle;
133 } else {
134 return nullptr;
135 }
136 }
137
138 /// \private
139 const detail::Rotation3DData& get_union_data() const {
140 return _data;
141 }
142
143 /// \private
144 detail::Rotation3DTag get_union_tag() const {
145 return _tag;
146 }
147
148 private:
149 detail::Rotation3DTag _tag;
150 detail::Rotation3DData _data;
151 };
152} // namespace rerun::datatypes
153
154namespace rerun {
155 template <typename T>
156 struct Loggable;
157
158 /// \private
159 template <>
160 struct Loggable<datatypes::Rotation3D> {
161 static constexpr const char Name[] = "rerun.datatypes.Rotation3D";
162
163 /// Returns the arrow data type this type corresponds to.
164 static const std::shared_ptr<arrow::DataType>& arrow_datatype();
165
166 /// Fills an arrow array builder with an array of this type.
167 static rerun::Error fill_arrow_array_builder(
168 arrow::DenseUnionBuilder* builder, const datatypes::Rotation3D* elements,
169 size_t num_elements
170 );
171
172 /// Serializes an array of `rerun::datatypes::Rotation3D` into an arrow array.
173 static Result<std::shared_ptr<arrow::Array>> to_arrow(
174 const datatypes::Rotation3D* instances, size_t num_instances
175 );
176 };
177} // 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
Datatype: A Quaternion represented by 4 real numbers.
Definition quaternion.hpp:23
Datatype: A 3D rotation.
Definition rotation3d.hpp:59
Rotation3D(rerun::datatypes::Quaternion quaternion)
Rotation defined by a quaternion.
Definition rotation3d.hpp:95
static Rotation3D quaternion(rerun::datatypes::Quaternion quaternion)
Rotation defined by a quaternion.
Definition rotation3d.hpp:105
static Rotation3D axis_angle(rerun::datatypes::RotationAxisAngle axis_angle)
Rotation defined with an axis and an angle.
Definition rotation3d.hpp:113
const rerun::datatypes::RotationAxisAngle * get_axis_angle() const
Return a pointer to axis_angle if the union is in that state, otherwise nullptr.
Definition rotation3d.hpp:130
Rotation3D(rerun::datatypes::RotationAxisAngle axis_angle)
Rotation defined with an axis and an angle.
Definition rotation3d.hpp:100
Rotation3D(const Rotation3D &other)
Copy constructor.
Definition rotation3d.hpp:63
const rerun::datatypes::Quaternion * get_quaternion() const
Return a pointer to quaternion if the union is in that state, otherwise nullptr.
Definition rotation3d.hpp:121
Datatype: 3D rotation represented by a rotation around a given axis.
Definition rotation_axis_angle.hpp:21