test_invariant_feature.cpp
Go to the documentation of this file.
00001 
00058 #include <fstream>
00059 #include <ros/ros.h>
00060 #include <pcl/point_types.h>
00061 #include <pcl/io/pcd_io.h>
00062 #include <sensor_msgs/Image.h>
00063 #include <pcl/io/ply_io.h>
00064 #include <pcl/io/vtk_lib_io.h>
00065 
00066 #include <iostream>
00067 #include <Eigen/Geometry>
00068 
00069 /*
00070 #include "ShapeSPH/Util/SphereSampler.h"
00071 #include "ShapeSPH/Util/Signature.h"
00072 #include "ShapeSPH/Util/lineqn.h"
00073 #include "ShapeSPH/Util/SphericalPolynomials.h"
00074 #include "cob_3d_features/invariant_surface_feature/triangle.hpp"
00075 */
00076 
00077 
00078 // Packages Includes:
00079 #include "cob_3d_features/impl/invariant_surface_feature.hpp"
00080 //#include "cob_3d_features/impl/invariant_surface_feature_unit_tests.hpp"
00081 #include "cob_3d_features/impl/invariant_surface_feature_debug.hpp"
00082 #include <cob_3d_segmentation/quad_regression/quad_regression.h>
00083 #include "cob_3d_segmentation/quad_regression/polygon.h"
00084  
00085 
00086 template<class Samples, class Values>
00087 void simple_test(Eigen::Vector3d n, const Samples &samples, Values &vals) {
00088         vals.resize(samples.size());
00089 double s=0;
00090         for(size_t i=0; i<samples.size(); i++) {
00091                 for(size_t j=0; j<samples[i].size(); j++) {
00092 //                      vals[i].push_back( (i==0&&j==3)?1:0 );
00093 //                      vals[i].push_back(samples[i][j].dot(n)>0.4);
00094                         vals[i].push_back(std::complex<double>(samples[i][j].dot(n), 0));
00095 //std::cout<<samples[i][j].transpose()<<" = ";
00096 //std::cout<<vals[i].back()<<" ";
00097 s+=std::abs(vals[i].back());
00098 //if(j%8==7)
00099 //              std::cout<<std::endl;
00100                 }
00101 //              std::cout<<std::endl;
00102         }
00103 std::cout<<"sum "<<s<<std::endl;
00104 }
00105 
00106 int main(int argc, char **argv)
00107 {
00108 
00109         std::string fn = "/home/josh/Downloads/MaleLow.obj";
00110         //fn = "/home/josh/Downloads/batmobile.obj";
00111         fn = "/home/josh/Downloads/bunny.ply";
00112         //fn = "/home/josh/Downloads/Beautiful Girl.obj";
00113         //fn = "/home/josh/Downloads/Sovereign 5.obj";
00114         fn = "/home/josh/Downloads/cylinder.obj";
00115         fn = "/home/josh/Downloads/sphere.obj";
00116         //fn = "/home/josh/Downloads/prowler_c.obj";
00117         //fn = "/home/josh/Downloads/skinner.obj";
00118         std::string fn2 = "/home/josh/Downloads/Beautiful Girl.obj";
00119         //fn2 = "/home/josh/Downloads/Sovereign 5.obj";
00120         fn2 = "/home/josh/Downloads/sphere.obj";
00121         //fn2 = "/home/josh/Downloads/skinner.obj";
00122         //fn2 = "/home/josh/Downloads/cylinder.obj";
00123 
00124         typedef float Real;
00125         typedef double Scalar;
00126         typedef Sampler<Real, Scalar> S;
00127 
00128         srand(time(NULL));
00129 
00130         const int num_radii = 8;
00131         const int num_angles = 32;
00132         S gedt((Real)num_radii , num_radii , num_angles);
00133         S gedt2((Real)num_radii , num_radii , num_angles);
00134         std::vector< FourierKeyS2< Real > > sKeys;
00135         S::Samples samples;
00136         gedt.getSamples(samples);
00137 
00138         Eigen::Vector3d p1 = Eigen::Vector3d::Random(), p2 = Eigen::Vector3d::Random(), p3 = Eigen::Vector3d::Random(), off = Eigen::Vector3d::Random(), n1=Eigen::Vector3d::Random(),n2, off2;
00139         Eigen::Vector3d p4 = Eigen::Vector3d::Random(), p5 = Eigen::Vector3d::Random(), p6 = Eigen::Vector3d::Random();
00140         
00141         off2(0)=off2(1)=off2(2)=0;
00142 
00143 //p1(0)=0;
00144 //p1(1)=0;
00145 //p1(2)=0;
00146 
00147 //p2(0)=1;
00148 //p2(1)=0;
00149 //p2(2)=1;
00150 
00151 //p3(0)=1;
00152 //p3(1)=1;
00153 //p3(2)=1;
00154 
00155         Eigen::AngleAxisd rotA(0.33*M_PI, Eigen::Vector3d::Random().normalized());
00156         Eigen::Matrix3d rot = rotA.matrix();
00157 //      Eigen::AngleAxisd rot(0.5*M_PI, Eigen::Vector3d::UnitX());
00158         n2 = rot*n1;
00159 
00160         if(1) {         
00161                 cob_3d_features::invariant_surface_feature::SingleTriangle<Scalar, S::Samples, S::Values> tri(p1, p2, p3);
00162                 cob_3d_features::invariant_surface_feature::SingleTriangle<Scalar, S::Samples, S::Values> tri_opp(-p1, -p2, -p3);
00163                 
00164                 cob_3d_features::invariant_surface_feature::SingleTriangle<Scalar, S::Samples, S::Values> tri3(p4, p5, p6);
00165                 cob_3d_features::invariant_surface_feature::SingleTriangle<Scalar, S::Samples, S::Values> tri5(p4*2, p5, p6+p2);
00166 
00167                 //cob_3d_features::invariant_surface_feature::SingleTriangle<Scalar, S::Samples, S::Values> tri2(p1+off, p2+off, p3+off);
00168                 cob_3d_features::invariant_surface_feature::SingleTriangle<Scalar, S::Samples, S::Values> tri2(rot*p1+off, rot*p2+off, rot*p3+off);
00169                 cob_3d_features::invariant_surface_feature::SingleTriangle<Scalar, S::Samples, S::Values> tri4(rot*p4+off, rot*p5+off, rot*p6+off);
00170                 cob_3d_features::invariant_surface_feature::SingleTriangle<Scalar, S::Samples, S::Values> tri6(rot*(2*p4)+off, rot*p5+off, rot*(p6+p2)+off);
00171 
00172                 std::cout<<"nd1 "<<n1.dot(p1)<<std::endl;
00173                 std::cout<<"nd2 "<<n2.dot(rot*p1)<<std::endl;
00174 
00175                 std::cout<<"area "<<(p2-p1).cross(p3-p1).norm()/2<<std::endl;
00176                 std::cout<<"0 val. "<<std::abs(tri.kernel_lin_tri(Eigen::Vector3d::Zero())+tri3.kernel_lin_tri(Eigen::Vector3d::Zero())+tri5.kernel_lin_tri(Eigen::Vector3d::Zero()))<<std::endl;
00177                 std::cout<<"0 val. "<<std::abs(tri2.kernel_lin_tri(Eigen::Vector3d::Zero())+tri4.kernel_lin_tri(Eigen::Vector3d::Zero())+tri6.kernel_lin_tri(Eigen::Vector3d::Zero()))<<std::endl;
00178 
00179                 std::cout<<"single val. "<<std::abs(tri.kernel_lin_tri(n1)+tri3.kernel_lin_tri(n1)+tri5.kernel_lin_tri(n1))<<std::endl;
00180                 //std::cout<<"single val. "<<tri.kernel_lin_tri(n2)<<std::endl;
00181                 //std::cout<<"single val. "<<tri2.kernel_lin_tri(n1)<<std::endl;
00182                 std::cout<<"single val. "<<std::abs(tri2.kernel_lin_tri(n2)+tri4.kernel_lin_tri(n2)+tri6.kernel_lin_tri(n2))<<std::endl;
00183 
00184                 std::cout<<"single val. "<<std::abs( tri.kernel_lin_tri(n1,true))<<std::endl;
00185                 std::cout<<"single val. "<<std::abs( tri_opp.kernel_lin_tri(n1,true))<<std::endl;
00186                 std::cout<<"single val. "<<std::abs(tri2.kernel_lin_tri(n2,true))<<std::endl;
00187                 //std::cout<<"single val. "<<std::abs(tri2.kernel_lin_tri(n1,true))<<std::endl;
00188                 
00189                 std::cout<<"sum val. "<<std::abs( tri.kernel_lin_tri(n1)+tri_opp.kernel_lin_tri(n1))<<std::endl;
00190                 
00191                 std::cout<<"t "<<std::polar<float>(1,0)<<std::endl;
00192                 std::cout<<"t "<<std::polar<float>(1,PI)<<std::endl;
00193                 std::cout<<"t "<<std::polar<float>(1,0)+std::polar<float>(1,PI)<<std::endl;
00194 
00195                 tri.compute(samples);
00196                 tri2.compute(samples);
00197                 exit(0);
00198         }
00199 
00200         /*std::cout<<"off: "<<off.transpose()<<std::endl;
00201         for(size_t i=0; i<((S::Values)tri).size(); i++) {
00202                 for(size_t j=0; j<((S::Values)tri)[i].size(); j++) {
00203                         std::complex<Scalar> a = ((S::Values)tri)[i][j], b = ((S::Values)tri2)[i][j];
00204                         if(std::abs(std::abs(a)-std::abs(b))>0.01) {
00205                                 std::cout<<std::abs(a)<<"/"<<std::abs(b)<<" "<<std::endl;
00206                                 std::cout<<(a)<<"/"<<(b)<<" "<<std::endl;
00207                                 //assert(0);
00208                         }
00209                 }
00210         }*/
00211 
00212 
00213         const bool test=false;
00214         const int M=atoi(argv[2]), Start=atoi(argv[1]);
00215         if(!test) {
00216                 FILE *fp = fopen("/tmp/cmp_prec", "wb");
00217                 pcl::PolygonMesh mesh;
00218                 pcl::io::loadPolygonFile(fn, mesh);
00219                 std::cout<<"step 1 finished"<<std::endl;
00220 
00221                 pcl::PointCloud<pcl::PointXYZ> points;
00222                 pcl::fromROSMsg(mesh.cloud, points);
00223                 time_t start = time(0);
00224                 for(size_t i=Start; i<std::min(mesh.polygons.size(), (size_t)M); i++) {
00225                         for(int j=0; j<(int)mesh.polygons[i].vertices.size()-2; j++) {
00226 /*std::cout
00227                                         <<(points[mesh.polygons[i].vertices[j  ]].getVector3fMap().cast<double>()+off2).transpose()<<std::endl
00228                                         <<(points[mesh.polygons[i].vertices[j+1]].getVector3fMap().cast<double>()+off2).transpose()<<std::endl
00229                                         <<(points[mesh.polygons[i].vertices[j+2]].getVector3fMap().cast<double>()+off2).transpose()<<std::endl
00230 <<std::endl;
00231 std::cout
00232                                         <<(rot*points[mesh.polygons[i].vertices[j  ]].getVector3fMap().cast<double>()+off+off2).transpose()<<std::endl
00233                                         <<(rot*points[mesh.polygons[i].vertices[j+1]].getVector3fMap().cast<double>()+off+off2).transpose()<<std::endl
00234                                         <<(rot*points[mesh.polygons[i].vertices[j+2]].getVector3fMap().cast<double>()+off+off2).transpose()<<std::endl
00235 <<std::endl;*/
00236 
00237 
00238                                 cob_3d_features::invariant_surface_feature::SingleTriangle<Scalar, S::Samples, S::Values> tri(
00239                                         points[mesh.polygons[i].vertices[j  ]].getVector3fMap().cast<double>()+off2,
00240                                         points[mesh.polygons[i].vertices[j+1]].getVector3fMap().cast<double>()+off2,
00241                                         points[mesh.polygons[i].vertices[j+2]].getVector3fMap().cast<double>()+off2
00242                                 );
00243                                 tri.compute(samples);
00244                                 gedt += tri;
00245 
00246 //std::cout<<"single val. "<<( tri.kernel_lin_tri(samples[7][42]))<<" "<<tri.area()<<std::endl;
00247 //std::cout<<"at 42 "<<gedt.complex_vals_[7][42]<<std::endl;
00248 
00249                                 /*std::cout<<"single val. "<<std::abs( tri.kernel_lin_tri(n1))<<" "<<tri.area()<<std::endl;
00250 for(size_t l=0; l<((S::Values)tri)[7].size(); l++) {
00251         std::cout<<std::abs(((S::Values)tri)[7][l])<<" ";
00252 }
00253 std::cout<<std::endl;*/
00254                         }
00255                 }
00256 for(size_t l=0; l<gedt.complex_vals_[7].size(); l++) {
00257         double d;
00258         d=std::abs(gedt.complex_vals_[7][l]);
00259         fwrite(&d, sizeof(double), 1, fp);
00260 }
00261 fclose(fp);
00262                 std::cout<<"step 2 finished: "<<(time(0)-start)<<"s"<<std::endl;
00263         }
00264 
00265         if(test) {S::Values vals;
00266         simple_test(n1, samples, vals);
00267         gedt+=vals;}
00268         gedt.sample(sKeys);
00269 
00270         const int bw = sKeys[0].bandWidth();
00271         Signature< Real > sig( (bw) * int( sKeys.size() ) );
00272         for( int i=0 ; i<sKeys.size() ; i++ )
00273         {
00274                 std::cout<<"Key:"<<std::endl;
00275                 for( int b=0 ; b<bw ; b++ )
00276                 {
00277                         Real _norm2 = sKeys[i](b,0).squareNorm();
00278                         //std::cout<<sKeys[i](b,0).squareNorm()<<" ";
00279                         for( int j=1 ; j<=b ; j++ ) {
00280                                 _norm2 += sKeys[i](b,j).squareNorm()*2;
00281                                 //std::cout<<sKeys[i](b,j).squareNorm()<<" ";
00282                         }
00283                         sig[i*bw+b] = Real( sqrt(_norm2) );
00284                         if(b%2==0)
00285                                 std::cout<<sig[i*bw+b]<</*"/"<<sig[i*bw+b]/sig[i*bw]<<*/" ";
00286                 }
00287                 std::cout<<std::endl;
00288         }
00289         sig.write( "/tmp/sig1" /*, Binary.set*/ );
00290 
00291         for(size_t i=0; i<sKeys.size(); i++)
00292         {
00293                 char fn[512];
00294                 sprintf(fn, "/tmp/key1_%d", i);
00295                 sKeys[i].write(fn);
00296         }
00297 
00298 
00299         if(!test) {
00300                 FILE *fp = fopen("/tmp/cmp_prec2", "wb");
00301                 pcl::PolygonMesh mesh;
00302                 pcl::io::loadPolygonFile(fn2, mesh);
00303                 std::cout<<"step 1 finished"<<std::endl;
00304 
00305                 pcl::PointCloud<pcl::PointXYZ> points;
00306                 pcl::fromROSMsg(mesh.cloud, points);
00307                 time_t start = time(0);
00308                 for(size_t i=Start; i<std::min(mesh.polygons.size(), (size_t)M); i++) {
00309                         for(int j=0; j<(int)mesh.polygons[i].vertices.size()-2; j++) {
00310                                 cob_3d_features::invariant_surface_feature::SingleTriangle<Scalar, S::Samples, S::Values> tri(
00311                                         rot*points[mesh.polygons[i].vertices[j  ]].getVector3fMap().cast<double>()+off+off2,
00312                                         rot*points[mesh.polygons[i].vertices[j+1]].getVector3fMap().cast<double>()+off+off2,
00313                                         rot*points[mesh.polygons[i].vertices[j+2]].getVector3fMap().cast<double>()+off+off2
00314                                 );
00315                                 tri.compute(samples);
00316                                 gedt2 += tri;
00317 
00318 //std::cout<<"single val. "<<( tri.kernel_lin_tri(samples[7][42]))<<" "<<tri.area()<<std::endl;
00319 //std::cout<<"at 42 "<<gedt2.complex_vals_[7][42]<<std::endl;
00320 
00321                                 /*std::cout<<"single val. "<<std::abs( tri.kernel_lin_tri(n2))<<" "<<tri.area()<<std::endl;
00322                 std::cout<<"step 2 finished: "<<(time(0)-start)<<"s"<<std::endl;
00323 for(size_t l=0; l<((S::Values)tri)[7].size(); l++) std::cout<<std::abs( ((S::Values)tri)[7][l] )<<" ";
00324 std::cout<<std::endl;*/
00325 
00326                                 /*cob_3d_features::invariant_surface_feature::SingleTriangle<Scalar, S::Samples, S::Values> tri2(
00327                                         points[mesh.polygons[i].vertices[j  ]].getVector3fMap().cast<double>(),
00328                                         points[mesh.polygons[i].vertices[j+1]].getVector3fMap().cast<double>(),
00329                                         points[mesh.polygons[i].vertices[j+2]].getVector3fMap().cast<double>()
00330                                 );
00331                                 tri2.compute(samples);
00332                                 for(size_t k=0; k<((S::Values)tri).size(); k++) for(size_t l=0; l<((S::Values)tri)[k].size(); l++)
00333                                         if(std::abs( std::abs(((S::Values)tri)[k][l])-std::abs(((S::Values)tri2)[k][l]) )>0.0001) {
00334                                                 std::cout<<((S::Values)tri)[k][l]-((S::Values)tri2)[k][l]<<std::endl;
00335                                                 std::cout<<std::abs( std::abs(((S::Values)tri)[k][l])-std::abs(((S::Values)tri2)[k][l]) )<<std::endl;
00336                                                 tri.kernel_lin_tri(samples[k][l],true);
00337                                                 tri2.kernel_lin_tri(samples[k][l],true);
00338                                                 assert(0);
00339                                         }*/
00340                         }
00341                 }
00342 for(size_t l=0; l<gedt2.complex_vals_[7].size(); l++) {
00343         double d;
00344         d=std::abs(gedt2.complex_vals_[7][l]);
00345         fwrite(&d, sizeof(double), 1, fp);
00346 }
00347 fclose(fp);
00348         }
00349 
00350         if(test) {
00351                 FILE *fp1 = fopen("/tmp/cmp_prec", "rb");
00352                 FILE *fp2 = fopen("/tmp/cmp_prec2", "rb");
00353                 double m=0;
00354                 int i=0;
00355                 while(!feof(fp1) && !feof(fp2)) {
00356                         double d1,d2;
00357                         fread(&d1, sizeof(double), 1, fp1);
00358                         fread(&d2, sizeof(double), 1, fp2);
00359                         std::cout<<i<<":\t"<<d1-d2<<" "<<d1<<" "<<d2<<" \t    "<<samples[7][i++].transpose()<<"\n";
00360                         m = std::max(std::abs(d1-d2), m);
00361                 }
00362                 std::cout<<std::endl<<"MAX "<<m<<std::endl;
00363                 fclose(fp1);
00364                 fclose(fp2);
00365         }
00366 
00367 
00368         if(test) {S::Values vals;
00369         simple_test(n2, samples, vals);
00370         gedt2+=vals;}
00371         gedt2.sample(sKeys);
00372 
00373         /*for(int n=0; n<gedt.vals_.size(); n++) {
00374                 std::cout<<"DELTA"<<n<<"\n";
00375                 for(int i=0; i<gedt.vals_[n].size(); i++)
00376                         std::cout<<(gedt.vals_[n][i]-gedt2.vals_[n][i])<<" ";
00377                 std::cout<<std::endl;
00378                 std::cout<<"DELTA"<<n<<"\n";
00379                 for(int i=0; i<gedt.vals_[n].size(); i++)
00380                         std::cout<<(gedt.vals_[n][i])<<" "<<(gedt2.vals_[n][i])<<" "<<std::abs(gedt.complex_vals_[n][i])<<" "<<std::abs(gedt2.complex_vals_[n][i])<<" | ";
00381                         //std::cout<<(gedt.complex_vals_[n][i])<<" "<<(gedt2.complex_vals_[n][i])<<std::abs(gedt.complex_vals_[n][i])<<" "<<std::abs(gedt2.complex_vals_[n][i])<<" | ";
00382                 std::cout<<std::endl;
00383         }*/
00384 
00385         {
00386         Signature< Real > sig( (bw) * int( sKeys.size() ) );
00387         for( int i=0 ; i<sKeys.size() ; i++ )
00388         {
00389                 std::cout<<"Key:"<<std::endl;
00390                 for( int b=0 ; b<bw ; b++ )
00391                 {
00392                         Real _norm2 = sKeys[i](b,0).squareNorm();
00393                         //std::cout<<sKeys[i](b,0).squareNorm()<<" ";
00394                         for( int j=1 ; j<=b ; j++ ) {
00395                                 _norm2 += sKeys[i](b,j).squareNorm()*2;
00396                                 //std::cout<<sKeys[i](b,j).squareNorm()<<" ";
00397                         }
00398                         sig[i*bw+b] = Real( sqrt(_norm2) );
00399                         if(b%2==0) std::cout<<sig[i*bw+b]<</*"/"<<sig[i*bw+b]/sig[i*bw]<<*/" ";
00400                 }
00401                 std::cout<<std::endl;
00402         }
00403         sig.write( "/tmp/sig2" /*, Binary.set*/ );}
00404 
00405         for(size_t i=0; i<sKeys.size(); i++)
00406         {
00407                 char fn[512];
00408                 sprintf(fn, "/tmp/key2_%d", i);
00409                 sKeys[i].write(fn);
00410         }
00411         
00412         {
00413                 enum {DEGREE=2};
00414                 typedef cob_3d_features::InvariantSurfaceFeature<Segmentation::S_POLYGON<DEGREE> > ISF;
00415                 ISF isf(16,16);
00416                 
00417                 //parameters
00418                 isf.addRadius(0.25);
00419                 
00420                 //input
00421                 std::ifstream fis("/tmp/blub");
00422                 Segmentation::Segmentation_QuadRegression<pcl::PointXYZ, pcl::PointXYZRGB, Segmentation::QPPF::QuadRegression<DEGREE, pcl::PointXYZ, Segmentation::QPPF::CameraModel_Kinect<pcl::PointXYZ> > > seg;
00423                 seg.serialize(fis);
00424                 
00425                 ISF::PTSurfaceList input(new ISF::TSurfaceList);
00426                 *input = seg.getPolygons();
00427                 std::cout<<"read data"<<std::endl;
00428                 
00429                 //compute
00430                 isf.setInput(input);
00431                 std::cout<<"setInput"<<std::endl;
00432                 isf.compute();
00433                 std::cout<<"compute"<<std::endl;
00434                 ISF::PResultConst oldR = isf.getResult();
00435                 std::cout<<"getResult"<<std::endl;
00436                 
00437                 pcl::io::savePLYFile("map1.ply",                *isf.dbg_Mesh_of_Map());
00438         }
00439 }
00440 
00441 #if 0
00442 #include <fstream>
00443 #include <ros/ros.h>
00444 #include <pcl/point_types.h>
00445 #include <pcl/io/pcd_io.h>
00446 #include <sensor_msgs/Image.h>
00447 #include <pcl/io/ply_io.h>
00448 
00449 // Packages Includes:
00450 #include "cob_3d_features/impl/invariant_surface_feature.hpp"
00451 #include "cob_3d_features/impl/invariant_surface_feature_unit_tests.hpp"
00452 #include "cob_3d_features/impl/invariant_surface_feature_debug.hpp"
00453 #include <cob_3d_segmentation/quad_regression/quad_regression.h>
00454 #include "cob_3d_segmentation/quad_regression/polygon.h"
00455 
00456 
00457 TEST(InvariantSurfaceFeature, sampleSurfaces) {
00458         typedef cob_3d_features::InvariantSurfaceFeature<4,4, Segmentation::S_POLYGON<2>, double, Eigen::Affine3d> ISF;
00459 
00460         //read data
00461         std::ifstream fis("/tmp/blub");
00462         Segmentation::Segmentation_QuadRegression<pcl::PointXYZ, pcl::PointXYZRGB, Segmentation::QPPF::QuadRegression<2, pcl::PointXYZ, Segmentation::QPPF::CameraModel_Kinect<pcl::PointXYZ> > > seg;
00463         seg.serialize(fis);
00464         ISF::PTSurfaceList input(new ISF::TSurfaceList);
00465         *input = seg.getPolygons();
00466 
00467         //read data
00468         std::ifstream fis2("/tmp/blub2");
00469         seg.serialize(fis2);
00470         ISF::PTSurfaceList input2(new ISF::TSurfaceList);
00471         *input2 = seg.getPolygons();
00472 
00473         ISF isf;
00474 
00475         //parameters
00476         //isf.addRadius(0.2);
00477         isf.addRadius(0.5);
00478         //isf.addRadius(1);
00479 
00480         //compute
00481         isf.setInput(input);
00482         isf.compute();
00483         ISF::PResultVectorListConst oldR = isf.getResult();
00484         pcl::io::savePLYFile("map1.ply",                *isf.dbg_Mesh_of_Map());
00485 
00486         //compute
00487         isf.setInput(input2);
00488         isf.compute();
00489         ISF::PResultVectorListConst newR = isf.getResult();
00490         pcl::io::savePLYFile("map2.ply",                *isf.dbg_Mesh_of_Map());
00491 
00492         //analyse: distinctiveness within same data
00493         Eigen::MatrixXd cor(oldR->size(),oldR->size());
00494         for(size_t i=0; i<oldR->size(); i++) {
00495                 for(size_t k=0; k<oldR->size(); k++) {
00496 
00497                         cor(i,k)=0;
00498                         for(size_t j=0; j<(*oldR)[i].ft.size(); j++)
00499                                 cor(i,k) += (*oldR)[i].ft[j]-(*oldR)[k].ft[j];
00500 
00501                 }
00502         }
00503 
00504         std::cout<<"Correlation\n"<<cor<<std::endl;
00505 
00506 
00507         //analyse: distinctiveness within same data
00508         Eigen::MatrixXd cor2(oldR->size(),newR->size());
00509         for(size_t i=0; i<oldR->size(); i++) {
00510                 for(size_t k=0; k<newR->size(); k++) {
00511 
00512                         cor2(i,k)=0;
00513                         for(size_t j=0; j<(*oldR)[i].ft.size(); j++)
00514                                 cor2(i,k) += (*oldR)[i].ft[j]-(*newR)[k].ft[j];
00515 
00516                 }
00517         }
00518 
00519         std::cout<<"Correlation\n"<<cor2<<std::endl;
00520 }
00521 
00522 /*TEST(InvariantSurfaceFeature, singleTriangle) {
00523         typedef cob_3d_features::InvariantSurfaceFeature<4,4, Segmentation::S_POLYGON<1>, double, Eigen::Affine3d> ISF;
00524         ISF isf;
00525 
00526         //parameters
00527         isf.addRadius(1);
00528 
00529         //tests
00530         //EXPECT_TRUE( isf.test_singleTriangle(100) );
00531         //return;
00532         pcl::io::savePLYFile("random_submap.ply",       *isf.test_subsampling_of_Map(5, 0.5));
00533         pcl::io::savePLYFile("random_map.ply",          *isf.dbg_Mesh_of_Map());
00534 
00535         isf.compute();
00536         ISF::PResultVectorListConst oldR = isf.getResult();
00537 
00538         //test translational invariance (for ease only in z direction for now)
00539         double off = 1.781;
00540         std::cout<<"moved in z-direction by "<<off<<std::endl;
00541         //isf.test_addOffset(off*3, off*2, off);
00542         isf.test_rotate(0.123+M_PI/4);
00543         isf.compute();
00544         ISF::PResultVectorListConst newR = isf.getResult();
00545 
00546         pcl::io::savePLYFile("random_map_rotated.ply",          *isf.dbg_Mesh_of_Map());
00547 
00548         assert(oldR->size()==newR->size());
00549         for(size_t i=0; i<oldR->size(); i++) {
00550                 assert((*oldR)[i].ft.size()==(*newR)[i].ft.size());
00551 
00552                 for(size_t j=0; j<(*oldR)[i].ft.size(); j++) {
00553                         for(size_t k=0; k<ISF::NUM_RADIUS; k++) {
00554                                 //std::cout<<i<<" "<<j<<" "<<k<<" "<<oldR->size()<<" "<<newR->size()<<std::endl;
00555                                 std::cout<<"dist "<<(*oldR)[i].ft[j]-(*newR)[i].ft[j]<<std::endl;
00556                                 std::cout<<( (*oldR)[i].ft[j].vals[k])<<std::endl;
00557                                 std::cout<<( (*newR)[i].ft[j].vals[k] )<<std::endl;
00558                                 std::cout<<( (*oldR)[i].ft[j].vals[k]-         (*newR)[i].ft[j].vals[k] )<<std::endl<<std::endl;
00559                                 EXPECT_TRUE( (*oldR)[i].ft[j].vals[k].isApprox((*newR)[i].ft[j].vals[k], 0.1) );
00560                         }
00561                 }
00562         }
00563 
00564         Eigen::MatrixXd cor(oldR->size(),oldR->size());
00565         for(size_t i=0; i<oldR->size(); i++) {
00566                 for(size_t k=0; k<newR->size(); k++) {
00567 
00568                         cor(i,k)=0;
00569                         for(size_t j=0; j<(*oldR)[i].ft.size(); j++)
00570                                 cor(i,k) += (*oldR)[i].ft[j]-(*newR)[k].ft[j];
00571 
00572                 }
00573         }
00574 
00575         std::cout<<"Correlation\n"<<cor<<std::endl;
00576 
00577 }
00578 */
00579 
00580 int main(int argc, char **argv)
00581 {
00582   ::testing::InitGoogleTest(&argc, argv);
00583   return RUN_ALL_TESTS();
00584 }
00585 #endif


cob_3d_features
Author(s): Georg Arbeiter
autogenerated on Wed Aug 26 2015 11:02:26