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 
00042 
00044         ref3DCopy = DP(ref3D.features, ref3D.featureLabels);
00045         EXPECT_TRUE(ref3DCopy.features == ref3D.features);
00046         EXPECT_TRUE(ref3DCopy.featureLabels == ref3D.featureLabels);
00047         
00048         // descriptor missing in ref3DCopy
00049         EXPECT_FALSE(ref3DCopy == ref3D); 
00050         
00051         EXPECT_TRUE(ref3DCopy.descriptors.rows() == 0);
00052         EXPECT_TRUE(ref3DCopy.descriptors.cols() == 0);
00053 
00055         ref3DCopy = DP(ref3D.features, ref3D.featureLabels, ref3D.descriptors, ref3D.descriptorLabels);
00056         
00057         EXPECT_TRUE(ref3DCopy.features == ref3D.features);
00058         EXPECT_TRUE(ref3DCopy.featureLabels == ref3D.featureLabels);
00059         EXPECT_TRUE(ref3DCopy.descriptors== ref3D.descriptors);
00060         EXPECT_TRUE(ref3DCopy.descriptorLabels == ref3D.descriptorLabels);
00061         
00062 
00063         EXPECT_TRUE(ref3DCopy == ref3D); 
00064         
00066         ref3DCopy = DP(ref3D);
00067         
00068         EXPECT_TRUE(ref3DCopy.features == ref3D.features);
00069         EXPECT_TRUE(ref3DCopy.featureLabels == ref3D.featureLabels);
00070         EXPECT_TRUE(ref3DCopy.descriptors== ref3D.descriptors);
00071         EXPECT_TRUE(ref3DCopy.descriptorLabels == ref3D.descriptorLabels);
00072         
00073 
00074         EXPECT_TRUE(ref3DCopy == ref3D);
00075 }
00076 
00077 TEST(PointCloudTest, ConcatenateFeatures2D)
00078 {
00079         const int leftPoints(ref2D.features.cols() / 2);
00080         const int rightPoints(ref2D.features.cols() - leftPoints);
00081         DP lefts(
00082                 ref2D.features.leftCols(leftPoints),
00083                 ref2D.featureLabels
00084         );
00085         DP rights(
00086                 ref2D.features.rightCols(rightPoints),
00087                 ref2D.featureLabels
00088         );
00089         lefts.concatenate(rights);
00090         EXPECT_TRUE(lefts == ref2D);
00091 }
00092 
00093 TEST(PointCloudTest, ConcatenateFeatures3D)
00094 {
00095         const int leftPoints(ref3D.features.cols() / 2);
00096         const int rightPoints(ref3D.features.cols() - leftPoints);
00097         DP lefts(
00098                 ref3D.features.leftCols(leftPoints),
00099                 ref3D.featureLabels
00100         );
00101         DP rights(
00102                 ref3D.features.rightCols(rightPoints),
00103                 ref3D.featureLabels
00104         );
00105         lefts.concatenate(rights);
00106         EXPECT_TRUE(lefts.features == ref3D.features);
00107 }
00108 
00109 TEST(PointCloudTest, ConcatenateDescSame)
00110 {
00111         typedef DP::Label Label;
00112         typedef DP::Labels Labels;
00113         
00114         const int leftPoints(ref2D.features.cols() / 2);
00115         const int rightPoints(ref2D.features.cols() - leftPoints);
00116         DP lefts(
00117                 ref2D.features.leftCols(leftPoints),
00118                 ref2D.featureLabels,
00119                 PM::Matrix::Random(5, leftPoints),
00120                 Labels(Label("Desc5D", 5))
00121         );
00122         DP rights(
00123                 ref2D.features.rightCols(rightPoints),
00124                 ref2D.featureLabels,
00125                 PM::Matrix::Random(5, rightPoints),
00126                 Labels(Label("Desc5D", 5))
00127         );
00128         lefts.concatenate(rights);
00129         EXPECT_TRUE(lefts.descriptors.rows() == 5);
00130         EXPECT_TRUE(lefts.descriptors.cols() == lefts.features.cols());
00131 }
00132 
00133 TEST(PointCloudTest, ConcatenateDescSame2)
00134 {
00135         typedef DP::Label Label;
00136         typedef DP::Labels Labels;
00137         
00138         DP ref3DCopy(ref3D.features, ref3D.featureLabels);
00139         ref3DCopy.descriptorLabels.push_back(Label("Desc5D", 5));
00140         ref3DCopy.descriptors = PM::Matrix::Random(5, ref3DCopy.features.cols());
00141         
00142         const int leftPoints(ref3DCopy.features.cols() / 2);
00143         const int rightPoints(ref3DCopy.features.cols() - leftPoints);
00144         DP lefts(
00145                 ref3DCopy.features.leftCols(leftPoints),
00146                 ref3DCopy.featureLabels,
00147                 ref3DCopy.descriptors.leftCols(leftPoints),
00148                 ref3DCopy.descriptorLabels
00149         );
00150         DP rights(
00151                 ref3DCopy.features.rightCols(rightPoints),
00152                 ref3DCopy.featureLabels,
00153                 ref3DCopy.descriptors.rightCols(rightPoints),
00154                 ref3DCopy.descriptorLabels
00155         );
00156         lefts.concatenate(rights);
00157         EXPECT_TRUE(lefts == ref3DCopy);
00158 }
00159 
00160 TEST(PointCloudTest, ConcatenateDescDiffName)
00161 {
00162         typedef DP::Label Label;
00163         typedef DP::Labels Labels;
00164         
00165         const int leftPoints(ref2D.features.cols() / 2);
00166         const int rightPoints(ref2D.features.cols() - leftPoints);
00167         DP lefts(
00168                 ref2D.features.leftCols(leftPoints),
00169                 ref2D.featureLabels,
00170                 PM::Matrix::Random(5, leftPoints),
00171                 Labels(Label("MyDesc5D", 5))
00172         );
00173         DP rights(
00174                 ref2D.features.rightCols(rightPoints),
00175                 ref2D.featureLabels,
00176                 PM::Matrix::Random(5, rightPoints),
00177                 Labels(Label("YourDesc5D", 5))
00178         );
00179         lefts.concatenate(rights);
00180         EXPECT_TRUE(lefts.descriptors.rows() == 0);
00181         EXPECT_TRUE(lefts.descriptors.cols() == 0);
00182 }
00183 
00184 TEST(PointCloudTest, ConcatenateDescDiffSize)
00185 {
00186         typedef DP::Label Label;
00187         typedef DP::Labels Labels;
00188         
00189         const int leftPoints(ref2D.features.cols() / 2);
00190         const int rightPoints(ref2D.features.cols() - leftPoints);
00191         DP lefts(
00192                 ref2D.features.leftCols(leftPoints),
00193                 ref2D.featureLabels,
00194                 PM::Matrix::Random(3, leftPoints),
00195                 Labels(Label("DescND", 3))
00196         );
00197         DP rights(
00198                 ref2D.features.rightCols(rightPoints),
00199                 ref2D.featureLabels,
00200                 PM::Matrix::Random(5, rightPoints),
00201                 Labels(Label("DescND", 5))
00202         );
00203         EXPECT_THROW(lefts.concatenate(rights), DP::InvalidField);
00204 }
00205 
00206 TEST(PointCloudTest, GetInfo)
00207 {
00208         //cerr << ref2D.features.rows() << endl;
00209         //cerr << ref2D.features.cols() << endl;
00210         //cerr << ref2D.descriptors.rows() << endl;
00211         //cerr << ref2D.descriptors.cols() << endl;
00212         
00213         EXPECT_EQ(ref3D.getNbPoints(), 24989u);
00214         EXPECT_EQ(ref3D.getEuclideanDim(), 3u);
00215         EXPECT_EQ(ref3D.getHomogeneousDim(), 4u);
00216         EXPECT_EQ(ref3D.getNbGroupedDescriptors(), 1u);
00217         EXPECT_EQ(ref3D.getDescriptorDim(), 3u);
00218         
00219         EXPECT_EQ(ref2D.getNbPoints(), 361u);
00220         EXPECT_EQ(ref2D.getEuclideanDim(), 2u);
00221         EXPECT_EQ(ref2D.getHomogeneousDim(), 3u);
00222         EXPECT_EQ(ref2D.getNbGroupedDescriptors(), 0u);
00223         EXPECT_EQ(ref2D.getDescriptorDim(), 0u);
00224 
00225 }
00226 
00227 TEST(PointCloudTest, AddRemove)
00228 {
00229         DP ref3DCopy = ref3D;
00230         const int testedValue = 9;
00231 
00233         PM::Matrix newFeature = PM::Matrix::Ones(1,ref3DCopy.getNbPoints())*testedValue;
00234         ref3DCopy.addFeature("testF", newFeature);
00235 
00236         //Is the new row added?
00237         EXPECT_EQ(ref3DCopy.getHomogeneousDim(), ref3D.getHomogeneousDim()+1);
00238         
00239         //Is padding still at the end?
00240         EXPECT_EQ(ref3DCopy.featureLabels.back().text, "pad");
00241 
00242         //Is the value right?
00243         DP::View newFeatureView = ref3DCopy.getFeatureViewByName("testF");
00244         EXPECT_EQ(newFeatureView(0,0), testedValue);
00245 
00247         ref3DCopy.removeFeature("testF");
00248 
00249         // Is the extra data removed?
00250         EXPECT_TRUE(ref3DCopy.features.isApprox(ref3D.features));
00251 
00252 
00254         const int testedValue2 = 88;
00255         PM::Matrix newDescriptor4D = PM::Matrix::Ones(4,ref3DCopy.getNbPoints())*testedValue;
00256         PM::Matrix newDescriptor2D = PM::Matrix::Ones(2,ref3DCopy.getNbPoints())*testedValue2;
00257 
00258         ref3DCopy.addDescriptor("test4D", newDescriptor4D);
00259         ref3DCopy.addDescriptor("test2D", newDescriptor2D);
00260         
00261         //Is the new row added?
00262         EXPECT_EQ(ref3DCopy.getDescriptorDim(), ref3D.getDescriptorDim()+6);
00263         EXPECT_EQ(ref3DCopy.getNbGroupedDescriptors(), ref3D.getNbGroupedDescriptors()+2);
00264 
00265         //Is the value right?
00266         DP::View newDescriptor4DView = ref3DCopy.getDescriptorViewByName("test4D");
00267         EXPECT_EQ(newDescriptor4DView(0,0), testedValue);
00268         DP::View newDescriptor2DView = ref3DCopy.getDescriptorViewByName("test2D");
00269         EXPECT_EQ(newDescriptor2DView(0,0), testedValue2);
00270 
00271 
00273         ref3DCopy.removeDescriptor("test4D");
00274         ref3DCopy.removeDescriptor("test2D");
00275         
00276         //removing random name shoudn't have any effect
00277         ref3DCopy.removeDescriptor("grrrrr");
00278 
00279         // Is the extra data removed?
00280         EXPECT_TRUE(ref3DCopy.descriptors.isApprox(ref3D.descriptors));
00281 
00282 }


upstream_src
Author(s):
autogenerated on Mon Oct 6 2014 10:27:39