DataFilters.cpp
Go to the documentation of this file.
00001 #include "../utest.h"
00002 
00003 using namespace std;
00004 using namespace PointMatcherSupport;
00005 
00006 //---------------------------
00007 // DataFilter modules
00008 //---------------------------
00009 
00010 // Utility classes
00011 class DataFilterTest: public IcpHelper
00012 {
00013 public:
00014         // Will be called for every tests
00015         virtual void SetUp()
00016         {
00017                 icp.setDefault();
00018                 // Uncomment for console outputs
00019                 //setLogger(PM::get().LoggerRegistrar.create("FileLogger"));
00020                 
00021                 // We'll test the filters on reading point cloud
00022                 icp.readingDataPointsFilters.clear();
00023         }
00024 
00025         // Will be called for every tests
00026         virtual void TearDown() {}
00027 
00028         void addFilter(string name, PM::Parameters params)
00029         {
00030                 PM::DataPointsFilter* testedDataPointFilter = 
00031                         PM::get().DataPointsFilterRegistrar.create(name, params);
00032         
00033                 icp.readingDataPointsFilters.push_back(testedDataPointFilter);
00034         }
00035         
00036         void addFilter(string name)
00037         {
00038                 PM::DataPointsFilter* testedDataPointFilter = 
00039                         PM::get().DataPointsFilterRegistrar.create(name);
00040                 
00041                 icp.readingDataPointsFilters.push_back(testedDataPointFilter);
00042         }
00043 };
00044 
00045 
00046 TEST_F(DataFilterTest, RemoveNaNDataPointsFilter)
00047 {
00048         // build test cloud
00049         DP ref2DCopy(ref2D);
00050         int goodCount(0);
00051         const float nan(std::numeric_limits<float>::quiet_NaN());
00052         for (int i(0); i < ref2DCopy.features.cols(); ++i)
00053         {
00054                 if (rand() % 3 == 0)
00055                 {
00056                         ref2DCopy.features(rand() % ref2DCopy.features.rows(), i) = nan;
00057                 }
00058                 else
00059                         ++goodCount;
00060         }
00061         
00062         // apply and checked
00063         addFilter("RemoveNaNDataPointsFilter");
00064         icp.readingDataPointsFilters.apply(ref2DCopy);
00065         EXPECT_TRUE(ref2DCopy.features.cols() == goodCount);
00066 }
00067 
00068 TEST_F(DataFilterTest, MaxDistDataPointsFilter)
00069 {
00070         // Max dist has been selected to not affect the points
00071         params = map_list_of<string,string>
00072                 ("dim","0")
00073                 ("maxDist", toParam(6.0))
00074         ;
00075         
00076         // Filter on x axis
00077         params["dim"] = "0";
00078         icp.readingDataPointsFilters.clear();
00079         addFilter("MaxDistDataPointsFilter", params);
00080         validate2dTransformation();
00081         validate3dTransformation();
00082         
00083         // Filter on y axis
00084         params["dim"] = "1";
00085         icp.readingDataPointsFilters.clear();
00086         addFilter("MaxDistDataPointsFilter", params);
00087         validate2dTransformation();
00088         validate3dTransformation();
00089         
00090         // Filter on z axis (not existing)
00091         params["dim"] = "2";
00092         icp.readingDataPointsFilters.clear();
00093         addFilter("MaxDistDataPointsFilter", params);
00094         EXPECT_ANY_THROW(validate2dTransformation());
00095         validate3dTransformation();
00096         
00097         // Filter on a radius
00098         params["dim"] = "-1";
00099         icp.readingDataPointsFilters.clear();
00100         addFilter("MaxDistDataPointsFilter", params);
00101         validate2dTransformation();
00102         validate3dTransformation();
00103         
00104         // Parameter outside valid range
00105         params["dim"] = "3";
00106         //TODO: specify the exception, move that to GenericTest
00107         EXPECT_ANY_THROW(addFilter("MaxDistDataPointsFilter", params));
00108         
00109 }
00110 
00111 TEST_F(DataFilterTest, MinDistDataPointsFilter)
00112 {
00113         // Min dist has been selected to not affect the points too much
00114         params = map_list_of<string,string>
00115                 ("dim","0")
00116                 ("minDist", toParam(0.05))
00117         ;
00118         
00119         // Filter on x axis
00120         params["dim"] = "0";
00121         icp.readingDataPointsFilters.clear();
00122         addFilter("MinDistDataPointsFilter", params);
00123         validate2dTransformation();
00124         validate3dTransformation();
00125         
00126         // Filter on y axis
00127         params["dim"] = "1";
00128         icp.readingDataPointsFilters.clear();
00129         addFilter("MinDistDataPointsFilter", params);
00130         validate2dTransformation();
00131         validate3dTransformation();
00132         
00133         //TODO: move that to specific 2D test
00134         // Filter on z axis (not existing)
00135         params["dim"] = "2";
00136         icp.readingDataPointsFilters.clear();
00137         addFilter("MinDistDataPointsFilter", params);
00138         EXPECT_ANY_THROW(validate2dTransformation());
00139         validate3dTransformation();
00140         
00141         // Filter on a radius
00142         params["dim"] = "-1";
00143         icp.readingDataPointsFilters.clear();
00144         addFilter("MinDistDataPointsFilter", params);
00145         validate2dTransformation();
00146         validate3dTransformation();
00147                 
00148 }
00149 
00150 TEST_F(DataFilterTest, MaxQuantileOnAxisDataPointsFilter)
00151 {
00152         // Ratio has been selected to not affect the points too much
00153         string ratio = "0.95";
00154         params = map_list_of<string,string>
00155                 ("dim","0")
00156                 ("ratio", ratio)
00157         ;
00158         
00159         // Filter on x axis
00160         params["dim"] = "0";
00161         icp.readingDataPointsFilters.clear();
00162         addFilter("MaxQuantileOnAxisDataPointsFilter", params);
00163         validate2dTransformation();
00164         validate3dTransformation();
00165         
00166         // Filter on y axis
00167         params["dim"] = "1";
00168         icp.readingDataPointsFilters.clear();
00169         addFilter("MaxQuantileOnAxisDataPointsFilter", params);
00170         validate2dTransformation();
00171         validate3dTransformation();
00172         
00173         // Filter on z axis (not existing)
00174         params["dim"] = "2";
00175         icp.readingDataPointsFilters.clear();
00176         addFilter("MaxQuantileOnAxisDataPointsFilter", params);
00177         EXPECT_ANY_THROW(validate2dTransformation());
00178         validate3dTransformation();
00179 }
00180 
00181 
00182 
00183 TEST_F(DataFilterTest, SurfaceNormalDataPointsFilter)
00184 {
00185         // This filter create descriptor, so parameters should'nt impact results
00186         params = map_list_of
00187                 ("knn", "5") 
00188                 ("epsilon", "0.1") 
00189                 ("keepNormals", "1")
00190                 ("keepDensities", "1")
00191                 ("keepEigenValues", "1")
00192                 ("keepEigenVectors", "1" )
00193                 ("keepMatchedIds" , "1" )
00194         ;
00195         // FIXME: the parameter keepMatchedIds seems to do nothing...
00196 
00197         addFilter("SurfaceNormalDataPointsFilter", params);
00198         validate2dTransformation();     
00199         validate3dTransformation();
00200 
00201         // TODO: standardize how filter are tested:
00202         // 1- impact on number of points
00203         // 2- impact on descriptors
00204         // 3- impact on ICP (that's what we test now)
00205 }
00206 
00207 TEST_F(DataFilterTest, MaxDensityDataPointsFilter)
00208 {
00209         // Ratio has been selected to not affect the points too much
00210         vector<double> ratio = list_of (100) (1000) (5000);
00211  
00212         for(unsigned i=0; i < ratio.size(); i++)
00213         {
00214                 icp.readingDataPointsFilters.clear();
00215                 params = map_list_of
00216                         ("knn", "5") 
00217                         ("epsilon", "0.1") 
00218                         ("keepNormals", "0")
00219                         ("keepDensities", "1")
00220                         ("keepEigenValues", "0")
00221                         ("keepEigenVectors", "0" )
00222                         ("keepMatchedIds" , "0" )
00223                 ;
00224 
00225                 addFilter("SurfaceNormalDataPointsFilter", params);
00226 
00227                 params = map_list_of ("maxDensity", toParam(ratio[i]));
00228                 addFilter("MaxDensityDataPointsFilter", params);
00229                 
00230                 // FIXME BUG: the density in 2D is not well computed
00231                 //validate2dTransformation();   
00232  
00233                 //double nbInitPts = data2D.features.cols();
00234                 //double nbRemainingPts = icp.getPrefilteredReadingPtsCount();
00235                 //EXPECT_TRUE(nbRemainingPts < nbInitPts);
00236                 
00237                 validate3dTransformation();
00238 
00239                 double nbInitPts = data3D.features.cols();
00240                 double nbRemainingPts = icp.getPrefilteredReadingPtsCount();
00241                 EXPECT_TRUE(nbRemainingPts < nbInitPts);
00242         }
00243 }
00244 
00245 TEST_F(DataFilterTest, SamplingSurfaceNormalDataPointsFilter)
00246 {
00247         // This filter create descriptor AND subsample
00248         params = map_list_of
00249                 ("knn", "5")
00250                 ("averageExistingDescriptors", "1")
00251                 ("keepNormals", "1")
00252                 ("keepDensities", "1")
00253                 ("keepEigenValues", "1")
00254                 ("keepEigenVectors", "1")
00255         ;
00256         
00257         addFilter("SamplingSurfaceNormalDataPointsFilter", params);
00258         validate2dTransformation();
00259         validate3dTransformation();
00260 
00261 }
00262 
00263 TEST_F(DataFilterTest, OrientNormalsDataPointsFilter)
00264 {
00265         // Used to create normal for reading point cloud
00266         PM::DataPointsFilter* extraDataPointFilter;
00267         extraDataPointFilter = PM::get().DataPointsFilterRegistrar.create(
00268                         "SurfaceNormalDataPointsFilter");
00269         icp.readingDataPointsFilters.push_back(extraDataPointFilter);
00270         addFilter("ObservationDirectionDataPointsFilter");
00271         addFilter("OrientNormalsDataPointsFilter", map_list_of
00272                 ("towardCenter", toParam(false))
00273         );
00274         validate2dTransformation();
00275         validate3dTransformation();
00276 }
00277 
00278 
00279 TEST_F(DataFilterTest, RandomSamplingDataPointsFilter)
00280 {
00281         vector<double> prob = list_of (0.80) (0.85) (0.90) (0.95);
00282         for(unsigned i=0; i<prob.size(); i++)
00283         {
00284                 // Try to avoid to low value for the reduction to avoid under sampling
00285                 params = map_list_of
00286                         ("prob", toParam(prob[i]))
00287                 ;
00288                 icp.readingDataPointsFilters.clear();
00289                 addFilter("RandomSamplingDataPointsFilter", params);
00290                 validate2dTransformation();
00291                 validate3dTransformation();
00292         }
00293 }
00294 
00295 TEST_F(DataFilterTest, FixStepSamplingDataPointsFilter)
00296 {
00297         vector<unsigned> steps = list_of (1) (2) (3);
00298         for(unsigned i=0; i<steps.size(); i++)
00299         {
00300                 // Try to avoid too low value for the reduction to avoid under sampling
00301                 params = map_list_of
00302                         ("startStep", toParam(steps[i]))
00303                 ;
00304                 icp.readingDataPointsFilters.clear();
00305                 addFilter("FixStepSamplingDataPointsFilter", params);
00306                 validate2dTransformation();
00307                 validate3dTransformation();
00308         }
00309 }
00310 
00311 TEST_F(DataFilterTest, VoxelGridDataPointsFilter)
00312 {
00313         vector<bool> useCentroid = list_of(false)(true);
00314         vector<bool> averageExistingDescriptors = list_of(false)(true);
00315         for (unsigned i = 0 ; i < useCentroid.size() ; i++) 
00316         {
00317                 for (unsigned j = 0; j < averageExistingDescriptors.size(); j++) 
00318                 {
00319                         params = map_list_of<string,string>
00320                                         ("vSizeX","0.02")
00321                                         ("vSizeY","0.02")
00322                                         ("vSizeZ","0.02")
00323                                         ("useCentroid",toParam(true))
00324                                         ("averageExistingDescriptors",toParam(true))
00325                         ;
00326                         icp.readingDataPointsFilters.clear();
00327                         addFilter("VoxelGridDataPointsFilter", params);
00328                         validate2dTransformation();
00329                 }
00330         }
00331 
00332         for (unsigned i = 0 ; i < useCentroid.size() ; i++)
00333         {
00334                 for (unsigned j = 0; j < averageExistingDescriptors.size(); j++)
00335                 {
00336                         params = map_list_of<string,string>
00337                         ("vSizeX","1")
00338                         ("vSizeY","1")
00339                         ("vSizeZ","1")
00340                         ("useCentroid",toParam(true))
00341                         ("averageExistingDescriptors",toParam(true));
00342                         icp.readingDataPointsFilters.clear();
00343                         addFilter("VoxelGridDataPointsFilter", params);
00344                         validate3dTransformation();
00345                 }
00346         }
00347 }
00348 
00349 TEST_F(DataFilterTest, CutAtDescriptorThresholdDataPointsFilter)
00350 {
00351         // Copied from density ratio above
00352         vector<double> thresholds = list_of (100) (1000) (5000);
00353 
00354         DP ref3Ddensities = ref3D;
00355         // Adding descriptor "densities"
00356         icp.readingDataPointsFilters.clear();
00357         params = map_list_of
00358                 ("knn", "5") 
00359                 ("epsilon", "0.1") 
00360                 ("keepNormals", "0")
00361                 ("keepDensities", "1")
00362                 ("keepEigenValues", "0")
00363                 ("keepEigenVectors", "0" )
00364                 ("keepMatchedIds" , "0" )
00365         ;
00366 
00367         addFilter("SurfaceNormalDataPointsFilter", params);
00368         icp.readingDataPointsFilters.apply(ref3Ddensities);
00369 
00370         for(unsigned i=0; i < thresholds.size(); i++)
00371         {
00372                 int belowCount=0;
00373                 int aboveCount=0;
00374 
00375                 // counting points above and below
00376                 PM::DataPoints::View densities = ref3Ddensities.getDescriptorViewByName("densities");
00377                 for (unsigned j=0; j < densities.cols(); ++j)
00378                 {
00379                         if (densities(0, j) <= thresholds[i])
00380                         {
00381                                 ++belowCount;
00382                         }
00383                         if (densities(0, j) >= thresholds[i])
00384                         {
00385                                 ++aboveCount;
00386                         }
00387                 }
00388 
00389                 for(bool useLargerThan(true); useLargerThan; useLargerThan=false)
00390                 {
00391                         DP ref3DCopy = ref3Ddensities;
00392 
00393                         icp.readingDataPointsFilters.clear();
00394                         params = map_list_of
00395                                 ("descName", toParam("densities"))
00396                                 ("useLargerThan", toParam(useLargerThan))
00397                                 ("threshold", toParam(thresholds[i]))
00398                         ;
00399 
00400                         addFilter("CutAtDescriptorThresholdDataPointsFilter", params);
00401                         icp.readingDataPointsFilters.apply(ref3DCopy);
00402                         if (useLargerThan)
00403                         {
00404                                 EXPECT_TRUE(ref3DCopy.features.cols() == belowCount);
00405                         }
00406                         else
00407                         {
00408                                 EXPECT_TRUE(ref3DCopy.features.cols() == aboveCount);
00409                         }
00410                 }
00411         }
00412 }
00413 


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