MeshLib C++ Docs
Loading...
Searching...
No Matches
MRToFromEigen.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRQuaternion.h"
4#include "MRVector2.h"
5#include "MRVector3.h"
6#include "MRVector4.h"
7#include "MRSymMatrix2.h"
8#include "MRSymMatrix3.h"
9#include "MRSymMatrix4.h"
10#include "MRMatrix2.h"
11#include "MRMatrix3.h"
12#include "MRMatrix4.h"
13#include <MRPch/MREigenCore.h>
14
15namespace MR
16{
19
20
23
24template <typename T>
25[[nodiscard]] inline Vector2<T> fromEigen( const Eigen::Matrix<T, 2, 1> & ev )
26{
27 return Vector2<T>{ ev.x(), ev.y() };
28}
29
30template <typename T>
31[[nodiscard]] inline Eigen::Matrix<T, 2, 1> toEigen( const Vector2<T> & v )
32{
33 return Eigen::Matrix<T, 2, 1>{ v.x, v.y };
34}
35
36template <typename T>
37[[nodiscard]] inline Eigen::Matrix<T, 2, 2> toEigen( const SymMatrix2<T> & m )
38{
39 Eigen::Matrix<T, 2, 2> res;
40 res << m.xx, m.xy,
41 m.xy, m.yy;
42 return res;
43}
44
45template <typename T>
46[[nodiscard]] inline Eigen::Matrix<T, 2, 2> toEigen( const Matrix2<T> & m )
47{
48 Eigen::Matrix<T, 2, 2> res;
49 res << m.x.x, m.x.y,
50 m.y.x, m.y.y;
51 return res;
52}
53
54template <typename T>
55[[nodiscard]] inline Matrix2<T> fromEigen( const Eigen::Matrix<T, 2, 2> & m )
56{
57 return Matrix2<T> {
58 { m( 0, 0 ), m( 0, 1 ) },
59 { m( 1, 0 ), m( 1, 1 ) }
60 };
61}
62
63template <typename T>
64[[nodiscard]] inline Vector3<T> fromEigen( const Eigen::Matrix<T, 3, 1> & ev )
65{
66 return Vector3<T>{ ev.x(), ev.y(), ev.z() };
67}
68
69template <typename T>
70[[nodiscard]] inline Eigen::Matrix<T, 3, 1> toEigen( const Vector3<T> & v )
71{
72 return Eigen::Matrix<T, 3, 1>{ v.x, v.y, v.z };
73}
74
75template <typename T>
76[[nodiscard]] inline Eigen::Matrix<T, 3, 3> toEigen( const SymMatrix3<T> & m )
77{
78 Eigen::Matrix<T, 3, 3> res;
79 res << m.xx, m.xy, m.xz,
80 m.xy, m.yy, m.yz,
81 m.xz, m.yz, m.zz;
82 return res;
83}
84
85template <typename T>
86[[nodiscard]] inline Eigen::Matrix<T, 3, 3> toEigen( const Matrix3<T> & m )
87{
88 Eigen::Matrix<T, 3, 3> res;
89 res << m.x.x, m.x.y, m.x.z,
90 m.y.x, m.y.y, m.y.z,
91 m.z.x, m.z.y, m.z.z;
92 return res;
93}
94
95template <typename T>
96[[nodiscard]] inline Matrix3<T> fromEigen( const Eigen::Matrix<T, 3, 3> & m )
97{
98 return Matrix3<T> {
99 { m( 0, 0 ), m( 0, 1 ), m( 0, 2 ) },
100 { m( 1, 0 ), m( 1, 1 ), m( 1, 2 ) },
101 { m( 2, 0 ), m( 2, 1 ), m( 2, 2 ) }
102 };
103}
104
105template <typename T>
106[[nodiscard]] inline Eigen::Matrix<T, 4, 4> toEigen( const SymMatrix4<T> & m )
107{
108 Eigen::Matrix<T, 4, 4> res;
109 res << m.xx, m.xy, m.xz, m.xw,
110 m.xy, m.yy, m.yz, m.yw,
111 m.xz, m.yz, m.zz, m.zw,
112 m.xw, m.yw, m.zw, m.ww;
113 return res;
114}
115
116template <typename T>
117[[nodiscard]] inline Eigen::Matrix<T, 4, 4> toEigen( const Matrix4<T> & m )
118{
119 Eigen::Matrix<T, 4, 4> res;
120 res << m.x.x, m.x.y, m.x.z, m.x.w,
121 m.y.x, m.y.y, m.y.z, m.y.w,
122 m.z.x, m.z.y, m.z.z, m.x.w,
123 m.w.x, m.w.y, m.w.z, m.w.w;
124 return res;
125}
126
127template <typename T>
128[[nodiscard]] inline Matrix4<T> fromEigen( const Eigen::Matrix<T, 4, 4> & m )
129{
130 return Matrix4<T> {
131 { m( 0, 0 ), m( 0, 1 ), m( 0, 2 ), m( 0, 3 ) },
132 { m( 1, 0 ), m( 1, 1 ), m( 1, 2 ), m( 1, 3 ) },
133 { m( 2, 0 ), m( 2, 1 ), m( 2, 2 ), m( 2, 3 ) },
134 { m( 3, 0 ), m( 3, 1 ), m( 3, 2 ), m( 3, 3 ) }
135 };
136}
137
138template <typename T>
139[[nodiscard]] inline Vector4<T> fromEigen( const Eigen::Matrix<T, 4, 1> & ev )
140{
141 return Vector4<T>{ ev.x(), ev.y(), ev.z(), ev.w() };
142}
143
144template <typename T>
145[[nodiscard]] inline Eigen::Matrix<T, 4, 1> toEigen( const Vector4<T> & v )
146{
147 return Eigen::Matrix<T, 4, 1>{ v.x, v.y, v.z, v.w };
148}
149
150template <typename T>
151[[nodiscard]] inline Eigen::Matrix<T, 4, 1> toEigen( const Vector3<T> & v, T w )
152{
153 return Eigen::Matrix<T, 4, 1>{ v.x, v.y, v.z, w };
154}
155
156template <typename T>
157[[nodiscard]] inline Quaternion<T> fromEigen( const Eigen::Quaternion<T> & eq )
158{
159 return Quaternion<T>{ eq.w(), eq.x(), eq.y(), eq.z() };
160}
161
162template <typename T>
163[[nodiscard]] inline Eigen::Quaternion<T> toEigen( const Quaternion<T> & q )
164{
165 return Eigen::Quaternion<T>{ q.a, q.b, q.c, q.d };
166}
167
169
170}
T xz
Definition MRSymMatrix4.h:20
Vector2< T > x
rows, identity matrix by default
Definition MRMatrix2.h:29
T y
Definition MRVector4.h:32
T d
imaginary part: b*i + c*j + d*k
Definition MRQuaternion.h:18
T z
Definition MRVector4.h:32
Vector4< T > z
Definition MRMatrix4.h:32
T x
Definition MRVector4.h:32
T xy
Definition MRSymMatrix2.h:21
T w
Definition MRVector4.h:32
T xy
Definition MRSymMatrix3.h:22
T c
Definition MRQuaternion.h:18
Vector3< T > x
rows, identity matrix by default
Definition MRMatrix3.h:29
T x
Definition MRVector3.h:39
T yy
Definition MRSymMatrix2.h:21
T zw
Definition MRSymMatrix4.h:22
T y
Definition MRVector3.h:39
T xx
zero matrix by default
Definition MRSymMatrix4.h:20
T ww
Definition MRSymMatrix4.h:23
T yz
Definition MRSymMatrix3.h:22
Vector2< T > y
Definition MRMatrix2.h:30
T zz
Definition MRSymMatrix4.h:22
Vector4< T > y
Definition MRMatrix4.h:31
T xy
Definition MRSymMatrix4.h:20
T xz
Definition MRSymMatrix3.h:22
T a
real part of the quaternion
Definition MRQuaternion.h:17
T xx
zero matrix by default
Definition MRSymMatrix3.h:22
T b
Definition MRQuaternion.h:18
Vector4< T > w
Definition MRMatrix4.h:33
T yz
Definition MRSymMatrix4.h:21
T xw
Definition MRSymMatrix4.h:20
Vector3< T > y
Definition MRMatrix3.h:30
T yy
Definition MRSymMatrix4.h:21
Vector3< T > z
Definition MRMatrix3.h:31
T zz
Definition MRSymMatrix3.h:22
T z
Definition MRVector3.h:39
T yy
Definition MRSymMatrix3.h:22
T xx
zero matrix by default
Definition MRSymMatrix2.h:21
T yw
Definition MRSymMatrix4.h:21
Vector4< T > x
rows, identity matrix by default
Definition MRMatrix4.h:30
Vector2< T > fromEigen(const Eigen::Matrix< T, 2, 1 > &ev)
Definition MRToFromEigen.h:25
Eigen::Matrix< T, 2, 1 > toEigen(const Vector2< T > &v)
Definition MRToFromEigen.h:31
only for bindings generation
Definition MRCameraOrientationPlugin.h:8
Definition MRMatrix2.h:24
Definition MRMatrix3.h:24
Definition MRMatrix4.h:25
Definition MRQuaternion.h:16
Definition MRSymMatrix2.h:17
Definition MRSymMatrix3.h:18
Definition MRSymMatrix4.h:16
Definition MRVector2.h:29
T x
Definition MRVector2.h:35
T y
Definition MRVector2.h:35
Definition MRVector3.h:33
Definition MRVector4.h:26