10 #include <CTraitsTest.h> 11 #include <gtest/gtest.h> 16 #include <Eigen/Dense> 24 template class mrpt::CTraitsTest<CPose3DQuat>;
32 double x1,
double y1,
double z1,
double yaw1,
double pitch1,
33 double roll1,
double x2,
double y2,
double z2,
double yaw2,
34 double pitch2,
double roll2)
36 const CPose3D p1(x1, y1, z1, yaw1, pitch1, roll1);
37 const CPose3D p2(x2, y2, z2, yaw2, pitch2, roll2);
39 const CPose3D p1_c_p2 = p1 + p2;
40 const CPose3D p1_i_p2 = p1 - p2;
58 <<
"p1_c_p2: " << p1_c_p2 << endl
59 <<
"q1_c_p2: " << p_q1_c_q2 << endl;
68 <<
"p1_i_p2: " << p1_i_p2 << endl
69 <<
"q1_i_p2: " << p_q1_i_q2 << endl;
77 (
A.asVectorVal() - q1_c_q2.
asVectorVal()).array().abs().sum(),
86 (
A.asVectorVal() - q1_c_q2.
asVectorVal()).array().abs().sum(),
95 (
A.asVectorVal() - q1_c_q2.
asVectorVal()).array().abs().sum(),
101 double x1,
double y1,
double z1,
double yaw1,
double pitch1,
102 double roll1,
double x,
double y,
double z)
104 const CPose3D p1(x1, y1, z1, yaw1, pitch1, roll1);
118 <<
"p1: " << p1 << endl
119 <<
"q1: " << q1 << endl
120 <<
"p: " <<
p << endl
121 <<
"p1_plus_p: " << p1_plus_p << endl
122 <<
"q1_plus_p: " << q1_plus_p << endl;
132 q.quat().normalize();
135 for (
int i = 0; i < 3; i++) Y[i] = pp[i];
139 double x1,
double y1,
double z1,
double yaw1,
double pitch1,
140 double roll1,
double x,
double y,
double z)
156 for (
int i = 0; i < 7; i++) x_mean[i] = q1[i];
170 x_incrs, DUMMY, numJacobs);
172 num_df_dpose = numJacobs.
asEigen().block<3, 7>(0, 0);
173 num_df_dpoint = numJacobs.
asEigen().block<3, 3>(0, 7);
179 (df_dpoint.
asEigen() - num_df_dpoint.
asEigen()).array().abs().sum(),
181 <<
"q1: " << q1 << endl
182 <<
"p: " <<
p << endl
183 <<
"Numeric approximation of df_dpoint: " << endl
184 << num_df_dpoint.
asEigen() << endl
185 <<
"Implemented method: " << endl
192 (df_dpose.
asEigen() - num_df_dpose.
asEigen()).array().abs().sum(),
194 <<
"q1: " << q1 << endl
195 <<
"p: " <<
p << endl
196 <<
"Numeric approximation of df_dpose: " << endl
197 << num_df_dpose.
asEigen() << endl
198 <<
"Implemented method: " << endl
205 double x1,
double y1,
double z1,
double yaw1,
double pitch1,
206 double roll1,
double x,
double y,
double z)
208 const CPose3D p1(x1, y1, z1, yaw1, pitch1, roll1);
219 (p_minus_p1.
asVectorVal() - p_minus_q1.asVectorVal())
224 <<
"p_minus_p1: " << p_minus_p1 << endl
225 <<
"p_minus_q1: " << p_minus_q1 << endl;
228 0, (p_rec.
asVectorVal() -
p.asVectorVal()).array().abs().sum(),
230 <<
"p_rec: " << p_rec << endl
231 <<
"p: " <<
p << endl;
241 q.quat().normalize();
250 double x1,
double y1,
double z1,
double yaw1,
double pitch1,
251 double roll1,
double x,
double y,
double z)
265 const double qr = q1.
quat().
r();
266 const double qx = q1.
quat().
x();
267 const double qy = q1.
quat().
y();
268 const double qz = q1.
quat().
z();
269 const double Ax =
x - x1;
270 const double Ay =
y - y1;
271 const double Az =
z - z1;
272 theorical.
x = Ax + 2 * (Ay) * (qr * qz + qx * qy) -
273 2 * (Az) * (qr * qy - qx * qz) -
275 theorical.
y = Ay - 2 * (Ax) * (qr * qz - qx * qy) +
276 2 * (Az) * (qr * qx + qy * qz) -
278 theorical.
z = Az + 2 * (Ax) * (qr * qy + qx * qz) -
279 2 * (Ay) * (qr * qx - qy * qz) -
282 EXPECT_NEAR(theorical.
x, l.
x, 1e-5);
283 EXPECT_NEAR(theorical.
y, l.
y, 1e-5);
284 EXPECT_NEAR(theorical.
z, l.
z, 1e-5);
291 for (
int i = 0; i < 7; i++) x_mean[i] = q1[i];
305 x_incrs, DUMMY, numJacobs);
307 num_df_dpose = numJacobs.
block<3, 7>(0, 0);
308 num_df_dpoint = numJacobs.
block<3, 3>(0, 7);
314 (df_dpoint.
asEigen() - num_df_dpoint.
asEigen()).array().abs().sum(),
316 <<
"q1: " << q1 << endl
317 <<
"from pose: " <<
CPose3D(x1, y1, z1, yaw1, pitch1, roll1) << endl
318 <<
"p: " <<
p << endl
319 <<
"local: " << l << endl
320 <<
"Numeric approximation of df_dpoint: " << endl
321 << num_df_dpoint.
asEigen() << endl
322 <<
"Implemented method: " << endl
325 << df_dpoint - num_df_dpoint << endl;
329 (df_dpose.
asEigen() - num_df_dpose.
asEigen()).array().abs().sum(),
331 <<
"q1: " << q1 << endl
332 <<
"from pose: " <<
CPose3D(x1, y1, z1, yaw1, pitch1, roll1) << endl
333 <<
"p: " <<
p << endl
334 <<
"local: " << l << endl
335 <<
"Numeric approximation of df_dpose: " << endl
336 << num_df_dpose.
asEigen() << endl
337 <<
"Implemented method: " << endl
344 double x1,
double y1,
double z1,
double yaw1,
double pitch1,
347 const CPose3D p1(x1, y1, z1, yaw1, pitch1, roll1);
359 <<
"p1.getHomogeneousMatrixVal<CMatrixDouble44>():\n" 361 <<
"q1.getHomogeneousMatrixVal<CMatrixDouble44>():\n" 366 <<
"p1: " << p1 << endl
367 <<
"q1: " << q1 << endl
368 <<
"p1r: " << p1r << endl;
372 double x1,
double y1,
double z1,
double yaw1,
double pitch1,
375 const CPose3D p1(x1, y1, z1, yaw1, pitch1, roll1);
389 <<
"p1_inv.getHomogeneousMatrixVal<CMatrixDouble44>():\n" 391 <<
"q1_inv.getHomogeneousMatrixVal<CMatrixDouble44>():\n" 396 double x1,
double y1,
double z1,
double yaw1,
double pitch1,
399 const CPose3D p1(x1, y1, z1, yaw1, pitch1, roll1);
412 <<
"q1.getHomogeneousMatrixVal<CMatrixDouble44>():\n" 414 <<
"q2.getHomogeneousMatrixVal<CMatrixDouble44>():\n" 419 double x1,
double y1,
double z1,
double yaw1,
double pitch1,
420 double roll1,
double x,
double y,
double z)
427 EXPECT_NEAR(
x, aux.
x, 1e-7);
428 EXPECT_NEAR(
y, aux.
y, 1e-7);
429 EXPECT_NEAR(
z, aux.
z, 1e-7);
433 double x1,
double y1,
double z1,
double yaw1,
double pitch1,
434 double roll1,
double x,
double y,
double z)
436 const CPose3D p1(x1, y1, z1, yaw1, pitch1, roll1);
442 EXPECT_NEAR(pt1.
x, pt2.
x, 1e-7);
443 EXPECT_NEAR(pt1.
y, pt2.
y, 1e-7);
444 EXPECT_NEAR(pt1.
z, pt2.
z, 1e-7);
448 double x1,
double y1,
double z1,
double yaw1,
double pitch1,
449 double roll1,
double x,
double y,
double z)
451 const CPose3D p1(x1, y1, z1, yaw1, pitch1, roll1);
457 EXPECT_NEAR(pt1.
x, pt2.
x, 1e-7);
458 EXPECT_NEAR(pt1.
y, pt2.
y, 1e-7);
459 EXPECT_NEAR(pt1.
z, pt2.
z, 1e-7);
464 float gx =
x, gy =
y, gz =
z;
466 double dist, yaw,
pitch;
472 double lx2, ly2, lz2;
473 q.inverseComposePoint(gx, gy, gz, lx2, ly2, lz2);
475 EXPECT_NEAR(lx, lx2, 1e-7);
476 EXPECT_NEAR(ly, ly2, 1e-7);
477 EXPECT_NEAR(lz, lz2, 1e-7);
488 q.quat().normalize();
490 q.sphericalCoordinates(
p, Y[0], Y[1], Y[2]);
494 double x1,
double y1,
double z1,
double yaw1,
double pitch1,
495 double roll1,
double x,
double y,
double z)
511 for (
int i = 0; i < 7; i++) x_mean[i] = q1[i];
525 x_incrs, DUMMY, numJacobs);
527 num_df_dpose = numJacobs.
block<3, 7>(0, 0);
528 num_df_dpoint = numJacobs.
block<3, 3>(0, 7);
534 (df_dpoint.
asEigen() - num_df_dpoint.
asEigen()).array().abs().sum(),
536 <<
"q1: " << q1 << endl
537 <<
"p: " <<
p << endl
538 <<
"Numeric approximation of df_dpoint: " << endl
539 << num_df_dpoint.
asEigen() << endl
540 <<
"Implemented method: " << endl
547 (df_dpose.
asEigen() - num_df_dpose.
asEigen()).array().abs().sum(),
549 <<
"q1: " << q1 << endl
550 <<
"p: " <<
p << endl
551 <<
"Numeric approximation of df_dpose: " << endl
552 << num_df_dpose.
asEigen() << endl
553 <<
"Implemented method: " << endl
565 for (
int i = 0; i < 4; i++)
q[i] =
x[i];
567 for (
int i = 0; i < 4; i++) Y[i] =
q[i];
572 const CPose3D pp(0, 0, 0, yaw1, pitch1, roll1);
583 for (
int i = 0; i < 4; i++) x_mean[i] = q1[i];
594 x_incrs, DUMMY, numJacobs);
596 num_df_dpose = numJacobs.
block<4, 4>(0, 0);
602 (df_dpose.
asEigen() - num_df_dpose.
asEigen()).array().abs().sum(),
604 <<
"q1: " << q1 << endl
605 <<
"Numeric approximation of df_dpose: " << endl
606 << num_df_dpose.
asEigen() << endl
607 <<
"Implemented method: " << endl
675 test_composePointJacob(
677 test_composePointJacob(
679 test_composePointJacob(
681 test_composePointJacob(
683 test_composePointJacob(
686 test_composePointJacob(
693 test_invComposePoint(
695 test_invComposePoint(
697 test_invComposePoint(
699 test_invComposePoint(
701 test_invComposePoint(
704 test_invComposePoint(
711 test_invComposePointJacob(
713 test_invComposePointJacob(
715 test_invComposePointJacob(
717 test_invComposePointJacob(
719 test_invComposePointJacob(
721 test_invComposePointJacob(
723 test_invComposePointJacob(
725 test_invComposePointJacob(
728 test_invComposePointJacob(
735 test_composeAndInvComposePoint(
737 test_composeAndInvComposePoint(
739 test_composeAndInvComposePoint(
741 test_composeAndInvComposePoint(
743 test_composeAndInvComposePoint(
746 test_composeAndInvComposePoint(
753 test_composePoint_vs_CPose3D(
755 test_composePoint_vs_CPose3D(
757 test_composePoint_vs_CPose3D(
759 test_composePoint_vs_CPose3D(
761 test_composePoint_vs_CPose3D(
764 test_composePoint_vs_CPose3D(
771 test_invComposePoint_vs_CPose3D(
773 test_invComposePoint_vs_CPose3D(
775 test_invComposePoint_vs_CPose3D(
777 test_invComposePoint_vs_CPose3D(
780 for (
size_t i = 0; i < 10; i++)
782 std::vector<double>
v(9);
784 test_invComposePoint_vs_CPose3D(
785 v[0],
v[1],
v[2],
v[3],
v[4],
v[5],
v[6],
v[7],
v[8]);
791 test_sphericalCoords(
793 test_sphericalCoords(
795 test_sphericalCoords(
797 test_sphericalCoords(
799 test_sphericalCoords(
802 test_sphericalCoords(
void test_sphericalCoords(double x1, double y1, double z1, double yaw1, double pitch1, double roll1, double x, double y, double z)
mrpt::math::CQuaternionDouble & quat()
Read/Write access to the quaternion representing the 3D rotation.
A compile-time fixed-size numeric matrix container.
void test_composePointJacob(double x1, double y1, double z1, double yaw1, double pitch1, double roll1, double x, double y, double z)
double x
X,Y,Z coordinates.
void composePoint(double lx, double ly, double lz, double &gx, double &gy, double &gz, mrpt::math::CMatrixFixed< double, 3, 3 > *out_jacobian_df_dpoint=nullptr, mrpt::math::CMatrixFixed< double, 3, 6 > *out_jacobian_df_dpose=nullptr, mrpt::math::CMatrixFixed< double, 3, 6 > *out_jacobian_df_dse3=nullptr, bool use_small_rot_approx=false) const
An alternative, slightly more efficient way of doing with G and L being 3D points and P this 6D pose...
void test_fromYPRAndBack(double x1, double y1, double z1, double yaw1, double pitch1, double roll1)
void drawGaussian1DVector(VEC &v, const double mean=0, const double std=1)
Fills the given vector with independent, 1D-normally distributed samples.
T y() const
Return y coordinate of the quaternion.
double DEG2RAD(const double x)
Degrees to radians.
static void func_spherical_coords(const CVectorFixedDouble< 7+3 > &x, const double &dummy, CVectorFixedDouble< 3 > &Y)
GLdouble GLdouble GLdouble GLdouble q
CQuaternion< double > CQuaternionDouble
A quaternion of data type "double".
void test_copy(double x1, double y1, double z1, double yaw1, double pitch1, double roll1)
void sphericalCoordinates(const mrpt::math::TPoint3D &point, double &out_range, double &out_yaw, double &out_pitch, mrpt::math::CMatrixFixed< double, 3, 3 > *out_jacob_dryp_dpoint=nullptr, mrpt::math::CMatrixFixed< double, 3, 7 > *out_jacob_dryp_dpose=nullptr) const
Computes the spherical coordinates of a 3D point as seen from the 6D pose specified by this object...
static void func_normalizeJacob(const CVectorFixedDouble< 4 > &x, const double &dummy, CVectorFixedDouble< 4 > &Y)
static void func_compose_point(const CVectorFixedDouble< 7+3 > &x, const double &dummy, CVectorFixedDouble< 3 > &Y)
void composePoint(const double lx, const double ly, const double lz, double &gx, double &gy, double &gz, mrpt::math::CMatrixFixed< double, 3, 3 > *out_jacobian_df_dpoint=nullptr, mrpt::math::CMatrixFixed< double, 3, 7 > *out_jacobian_df_dpose=nullptr) const
Computes the 3D point G such as .
T square(const T x)
Inline function for the square of a number.
This base provides a set of functions for maths stuff.
T r() const
Return r coordinate of the quaternion.
void inverseComposePoint(const double gx, const double gy, const double gz, double &lx, double &ly, double &lz, mrpt::math::CMatrixFixed< double, 3, 3 > *out_jacobian_df_dpoint=nullptr, mrpt::math::CMatrixFixed< double, 3, 7 > *out_jacobian_df_dpose=nullptr) const
Computes the 3D point L such as .
void inverseComposePoint(const double gx, const double gy, const double gz, double &lx, double &ly, double &lz, mrpt::math::CMatrixFixed< double, 3, 3 > *out_jacobian_df_dpoint=nullptr, mrpt::math::CMatrixFixed< double, 3, 6 > *out_jacobian_df_dpose=nullptr, mrpt::math::CMatrixFixed< double, 3, 6 > *out_jacobian_df_dse3=nullptr) const
Computes the 3D point L such as .
auto block(int start_row, int start_col)
non-const block(): Returns an Eigen::Block reference to the block
void getAsQuaternion(mrpt::math::CQuaternionDouble &q, mrpt::math::CMatrixFixed< double, 4, 3 > *out_dq_dr=nullptr) const
Returns the quaternion associated to the rotation of this object (NOTE: XYZ translation is ignored) ...
void sphericalCoordinates(const mrpt::math::TPoint3D &point, double &out_range, double &out_yaw, double &out_pitch) const
Computes the spherical coordinates of a 3D point as seen from the 6D pose specified by this object...
void test_invComposePoint(double x1, double y1, double z1, double yaw1, double pitch1, double roll1, double x, double y, double z)
void test_composeAndInvComposePoint(double x1, double y1, double z1, double yaw1, double pitch1, double roll1, double x, double y, double z)
double x() const
Common members of all points & poses classes.
A class used to store a 3D pose as a translation (x,y,z) and a quaternion (qr,qx,qy,qz).
static void func_inv_compose_point(const CVectorFixedDouble< 7+3 > &x, const double &dummy, CVectorFixedDouble< 3 > &Y)
A class used to store a 3D point.
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
void estimateJacobian(const VECTORLIKE &x, const std::function< void(const VECTORLIKE &x, const USERPARAM &y, VECTORLIKE3 &out)> &functor, const VECTORLIKE2 &increments, const USERPARAM &userParam, MATRIXLIKE &out_Jacobian)
Estimate the Jacobian of a multi-dimensional function around a point "x", using finite differences of...
void test_invComposePointJacob(double x1, double y1, double z1, double yaw1, double pitch1, double roll1, double x, double y, double z)
void test_compose(double x1, double y1, double z1, double yaw1, double pitch1, double roll1, double x2, double y2, double z2, double yaw2, double pitch2, double roll2)
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
T x() const
Return x coordinate of the quaternion.
void normalizationJacobian(MATRIXLIKE &J) const
Calculate the 4x4 Jacobian of the normalization operation of this quaternion.
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
void test_invComposePoint_vs_CPose3D(double x1, double y1, double z1, double yaw1, double pitch1, double roll1, double x, double y, double z)
void test_normalizeJacob(double yaw1, double pitch1, double roll1)
EIGEN_MAP asEigen()
Get as an Eigen-compatible Eigen::Map object.
void test_composePoint_vs_CPose3D(double x1, double y1, double z1, double yaw1, double pitch1, double roll1, double x, double y, double z)
MATRIX44 getHomogeneousMatrixVal() const
Returns the corresponding 4x4 homogeneous transformation matrix for the point(translation) or pose (t...
A quaternion, which can represent a 3D rotation as pair , with a real part "r" and a 3D vector ...
T z() const
Return z coordinate of the quaternion.
CRandomGenerator & getRandomGenerator()
A static instance of a CRandomGenerator class, for use in single-thread applications.
EIGEN_MAP asEigen()
Get as an Eigen-compatible Eigen::Map object.
void test_unaryInverse(double x1, double y1, double z1, double yaw1, double pitch1, double roll1)
void test_composePoint(double x1, double y1, double z1, double yaw1, double pitch1, double roll1, double x, double y, double z)
TEST_F(Pose3DQuatTests, FromYPRAndBack)
vector_t asVectorVal() const
Return the pose or point as a 1xN vector with all the components (see derived classes for each implem...
#define MRPT_UNUSED_PARAM(a)
Determines whether this is an X86 or AMD64 platform.