CubicInterpolationTest.cpp
Go to the documentation of this file.
1 /*
2  * CubicInterpolationTest.cpp
3  *
4  * Created on: Mar 12, 2020
5  * Author: Edo Jelavic
6  * Institute: ETH Zurich, Robotic Systems Lab
7  */
8 
9 #include "test_helpers.hpp"
10 
12 
13 // gtest
14 #include <gtest/gtest.h>
15 
16 namespace gm = grid_map;
17 namespace gmt = grid_map_test;
18 
19 TEST(CubicInterpolation, FlatWorld)
20 {
21  const int seed = rand();
22  gmt::rndGenerator.seed(seed);
23  auto map = gmt::createMap(gm::Length(2.0, 2.0), 0.1, gm::Position(0.0, 0.0));
24  auto trueValues = gmt::createFlatWorld(&map);
25  const auto queryPoints = gmt::uniformlyDitributedPointsWithinMap(map, 100);
26 
27  verifyValuesAtQueryPointsAreClose(map, trueValues, queryPoints, gm::InterpolationMethods::INTER_CUBIC);
28 
29  if (::testing::Test::HasFailure()) {
30  std::cout << "\n Test CubicInterpolation, FlatWorld failed with seed: " << seed << std::endl;
31  }
32 }
33 
34 TEST(CubicInterpolation, RationalFunctionWorld)
35 {
36  const int seed = rand();
37  gmt::rndGenerator.seed(seed);
38  auto map = gmt::createMap(gm::Length(3.0, 3.0), 0.01, gm::Position(0.0, 0.0));
39  auto trueValues = gmt::createRationalFunctionWorld(&map);
40  const auto queryPoints = gmt::uniformlyDitributedPointsWithinMap(map, 1000);
41 
42  verifyValuesAtQueryPointsAreClose(map, trueValues, queryPoints, gm::InterpolationMethods::INTER_CUBIC);
43 
44  if (::testing::Test::HasFailure()) {
45  std::cout << "\n Test CubicInterpolation, RationalFunctionWorld failed with seed: " << seed
46  << std::endl;
47  }
48 }
49 
50 TEST(CubicInterpolation, SaddleWorld)
51 {
52  const int seed = rand();
53  gmt::rndGenerator.seed(seed);
54  auto map = gmt::createMap(gm::Length(3.0, 3.0), 0.1, gm::Position(0.0, 0.0));
55  auto trueValues = gmt::createSaddleWorld(&map);
56  const auto queryPoints = gmt::uniformlyDitributedPointsWithinMap(map, 1000);
57 
58  verifyValuesAtQueryPointsAreClose(map, trueValues, queryPoints, gm::InterpolationMethods::INTER_CUBIC);
59 
60  if (::testing::Test::HasFailure()) {
61  std::cout << "\n Test CubicInterpolation, SaddleWorld failed with seed: " << seed << std::endl;
62  }
63 }
64 
65 TEST(CubicInterpolation, SecondOrderPolyWorld)
66 {
67  const int seed = rand();
68  gmt::rndGenerator.seed(seed);
69  auto map = gmt::createMap(gm::Length(3.0, 3.0), 0.1, gm::Position(0.0, 0.0));
70  auto trueValues = gmt::createSecondOrderPolyWorld(&map);
71  const auto queryPoints = gmt::uniformlyDitributedPointsWithinMap(map, 1000);
72 
73  verifyValuesAtQueryPointsAreClose(map, trueValues, queryPoints, gm::InterpolationMethods::INTER_CUBIC);
74 
75  if (::testing::Test::HasFailure()) {
76  std::cout << "\n Test CubicInterpolation, SecondOrderPolyWorld failed with seed: " << seed
77  << std::endl;
78  }
79 }
80 
81 TEST(CubicInterpolation, SineWorld)
82 {
83  const int seed = rand();
84  gmt::rndGenerator.seed(seed);
85  auto map = gmt::createMap(gm::Length(3.0, 3.0), 0.01, gm::Position(0.0, 0.0));
86  auto trueValues = gmt::createSineWorld(&map);
87  const auto queryPoints = gmt::uniformlyDitributedPointsWithinMap(map, 1000);
88 
89  verifyValuesAtQueryPointsAreClose(map, trueValues, queryPoints, gm::InterpolationMethods::INTER_CUBIC);
90 
91  if (::testing::Test::HasFailure()) {
92  std::cout << "\n Test CubicInterpolation, SineWorld failed with seed: " << seed << std::endl;
93  }
94 }
95 
96 TEST(CubicInterpolation, TanhWorld)
97 {
98  const int seed = rand();
99  gmt::rndGenerator.seed(seed);
100  auto map = gmt::createMap(gm::Length(2.5, 2.5), 0.02, gm::Position(0.0, 0.0));
101  auto trueValues = gmt::createTanhWorld(&map);
102  const auto queryPoints = gmt::uniformlyDitributedPointsWithinMap(map, 1000);
103 
104  verifyValuesAtQueryPointsAreClose(map, trueValues, queryPoints, gm::InterpolationMethods::INTER_CUBIC);
105 
106  if (::testing::Test::HasFailure()) {
107  std::cout << "\n Test CubicInterpolation, TanhWorld failed with seed: " << seed << std::endl;
108  }
109 }
110 
111 TEST(CubicInterpolation, GaussianWorld)
112 {
113  const int seed = rand();
114  gmt::rndGenerator.seed(seed);
115  auto map = gmt::createMap(gm::Length(3.0, 3.0), 0.02, gm::Position(0.0, 0.0));
116  auto trueValues = gmt::createGaussianWorld(&map);
117  const auto queryPoints = gmt::uniformlyDitributedPointsWithinMap(map, 1000);
118 
119  verifyValuesAtQueryPointsAreClose(map, trueValues, queryPoints, gm::InterpolationMethods::INTER_CUBIC);
120 
121  if (::testing::Test::HasFailure()) {
122  std::cout << "\n Test CubicInterpolation, GaussianWorld failed with seed: " << seed
123  << std::endl;
124  }
125 }
126 
std::mt19937 rndGenerator
AnalyticalFunctions createSaddleWorld(grid_map::GridMap *map)
AnalyticalFunctions createTanhWorld(grid_map::GridMap *map)
AnalyticalFunctions createRationalFunctionWorld(grid_map::GridMap *map)
std::vector< Point2D > uniformlyDitributedPointsWithinMap(const grid_map::GridMap &map, unsigned int numPoints)
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)
AnalyticalFunctions createGaussianWorld(grid_map::GridMap *map)
AnalyticalFunctions createSecondOrderPolyWorld(grid_map::GridMap *map)
TEST(CubicInterpolation, FlatWorld)
void verifyValuesAtQueryPointsAreClose(const grid_map::GridMap &map, const AnalyticalFunctions &trueValues, const std::vector< Point2D > &queryPoints, grid_map::InterpolationMethods interpolationMethod)
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