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