14 #include <CTraitsTest.h> 15 #include <gtest/gtest.h> 23 template class mrpt::CTraitsTest<CPose3DQuat>;
31 double x1,
double y1,
double z1,
double yaw1,
double pitch1,
32 double roll1,
double x2,
double y2,
double z2,
double yaw2,
33 double pitch2,
double roll2)
35 const CPose3D p1(x1, y1, z1, yaw1, pitch1, roll1);
36 const CPose3D p2(x2, y2, z2, yaw2, pitch2, roll2);
38 const CPose3D p1_c_p2 = p1 + p2;
39 const CPose3D p1_i_p2 = p1 - p2;
56 <<
"p1_c_p2: " << p1_c_p2 << endl
57 <<
"q1_c_p2: " << p_q1_c_q2 << endl;
65 <<
"p1_i_p2: " << p1_i_p2 << endl
66 <<
"q1_i_p2: " << p_q1_i_q2 << endl;
104 double x1,
double y1,
double z1,
double yaw1,
double pitch1,
105 double roll1,
double x,
double y,
double z)
107 const CPose3D p1(x1, y1, z1, yaw1, pitch1, roll1);
120 <<
"p1: " << p1 << endl
121 <<
"q1: " << q1 << endl
122 <<
"p: " <<
p << endl
123 <<
"p1_plus_p: " << p1_plus_p << endl
124 <<
"q1_plus_p: " << q1_plus_p << endl;
133 q.quat().normalize();
136 for (
int i = 0; i < 3; i++) Y[i] = pp[i];
140 double x1,
double y1,
double z1,
double yaw1,
double pitch1,
141 double roll1,
double x,
double y,
double z)
157 for (
int i = 0; i < 7; i++) x_mean[i] = q1[i];
164 x_incrs.assign(1e-7);
167 x_mean, std::function<
void(
170 x_incrs, DUMMY, numJacobs);
172 numJacobs.extractMatrix(0, 0, num_df_dpose);
173 numJacobs.extractMatrix(0, 7, num_df_dpoint);
177 EXPECT_NEAR(0, (df_dpoint - num_df_dpoint).array().abs().
sum(), 3e-3)
178 <<
"q1: " << q1 << endl
179 <<
"p: " <<
p << endl
180 <<
"Numeric approximation of df_dpoint: " << endl
181 << num_df_dpoint << endl
182 <<
"Implemented method: " << endl
185 << df_dpoint - num_df_dpoint << endl;
187 EXPECT_NEAR(0, (df_dpose - num_df_dpose).array().abs().
sum(), 3e-3)
188 <<
"q1: " << q1 << endl
189 <<
"p: " <<
p << endl
190 <<
"Numeric approximation of df_dpose: " << endl
191 << num_df_dpose << endl
192 <<
"Implemented method: " << endl
195 << df_dpose - num_df_dpose << endl;
199 double x1,
double y1,
double z1,
double yaw1,
double pitch1,
200 double roll1,
double x,
double y,
double z)
202 const CPose3D p1(x1, y1, z1, yaw1, pitch1, roll1);
217 <<
"p_minus_p1: " << p_minus_p1 << endl
218 <<
"p_minus_q1: " << p_minus_q1 << endl;
224 <<
"p_rec: " << p_rec << endl
225 <<
"p: " <<
p << endl;
234 q.quat().normalize();
243 double x1,
double y1,
double z1,
double yaw1,
double pitch1,
244 double roll1,
double x,
double y,
double z)
258 const double qr = q1.
quat().
r();
259 const double qx = q1.
quat().
x();
260 const double qy = q1.
quat().
y();
261 const double qz = q1.
quat().
z();
262 const double Ax =
x - x1;
263 const double Ay =
y - y1;
264 const double Az =
z - z1;
265 theorical.
x = Ax + 2 * (Ay) * (qr * qz + qx * qy) -
266 2 * (Az) * (qr * qy - qx * qz) -
268 theorical.
y = Ay - 2 * (Ax) * (qr * qz - qx * qy) +
269 2 * (Az) * (qr * qx + qy * qz) -
271 theorical.
z = Az + 2 * (Ax) * (qr * qy + qx * qz) -
272 2 * (Ay) * (qr * qx - qy * qz) -
275 EXPECT_NEAR(theorical.
x, l.
x, 1e-5);
276 EXPECT_NEAR(theorical.
y, l.
y, 1e-5);
277 EXPECT_NEAR(theorical.
z, l.
z, 1e-5);
284 for (
int i = 0; i < 7; i++) x_mean[i] = q1[i];
291 x_incrs.assign(1e-7);
294 x_mean, std::function<
void(
297 x_incrs, DUMMY, numJacobs);
299 numJacobs.extractMatrix(0, 0, num_df_dpose);
300 numJacobs.extractMatrix(0, 7, num_df_dpoint);
304 EXPECT_NEAR(0, (df_dpoint - num_df_dpoint).array().abs().
sum(), 3e-3)
305 <<
"q1: " << q1 << endl
306 <<
"from pose: " <<
CPose3D(x1, y1, z1, yaw1, pitch1, roll1) << endl
307 <<
"p: " <<
p << endl
308 <<
"local: " << l << endl
309 <<
"Numeric approximation of df_dpoint: " << endl
310 << num_df_dpoint << endl
311 <<
"Implemented method: " << endl
314 << df_dpoint - num_df_dpoint << endl;
316 EXPECT_NEAR(0, (df_dpose - num_df_dpose).array().abs().
sum(), 3e-3)
317 <<
"q1: " << q1 << endl
318 <<
"from pose: " <<
CPose3D(x1, y1, z1, yaw1, pitch1, roll1) << endl
319 <<
"p: " <<
p << endl
320 <<
"local: " << l << endl
321 <<
"Numeric approximation of df_dpose: " << endl
322 << num_df_dpose << endl
323 <<
"Implemented method: " << endl
326 << df_dpose - num_df_dpose << endl;
330 double x1,
double y1,
double z1,
double yaw1,
double pitch1,
333 const CPose3D p1(x1, y1, z1, yaw1, pitch1, roll1);
344 <<
"p1.getHomogeneousMatrixVal<CMatrixDouble44>():\n" 346 <<
"q1.getHomogeneousMatrixVal<CMatrixDouble44>():\n" 352 <<
"p1: " << p1 << endl
353 <<
"q1: " << q1 << endl
354 <<
"p1r: " << p1r << endl;
358 double x1,
double y1,
double z1,
double yaw1,
double pitch1,
361 const CPose3D p1(x1, y1, z1, yaw1, pitch1, roll1);
374 <<
"p1_inv.getHomogeneousMatrixVal<CMatrixDouble44>():\n" 376 <<
"q1_inv.getHomogeneousMatrixVal<CMatrixDouble44>():\n" 381 double x1,
double y1,
double z1,
double yaw1,
double pitch1,
384 const CPose3D p1(x1, y1, z1, yaw1, pitch1, roll1);
396 <<
"q1.getHomogeneousMatrixVal<CMatrixDouble44>():\n" 398 <<
"q2.getHomogeneousMatrixVal<CMatrixDouble44>():\n" 403 double x1,
double y1,
double z1,
double yaw1,
double pitch1,
404 double roll1,
double x,
double y,
double z)
411 EXPECT_NEAR(
x, aux.
x, 1e-7);
412 EXPECT_NEAR(
y, aux.
y, 1e-7);
413 EXPECT_NEAR(
z, aux.
z, 1e-7);
417 double x1,
double y1,
double z1,
double yaw1,
double pitch1,
418 double roll1,
double x,
double y,
double z)
420 const CPose3D p1(x1, y1, z1, yaw1, pitch1, roll1);
426 EXPECT_NEAR(pt1.
x, pt2.
x, 1e-7);
427 EXPECT_NEAR(pt1.
y, pt2.
y, 1e-7);
428 EXPECT_NEAR(pt1.
z, pt2.
z, 1e-7);
432 double x1,
double y1,
double z1,
double yaw1,
double pitch1,
433 double roll1,
double x,
double y,
double z)
435 const CPose3D p1(x1, y1, z1, yaw1, pitch1, roll1);
441 EXPECT_NEAR(pt1.
x, pt2.
x, 1e-7);
442 EXPECT_NEAR(pt1.
y, pt2.
y, 1e-7);
443 EXPECT_NEAR(pt1.
z, pt2.
z, 1e-7);
448 float gx =
x, gy =
y, gz =
z;
450 double dist, yaw,
pitch;
456 double lx2, ly2, lz2;
457 q.inverseComposePoint(gx, gy, gz, lx2, ly2, lz2);
459 EXPECT_NEAR(lx, lx2, 1e-7);
460 EXPECT_NEAR(ly, ly2, 1e-7);
461 EXPECT_NEAR(lz, lz2, 1e-7);
471 q.quat().normalize();
473 q.sphericalCoordinates(
p, Y[0], Y[1], Y[2]);
477 double x1,
double y1,
double z1,
double yaw1,
double pitch1,
478 double roll1,
double x,
double y,
double z)
494 for (
int i = 0; i < 7; i++) x_mean[i] = q1[i];
501 x_incrs.assign(1e-7);
504 x_mean, std::function<
void(
507 x_incrs, DUMMY, numJacobs);
509 numJacobs.extractMatrix(0, 0, num_df_dpose);
510 numJacobs.extractMatrix(0, 7, num_df_dpoint);
514 EXPECT_NEAR(0, (df_dpoint - num_df_dpoint).array().abs().
sum(), 3e-3)
515 <<
"q1: " << q1 << endl
516 <<
"p: " <<
p << endl
517 <<
"Numeric approximation of df_dpoint: " << endl
518 << num_df_dpoint << endl
519 <<
"Implemented method: " << endl
522 << df_dpoint - num_df_dpoint << endl;
524 EXPECT_NEAR(0, (df_dpose - num_df_dpose).array().abs().
sum(), 3e-3)
525 <<
"q1: " << q1 << endl
526 <<
"p: " <<
p << endl
527 <<
"Numeric approximation of df_dpose: " << endl
528 << num_df_dpose << endl
529 <<
"Implemented method: " << endl
532 << df_dpose - num_df_dpose << endl;
540 for (
int i = 0; i < 4; i++)
q[i] =
x[i];
542 for (
int i = 0; i < 4; i++) Y[i] =
q[i];
547 const CPose3D pp(0, 0, 0, yaw1, pitch1, roll1);
558 for (
int i = 0; i < 4; i++) x_mean[i] = q1[i];
562 x_incrs.assign(1e-5);
565 x_mean, std::function<
void(
568 x_incrs, DUMMY, numJacobs);
570 numJacobs.extractMatrix(0, 0, num_df_dpose);
574 EXPECT_NEAR(0, (df_dpose - num_df_dpose).array().abs().
sum(), 3e-3)
575 <<
"q1: " << q1 << endl
576 <<
"Numeric approximation of df_dpose: " << endl
577 << num_df_dpose << endl
578 <<
"Implemented method: " << endl
581 << df_dpose - num_df_dpose << endl;
646 test_composePointJacob(
648 test_composePointJacob(
650 test_composePointJacob(
652 test_composePointJacob(
654 test_composePointJacob(
657 test_composePointJacob(
664 test_invComposePoint(
666 test_invComposePoint(
668 test_invComposePoint(
670 test_invComposePoint(
672 test_invComposePoint(
675 test_invComposePoint(
682 test_invComposePointJacob(
684 test_invComposePointJacob(
686 test_invComposePointJacob(
688 test_invComposePointJacob(
690 test_invComposePointJacob(
692 test_invComposePointJacob(
694 test_invComposePointJacob(
696 test_invComposePointJacob(
699 test_invComposePointJacob(
706 test_composeAndInvComposePoint(
708 test_composeAndInvComposePoint(
710 test_composeAndInvComposePoint(
712 test_composeAndInvComposePoint(
714 test_composeAndInvComposePoint(
717 test_composeAndInvComposePoint(
724 test_composePoint_vs_CPose3D(
726 test_composePoint_vs_CPose3D(
728 test_composePoint_vs_CPose3D(
730 test_composePoint_vs_CPose3D(
732 test_composePoint_vs_CPose3D(
735 test_composePoint_vs_CPose3D(
742 test_invComposePoint_vs_CPose3D(
744 test_invComposePoint_vs_CPose3D(
746 test_invComposePoint_vs_CPose3D(
748 test_invComposePoint_vs_CPose3D(
751 for (
size_t i = 0; i < 10; i++)
753 std::vector<double>
v(9);
755 test_invComposePoint_vs_CPose3D(
756 v[0],
v[1],
v[2],
v[3],
v[4],
v[5],
v[6],
v[7],
v[8]);
762 test_sphericalCoords(
764 test_sphericalCoords(
766 test_sphericalCoords(
768 test_sphericalCoords(
770 test_sphericalCoords(
773 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.
double x() const
Common members of all points & poses classes.
void inverseComposePoint(const double gx, const double gy, const double gz, double &lx, double &ly, double &lz, mrpt::math::CMatrixFixedNumeric< double, 3, 3 > *out_jacobian_df_dpoint=nullptr, mrpt::math::CMatrixFixedNumeric< double, 3, 7 > *out_jacobian_df_dpose=nullptr) const
Computes the 3D point L such as .
void test_composePointJacob(double x1, double y1, double z1, double yaw1, double pitch1, double roll1, double x, double y, double z)
mrpt::math::CVectorDouble getAsVectorVal() const
Return the pose or point as a 1xN vector with all the components (see derived classes for each implem...
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.
static void func_normalizeJacob(const CArrayDouble< 4 > &x, const double &dummy, CArrayDouble< 4 > &Y)
T y() const
Return y coordinate of the quaternion.
double DEG2RAD(const double x)
Degrees to radians.
GLdouble GLdouble GLdouble GLdouble q
CArrayNumeric is an array for numeric types supporting several mathematical operations (actually...
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 getAsQuaternion(mrpt::math::CQuaternionDouble &q, mrpt::math::CMatrixFixedNumeric< 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, mrpt::math::CMatrixFixedNumeric< double, 3, 3 > *out_jacob_dryp_dpoint=nullptr, mrpt::math::CMatrixFixedNumeric< 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...
T square(const T x)
Inline function for the square of a number.
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 composePoint(const double lx, const double ly, const double lz, double &gx, double &gy, double &gz, mrpt::math::CMatrixFixedNumeric< double, 3, 3 > *out_jacobian_df_dpoint=nullptr, mrpt::math::CMatrixFixedNumeric< double, 3, 7 > *out_jacobian_df_dpose=nullptr) const
Computes the 3D point G such as .
static void func_spherical_coords(const CArrayDouble< 7+3 > &x, const double &dummy, CArrayDouble< 3 > &Y)
This base provides a set of functions for maths stuff.
T r() const
Return r coordinate of the quaternion.
CONTAINER::Scalar sum(const CONTAINER &v)
Computes the sum of all the elements.
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)
static void func_compose_point(const CArrayDouble< 7+3 > &x, const double &dummy, CArrayDouble< 3 > &Y)
void test_composeAndInvComposePoint(double x1, double y1, double z1, double yaw1, double pitch1, double roll1, double x, double y, double z)
double x
X,Y,Z coordinates.
A class used to store a 3D pose as a translation (x,y,z) and a quaternion (qr,qx,qy,qz).
A class used to store a 3D point.
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
void test_invComposePointJacob(double x1, double y1, double z1, double yaw1, double pitch1, double roll1, double x, double y, double z)
static void func_inv_compose_point(const CArrayDouble< 7+3 > &x, const double &dummy, CArrayDouble< 3 > &Y)
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 composePoint(double lx, double ly, double lz, double &gx, double &gy, double &gz, mrpt::math::CMatrixFixedNumeric< double, 3, 3 > *out_jacobian_df_dpoint=nullptr, mrpt::math::CMatrixFixedNumeric< double, 3, 6 > *out_jacobian_df_dpose=nullptr, mrpt::math::CMatrixFixedNumeric< 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...
MATRIX44 getHomogeneousMatrixVal() const
Returns the corresponding 4x4 homogeneous transformation matrix for the point(translation) or pose (t...
void test_normalizeJacob(double yaw1, double pitch1, double roll1)
void test_composePoint_vs_CPose3D(double x1, double y1, double z1, double yaw1, double pitch1, double roll1, double x, double y, double z)
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.
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)
void inverseComposePoint(const double gx, const double gy, const double gz, double &lx, double &ly, double &lz, mrpt::math::CMatrixFixedNumeric< double, 3, 3 > *out_jacobian_df_dpoint=nullptr, mrpt::math::CMatrixFixedNumeric< double, 3, 6 > *out_jacobian_df_dpose=nullptr, mrpt::math::CMatrixFixedNumeric< double, 3, 6 > *out_jacobian_df_dse3=nullptr) const
Computes the 3D point L such as .
#define MRPT_UNUSED_PARAM(a)
Determines whether this is an X86 or AMD64 platform.