DataPoints.cpp
Go to the documentation of this file.
00001 #include "../utest.h"
00002 
00003 using namespace std;
00004 using namespace PointMatcherSupport;
00005 
00006 //---------------------------
00007 // Point-cloud structures
00008 //---------------------------
00009 
00010 TEST(PointCloudTest, CopyConstructor2D)
00011 {
00012         const DP ref2DCopy(ref2D);
00013         EXPECT_TRUE(ref2DCopy.features == ref2D.features);
00014         EXPECT_TRUE(ref2DCopy.featureLabels == ref2D.featureLabels);
00015         EXPECT_TRUE(ref2DCopy.descriptors == ref2D.descriptors);
00016         EXPECT_TRUE(ref2DCopy.descriptorLabels == ref2D.descriptorLabels);
00017         EXPECT_TRUE(ref2DCopy == ref2D);
00018 }
00019 
00020 
00021 TEST(PointCloudTest, FeatureConstructor2D)
00022 {
00023         const DP ref2DCopy(ref2D.features, ref2D.featureLabels);
00024         EXPECT_TRUE(ref2DCopy.features == ref2D.features);
00025         EXPECT_TRUE(ref2DCopy.featureLabels == ref2D.featureLabels);
00026         EXPECT_TRUE(ref2DCopy == ref2D);
00027         EXPECT_TRUE(ref2DCopy.descriptors.rows() == 0);
00028         EXPECT_TRUE(ref2DCopy.descriptors.cols() == 0);
00029 }
00030 
00031 TEST(PointCloudTest, FeatureConstructor3D)
00032 {
00033         // Note: this test cover also the operator ==
00034 
00036         DP ref3DCopy = DP();
00037         EXPECT_TRUE(ref3DCopy.features.rows() == 0);
00038         EXPECT_TRUE(ref3DCopy.features.cols() == 0);
00039         EXPECT_TRUE(ref3DCopy.descriptors.rows() == 0);
00040         EXPECT_TRUE(ref3DCopy.descriptors.cols() == 0);
00041         EXPECT_TRUE(ref3DCopy.times.rows() == 0);
00042         EXPECT_TRUE(ref3DCopy.times.cols() == 0);
00043 
00044 
00046         ref3DCopy = DP(ref3D.features, ref3D.featureLabels);
00047         EXPECT_TRUE(ref3DCopy.features == ref3D.features);
00048         EXPECT_TRUE(ref3DCopy.featureLabels == ref3D.featureLabels);
00049         
00050         // descriptor missing in ref3DCopy
00051         EXPECT_FALSE(ref3DCopy == ref3D); 
00052         
00053         EXPECT_TRUE(ref3DCopy.descriptors.rows() == 0);
00054         EXPECT_TRUE(ref3DCopy.descriptors.cols() == 0);
00055 
00057         ref3DCopy = DP(ref3D.features, ref3D.featureLabels, ref3D.descriptors, ref3D.descriptorLabels);
00058         
00059         EXPECT_TRUE(ref3DCopy.features == ref3D.features);
00060         EXPECT_TRUE(ref3DCopy.featureLabels == ref3D.featureLabels);
00061         EXPECT_TRUE(ref3DCopy.descriptors== ref3D.descriptors);
00062         EXPECT_TRUE(ref3DCopy.descriptorLabels == ref3D.descriptorLabels);
00063         
00064 
00065         EXPECT_TRUE(ref3DCopy == ref3D); 
00066         
00068         ref3DCopy = DP(ref3D);
00069         
00070         EXPECT_TRUE(ref3DCopy.features == ref3D.features);
00071         EXPECT_TRUE(ref3DCopy.featureLabels == ref3D.featureLabels);
00072         EXPECT_TRUE(ref3DCopy.descriptors== ref3D.descriptors);
00073         EXPECT_TRUE(ref3DCopy.descriptorLabels == ref3D.descriptorLabels);
00074         
00075 
00076         EXPECT_TRUE(ref3DCopy == ref3D);
00077 }
00078 
00079 
00080 TEST(PointCloudTest, ConstructorWithData)
00081 {
00082         const int nbPoints = 100;
00083         const int dimFeatures = 4;
00084         const int dimDescriptors = 3;
00085         const int dimTime = 2;
00086 
00087         PM::Matrix randFeat = PM::Matrix::Random(dimFeatures, nbPoints);
00088         DP::Labels featLabels;
00089         featLabels.push_back(DP::Label("x", 1));
00090         featLabels.push_back(DP::Label("y", 1));
00091         featLabels.push_back(DP::Label("z", 1));
00092         featLabels.push_back(DP::Label("pad", 1));
00093 
00094         PM::Matrix randDesc = PM::Matrix::Random(dimDescriptors, nbPoints);
00095         DP::Labels descLabels;
00096         descLabels.push_back(DP::Label("dummyDesc", 3));
00097 
00098         PM::Int64Matrix randTimes = PM::Int64Matrix::Random(dimTime, nbPoints);
00099         DP::Labels timeLabels;
00100         timeLabels.push_back(DP::Label("dummyTime", 2));
00101 
00102         // Construct the point cloud from the generated matrices
00103         DP pointCloud = DP(randFeat, featLabels, randDesc, descLabels, randTimes, timeLabels);
00104         
00105         EXPECT_EQ(pointCloud.features.rows(), dimFeatures);
00106         EXPECT_EQ(pointCloud.features.cols(), nbPoints);
00107         EXPECT_EQ(pointCloud.descriptors.rows(), dimDescriptors);
00108         EXPECT_EQ(pointCloud.descriptors.cols(), nbPoints);
00109         EXPECT_EQ(pointCloud.times.rows(), dimTime);
00110         EXPECT_EQ(pointCloud.times.cols(), nbPoints);
00111 
00112 
00113 
00114 }
00115 
00116 TEST(PointCloudTest, ConcatenateFeatures2D)
00117 {
00118         const int leftPoints(ref2D.features.cols() / 2);
00119         const int rightPoints(ref2D.features.cols() - leftPoints);
00120         DP lefts(
00121                 ref2D.features.leftCols(leftPoints),
00122                 ref2D.featureLabels
00123         );
00124         DP rights(
00125                 ref2D.features.rightCols(rightPoints),
00126                 ref2D.featureLabels
00127         );
00128         lefts.concatenate(rights);
00129         EXPECT_TRUE(lefts == ref2D);
00130 }
00131 
00132 TEST(PointCloudTest, ConcatenateFeatures3D)
00133 {
00134         const int leftPoints(ref3D.features.cols() / 2);
00135         const int rightPoints(ref3D.features.cols() - leftPoints);
00136         DP lefts(
00137                 ref3D.features.leftCols(leftPoints),
00138                 ref3D.featureLabels
00139         );
00140         DP rights(
00141                 ref3D.features.rightCols(rightPoints),
00142                 ref3D.featureLabels
00143         );
00144         lefts.concatenate(rights);
00145         EXPECT_TRUE(lefts.features == ref3D.features);
00146 }
00147 
00148 TEST(PointCloudTest, ConcatenateDescSame)
00149 {
00150         typedef DP::Label Label;
00151         typedef DP::Labels Labels;
00152         
00153         const int leftPoints(ref2D.features.cols() / 2);
00154         const int rightPoints(ref2D.features.cols() - leftPoints);
00155         DP lefts(
00156                 ref2D.features.leftCols(leftPoints),
00157                 ref2D.featureLabels,
00158                 PM::Matrix::Random(5, leftPoints),
00159                 Labels(Label("Desc5D", 5))
00160         );
00161         DP rights(
00162                 ref2D.features.rightCols(rightPoints),
00163                 ref2D.featureLabels,
00164                 PM::Matrix::Random(5, rightPoints),
00165                 Labels(Label("Desc5D", 5))
00166         );
00167         lefts.concatenate(rights);
00168         EXPECT_TRUE(lefts.descriptors.rows() == 5);
00169         EXPECT_TRUE(lefts.descriptors.cols() == lefts.features.cols());
00170 }
00171 
00172 TEST(PointCloudTest, ConcatenateDescSame2)
00173 {
00174         typedef DP::Label Label;
00175         
00176         DP ref3DCopy(ref3D.features, ref3D.featureLabels);
00177         ref3DCopy.descriptorLabels.push_back(Label("Desc5D", 5));
00178         ref3DCopy.descriptors = PM::Matrix::Random(5, ref3DCopy.features.cols());
00179         
00180         const int leftPoints(ref3DCopy.features.cols() / 2);
00181         const int rightPoints(ref3DCopy.features.cols() - leftPoints);
00182         DP lefts(
00183                 ref3DCopy.features.leftCols(leftPoints),
00184                 ref3DCopy.featureLabels,
00185                 ref3DCopy.descriptors.leftCols(leftPoints),
00186                 ref3DCopy.descriptorLabels
00187         );
00188         DP rights(
00189                 ref3DCopy.features.rightCols(rightPoints),
00190                 ref3DCopy.featureLabels,
00191                 ref3DCopy.descriptors.rightCols(rightPoints),
00192                 ref3DCopy.descriptorLabels
00193         );
00194         lefts.concatenate(rights);
00195         EXPECT_TRUE(lefts == ref3DCopy);
00196 }
00197 
00198 TEST(PointCloudTest, ConcatenateDescDiffName)
00199 {
00200         typedef DP::Label Label;
00201         typedef DP::Labels Labels;
00202         
00203         const int leftPoints(ref2D.features.cols() / 2);
00204         const int rightPoints(ref2D.features.cols() - leftPoints);
00205         DP lefts(
00206                 ref2D.features.leftCols(leftPoints),
00207                 ref2D.featureLabels,
00208                 PM::Matrix::Random(5, leftPoints),
00209                 Labels(Label("MyDesc5D", 5))
00210         );
00211         DP rights(
00212                 ref2D.features.rightCols(rightPoints),
00213                 ref2D.featureLabels,
00214                 PM::Matrix::Random(5, rightPoints),
00215                 Labels(Label("YourDesc5D", 5))
00216         );
00217         lefts.concatenate(rights);
00218         EXPECT_TRUE(lefts.descriptors.rows() == 0);
00219         EXPECT_TRUE(lefts.descriptors.cols() == 0);
00220 }
00221 
00222 TEST(PointCloudTest, ConcatenateDescDiffSize)
00223 {
00224         typedef DP::Label Label;
00225         typedef DP::Labels Labels;
00226         
00227         const int leftPoints(ref2D.features.cols() / 2);
00228         const int rightPoints(ref2D.features.cols() - leftPoints);
00229         DP lefts(
00230                 ref2D.features.leftCols(leftPoints),
00231                 ref2D.featureLabels,
00232                 PM::Matrix::Random(3, leftPoints),
00233                 Labels(Label("DescND", 3))
00234         );
00235         DP rights(
00236                 ref2D.features.rightCols(rightPoints),
00237                 ref2D.featureLabels,
00238                 PM::Matrix::Random(5, rightPoints),
00239                 Labels(Label("DescND", 5))
00240         );
00241         EXPECT_THROW(lefts.concatenate(rights), DP::InvalidField);
00242 }
00243 
00244 TEST(PointCloudTest, AssertConsistency)
00245 {
00246         DP ref2DCopy(ref2D);
00247 
00248   // Point cloud is in order after loading it
00249   EXPECT_NO_THROW(ref2DCopy.assertDescriptorConsistency());
00250 
00251   // We add only a descriptor label without descriptor
00252   PM::DataPoints::Labels labels;
00253   labels.push_back(PM::DataPoints::Label("FakeDesc", 2));
00254   ref2DCopy.descriptorLabels = labels;
00255         EXPECT_THROW(ref2DCopy.assertDescriptorConsistency(), std::runtime_error);
00256  
00257 
00258   // We add a descriptor with the wrong number of points
00259   PM::Matrix descriptors = PM::Matrix::Random(2, 10);
00260   ref2DCopy.descriptors = descriptors;
00261         
00262   EXPECT_THROW(ref2DCopy.assertDescriptorConsistency(), std::runtime_error);
00263   
00264   // We add a descriptor with the wrong dimension
00265   descriptors = PM::Matrix::Random(1, ref2DCopy.getNbPoints());
00266   ref2DCopy.descriptors = descriptors;
00267   EXPECT_THROW(ref2DCopy.assertDescriptorConsistency(), std::runtime_error);
00268 
00269 }
00270 
00271 TEST(PointCloudTest, GetInfo)
00272 {
00273         //cerr << ref2D.features.rows() << endl;
00274         //cerr << ref2D.features.cols() << endl;
00275         //cerr << ref2D.descriptors.rows() << endl;
00276         //cerr << ref2D.descriptors.cols() << endl;
00277         
00278         EXPECT_EQ(ref3D.getNbPoints(), 24989u);
00279         EXPECT_EQ(ref3D.getEuclideanDim(), 3u);
00280         EXPECT_EQ(ref3D.getHomogeneousDim(), 4u);
00281         EXPECT_EQ(ref3D.getNbGroupedDescriptors(), 1u);
00282         EXPECT_EQ(ref3D.getDescriptorDim(), 3u);
00283         
00284         EXPECT_EQ(ref2D.getNbPoints(), 361u);
00285         EXPECT_EQ(ref2D.getEuclideanDim(), 2u);
00286         EXPECT_EQ(ref2D.getHomogeneousDim(), 3u);
00287         EXPECT_EQ(ref2D.getNbGroupedDescriptors(), 0u);
00288         EXPECT_EQ(ref2D.getDescriptorDim(), 0u);
00289 
00290 }
00291 
00292 TEST(PointCloudTest, AddRemove)
00293 {
00294         DP ref3DCopy = ref3D;
00295         const int testedValue = 9;
00296 
00298         PM::Matrix newFeature = PM::Matrix::Ones(1,ref3DCopy.getNbPoints())*testedValue;
00299         ref3DCopy.addFeature("testF", newFeature);
00300 
00301         //Is the new row added?
00302         EXPECT_EQ(ref3DCopy.getHomogeneousDim(), ref3D.getHomogeneousDim()+1);
00303         
00304         //Is padding still at the end?
00305         EXPECT_EQ(ref3DCopy.featureLabels.back().text, "pad");
00306 
00307         //Is the value right?
00308         DP::View newFeatureView = ref3DCopy.getFeatureViewByName("testF");
00309         EXPECT_EQ(newFeatureView(0,0), testedValue);
00310 
00312         ref3DCopy.removeFeature("testF");
00313 
00314         // Is the extra data removed?
00315         EXPECT_TRUE(ref3DCopy.features.isApprox(ref3D.features));
00316 
00317 
00319         const int testedValue2 = 88;
00320         PM::Matrix newDescriptor4D = PM::Matrix::Ones(4,ref3DCopy.getNbPoints())*testedValue;
00321         PM::Matrix newDescriptor2D = PM::Matrix::Ones(2,ref3DCopy.getNbPoints())*testedValue2;
00322 
00323         ref3DCopy.addDescriptor("test4D", newDescriptor4D);
00324         ref3DCopy.addDescriptor("test2D", newDescriptor2D);
00325         
00326         //Is the new row added?
00327         EXPECT_EQ(ref3DCopy.getDescriptorDim(), ref3D.getDescriptorDim()+6);
00328         EXPECT_EQ(ref3DCopy.getNbGroupedDescriptors(), ref3D.getNbGroupedDescriptors()+2);
00329 
00330         //Is the value right?
00331         DP::View newDescriptor4DView = ref3DCopy.getDescriptorViewByName("test4D");
00332         EXPECT_EQ(newDescriptor4DView(0,0), testedValue);
00333         DP::View newDescriptor2DView = ref3DCopy.getDescriptorViewByName("test2D");
00334         EXPECT_EQ(newDescriptor2DView(0,0), testedValue2);
00335 
00336 
00338         ref3DCopy.removeDescriptor("test4D");
00339         ref3DCopy.removeDescriptor("test2D");
00340         
00341         //removing random name shoudn't have any effect
00342         ref3DCopy.removeDescriptor("grrrrr");
00343 
00344         // Is the extra data removed?
00345         EXPECT_TRUE(ref3DCopy.descriptors.isApprox(ref3D.descriptors));
00346 
00347 }


libpointmatcher
Author(s):
autogenerated on Thu Jun 20 2019 19:51:29