test_helpers.hpp
Go to the documentation of this file.
1 /*
2  * test_helpers.hpp
3  *
4  * Created on: Mar 3, 2020
5  * Author: Edo Jelavic
6  * Institute: ETH Zurich, Robotic Systems Lab
7  */
8 
9 #pragma once
11 #include <functional>
12 #include <vector>
13 #include <random>
14 
15 namespace grid_map {
16  class GridMap;
17 }
18 
19 namespace grid_map_test {
20 
21 /*
22  * Name of the layer that is used in all tests.
23  * It has no special meaning.
24  */
25 static const std::string testLayer = "test";
26 
27 /*
28  * Class that holds a function pointer to analytical
29  * functions used for evaluation. Analytical functions
30  * are in the form of f = f(x,y). One could also add
31  * derivatives to this class, e.g. for testing the
32  * accuracy of the normal estimation.
33  */
35 {
36  std::function<double(double, double)> f_;
37 };
38 
39 struct Point2D
40 {
41  double x_ = 0.0;
42  double y_ = 0.0;
43 };
44 
45 // Random generator engine.
46 extern std::mt19937 rndGenerator;
47 
48 // Maximal tolerance when comparing doubles in tests.
49 const double maxAbsErrorValue = 1e-3;
50 
51 grid_map::GridMap createMap(const grid_map::Length &length, double resolution,
52  const grid_map::Position &pos);
53 
54 /*
55  * Collections of methods that modify the grid map.
56  * All these methods create an analytical function that
57  * describes the value of the layer "testLayer" as a function
58  * of coordinates. That can be any mathematical function. Inside the test,
59  * sinusoidal, polynomial functions and exponential functions are used.
60  * e.g. f(x,y) = sin(x) + cos(y), f(x,y) = exp(-x*x - y*y)
61  * Grid map is then filled by evaluating
62  * that analytical function over the entire length and width of the
63  * grid map. Grid map thus contains spatially sampled mathematical
64  * function.
65  * Each method returns a structure containing the analytical function.
66  */
74 
75 /*
76  * Iterates over the grid map and fill it with values.
77  * values are calculated by evaluating analytical function.
78  */
79 void fillGridMap(grid_map::GridMap *map, const AnalyticalFunctions &functions);
80 
81 /*
82  * Create numPoints uniformly distributed random points that lie within the grid map.
83  */
84 std::vector<Point2D> uniformlyDitributedPointsWithinMap(const grid_map::GridMap &map,
85  unsigned int numPoints);
86 
87 /*
88  * For each point in queryPoints, verify that the interpolated value of the grid map
89  * is close to the ground truth which is contained in Analytical functions structure.
90  * Called inside the tests. Calls macros from gtest.
91  */
93  const std::vector<Point2D> &queryPoints,
94  grid_map::InterpolationMethods interpolationMethod);
95 
96 } /*grid_map_test*/
std::mt19937 rndGenerator
void fillGridMap(grid_map::GridMap *map, const AnalyticalFunctions &functions)
AnalyticalFunctions createSaddleWorld(grid_map::GridMap *map)
AnalyticalFunctions createTanhWorld(grid_map::GridMap *map)
InterpolationMethods
Definition: TypeDefs.hpp:39
AnalyticalFunctions createRationalFunctionWorld(grid_map::GridMap *map)
std::vector< Point2D > uniformlyDitributedPointsWithinMap(const grid_map::GridMap &map, unsigned int numPoints)
static const std::string testLayer
Eigen::Vector2d Position
Definition: TypeDefs.hpp:18
AnalyticalFunctions createSineWorld(grid_map::GridMap *map)
grid_map::GridMap createMap(const grid_map::Length &length, double resolution, const grid_map::Position &pos)
std::function< double(double, double)> f_
AnalyticalFunctions createGaussianWorld(grid_map::GridMap *map)
AnalyticalFunctions createSecondOrderPolyWorld(grid_map::GridMap *map)
void verifyValuesAtQueryPointsAreClose(const grid_map::GridMap &map, const AnalyticalFunctions &trueValues, const std::vector< Point2D > &queryPoints, grid_map::InterpolationMethods interpolationMethod)
const double maxAbsErrorValue
Eigen::Array2d Length
Definition: TypeDefs.hpp:24
AnalyticalFunctions createFlatWorld(grid_map::GridMap *map)


grid_map_core
Author(s): Péter Fankhauser
autogenerated on Tue Jun 1 2021 02:13:27