15 #include <gtest/gtest.h> 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);
343 <<
"p1.getHomogeneousMatrixVal():\n" 345 <<
"q1.getHomogeneousMatrixVal():\n" 351 <<
"p1: " << p1 << endl
352 <<
"q1: " << q1 << endl
353 <<
"p1r: " << p1r << endl;
357 double x1,
double y1,
double z1,
double yaw1,
double pitch1,
360 const CPose3D p1(x1, y1,
z1, yaw1, pitch1, roll1);
373 <<
"p1_inv.getHomogeneousMatrixVal():\n" 375 <<
"q1_inv.getHomogeneousMatrixVal():\n" 380 double x1,
double y1,
double z1,
double yaw1,
double pitch1,
383 const CPose3D p1(x1, y1,
z1, yaw1, pitch1, roll1);
394 <<
"q1.getHomogeneousMatrixVal():\n" 396 <<
"q2.getHomogeneousMatrixVal():\n" 401 double x1,
double y1,
double z1,
double yaw1,
double pitch1,
402 double roll1,
double x,
double y,
double z)
409 EXPECT_NEAR(
x, aux.
x, 1e-7);
410 EXPECT_NEAR(
y, aux.
y, 1e-7);
411 EXPECT_NEAR(
z, aux.
z, 1e-7);
415 double x1,
double y1,
double z1,
double yaw1,
double pitch1,
416 double roll1,
double x,
double y,
double z)
418 const CPose3D p1(x1, y1,
z1, yaw1, pitch1, roll1);
424 EXPECT_NEAR(pt1.
x, pt2.
x, 1e-7);
425 EXPECT_NEAR(pt1.
y, pt2.
y, 1e-7);
426 EXPECT_NEAR(pt1.
z, pt2.
z, 1e-7);
430 double x1,
double y1,
double z1,
double yaw1,
double pitch1,
431 double roll1,
double x,
double y,
double z)
433 const CPose3D p1(x1, y1,
z1, yaw1, pitch1, roll1);
439 EXPECT_NEAR(pt1.
x, pt2.
x, 1e-7);
440 EXPECT_NEAR(pt1.
y, pt2.
y, 1e-7);
441 EXPECT_NEAR(pt1.
z, pt2.
z, 1e-7);
446 float gx =
x, gy =
y, gz =
z;
448 double dist, yaw,
pitch;
454 double lx2, ly2, lz2;
455 q.inverseComposePoint(gx, gy, gz, lx2, ly2, lz2);
457 EXPECT_NEAR(lx, lx2, 1e-7);
458 EXPECT_NEAR(ly, ly2, 1e-7);
459 EXPECT_NEAR(lz, lz2, 1e-7);
469 q.quat().normalize();
471 q.sphericalCoordinates(
p, Y[0], Y[1], Y[2]);
475 double x1,
double y1,
double z1,
double yaw1,
double pitch1,
476 double roll1,
double x,
double y,
double z)
492 for (
int i = 0; i < 7; i++) x_mean[i] = q1[i];
499 x_incrs.assign(1e-7);
502 x_mean, std::function<
void(
505 x_incrs, DUMMY, numJacobs);
507 numJacobs.extractMatrix(0, 0, num_df_dpose);
508 numJacobs.extractMatrix(0, 7, num_df_dpoint);
512 EXPECT_NEAR(0, (df_dpoint - num_df_dpoint).array().abs().
sum(), 3e-3)
513 <<
"q1: " << q1 << endl
514 <<
"p: " <<
p << endl
515 <<
"Numeric approximation of df_dpoint: " << endl
516 << num_df_dpoint << endl
517 <<
"Implemented method: " << endl
520 << df_dpoint - num_df_dpoint << endl;
522 EXPECT_NEAR(0, (df_dpose - num_df_dpose).array().abs().
sum(), 3e-3)
523 <<
"q1: " << q1 << endl
524 <<
"p: " <<
p << endl
525 <<
"Numeric approximation of df_dpose: " << endl
526 << num_df_dpose << endl
527 <<
"Implemented method: " << endl
530 << df_dpose - num_df_dpose << endl;
538 for (
int i = 0; i < 4; i++)
q[i] =
x[i];
540 for (
int i = 0; i < 4; i++) Y[i] =
q[i];
545 const CPose3D pp(0, 0, 0, yaw1, pitch1, roll1);
556 for (
int i = 0; i < 4; i++) x_mean[i] = q1[i];
560 x_incrs.assign(1e-5);
563 x_mean, std::function<
void(
566 x_incrs, DUMMY, numJacobs);
568 numJacobs.extractMatrix(0, 0, num_df_dpose);
572 EXPECT_NEAR(0, (df_dpose - num_df_dpose).array().abs().
sum(), 3e-3)
573 <<
"q1: " << q1 << endl
574 <<
"Numeric approximation of df_dpose: " << endl
575 << num_df_dpose << endl
576 <<
"Implemented method: " << endl
579 << df_dpose - num_df_dpose << endl;
644 test_composePointJacob(
646 test_composePointJacob(
648 test_composePointJacob(
650 test_composePointJacob(
652 test_composePointJacob(
655 test_composePointJacob(
662 test_invComposePoint(
664 test_invComposePoint(
666 test_invComposePoint(
668 test_invComposePoint(
670 test_invComposePoint(
673 test_invComposePoint(
680 test_invComposePointJacob(
682 test_invComposePointJacob(
684 test_invComposePointJacob(
686 test_invComposePointJacob(
688 test_invComposePointJacob(
690 test_invComposePointJacob(
692 test_invComposePointJacob(
694 test_invComposePointJacob(
697 test_invComposePointJacob(
704 test_composeAndInvComposePoint(
706 test_composeAndInvComposePoint(
708 test_composeAndInvComposePoint(
710 test_composeAndInvComposePoint(
712 test_composeAndInvComposePoint(
715 test_composeAndInvComposePoint(
722 test_composePoint_vs_CPose3D(
724 test_composePoint_vs_CPose3D(
726 test_composePoint_vs_CPose3D(
728 test_composePoint_vs_CPose3D(
730 test_composePoint_vs_CPose3D(
733 test_composePoint_vs_CPose3D(
740 test_invComposePoint_vs_CPose3D(
742 test_invComposePoint_vs_CPose3D(
744 test_invComposePoint_vs_CPose3D(
746 test_invComposePoint_vs_CPose3D(
749 for (
size_t i = 0; i < 10; i++)
751 std::vector<double>
v(9);
753 test_invComposePoint_vs_CPose3D(
754 v[0],
v[1],
v[2],
v[3],
v[4],
v[5],
v[6],
v[7],
v[8]);
760 test_sphericalCoords(
762 test_sphericalCoords(
764 test_sphericalCoords(
766 test_sphericalCoords(
768 test_sphericalCoords(
771 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)
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
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.
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 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...
mrpt::math::CMatrixDouble44 getHomogeneousMatrixVal() const
Returns the corresponding 4x4 homogeneous transformation matrix for the point(translation) or pose (t...
void jacob_numeric_estimate(const VECTORLIKE &x, std::function< void(const VECTORLIKE &x, const USERPARAM &y, VECTORLIKE3 &out)> functor, const VECTORLIKE2 &increments, const USERPARAM &userParam, MATRIXLIKE &out_Jacobian)
Numerical estimation of the Jacobian of a user-supplied function - this template redirects to mrpt::m...
T square(const T x)
Inline function for the square of a number.
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.
#define MRPT_UNUSED_PARAM(a)
Can be used to avoid "not used parameters" warnings from the compiler.
mrpt::math::CMatrixDouble44 getHomogeneousMatrixVal() const
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...
void test_normalizeJacob(double yaw1, double pitch1, double roll1)
A partial specialization of CArrayNumeric for double numbers.
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 .