$search
00001 00061 #include "cob_3d_mapping_common/cylinder.h" 00062 00063 using namespace cob_3d_mapping; 00064 00065 00066 00067 void 00068 transform_cylinder(CylinderPtr & c_ptr,Eigen::Affine3f& trafo) 00069 { 00070 00071 00072 Cylinder & c=*c_ptr; 00073 00074 for (int i = 0; i < (int) c.contours.size(); ++i) { 00075 for (int j = 0; j < (int) c.contours[i].size(); ++j) { 00076 00077 00078 c.contours[i][j]=trafo*c.contours[i][j]; 00079 00080 00081 } 00082 } 00083 00084 c.origin_=trafo*c.origin_; 00085 std::cout<<"transformed origin\n"<<c.origin_<<std::endl; 00086 00087 00088 c.sym_axis=trafo.rotation()*c.sym_axis; 00089 c.normal = trafo.rotation()*c.normal; 00090 // std::cout<<"axis -"<<i<<" \n"<<c.axes_[i]<<std::endl; 00091 c.normal=trafo.rotation()*c.normal; 00092 00093 float roll,pitch,yaw,x,y,z; 00094 pcl::getTranslationAndEulerAngles(trafo,x,y,z,roll,pitch,yaw); 00095 // std::cout<<" x= "<<x<<" y= "<<z<<" z= "<<z<<" roll= "<<roll<<" pitch= "<<pitch<<" yaw= "<<yaw<<std::endl; 00096 00097 c.computeAttributes(c.sym_axis, c.normal, c.origin_); // configure unrolled polygon 00098 } 00099 00100 00101 int main(int argc, char **argv) { 00102 00103 00104 //#################################################### 00105 //Cylinder #1 00106 00107 CylinderPtr c1 =CylinderPtr(new Cylinder()); 00108 c1->id = 0; 00109 00110 Eigen::Vector3f x_axis1,y_axis1,z_axis1; 00111 std::vector<Eigen::Vector3f> axes1; 00112 Eigen::Vector3f origin1; 00113 std::vector<Eigen::Vector3f> contour1; 00114 std::vector<std::vector<Eigen::Vector3f> > contours1; 00115 00116 Eigen::Vector3f v1; 00117 00118 00119 x_axis1 << 1,0,0; 00120 axes1.push_back(x_axis1); 00121 00122 y_axis1 << 0,0,1; 00123 axes1.push_back(y_axis1); 00124 00125 z_axis1 << 0,1,0; 00126 axes1.push_back(z_axis1); 00127 00128 c1->sym_axis = y_axis1; 00129 c1->normal = z_axis1; 00130 c1->r_=1; 00131 00132 00133 00134 v1 << -1, 0, 1; 00135 contour1.push_back(v1); 00136 v1 << 0, 1, 1; 00137 contour1.push_back(v1); 00138 v1 << 1, 0, 1; 00139 contour1.push_back(v1); 00140 v1 << 1 ,0 ,-1; 00141 contour1.push_back(v1); 00142 v1 << 0, 1, -1; 00143 contour1.push_back(v1); 00144 v1 << -1, 0 ,-1; 00145 contour1.push_back(v1); 00146 00147 c1->merged=0; 00148 origin1 << 0,0,0; 00149 c1->origin_=origin1; 00150 00151 c1->holes.push_back(0); 00152 c1->debug_=true; 00153 00154 contours1.push_back(contour1); 00155 c1->ContoursFromList(contours1); 00156 00157 00158 00159 00160 00161 00162 // c1->r_=1; 00163 00164 00165 00166 00167 // if (c1->debug_== true) { 00168 // 00169 // std::cout<<"goa-tz C1--> new vertices"<<std::endl; 00170 // for (int i = 0; i < (int) c1->contours.size(); ++i) { 00171 // for (int j = 0; j < (int) c1->contours[i].size(); ++j) { 00172 // 00173 // std::cout<<"contor "<<i<<" vertex "<<j <<" : "<<std::endl<<"~~~~"<<std::endl<<c1->contours[i][j]<<std::endl<<std::endl; 00174 // } 00175 // } 00176 // } 00177 00178 00179 00180 00181 00182 00183 //#################################################### 00184 //Cylinder #2 00185 CylinderPtr c2 =CylinderPtr(new Cylinder()); 00186 c2->id = 0; 00187 00188 Eigen::Vector3f x_axis2,y_axis2,z_axis2; 00189 std::vector<Eigen::Vector3f> axes2; 00190 Eigen::Vector3f origin2; 00191 std::vector<Eigen::Vector3f> contour2; 00192 std::vector<std::vector<Eigen::Vector3f> > contours2; 00193 Eigen::Vector3f v2; 00194 00195 00196 x_axis2 << 1,0,0; 00197 axes2.push_back(x_axis2); 00198 00199 y_axis2 << 0,0,1; 00200 axes2.push_back(y_axis2); 00201 00202 z_axis2 << 0,1,0; 00203 axes2.push_back(z_axis2); 00204 00205 c2->sym_axis=y_axis2; 00206 c2->normal = z_axis2; 00207 c2->r_=1; 00208 00209 00210 00211 v2 << -1, 0, 1; 00212 contour2.push_back(v2); 00213 v2 << 0.1, 0, 1; 00214 contour2.push_back(v2); 00215 v2 << 1, 0, 1; 00216 contour2.push_back(v2); 00217 v2 << 1 ,0 ,-1; 00218 contour2.push_back(v2); 00219 v2 << 0.1, 0, -1; 00220 contour2.push_back(v2); 00221 v2 << -1, 0 ,-1; 00222 contour2.push_back(v2); 00223 00224 c2->merged=0; 00225 origin1 << 0,0,0; 00226 c2->origin_=origin2; 00227 00228 c2->holes.push_back(0); 00229 c2->debug_=false; 00230 00231 contours2.push_back(contour2); 00232 c2->ContoursFromList(contours2); 00233 00234 00235 00236 // if (c2->debug_== true) { 00237 // 00238 // std::cout<<"goa-tz C2--> new vertices"<<std::endl; 00239 // for (int i = 0; i < (int) c2->contours.size(); ++i) { 00240 // for (int j = 0; j < (int) c2->contours[i].size(); ++j) { 00241 // 00242 // std::cout<<"contor "<<i<<" vertex "<<j <<" : "<<std::endl<<"~~~~"<<std::endl<<c2->contours[i][j]<<std::endl<<std::endl; 00243 // } 00244 // } 00245 // } 00246 00247 00248 //transform cylinders 00249 00250 float x,y,z,roll,pitch,yaw; 00251 00252 x=1; 00253 y=2; 00254 z=3; 00255 roll=0.2; 00256 pitch=0.4; 00257 yaw=1; 00258 00259 00260 Eigen::Affine3f trafo; 00261 pcl::getTransformation(x,y,z,roll,pitch,yaw,trafo); 00262 00263 transform_cylinder(c1,trafo); 00264 transform_cylinder(c2,trafo); 00265 00266 00267 00268 00269 std::string s_c1 = "c1->unrolled"; 00270 00271 std::string s_c2 = "c2->unrolled"; 00272 //####################################################### 00273 // completion test 00274 // c1->completeCylinder(); 00275 // c2->completeCylinder(); 00276 // std::cout<<"X-axis = \n"<<c1->axes_[0]<<std::endl; 00277 // std::cout<<"X-axis = \n"<<c2->axes_[0]<<std::endl; 00278 00279 00280 std::cout<<"r = "<<c1->r_<<std::endl; 00281 std::cout<<"r = "<<c2->r_<<std::endl; 00282 00283 00284 00285 00286 //####################################################### 00287 // cylinders from octave script 00288 //####################################################### 00289 00290 00291 00292 00293 //#################################################### 00294 //Is merge??? 00295 00296 // std::cout<<"c1"<<c1->unrolled_.normal<<std::endl; 00297 // std::cout<<"c2"<<c2->unrolled_.normal<<std::endl; 00298 00299 std::vector<CylinderPtr> c_map; 00300 std::vector<int> intersections; 00301 merge_config limits; 00302 limits.angle_thresh=0.97; 00303 limits.d_thresh= 0.1; 00304 00305 //c_map.push_back(c2); 00306 00307 c_map.push_back(c2); 00308 //c_map.push_back(c3); 00309 00310 00311 c1->isMergeCandidate(c_map,limits,intersections); 00312 std::vector<CylinderPtr> merge_candidates ; 00313 00314 for(int i=0;i<(int)intersections.size();i++) 00315 { 00316 00317 merge_candidates.push_back(c_map[intersections[i]]); 00318 } 00319 std::cout<<"intersections size: ="<<intersections.size()<<std::endl; 00320 00321 std::cout<<"merge_candidates size: ="<<merge_candidates.size()<<std::endl; 00322 00323 00324 if(merge_candidates.size()>0){ 00325 c1->merge(merge_candidates); 00326 // 00327 // 00328 00329 Cylinder& result=*merge_candidates[0]; 00330 //result.unrolled_.debug_output("result_polygon"); 00331 // std::cout<<"goa-tz MERGED--> new vertices"<<std::endl; 00332 // for (int i = 0; i < (int) result.contours.size(); ++i) { 00333 // for (int j = 0; j < (int) result.contours[i].size(); ++j) { 00334 // 00335 // std::cout<<"contor "<<i<<" vertex "<<j <<" : "<<std::endl<<"~~~~"<<std::endl<<result.contours[i][j]<<std::endl<<std::endl; 00336 // } 00337 // } 00338 // 00339 00340 00341 00342 00343 std::vector<std::vector<Eigen::Vector3f> > con3d; 00344 00345 c1->getCyl3D(con3d); 00346 00347 std::cout<<"c1 - size"<<c1->contours[0].size()<<std::endl; 00348 std::cout<<"con3d - size"<<con3d[0].size()<<std::endl; 00349 00350 00351 for (int i = 0; i < con3d.size(); ++i) { 00352 for (int j = 0; j < con3d[i].size(); ++j) { 00353 00354 std::cout<<con3d[i][j]<<std::endl<<std::endl; 00355 00356 } 00357 00358 00359 } 00360 } 00361 00362 00363 00364 00365 00366 return 1; 00367 } 00368