Main MRPT website > C++ reference for 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-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 
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::utils;
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  CPoint2D 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  CPoint2D 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  CPoint2D 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(CSimplePointsMapTests, clipOutOfRangeInZ)
160 {
161  do_test_clipOutOfRangeInZ<CSimplePointsMap>();
162 }
163 
164 TEST(CWeightedPointsMapTests, clipOutOfRangeInZ)
165 {
166  do_test_clipOutOfRangeInZ<CWeightedPointsMap>();
167 }
168 
169 TEST(CColouredPointsMapTests, clipOutOfRangeInZ)
170 {
171  do_test_clipOutOfRangeInZ<CColouredPointsMap>();
172 }
173 
174 TEST(CSimplePointsMapTests, clipOutOfRange)
175 {
176  do_test_clipOutOfRange<CSimplePointsMap>();
177 }
178 
179 TEST(CWeightedPointsMapTests, clipOutOfRange)
180 {
181  do_test_clipOutOfRange<CWeightedPointsMap>();
182 }
183 
184 TEST(CColouredPointsMapTests, clipOutOfRange)
185 {
186  do_test_clipOutOfRange<CColouredPointsMap>();
187 }
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
GLdouble GLdouble z
Definition: glext.h:3872
const float demo9_zs[demo9_N]
void do_test_clipOutOfRange()
INT32 z2
Definition: jidctint.cpp:130
void do_test_clipOutOfRangeInZ()
const float demo9_xs[demo9_N]
STL namespace.
INT32 z3
Definition: jidctint.cpp:130
This base provides a set of functions for maths stuff.
Definition: CArrayNumeric.h:19
This namespace contains representation of robot actions and observations.
const float demo9_ys[demo9_N]
A class used to store a 2D point.
Definition: CPoint2D.h:36
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
Definition: CPoint.h:17
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



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019