16 #include <gtest/gtest.h>
41 for (
int i=0;i<6;i++)
cov(i,i)+=1e-7;
57 const double cov_mean_error = (p6pdf_recov.
cov - p6pdf.
cov).array().abs().mean();
59 EXPECT_TRUE(val_mean_error < 1e-8);
60 EXPECT_TRUE(cov_mean_error < 1e-8);
70 for (
int i=0;i<6;i++) Y[i]=
p[i];
79 for (
int i=0;i<6;i++) Y[i]=
p[i];
84 double x,
double y,
double z,
double yaw,
double pitch,
double roll,
double std_scale,
85 double x2,
double y2,
double z2,
double yaw2,
double pitch2,
double roll2,
double std_scale2 )
88 CPose3DPDFGaussian p6pdf2 = generateRandomPose3DPDF(x2,y2,z2,yaw2,pitch2,roll2, std_scale2);
98 for (
int i=0;i<6;i++) x_mean[i]=p6pdf1.
mean[i];
99 for (
int i=0;i<6;i++) x_mean[6+i]=p6pdf2.
mean[i];
102 x_cov.insertMatrix(0,0, p6pdf1.
cov);
103 x_cov.insertMatrix(6,6, p6pdf2.
cov);
107 x_incrs.assign(1e-6);
112 <<
"p1 mean: " << p6pdf1.
mean << endl
113 <<
"p2 mean: " << p6pdf2.
mean << endl;
116 EXPECT_NEAR(0, (y_cov-p6_comp.
cov).array().abs().sum(), 1e-2 )
117 <<
"p1 mean: " << p6pdf1.
mean << endl
118 <<
"p2 mean: " << p6pdf2.
mean << endl;
126 <<
"p1 mean: " << p6pdf1.
mean << endl
127 <<
"p2 mean: " << p6pdf2.
mean << endl;
130 EXPECT_NEAR(0, (y_cov-p6_comp.
cov).array().abs().sum(), 1e-2 )
131 <<
"p1 mean: " << p6pdf1.
mean << endl
132 <<
"p2 mean: " << p6pdf2.
mean << endl;
137 double x,
double y,
double z,
double yaw,
double pitch,
double roll,
138 double x2,
double y2,
double z2,
double yaw2,
double pitch2,
double roll2)
141 const CPose3D q2(x2,y2,z2,yaw2,pitch2,roll2);
155 for (
int i=0;i<6;i++) x_mean[i]=q1[i];
156 for (
int i=0;i<6;i++) x_mean[6+i]=q2[i];
160 x_incrs.assign(1e-7);
164 numJacobs.extractMatrix(0,0, num_df_dx);
165 numJacobs.extractMatrix(0,6, num_df_du);
169 EXPECT_NEAR(0, (df_dx-num_df_dx).array().abs().
sum(), 3e-3 )
170 <<
"q1: " << q1 << endl
171 <<
"q2: " << q2 << endl
172 <<
"Numeric approximation of df_dx: " << endl << num_df_dx << endl
173 <<
"Implemented method: " << endl << df_dx << endl
174 <<
"Error: " << endl << df_dx-num_df_dx << endl;
176 EXPECT_NEAR(0, (df_du-num_df_du).array().abs().
sum(), 3e-3 )
177 <<
"q1: " << q1 << endl
178 <<
"q2: " << q2 << endl
179 <<
"Numeric approximation of df_du: " << endl << num_df_du << endl
180 <<
"Implemented method: " << endl << df_du << endl
181 <<
"Error: " << endl << df_du-num_df_du << endl;
187 double x,
double y,
double z,
double yaw,
double pitch,
double roll,
double std_scale,
188 double x2,
double y2,
double z2,
double yaw2,
double pitch2,
double roll2,
double std_scale2 )
191 CPose3DPDFGaussian p6pdf2 = generateRandomPose3DPDF(x2,y2,z2,yaw2,pitch2,roll2, std_scale2);
201 for (
int i=0;i<6;i++) x_mean[i]=p6pdf1.
mean[i];
202 for (
int i=0;i<6;i++) x_mean[6+i]=p6pdf2.
mean[i];
205 x_cov.insertMatrix(0,0, p6pdf1.
cov);
206 x_cov.insertMatrix(6,6, p6pdf2.
cov);
210 x_incrs.assign(1e-6);
215 <<
"p1 mean: " << p6pdf1.
mean << endl
216 <<
"p2 mean: " << p6pdf2.
mean << endl;
219 EXPECT_NEAR(0, (y_cov-p6_comp.
cov).array().abs().sum(), 1e-2 )
220 <<
"p1 mean: " << p6pdf1.
mean << endl
221 <<
"p2 mean: " << p6pdf2.
mean << endl;
229 <<
"p1 mean: " << p6pdf1.
mean << endl
230 <<
"p2 mean: " << p6pdf2.
mean << endl;
233 EXPECT_NEAR(0, (y_cov-p6_comp.
cov).array().abs().sum(), 1e-2 )
234 <<
"p1 mean: " << p6pdf1.
mean << endl
235 <<
"p2 mean: " << p6pdf2.
mean << endl;
240 double x,
double y,
double z,
double yaw,
double pitch,
double roll,
double std_scale )
253 <<
"p mean: " << p6pdf2.
mean << endl;
256 EXPECT_NEAR(0, (p6_inv.
cov-p6_comp.
cov).array().abs().sum(), 1e-2 )
257 <<
"p mean: " << p6pdf2.
mean << endl;
266 <<
"p mean: " << p6pdf2.
mean << endl
267 <<
"p6_inv2 mean: " << p6_inv2.
mean << endl
268 <<
"p6_comp mean: " << p6_comp.
mean << endl;
271 EXPECT_NEAR(0, (p6_inv2.
cov-p6_comp.
cov).array().abs().sum(), 1e-2 )
272 <<
"p mean: " << p6pdf2.
mean << endl
273 <<
"p6_inv2 mean: " << p6_inv2.
mean << endl
274 <<
"p6_comp mean: " << p6_comp.
mean << endl;
279 double x,
double y,
double z,
double yaw,
double pitch,
double roll,
double std_scale,
280 double x2,
double y2,
double z2,
double yaw2,
double pitch2,
double roll2,
double std_scale2 )
283 testPoseComposition(
x,
y,
z,yaw,
pitch,
roll,std_scale, x2,y2,z2,yaw2,pitch2,roll2,std_scale2 );
285 testPoseInverseComposition(
x,
y,
z,yaw,
pitch,
roll,std_scale, x2,y2,z2,yaw2,pitch2,roll2,std_scale2 );
292 double x,
double y,
double z,
double yaw,
double pitch,
double roll,
double std_scale,
293 double x2,
double y2,
double z2,
double yaw2,
double pitch2,
double roll2 )
305 EXPECT_NEAR(0, (p6_new_base_pdf.
cov - p6pdf1.
cov).array().abs().mean(), 1e-2 )
306 <<
"p1 mean: " << p6pdf1.
mean << endl
307 <<
"new_base: " << new_base << endl;
309 <<
"p1 mean: " << p6pdf1.
mean << endl
310 <<
"new_base: " << new_base << endl;
336 testCompositionJacobian(0,0,0,
DEG2RAD(2),
DEG2RAD(0),
DEG2RAD(0), 0,0,0,
DEG2RAD(0),
DEG2RAD(0),
DEG2RAD(0) );
337 testCompositionJacobian(0,0,0,
DEG2RAD(2),
DEG2RAD(0),
DEG2RAD(0), 0,0,0,
DEG2RAD(0),
DEG2RAD(0),
DEG2RAD(0) );
338 testCompositionJacobian(1,2,3,
DEG2RAD(2),
DEG2RAD(0),
DEG2RAD(0), -8,45,10,
DEG2RAD(0),
DEG2RAD(0),
DEG2RAD(0) );
339 testCompositionJacobian(1,-2,3,
DEG2RAD(2),
DEG2RAD(0),
DEG2RAD(0), -8,45,10,
DEG2RAD(0),
DEG2RAD(0),
DEG2RAD(0) );
340 testCompositionJacobian(1,2,-3,
DEG2RAD(2),
DEG2RAD(0),
DEG2RAD(0), -8,45,10,
DEG2RAD(0),
DEG2RAD(0),
DEG2RAD(0) );
341 testCompositionJacobian(1,2,3,
DEG2RAD(20),
DEG2RAD(80),
DEG2RAD(70), -8,45,10,
DEG2RAD(50),
DEG2RAD(-10),
DEG2RAD(30) );
342 testCompositionJacobian(1,2,3,
DEG2RAD(20),
DEG2RAD(-80),
DEG2RAD(70), -8,45,10,
DEG2RAD(50),
DEG2RAD(-10),
DEG2RAD(30) );
343 testCompositionJacobian(1,2,3,
DEG2RAD(20),
DEG2RAD(80),
DEG2RAD(-70), -8,45,10,
DEG2RAD(50),
DEG2RAD(-10),
DEG2RAD(30) );
344 testCompositionJacobian(1,2,3,
DEG2RAD(20),
DEG2RAD(80),
DEG2RAD(70), -8,45,10,
DEG2RAD(-50),
DEG2RAD(-10),
DEG2RAD(30) );
345 testCompositionJacobian(1,2,3,
DEG2RAD(20),
DEG2RAD(80),
DEG2RAD(70), -8,45,10,
DEG2RAD(50),
DEG2RAD(10),
DEG2RAD(30) );
346 testCompositionJacobian(1,2,3,
DEG2RAD(20),
DEG2RAD(80),
DEG2RAD(70), -8,45,10,
DEG2RAD(50),
DEG2RAD(-10),
DEG2RAD(-30) );
352 testAllPoseOperators(0,0,0,
DEG2RAD(0),
DEG2RAD(0),
DEG2RAD(0), 0.1, 0,0,0,
DEG2RAD(0),
DEG2RAD(0),
DEG2RAD(0), 0.1 );
353 testAllPoseOperators(1,2,3,
DEG2RAD(0),
DEG2RAD(0),
DEG2RAD(0), 0.1, -8,45,10,
DEG2RAD(0),
DEG2RAD(0),
DEG2RAD(0), 0.1 );
355 testAllPoseOperators(1,2,3,
DEG2RAD(20),
DEG2RAD(80),
DEG2RAD(70), 0.1, -8,45,10,
DEG2RAD(50),
DEG2RAD(-10),
DEG2RAD(30), 0.1 );
356 testAllPoseOperators(1,2,3,
DEG2RAD(20),
DEG2RAD(80),
DEG2RAD(70), 0.2, -8,45,10,
DEG2RAD(50),
DEG2RAD(-10),
DEG2RAD(30), 0.2 );
358 testAllPoseOperators(1,2,3,
DEG2RAD(10),
DEG2RAD(0),
DEG2RAD(0), 0.1, -8,45,10,
DEG2RAD(0),
DEG2RAD(0),
DEG2RAD(0), 0.1 );
359 testAllPoseOperators(1,2,3,
DEG2RAD(0),
DEG2RAD(10),
DEG2RAD(0), 0.1, -8,45,10,
DEG2RAD(0),
DEG2RAD(0),
DEG2RAD(0), 0.1 );
360 testAllPoseOperators(1,2,3,
DEG2RAD(0),
DEG2RAD(0),
DEG2RAD(10), 0.1, -8,45,10,
DEG2RAD(0),
DEG2RAD(0),
DEG2RAD(0), 0.1 );
361 testAllPoseOperators(1,2,3,
DEG2RAD(0),
DEG2RAD(0),
DEG2RAD(0), 0.1, -8,45,10,
DEG2RAD(10),
DEG2RAD(0),
DEG2RAD(0), 0.1 );
362 testAllPoseOperators(1,2,3,
DEG2RAD(0),
DEG2RAD(0),
DEG2RAD(0), 0.1, -8,45,10,
DEG2RAD(0),
DEG2RAD(10),
DEG2RAD(0), 0.1 );
363 testAllPoseOperators(1,2,3,
DEG2RAD(0),
DEG2RAD(0),
DEG2RAD(0), 0.1, -8,45,10,
DEG2RAD(0),
DEG2RAD(0),
DEG2RAD(10), 0.1 );
368 testChangeCoordsRef(0,0,0,
DEG2RAD(0),
DEG2RAD(0),
DEG2RAD(0), 0.1, 0,0,0,
DEG2RAD(0),
DEG2RAD(0),
DEG2RAD(0) );
369 testChangeCoordsRef(1,2,3,
DEG2RAD(0),
DEG2RAD(0),
DEG2RAD(0), 0.1, -8,45,10,
DEG2RAD(0),
DEG2RAD(0),
DEG2RAD(0) );
371 testChangeCoordsRef(1,2,3,
DEG2RAD(20),
DEG2RAD(80),
DEG2RAD(70), 0.1, -8,45,10,
DEG2RAD(50),
DEG2RAD(-10),
DEG2RAD(30) );
372 testChangeCoordsRef(1,2,3,
DEG2RAD(20),
DEG2RAD(80),
DEG2RAD(70), 0.2, -8,45,10,
DEG2RAD(50),
DEG2RAD(-10),
DEG2RAD(30) );
TEST_F(Pose3DPDFGaussTests, ToQuatGaussPDFAndBack)
void testToQuatPDFAndBack(double x, double y, double z, double yaw, double pitch, double roll, double std_scale)
static void func_compose(const CArrayDouble< 12 > &x, const double &dummy, CArrayDouble< 6 > &Y)
void testPoseInverse(double x, double y, double z, double yaw, double pitch, double roll, double std_scale)
static void func_inv_compose(const CArrayDouble< 2 *6 > &x, const double &dummy, CArrayDouble< 6 > &Y)
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 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)
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)
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 testAllPoseOperators(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)
A partial specialization of CArrayNumeric for double numbers.
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 .
void inverse(CPose3DPDF &o) const MRPT_OVERRIDE
Returns a new PDF such as: NEW_PDF = (0,0,0) - THIS_PDF.
void changeCoordinatesReference(const CPose3D &newReferenceBase) MRPT_OVERRIDE
this = p (+) this.
CPose3D mean
The mean value.
mrpt::math::CMatrixDouble66 cov
The 6x6 covariance matrix.
static void jacobiansPoseComposition(const CPose3D &x, const CPose3D &u, mrpt::math::CMatrixDouble66 &df_dx, mrpt::math::CMatrixDouble66 &df_du)
This static method computes the pose composition Jacobians.
Declares a class that represents a Probability Density function (PDF) of a 3D pose using a quaternion...
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.
GLdouble GLdouble GLdouble r
#define MRPT_UNUSED_PARAM(a)
Can be used to avoid "not used parameters" warnings from the compiler.
void jacob_numeric_estimate(const VECTORLIKE &x, void(*functor)(const VECTORLIKE &x, const USERPARAM &y, VECTORLIKE3 &out), 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...
This base provides a set of functions for maths stuff.
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, 6, 6 > CMatrixDouble66
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...
BASE_IMPEXP CRandomGenerator randomGenerator
A static instance of a CRandomGenerator class, for use in single-thread applications.
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values,...
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.