merging.cpp
Go to the documentation of this file.
00001 /*
00002  * atoms.cpp
00003  *
00004  *  Created on: 17.05.2012
00005  *      Author: josh
00006  */
00007 
00008 #define DEBUG_
00009 #define ATOM_TESTING_
00010 
00011 #include <ros/ros.h>
00012 #include <rosbag/bag.h>
00013 #include <pcl/point_types.h>
00014 #include <pcl/point_cloud.h>
00015 #include <pcl/io/pcd_io.h>
00016 #include <cob_3d_mapping_slam/curved_polygons/form.h>
00017 #include <visualization_msgs/Marker.h>
00018 
00019 #include <cob_3d_mapping_slam/curved_polygons/debug_interface.h>
00020 #include <cob_3d_mapping_slam/dof/tflink.h>
00021 #include <cob_3d_mapping_slam/dof/dof_uncertainty.h>
00022 #include <cob_3d_mapping_slam/dof/dof_variance.h>
00023 #include <cob_3d_mapping_slam/curved_polygons/objctxt.h>
00024 #include <cob_3d_mapping_slam/slam/dummy/robot.h>
00025 
00026 #include "gnuplot_i.hpp"
00027 #include <gtest/gtest.h>
00028 #include <unsupported/Eigen/NonLinearOptimization>
00029 
00030 #include <cob_3d_mapping_slam/curved_polygons/surface_tri_spline.h>
00031 
00032 #ifndef NDEBUG
00033 //#error
00034 #endif
00035 
00036 //#define ENABLE_TEST_1
00037 //#define ENABLE_TEST_2
00038 //#define ENABLE_TEST_3
00039 //#define ENABLE_TEST_4
00040 //#define ENABLE_TEST_5
00041 //#define ENABLE_TEST_6
00042 //#define ENABLE_TEST_7
00043 //#define ENABLE_TEST_8
00044 //#define ENABLE_TEST_9
00045 //#define ENABLE_TEST_10
00046 //#define ENABLE_TEST_11
00047 //#define ENABLE_TEST_12
00048 //#define ENABLE_TEST_14
00049 //#define ENABLE_TEST_15
00050 //#define ENABLE_TEST_16
00051 //#define ENABLE_TEST_17
00052 //#define ENABLE_TEST_18
00053 //#define ENABLE_TEST_19
00054 #define ENABLE_TEST_20
00055 
00056 struct MyFunctor
00057 {
00058   const float a,b,c;
00059   const float x0,y0,z0;
00060 
00061   int operator()(const Eigen::VectorXf &x, Eigen::VectorXf &fvec) const
00062   {
00063     // Implement y = x^2
00064     fvec(0) = std::pow((-z0+b*x(1)*x(1)+c*x(0)*x(1)+a*x(0)*x(0)),2)+std::pow(x(1)-y0,2)+std::pow(x(0)-x0,2);
00065 
00066     std::cout<<"fvec\n"<<fvec<<std::endl;
00067 
00068     return 0;
00069   }
00070 
00071   int df(const Eigen::VectorXf &x, Eigen::MatrixXf &fjac) const
00072   {
00073     //Jacobian
00074     fjac(0,0) = 2*(c*x(1)+2*a*x(0))*(-z0+b*x(1)*x(1)+c*x(0)*x(1)+a*x(0)*x(0))+2*(x(0)-x0);
00075     fjac(0,1) = 2*(2*b*x(1)+c*x(0))*(-z0+b*x(1)*x(1)+c*x(0)*x(1)+a*x(0)*x(0))+2*(x(1)-y0);
00076 
00077     std::cout<<"fjac\n"<<fjac<<std::endl;
00078 
00079     return 0;
00080   }
00081 
00082   int inputs() const { return 2; }
00083   int values() const { return 2; } // number of constraints
00084 };
00085 
00086 #ifdef ENABLE_TEST_1
00087 TEST(Opti, LM)
00088 #else
00089 void t1()
00090 #endif
00091 {
00092   Eigen::VectorXf x(2);
00093   x(0) = 1;
00094   x(1) = 1;
00095   std::cout << "x: " << x << std::endl;
00096 
00097   MyFunctor functor={5,6,7, 1,1,18};
00098   Eigen::LevenbergMarquardt<MyFunctor, float> lm(functor);
00099   lm.minimize(x);
00100 
00101   std::cout << "x that minimizes the function:\n" << x << std::endl;
00102 }
00103 
00104 void ADD_POINT(Slam_CurvedPolygon::Outline &O, const float x, const float y, const float e)
00105 {
00106   Eigen::Vector3f v;
00107   v(0) = x;
00108   v(1) = y;
00109   v(2) = e;
00110   O += v;
00111 }
00112 
00113 #ifdef ENABLE_TEST_2
00114 TEST(Merging, Extension)
00115 #else
00116 void test2()
00117 #endif
00118 {
00119   Slam_CurvedPolygon::Outline A, B;
00120 
00121   //  ADD_POINT(A, 0,0,    0.2);
00122   //  ADD_POINT(A, 0,3.5,  0.3);
00123   //  ADD_POINT(A, -1,3.5, 0.8);
00124   //  ADD_POINT(A, -1,2.5, 0.9);
00125   //  ADD_POINT(A, -2,2.5, 0.9);
00126   //  ADD_POINT(A, -2,0,   0.9);
00127 
00128   ADD_POINT(A, 0,0.5,    0.7);
00129   ADD_POINT(A, 0,3,     1);
00130   ADD_POINT(A, -2.5,3,  0.1);
00131   ADD_POINT(A, -2.5,0.5, 0.2);
00132 
00133   ADD_POINT(B, 1,-0.5,    0.7);
00134   ADD_POINT(B, 1,2,     1);
00135   ADD_POINT(B, -1.5,2,  0.1);
00136   ADD_POINT(B, -1.5,-0.5, 0.2);
00137 
00138   A.reverse();
00139   B.reverse();
00140 
00141   (B+A).debug_svg((A+B).debug_svg(B.debug_svg(A.debug_svg("A.svg"),100,300,"red"),100,300,"green"),100,300,"blue");
00142   //  (A+B).debug_svg(B.debug_svg(A.debug_svg("A.svg"),100,300,"red"),100,300,"green");
00143   //  exit(0);
00144 }
00145 
00146 #ifdef ENABLE_TEST_15
00147 TEST(Merging, Extension8)
00148 #else
00149 void test15()
00150 #endif
00151 {
00152   Slam_CurvedPolygon::Outline A, B;
00153 
00154   ADD_POINT(A, 0,0,    0.7);
00155   ADD_POINT(A, 0,3,     1);
00156   ADD_POINT(A, 3,3,  0.1);
00157   ADD_POINT(A, 3,0, 0.2);
00158 
00159   ADD_POINT(B, 1,1,    0.7);
00160   ADD_POINT(B, 1,2,     1);
00161   ADD_POINT(B, 2,3,  0.1);
00162   ADD_POINT(B, 2,1, 0.2);
00163 
00164   (B+A).debug_svg((A+B).debug_svg(B.debug_svg(A.debug_svg("A7.svg"),100,300,"red"),100,300,"green"),100,300,"blue");
00165   //  (A+B).debug_svg(B.debug_svg(A.debug_svg("A.svg"),100,300,"red"),100,300,"green");
00166   //  exit(0);
00167 }
00168 
00169 
00170 #ifdef ENABLE_TEST_16
00171 TEST(Merging, Extension9)
00172 #else
00173 void test16()
00174 #endif
00175 {
00176   Slam_CurvedPolygon::Outline A, B;
00177   ADD_POINT(A, -1.045884,-0.014834,         0.000000);
00178   ADD_POINT(A, -1.034974,1.645458,  0.000000);
00179   ADD_POINT(A, 1.407966,1.740485,   102.129730);
00180   ADD_POINT(A, 1.567071,1.729963,   110.842232);
00181   ADD_POINT(A, 1.518147,1.239551,   90.983131);
00182   ADD_POINT(A, 1.042412,1.229564,   0.000000);
00183   ADD_POINT(A, 0.233320,1.125095,   0.000000);
00184   ADD_POINT(A, -0.072294,1.023921,  59.796158);
00185   ADD_POINT(A, -0.106954,0.939260,  110.842232);
00186   ADD_POINT(A, -0.092559,0.617795,  110.842232);
00187   ADD_POINT(A, -0.130699,-0.005967,         110.842232);
00188   ADD_POINT(A, -1.015610,-0.037512,         9.617739);
00189 
00190 
00191   ADD_POINT(B, -1.205974,1.611247,  71.553490);
00192   ADD_POINT(B, -1.170201,1.649200,  0.000000);
00193   ADD_POINT(B, -0.848359,1.660372,  0.000000);
00194   ADD_POINT(B, -0.845104,1.702806,  0.000000);
00195   ADD_POINT(B, -0.581432,1.711480,  453.172150);
00196   ADD_POINT(B, 0.151303,1.695081,   453.172150);
00197   ADD_POINT(B, 1.510661,1.742285,   436.925049);
00198   ADD_POINT(B, 1.628683,1.662013,   453.172150);
00199   ADD_POINT(B, 1.830167,1.641676,   453.172150);
00200   ADD_POINT(B, 1.811066,1.537026,   453.172150);
00201   ADD_POINT(B, 1.746713,-0.252298,  385.196350);
00202   ADD_POINT(B, 1.684610,-0.544174,  385.196350);
00203   ADD_POINT(B, 1.701388,-0.963158,  436.578918);
00204   ADD_POINT(B, 1.571333,-0.986580,  445.391266);
00205   ADD_POINT(B, 1.241471,-0.963770,  452.844971);
00206   ADD_POINT(B, 1.140533,0.326848,   452.844971);
00207   ADD_POINT(B, 0.475619,-1.115085,  349.422333);
00208   ADD_POINT(B, 0.249968,-1.121169,  453.172150);
00209   ADD_POINT(B, -0.250100,-0.763183,         453.172150);
00210   ADD_POINT(B, -0.570233,-0.695548,         453.172150);
00211   ADD_POINT(B, -0.806169,-0.323459,         0.000000);
00212   ADD_POINT(B, -0.447819,0.019148,  0.000000);
00213   ADD_POINT(B, -1.204315,1.611264,  71.553490);
00214   ADD_POINT(B, -1.203599,1.673734,  0.000000);
00215   ADD_POINT(B, -0.581432,1.711480,  187.892410);
00216   ADD_POINT(B, -0.264263,1.704379,  453.172150);
00217   ADD_POINT(B, 1.513072,1.753348,   436.925995);
00218   ADD_POINT(B, 1.630895,1.717116,   453.172150);
00219   ADD_POINT(B, 1.627996,1.060091,   453.172150);
00220   ADD_POINT(B, 1.554010,1.183118,   453.172150);
00221   ADD_POINT(B, 1.313412,1.211873,   275.035492);
00222   ADD_POINT(B, 0.897379,1.211863,   0.000000);
00223   ADD_POINT(B, 0.040116,1.106657,   0.000000);
00224   ADD_POINT(B, -0.251436,1.011473,  343.437988);
00225   ADD_POINT(B, -0.264279,0.681655,  343.437988);
00226   ADD_POINT(B, -0.247862,0.210322,  453.172150);
00227   ADD_POINT(B, 0.132636,0.574106,   0.000000);
00228   ADD_POINT(B, 0.354757,0.580037,   0.000000);
00229   ADD_POINT(B, 0.386799,0.662925,   0.000000);
00230   ADD_POINT(B, 0.355860,0.983544,   0.000000);
00231   ADD_POINT(B, 0.001064,1.029807,   0.000000);
00232   ADD_POINT(B, -0.253165,0.967086,  0.000000);
00233   ADD_POINT(B, -0.264279,0.681653,  343.437988);
00234   ADD_POINT(B, -0.241488,0.027288,  453.172150);
00235   ADD_POINT(B, -0.482831,-0.014327,         453.172150);
00236   ADD_POINT(B, -0.619539,-0.145028,         21.026535);
00237   ADD_POINT(B, -1.129928,-0.175288,         453.172150);
00238   ADD_POINT(B, -1.111384,-0.269988,         85.979233);
00239   ADD_POINT(B, -1.389662,-0.255861,         28.425617);
00240   ADD_POINT(B, -1.425714,0.098974,  208.680603);
00241   ADD_POINT(B, -1.500362,0.447526,  164.860352);
00242   ADD_POINT(B, -1.796075,0.471063,  0.000000);
00243   ADD_POINT(B, -2.274216,0.418171,  234.627274);
00244   ADD_POINT(B, -2.296404,0.136106,  0.000000);
00245   ADD_POINT(B, -2.388968,0.193383,  0.000000);
00246   ADD_POINT(B, -2.313087,1.600093,  71.553490);
00247   ADD_POINT(B, -0.851855,1.614811,  72.198341);
00248   ADD_POINT(B, -0.845104,1.702806,  0.000000);
00249   ADD_POINT(B, -0.581432,1.711480,  453.172150);
00250   ADD_POINT(B, 1.640513,1.661748,   453.172150);
00251   ADD_POINT(B, 1.830167,1.641676,   453.172150);
00252   ADD_POINT(B, 1.811066,1.537026,   453.172150);
00253   ADD_POINT(B, 1.746713,-0.252298,  385.196350);
00254   ADD_POINT(B, 1.684610,-0.544174,  385.196350);
00255   ADD_POINT(B, 1.701388,-0.963158,  436.578918);
00256   ADD_POINT(B, 1.571333,-0.986580,  445.391266);
00257   ADD_POINT(B, 1.241471,-0.963770,  452.844971);
00258   ADD_POINT(B, 1.140533,0.326848,   452.844971);
00259   ADD_POINT(B, 0.475619,-1.115085,  349.422333);
00260   ADD_POINT(B, 0.249968,-1.121169,  453.172150);
00261   ADD_POINT(B, -0.250100,-0.763183,         453.172150);
00262   ADD_POINT(B, -0.570233,-0.695548,         453.172150);
00263   ADD_POINT(B, -0.806169,-0.323459,         0.000000);
00264   ADD_POINT(B, -0.482831,-0.014326,         0.000000);
00265 
00266   (B+A).debug_svg((A+B).debug_svg(B.debug_svg(A.debug_svg("A16.svg"),100,300,"red"),100,300,"green"),100,300,"blue");
00267   //  (A+B).debug_svg(B.debug_svg(A.debug_svg("A.svg"),100,300,"red"),100,300,"green");
00268   //  exit(0);
00269 }
00270 
00271 
00272 #ifdef ENABLE_TEST_14
00273 TEST(Merging, Extension7)
00274 #else
00275 void test14()
00276 #endif
00277 {
00278   Slam_CurvedPolygon::Outline A, B;
00279 
00280   ADD_POINT(A, 1.269705,-0.975754,  136.011032);
00281   ADD_POINT(A, 1.276548,-0.271520,  51.004135);
00282   ADD_POINT(A, 1.173826,0.516804,   0.000000);
00283   ADD_POINT(A, 0.407346,0.444026,   0.000000);
00284   ADD_POINT(A, 0.422948,0.493314,   0.000000);
00285   ADD_POINT(A, 0.330092,0.987637,   0.000000);
00286   ADD_POINT(A, 0.018048,1.042598,   0.000000);
00287   ADD_POINT(A, -0.350869,1.057517,  0.000000);
00288   ADD_POINT(A, -0.879164,1.038550,  0.000000);
00289   ADD_POINT(A, -1.280176,0.954838,  66.554298);
00290   ADD_POINT(A, -1.339894,0.894041,  136.011032);
00291   ADD_POINT(A, -1.334974,0.536400,  136.011032);
00292   ADD_POINT(A, -1.384047,0.112611,  136.011032);
00293   ADD_POINT(A, -1.483590,0.481948,  136.011032);
00294   ADD_POINT(A, -1.557691,0.496490,  136.011032);
00295   ADD_POINT(A, -2.297758,0.392300,  13.601104);
00296   ADD_POINT(A, -2.320095,0.108696,  0.000000);
00297   ADD_POINT(A, -2.389679,0.168287,  0.000000);
00298   ADD_POINT(A, -2.334253,1.576999,  14.316951);
00299   ADD_POINT(A, -1.967494,1.574737,  136.011032);
00300   ADD_POINT(A, 1.549718,1.597524,   136.011032);
00301   ADD_POINT(A, 1.699055,1.555135,   136.011032);
00302   ADD_POINT(A, 1.695281,0.150421,   136.011032);
00303   ADD_POINT(A, 1.678939,-0.882572,  136.011032);
00304   ADD_POINT(A, 1.574028,-0.974080,  136.011032);
00305 
00306 
00307   ADD_POINT(B, 1.275477,-0.981885,  0.000000);
00308   ADD_POINT(B, 1.278862,-0.292657,  50.942062);
00309   ADD_POINT(B, 1.175625,0.503335,   0.000000);
00310   ADD_POINT(B, 0.409199,0.422850,   45.281837);
00311   ADD_POINT(B, 0.331370,0.982494,   0.000000);
00312   ADD_POINT(B, 0.019325,1.037043,   0.000000);
00313   ADD_POINT(B, -0.349669,1.052238,  0.000000);
00314   ADD_POINT(B, -0.878034,1.033058,  0.000000);
00315   ADD_POINT(B, -1.279239,0.949065,  66.449097);
00316   ADD_POINT(B, -1.338103,0.888892,  135.845505);
00317   ADD_POINT(B, -1.333009,0.590709,  135.845505);
00318   ADD_POINT(B, -1.370899,0.058651,  135.845505);
00319   ADD_POINT(B, -1.482420,0.475614,  113.537460);
00320   ADD_POINT(B, -1.555821,0.482391,  135.845505);
00321   ADD_POINT(B, -2.295438,0.385319,  13.584551);
00322   ADD_POINT(B, -2.317035,0.101376,  0.000000);
00323   ADD_POINT(B, -2.386773,0.161003,  0.000000);
00324   ADD_POINT(B, -2.333375,1.571880,  14.299527);
00325   ADD_POINT(B, -2.051811,1.566876,  135.845505);
00326   ADD_POINT(B, 1.420109,1.589480,   135.845505);
00327   ADD_POINT(B, 1.700595,1.551211,   135.845505);
00328   ADD_POINT(B, 1.697783,0.128521,   135.845505);
00329   ADD_POINT(B, 1.680066,-0.868659,  135.845505);
00330   ADD_POINT(B, 1.610140,-0.976139,  135.845505);
00331 
00332   (B+A).debug_svg((A+B).debug_svg(B.debug_svg(A.debug_svg("A.svg"),100,300,"red"),100,300,"green"),100,300,"blue");
00333   //    (A+B).debug_svg(B.debug_svg(A.debug_svg("A.svg"),100,300,"red"),100,300,"green");
00334   //    exit(0);
00335 }
00336 
00337 #ifdef ENABLE_TEST_3
00338 TEST(Merging, Extension2)
00339 #else
00340 void test3()
00341 #endif
00342 {
00343   float ws[4]={1,0, 0,1};
00344 
00345   for(int i=0; i<2; i++)
00346   {
00347     Slam_CurvedPolygon::Outline A, B;
00348 
00349     ADD_POINT(A, 0,0,    ws[i*2+0]);
00350     ADD_POINT(A, 0,3.5,  ws[i*2+0]);
00351     ADD_POINT(A, -1,3.5, ws[i*2+0]);
00352     ADD_POINT(A, -1,2.5, ws[i*2+0]);
00353     ADD_POINT(A, -2,2.5, ws[i*2+0]);
00354     ADD_POINT(A, -2,0,   ws[i*2+0]);
00355 
00356     ADD_POINT(B, 1,-0.5,    ws[i*2+1]);
00357     ADD_POINT(B, 1,2,       ws[i*2+1]);
00358     ADD_POINT(B, -1.5,2,    ws[i*2+1]);
00359     ADD_POINT(B, -1.5,-0.5, ws[i*2+1]);
00360 
00361     A.reverse();
00362     B.reverse();
00363 
00364     char buffer[128];
00365 
00366     sprintf(buffer,"%d.svg",i);
00367     (B+A).debug_svg((A+B).debug_svg(B.debug_svg(A.debug_svg(buffer),100,300,"red"),100,300,"green"),100,300,"blue");
00368     //(B+A).debug_svg(B.debug_svg(A.debug_svg(buffer),100,300,"red"),100,300,"blue");
00369   }
00370 }
00371 
00372 #ifdef ENABLE_TEST_4
00373 TEST(Merging, Extension3)
00374 #else
00375 void test4()
00376 #endif
00377 {
00378   Slam_CurvedPolygon::Outline A, B;
00379 
00380   ADD_POINT(A, 0.362614,-0.386075,        0.000000);
00381   ADD_POINT(A, 0.301979,-0.022260,  1.000000);
00382   ADD_POINT(A, -0.121422,-0.058531,         1.000000);
00383   ADD_POINT(A, -0.083883,-0.430221,         0.000000);
00384 
00385   ADD_POINT(B, 0.375979,-0.382710,  0.000000);
00386   ADD_POINT(B, 0.285977,-0.017765,  1.000000);
00387   ADD_POINT(B, -0.121091,-0.055354,         1.000000);
00388   ADD_POINT(B, -0.092725,-0.439833,         0.000000);
00389 
00390   A.reverse();
00391   B.reverse();
00392 
00393   //  (B+A).debug_svg((A+B).debug_svg(B.debug_svg(A.debug_svg("A3.svg",400,1000),400,1000,"red"),400,1000,"green"),400,1000,"blue");
00394   (A+B).debug_svg(B.debug_svg(A.debug_svg("A3.svg",400,1000),400,1000,"red"),400,1000,"green");
00395   B.debug_svg(A.debug_svg("A3X.svg",400,1000),400,1000,"red");
00396 }
00397 
00398 #ifdef ENABLE_TEST_5
00399 TEST(Merging, Extension4)
00400 #else
00401 void test5()
00402 #endif
00403 {
00404   Slam_CurvedPolygon::Outline A, B;
00405 
00406   //  ADD_POINT(A, 0.352464,-0.328968,  0.544554);
00407   //  ADD_POINT(A, 0.310498,-0.012788,  0.625000);
00408   //  ADD_POINT(A, -0.105240,-0.051654,         1.000000);
00409   //  ADD_POINT(A, -0.085381,-0.333977,         0.354167);
00410   //
00411   //  ADD_POINT(B, 0.381562,-0.382153,  0.000000);
00412   //  ADD_POINT(B, 0.319971,-0.017452,  0.400000);
00413   //  ADD_POINT(B, -0.117289,-0.067878,         1.000000);
00414   //  ADD_POINT(B, -0.064972,-0.428602,         0.000000);
00415 
00416   //  ADD_POINT(A, 1.271197,-1.002109,  36.201504);
00417   //  ADD_POINT(A, 1.276123,-0.289343,  73.547798);
00418   //  ADD_POINT(A, 1.173015,0.508309,   32.055977);
00419   //  ADD_POINT(A, 0.422219,0.430278,   32.019093);
00420   //  ADD_POINT(A, 0.332066,0.989471,   0.000000);
00421   //  ADD_POINT(A, 0.019068,1.044561,   0.000000);
00422   //  ADD_POINT(A, -0.350912,1.059492,  0.000000);
00423   //  ADD_POINT(A, -0.880648,1.040339,  46.949902);
00424   //  ADD_POINT(A, -1.281505,0.958299,  139.610519);
00425   //  ADD_POINT(A, -1.342242,0.895776,  192.148376);
00426   //  ADD_POINT(A, -1.334560,0.568031,  192.148376);
00427   //  ADD_POINT(A, -1.378715,0.072318,  192.148376);
00428   //  ADD_POINT(A, -1.482872,0.482487,  173.982361);
00429   //  ADD_POINT(A, -1.557451,0.488403,  189.394531);
00430   //  ADD_POINT(A, -2.298002,0.391501,  19.141132);
00431   //  ADD_POINT(A, -2.316800,0.111018,  0.000000);
00432   //  ADD_POINT(A, -2.392913,0.168025,  10.024461);
00433   //  ADD_POINT(A, -2.329704,1.573308,  106.172142);
00434   //  ADD_POINT(A, -2.019224,1.569707,  192.148376);
00435   //  ADD_POINT(A, 1.417241,1.592710,   192.148376);
00436   //  ADD_POINT(A, 1.697454,1.553752,   192.148376);
00437   //  ADD_POINT(A, 1.695868,-0.567176,  192.148376);
00438   //  ADD_POINT(A, 1.687407,-0.873390,  192.148376);
00439   //  ADD_POINT(A, 1.630390,-1.005029,  184.242416);
00440   //
00441   //  A.weight_ = 200;
00442   //
00443   //
00444   //  ADD_POINT(B, 1.232858,-1.038015,  0.000000);
00445   //  ADD_POINT(B, 1.234751,-0.645128,  93.168755);
00446   //  ADD_POINT(B, 1.120643,0.477694,   0.000000);
00447   //  ADD_POINT(B, 0.588452,0.474953,   0.000000);
00448   //  ADD_POINT(B, 0.592946,0.791144,   0.000000);
00449   //  ADD_POINT(B, 0.501822,0.960626,   0.000000);
00450   //  ADD_POINT(B, 0.166220,1.010063,   0.000000);
00451   //  ADD_POINT(B, -0.222853,1.017744,  0.000000);
00452   //  ADD_POINT(B, -0.720829,0.990421,  0.000000);
00453   //  ADD_POINT(B, -1.116511,0.900883,  69.494606);
00454   //  ADD_POINT(B, -1.174784,0.839676,  132.740341);
00455   //  ADD_POINT(B, -1.162942,0.602914,  132.740341);
00456   //  ADD_POINT(B, -1.215195,-0.140121,         132.740341);
00457   //  ADD_POINT(B, -1.466481,-0.087689,         44.246780);
00458   //  ADD_POINT(B, -1.536346,0.423917,  0.000000);
00459   //  ADD_POINT(B, -2.169648,0.432516,  42.863258);
00460   //  ADD_POINT(B, -2.131289,1.512646,  17.698713);
00461   //  ADD_POINT(B, 1.574970,1.562794,   132.740341);
00462   //  ADD_POINT(B, 1.627951,1.517644,   132.740341);
00463   //  ADD_POINT(B, 1.637892,-0.282478,  132.740341);
00464   //  ADD_POINT(B, 1.627902,-0.618023,  132.740341);
00465   //  ADD_POINT(B, 1.583944,-1.039931,  132.740341);
00466   //
00467   //  B.weight_ = 200;
00468 
00469 
00470   ADD_POINT(A, -0.307397,-0.237957,         11.327011);
00471   ADD_POINT(A, -0.294620,0.200909,  204.053207);
00472   ADD_POINT(A, 0.069812,0.199390,   58.021393);
00473   ADD_POINT(A, 0.058937,-0.400914,  267.556702);
00474   A.weight_ = 200;
00475 
00476   ADD_POINT(B, -0.304834,-0.242607,         0.000000);
00477   ADD_POINT(B, -0.201638,0.103096,  5.053251);
00478   ADD_POINT(B, 0.001059,0.104582,   117.428665);
00479   ADD_POINT(B, 0.048089,-0.513129,  134.123077);
00480   B.weight_ = 200;
00481 
00482   //    B.debug_svg(A.debug_svg("A4.svg"),100,300,"red");
00483   (B+A).debug_svg((A+B).debug_svg(B.debug_svg(A.debug_svg("A4.svg",400,1000),400,1000,"red"),400,1000,"green"),400,1000,"blue");
00484   //    (B+A).debug_svg(B.debug_svg(A.debug_svg("A4.svg",400,1000),400,1000,"red"),400,1000,"green");
00485   //      exit(0);
00486 }
00487 
00488 #ifdef ENABLE_TEST_6
00489 TEST(Merging, MergeSame)
00490 #else
00491 void test6()
00492 #endif
00493 {
00494   Slam_CurvedPolygon::Outline A, B;
00495 
00496   ADD_POINT(A, 0,0,    0.2);
00497   ADD_POINT(A, 1,0,  1.);
00498   ADD_POINT(A, 0,1,  0.3);
00499 
00500   ADD_POINT(B, 0,0,    0.2);
00501   ADD_POINT(B, 1,0,  0.3);
00502   ADD_POINT(B, 0,1,  0.3);
00503 
00504   (B+A).debug_svg((A+B).debug_svg(B.debug_svg(A.debug_svg("msA.svg",400,300),400,300,"red"),400,300,"green"),400,300,"blue");
00505 }
00506 
00507 #ifdef ENABLE_TEST_7
00508 TEST(Merging, MergeSimiliar)
00509 #else
00510 void test7()
00511 #endif
00512 {
00513   Slam_CurvedPolygon::Outline A, B;
00514 
00515   ADD_POINT(A, 0,0,    0.2);
00516   ADD_POINT(A, 1,0,  0.3);
00517   ADD_POINT(A, 0,1,  0.3);
00518 
00519   ADD_POINT(B, 0,0,    0.2);
00520   ADD_POINT(B, 0.5,-1,  0.3);
00521   ADD_POINT(B, 1,0,  0.3);
00522   ADD_POINT(B, 0,1,  0.3);
00523 
00524   (B+A).debug_svg((A+B).debug_svg(B.debug_svg(A.debug_svg("msiA.svg",400,300),400,300,"red"),400,300,"green"),400,300,"blue");
00525 }
00526 
00527 #ifdef ENABLE_TEST_8
00528 TEST(Merging, MergeInner)
00529 #else
00530 void test8()
00531 #endif
00532 {
00533   Slam_CurvedPolygon::Outline A, B;
00534 
00535   ADD_POINT(A, 0,0,  0);
00536   ADD_POINT(A, 1,0,  0);
00537   ADD_POINT(A, 1,1,  0);
00538   ADD_POINT(A, 0,1,  0);
00539 
00540   ADD_POINT(B, 0,0,  0);
00541   ADD_POINT(B, 1,0,  0);
00542   ADD_POINT(B, 0.1,0.5,  0);
00543   ADD_POINT(B, 1,1,  0);
00544   ADD_POINT(B, 0,1,  0);
00545 
00546   //  A.reverse();
00547   //  B.reverse();
00548 
00549   (B+A).debug_svg((A+B).debug_svg(B.debug_svg(A.debug_svg("8A.svg",400,300),400,300,"red"),400,300,"green"),400,300,"blue");
00550 
00551   (A|B).debug_svg("8C3.svg");
00552   (B|A).debug_svg("8C4.svg");
00553 }
00554 
00555 #ifdef ENABLE_TEST_9
00556 TEST(Merging, Reverse)
00557 #else
00558 void test9()
00559 #endif
00560 {
00561   Slam_CurvedPolygon::Outline A, B;
00562 
00563   ADD_POINT(A, 0,1,  0);
00564   ADD_POINT(A, 0,0,  0);
00565   ADD_POINT(A, 1,0,  1);
00566 
00567   A.debug_svg("9A1.svg");
00568 
00569   A.reverse(true);
00570   A.debug_svg("9A2.svg");
00571 
00572   A.reverse(true);
00573   A.debug_svg("9A3.svg");
00574 }
00575 
00576 #ifdef ENABLE_TEST_10
00577 TEST(Merging, FOV)
00578 #else
00579 void test10()
00580 #endif
00581 {
00582   typedef DOF6::DOF6_Source<DOF6::TFLinkvf,DOF6::DOF6_Uncertainty<Dummy::RobotParameters,float> > DOF6;
00583   BoundingBox::FoVBB<float> A, B;
00584   Eigen::Vector3f v1, v2;
00585 
00586   v1(0) = -0.5;
00587   v1(1) = 0;
00588   v1(2) = 2;
00589   v2(0) = 0;
00590   v2(1) = 0.5;
00591   v2(2) = 2.5;
00592   A.update(v1,v2);
00593 
00594   v1(0) = -0.2;
00595   v1(1) = 0;
00596   v1(2) = 2;
00597   v2(0) = 0.7;
00598   v2(1) = 0.5;
00599   v2(2) = 2.5;
00600   B.update(v1,v2);
00601 
00602   Eigen::Matrix3f R1, R2;
00603   Eigen::Vector3f t1, t2;
00604   R1 = R2 = Eigen::Matrix3f::Identity();
00605   t1 = t2 = Eigen::Vector3f::Zero();
00606   std::cout<< ((A.transform(R1,t1) & B.transform(R2,t2))?"intersects":"not intersects") <<"\n";
00607 }
00608 
00609 #ifdef ENABLE_TEST_11
00610 TEST(Surface, Compare)
00611 #else
00612 void test11()
00613 #endif
00614 {
00615   const int NUM=10;
00616 
00617   for(size_t l=0; l<10; l++) {
00618 
00619     boost::array<float, 6> params;
00620     for(int i=0; i<6; i++)
00621       params[i] = (rand()%10000-5000)/10000.f;
00622 
00623     //    params[2]=params[4]=params[5]=0;
00624     //    params[0]=1;
00625     //    params[2]=1;params[4]=params[5]=0;
00626     //    params[5]=0;
00627 
00628     Eigen::Vector2f p2s[10];
00629     Eigen::Vector3f p3s[10];
00630 
00631     for(int i=0; i<NUM; i++)
00632     {
00633       p2s[i](0) = (rand()%10000-5000)/1000.f;
00634       p2s[i](1) = (rand()%10000-5000)/1000.f;
00635 
00636       p2s[i](0) = (i%3)*0.5f*20-10;
00637       p2s[i](1) = ((i/3)%3)*0.5f*20-10;
00638 
00639       p3s[i](0) = (rand()%10000-5000)/1000.f;
00640       p3s[i](1) = (rand()%10000-5000)/1000.f;
00641       p3s[i](2) = (rand()%10000-5000)/1000.f;
00642     }
00643 
00644     //instances to test
00645     Slam_Surface::Surface *insts[] = {new Slam_Surface::PolynomialSurface, new Slam_Surface::SurfaceNurbs};
00646     Eigen::Vector3f r1[sizeof(insts)/sizeof(Slam_Surface::Surface *)*NUM];
00647     Eigen::Vector3f r2[sizeof(insts)/sizeof(Slam_Surface::Surface *)*NUM];
00648     Eigen::Vector2f r3[sizeof(insts)/sizeof(Slam_Surface::Surface *)*NUM];
00649 
00650     int p=0;
00651 
00652     for(int i=0; i<(int)(sizeof(insts)/sizeof(Slam_Surface::Surface *)); i++)
00653     {
00654       EXPECT_EQ(insts[i]!=0,true);
00655       ROS_INFO("testing --> %s <--", insts[i]->getName());
00656       EXPECT_EQ(insts[i]->getSurfaceType(),i+1);
00657 
00658       insts[i]->init(params,-10,10, -10,10,1);
00659       //insts[i]->init(params,0,1, 0,1);
00660       if(1){ // test transform
00661         Eigen::Matrix3f R = Eigen::Matrix3f::Identity();
00662         Eigen::Vector3f t = Eigen::Vector3f::Identity()*3;
00663         Eigen::AngleAxisf aa(0.4,t);
00664         //R = aa.toRotationMatrix();
00665         insts[i]->transform(R,t);
00666       }
00667 
00668       for(int j=0; j<NUM; j++)
00669       {
00670         //p3s[j] = insts[0]->project2world(p2s[j]);
00671 
00672         r1[p] = insts[i]->project2world(p2s[j]);
00673         r2[p] = insts[i]->normalAt(p2s[j]);
00674         r3[p] = insts[i]->nextPoint(p3s[j]);
00675 
00676         Eigen::Vector2f pt = insts[i]->nextPoint(r1[p]);
00677 
00678         std::cout<<pt<<"\n\n";
00679         std::cout<<p2s[j]<<"\n";
00680         std::cout<<"-------\n";
00681 
00682         EXPECT_NEAR( (insts[i]->project2world(pt)-r1[p]).squaredNorm(), 0.f, 0.01f);
00683 
00684         ++p;
00685       }
00686     }
00687 
00688     //check instances against each other
00689     p=NUM;
00690     for(int i=1; i<(int)(sizeof(insts)/sizeof(Slam_Surface::Surface *)); i++)
00691     {
00692 
00693       for(int j=0; j<NUM; j++)
00694       {
00695 
00696 #if 1
00697         std::cout<<p2s[p%NUM]<<"\n\n";
00698         std::cout<<r1[p]<<"\n\n";
00699         std::cout<<r1[p%NUM]<<"\n";
00700         std::cout<<"-------\n";
00701 
00702         std::cout<<r2[p]<<"\n\n";
00703         std::cout<<r2[p%NUM]<<"\n";
00704         std::cout<<"-------\n";
00705 
00706         std::cout<<r3[p]<<"\n\n";
00707         std::cout<<r3[p%NUM]<<"\n";
00708 
00709         std::cout<< (insts[i]->project2world(r3[p])-p3s[j]).norm() <<"  "<< (insts[0]->project2world(r3[p%NUM])-p3s[j]).norm()<<"\n";
00710         std::cout<<"-------\n";
00711 #else
00712         EXPECT_NEAR( (r1[p]-r1[p%NUM]).squaredNorm(), 0.f, 0.01f);
00713         EXPECT_NEAR( (r2[p]-r2[p%NUM]).squaredNorm(), 0.f, 0.01f);
00714         EXPECT_NEAR( (r3[p]-r3[p%NUM]).squaredNorm(), 0.f, 0.01f);
00715 #endif
00716 
00717         ++p;
00718       }
00719 
00720     }
00721 
00722   }
00723 }
00724 
00725 
00726 
00727 #ifdef ENABLE_TEST_12
00728 TEST(Surface, Compare2)
00729 #else
00730 void test12()
00731 #endif
00732 {
00733   boost::array<float, 6> params;
00734   for(int i=0; i<6; i++)
00735     params[i] = (rand()%10000-5000)/10000.f;
00736 
00737   Slam_Surface::SurfaceNurbs inst;
00738 
00739   inst.init(params,-10,10, -10,10, 1);
00740 
00741   Eigen::Vector3f p;
00742   p(0) = 3.;
00743   p(1) = 5.;
00744   p(2) = 0.;
00745   Eigen::Vector2f p2;
00746   p2(0) = 0.4;
00747   p2(1) = 0.7;
00748   //p=inst._project2world(p2);
00749   inst.nextPoint(p);
00750 }
00751 
00752 #include <cob_3d_mapping_slam/trispline/trispline.h>
00753 
00754 
00755 void Surface2PCD(const Slam_Surface::Surface *surf, pcl::PointCloud<pcl::PointXYZRGB> &pc, const float Fsize, const int r, const int g, const int b) {
00756 
00757   pcl::PointXYZRGB p;
00758   p.r = r;
00759   p.g = g;
00760   p.b = b;
00761   Eigen::Vector2f p3;
00762 
00763   const float F=1;
00764 
00765   for(float x=-Fsize*F; x<=Fsize*F; x+=Fsize/20) {
00766     for(float y=-Fsize*F; y<=Fsize*F; y+=Fsize/20) {
00767       Eigen::Vector3f v;
00768 
00769       p.r = (x+F*Fsize)/(2*F*Fsize)*255;
00770       p.g = (y+F*Fsize)/(2*F*Fsize)*255;
00771 
00772       p3(0) = x;
00773       p3(1) = y;
00774       v = surf->project2world(p3);
00775       p.x = v(0);
00776       p.y = v(1);
00777       p.z = v(2);
00778       pc.points.push_back(p);
00779     }
00780   }
00781 }
00782 
00783 #ifdef ENABLE_TEST_18
00784 TEST(TriSplineSurface, Basics1)
00785 #else
00786 void test18()
00787 #endif
00788 {
00789   srand(clock());
00790 
00791 #if 0
00792   {
00793     ParametricSurface::TriSpline2_Fade abc;
00794 
00795     Eigen::Vector3f v;
00796     v.fill(0);
00797     v(0)=1;
00798     std::cout<<"TEMPLATE\n"<<abc(v)<<"\n";
00799     exit(0);
00800   }
00801 #endif
00802 
00803   boost::array<float, 6> params;
00804   for(int i=0; i<6; i++)
00805     params[i] = (rand()%10000-5000)/20000.f;
00806   /*params[0] = 0;
00807   params[1] = 0;
00808   params[2] = 1;
00809   params[3] = 0;
00810   params[4] = 0;
00811   params[5] = 0;
00812   /*params[0] = 0;
00813   params[0] = 1;
00814   params[1] = 1;
00815   params[3] = 1;
00816   params[5] = 1;
00817   params[2] = 1;
00818   params[4] = 1;*/
00819 
00820   Slam_Surface::PolynomialSurface poly;
00821   Slam_Surface::SurfaceTriSpline inst;
00822 
00823   const float Fsize = 0.017;
00824   poly.init(params,-Fsize,Fsize, -Fsize,Fsize, 1);
00825   inst.init(&poly,-Fsize,Fsize, -Fsize,Fsize, 1);
00826 
00827   if(0){
00828     Eigen::AngleAxisf aa(0.3f, Eigen::Vector3f::Identity());
00829     poly.transform(aa.toRotationMatrix(), Eigen::Vector3f::Identity());
00830     inst.transform(aa.toRotationMatrix(), Eigen::Vector3f::Identity());
00831   }
00832 
00833   Eigen::Vector3f p1,p2;
00834   Eigen::Vector2f p3;
00835 
00836   for(int i=0; i<3; i++) {
00837     for(int j=0; j<3; j++) {
00838       p3(0) = -Fsize+i*Fsize;
00839       p3(1) = -Fsize+j*Fsize;
00840 
00841       p1=inst.project2world(p3);
00842       p2=poly.project2world(p3);
00843 
00844       std::cout<<"got\n"<<p1<<"\n";
00845       std::cout<<"should\n"<<p2<<"\n";
00846 
00847       EXPECT_NEAR( (p1-p2).squaredNorm(), 0, 0.01f);
00848     }
00849   }
00850 
00851   p3(0) = -1;
00852   p3(1) = 0;
00853   std::cout<<"normal\n"<<inst.normalAt(p3)<<"\n";
00854   std::cout<<"pt\n"<<(p2=inst.project2world(p3))<<"\n";
00855   std::cout<<"normal\n"<<poly.normalAt(p3)<<"\n";
00856   std::cout<<"pt\n"<<poly.project2world(p3)<<"\n";
00857   p3 = poly.nextPoint(p2);
00858   std::cout<<"normal\n"<<poly.normalAt(p3)<<"\n";
00859   std::cout<<"pt\n"<<poly.project2world(p3)<<"\n";
00860 
00861   for(int i=0; i<10; i++) {
00862     p3(0) = i/10.f+3;
00863     p3(1) = (rand()%20)/20.f+3;
00864 
00865     Eigen::Vector3f v=inst.project2world(p3);
00866     float mi = (rand()%20)/10.f;
00867     v(0) += mi;
00868     std::cout<<"FIRST\n";
00869     Eigen::Vector2f g2 = poly.nextPoint(v);
00870     p2=poly.project2world(g2);
00871 
00872     std::cout<<"FIRST\n";
00873     p3=inst.nextPoint(v);
00874     p1=inst.project2world(p3);
00875 
00876     std::cout<<"search\n"<<v<<"\n";
00877     std::cout<<"dist "<<(p2-v).norm()<<" "<<(p1-v).norm()<<" "<<mi<<"\n";
00878     std::cout<<"should\n"<<g2<<"\n";
00879     std::cout<<"got\n"<<p3<<"\n";
00880     std::cout<<"got\n"<<p2<<"\n";
00881     std::cout<<"should\n"<<p1<<"\n";
00882     std::cout<<"should\n"<<poly.project2world(p3)<<"\n";
00883 
00884     if( (p2-v).norm()<(p1-v).norm() )
00885       EXPECT_NEAR( (p1-p2).squaredNorm(), 0, 0.01f);
00886     else
00887       std::cout<<"is even better\n";
00888 
00889     std::cout<<"normal\n"<<inst.normalAt(p3)<<"\n";
00890     std::cout<<"normal\n"<<poly.normalAt(p3)<<"\n";
00891   }
00892   //exit(0);
00893 
00894   pcl::PointCloud<pcl::PointXYZRGB> pc;
00895   pcl::PointXYZRGB p;
00896   p.b = 255;
00897   p.g = p.r = 0;
00898   /*for(size_t i=0; i<inst.getTriangles().size(); i++) {
00899     for(int j=0; j<3; j++) {
00900       Eigen::Vector3f v = inst.getTriangles()[i].I_[j];
00901       p.x = v(0);
00902       p.y = v(1);
00903       p.z = v(2);
00904       pc.points.push_back(p);
00905 
00906       v = inst.getTriangles()[i].pb_[j];
00907       p.x = v(0);
00908       p.y = v(1);
00909       p.z = v(2);
00910       pc.points.push_back(p);
00911     }
00912   }*/
00913 
00914   for(float x=-Fsize*3.f; x<=Fsize*3.f; x+=Fsize/100) {
00915     for(float y=-Fsize*3.f; y<=Fsize*3.f; y+=Fsize/100) {
00916       Eigen::Vector3f v;
00917 
00918       p3(0) = x;
00919       p3(1) = y;
00920       v = inst.project2world(p3);
00921       p.r = 255*std::abs(inst.normalAt(p3)(2));
00922       p.g = p.b = 0;
00923       p.x = v(0);
00924       p.y = v(1);
00925       p.z = v(2);
00926       //if(x>=-Fsize && x<=Fsize && y>=-Fsize && y<=Fsize)
00927       pc.points.push_back(p);
00928 
00929       v = poly.project2world(p3);
00930       p.g = 255;
00931       p.r = p.b = 0;
00932       p.x = v(0);
00933       p.y = v(1);
00934       p.z = v(2);
00935       pc.points.push_back(p);
00936     }
00937   }
00938 
00939   pcl::io::savePCDFile("test18.pcd",pc);
00940 }
00941 
00942 #ifdef ENABLE_TEST_19
00943 TEST(TriSplineSurface, Basics2)
00944 #else
00945 void test19()
00946 #endif
00947 {
00948   ros::Time::init();
00949   srand(clock());
00950 
00951   boost::array<float, 6> params;
00952   for(int i=0; i<6; i++)
00953     params[i] = 0;
00954 
00955   params[0] = 1;
00956   params[4] = -0.8f;
00957   params[2] = -0.03f;
00958 
00959   Slam_Surface::PolynomialSurface poly;
00960 
00961   const float Fsize = 0.7f;
00962   poly.init(params,-Fsize,Fsize, -Fsize,Fsize, 1);
00963 
00964   Slam_Surface::SurfaceTriSpline res;
00965 
00966   const float angle = 0.1f;
00967   const int steps = 30;
00968 
00969   Eigen::Vector3f x = Eigen::Vector3f::Zero(); x(0)=1;
00970 
00971   for(int i=0; i<steps; i++) {
00972     Slam_Surface::SurfaceTriSpline inst;
00973     inst.init(&poly,-Fsize
00974               //+i/100.f
00975               ,Fsize
00976               //-i/100.f
00977               , -Fsize,Fsize, 1);
00978 
00979     Slam_Surface::Surface::SWINDOW w;
00980     res.merge(inst,0,0,w,w);
00981 
00982     Eigen::AngleAxisf aa(angle, x);
00983     poly.transform(aa.toRotationMatrix(), Eigen::Vector3f::Zero());
00984 
00985     pcl::PointCloud<pcl::PointXYZRGB> pc;
00986     char buf[128];
00987     sprintf(buf,"test19_%d.pcd", i);
00988     Surface2PCD(&inst, pc, Fsize, 0, 255, 0);
00989     Surface2PCD(&res, pc, Fsize, 255, 0, 0);
00990     pcl::io::savePCDFile(buf,pc);
00991 
00992     std::cout<<"STEP\n";
00993     res.print();
00994 
00995     sprintf(buf,"test19_%d.bag", i);
00996     cob_3d_marker::MarkerContainer()<<new cob_3d_marker::MarkerList_Triangles(0)<<new cob_3d_marker::MarkerList_Text(4)<<new cob_3d_marker::MarkerList_Line(2)<<new cob_3d_marker::MarkerList_Arrow(3)<<res >>&cob_3d_marker::MarkerBagfile(&rosbag::Bag(buf, rosbag::bagmode::Write));
00997 
00998     //if(i==15) exit(0);
00999   }
01000 
01001   pcl::PointCloud<pcl::PointXYZRGB> pc;
01002   Surface2PCD(&res, pc, Fsize, 255, 0, 0);
01003   pcl::io::savePCDFile("test19.pcd",pc);
01004 }
01005 
01006 #include <omp.h>
01007 #ifdef ENABLE_TEST_20
01008 TEST(TriSplineSurface, Basics3)
01009 #else
01010 void test20()
01011 #endif
01012 {
01013   ros::Time::init();
01014   srand(clock());
01015 
01016   omp_set_num_threads(4);
01017 
01018   boost::array<float, 6> params;
01019   for(int i=0; i<6; i++)
01020     params[i] = (rand()%10000-5000)/10000.f;
01021 
01022   Slam_Surface::PolynomialSurface poly;
01023   Slam_Surface::SurfaceTriSpline inst;
01024 
01025   const float Fsize = 1.;
01026   poly.init(params,-Fsize,Fsize, -Fsize,Fsize, 1);
01027   inst.init(&poly,-Fsize,Fsize, -Fsize,Fsize, 1);
01028 
01029   const size_t num = 10000;
01030 
01031   double start = ros::Time::now().toSec();
01032 
01033 #pragma omp parallel for
01034   for(size_t i=0; i<num; i++) {
01035     Eigen::Vector3f p, p2;
01036     Eigen::Vector2f r;
01037     p2(0) = (rand()%2000-1000)/1000.f;
01038     p2(1) = (rand()%2000-1000)/1000.f;
01039     p2(2) = 0;//(rand()%2000-1000)/100.f;
01040 
01041     p = inst.project2world(p2.head<2>());
01042     r = inst.nextPoint(p);
01043 
01044 //    std::cout<<"should\n"<<p2.head<2>()<<"\n";
01045 //    std::cout<<"got\n"<<r<<"\n";
01046     EXPECT_NEAR( (r-p2.head<2>()).squaredNorm(), 0, 0.01f);
01047 
01048     ;
01049   }
01050 
01051   ROS_INFO("MIXED: Op. per 100ms %f", num*0.03/(ros::Time::now().toSec()-start));
01052 
01053   start = ros::Time::now().toSec();
01054 
01055   #pragma omp parallel for
01056     for(size_t i=0; i<num; i++) {
01057       Eigen::Vector3f p, p2;
01058       Eigen::Vector2f r;
01059       p2(0) = (rand()%2000-1000)/1000.f;
01060       p2(1) = (rand()%2000-1000)/1000.f;
01061       p2(2) = 0;//(rand()%2000-1000)/100.f;
01062 
01063       p = poly.project2world(p2.head<2>());
01064       r = poly.nextPoint(p);
01065 
01066   //    std::cout<<"should\n"<<p2.head<2>()<<"\n";
01067   //    std::cout<<"got\n"<<r<<"\n";
01068       EXPECT_NEAR( (r-p2.head<2>()).squaredNorm(), 0, 0.01f);
01069 
01070       ;
01071     }
01072 
01073     ROS_INFO("POLY MIXED: Op. per 100ms %f", num*0.03/(ros::Time::now().toSec()-start));
01074 
01075 //  params[1]=10;
01076 //  params[3]=0.1;
01077   params[2]=params[4]=params[5]=0;
01078   start = ros::Time::now().toSec();
01079 
01080 #pragma omp parallel for
01081   for(size_t i=0; i<num; i++) {
01082     Eigen::Vector3f p, p2;
01083     Eigen::Vector2f r;
01084     p2(0) = (rand()%2000-1000)/1000.f;
01085     p2(1) = (rand()%2000-1000)/1000.f;
01086     p2(2) = 0;//p(2) = (rand()%2000-1000)/100.f;
01087 
01088     p = inst.project2world(p2.head<2>());
01089     r = inst.nextPoint(p);
01090 
01091 //    std::cout<<"should\n"<<p2.head<2>()<<"\n";
01092 //    std::cout<<"got\n"<<r<<"\n";
01093     EXPECT_NEAR( (r-p2.head<2>()).squaredNorm(), 0, 0.01f);
01094   }
01095 
01096   ROS_INFO("PLANE: Op. per 100ms %f", num*0.03/(ros::Time::now().toSec()-start));
01097 
01098     start = ros::Time::now().toSec();
01099 
01100   #pragma omp parallel for
01101     for(size_t i=0; i<num; i++) {
01102       Eigen::Vector3f p, p2;
01103       Eigen::Vector2f r;
01104       p2(0) = (rand()%2000-1000)/1000.f;
01105       p2(1) = (rand()%2000-1000)/1000.f;
01106       p2(2) = 0;//p(2) = (rand()%2000-1000)/100.f;
01107 
01108       p = poly.project2world(p2.head<2>());
01109       r = poly.nextPoint(p);
01110 
01111   //    std::cout<<"should\n"<<p2.head<2>()<<"\n";
01112   //    std::cout<<"got\n"<<r<<"\n";
01113       EXPECT_NEAR( (r-p2.head<2>()).squaredNorm(), 0, 0.01f);
01114     }
01115 
01116     ROS_INFO("POLY PLANE: Op. per 100ms %f", num*0.03/(ros::Time::now().toSec()-start));
01117 }
01118 
01119 template<typename T>
01120 void addBB(visualization_msgs::Marker &marker, const T&bb, const ::std_msgs::ColorRGBA &col, const Eigen::Matrix3f &tmp_rot, const Eigen::Vector3f &tmp_tr) {
01121   geometry_msgs::Point line_p;
01122   Eigen::Vector3f edges[8];
01123 
01124   bb.get8Edges(edges);
01125   for(int i=0; i<8; i++)
01126     edges[i] = tmp_rot*edges[i]+tmp_tr;
01127 
01128   for(int i=0; i<4; i++)
01129   {
01130     line_p.x = edges[2*i](0);
01131     line_p.y = edges[2*i](1);
01132     line_p.z = edges[2*i](2);
01133     marker.points.push_back(line_p);
01134     marker.colors.push_back(col);
01135     line_p.x = edges[2*i+1](0);
01136     line_p.y = edges[2*i+1](1);
01137     line_p.z = edges[2*i+1](2);
01138     marker.points.push_back(line_p);
01139     marker.colors.push_back(col);
01140   }
01141 
01142   int conv[]={0,1,4,5};
01143   for(int j=0; j<4; j++)
01144   {
01145     int i=conv[j];
01146     line_p.x = edges[i](0);
01147     line_p.y = edges[i](1);
01148     line_p.z = edges[i](2);
01149     marker.points.push_back(line_p);
01150     marker.colors.push_back(col);
01151     line_p.x = edges[i+2](0);
01152     line_p.y = edges[i+2](1);
01153     line_p.z = edges[i+2](2);
01154     marker.points.push_back(line_p);
01155     marker.colors.push_back(col);
01156   }
01157 
01158   for(int i=0; i<4; i++)
01159   {
01160     line_p.x = edges[i](0);
01161     line_p.y = edges[i](1);
01162     line_p.z = edges[i](2);
01163     marker.points.push_back(line_p);
01164     marker.colors.push_back(col);
01165     line_p.x = edges[i+4](0);
01166     line_p.y = edges[i+4](1);
01167     line_p.z = edges[i+4](2);
01168     marker.points.push_back(line_p);
01169     marker.colors.push_back(col);
01170   }
01171 }
01172 
01173 #ifdef ENABLE_TEST_17
01174 TEST(BB, OOBB)
01175 #else
01176 void test17()
01177 #endif
01178 {
01179   {
01180     PlNurbsSurfaceSPf nurbs_;
01181     Matrix_Point3Df Pts(3,3);
01182     for(int i=0;i<3;++i){
01183       for(int j=0;j<3;++j){
01184         Pts(i,j) = PlPoint3Df((i-1)*(j+1), j*2,
01185                               0
01186         ) ;
01187       }
01188     }
01189     nurbs_.globalInterp(Pts,2,2);
01190 
01191     Eigen::Vector3f map[100][100];
01192 
01193     for(int i=0; i<1000; i++)  {
01194 
01195       for(int j=0; j<100; j++) {
01196         for(int k=0; k<100; k++) {
01197           PlPoint3Df p = nurbs_.pointAt(j/99.f,k/99.f);
01198           map[j][k](0) = p.x();
01199           map[j][k](1) = p.y();
01200           map[j][k](2) = p.z();
01201         }
01202       }
01203 
01204       //10 planes
01205       for(int m=0; m<10; m++) {
01206         Eigen::Vector3f n, p3;
01207         n(0) = (rand()%100)/100.f;
01208         n(1) = (rand()%100)/100.f;
01209         n(2) = (rand()%100)/100.f;
01210         p3(0) = (rand()%100)/100.f;
01211         p3(1) = (rand()%100)/100.f;
01212         p3(2) = (rand()%100)/100.f;
01213         n.normalize();
01214 
01215         int num=0;
01216         for(int j=0; j<99; j++) {
01217           for(int k=0; k<99; k++) {
01218             float f;
01219             f=n.dot(p3-map[j][k])/n.dot(map[j+1][k]-map[j][k]);
01220             if(f>=0&&f<1) num++;
01221             f=n.dot(p3-map[j][k])/n.dot(map[j][k+1]-map[j][k]);
01222             if(f>=0&&f<1) num++;
01223           }
01224         }
01225 
01226         std::cout<<num<<"\n";
01227       }
01228     }
01229     //nurbs_.writeVRML97("torus.wrl");
01230   }
01231 
01232 
01233   ros::Time::init();
01234 
01235   rosbag::Bag bag_out;
01236   bag_out.open("merging17.bag", rosbag::bagmode::Write);
01237   ::std_msgs::ColorRGBA col;
01238   col.g = col.r = col.b=0;
01239 
01240   visualization_msgs::Marker marker;
01241   marker.header.frame_id = "/openni_rgb_optical_frame";
01242   marker.pose.position.x = 0;
01243   marker.pose.position.y = 0;
01244   marker.pose.position.z = 0;
01245   marker.pose.orientation.x = 0.0;
01246   marker.pose.orientation.y = 0.0;
01247   marker.pose.orientation.z = 0.0;
01248   marker.pose.orientation.w = 1.0;
01249   marker.action = visualization_msgs::Marker::ADD;
01250   marker.color.r = marker.color.g = marker.color.b =  marker.color.a = 1;
01251   marker.type = visualization_msgs::Marker::LINE_LIST;
01252   marker.scale.x = marker.scale.y = marker.scale.z = 0.01;
01253   marker.id = 5;
01254 
01255 
01256 
01257   //no intersection
01258   for(int i=0; i<100; i++) {
01259     if( !(i&1) && !(i&2) && !(i&4) ) continue;
01260 
01261     pcl::PointCloud<pcl::PointXYZ> pc1, pc2;
01262     pcl::PointXYZ p;
01263     for(int j=0; j<100; j++) {
01264       p.x=(rand()%10000-5000)/10000.f;
01265       p.y=(rand()%10000-5000)/10000.f;
01266       p.z=(rand()%10000-5000)/10000.f;
01267       pc1.push_back(p);
01268     }
01269     for(int j=0; j<100; j++) {
01270       p.x=(rand()%10000-5000)/10000.f+(i&1?2.3f:0);
01271       p.y=(rand()%10000-5000)/10000.f+(i&2?2.3f:0);
01272       p.z=(rand()%10000-5000)/10000.f+(i&4?2.3f:0);
01273       pc2.push_back(p);
01274     }
01275     BoundingBox::OOBB bb1,bb2;
01276     bb1.set(pc1);
01277     bb2.set(pc2);
01278 
01279     bb1.debug();
01280     bb2.debug();
01281 
01282     bool in=bb1&bb2;
01283     if(in) {
01284       addBB(marker,bb1,col,Eigen::Matrix3f::Identity(),Eigen::Vector3f::Zero());
01285       col.r=1;
01286       addBB(marker,bb2,col,Eigen::Matrix3f::Identity(),Eigen::Vector3f::Zero());
01287 
01288       bag_out.write("/markers", ros::Time::now(), marker);
01289       bag_out.close();
01290 
01291       std::cout<<std::endl;
01292 
01293       exit(0);
01294     }
01295     EXPECT_FALSE(in);
01296   }
01297 
01298   //intersection
01299   for(int i=0; i<100; i++) {
01300     pcl::PointCloud<pcl::PointXYZ> pc1, pc2;
01301     pcl::PointXYZ p;
01302     for(int j=0; j<100; j++) {
01303       p.x=(rand()%10000-5000)/10000.f;
01304       p.y=(rand()%10000-5000)/10000.f;
01305       p.z=(rand()%10000-5000)/10000.f;
01306       pc1.push_back(p);
01307     }
01308     for(int j=0; j<100; j++) {
01309       p.x=(rand()%10000-5000)/10000.f+(i&1?.5f:0);
01310       p.y=(rand()%10000-5000)/10000.f+(i&2?.5f:0);
01311       p.z=(rand()%10000-5000)/10000.f+(i&4?.5f:0);
01312       pc2.push_back(p);
01313     }
01314     BoundingBox::OOBB bb1,bb2;
01315     bb1.set(pc1);
01316     bb2.set(pc2);
01317 
01318     EXPECT_TRUE(bb1&bb2);
01319   }
01320 
01321   {
01322     pcl::PointCloud<pcl::PointXYZ> pc1, pc2;
01323     pcl::PointXYZ p;
01324     for(int i=0; i<10; i++)
01325       for(int j=0; j<10; j++) {
01326         p.x=i;
01327         p.y=j;
01328         p.z=0;
01329         pc1.push_back(p);
01330       }
01331     for(int i=0; i<10; i++)
01332       for(int j=0; j<10; j++) {
01333         p.x=i;
01334         p.y=j/2+3;
01335         p.z=i-3;
01336         pc2.push_back(p);
01337       }
01338     BoundingBox::OOBB bb1,bb2;
01339     bb1.set(pc1);
01340     bb2.set(pc2);
01341 
01342     EXPECT_TRUE(bb1&bb2);
01343   }
01344 
01345 }
01346 
01347 
01348 int main(int argc, char **argv){
01349   testing::InitGoogleTest(&argc, argv);
01350   return RUN_ALL_TESTS();
01351 }
01352 


cob_3d_mapping_slam
Author(s): Joshua Hampp
autogenerated on Wed Aug 26 2015 11:04:51