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
00036 #ifndef _polygon_primitive_with_texture_CPP_
00037 #define _polygon_primitive_with_texture_CPP_
00038
00039
00040 #include "polygon_primitive_with_texture.h"
00041
00042 int c_polygon_primitive_with_texture::compute_projection_union(void)
00043 {
00044 ROS_INFO("Computing the projection union");
00045 dp.projection_union.erase(dp.projection_union.begin(), dp.projection_union.end());
00046
00047 if (cp.size()>0)
00048 {
00049 tf::Transform tf_inv = data.frames.current.transform.inverse();
00050 class_polygon_boolean_operations pbo;
00051 pbo.set_transform(&tf_inv);
00052 pbo.insert(&cp[0].vertex_intersection);
00053
00054 for (size_t i=1; i< cp.size(); i++)
00055 {
00056 pbo.join(&cp[i].vertex_intersection);
00057 }
00058
00059
00060
00061
00062 pbo.get_all_pcls(&dp.projection_union);
00063 }
00064
00065 ROS_INFO("Computing the projection union FINISHED");
00066
00067 return 1;
00068 }
00069
00070 int c_polygon_primitive_with_texture::add_camera_projection_known_camera(cv::Mat* m, ros::Time t, tf::StampedTransform tf, std::string cam_name, std::string projection_name, cv::Scalar color)
00071 {
00072
00073 double fx=0,fy=0,cx=0,cy=0,k1=0,k2=0,p1=0,p2=0,k3=0,sd_cx=0, sd_cy=0, param=0, scale=0;
00074
00075 if (cam_name=="cam_roof_fc")
00076 {
00077 fx = 479.867758/2.; fy= 479.867758/2.; cx= 360.036957/2.; cy= 267.139665/2.;
00078 k1=0; k2=0; p1=0; p2=0; k3=0;
00079 sd_cx= -0.020410; sd_cy=0.033517; param= 1.074213; scale= 0.5;
00080 }
00081 else if(cam_name=="cam_roof_fl")
00082 {
00083 fx = 479.567636/2; fy= 479.567636/2; cx= 359.563721/2; cy= 216.757192/2;
00084 k1= 0; k2= 0; p1= 0; p2= 0; k3= 0;
00085 sd_cx= -0.021519; sd_cy= -0.031968; param= 1.072291; scale= 0.5;
00086 }
00087 else if(cam_name=="cam_roof_fr")
00088 {
00089 fx= 482.093010/2; fy= 482.093010/2; cx= 384.128030/2; cy= 211.236693/2;
00090 k1= 0; k2= 0; p1= 0; p2= 0; k3=0;
00091 sd_cx= 0.011822; sd_cy=-0.039534; param= 1.071786; scale= 0.5;
00092 }
00093 else if(cam_name=="cam_roof_rc")
00094 {
00095 fx= 473.1791/2; fy=473.1791/2; cx=333.0504/2; cy=237.5875/2;
00096 k1= 0; k2= 0; p1= 0; p2= 0; k3=0;
00097 sd_cx= -0.05616908; sd_cy=-0.005963998; param= 1.085173436; scale= 0.5;
00098 }
00099 else if(cam_name=="cam_roof_fc_6mm")
00100 {
00101 fx=1024.920603/2; fy=1024.920603/2; cx=373.788212/2; cy=233.819293/2;
00102 k1= 0; k2= 0; p1= 0; p2= 0; k3=0;
00103 sd_cx=-0.001310066976; sd_cy=-0.01458390567; param= 0.68462101929529; scale= 0.5;
00104 }
00105 else
00106 {
00107 ROS_ERROR("add_camera_projection_known_camera: camera name is unknown.");
00108 return 0;
00109 }
00110
00111 return add_camera_projection(m, t, fx, fy, cx, cy, tf, k1, k2, p1, p2, k3, sd_cx, sd_cy, param, scale, projection_name, color);
00112 }
00113
00114 int c_polygon_primitive_with_texture::add_camera_projection(cv::Mat* m, ros::Time t, double fx, double fy, double cx, double cy, tf::StampedTransform tf, double k1, double k2, double p1, double p2, double k3, double sd_cx, double sd_cy, double param, double scale, std::string projection_name, cv::Scalar color)
00115 {
00116
00117
00118
00119 class_camera_projection camera;
00120
00121 PFLN
00122
00123 camera.projection_name = projection_name;
00124 camera.set_width_height_num_channels(m->rows, m->cols,m->channels());
00125 camera.set_distortion_spherical(m->cols*2, m->rows*2, sd_cx, sd_cy, param, scale);
00126 camera.set_distortion(k1,k2,p1,p2,k3);
00127 camera.set_intrinsic(fx,fy,cx,cy);
00128 camera.set_extrinsic(&tf);
00129 tf::Transform tf_inv = data.frames.current.transform.inverse();
00130 camera.set_projection_plane(data.planes.current->values[0], data.planes.current->values[1], data.planes.current->values[2], data.planes.current->values[3]);
00131
00132 camera.set_image(m, t, tf.frame_id_);
00133
00134 camera.vertex_canvas.header.frame_id = "/world"; camera.vertex_canvas.header.stamp = t; camera.vertex_canvas.height = 1; camera.vertex_canvas.is_dense = 0;
00135
00136 camera.set_vertex_chull(data.hulls.convex.polygon);
00137
00138
00139
00140
00141 if (!camera.project_pixel_to_vertex(&camera.pixels_canvas, &camera.vertex_canvas))
00142 {
00143 ROS_WARN("Projection %s: canvas polygon does not have projection on the plane of the polygon", camera.projection_name.c_str());
00144 return -1;
00145 }
00146 camera.vertex_canvas.width = camera.vertex_canvas.points.size();
00147
00148
00149
00150
00151
00152 class_polygon_boolean_operations pbo;
00153 pbo.set_transform(&tf_inv);
00154
00155 ROS_INFO("chull size = %ld",camera.vertex_chull.size());
00156 if (!pbo.insert(&camera.vertex_chull))
00157 {
00158 ROS_WARN("Could not insert convex hull");
00159 return -1;
00160 }
00161
00162 ROS_INFO("vertex canvas size = %ld",camera.vertex_canvas.size());
00163 if (!pbo.intersection(&camera.vertex_canvas))
00164 {
00165 ROS_WARN("Could not intersect with canvas");
00166 return -1;
00167 }
00168
00169 pbo.get_largest_pcl(&camera.vertex_intersection);
00170
00171 if (camera.vertex_intersection.points.size()==0)
00172 {
00173 ROS_WARN("Vertex_intersection has zero points");
00174 return -1;
00175 }
00176
00177 camera.vertex_intersection.header.frame_id = "/world"; camera.vertex_intersection.header.stamp = t; camera.vertex_intersection.height = 1; camera.vertex_intersection.is_dense = 0;
00178
00179
00180
00181
00182
00183 camera.project_vertex_to_pixel(camera.vertex_intersection.makeShared(), &camera.pixels_intersection);
00184 camera.vertex_intersection.width = camera.vertex_intersection.points.size();
00185
00186
00187
00188
00189
00190
00191 camera.compute_projectable_pixels();
00192
00193
00194
00195
00196
00197 camera.project_pixel_with_color_to_vertex(&camera.pixels_projectable, &camera.vertex_projectable);
00198 camera.vertex_projectable.height=1;
00199 camera.vertex_projectable.header.frame_id="/world";
00200 camera.vertex_projectable.header.stamp=ros::Time::now();
00201 camera.vertex_projectable.is_dense=0;
00202 camera.vertex_projectable.width=camera.vertex_projectable.points.size();
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00215
00216
00217
00218
00219
00220
00221
00222
00223
00225
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246 for (int l=0; l<camera.mask_projectable_pixels.rows; l++)
00247 for (int c=0; c<camera.mask_projectable_pixels.cols; c++)
00248 {
00249 if (camera.mask_projectable_pixels.at<unsigned char>(l,c))
00250 {
00251 PT::Point pt(c,l);
00252 camera.mesh.insert(pt);
00253 }
00254 }
00255
00256
00257 float px = (tf.inverse().getOrigin()).x();
00258 float py = (tf.inverse().getOrigin()).y();
00259 float pz = (tf.inverse().getOrigin()).z();
00260
00261
00262 for (PT::Vertex_iterator it = camera.mesh.vertices_begin(); it != camera.mesh.vertices_end(); ++it)
00263 {
00264 if (camera.mesh.is_infinite(it))
00265 continue;
00266
00267 int c = (int)CGAL::to_double(it->point().x());
00268 int l = (int)CGAL::to_double(it->point().y());
00269
00270 unsigned char r = camera.image_corrected.at<t_pixel>(l,c)[0];
00271 unsigned char g = camera.image_corrected.at<t_pixel>(l,c)[1];
00272 unsigned char b = camera.image_corrected.at<t_pixel>(l,c)[2];
00273 uint32_t rgb = ((uint32_t)b << 16 | (uint32_t)g << 8 | (uint32_t)r);
00274 it->info().rgb = *reinterpret_cast<float*>(&rgb);
00275 it->info().weight = camera.get_weight_for_pixel(l,c, 1, px,py,pz);
00276 }
00277
00278
00279
00280 std::vector<PT::Vertex_handle> vec;
00281 for (PT::Vertex_iterator vit = camera.mesh.vertices_begin(); vit != camera.mesh.vertices_end(); ++vit)
00282 {
00283 std::vector<float> vr; std::vector<float> vg; std::vector<float> vb;
00284 PT::Vertex_circulator vc = camera.mesh.incident_vertices(vit), done(vc);
00285 if(vc!=0)
00286 {
00287 do
00288 {
00289
00290 uint32_t rgb = *reinterpret_cast<int*>(&vc->info().rgb);
00291 uint8_t r = (rgb >> 16) & 0x0000ff;
00292 uint8_t g = (rgb >> 8) & 0x0000ff;
00293 uint8_t b = (rgb) & 0x0000ff;
00294
00295 vr.push_back((float)r); vg.push_back((float)g); vb.push_back((float)b);
00296 }
00297 while(++vc!=done);
00298
00299 float mean_r, mean_g, mean_b;
00300 float std_r, std_g, std_b;
00301
00302 compute_mean_and_std(&vr, &mean_r, &std_r);
00303 compute_mean_and_std(&vg, &mean_g, &std_g);
00304 compute_mean_and_std(&vb, &mean_b, &std_b);
00305
00306
00307 uint32_t rgb = *reinterpret_cast<int*>(&vit->info().rgb);
00308 uint8_t ur = (rgb >> 16) & 0x0000ff;
00309 uint8_t ug = (rgb >> 8) & 0x0000ff;
00310 uint8_t ub = (rgb) & 0x0000ff;
00311
00312 float r= (float)ur; float g= (float)ug; float b= (float)ub;
00313
00314 if (std_r<5 && std_g<5 && std_b<5 &&
00315 fabs(mean_r-r)< 5 &&
00316 fabs(mean_g-g)< 5 &&
00317 fabs(mean_b-b)< 5)
00318 {
00319 vec.push_back(vit);
00320 }
00321
00322 }
00323 }
00324
00325
00326
00327 for (size_t i=0; i<vec.size(); i++)
00328 {
00329 camera.mesh.remove(vec[i]);
00330 }
00331
00332
00333
00334 camera.set_constraint_polygon(&camera.pixels_intersection);
00335
00336 px = (tf.inverse().getOrigin()).x();
00337 py = (tf.inverse().getOrigin()).y();
00338 pz = (tf.inverse().getOrigin()).z();
00339
00340
00341 for (PT::Vertex_iterator it = camera.mesh.vertices_begin(); it != camera.mesh.vertices_end(); ++it)
00342 {
00343 if (camera.mesh.is_infinite(it))
00344 continue;
00345
00346 int c = (int)CGAL::to_double(it->point().x());
00347 int l = (int)CGAL::to_double(it->point().y());
00348
00349 unsigned char r = camera.image_corrected.at<t_pixel>(l,c)[0];
00350 unsigned char g = camera.image_corrected.at<t_pixel>(l,c)[1];
00351 unsigned char b = camera.image_corrected.at<t_pixel>(l,c)[2];
00352 uint32_t rgb = ((uint32_t)b << 16 | (uint32_t)g << 8 | (uint32_t)r);
00353 it->info().rgb = *reinterpret_cast<float*>(&rgb);
00354 it->info().weight = camera.get_weight_for_pixel(l,c, 1, px,py,pz);
00355 }
00356 camera.compute_face_weights();
00357
00358
00359 camera.initialize_all_faces_status();
00360 camera.discoverComponents(camera.mesh);
00361 camera.export_triangles_in_order(&camera.pixel_list, &camera.face_weight);
00362
00363
00364
00365
00366
00367 camera.draw_mesh_triangles(&camera.image_gui, cv::Scalar(0,255,0), 1);
00368 camera.draw_pixels_vector_as_polyline(&camera.image_gui, &camera.pixels_canvas, cv::Scalar(0,0,255),3);
00369 camera.draw_pixels_vector_as_polyline(&camera.image_gui, &camera.pixels_intersection, cv::Scalar(255,0,0),2);
00370
00371
00372
00373
00374
00375 cp.push_back(camera);
00376
00377 return cp.size()-1;
00378 }
00379
00380
00381 int c_polygon_primitive_with_texture::compute_mean_and_std(std::vector<float>* v, float* mean, float* std)
00382 {
00383 float sum=0;
00384 for (size_t i=0; i<v->size(); i++)
00385 {
00386 sum += (*v)[i];
00387 }
00388
00389 *mean = sum/(v->size());
00390
00391 float std_sum=0;
00392 for (size_t i=0; i<v->size(); i++)
00393 {
00394 std_sum += ((*v)[i]-(*mean))*((*v)[i]-(*mean));
00395 }
00396
00397 *std = sqrt(std_sum/(v->size()-1));
00398 return 1;
00399 }
00400
00401
00402
00403
00404
00405
00409
00410
00411
00412
00413
00414
00418
00419
00420
00427
00428
00429
00430
00439
00440
00442
00445
00451
00454
00456
00457
00458
00459
00460
00462
00467
00470
00471
00474
00476
00481
00482
00483
00484
00485
00487
00488
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512
00515
00516
00517
00518
00523
00524
00525
00526
00527
00528
00529
00530
00532
00533
00534
00536
00537
00538
00539
00540
00542
00543
00544
00545
00547
00548
00549
00550
00551
00552
00553
00554
00555
00556
00557
00558
00559
00560 int c_polygon_primitive_with_texture::readapt_to_new_plane(polygon_primitive_msg::polygon_primitive* new_plg)
00561 {
00562 pcl::ModelCoefficients::Ptr coeff = pcl::ModelCoefficients::Ptr(new pcl::ModelCoefficients);
00563
00564 coeff->values.resize(4);
00565 coeff->values[0] = new_plg->support_plane_A;
00566 coeff->values[1] = new_plg->support_plane_B;
00567 coeff->values[2] = new_plg->support_plane_C;
00568 coeff->values[3] = new_plg->support_plane_D;
00569
00570 for (size_t u=0; u<cp.size(); u++)
00571 {
00572 pcl::ProjectInliers<pcl::PointXYZ> projection;
00573 projection.setModelType(pcl::SACMODEL_PLANE);
00574
00575 projection.setInputCloud(cp[u].vertex_canvas.makeShared());
00576 projection.setModelCoefficients(coeff);
00577 projection.filter(cp[u].vertex_canvas);
00578
00579 projection.setInputCloud(cp[u].vertex_chull.makeShared());
00580 projection.setModelCoefficients(coeff);
00581 projection.filter(cp[u].vertex_chull);
00582
00583 projection.setInputCloud(cp[u].vertex_intersection.makeShared());
00584 projection.setModelCoefficients(coeff);
00585 projection.filter(cp[u].vertex_intersection);
00586
00587 pcl::ProjectInliers<pcl::PointXYZRGB> projectionRGB;
00588 projectionRGB.setModelType(pcl::SACMODEL_PLANE);
00589
00590 projectionRGB.setInputCloud(cp[u].vertex_projectable.makeShared());
00591 projectionRGB.setModelCoefficients(coeff);
00592 projectionRGB.filter(cp[u].vertex_projectable);
00593 }
00594
00595 for (size_t u=0; u<dp.projection_union.size(); u++)
00596 {
00597 pcl::ProjectInliers<pcl::PointXYZ> projection;
00598 projection.setModelType(pcl::SACMODEL_PLANE);
00599
00600 projection.setInputCloud(dp.projection_union[u].makeShared());
00601 projection.setModelCoefficients(coeff);
00602 projection.filter(dp.projection_union[u]);
00603 }
00604
00605
00606 import_from_polygon_primitive_msg(new_plg);
00607
00608 return 1;
00609 }
00610
00611 size_t c_polygon_primitive_with_texture::ask_for_number(void)
00612 {
00613 size_t myNumber = 0;
00614 std::string input = "";
00615 while (true)
00616 {
00617 std::getline(std::cin, input);
00618
00619 std::stringstream myStream(input);
00620 if (myStream >> myNumber)
00621 break;
00622 std::cout << "Invalid number, please try again" << std::endl;
00623 }
00624 return myNumber;
00625 }
00626
00627 int c_polygon_primitive_with_texture::publish_to_rviz(ros::Publisher* p_marker_pub)
00628 {
00629 dp.export_points_to_pc();
00630 visualization_msgs::MarkerArray marker_vec;
00631
00632 create_textures_vizualization_msg(&marker_vec,true);
00633
00634 p_marker_pub->publish(marker_vec);
00635 return 1;
00636 }
00637
00638 int c_polygon_primitive_with_texture::build_global_mesh(ros::Publisher* p_marker_pub)
00639 {
00640 int debug=0;
00641
00642
00643
00644
00645 tf::Transform tf_inv = data.frames.current.transform.inverse();
00646 dp.set_transform(&tf_inv);
00647
00648
00649 for (size_t i=0; i<cp.size(); i++)
00650 {
00651 if (cp[i].is_mapped_to_mesh==true)
00652 {
00653 ROS_INFO("Camera projection %ld (%s) is already added to global mesh", i, cp[i].projection_name.c_str());
00654 continue;
00655 }
00656
00657 ros::Time t_overall = ros::Time::now();
00658
00659 cp[i].set_projection_plane(data.planes.current->values[0], data.planes.current->values[1], data.planes.current->values[2], data.planes.current->values[3]);
00660 cp[i].project_pixel_with_color_to_vertex(&cp[i].pixel_list, &cp[i].vertex_list);
00661 cp[i].vertex_list.height=1;
00662 cp[i].vertex_list.header.frame_id="/world";
00663 cp[i].vertex_list.header.stamp=ros::Time::now();
00664 cp[i].vertex_list.is_dense=0;
00665 cp[i].vertex_list.width=cp[i].vertex_list.points.size();
00666
00667
00668 pcl::PointCloud<pcl::PointXYZRGB> pl;
00669 pcl_ros::transformPointCloud(cp[i].vertex_list, pl, dp.transform);
00670
00671
00672 for (size_t g=0; g<pl.points.size(); ++g)
00673 {
00674 pl.points[g].x = floorf(pl.points[g].x * 1000 + 0.5) / 1000;
00675 pl.points[g].y = floorf(pl.points[g].y * 1000 + 0.5) / 1000;
00676 pl.points[g].z = floorf(pl.points[g].z * 1000 + 0.5) / 1000;
00677 }
00678
00679 ROS_INFO("Adding camera projection %ld (%s) to global mesh %ld triangles", i, cp[i].projection_name.c_str(), pl.points.size()/3);
00680
00681 size_t process_until_index=0;
00682 size_t cnt_skip_search=0;
00683 size_t cnt_vertices_removed=0;
00684 size_t cnt_constraints_removed=0;
00685 size_t cnt_add_face=0;
00686 ros::Duration d_skip_search(0);
00687 ros::Duration d_vertices_removed(0);
00688 ros::Duration d_constraints_removed(0);
00689 ros::Duration d_add_face(0);
00690 for (size_t k=0, u=0; u<pl.points.size(); u+=3, k++)
00691 {
00692 ros::Duration d; ros::Time t; int cnt;
00693
00694 if(debug)ROS_INFO("Adding camera projection %ld (%s) to global mesh (%ld of %ld triangles)", i, cp[i].projection_name.c_str(), k, pl.points.size()/3);
00695 bool insert_triangle=true;
00696
00697
00698 next_triangle.points.erase(next_triangle.points.begin(), next_triangle.points.end());
00699 pcl::PointXYZ pt;
00700 pt.x = cp[i].vertex_list.points[u].x; pt.y = cp[i].vertex_list.points[u].y; pt.z = cp[i].vertex_list.points[u].z;
00701 next_triangle.points.push_back(pt);
00702 pt.x = cp[i].vertex_list.points[u+1].x; pt.y = cp[i].vertex_list.points[u+1].y; pt.z = cp[i].vertex_list.points[u+1].z;
00703 next_triangle.points.push_back(pt);
00704
00705
00706 pt.x = cp[i].vertex_list.points[u+1].x; pt.y = cp[i].vertex_list.points[u+1].y; pt.z = cp[i].vertex_list.points[u+1].z;
00707 next_triangle.points.push_back(pt);
00708 pt.x = cp[i].vertex_list.points[u+2].x; pt.y = cp[i].vertex_list.points[u+2].y; pt.z = cp[i].vertex_list.points[u+2].z;
00709 next_triangle.points.push_back(pt);
00710
00711
00712 pt.x = cp[i].vertex_list.points[u].x; pt.y = cp[i].vertex_list.points[u].y; pt.z = cp[i].vertex_list.points[u].z;
00713 next_triangle.points.push_back(pt);
00714 pt.x = cp[i].vertex_list.points[u+2].x; pt.y = cp[i].vertex_list.points[u+2].y; pt.z = cp[i].vertex_list.points[u+2].z;
00715 next_triangle.points.push_back(pt);
00716
00717
00718
00719 CDT tmp_mesh;
00720 CDT::Vertex_handle vh[3];
00721
00722 for (size_t j=0; j<3; ++j)
00723 {
00724 vh[j] = tmp_mesh.insert(Point_2(pl.points[u+j].x, pl.points[u+j].y));
00725 vh[j]->info().rgb = cp[i].vertex_list.points[u+j].rgb;
00726 vh[j]->info().z = 0;
00727 vh[j]->info().index = 0;
00728 }
00729
00730 CDT::Face_handle fti;
00731 if (tmp_mesh.is_face(vh[0],vh[1],vh[2], fti))
00732 {
00733 fti->weight = cp[i].face_weight[k];
00734 fti->provenience = i;
00735 }
00736 else
00737 {
00738 ROS_ERROR("Could not start fti face");
00739 continue;
00740 }
00741
00742
00743 if (debug) dp.printf_face_info(fti);
00744
00745
00746 if ( (k==0 || k>(process_until_index)) && debug )
00747 {
00748 publish_to_rviz(p_marker_pub);
00749 ROS_INFO("How many triangles to insert? (k=%d out of %d)", (int)k, ((int)pl.points.size()/3));
00750 process_until_index = k+ask_for_number()-1;
00751 }
00752
00753
00754 if (k==process_until_index && debug) dp.debug=0;
00755 else dp.debug=0;
00756
00757
00758
00759 if (dp.is_degenerate(pl.points[u].x, pl.points[u].y, pl.points[u].z,
00760 pl.points[u+1].x, pl.points[u+1].y, pl.points[u+1].z,
00761 pl.points[u+2].x, pl.points[u+2].y, pl.points[u+2].z))
00762 {
00763 ROS_WARN("Skiping a degenerate triangle");
00764 continue;
00765 }
00766
00767
00768 t = ros::Time::now(); cnt=0;
00769 if(!dp.iterate_intersecting_faces(fti, 0))
00770 {
00771 if(debug)ROS_INFO("could not insert triangle %ld out of %d. check_if_face_should_be_inserted refused", k, (int)pl.points.size()/3);
00772 continue;
00773 }
00774 cnt_skip_search++; d_skip_search += ros::Time::now()-t;
00775
00776
00777 if ((k==process_until_index) && debug )
00778 {
00779 d = ros::Time::now()-t;
00780 ROS_INFO("iterate intersecting faces in %f seconds.", d.toSec());
00781 }
00782
00783
00784 t = ros::Time::now(); cnt=0;
00785 while(!dp.iterate_intersecting_faces(fti, 1))
00786 {
00787 cnt++;
00788 }
00789 cnt_vertices_removed++; d_vertices_removed += ros::Time::now()-t;
00790
00791 if ((k==process_until_index) && debug )
00792 {
00793 d = ros::Time::now()-t;
00794 publish_to_rviz(p_marker_pub);
00795 ROS_INFO("Vertices inside triangle removed in %d iterations and %f seconds. press to continue", cnt, d.toSec());
00796 ask_for_number();
00797 }
00798
00799
00800
00801 t = ros::Time::now(); cnt=0;
00802 while(!dp.iterate_intersecting_faces(fti, 2))
00803 {
00804 cnt++;
00805 }
00806 cnt_constraints_removed++; d_constraints_removed += ros::Time::now()-t;
00807
00808 if ((k==process_until_index) && debug )
00809 {
00810 d = ros::Time::now()-t;
00811 publish_to_rviz(p_marker_pub);
00812 ROS_INFO("Intersecting constrained edges removed in %d iterations and %f seconds\nMesh prepared to receive new triangle %ld out of %d. \nDo you want to insert the triangle? [0,1]",cnt, d.toSec(), k, (int)pl.points.size()/3);
00813 if (ask_for_number()) insert_triangle=true;
00814 else insert_triangle=false;
00815 }
00816
00817
00818 t = ros::Time::now(); cnt=0;
00819 if(insert_triangle)
00820 {
00821 dp.add_face_to_mesh(fti);
00822 }
00823 cnt_add_face++; d_add_face += ros::Time::now()-t;
00824
00825 if ((k==process_until_index) && debug )
00826 {
00827 d = ros::Time::now()-t;
00828 ROS_INFO("Triangle inserted in %f seconds", d.toSec());
00829 }
00830 }
00831
00832 cp[i].is_mapped_to_mesh=true;
00833 ros::Duration d_overall;
00834 d_overall = ros::Time::now()-t_overall;
00835 ROS_INFO("Finished adding camera projection %ld (%s) to global mesh %ld triangles in %f seconds\n%f secs per triangle overall\n%f secs (%f per pixel) skip_search\n%f secs (%f per pixel) vertices remove\n%f secs (%f per pixel) constraints remove\n%f secs (%f per pixel) add face", i, cp[i].projection_name.c_str(), pl.points.size()/3, d_overall.toSec(), d_overall.toSec()/(double)(pl.points.size()/3), d_skip_search.toSec(), d_skip_search.toSec()/cnt_skip_search , d_vertices_removed.toSec(), d_vertices_removed.toSec()/cnt_vertices_removed , d_constraints_removed.toSec(), d_constraints_removed.toSec()/cnt_constraints_removed , d_add_face.toSec(), d_add_face.toSec()/cnt_add_face);
00836 }
00837
00838
00839 dp.export_points_to_pc();
00840 get_mesh_statistics();
00841
00842
00843
00844
00845
00846
00847
00848
00849
00850
00851
00852
00853
00854
00855
00856
00857
00858
00859
00860 return 1;
00861 }
00862
00863 int c_polygon_primitive_with_texture::get_mesh_statistics(void)
00864 {
00865
00866
00867 std::vector<int> vec;
00868
00869
00870 for (size_t i=0; i<cp.size()+1; i++)
00871 {
00872 vec.push_back(0);
00873 }
00874
00875
00876 for(CDT::Finite_faces_iterator ffi = dp.dt.finite_faces_begin(); ffi != dp.dt.finite_faces_end(); ++ffi)
00877 {
00878
00879 int a=ffi->provenience;
00880
00881
00882 if (a>=-1 && a <(int)cp.size())
00883 vec.at(a+1) ++;
00884 else
00885 ROS_ERROR("There is a face with provenience %d", a);
00886 }
00887
00888
00889
00890 char tmp[1024];
00891 sprintf(tmp, "Polygon %s mesh information:\n mesh has %d vertices and %d triangles\n Total to %d projections:\n", data.misc.name,(int) dp.dt.number_of_vertices(),(int) dp.dt.number_of_faces(),(int) vec.size());
00892
00893
00894 std::string st = tmp;;
00895 for (size_t i=1; i<vec.size(); i++)
00896 {
00897
00898 char tmp[1024];
00899 sprintf(tmp, "%s: %d faces, %d in mesh\n", cp[i-1].projection_name.c_str(), (int)cp[i-1].mesh.number_of_faces(), vec[i]);
00900 st += tmp;
00901
00902 }
00903
00904
00905 sprintf(tmp, "Auto created: %d faces in mesh\n", vec[0]);
00906 st += tmp;
00907
00908
00909 ROS_INFO("%s",st.c_str());
00910 return 1;
00911 }
00912
00913 #endif
00914