MRPT  2.0.1
CPointsMap_unittest.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2020, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #include <gtest/gtest.h>
15 #include <mrpt/poses/CPoint2D.h>
16 
17 using namespace mrpt;
18 using namespace mrpt::maps;
19 using namespace mrpt::obs;
20 using namespace mrpt::poses;
21 using namespace mrpt::math;
22 using namespace std;
23 
24 const size_t demo9_N = 9;
25 const float demo9_xs[demo9_N] = {0, 0, 0, 1, 1, 1, 2, 2, 2};
26 const float demo9_ys[demo9_N] = {0, 1, 2, 0, 1, 2, 0, 1, 2};
27 const float demo9_zs[demo9_N] = {0, 1, 2, 0, 1, 2, 0, 1, 2};
28 
29 template <class MAP>
30 void load_demo_9pts_map(MAP& pts)
31 {
32  pts.clear();
33  for (size_t i = 0; i < demo9_N; i++)
34  pts.insertPoint(demo9_xs[i], demo9_ys[i], demo9_zs[i]);
35 }
36 
37 template <class MAP>
39 {
40  // test 1: Insert and check expected values:
41  {
42  MAP pts;
43  load_demo_9pts_map(pts);
44 
45  EXPECT_EQ(pts.size(), demo9_N);
46 
47  for (size_t i = 0; i < demo9_N; i++)
48  {
49  float x, y, z;
50  pts.getPoint(i, x, y, z);
51  EXPECT_EQ(x, demo9_xs[i]);
52  EXPECT_EQ(y, demo9_ys[i]);
53  EXPECT_EQ(z, demo9_zs[i]);
54  }
55  }
56 
57  // test 2: Copy between maps
58  {
59  MAP pts1;
60  load_demo_9pts_map(pts1);
61 
62  MAP pts2 = pts1;
63  MAP pts3 = pts1;
64 
65  EXPECT_EQ(pts2.size(), pts3.size());
66  for (size_t i = 0; i < demo9_N; i++)
67  {
68  float x2, y2, z2;
69  float x3, y3, z3;
70  pts2.getPoint(i, x2, y2, z2);
71  pts3.getPoint(i, x3, y3, z3);
72  EXPECT_EQ(x2, x3);
73  EXPECT_EQ(y2, y3);
74  EXPECT_EQ(z2, z3);
75  }
76  }
77 }
78 
79 template <class MAP>
81 {
82  MAP pts0;
83  load_demo_9pts_map(pts0);
84 
85  // Clip: z=[-10,-1] -> 0 pts
86  {
87  MAP pts = pts0;
88  pts.clipOutOfRangeInZ(-10, -1);
89  EXPECT_EQ(pts.size(), 0u);
90  }
91 
92  // Clip: z=[-10,10] -> 9 pts
93  {
94  MAP pts = pts0;
95  pts.clipOutOfRangeInZ(-10, 10);
96  EXPECT_EQ(pts.size(), 9u);
97  }
98 
99  // Clip: z=[0.5,1.5] -> 3 pts
100  {
101  MAP pts = pts0;
102  pts.clipOutOfRangeInZ(0.5, 1.5);
103  EXPECT_EQ(pts.size(), 3u);
104  }
105 }
106 
107 template <class MAP>
109 {
110  MAP pts0;
111  load_demo_9pts_map(pts0);
112 
113  // Clip:
114  {
115  TPoint2D pivot(0, 0);
116  const float radius = 0.5;
117 
118  MAP pts = pts0;
119  pts.clipOutOfRange(pivot, radius);
120  EXPECT_EQ(pts.size(), 1u);
121  }
122 
123  // Clip:
124  {
125  TPoint2D pivot(-10, -10);
126  const float radius = 1;
127 
128  MAP pts = pts0;
129  pts.clipOutOfRange(pivot, radius);
130  EXPECT_EQ(pts.size(), 0u);
131  }
132 
133  // Clip:
134  {
135  TPoint2D pivot(0, 0);
136  const float radius = 1.1f;
137 
138  MAP pts = pts0;
139  pts.clipOutOfRange(pivot, radius);
140  EXPECT_EQ(pts.size(), 3u);
141  }
142 }
143 
144 TEST(CSimplePointsMapTests, insertPoints)
145 {
146  do_test_insertPoints<CSimplePointsMap>();
147 }
148 
149 TEST(CWeightedPointsMapTests, insertPoints)
150 {
151  do_test_insertPoints<CWeightedPointsMap>();
152 }
153 
154 TEST(CColouredPointsMapTests, insertPoints)
155 {
156  do_test_insertPoints<CColouredPointsMap>();
157 }
158 
159 TEST(CPointsMapXYZI, insertPoints) { do_test_insertPoints<CPointsMapXYZI>(); }
160 
161 TEST(CSimplePointsMapTests, clipOutOfRangeInZ)
162 {
163  do_test_clipOutOfRangeInZ<CSimplePointsMap>();
164 }
165 
166 TEST(CWeightedPointsMapTests, clipOutOfRangeInZ)
167 {
168  do_test_clipOutOfRangeInZ<CWeightedPointsMap>();
169 }
170 
171 TEST(CColouredPointsMapTests, clipOutOfRangeInZ)
172 {
173  do_test_clipOutOfRangeInZ<CColouredPointsMap>();
174 }
175 
176 TEST(CSimplePointsMapTests, clipOutOfRange)
177 {
178  do_test_clipOutOfRange<CSimplePointsMap>();
179 }
180 
181 TEST(CWeightedPointsMapTests, clipOutOfRange)
182 {
183  do_test_clipOutOfRange<CWeightedPointsMap>();
184 }
185 
186 TEST(CColouredPointsMapTests, clipOutOfRange)
187 {
188  do_test_clipOutOfRange<CColouredPointsMap>();
189 }
const float demo9_zs[demo9_N]
void do_test_clipOutOfRange()
void do_test_clipOutOfRangeInZ()
const float demo9_xs[demo9_N]
STL namespace.
This base provides a set of functions for maths stuff.
This namespace contains representation of robot actions and observations.
const float demo9_ys[demo9_N]
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
void load_demo_9pts_map(MAP &pts)
const size_t demo9_N
void do_test_insertPoints()
A map of 3D points with reflectance/intensity (float).
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
EXPECT_EQ(out.image_pair_was_used.size(), NUM_IMGS)
TEST(CSimplePointsMapTests, insertPoints)



Page generated by Doxygen 1.8.14 for MRPT 2.0.1 Git: 0fef1a6d7 Fri Apr 3 23:00:21 2020 +0200 at vie abr 3 23:20:28 CEST 2020