Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
wolf
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mobile_robotics
wolf_projects
wolf_lib
wolf
Merge requests
!278
Resolve "Revisit demos (formerly called examples) and update them"
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Resolve "Revisit demos (formerly called examples) and update them"
209-revisit-demos-formerly-called-examples-and-update-them
into
devel
Overview
1
Commits
29
Pipelines
8
Changes
1
Merged
Joan Vallvé Navarro
requested to merge
209-revisit-demos-formerly-called-examples-and-update-them
into
devel
6 years ago
Overview
1
Commits
29
Pipelines
8
Changes
1
Expand
Closes
#209 (closed)
Edited
6 years ago
by
Joan Vallvé Navarro
0
0
Merge request reports
Viewing commit
fa891a82
Prev
Next
Show latest version
1 file
+
0
−
105
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
fa891a82
removed eigen_template demo
· fa891a82
Joan Vallvé Navarro
authored
6 years ago
demos/demo_eigen_template.cpp deleted
100644 → 0
+
0
−
105
Options
/**
* \file test_eigen_template.cpp
*
* Created on: Sep 12, 2016
* \author: jsola
*/
#include
<eigen3/Eigen/Dense>
#include
<eigen3/Eigen/Geometry>
#include
<iostream>
template
<
int
Size
,
int
DesiredSize
>
struct
StaticSizeCheck
{
template
<
typename
T
>
StaticSizeCheck
(
const
T
&
)
{
static_assert
(
Size
==
DesiredSize
,
"Static sizes do not match"
);
}
};
template
<
int
DesiredSize
>
struct
StaticSizeCheck
<
Eigen
::
Dynamic
,
DesiredSize
>
{
template
<
typename
T
>
StaticSizeCheck
(
const
T
&
t
)
{
assert
(
t
==
DesiredSize
&&
"Dynamic sizes do not match"
);
}
};
template
<
int
DesiredR
,
int
DesiredC
>
struct
MatrixSizeCheck
{
template
<
typename
T
>
static
void
check
(
const
T
&
t
)
{
StaticSizeCheck
<
T
::
RowsAtCompileTime
,
DesiredR
>
(
t
.
rows
());
StaticSizeCheck
<
T
::
ColsAtCompileTime
,
DesiredC
>
(
t
.
cols
());
}
};
template
<
typename
Derived
>
inline
Eigen
::
Quaternion
<
typename
Derived
::
Scalar
>
v2q
(
const
Eigen
::
MatrixBase
<
Derived
>&
_v
){
MatrixSizeCheck
<
3
,
1
>::
check
(
_v
);
Eigen
::
Quaternion
<
typename
Derived
::
Scalar
>
q
;
typename
Derived
::
Scalar
angle
=
_v
.
norm
();
typename
Derived
::
Scalar
angle_half
=
angle
/
2.0
;
if
(
angle
>
1e-8
)
{
q
.
w
()
=
cos
(
angle_half
);
q
.
vec
()
=
_v
/
angle
*
sin
(
angle_half
);
return
q
;
}
else
{
q
.
w
()
=
cos
(
angle_half
);
q
.
vec
()
=
_v
*
(
(
typename
Derived
::
Scalar
)
0.5
-
angle_half
*
angle_half
/
(
typename
Derived
::
Scalar
)
12.0
);
// see the Taylor series of sinc(x) ~ 1 - x^2/3!, and have q.vec = v/2 * sinc(angle_half)
return
q
;
}
}
int
main
(
void
)
{
using
namespace
Eigen
;
VectorXd
x
(
10
);
x
<<
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
;
Quaterniond
q
;
Map
<
Quaterniond
>
qm
(
x
.
data
()
+
5
);
// Static vector
Vector3d
v
;
v
<<
1
,
2
,
3
;
q
=
v2q
(
v
);
qm
=
v2q
(
v
);
std
::
cout
<<
q
.
coeffs
().
transpose
()
<<
std
::
endl
;
std
::
cout
<<
qm
.
coeffs
().
transpose
()
<<
std
::
endl
;
// Dynamic matrix
Matrix
<
double
,
Dynamic
,
Dynamic
>
M
(
3
,
1
);
M
<<
1
,
2
,
3
;
q
=
v2q
(
M
);
std
::
cout
<<
q
.
coeffs
().
transpose
()
<<
std
::
endl
;
// Dynamic vector segment
x
<<
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
;
q
=
v2q
(
x
.
head
(
3
));
std
::
cout
<<
q
.
coeffs
().
transpose
()
<<
std
::
endl
;
// Map over dynamic vector
Map
<
VectorXd
>
m
(
x
.
data
(),
3
);
q
=
v2q
(
m
);
std
::
cout
<<
q
.
coeffs
().
transpose
()
<<
std
::
endl
;
// Float scalar
Vector3f
vf
;
Quaternionf
qf
;
vf
<<
1
,
2
,
3
;
qf
=
v2q
(
vf
);
std
::
cout
<<
qf
.
coeffs
().
transpose
()
<<
std
::
endl
;
// // Static assert at compile time
// Vector2d v2;
// q= v2q(v2);
// std::cout << q.coeffs().transpose() << std::endl;
}
Loading