MRPT  1.9.9
CPointsMap_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-2018, 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 
13 #include <mrpt/poses/CPoint2D.h>
14 #include <gtest/gtest.h>
15 
16 using namespace mrpt;
17 using namespace mrpt::maps;
18 using namespace mrpt::obs;
19 using namespace mrpt::poses;
20 using namespace mrpt::math;
21 using namespace std;
22 
23 const size_t demo9_N = 9;
24 const float demo9_xs[demo9_N] = {0, 0, 0, 1, 1, 1, 2, 2, 2};
25 const float demo9_ys[demo9_N] = {0, 1, 2, 0, 1, 2, 0, 1, 2};
26 const float demo9_zs[demo9_N] = {0, 1, 2, 0, 1, 2, 0, 1, 2};
27 
28 template <class MAP>
29 void load_demo_9pts_map(MAP& pts)
30 {
31  pts.clear();
32  for (size_t i = 0; i < demo9_N; i++)
33  pts.insertPoint(demo9_xs[i], demo9_ys[i], demo9_zs[i]);
34 }
35 
36 template <class MAP>
38 {
39  // test 1: Insert and check expected values:
40  {
41  MAP pts;
42  load_demo_9pts_map(pts);
43 
44  EXPECT_EQ(pts.size(), demo9_N);
45 
46  for (size_t i = 0; i < demo9_N; i++)
47  {
48  float x, y, z;
49  pts.getPoint(i, x, y, z);
50  EXPECT_EQ(x, demo9_xs[i]);
51  EXPECT_EQ(y, demo9_ys[i]);
52  EXPECT_EQ(z, demo9_zs[i]);
53  }
54  }
55 
56  // test 2: Copy between maps
57  {
58  MAP pts1;
59  load_demo_9pts_map(pts1);
60 
61  MAP pts2 = pts1;
62  MAP pts3 = pts1;
63 
64  EXPECT_EQ(pts2.size(), pts3.size());
65  for (size_t i = 0; i < demo9_N; i++)
66  {
67  float x2, y2, z2;
68  float x3, y3, z3;
69  pts2.getPoint(i, x2, y2, z2);
70  pts3.getPoint(i, x3, y3, z3);
71  EXPECT_EQ(x2, x3);
72  EXPECT_EQ(y2, y3);
73  EXPECT_EQ(z2, z3);
74  }
75  }
76 }
77 
78 template <class MAP>
80 {
81  MAP pts0;
82  load_demo_9pts_map(pts0);
83 
84  // Clip: z=[-10,-1] -> 0 pts
85  {
86  MAP pts = pts0;
87  pts.clipOutOfRangeInZ(-10, -1);
88  EXPECT_EQ(pts.size(), 0u);
89  }
90 
91  // Clip: z=[-10,10] -> 9 pts
92  {
93  MAP pts = pts0;
94  pts.clipOutOfRangeInZ(-10, 10);
95  EXPECT_EQ(pts.size(), 9u);
96  }
97 
98  // Clip: z=[0.5,1.5] -> 3 pts
99  {
100  MAP pts = pts0;
101  pts.clipOutOfRangeInZ(0.5, 1.5);
102  EXPECT_EQ(pts.size(), 3u);
103  }
104 }
105 
106 template <class MAP>
108 {
109  MAP pts0;
110  load_demo_9pts_map(pts0);
111 
112  // Clip:
113  {
114  TPoint2D pivot(0, 0);
115  const float radius = 0.5;
116 
117  MAP pts = pts0;
118  pts.clipOutOfRange(pivot, radius);
119  EXPECT_EQ(pts.size(), 1u);
120  }
121 
122  // Clip:
123  {
124  TPoint2D pivot(-10, -10);
125  const float radius = 1;
126 
127  MAP pts = pts0;
128  pts.clipOutOfRange(pivot, radius);
129  EXPECT_EQ(pts.size(), 0u);
130  }
131 
132  // Clip:
133  {
134  TPoint2D pivot(0, 0);
135  const float radius = 1.1f;
136 
137  MAP pts = pts0;
138  pts.clipOutOfRange(pivot, radius);
139  EXPECT_EQ(pts.size(), 3u);
140  }
141 }
142 
143 TEST(CSimplePointsMapTests, insertPoints)
144 {
145  do_test_insertPoints<CSimplePointsMap>();
146 }
147 
148 TEST(CWeightedPointsMapTests, insertPoints)
149 {
150  do_test_insertPoints<CWeightedPointsMap>();
151 }
152 
153 TEST(CColouredPointsMapTests, insertPoints)
154 {
155  do_test_insertPoints<CColouredPointsMap>();
156 }
157 
158 TEST(CSimplePointsMapTests, clipOutOfRangeInZ)
159 {
160  do_test_clipOutOfRangeInZ<CSimplePointsMap>();
161 }
162 
163 TEST(CWeightedPointsMapTests, clipOutOfRangeInZ)
164 {
165  do_test_clipOutOfRangeInZ<CWeightedPointsMap>();
166 }
167 
168 TEST(CColouredPointsMapTests, clipOutOfRangeInZ)
169 {
170  do_test_clipOutOfRangeInZ<CColouredPointsMap>();
171 }
172 
173 TEST(CSimplePointsMapTests, clipOutOfRange)
174 {
175  do_test_clipOutOfRange<CSimplePointsMap>();
176 }
177 
178 TEST(CWeightedPointsMapTests, clipOutOfRange)
179 {
180  do_test_clipOutOfRange<CWeightedPointsMap>();
181 }
182 
183 TEST(CColouredPointsMapTests, clipOutOfRange)
184 {
185  do_test_clipOutOfRange<CColouredPointsMap>();
186 }
GLdouble GLdouble z
Definition: glext.h:3872
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()
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
TEST(CSimplePointsMapTests, insertPoints)
GLenum GLint GLint y
Definition: glext.h:3538
GLenum GLint x
Definition: glext.h:3538
Lightweight 2D point.



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 7d5e6d718 Fri Aug 24 01:51:28 2018 +0200 at lun nov 2 08:35:50 CET 2020