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



Page generated by Doxygen 1.8.6 for MRPT 1.5.6 Git: 4c65e84 Tue Apr 24 08:18:17 2018 +0200 at mar abr 24 08:26:17 CEST 2018