00001 #include "../utest.h"
00002
00003 using namespace std;
00004 using namespace PointMatcherSupport;
00005
00006
00007
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
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
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
00137 DP ref3DCopy(ref3D.features, ref3D.featureLabels);
00138 ref3DCopy.descriptorLabels.push_back(Label("Desc5D", 5));
00139 ref3DCopy.descriptors = PM::Matrix::Random(5, ref3DCopy.features.cols());
00140
00141 const int leftPoints(ref3DCopy.features.cols() / 2);
00142 const int rightPoints(ref3DCopy.features.cols() - leftPoints);
00143 DP lefts(
00144 ref3DCopy.features.leftCols(leftPoints),
00145 ref3DCopy.featureLabels,
00146 ref3DCopy.descriptors.leftCols(leftPoints),
00147 ref3DCopy.descriptorLabels
00148 );
00149 DP rights(
00150 ref3DCopy.features.rightCols(rightPoints),
00151 ref3DCopy.featureLabels,
00152 ref3DCopy.descriptors.rightCols(rightPoints),
00153 ref3DCopy.descriptorLabels
00154 );
00155 lefts.concatenate(rights);
00156 EXPECT_TRUE(lefts == ref3DCopy);
00157 }
00158
00159 TEST(PointCloudTest, ConcatenateDescDiffName)
00160 {
00161 typedef DP::Label Label;
00162 typedef DP::Labels Labels;
00163
00164 const int leftPoints(ref2D.features.cols() / 2);
00165 const int rightPoints(ref2D.features.cols() - leftPoints);
00166 DP lefts(
00167 ref2D.features.leftCols(leftPoints),
00168 ref2D.featureLabels,
00169 PM::Matrix::Random(5, leftPoints),
00170 Labels(Label("MyDesc5D", 5))
00171 );
00172 DP rights(
00173 ref2D.features.rightCols(rightPoints),
00174 ref2D.featureLabels,
00175 PM::Matrix::Random(5, rightPoints),
00176 Labels(Label("YourDesc5D", 5))
00177 );
00178 lefts.concatenate(rights);
00179 EXPECT_TRUE(lefts.descriptors.rows() == 0);
00180 EXPECT_TRUE(lefts.descriptors.cols() == 0);
00181 }
00182
00183 TEST(PointCloudTest, ConcatenateDescDiffSize)
00184 {
00185 typedef DP::Label Label;
00186 typedef DP::Labels Labels;
00187
00188 const int leftPoints(ref2D.features.cols() / 2);
00189 const int rightPoints(ref2D.features.cols() - leftPoints);
00190 DP lefts(
00191 ref2D.features.leftCols(leftPoints),
00192 ref2D.featureLabels,
00193 PM::Matrix::Random(3, leftPoints),
00194 Labels(Label("DescND", 3))
00195 );
00196 DP rights(
00197 ref2D.features.rightCols(rightPoints),
00198 ref2D.featureLabels,
00199 PM::Matrix::Random(5, rightPoints),
00200 Labels(Label("DescND", 5))
00201 );
00202 EXPECT_THROW(lefts.concatenate(rights), DP::InvalidField);
00203 }
00204
00205 TEST(PointCloudTest, GetInfo)
00206 {
00207
00208
00209
00210
00211
00212 EXPECT_EQ(ref3D.getNbPoints(), 24989u);
00213 EXPECT_EQ(ref3D.getEuclideanDim(), 3u);
00214 EXPECT_EQ(ref3D.getHomogeneousDim(), 4u);
00215 EXPECT_EQ(ref3D.getNbGroupedDescriptors(), 1u);
00216 EXPECT_EQ(ref3D.getDescriptorDim(), 3u);
00217
00218 EXPECT_EQ(ref2D.getNbPoints(), 361u);
00219 EXPECT_EQ(ref2D.getEuclideanDim(), 2u);
00220 EXPECT_EQ(ref2D.getHomogeneousDim(), 3u);
00221 EXPECT_EQ(ref2D.getNbGroupedDescriptors(), 0u);
00222 EXPECT_EQ(ref2D.getDescriptorDim(), 0u);
00223
00224 }
00225
00226 TEST(PointCloudTest, AddRemove)
00227 {
00228 DP ref3DCopy = ref3D;
00229 const int testedValue = 9;
00230
00232 PM::Matrix newFeature = PM::Matrix::Ones(1,ref3DCopy.getNbPoints())*testedValue;
00233 ref3DCopy.addFeature("testF", newFeature);
00234
00235
00236 EXPECT_EQ(ref3DCopy.getHomogeneousDim(), ref3D.getHomogeneousDim()+1);
00237
00238
00239 EXPECT_EQ(ref3DCopy.featureLabels.back().text, "pad");
00240
00241
00242 DP::View newFeatureView = ref3DCopy.getFeatureViewByName("testF");
00243 EXPECT_EQ(newFeatureView(0,0), testedValue);
00244
00246 ref3DCopy.removeFeature("testF");
00247
00248
00249 EXPECT_TRUE(ref3DCopy.features.isApprox(ref3D.features));
00250
00251
00253 const int testedValue2 = 88;
00254 PM::Matrix newDescriptor4D = PM::Matrix::Ones(4,ref3DCopy.getNbPoints())*testedValue;
00255 PM::Matrix newDescriptor2D = PM::Matrix::Ones(2,ref3DCopy.getNbPoints())*testedValue2;
00256
00257 ref3DCopy.addDescriptor("test4D", newDescriptor4D);
00258 ref3DCopy.addDescriptor("test2D", newDescriptor2D);
00259
00260
00261 EXPECT_EQ(ref3DCopy.getDescriptorDim(), ref3D.getDescriptorDim()+6);
00262 EXPECT_EQ(ref3DCopy.getNbGroupedDescriptors(), ref3D.getNbGroupedDescriptors()+2);
00263
00264
00265 DP::View newDescriptor4DView = ref3DCopy.getDescriptorViewByName("test4D");
00266 EXPECT_EQ(newDescriptor4DView(0,0), testedValue);
00267 DP::View newDescriptor2DView = ref3DCopy.getDescriptorViewByName("test2D");
00268 EXPECT_EQ(newDescriptor2DView(0,0), testedValue2);
00269
00270
00272 ref3DCopy.removeDescriptor("test4D");
00273 ref3DCopy.removeDescriptor("test2D");
00274
00275
00276 ref3DCopy.removeDescriptor("grrrrr");
00277
00278
00279 EXPECT_TRUE(ref3DCopy.descriptors.isApprox(ref3D.descriptors));
00280
00281 }