00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054 #pragma once
00055
00056 #include "invariant_surface_feature.hpp"
00057 #include "gtest/gtest.h"
00058
00059
00060 template<const int num_radius_, const int num_angle_, typename TSurface, typename Scalar, typename TAffine>
00061 void cob_3d_features::InvariantSurfaceFeature<num_radius_,num_angle_,TSurface,Scalar,TAffine>::test_addOffset(const Scalar off_x, const Scalar off_y, const Scalar off_z) {
00062 for(size_t i=0; i<input_->size(); i++) {
00063 (*input_)[i].model_.p(0) += off_z;
00064 for(size_t j=0; j<(*input_)[i].segments_.size(); j++)
00065 for(size_t k=0; k<(*input_)[i].segments_[j].size(); k++) {
00066 (*input_)[i].segments_[j][k](0) += off_x;
00067 (*input_)[i].segments_[j][k](1) += off_y;
00068 }
00069 }
00070
00071 for(size_t i=0; i<triangulated_input_.size(); i++) {
00072 for(int j=0; j<3; j++) {
00073 triangulated_input_[i].p_[j](0) += off_x;
00074 triangulated_input_[i].p_[j](1) += off_y;
00075 }
00076 triangulated_input_[i].compute(radii_);
00077 }
00078 }
00079
00080 template<const int num_radius_, const int num_angle_, typename TSurface, typename Scalar, typename TAffine>
00081 void cob_3d_features::InvariantSurfaceFeature<num_radius_,num_angle_,TSurface,Scalar,TAffine>::test_rotate(const Scalar angle) {
00082 for(size_t i=0; i<triangulated_input_.size(); i++) {
00083 std::cout<<"AAAAA "<<i<<std::endl;
00084 triangulated_input_[i].print();
00085 }
00086
00087 const Scalar s = std::sin(angle);
00088 const Scalar c = std::cos(angle);
00089
00090 Eigen::Matrix<Scalar, 2,2> R3;
00091 Eigen::Matrix<float, 4,4> R, Ri;
00092 Eigen::Matrix3f R2;
00093 R.fill(0);
00094 R(0,0)=1;
00095 R(1,1)=c; R(1,2)=-s;
00096 R(2,1)=s; R(2,2)=c;
00097 Ri = R;
00098 Ri(2,1)*=-1;
00099 Ri(1,2)*=-1;
00100
00101 R2.fill(0);
00102 R2(2,2)=1;
00103 R2(0,0)=c; R2(0,1)=-s;
00104 R2(1,0)=s; R2(1,1)=c;
00105
00106 R3.fill(0);
00107 R3(0,0)=c; R3(0,1)=-s;
00108 R3(1,0)=s; R3(1,1)=c;
00109
00110 for(size_t i=0; i<input_->size(); i++) {
00111 (*input_)[i].model_.p = Ri*(*input_)[i].model_.p;
00112 for(size_t j=0; j<(*input_)[i].segments_.size(); j++)
00113 for(size_t k=0; k<(*input_)[i].segments_[j].size(); k++)
00114 (*input_)[i].segments_[j][k] = R2*(*input_)[i].segments_[j][k];
00115 }
00116
00117 for(size_t i=0; i<triangulated_input_.size(); i++) {
00118 for(int j=0; j<3; j++)
00119 triangulated_input_[i].p_[j] = R3*triangulated_input_[i].p_[j];
00120 triangulated_input_[i].compute(radii_);
00121 std::cout<<"BBBBB "<<i<<std::endl;
00122 triangulated_input_[i].print();
00123 }
00124 }
00125
00126 template<const int num_radius_, const int num_angle_, typename TSurface, typename Scalar, typename TAffine>
00127 pcl::PolygonMesh::Ptr cob_3d_features::InvariantSurfaceFeature<num_radius_,num_angle_,TSurface,Scalar,TAffine>::test_subsampling_of_Map(const int num, const Scalar r2) {
00128
00129 input_.reset(new TSurfaceList);
00130 input_->resize(num);
00131 triangulated_input_.clear();
00132 for(int i=0; i<num; i++) {
00133
00134 typename TSurface::Model *model = &(*input_)[i].model_;
00135 model->p = model->p.Random();
00136
00137
00138 Triangle t;
00139 (*input_)[i].segments_.resize(1);
00140 for(int j=0; j<3; j++) {
00141 t.p_[j] = t.p_[j].Random();
00142 Eigen::Vector3f v = Eigen::Vector3f::Zero();
00143 v.head<2>() = t.p_[j].template cast<float>();
00144 (*input_)[i].segments_[0].push_back(v);
00145 }
00146 t.model_ = model;
00147 t.compute(radii_);
00148 triangulated_input_.push_back(t);
00149 }
00150
00151
00152 std::vector<Triangle> res;
00153
00154 subsample(Eigen::Matrix<Scalar, 3, 1>::UnitX(), r2, res);
00155
00156 return dbg_triangles2mesh(res);
00157 }
00158
00159 template<const int num_radius_, const int num_angle_, typename TSurface, typename Scalar, typename TAffine>
00160 bool cob_3d_features::InvariantSurfaceFeature<num_radius_,num_angle_,TSurface,Scalar,TAffine>::test_singleTriangle(const int num) const {
00161
00162 bool zero_model = false, random_triangles=true;
00163 int test = 0, tests_succeeded=0, tests_num=0;
00164
00165 for(int i=0; i<num; i++) {
00166
00167 typename TSurface::Model model;
00168 if(zero_model)
00169 model.p.fill(0);
00170 else
00171 model.p = model.p.Random();
00172 model.p(0) += 2;
00173
00174
00175
00176 Triangle t;
00177 if(random_triangles) {
00178 for(int j=0; j<3; j++) t.p_[j] = t.p_[j].Random();
00179 } else {
00180 t.p_[0](0)=0;
00181 t.p_[0](1)=0;
00182 t.p_[1](0)=0;
00183 t.p_[1](1)=1;
00184 t.p_[2](0)=1;
00185 t.p_[2](1)=1;
00186 }
00187 t.model_ = &model;
00188 t.compute(radii_);
00189
00190
00191
00192 Triangle t1 = t, t2=t, t3=t;
00193 t1.p_[0] = (t.p_[0]+t.p_[1]+t.p_[2])/3;
00194 t2.p_[1] = (t.p_[0]+t.p_[1]+t.p_[2])/3;
00195 t3.p_[2] = (t.p_[0]+t.p_[1]+t.p_[2])/3;
00196
00197 t1.compute(radii_);
00198 t2.compute(radii_);
00199 t3.compute(radii_);
00200
00201 if(test==0) {
00202 Scalar m=0.9,n=0.4,p=0;
00203
00204 for(m=0; m<=3; m++)
00205 for(n=0; n<=3; n++)
00206 for(p=0; p<=3; p++)
00207 {
00208 std::complex<Scalar> c, c2, c3;
00209
00210 std::cout<<"mnp "<<m<<" "<<n<<" "<<p <<" ------------------------"<<std::endl;
00211 c = t1.kernel(m,n,p);
00212 std::cout<< c<<" "<<std::abs(c) <<std::endl<<std::endl;
00213 c = t2.kernel(m,n,p);
00214 std::cout<< c<<" "<<std::abs(c) <<std::endl<<std::endl;
00215 c = t3.kernel(m,n,p);
00216 std::cout<< c<<" "<<std::abs(c) <<std::endl<<std::endl;
00217
00218 std::cout<<"mnp "<<m<<" "<<n<<" "<<p <<" -------------------11111"<<std::endl;
00219 c = (t1.kernel(m,n,p)+t2.kernel(m,n,p)+t3.kernel(m,n,p));
00220 std::cout<< c<<" "<<std::abs(c) <<std::endl<<std::endl;
00221 std::cout<<"mnp "<<m<<" "<<n<<" "<<p <<" -------------------22222"<<std::endl;
00222 c2 = t.kernel(m,n,p);
00223 std::cout<< c2<<" "<<std::abs(c2) <<std::endl<<std::endl;
00224 std::cout<<"----------------------------------------"<<std::endl;
00225
00226 t1.print();
00227 t2.print();
00228 t3.print();
00229 t.print();
00230
00231 std::cout<<"model: "<<model.p.transpose()<<std::endl;
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244 EXPECT_NEAR(c.real(),c2.real(), 0.05);
00245 EXPECT_NEAR(c.imag(),c2.imag(), 0.05);
00246 EXPECT_TRUE(c==c);
00247
00248 tests_succeeded += (std::abs(c-c2) < 0.1&&c==c)?1:0;
00249 tests_num++;
00250
00251
00252
00253 }
00254 }
00255 else if(test==1) {
00256 FeatureAngleComplex sum1, sum2; sum1.fill(0); sum2.fill(0);
00257 for(size_t j=0; j<radii_.size(); j++)
00258 for(size_t k=0; k<num_radius_; k++) {
00259 sum1 += t1.f_[j].vals[k]+t2.f_[j].vals[k]+t3.f_[j].vals[k];
00260 sum2 += t.f_[j].vals[k];
00261
00262 std::cout<<"==================="<<std::endl;
00263 std::cout<<std::endl<<(t1.f_[j].vals[k])<<std::endl<<std::endl;
00264 std::cout<<std::endl<<(t2.f_[j].vals[k])<<std::endl<<std::endl;
00265 std::cout<<std::endl<<(t3.f_[j].vals[k])<<std::endl<<std::endl;
00266 std::cout<<"###################"<<std::endl;
00267 std::cout<<std::endl<<(t1.f_[j].vals[k]+t2.f_[j].vals[k]+t3.f_[j].vals[k])<<std::endl<<std::endl;
00268 std::cout<<t.f_[j].vals[k]<<std::endl;
00269 }
00270
00271 std::cout<<"----------------------------------------"<<std::endl;
00272 std::cout<<std::endl<<sum1<<std::endl<<std::endl;
00273 std::cout<<sum2<<std::endl;
00274 std::cout<<"----------------------------------------"<<std::endl;
00275 std::cout<<sum2-sum1<<std::endl;
00276
00277 std::cout<<"model: "<<model.p.transpose()<<std::endl;
00278
00279 EXPECT_TRUE( sum1.isApprox(sum2, 0.001) );
00280
00281
00282
00283 }
00284 else return false;
00285 }
00286
00287 std::cout<<"Tests: "<<tests_succeeded<<"/"<<tests_num<<std::endl;
00288
00289 return tests_succeeded==tests_num;
00290 }
00291
00292 template<const int num_radius_, const int num_angle_, typename TSurface, typename Scalar, typename TAffine>
00293 void cob_3d_features::InvariantSurfaceFeature<num_radius_,num_angle_,TSurface,Scalar,TAffine>::Triangle::print() const {
00294 std::cout<< "Triangle "<< model_ <<std::endl;
00295 for(int i=0; i<3; i++)
00296 std::cout<<p_[i].transpose()<<std::endl;
00297 for(int i=0; i<3; i++) {
00298 std::cout<<p3_[i].transpose()<<std::endl;
00299 assert(at(p_[i])==p3_[i]);
00300 }
00301
00302
00303
00304
00305 }