Main MRPT website > C++ reference for MRPT 1.5.6
CAtan2LookUpTable_unittest.cpp
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2017, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +---------------------------------------------------------------------------+ */
9 
11 #include <mrpt/random.h>
12 #include <gtest/gtest.h>
13 #include <cmath>
14 
15 
16 template <class LUT_CLASS>
17 void atan2_lut_test(const LUT_CLASS & atan2lut, const double SIZE, const double max_deg_errors, const double skip_area)
18 {
19  for (int i=0;i<1000;i++)
20  {
21  const double x = mrpt::random::randomGenerator.drawUniform(-.5*SIZE, .5*SIZE);
22  const double y = mrpt::random::randomGenerator.drawUniform(-.5*SIZE, .5*SIZE);
23 
24  // Avoid the central part, where accuracy is worse
25  if (std::abs(x)<skip_area || std::abs(y)<skip_area)
26  continue;
27 
28  const double atan2_good = ::atan2(y,x);
29  double atan2_lut;
30  bool atan2_lut_valid = atan2lut.atan2(y,x,atan2_lut);
31 
32  EXPECT_TRUE(atan2_lut_valid);
33  EXPECT_LT(std::abs(atan2_good-atan2_lut), mrpt::utils::DEG2RAD(max_deg_errors) ) << "(x,y): ("<< x << " , " << y << ")" << "\natan2_good:" << atan2_good << " atan2_lut:" << atan2_lut << std::endl;
34  }
35 }
36 
37 TEST(CAtan2LookUpTable,ValidValidTest)
38 {
39  const double SIZE = 20.0;
40  const double RES = 0.10;
41  mrpt::math::CAtan2LookUpTable atan2lut(-.5*SIZE, .5*SIZE, -.5*SIZE, .5*SIZE, RES);
42  atan2_lut_test(atan2lut, SIZE,1.5 /*max error*/, 2.0 /* skip zone */);
43 }
44 
45 TEST(CAtan2LookUpTable,MultiResTest)
46 {
47  const double SIZE = 20.0;
49 
50  std::map<double,double> res2extension;
51  res2extension[0.001] = 0.8; // 0.1 cm resolution
52  res2extension[0.01] = 2.0; // 1.0 cm resolution
53  res2extension[0.02] = 5.0; // 2.0 cm resolution
54  res2extension[0.05] = 11.0; // 5.0 cm resolution
55  atan2lut.resize(res2extension);
56 
57  atan2_lut_test(atan2lut, SIZE,0.5 /*max error*/, 0.4 /* skip zone */);
58 }
59 
double drawUniform(const double Min, const double Max)
Generate a uniformly distributed pseudo-random number using the MT19937 algorithm, scaled to the selected range.
BASE_IMPEXP CRandomGenerator randomGenerator
A static instance of a CRandomGenerator class, for use in single-thread applications.
TEST(CAtan2LookUpTable, ValidValidTest)
A look-up-table (LUT) of atan values for any (x,y) value in a square/rectangular grid of predefined r...
Like CAtan2LookUpTable but with a multiresolution grid for increasingly better accuracy in points nea...
void atan2_lut_test(const LUT_CLASS &atan2lut, const double SIZE, const double max_deg_errors, const double skip_area)
double DEG2RAD(const double x)
Degrees to radians.
Definition: bits.h:82
void resize(const std::map< double, double > &lst_resolutions2extensions) MRPT_NO_THROWS
See CAtan2LookUpTableMultiRes for a discussion of the parameters.
GLenum GLint GLint y
Definition: glext.h:3516
GLenum GLint x
Definition: glext.h:3516



Page generated by Doxygen 1.8.14 for MRPT 1.5.6 Git: 4c65e8431 Tue Apr 24 08:18:17 2018 +0200 at lun oct 28 01:35:26 CET 2019