utest/ui/DataPoints.cpp
Go to the documentation of this file.
1 #include "../utest.h"
2 
3 using namespace std;
4 using namespace PointMatcherSupport;
5 
6 //---------------------------
7 // Point-cloud structures
8 //---------------------------
9 
10 TEST(PointCloudTest, CopyConstructor2D)
11 {
12  const DP ref2DCopy(ref2D);
13  EXPECT_TRUE(ref2DCopy.features == ref2D.features);
17  EXPECT_TRUE(ref2DCopy == ref2D);
18 }
19 
20 
21 TEST(PointCloudTest, FeatureConstructor2D)
22 {
23  const DP ref2DCopy(ref2D.features, ref2D.featureLabels);
24  EXPECT_TRUE(ref2DCopy.features == ref2D.features);
26  EXPECT_TRUE(ref2DCopy == ref2D);
27  EXPECT_TRUE(ref2DCopy.descriptors.rows() == 0);
28  EXPECT_TRUE(ref2DCopy.descriptors.cols() == 0);
29 }
30 
31 TEST(PointCloudTest, FeatureConstructor3D)
32 {
33  // Note: this test cover also the operator ==
34 
36  DP ref3DCopy = DP();
37  EXPECT_TRUE(ref3DCopy.features.rows() == 0);
38  EXPECT_TRUE(ref3DCopy.features.cols() == 0);
39  EXPECT_TRUE(ref3DCopy.descriptors.rows() == 0);
40  EXPECT_TRUE(ref3DCopy.descriptors.cols() == 0);
41  EXPECT_TRUE(ref3DCopy.times.rows() == 0);
42  EXPECT_TRUE(ref3DCopy.times.cols() == 0);
43 
44 
46  ref3DCopy = DP(ref3D.features, ref3D.featureLabels);
47  EXPECT_TRUE(ref3DCopy.features == ref3D.features);
49 
50  // descriptor missing in ref3DCopy
51  EXPECT_FALSE(ref3DCopy == ref3D);
52 
53  EXPECT_TRUE(ref3DCopy.descriptors.rows() == 0);
54  EXPECT_TRUE(ref3DCopy.descriptors.cols() == 0);
55 
58 
59  EXPECT_TRUE(ref3DCopy.features == ref3D.features);
63 
64 
65  EXPECT_TRUE(ref3DCopy == ref3D);
66 
68  ref3DCopy = DP(ref3D);
69 
70  EXPECT_TRUE(ref3DCopy.features == ref3D.features);
74 
75 
76  EXPECT_TRUE(ref3DCopy == ref3D);
77 }
78 
79 
80 TEST(PointCloudTest, ConstructorWithData)
81 {
82  const int nbPoints = 100;
83  const int dimFeatures = 4;
84  const int dimDescriptors = 3;
85  const int dimTime = 2;
86 
87  PM::Matrix randFeat = PM::Matrix::Random(dimFeatures, nbPoints);
88  DP::Labels featLabels;
89  featLabels.push_back(DP::Label("x", 1));
90  featLabels.push_back(DP::Label("y", 1));
91  featLabels.push_back(DP::Label("z", 1));
92  featLabels.push_back(DP::Label("pad", 1));
93 
94  PM::Matrix randDesc = PM::Matrix::Random(dimDescriptors, nbPoints);
95  DP::Labels descLabels;
96  descLabels.push_back(DP::Label("dummyDesc", 3));
97 
98  PM::Int64Matrix randTimes = PM::Int64Matrix::Random(dimTime, nbPoints);
99  DP::Labels timeLabels;
100  timeLabels.push_back(DP::Label("dummyTime", 2));
101 
102  // Construct the point cloud from the generated matrices
103  DP pointCloud = DP(randFeat, featLabels, randDesc, descLabels, randTimes, timeLabels);
104 
105  EXPECT_EQ(pointCloud.features.rows(), dimFeatures);
106  EXPECT_EQ(pointCloud.features.cols(), nbPoints);
107  EXPECT_EQ(pointCloud.descriptors.rows(), dimDescriptors);
108  EXPECT_EQ(pointCloud.descriptors.cols(), nbPoints);
109  EXPECT_EQ(pointCloud.times.rows(), dimTime);
110  EXPECT_EQ(pointCloud.times.cols(), nbPoints);
111 
112 
113 
114 }
115 
116 TEST(PointCloudTest, ConcatenateFeatures2D)
117 {
118  const int leftPoints(ref2D.features.cols() / 2);
119  const int rightPoints(ref2D.features.cols() - leftPoints);
120  DP lefts(
121  ref2D.features.leftCols(leftPoints),
123  );
124  DP rights(
125  ref2D.features.rightCols(rightPoints),
127  );
128  lefts.concatenate(rights);
129  EXPECT_TRUE(lefts == ref2D);
130 }
131 
132 TEST(PointCloudTest, ConcatenateFeatures3D)
133 {
134  const int leftPoints(ref3D.features.cols() / 2);
135  const int rightPoints(ref3D.features.cols() - leftPoints);
136  DP lefts(
137  ref3D.features.leftCols(leftPoints),
139  );
140  DP rights(
141  ref3D.features.rightCols(rightPoints),
143  );
144  lefts.concatenate(rights);
146 }
147 
148 TEST(PointCloudTest, ConcatenateDescSame)
149 {
150  typedef DP::Label Label;
151  typedef DP::Labels Labels;
152 
153  const int leftPoints(ref2D.features.cols() / 2);
154  const int rightPoints(ref2D.features.cols() - leftPoints);
155  DP lefts(
156  ref2D.features.leftCols(leftPoints),
158  PM::Matrix::Random(5, leftPoints),
159  Labels(Label("Desc5D", 5))
160  );
161  DP rights(
162  ref2D.features.rightCols(rightPoints),
164  PM::Matrix::Random(5, rightPoints),
165  Labels(Label("Desc5D", 5))
166  );
167  lefts.concatenate(rights);
168  EXPECT_TRUE(lefts.descriptors.rows() == 5);
169  EXPECT_TRUE(lefts.descriptors.cols() == lefts.features.cols());
170 }
171 
172 TEST(PointCloudTest, ConcatenateDescSame2)
173 {
174  typedef DP::Label Label;
175 
176  DP ref3DCopy(ref3D.features, ref3D.featureLabels);
177  ref3DCopy.descriptorLabels.push_back(Label("Desc5D", 5));
178  ref3DCopy.descriptors = PM::Matrix::Random(5, ref3DCopy.features.cols());
179 
180  const int leftPoints(ref3DCopy.features.cols() / 2);
181  const int rightPoints(ref3DCopy.features.cols() - leftPoints);
182  DP lefts(
183  ref3DCopy.features.leftCols(leftPoints),
184  ref3DCopy.featureLabels,
185  ref3DCopy.descriptors.leftCols(leftPoints),
186  ref3DCopy.descriptorLabels
187  );
188  DP rights(
189  ref3DCopy.features.rightCols(rightPoints),
190  ref3DCopy.featureLabels,
191  ref3DCopy.descriptors.rightCols(rightPoints),
192  ref3DCopy.descriptorLabels
193  );
194  lefts.concatenate(rights);
195  EXPECT_TRUE(lefts == ref3DCopy);
196 }
197 
198 TEST(PointCloudTest, ConcatenateDescDiffName)
199 {
200  typedef DP::Label Label;
201  typedef DP::Labels Labels;
202 
203  const int leftPoints(ref2D.features.cols() / 2);
204  const int rightPoints(ref2D.features.cols() - leftPoints);
205  DP lefts(
206  ref2D.features.leftCols(leftPoints),
208  PM::Matrix::Random(5, leftPoints),
209  Labels(Label("MyDesc5D", 5))
210  );
211  DP rights(
212  ref2D.features.rightCols(rightPoints),
214  PM::Matrix::Random(5, rightPoints),
215  Labels(Label("YourDesc5D", 5))
216  );
217  lefts.concatenate(rights);
218  EXPECT_TRUE(lefts.descriptors.rows() == 0);
219  EXPECT_TRUE(lefts.descriptors.cols() == 0);
220 }
221 
222 TEST(PointCloudTest, ConcatenateDescDiffSize)
223 {
224  typedef DP::Label Label;
225  typedef DP::Labels Labels;
226 
227  const int leftPoints(ref2D.features.cols() / 2);
228  const int rightPoints(ref2D.features.cols() - leftPoints);
229  DP lefts(
230  ref2D.features.leftCols(leftPoints),
232  PM::Matrix::Random(3, leftPoints),
233  Labels(Label("DescND", 3))
234  );
235  DP rights(
236  ref2D.features.rightCols(rightPoints),
238  PM::Matrix::Random(5, rightPoints),
239  Labels(Label("DescND", 5))
240  );
241  EXPECT_THROW(lefts.concatenate(rights), DP::InvalidField);
242 }
243 
244 TEST(PointCloudTest, AssertConsistency)
245 {
246  DP ref2DCopy(ref2D);
247 
248  // Point cloud is in order after loading it
250 
251  // We add only a descriptor label without descriptor
252  PM::DataPoints::Labels labels;
253  labels.push_back(PM::DataPoints::Label("FakeDesc", 2));
254  ref2DCopy.descriptorLabels = labels;
255  EXPECT_THROW(ref2DCopy.assertDescriptorConsistency(), std::runtime_error);
256 
257 
258  // We add a descriptor with the wrong number of points
259  PM::Matrix descriptors = PM::Matrix::Random(2, 10);
260  ref2DCopy.descriptors = descriptors;
261 
262  EXPECT_THROW(ref2DCopy.assertDescriptorConsistency(), std::runtime_error);
263 
264  // We add a descriptor with the wrong dimension
265  descriptors = PM::Matrix::Random(1, ref2DCopy.getNbPoints());
266  ref2DCopy.descriptors = descriptors;
267  EXPECT_THROW(ref2DCopy.assertDescriptorConsistency(), std::runtime_error);
268 
269 }
270 
271 TEST(PointCloudTest, GetInfo)
272 {
273  //cerr << ref2D.features.rows() << endl;
274  //cerr << ref2D.features.cols() << endl;
275  //cerr << ref2D.descriptors.rows() << endl;
276  //cerr << ref2D.descriptors.cols() << endl;
277 
278  EXPECT_EQ(ref3D.getNbPoints(), 24989u);
283 
284  EXPECT_EQ(ref2D.getNbPoints(), 361u);
289 
290 }
291 
292 TEST(PointCloudTest, AddRemove)
293 {
294  DP ref3DCopy = ref3D;
295  const int testedValue = 9;
296 
298  PM::Matrix newFeature = PM::Matrix::Ones(1,ref3DCopy.getNbPoints())*testedValue;
299  ref3DCopy.addFeature("testF", newFeature);
300 
301  //Is the new row added?
303 
304  //Is padding still at the end?
305  EXPECT_EQ(ref3DCopy.featureLabels.back().text, "pad");
306 
307  //Is the value right?
308  DP::View newFeatureView = ref3DCopy.getFeatureViewByName("testF");
309  EXPECT_EQ(newFeatureView(0,0), testedValue);
310 
312  ref3DCopy.removeFeature("testF");
313 
314  // Is the extra data removed?
315  EXPECT_TRUE(ref3DCopy.features.isApprox(ref3D.features));
316 
317 
319  const int testedValue2 = 88;
320  PM::Matrix newDescriptor4D = PM::Matrix::Ones(4,ref3DCopy.getNbPoints())*testedValue;
321  PM::Matrix newDescriptor2D = PM::Matrix::Ones(2,ref3DCopy.getNbPoints())*testedValue2;
322 
323  ref3DCopy.addDescriptor("test4D", newDescriptor4D);
324  ref3DCopy.addDescriptor("test2D", newDescriptor2D);
325 
326  //Is the new row added?
329 
330  //Is the value right?
331  DP::View newDescriptor4DView = ref3DCopy.getDescriptorViewByName("test4D");
332  EXPECT_EQ(newDescriptor4DView(0,0), testedValue);
333  DP::View newDescriptor2DView = ref3DCopy.getDescriptorViewByName("test2D");
334  EXPECT_EQ(newDescriptor2DView(0,0), testedValue2);
335 
336 
338  ref3DCopy.removeDescriptor("test4D");
339  ref3DCopy.removeDescriptor("test2D");
340 
341  //removing random name shoudn't have any effect
342  ref3DCopy.removeDescriptor("grrrrr");
343 
344  // Is the extra data removed?
345  EXPECT_TRUE(ref3DCopy.descriptors.isApprox(ref3D.descriptors));
346 
347 }
PointMatcher::DataPoints::getNbGroupedDescriptors
unsigned getNbGroupedDescriptors() const
Return the number of grouped descriptors (e.g., normals can have 3 components but would count as only...
Definition: pointmatcher/DataPoints.cpp:179
PointMatcher::DataPoints::descriptorLabels
Labels descriptorLabels
labels of descriptors
Definition: PointMatcher.h:334
PointMatcher::DataPoints::getEuclideanDim
unsigned getEuclideanDim() const
Return the dimension of the point cloud.
Definition: pointmatcher/DataPoints.cpp:165
PointMatcher::DataPoints::assertDescriptorConsistency
void assertDescriptorConsistency() const
Assert if descriptors are not consistent with features.
Definition: pointmatcher/DataPoints.cpp:610
PointMatcher::DataPoints::Labels
A vector of Label.
Definition: PointMatcher.h:229
PointMatcher::DataPoints::removeFeature
void removeFeature(const std::string &name)
Remove a feature by name, the whole matrix will be copied.
Definition: pointmatcher/DataPoints.cpp:444
PointMatcher::DataPoints::concatenate
void concatenate(const DataPoints &dp)
Add another point cloud after the current one. Faster merge will be achieved if all descriptor and ti...
Definition: pointmatcher/DataPoints.cpp:225
PointMatcher::DataPoints::addFeature
void addFeature(const std::string &name, const Matrix &newFeature)
Add a feature by name, remove first if already exists. The 'pad' field will stay at the end for homog...
Definition: pointmatcher/DataPoints.cpp:435
ref3D
DP ref3D
Definition: utest.cpp:47
PointMatcher::DataPoints::addDescriptor
void addDescriptor(const std::string &name, const Matrix &newDescriptor)
Add a descriptor by name, remove first if already exists.
Definition: pointmatcher/DataPoints.cpp:532
TEST
TEST(PointCloudTest, CopyConstructor2D)
Definition: utest/ui/DataPoints.cpp:10
PointMatcher::DataPoints
A point cloud.
Definition: PointMatcher.h:207
EXPECT_TRUE
#define EXPECT_TRUE(condition)
Definition: gtest.h:19327
PointMatcher::DataPoints::getHomogeneousDim
unsigned getHomogeneousDim() const
Return the dimension of the point cloud in homogeneous coordinates (one more than Euclidean dimension...
Definition: pointmatcher/DataPoints.cpp:172
EXPECT_EQ
#define EXPECT_EQ(expected, actual)
Definition: gtest.h:19747
PointMatcher::DataPoints::InvalidField
An exception thrown when one tries to access features or descriptors unexisting or of wrong dimension...
Definition: PointMatcher.h:250
PointMatcher::DataPoints::getFeatureViewByName
ConstView getFeatureViewByName(const std::string &name) const
Get a const view on a feature by name, throw an exception if it does not exist.
Definition: pointmatcher/DataPoints.cpp:458
PointMatcher< float >::Int64Matrix
Eigen::Matrix< std::int64_t, Eigen::Dynamic, Eigen::Dynamic > Int64Matrix
A dense signed 64-bits matrix.
Definition: PointMatcher.h:173
EXPECT_NO_THROW
#define EXPECT_NO_THROW(statement)
Definition: gtest.h:19313
EXPECT_FALSE
#define EXPECT_FALSE(condition)
Definition: gtest.h:19330
PointMatcher::DataPoints::featureLabels
Labels featureLabels
labels of features
Definition: PointMatcher.h:332
PointMatcher::DataPoints::descriptors
Matrix descriptors
descriptors of points in the cloud, might be empty
Definition: PointMatcher.h:333
PointMatcher< float >::Matrix
Eigen::Matrix< float, Eigen::Dynamic, Eigen::Dynamic > Matrix
A dense matrix over ScalarType.
Definition: PointMatcher.h:169
ref2D
DP ref2D
Definition: utest.cpp:45
PointMatcher::DataPoints::getNbPoints
unsigned getNbPoints() const
Return the number of points contained in the point cloud.
Definition: pointmatcher/DataPoints.cpp:158
PointMatcher::DataPoints::features
Matrix features
features of points in the cloud
Definition: PointMatcher.h:331
PointMatcher::DataPoints::times
Int64Matrix times
time associated to each points, might be empty
Definition: PointMatcher.h:335
std
PointMatcher::DataPoints::removeDescriptor
void removeDescriptor(const std::string &name)
Remove a descriptor by name, the whole matrix will be copied.
Definition: pointmatcher/DataPoints.cpp:539
PointMatcher::DataPoints::getDescriptorDim
unsigned getDescriptorDim() const
Return the total number of descriptors.
Definition: pointmatcher/DataPoints.cpp:186
PointMatcher::DataPoints::View
Eigen::Block< Matrix > View
A view on a feature or descriptor.
Definition: PointMatcher.h:210
EXPECT_THROW
#define EXPECT_THROW(statement, expected_exception)
Definition: gtest.h:19311
PointMatcherSupport
Functions and classes that are not dependant on scalar type are defined in this namespace.
Definition: Bibliography.cpp:45
DP
PM::DataPoints DP
Definition: convert.cpp:45
PointMatcher::DataPoints::getDescriptorViewByName
ConstView getDescriptorViewByName(const std::string &name) const
Get a const view on a descriptor by name, throw an exception if it does not exist.
Definition: pointmatcher/DataPoints.cpp:554
PointMatcher::DataPoints::Label
The name for a certain number of dim.
Definition: PointMatcher.h:221


mp2p_icp
Author(s): Jose-Luis Blanco-Claraco
autogenerated on Tue Jul 2 2024 02:47:23