16 #include <CTraitsTest.h>
17 #include <gtest/gtest.h>
25 template class mrpt::CTraitsTest<CPose3DQuatPDFGaussian>;
33 double x,
double y,
double z,
double yaw,
double pitch,
double roll,
37 generateRandomPose3DPDF(
x,
y,
z, yaw,
pitch,
roll, std_scale));
41 double x,
double y,
double z,
double yaw,
double pitch,
double roll,
49 for (
int i = 0; i < 6; i++)
cov(i, i) += 1e-7;
58 generateRandomPose3DPDF(1.0, 2.0, 3.0, yaw,
pitch,
roll, 0.1);
64 EXPECT_NEAR(0, (p2ypr.
cov - p1ypr.
cov).array().abs().mean(), 1e-2)
67 <<
"p1quat : " << endl
80 x[7 + 0],
x[7 + 1],
x[7 + 2],
83 for (
int i = 0; i < 7; i++) Y[i] =
p[i];
93 x[7 + 0],
x[7 + 1],
x[7 + 2],
96 for (
int i = 0; i < 7; i++) Y[i] =
p[i];
100 double x,
double y,
double z,
double yaw,
double pitch,
double roll,
101 double std_scale,
double x2,
double y2,
double z2,
double yaw2,
102 double pitch2,
double roll2,
double std_scale2)
105 generateRandomPoseQuat3DPDF(
x,
y,
z, yaw,
pitch,
roll, std_scale);
107 x2, y2, z2, yaw2, pitch2, roll2, std_scale2);
116 for (
int i = 0; i < 7; i++) x_mean[i] = p7pdf1.
mean[i];
117 for (
int i = 0; i < 7; i++) x_mean[7 + i] = p7pdf2.
mean[i];
120 x_cov.insertMatrix(0, 0, p7pdf1.
cov);
121 x_cov.insertMatrix(7, 7, p7pdf2.
cov);
125 x_incrs.assign(1e-6);
127 x_mean, x_cov, func_compose, DUMMY, y_mean, y_cov, x_incrs);
130 EXPECT_NEAR(0, (y_cov - p7_comp.
cov).array().abs().mean(), 1e-2)
131 <<
"p1 mean: " << p7pdf1.
mean << endl
132 <<
"p2 mean: " << p7pdf2.
mean << endl
133 <<
"Numeric approximation of covariance: " << endl
135 <<
"Returned covariance: " << endl
136 << p7_comp.
cov << endl;
146 for (
int i = 0; i < 7; i++) Y[i] = p1_inv[i];
150 double x,
double y,
double z,
double yaw,
double pitch,
double roll,
151 double x2,
double y2,
double z2,
double yaw2,
double pitch2,
170 for (
int i = 0; i < 7; i++) x_mean[i] = q1[i];
171 for (
int i = 0; i < 7; i++) x_mean[7 + i] = q2[i];
175 x_incrs.assign(1e-7);
178 x_mean, std::function<
void(
181 x_incrs, DUMMY, numJacobs);
183 numJacobs.extractMatrix(0, 0, num_df_dx);
184 numJacobs.extractMatrix(0, 7, num_df_du);
188 EXPECT_NEAR(0, (df_dx - num_df_dx).array().abs().
sum(), 3e-3)
189 <<
"q1: " << q1 << endl
190 <<
"q2: " << q2 << endl
191 <<
"Numeric approximation of df_dx: " << endl
193 <<
"Implemented method: " << endl
196 << df_dx - num_df_dx << endl;
198 EXPECT_NEAR(0, (df_du - num_df_du).array().abs().
sum(), 3e-3)
199 <<
"q1: " << q1 << endl
200 <<
"q2: " << q2 << endl
201 <<
"Numeric approximation of df_du: " << endl
203 <<
"Implemented method: " << endl
206 << df_du - num_df_du << endl;
210 double x,
double y,
double z,
double yaw,
double pitch,
double roll,
214 generateRandomPoseQuat3DPDF(
x,
y,
z, yaw,
pitch,
roll, std_scale);
223 for (
int i = 0; i < 7; i++) x_mean[i] = p7pdf1.
mean[i];
226 x_cov.insertMatrix(0, 0, p7pdf1.
cov);
230 x_incrs.assign(1e-6);
232 x_mean, x_cov, func_inverse, DUMMY, y_mean, y_cov, x_incrs);
236 EXPECT_NEAR(0, (y_cov - p7_inv.
cov).array().abs().mean(), 1e-2)
237 <<
"p1 mean: " << p7pdf1.
mean << endl
238 <<
"inv mean: " << p7_inv.
mean << endl
239 <<
"Numeric approximation of covariance: " << endl
241 <<
"Returned covariance: " << endl
242 << p7_inv.
cov << endl
244 << y_cov - p7_inv.
cov << endl;
248 double x,
double y,
double z,
double yaw,
double pitch,
double roll,
249 double std_scale,
double x2,
double y2,
double z2,
double yaw2,
250 double pitch2,
double roll2,
double std_scale2)
253 generateRandomPoseQuat3DPDF(
x,
y,
z, yaw,
pitch,
roll, std_scale);
255 x2, y2, z2, yaw2, pitch2, roll2, std_scale2);
264 for (
int i = 0; i < 7; i++) x_mean[i] = p7pdf1.
mean[i];
265 for (
int i = 0; i < 7; i++) x_mean[7 + i] = p7pdf2.
mean[i];
268 x_cov.insertMatrix(0, 0, p7pdf1.
cov);
269 x_cov.insertMatrix(7, 7, p7pdf2.
cov);
273 x_incrs.assign(1e-6);
275 x_mean, x_cov, func_inv_compose, DUMMY, y_mean, y_cov, x_incrs);
278 EXPECT_NEAR(0, (y_cov - p7_comp.
cov).array().abs().mean(), 1e-2)
279 <<
"p1 mean: " << p7pdf1.
mean << endl
280 <<
"p2 mean: " << p7pdf2.
mean << endl
281 <<
"Numeric approximation of covariance: " << endl
283 <<
"Returned covariance: " << endl
284 << p7_comp.
cov << endl;
288 double x,
double y,
double z,
double yaw,
double pitch,
double roll,
289 double std_scale,
double x2,
double y2,
double z2,
double yaw2,
290 double pitch2,
double roll2)
293 generateRandomPoseQuat3DPDF(
x,
y,
z, yaw,
pitch,
roll, std_scale);
305 0, (p7_new_base_pdf.
cov - p7pdf1.
cov).array().abs().mean(), 1e-2)
306 <<
"p1 mean: " << p7pdf1.
mean << endl
307 <<
"new_base: " << new_base << endl;
315 <<
"p1 mean: " << p7pdf1.
mean << endl
316 <<
"new_base: " << new_base << endl;
330 testCompositionJacobian(
331 0, 0, 0,
DEG2RAD(2),
DEG2RAD(0),
DEG2RAD(0), 0, 0, 0,
DEG2RAD(0),
333 testCompositionJacobian(
334 1, 2, 3,
DEG2RAD(2),
DEG2RAD(0),
DEG2RAD(0), -8, 45, 10,
DEG2RAD(0),
336 testCompositionJacobian(
337 1, -2, 3,
DEG2RAD(2),
DEG2RAD(0),
DEG2RAD(0), -8, 45, 10,
DEG2RAD(0),
339 testCompositionJacobian(
340 1, 2, -3,
DEG2RAD(2),
DEG2RAD(0),
DEG2RAD(0), -8, 45, 10,
DEG2RAD(0),
342 testCompositionJacobian(
343 1, 2, 3,
DEG2RAD(20),
DEG2RAD(80),
DEG2RAD(70), -8, 45, 10,
DEG2RAD(50),
345 testCompositionJacobian(
348 testCompositionJacobian(
351 testCompositionJacobian(
354 testCompositionJacobian(
355 1, 2, 3,
DEG2RAD(20),
DEG2RAD(80),
DEG2RAD(70), -8, 45, 10,
DEG2RAD(50),
357 testCompositionJacobian(
358 1, 2, 3,
DEG2RAD(20),
DEG2RAD(80),
DEG2RAD(70), -8, 45, 10,
DEG2RAD(50),
401 0, 0, 0,
DEG2RAD(0),
DEG2RAD(0),
DEG2RAD(0), 0.1, 0, 0, 0,
DEG2RAD(0),
404 1, 2, 3,
DEG2RAD(0),
DEG2RAD(0),
DEG2RAD(0), 0.1, -8, 45, 10,
408 1, 2, 3,
DEG2RAD(20),
DEG2RAD(80),
DEG2RAD(70), 0.1, -8, 45, 10,
411 1, 2, 3,
DEG2RAD(20),
DEG2RAD(80),
DEG2RAD(70), 0.2, -8, 45, 10,
415 1, 2, 3,
DEG2RAD(10),
DEG2RAD(0),
DEG2RAD(0), 0.1, -8, 45, 10,
418 1, 2, 3,
DEG2RAD(0),
DEG2RAD(10),
DEG2RAD(0), 0.1, -8, 45, 10,
421 1, 2, 3,
DEG2RAD(0),
DEG2RAD(0),
DEG2RAD(10), 0.1, -8, 45, 10,
424 1, 2, 3,
DEG2RAD(0),
DEG2RAD(0),
DEG2RAD(0), 0.1, -8, 45, 10,
427 1, 2, 3,
DEG2RAD(0),
DEG2RAD(0),
DEG2RAD(0), 0.1, -8, 45, 10,
430 1, 2, 3,
DEG2RAD(0),
DEG2RAD(0),
DEG2RAD(0), 0.1, -8, 45, 10,
436 testPoseInverseComposition(
437 0, 0, 0,
DEG2RAD(0),
DEG2RAD(0),
DEG2RAD(0), 0.1, 0, 0, 0,
DEG2RAD(0),
439 testPoseInverseComposition(
440 1, 2, 3,
DEG2RAD(0),
DEG2RAD(0),
DEG2RAD(0), 0.1, -8, 45, 10,
443 testPoseInverseComposition(
444 1, 2, 3,
DEG2RAD(20),
DEG2RAD(80),
DEG2RAD(70), 0.1, -8, 45, 10,
446 testPoseInverseComposition(
447 1, 2, 3,
DEG2RAD(20),
DEG2RAD(80),
DEG2RAD(70), 0.2, -8, 45, 10,
450 testPoseInverseComposition(
451 1, 2, 3,
DEG2RAD(10),
DEG2RAD(0),
DEG2RAD(0), 0.1, -8, 45, 10,
453 testPoseInverseComposition(
454 1, 2, 3,
DEG2RAD(0),
DEG2RAD(10),
DEG2RAD(0), 0.1, -8, 45, 10,
456 testPoseInverseComposition(
457 1, 2, 3,
DEG2RAD(0),
DEG2RAD(0),
DEG2RAD(10), 0.1, -8, 45, 10,
459 testPoseInverseComposition(
460 1, 2, 3,
DEG2RAD(0),
DEG2RAD(0),
DEG2RAD(0), 0.1, -8, 45, 10,
462 testPoseInverseComposition(
463 1, 2, 3,
DEG2RAD(0),
DEG2RAD(0),
DEG2RAD(0), 0.1, -8, 45, 10,
465 testPoseInverseComposition(
466 1, 2, 3,
DEG2RAD(0),
DEG2RAD(0),
DEG2RAD(0), 0.1, -8, 45, 10,
473 0, 0, 0,
DEG2RAD(0),
DEG2RAD(0),
DEG2RAD(0), 0.1, 0, 0, 0,
DEG2RAD(0),
476 1, 2, 3,
DEG2RAD(0),
DEG2RAD(0),
DEG2RAD(0), 0.1, -8, 45, 10,
480 1, 2, 3,
DEG2RAD(20),
DEG2RAD(80),
DEG2RAD(70), 0.1, -8, 45, 10,
483 1, 2, 3,
DEG2RAD(20),
DEG2RAD(80),
DEG2RAD(70), 0.2, -8, 45, 10,
TEST_F(Pose3DQuatPDFGaussTests, ToYPRGaussPDFAndBack)
void test_toFromYPRGauss(double yaw, double pitch, double roll)
void testCompositionJacobian(double x, double y, double z, double yaw, double pitch, double roll, double x2, double y2, double z2, double yaw2, double pitch2, double roll2)
void testInverse(double x, double y, double z, double yaw, double pitch, double roll, double std_scale)
void testChangeCoordsRef(double x, double y, double z, double yaw, double pitch, double roll, double std_scale, double x2, double y2, double z2, double yaw2, double pitch2, double roll2)
void testPoseComposition(double x, double y, double z, double yaw, double pitch, double roll, double std_scale, double x2, double y2, double z2, double yaw2, double pitch2, double roll2, double std_scale2)
static CPose3DQuatPDFGaussian generateRandomPoseQuat3DPDF(double x, double y, double z, double yaw, double pitch, double roll, double std_scale)
static void func_inv_compose(const CArrayDouble< 2 *7 > &x, const double &dummy, CArrayDouble< 7 > &Y)
static void func_compose(const CArrayDouble< 2 *7 > &x, const double &dummy, CArrayDouble< 7 > &Y)
static void func_inverse(const CArrayDouble< 7 > &x, const double &dummy, CArrayDouble< 7 > &Y)
void testPoseInverseComposition(double x, double y, double z, double yaw, double pitch, double roll, double std_scale, double x2, double y2, double z2, double yaw2, double pitch2, double roll2, double std_scale2)
static CPose3DPDFGaussian generateRandomPose3DPDF(double x, double y, double z, double yaw, double pitch, double roll, double std_scale)
CArrayNumeric is an array for numeric types supporting several mathematical operations (actually,...
A numeric matrix of compile-time fixed size.
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Declares a class that represents a Probability Density function (PDF) of a 3D pose .
mrpt::math::CMatrixDouble66 cov
The 6x6 covariance matrix.
A class used to store a 3D pose as a translation (x,y,z) and a quaternion (qr,qx,qy,...
Declares a class that represents a Probability Density function (PDF) of a 3D pose using a quaternion...
mrpt::math::CMatrixDouble77 cov
The 7x7 covariance matrix.
CPose3DQuat mean
The mean value.
void changeCoordinatesReference(const CPose3DQuat &newReferenceBase)
this = p (+) this.
static void jacobiansPoseComposition(const CPose3DQuat &x, const CPose3DQuat &u, mrpt::math::CMatrixDouble77 &df_dx, mrpt::math::CMatrixDouble77 &df_du, CPose3DQuat *out_x_oplus_u=nullptr)
This static method computes the two Jacobians of a pose composition operation $f(x,...
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 drawGaussian1DMatrix(MAT &matrix, const double mean=0, const double std=1)
Fills the given matrix with independent, 1D-normally distributed samples.
#define MRPT_UNUSED_PARAM(a)
Determines whether this is an X86 or AMD64 platform.
GLdouble GLdouble GLdouble r
This base provides a set of functions for maths stuff.
CQuaternion< double > CQuaternionDouble
A quaternion of data type "double".
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...
Eigen::Matrix< typename MATRIX::Scalar, MATRIX::ColsAtCompileTime, MATRIX::ColsAtCompileTime > cov(const MATRIX &v)
Computes the covariance matrix from a list of samples in an NxM matrix, where each row is a sample,...
CMatrixFixedNumeric< double, 7, 7 > CMatrixDouble77
CONTAINER::Scalar sum(const CONTAINER &v)
Computes the sum of all the elements.
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
CRandomGenerator & getRandomGenerator()
A static instance of a CRandomGenerator class, for use in single-thread applications.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
double DEG2RAD(const double x)
Degrees to radians.