42 #include <visp3/core/vpConfig.h> 43 #include <visp3/core/vpEigenConversion.h> 45 #if defined(VISP_HAVE_EIGEN3) && defined(VISP_HAVE_CATCH2) 46 #define CATCH_CONFIG_RUNNER 51 template<
typename Type>
52 std::ostream &operator<<(std::ostream &os, const Eigen::Quaternion<Type> &q) {
53 return os <<
"qw: " << q.w() <<
" ; qx: " << q.x() <<
" ; qy: " 54 << q.y() <<
" ; qz: " << q.z();
57 template<
typename Type>
58 std::ostream &operator<<(std::ostream &os, const Eigen::AngleAxis<Type> &aa) {
59 return os <<
"angle: " << aa.angle() <<
" ; axis: " << aa.axis()(0)
60 <<
" ; " << aa.axis()(1) <<
" ; " << aa.axis()(2)
61 <<
" ; thetau: " << aa.angle()*aa.axis()(0)
62 <<
" ; " << aa.angle()*aa.axis()(1)
63 <<
" ; " << aa.angle()*aa.axis()(2);
67 TEST_CASE(
"vpMatrix <--> Eigen::MatrixXd/Matrix3Xd conversion",
"[eigen_conversion]") {
69 for (
unsigned int i = 0; i < visp_m.size(); i++) {
74 Eigen::MatrixXd eigen_m;
76 std::cout <<
"Eigen MatrixXd:\n" << eigen_m << std::endl;
80 std::cout <<
"ViSP vpMatrix:\n" << visp_m2 << std::endl;
82 REQUIRE(visp_m == visp_m2);
83 std::cout << std::endl;
86 Eigen::Matrix3Xd eigen_m;
88 std::cout <<
"Eigen Matrix3Xd:\n" << eigen_m << std::endl;
92 std::cout <<
"ViSP vpMatrix:\n" << visp_m2 << std::endl;
94 REQUIRE(visp_m == visp_m2);
95 std::cout << std::endl;
99 TEST_CASE(
"Eigen::MatrixXd <--> vpMatrix conversion",
"[eigen_conversion]") {
100 Eigen::MatrixXd eigen_m(3, 5);
101 #if (VP_VERSION_INT(EIGEN_WORLD_VERSION, EIGEN_MAJOR_VERSION, EIGEN_MINOR_VERSION) < 0x030300) 102 for (Eigen::DenseIndex i = 0; i < eigen_m.rows(); i++) {
103 for (Eigen::DenseIndex j = 0; j < eigen_m.cols(); j++) {
105 for (Eigen::Index i = 0; i < eigen_m.rows(); i++) {
106 for (Eigen::Index j = 0; j < eigen_m.cols(); j++) {
108 eigen_m(i, j) =
static_cast<double>(i * eigen_m.cols() + j);
111 std::cout <<
"Eigen Matrix (row major: " << eigen_m.IsRowMajor <<
"):\n" << eigen_m << std::endl;
115 std::cout <<
"ViSP vpMatrix:\n" << visp_m << std::endl;
117 Eigen::MatrixXd eigen_m2;
119 std::cout <<
"Eigen MatrixXd (row major: " << eigen_m2.IsRowMajor <<
"):\n" << eigen_m2 << std::endl;
123 REQUIRE(visp_m == visp_m2);
124 std::cout << std::endl;
127 TEST_CASE(
"Eigen::MatrixX4d <--> vpMatrix conversion",
"[eigen_conversion]") {
128 Eigen::MatrixX4d eigen_m(2, 4);
129 #if (VP_VERSION_INT(EIGEN_WORLD_VERSION, EIGEN_MAJOR_VERSION, EIGEN_MINOR_VERSION) < 0x030300) 130 for (Eigen::DenseIndex i = 0; i < eigen_m.rows(); i++) {
131 for (Eigen::DenseIndex j = 0; j < eigen_m.cols(); j++) {
133 for (Eigen::Index i = 0; i < eigen_m.rows(); i++) {
134 for (Eigen::Index j = 0; j < eigen_m.cols(); j++) {
136 eigen_m(i, j) =
static_cast<double>(i * eigen_m.cols() + j);
139 std::cout <<
"Eigen MatrixX4d (row major: " << eigen_m.IsRowMajor <<
"):\n" << eigen_m << std::endl;
143 std::cout <<
"ViSP vpMatrix:\n" << visp_m << std::endl;
145 Eigen::MatrixX4d eigen_m2;
147 std::cout <<
"Eigen MatrixX4d (row major: " << eigen_m2.IsRowMajor <<
"):\n" << eigen_m2 << std::endl;
151 REQUIRE(visp_m == visp_m2);
152 std::cout << std::endl;
155 TEST_CASE(
"Eigen::Matrix<double, Dynamic, Dynamic, RowMajor> <--> vpMatrix conversion",
"[eigen_conversion]") {
156 Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> eigen_m(3, 5);
157 #if (VP_VERSION_INT(EIGEN_WORLD_VERSION, EIGEN_MAJOR_VERSION, EIGEN_MINOR_VERSION) < 0x030300) 158 for (Eigen::DenseIndex i = 0; i < eigen_m.rows(); i++) {
159 for (Eigen::DenseIndex j = 0; j < eigen_m.cols(); j++) {
161 for (Eigen::Index i = 0; i < eigen_m.rows(); i++) {
162 for (Eigen::Index j = 0; j < eigen_m.cols(); j++) {
164 eigen_m(i, j) =
static_cast<double>(i * eigen_m.cols() + j);
167 std::cout <<
"Eigen Matrix (RowMajor):\n" << eigen_m << std::endl;
171 std::cout <<
"ViSP vpMatrix:\n" << visp_m << std::endl;
173 Eigen::MatrixXd eigen_m2;
175 std::cout <<
"Eigen MatrixXd (row major: " << eigen_m2.IsRowMajor <<
"):\n" << eigen_m2 << std::endl;
179 REQUIRE(visp_m == visp_m2);
180 std::cout << std::endl;
183 TEST_CASE(
"Eigen::Matrix<double, Dynamic, Dynamic, ColMajor> <--> vpMatrix conversion",
"[eigen_conversion]") {
184 Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor> eigen_m(3, 5);
185 #if (VP_VERSION_INT(EIGEN_WORLD_VERSION, EIGEN_MAJOR_VERSION, EIGEN_MINOR_VERSION) < 0x030300) 186 for (Eigen::DenseIndex i = 0; i < eigen_m.rows(); i++) {
187 for (Eigen::DenseIndex j = 0; j < eigen_m.cols(); j++) {
189 for (Eigen::Index i = 0; i < eigen_m.rows(); i++) {
190 for (Eigen::Index j = 0; j < eigen_m.cols(); j++) {
192 eigen_m(i, j) =
static_cast<double>(i * eigen_m.cols() + j);
195 std::cout <<
"Eigen Matrix (ColMajor):\n" << eigen_m << std::endl;
199 std::cout <<
"ViSP vpMatrix:\n" << visp_m << std::endl;
201 Eigen::MatrixXd eigen_m2;
203 std::cout <<
"Eigen MatrixXd (row major: " << eigen_m2.IsRowMajor <<
"):\n" << eigen_m2 << std::endl;
207 REQUIRE(visp_m == visp_m2);
208 std::cout << std::endl;
211 TEST_CASE(
"vpHomogeneousMatrix <--> Eigen::Matrix4d conversion",
"[eigen_conversion]") {
213 Eigen::Matrix4d eigen_cMo;
215 std::cout <<
"Eigen Matrix4d cMo:\n" << eigen_cMo << std::endl;
219 std::cout <<
"ViSP vpHomogeneousMatrix cMo:\n" << visp_cMo2 << std::endl;
220 REQUIRE(visp_cMo == visp_cMo2);
221 std::cout << std::endl;
224 TEST_CASE(
"vpHomogeneousMatrix <--> Eigen::Matrix4f + double casting conversion",
"[eigen_conversion]") {
226 Eigen::Matrix4d eigen_cMo_tmp;
228 Eigen::Matrix4f eigen_cMo = eigen_cMo_tmp.cast<
float>();
229 std::cout <<
"Eigen Matrix4f cMo:\n" << eigen_cMo << std::endl;
233 std::cout <<
"ViSP vpHomogeneousMatrix cMo:\n" << visp_cMo2 << std::endl;
234 REQUIRE(visp_cMo == visp_cMo2);
235 std::cout << std::endl;
238 TEST_CASE(
"vpQuaternionVector <--> Eigen::Quaternionf conversion",
"[eigen_conversion]") {
240 Eigen::Quaternionf eigen_quaternion;
242 std::cout <<
"Eigen quaternion: " << eigen_quaternion << std::endl;
246 std::cout <<
"ViSP quaternion: " << visp_quaternion2.
t() << std::endl;
247 REQUIRE(visp_quaternion == visp_quaternion2);
248 std::cout << std::endl;
251 TEST_CASE(
"vpThetaUVector <--> Eigen::AngleAxisf conversion",
"[eigen_conversion]") {
253 Eigen::AngleAxisf eigen_angle_axis;
255 std::cout <<
"Eigen AngleAxis: " << eigen_angle_axis << std::endl;
259 std::cout <<
"ViSP AngleAxis: " << visp_thetau2.
t() << std::endl;
260 REQUIRE(visp_thetau == visp_thetau2);
261 std::cout << std::endl;
264 TEST_CASE(
"vpColVector <--> Eigen::VectorXd conversion",
"[eigen_conversion]") {
267 Eigen::VectorXd eigen_col;
269 std::cout <<
"Eigen VectorXd: " << eigen_col.transpose() << std::endl;
273 std::cout <<
"ViSP vpColVector: " << visp_col2.
t() << std::endl;
274 REQUIRE(visp_col == visp_col2);
275 std::cout << std::endl;
278 TEST_CASE(
"vpRowVector <--> Eigen::RowVectorXd conversion",
"[eigen_conversion]") {
281 Eigen::RowVectorXd eigen_row;
283 std::cout <<
"Eigen RowVectorXd: " << eigen_row << std::endl;
287 std::cout <<
"ViSP vpRowVector: " << visp_row2 << std::endl;
288 REQUIRE(visp_row == visp_row2);
289 std::cout << std::endl;
292 TEST_CASE(
"Eigen::RowVector4d <--> vpRowVector conversion",
"[eigen_conversion]") {
293 Eigen::RowVector4d eigen_row;
294 eigen_row << 9, 8, 7, 6;
297 std::cout <<
"ViSP vpRowVector: " << visp_row << std::endl;
299 Eigen::RowVector4d eigen_row2;
301 std::cout <<
"Eigen RowVector4d: " << eigen_row2 << std::endl;
305 REQUIRE(visp_row == visp_row2);
306 std::cout << std::endl;
309 TEST_CASE(
"vpRowVector <--> Eigen::RowVector4d conversion",
"[eigen_conversion]") {
312 Eigen::RowVector4d eigen_row;
314 std::cout <<
"Eigen RowVector4d: " << eigen_row << std::endl;
318 std::cout <<
"ViSP vpRowVector: " << visp_row2 << std::endl;
319 REQUIRE(visp_row == visp_row2);
320 std::cout << std::endl;
323 int main(
int argc,
char *argv[])
325 Catch::Session session;
328 session.applyCommandLine(argc, argv);
330 int numFailed = session.run();
Implementation of a matrix and operations on matrices.
VISP_EXPORT void eigen2visp(const Eigen::MatrixXd &src, vpMatrix &dst)
Implementation of an homogeneous matrix and operations on such kind of matrices.
Implementation of row vector and the associated operations.
Implementation of a rotation vector as quaternion angle minimal representation.
void visp2eigen(const vpMatrix &src, Eigen::MatrixBase< Derived > &dst)
Implementation of column vector and the associated operations.
Implementation of a rotation vector as axis-angle minimal representation.