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> std::ostream &
operator<<(std::ostream &os,
const Eigen::Quaternion<Type> &q)
53 return os <<
"qw: " << q.w() <<
" ; qx: " << q.x() <<
" ; qy: " << q.y() <<
" ; qz: " << q.z();
56 template <
typename Type> std::ostream &
operator<<(std::ostream &os,
const Eigen::AngleAxis<Type> &aa)
58 return os <<
"angle: " << aa.angle() <<
" ; axis: " << aa.axis()(0) <<
" ; " << aa.axis()(1) <<
" ; " << aa.axis()(2)
59 <<
" ; thetau: " << aa.angle() * aa.axis()(0) <<
" ; " << aa.angle() * aa.axis()(1) <<
" ; "
60 << aa.angle() * aa.axis()(2);
64 TEST_CASE(
"vpMatrix <--> Eigen::MatrixXd/Matrix3Xd conversion",
"[eigen_conversion]")
67 for (
unsigned int i = 0; i < visp_m.size(); i++) {
72 Eigen::MatrixXd eigen_m;
74 std::cout <<
"Eigen MatrixXd:\n" << eigen_m << std::endl;
78 std::cout <<
"ViSP vpMatrix:\n" << visp_m2 << std::endl;
80 REQUIRE(visp_m == visp_m2);
81 std::cout << std::endl;
84 Eigen::Matrix3Xd eigen_m;
86 std::cout <<
"Eigen Matrix3Xd:\n" << eigen_m << std::endl;
90 std::cout <<
"ViSP vpMatrix:\n" << visp_m2 << std::endl;
92 REQUIRE(visp_m == visp_m2);
93 std::cout << std::endl;
97 TEST_CASE(
"Eigen::MatrixXd <--> vpMatrix conversion",
"[eigen_conversion]")
99 Eigen::MatrixXd eigen_m(3, 5);
100 #if (VP_VERSION_INT(EIGEN_WORLD_VERSION, EIGEN_MAJOR_VERSION, EIGEN_MINOR_VERSION) < 0x030300)
101 for (Eigen::DenseIndex i = 0; i < eigen_m.rows(); i++) {
102 for (Eigen::DenseIndex j = 0; j < eigen_m.cols(); j++) {
104 for (Eigen::Index i = 0; i < eigen_m.rows(); i++) {
105 for (Eigen::Index j = 0; j < eigen_m.cols(); j++) {
107 eigen_m(i, j) =
static_cast<double>(i * eigen_m.cols() + j);
110 std::cout <<
"Eigen Matrix (row major: " << eigen_m.IsRowMajor <<
"):\n" << eigen_m << std::endl;
114 std::cout <<
"ViSP vpMatrix:\n" << visp_m << std::endl;
116 Eigen::MatrixXd eigen_m2;
118 std::cout <<
"Eigen MatrixXd (row major: " << eigen_m2.IsRowMajor <<
"):\n" << eigen_m2 << std::endl;
122 REQUIRE(visp_m == visp_m2);
123 std::cout << std::endl;
126 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]")
157 Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> eigen_m(3, 5);
158 #if (VP_VERSION_INT(EIGEN_WORLD_VERSION, EIGEN_MAJOR_VERSION, EIGEN_MINOR_VERSION) < 0x030300)
159 for (Eigen::DenseIndex i = 0; i < eigen_m.rows(); i++) {
160 for (Eigen::DenseIndex j = 0; j < eigen_m.cols(); j++) {
162 for (Eigen::Index i = 0; i < eigen_m.rows(); i++) {
163 for (Eigen::Index j = 0; j < eigen_m.cols(); j++) {
165 eigen_m(i, j) =
static_cast<double>(i * eigen_m.cols() + j);
168 std::cout <<
"Eigen Matrix (RowMajor):\n" << eigen_m << std::endl;
172 std::cout <<
"ViSP vpMatrix:\n" << visp_m << std::endl;
174 Eigen::MatrixXd eigen_m2;
176 std::cout <<
"Eigen MatrixXd (row major: " << eigen_m2.IsRowMajor <<
"):\n" << eigen_m2 << std::endl;
180 REQUIRE(visp_m == visp_m2);
181 std::cout << std::endl;
184 TEST_CASE(
"Eigen::Matrix<double, Dynamic, Dynamic, ColMajor> <--> vpMatrix conversion",
"[eigen_conversion]")
186 Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor> eigen_m(3, 5);
187 #if (VP_VERSION_INT(EIGEN_WORLD_VERSION, EIGEN_MAJOR_VERSION, EIGEN_MINOR_VERSION) < 0x030300)
188 for (Eigen::DenseIndex i = 0; i < eigen_m.rows(); i++) {
189 for (Eigen::DenseIndex j = 0; j < eigen_m.cols(); j++) {
191 for (Eigen::Index i = 0; i < eigen_m.rows(); i++) {
192 for (Eigen::Index j = 0; j < eigen_m.cols(); j++) {
194 eigen_m(i, j) =
static_cast<double>(i * eigen_m.cols() + j);
197 std::cout <<
"Eigen Matrix (ColMajor):\n" << eigen_m << std::endl;
201 std::cout <<
"ViSP vpMatrix:\n" << visp_m << std::endl;
203 Eigen::MatrixXd eigen_m2;
205 std::cout <<
"Eigen MatrixXd (row major: " << eigen_m2.IsRowMajor <<
"):\n" << eigen_m2 << std::endl;
209 REQUIRE(visp_m == visp_m2);
210 std::cout << std::endl;
213 TEST_CASE(
"vpHomogeneousMatrix <--> Eigen::Matrix4d conversion",
"[eigen_conversion]")
216 Eigen::Matrix4d eigen_cMo;
218 std::cout <<
"Eigen Matrix4d cMo:\n" << eigen_cMo << std::endl;
222 std::cout <<
"ViSP vpHomogeneousMatrix cMo:\n" << visp_cMo2 << std::endl;
223 REQUIRE(visp_cMo == visp_cMo2);
224 std::cout << std::endl;
227 TEST_CASE(
"vpHomogeneousMatrix <--> Eigen::Matrix4f + double casting conversion",
"[eigen_conversion]")
230 Eigen::Matrix4d eigen_cMo_tmp;
232 Eigen::Matrix4f eigen_cMo = eigen_cMo_tmp.cast<
float>();
233 std::cout <<
"Eigen Matrix4f cMo:\n" << eigen_cMo << std::endl;
237 std::cout <<
"ViSP vpHomogeneousMatrix cMo:\n" << visp_cMo2 << std::endl;
238 REQUIRE(visp_cMo == visp_cMo2);
239 std::cout << std::endl;
242 TEST_CASE(
"vpQuaternionVector <--> Eigen::Quaternionf conversion",
"[eigen_conversion]")
245 Eigen::Quaternionf eigen_quaternion;
247 std::cout <<
"Eigen quaternion: " << eigen_quaternion << std::endl;
251 std::cout <<
"ViSP quaternion: " << visp_quaternion2.
t() << std::endl;
252 REQUIRE(visp_quaternion == visp_quaternion2);
253 std::cout << std::endl;
256 TEST_CASE(
"vpThetaUVector <--> Eigen::AngleAxisf conversion",
"[eigen_conversion]")
259 Eigen::AngleAxisf eigen_angle_axis;
261 std::cout <<
"Eigen AngleAxis: " << eigen_angle_axis << std::endl;
265 std::cout <<
"ViSP AngleAxis: " << visp_thetau2.
t() << std::endl;
266 REQUIRE(visp_thetau == visp_thetau2);
267 std::cout << std::endl;
270 TEST_CASE(
"vpColVector <--> Eigen::VectorXd conversion",
"[eigen_conversion]")
274 Eigen::VectorXd eigen_col;
276 std::cout <<
"Eigen VectorXd: " << eigen_col.transpose() << std::endl;
280 std::cout <<
"ViSP vpColVector: " << visp_col2.
t() << std::endl;
281 REQUIRE(visp_col == visp_col2);
282 std::cout << std::endl;
285 TEST_CASE(
"vpRowVector <--> Eigen::RowVectorXd conversion",
"[eigen_conversion]")
289 Eigen::RowVectorXd eigen_row;
291 std::cout <<
"Eigen RowVectorXd: " << eigen_row << std::endl;
295 std::cout <<
"ViSP vpRowVector: " << visp_row2 << std::endl;
296 REQUIRE(visp_row == visp_row2);
297 std::cout << std::endl;
300 TEST_CASE(
"Eigen::RowVector4d <--> vpRowVector conversion",
"[eigen_conversion]")
302 Eigen::RowVector4d eigen_row;
303 eigen_row << 9, 8, 7, 6;
306 std::cout <<
"ViSP vpRowVector: " << visp_row << std::endl;
308 Eigen::RowVector4d eigen_row2;
310 std::cout <<
"Eigen RowVector4d: " << eigen_row2 << std::endl;
314 REQUIRE(visp_row == visp_row2);
315 std::cout << std::endl;
318 TEST_CASE(
"vpRowVector <--> Eigen::RowVector4d conversion",
"[eigen_conversion]")
322 Eigen::RowVector4d eigen_row;
324 std::cout <<
"Eigen RowVector4d: " << eigen_row << std::endl;
328 std::cout <<
"ViSP vpRowVector: " << visp_row2 << std::endl;
329 REQUIRE(visp_row == visp_row2);
330 std::cout << std::endl;
333 int main(
int argc,
char *argv[])
335 Catch::Session session;
338 session.applyCommandLine(argc, argv);
340 int numFailed = session.run();
348 int main() {
return EXIT_SUCCESS; }
friend std::ostream & operator<<(std::ostream &s, const vpArray2D< Type > &A)
Implementation of column vector and the associated operations.
Implementation of an homogeneous matrix and operations on such kind of matrices.
Implementation of a matrix and operations on matrices.
Implementation of a rotation vector as quaternion angle minimal representation.
Implementation of row vector and the associated operations.
Implementation of a rotation vector as axis-angle minimal representation.
void visp2eigen(const vpMatrix &src, Eigen::MatrixBase< Derived > &dst)
VISP_EXPORT void eigen2visp(const Eigen::MatrixXd &src, vpMatrix &dst)