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
00033 #ifndef _CONSTRAINED_DELAUNAY_TRIANGULATION_CPP_
00034 #define _CONSTRAINED_DELAUNAY_TRIANGULATION_CPP_
00035
00036 #include "constrained_delaunay_triangulation.h"
00037
00038 int class_constrained_delaunay_triangulation::compute_union(void)
00039 {
00040
00041
00042
00043
00044
00045
00046
00047 return 1;
00048
00049 }
00050
00051
00052 int class_constrained_delaunay_triangulation::clear_constraints(void)
00053 {
00054 for (CDT::Vertex_iterator it=dt.vertices_begin(); it!=dt.vertices_end(); ++it)
00055 {
00056 dt.remove_incident_constraints(it);
00057 }
00058 return 1;
00059 }
00060
00061 int class_constrained_delaunay_triangulation::clear_vertices(void)
00062 {
00063 dt.clear();
00064 index_count=1;
00065 return 1;
00066 }
00067
00068 int class_constrained_delaunay_triangulation::set_constraint_polygon(void)
00069 {
00070
00071 return 1;
00072 }
00073
00074 int class_constrained_delaunay_triangulation::set_transform(tf::Transform* st)
00075 {
00076 transform.setRotation(st->getRotation());
00077 transform.setOrigin(st->getOrigin());
00078 return 1;
00079 }
00080
00081 int class_constrained_delaunay_triangulation::export_points_to_pc(void)
00082 {
00083
00084 pc_vertices_indices.erase(pc_vertices_indices.begin(), pc_vertices_indices.end());
00085 pc_vertices.erase(pc_vertices.points.begin(), pc_vertices.points.end());
00086 for (CDT::Finite_vertices_iterator vi=dt.finite_vertices_begin(); vi!=dt.finite_vertices_end(); ++vi)
00087 {
00088 pcl::PointXYZ pt;
00089 pt.x = CGAL::to_double(vi->point().x());
00090 pt.y = CGAL::to_double(vi->point().y());
00091 pt.z = CGAL::to_double(vi->info().z);
00092 pc_vertices.push_back(pt);
00093 pc_vertices_indices.push_back(vi->info().index);
00094 }
00095 pcl_ros::transformPointCloud(pc_vertices, pc_vertices, transform.inverse());
00096
00097
00098 pc_constraints.points.erase(pc_constraints.points.begin(), pc_constraints.points.end());
00099 pcl::PointCloud<pcl::PointXYZ> pc_local;
00100 pcl::PointXYZ pt;
00101 for(CDT::Edge_iterator ei = dt.finite_edges_begin(); ei != dt.finite_edges_end(); ++ei)
00102 {
00103 if (dt.is_constrained(*ei))
00104 {
00105 CDT::Segment s= dt.segment(ei);
00106 pt.x = CGAL::to_double((s.point(0)).x());
00107 pt.y = CGAL::to_double((s.point(0)).y());
00108 pt.z = 0;
00109 pc_local.points.push_back(pt);
00110
00111 pt.x = CGAL::to_double((s.point(1)).x());
00112 pt.y = CGAL::to_double((s.point(1)).y());
00113 pt.z = 0;
00114 pc_local.points.push_back(pt);
00115
00116 }
00117 }
00118 pcl_ros::transformPointCloud(pc_local, pc_constraints, transform.inverse());
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131 initialize_all_faces_status();
00132 discoverComponents(dt);
00133
00134 pc.points.erase(pc.points.begin(), pc.points.end());
00135 pc_proveniences.erase(pc_proveniences.begin(), pc_proveniences.end());
00136
00137 ros::Time t1=ros::Time::now();
00138
00139 unsigned int num_triangles=0;
00140 for(Finite_faces_iterator fc1 = dt.finite_faces_begin(); fc1 != dt.finite_faces_end(); ++fc1)
00141 {
00142
00143
00144 if (!fc1->is_in_domain())
00145 {
00146
00147
00148 }
00149
00150 if (fc1->vertex(0)->info().rgb==-1)
00151 {
00152
00153 }
00154
00155 if (fc1->vertex(1)->info().rgb==-1)
00156 {
00157
00158 }
00159
00160 if (fc1->vertex(2)->info().rgb==-1)
00161 {
00162
00163 }
00164
00165 for (int u=0; u<3;u++)
00166 {
00167 pcl::PointCloud<pcl::PointXYZ> pc_local;
00168 pcl::PointXYZ pt;
00169
00170 pt.x = CGAL::to_double(fc1->vertex(u)->point().x());
00171 pt.y = CGAL::to_double(fc1->vertex(u)->point().y());
00172 pt.z = CGAL::to_double(fc1->vertex(u)->info().z);
00173
00174 pc_local.points.push_back(pt);
00175
00176 pcl::PointCloud<pcl::PointXYZ> pc_global;
00177 pcl_ros::transformPointCloud(pc_local, pc_global, transform.inverse());
00178 pcl::PointXYZRGB ptcolor;
00179 ptcolor.x = pc_global.points[0].x;
00180 ptcolor.y = pc_global.points[0].y;
00181 ptcolor.z = pc_global.points[0].z;
00182 ptcolor.rgb = fc1->vertex(u)->info().rgb;
00183
00184 pc.points.push_back(ptcolor);
00185 pc_proveniences.push_back(fc1->provenience);
00186
00187 pc.height = 1;
00188 pc.width = pc.points.size();
00189 pc.is_dense = 0;
00190
00191 }
00192 num_triangles++;
00193 }
00194
00195
00196
00197
00198
00199 return 1;
00200 }
00201
00202
00203 void class_constrained_delaunay_triangulation::discoverComponent(const CDT & ct,
00204 Face_handle start,
00205 int index,
00206 std::list<CDT::Edge>& border )
00207 {
00208 if(start->counter != -1)
00209 {
00210 return;
00211 }
00212 std::list<Face_handle> queue;
00213 queue.push_back(start);
00214
00215 while(! queue.empty())
00216 {
00217 Face_handle fh = queue.front();
00218 queue.pop_front();
00219 if(fh->counter == -1)
00220 {
00221 fh->counter = index;
00222 fh->set_in_domain(index%2 == 1);
00223 for(int i = 0; i < 3; i++)
00224 {
00225 CDT::Edge e(fh,i);
00226 Face_handle n = fh->neighbor(i);
00227 if(n->counter == -1)
00228 {
00229 if(ct.is_constrained(e))
00230 {
00231 border.push_back(e);
00232 }
00233 else
00234 {
00235 queue.push_back(n);
00236 }
00237 }
00238
00239 }
00240 }
00241 }
00242 }
00243
00244 void class_constrained_delaunay_triangulation::discoverComponents(const CDT & ct)
00245 {
00246 int index = 0;
00247 std::list<CDT::Edge> border;
00248 discoverComponent(ct, ct.infinite_face(), index++, border);
00249 while(! border.empty())
00250 {
00251 CDT::Edge e = border.front();
00252 border.pop_front();
00253 Face_handle n = e.first->neighbor(e.second);
00254 if(n->counter == -1)
00255 {
00256 discoverComponent(ct, n, e.first->counter+1, border);
00257 }
00258 }
00259 }
00260
00261
00262 int class_constrained_delaunay_triangulation::project_triangulation_to_new_plane(pcl::ModelCoefficients::Ptr plane, tf::Transform tf)
00263 {
00264 pcl::PointCloud<pcl::PointXYZ> pc_local;
00265 pcl::PointCloud<pcl::PointXYZ> pc_global;
00266 pcl::PointCloud<pcl::PointXYZ> pc_global_projected;
00267 pcl::PointCloud<pcl::PointXYZ> pc_local_projected;
00268
00269
00270 for(Finite_vertices_iterator fv = dt.finite_vertices_begin(); fv != dt.finite_vertices_end(); ++fv)
00271 {
00272 pcl::PointXYZ p;
00273 p.x = CGAL::to_double(fv->point().x());
00274 p.y = CGAL::to_double(fv->point().y());
00275 p.z = CGAL::to_double(fv->info().z);
00276 pc_local.points.push_back(p);
00277 }
00278
00279
00280
00281 pcl_ros::transformPointCloud(pc_local,pc_global, transform.inverse());
00282
00283 pcl::ProjectInliers<pcl::PointXYZ> projection;
00284 projection.setModelType(pcl::SACMODEL_PLANE);
00285
00286 projection.setInputCloud(pc_global.makeShared());
00287 projection.setModelCoefficients(plane);
00288 projection.filter(pc_global_projected);
00289
00290
00291 pcl_ros::transformPointCloud(pc_global_projected, pc_local_projected, tf);
00292
00293 size_t count=0;
00294
00295 for(Finite_vertices_iterator fv = dt.finite_vertices_begin(); fv != dt.finite_vertices_end(); ++fv)
00296 {
00297 Point_2 p(pc_local_projected.points[count].x, pc_local_projected.points[count].y);
00298
00299
00300
00301 count++;
00302 }
00303
00304 return 1;
00305 }
00306
00307 CDT::Face_handle class_constrained_delaunay_triangulation::get_face_handle_from_t_face(t_face* f)
00308 {
00309 CDT::Face_handle fh;
00310
00311 CDT::Vertex_handle v0 = get_vertex_at(f->v0);
00312 CDT::Vertex_handle v1 = get_vertex_at(f->v1);
00313 CDT::Vertex_handle v2 = get_vertex_at(f->v2);
00314
00315 if(v0==NULL || v1==NULL || v2==NULL) return NULL;
00316
00317 if(dt.is_face(v0,v1,v2 , fh))
00318 {
00319 return fh;
00320 }
00321 else
00322 {
00323 ROS_ERROR("Something very wrong this is not a face");
00324 return NULL;
00325 }
00326 }
00327
00328 CDT::Vertex_handle class_constrained_delaunay_triangulation::get_vertex_at(Point_2 p)
00329 {
00330 CDT::Locate_type lt; int li;
00331
00332 CDT::Face_handle fh = dt.locate(p, lt, li);
00333 if (lt==CDT::VERTEX)
00334 {
00335 if(debug>2) ROS_INFO("Found vertex index=%ld at x=%f y=%f",fh->vertex(li)->info().index, CGAL::to_double(p.x()), CGAL::to_double(p.y()));
00336 return fh->vertex(li);
00337 }
00338 else
00339 {
00340 ROS_ERROR("There is no vertex at x=%f y=%f", CGAL::to_double(p.x()), CGAL::to_double(p.y()));
00341 return NULL;
00342 }
00343 }
00344
00345
00346 int class_constrained_delaunay_triangulation::add_face_to_mesh(CDT::Face_handle fti)
00347 {
00348 size_t index[3];
00349 for (int u=0; u<3;u++)
00350 {
00351 CDT::Locate_type lt; int li;
00352 CDT::Face_handle fh = dt.locate(fti->vertex(u)->point(), lt,li);
00353 if (lt==CDT::VERTEX)
00354 {
00355 if(debug)printf("v%d is on vertex %ld\n",u, fh->vertex(li)->info().index);
00356 index[u] = fh->vertex(li)->info().index;
00357 }
00358 else if (lt==CDT::EDGE)
00359 {
00360 if(debug) printf("v%d is on edge\n",u);
00361 index[u] = index_count++;
00362 }
00363 else if (lt==CDT::FACE)
00364 {
00365 if(debug) printf("v%d is on face(%ld,%ld,%ld)\n",u, fh->vertex(0)->info().index, fh->vertex(1)->info().index, fh->vertex(2)->info().index);
00366 index[u] = index_count++;
00367 }
00368 else
00369 {
00370 if(debug)printf("v%d other\n",u);
00371 index[u] = index_count++;
00372 }
00373 }
00374
00375
00376 for (int k=0; k<3; k++)
00377 {
00378 int k1,k2;
00379 if (k==0) {k1=1; k2=2;}
00380 else if (k==1) {k1=0; k2=2;}
00381 else if (k==2) {k1=0; k2=1;}
00382
00383 if(debug)ROS_INFO("inserting constraint v%d to v%d", k1,k2);
00384 dt.insert_constraint(fti->vertex(k1)->point(), fti->vertex(k2)->point());
00385 }
00386
00387 CDT::Vertex_handle fh_v[3];
00388 for (int u=0; u<3;u++)
00389 {
00390 CDT::Locate_type lt; int li;
00391 CDT::Face_handle fh = dt.locate(fti->vertex(u)->point(), lt, li);
00392 if (lt==CDT::VERTEX)
00393 {
00394 fh_v[u] = fh->vertex(li);
00395 fh_v[u]->info().index = index[u];
00396 fh_v[u]->info().rgb = fti->vertex(u)->info().rgb;
00397 fh_v[u]->info().z = fti->vertex(u)->info().z;
00398 }
00399 else
00400 {
00401 if(debug)ROS_ERROR("There is a error, should be a vertex and its not");
00402 }
00403 }
00404
00405
00406
00407 CDT::Face_handle fh;
00408 if(!dt.is_face(fh_v[0], fh_v[1],fh_v[2], fh))
00409 {
00410 ROS_ERROR("could not add explicit face");
00411 }
00412 else
00413 {
00414 fh->provenience = fti->provenience;
00415 fh->weight = fti->weight;
00416 }
00417
00418 test_if_triangulation_is_valid();
00419 return 1;
00420 }
00421
00422
00423 int class_constrained_delaunay_triangulation::add_face_to_mesh(double x0, double y0, double z0, float rgb0,
00424 double x1, double y1, double z1, float rgb1,
00425 double x2, double y2, double z2, float rgb2,
00426 float weight, int provenience)
00427 {
00428 if(debug)ROS_WARN("Starting add_face_to_mesh");
00429
00430 double x[3] = {x0, x1, x2};
00431 double y[3] = {y0, y1, y2};
00432 double z[3] = {z0, z1, z2};
00433 float rgb[3] = {rgb0,rgb1,rgb2};
00434
00435 CDT::Locate_type lt[3];
00436 int li[3];
00437 CDT::Face_handle fh_v[3];
00438 size_t index[3];
00439
00440 for (int u=0; u<3;u++)
00441 {
00442 fh_v[u] = dt.locate(Point_2(x[u], y[u]), lt[u], li[u]);
00443 if (lt[u]==CDT::VERTEX)
00444 {
00445 if(debug)printf("v%d is on vertex %ld\n",u, fh_v[u]->vertex(li[u])->info().index);
00446 index[u] = fh_v[u]->vertex(li[u])->info().index;
00447 }
00448 else if (lt[u]==CDT::EDGE)
00449 {
00450 if(debug) printf("v%d is on edge\n",u);
00451 index[u] = index_count++;
00452 }
00453 else if (lt[u]==CDT::FACE)
00454 {
00455 if(debug) printf("v%d is on face(%ld,%ld,%ld)\n",u, fh_v[u]->vertex(0)->info().index, fh_v[u]->vertex(1)->info().index, fh_v[u]->vertex(2)->info().index);
00456 index[u] = index_count++;
00457 }
00458 else
00459 {
00460 if(debug)printf("v%d other\n",u);
00461 index[u] = index_count++;
00462 }
00463 }
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478 for (int u=0; u<3;u++)
00479 {
00480 if (lt[u]!=CDT::VERTEX)
00481 {
00482 dt.insert(Point_2(x[u],y[u]));
00483 if(debug)ROS_INFO("Adding new vertex v%d",u);
00484 }
00485 }
00486
00487
00488 Vertex_handle1 vh[3];
00489 for (int u=0; u<3;u++)
00490 {
00491 vh[u] = get_vertex_at(Point_2(x[u], y[u]));
00492 vh[u]->info().rgb = rgb[u];
00493 vh[u]->info().z = z[u];
00494 vh[u]->info().index = index[u];
00495 }
00496
00497 if(debug)
00498 {
00499 for (int u=0; u<3;u++)
00500 {
00501 printf("v%d has index %ld\n",u, vh[u]->info().index);
00502 }
00503 }
00504
00505
00506 if(debug)ROS_INFO("inserting constraint v0 (%f; %f) to v1(%f; %f)", CGAL::to_double(vh[0]->point().x()), CGAL::to_double(vh[0]->point().y()) , CGAL::to_double(vh[1]->point().x()) , CGAL::to_double(vh[1]->point().y()));
00507 dt.insert_constraint(get_vertex_at(Point_2(x[0], y[0])), get_vertex_at(Point_2(x[1], y[1])));
00508
00509 if(debug)ROS_INFO("inserting constraint v1 (%f; %f) to v2(%f; %f)", x[1], y[1], x[2], y[2]);
00510 dt.insert_constraint(get_vertex_at(Point_2(x[1], y[1])), get_vertex_at(Point_2(x[2], y[2])));
00511
00512 if(debug)ROS_INFO("inserting constraint v0 (%f; %f) to v2(%f; %f)", x[0], y[0], x[2], y[2]);
00513 dt.insert_constraint(get_vertex_at(Point_2(x[0], y[0])), get_vertex_at(Point_2(x[2], y[2])));
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543 CDT::Face_handle fh;
00544 if(!dt.is_face(get_vertex_at(Point_2(x[0], y[0])), get_vertex_at(Point_2(x[1], y[1])),get_vertex_at(Point_2(x[2], y[2])), fh))
00545 {
00546 ROS_ERROR("could not add explicit face");
00547 }
00548 else
00549 {
00550 fh->provenience = provenience;
00551 fh->weight = weight;
00552
00553
00554
00555
00556
00557
00558
00559
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577
00578
00579
00580
00581
00582
00583
00584
00585
00586
00587
00588
00589
00590
00591
00592
00593
00594
00595
00596 }
00597
00598 test_if_triangulation_is_valid();
00599 return 1;
00600 }
00601
00602
00603
00604
00605
00606
00607
00608 int class_constrained_delaunay_triangulation::remove_constraint(CDT::Face_handle fh, int li)
00609 {
00610
00611
00612
00613
00614
00615
00616
00617
00618
00619
00620
00621
00622
00623
00624
00625
00626
00627
00628
00629
00630
00631
00632
00633
00634
00635
00636
00637
00638
00639
00640
00641
00642
00643
00644
00645
00646
00647
00648
00649
00650
00651
00652
00653
00654
00655
00656
00657
00658
00659
00660
00661
00662
00663
00664
00665
00666
00667
00668
00669
00670
00671
00672
00673 int k1,k2;
00674 size_t id_k1, id_k2;
00675 if (li==0) {k1=1; k2=2;}
00676 else if (li==1) {k1=0; k2=2;}
00677 else {k1=0; k2=1;}
00678
00679 id_k1 = fh->vertex(k1)->info().index;
00680 id_k2 = fh->vertex(k2)->info().index;
00681
00682 CDT::Face_handle nf = fh->neighbor(li);
00683 int nk1, nk2;
00684 int index_u=-1;
00685 for (int u=0; u<3;u++)
00686 {
00687 if (u==0) {nk1=1; nk2=2;}
00688 else if (u==1) {nk1=0; nk2=2;}
00689 else {nk1=0; nk2=1;}
00690
00691 if ((nf->vertex(nk1)->info().index == id_k1 && nf->vertex(nk2)->info().index == id_k2) ||
00692 (nf->vertex(nk1)->info().index == id_k2 && nf->vertex(nk2)->info().index == id_k1))
00693 {
00694 index_u=u;
00695 break;
00696 }
00697 }
00698
00699 if(index_u==-1)
00700 {
00701 if (debug) ROS_INFO("Something wrong, index_u =%d",index_u);
00702 }
00703
00704 if(debug>1)ROS_INFO("Removing constraint from face(%ld,%ld,%ld) edge(%ld,%ld) and neighbor face(%ld,%ld,%ld) edge(%ld,%ld)",fh->vertex(0)->info().index, fh->vertex(1)->info().index,fh->vertex(2)->info().index,fh->vertex(k1)->info().index, fh->vertex(k2)->info().index, nf->vertex(0)->info().index, nf->vertex(1)->info().index,nf->vertex(2)->info().index,nf->vertex(nk1)->info().index, nf->vertex(nk2)->info().index);
00705
00706
00707 if(debug>1)ROS_INFO("fh has index %ld nf has index %ld",fh->vertex(li)->info().index, nf->vertex(index_u)->info().index);
00708 if(fh->is_constrained(li))
00709 {
00710 if(debug>1)ROS_INFO("fh is constrained");
00711 fh->set_constraint(li,false);
00712 if(debug>1)ROS_INFO("now fh is constrained=%d ",fh->is_constrained(li));
00713 }
00714
00715 if(debug>1)ROS_INFO("fh has index %ld nf has index %ld",fh->vertex(li)->info().index, nf->vertex(index_u)->info().index);
00716 if(nf->is_constrained(index_u))
00717 {
00718 if(debug>1)ROS_INFO("nf is constrained");
00719 nf->set_constraint(index_u,false);
00720 if(debug>1)ROS_INFO("now nf is constrained=%d ",nf->is_constrained(index_u));
00721 }
00722
00723 if(debug>1)ROS_INFO("fh has index %ld nf has index %ld",fh->vertex(li)->info().index, nf->vertex(index_u)->info().index);
00724
00725 if(debug>1)ROS_INFO("fh->is_valid=%d",fh->is_valid(true));
00726 if(debug>1)ROS_INFO("nf->is_valid=%d",nf->is_valid(true));
00727
00728
00729 for (int u=0; u<3;u++)
00730 {
00731 if(debug>1)ROS_INFO("fh->vertex(%d)->is_valid=%d",u, fh->vertex(u)->is_valid(true));
00732 if(debug>1)ROS_INFO("nf->vertex(%d)->is_valid=%d",u, nf->vertex(u)->is_valid(true));
00733 }
00734
00735
00736
00737
00738
00739
00740
00741
00742
00743
00744
00745
00746
00747 test_if_triangulation_is_valid();
00748
00749
00750
00752
00756
00758
00760
00761
00762
00763
00764
00765
00766
00767
00768
00769
00770
00771
00772
00773
00774 return 1;
00775 }
00776
00777
00778 int class_constrained_delaunay_triangulation::get_intersecting_faces_list(double x0, double y0, double z0, float rgb0,
00779 double x1, double y1, double z1, float rgb1,
00780 double x2, double y2, double z2, float rgb2,
00781 float face_weight, int provenience)
00782 {
00783 char str_seed_point[1024];
00784
00785 Point_2 p0(x0,y0);
00786 Point_2 p1(x1,y1);
00787 Point_2 p2(x2,y2);
00788 Point_2 p_seed((x0+x1+x2)/3., (y0+y1+y2)/3.);
00789
00790 vector_faces.erase(vector_faces.begin(),vector_faces.end());
00791
00792 std::vector<boost::shared_ptr<CDT::Face_handle> > queue;
00793
00794 CDT::Locate_type lt;
00795 int li;
00796 CDT::Face_handle
00797
00798 fh = dt.locate(p_seed, lt, li);
00799
00800 if (lt==CDT::OUTSIDE_AFFINE_HULL)
00801 {
00802 if(debug){sprintf(str_seed_point,"seed point outside affine hull");}
00803 if(debug>1)ROS_INFO("seed point outside affine hull");
00804 }
00805 else if (lt==CDT::OUTSIDE_CONVEX_HULL)
00806 {
00807 boost::shared_ptr<CDT::Face_handle> bp_fh(new CDT::Face_handle(fh));
00808 queue.push_back(bp_fh);
00809
00810 fh = dt.locate(p0, lt, li);
00811 if(lt==CDT::FACE)
00812 {
00813 boost::shared_ptr<CDT::Face_handle> bp_fh(new CDT::Face_handle(fh));
00814 queue.push_back(bp_fh);
00815 }
00816
00817 fh = dt.locate(p1, lt, li);
00818 if(lt==CDT::FACE)
00819 {
00820 boost::shared_ptr<CDT::Face_handle> bp_fh(new CDT::Face_handle(fh));
00821 queue.push_back(bp_fh);
00822 }
00823
00824 fh = dt.locate(p2, lt, li);
00825 if(lt==CDT::FACE)
00826 {
00827 boost::shared_ptr<CDT::Face_handle> bp_fh(new CDT::Face_handle(fh));
00828 queue.push_back(bp_fh);
00829 }
00830
00831
00832 if(debug){sprintf(str_seed_point,"seed point outside convex hull. Added faces on vertices. Queue size = %d",(int)queue.size());}
00833 if(debug>1) ROS_INFO("seed point outside convex hull.Added faces on vertices. Queue size = %d",(int)queue.size());
00834 }
00835 if(lt==CDT::FACE)
00836 {
00837 boost::shared_ptr<CDT::Face_handle> bp_fh(new CDT::Face_handle(fh));
00838 queue.push_back(bp_fh);
00839 if(debug){sprintf(str_seed_point,"seed point on face (%ld %ld %ld)", fh->vertex(0)->info().index, fh->vertex(1)->info().index, fh->vertex(2)->info().index);}
00840 if(debug>1) ROS_INFO("seed point on face (%ld %ld %ld)", fh->vertex(0)->info().index, fh->vertex(1)->info().index, fh->vertex(2)->info().index);
00841 }
00842 else if(lt==CDT::EDGE)
00843 {
00844 boost::shared_ptr<CDT::Face_handle> bp_fh(new CDT::Face_handle(fh));
00845 queue.push_back(bp_fh);
00846 boost::shared_ptr<CDT::Face_handle> bp_nf(new CDT::Face_handle(fh->neighbor(li)));
00847 queue.push_back(bp_nf);
00848 if(debug){sprintf(str_seed_point,"seed point in segment");}
00849 if(debug>1) ROS_INFO("seed point in segment");
00850 }
00851 else if(lt==CDT::VERTEX)
00852 {
00853 CDT::Face_circulator fc = dt.incident_faces(fh->vertex(li)), done(fc);
00854 if(fc!=0)
00855 {
00856 do
00857 {
00858 boost::shared_ptr<CDT::Face_handle> bp_fh(new CDT::Face_handle(fc));
00859 queue.push_back(bp_fh);
00860 }
00861 while(++fc!=done);
00862 }
00863
00864
00865
00866
00867
00868 if(debug){sprintf(str_seed_point,"seed point in vertex");}
00869 if(debug>1) ROS_INFO("seed point in vertex;");
00870 }
00871 else
00872 {
00873 if(debug){sprintf(str_seed_point,"seed point not located no queue");}
00874 if(debug)ROS_INFO("seed point not located no queue");
00875 }
00876
00877
00878
00879
00880 if(debug>1)ROS_INFO("sterting queue search %d" ,(int)queue.size());
00881 initialize_visited();
00882 for (size_t i=0; i<queue.size(); i++)
00883 {
00884 bool reset=false;
00885
00886 if(debug>1) ROS_INFO("new iterations Queue has %d faces i=%d",(int)queue.size(), (int)i);
00887 if ((*queue[i])->visited==false)
00888 {
00889
00890
00891
00892 if(dt.is_infinite((*queue[i])))
00893 {
00894 if(debug>1)ROS_INFO("queue[%d] is infinite. propagating to neighbours",(int)i);
00895
00896
00897 CDT::Face_handle nfh;
00898
00899 nfh = (*queue[i])->neighbor(0);
00900 if (nfh->visited==false)
00901 {
00902 if(debug>1) ROS_INFO("propagating to neighbour 0");
00903 boost::shared_ptr<CDT::Face_handle> bp_fh(new CDT::Face_handle(nfh));
00904 queue.push_back(bp_fh);
00905 }
00906
00907 nfh = (*queue[i])->neighbor(1);
00908 if (nfh->visited==false)
00909 {
00910 if(debug>1) ROS_INFO("propagating to neighbour 1");
00911 boost::shared_ptr<CDT::Face_handle> bp_fh(new CDT::Face_handle(nfh));
00912 queue.push_back(bp_fh);
00913 }
00914
00915 nfh = (*queue[i])->neighbor(2);
00916 if (nfh->visited==false)
00917 {
00918 if(debug>1) ROS_INFO("propagating to neighbour 2");
00919 boost::shared_ptr<CDT::Face_handle> bp_fh(new CDT::Face_handle(nfh));
00920 queue.push_back(bp_fh);
00921 }
00922 (*queue[i])->visited=true;
00923
00924 queue.erase(queue.begin()+i);
00925
00926 }
00927 else if (triangles_overlap(p0,p1,p2, (*queue[i])->vertex(0)->point(), (*queue[i])->vertex(1)->point(), (*queue[i])->vertex(2)->point()))
00928 {
00929 if(debug>1)ROS_INFO("queue[%d] overlaps with triangle propagating to neighbours",(int)i);
00930
00931
00932 CDT::Face_handle nfh;
00933
00934 nfh = (*queue[i])->neighbor(0);
00935 if (nfh->visited==false && !dt.is_infinite(nfh))
00936 {
00937 if(debug>1) ROS_INFO("propagating to neighbour 0");
00938 boost::shared_ptr<CDT::Face_handle> bp_fh(new CDT::Face_handle(nfh));
00939 queue.push_back(bp_fh);
00940 }
00941
00942 nfh = (*queue[i])->neighbor(1);
00943 if (nfh->visited==false && !dt.is_infinite(nfh))
00944 {
00945 if(debug>1) ROS_INFO("propagating to neighbour 1");
00946 boost::shared_ptr<CDT::Face_handle> bp_fh(new CDT::Face_handle(nfh));
00947 queue.push_back(bp_fh);
00948 }
00949
00950 nfh = (*queue[i])->neighbor(2);
00951 if (nfh->visited==false && !dt.is_infinite(nfh))
00952 {
00953 if(debug>1) ROS_INFO("propagating to neighbour 2");
00954 boost::shared_ptr<CDT::Face_handle> bp_fh(new CDT::Face_handle(nfh));
00955 queue.push_back(bp_fh);
00956 }
00957 (*queue[i])->visited=true;
00958 t_face face;
00959 face.v0 = (*queue[i])->vertex(0)->point();
00960 face.v1 = (*queue[i])->vertex(1)->point();
00961 face.v2 = (*queue[i])->vertex(2)->point();
00962 vector_faces.push_back(face);
00963 queue.erase(queue.begin()+i);
00964 }
00965 else
00966 {
00967
00968 if(debug>1)ROS_INFO("queue[%d] does not overlap with triangle",(int)i);
00969 (*queue[i])->visited=true;
00970
00971 queue.erase(queue.begin()+i);
00972 }
00973 }
00974 else
00975 {
00976 if(debug>1) ROS_INFO("queue[%d] was visited",(int)i);
00977 queue.erase(queue.begin()+i);
00978 }
00979
00980 reset=true;
00981 if (reset)i=-1;
00982 }
00983
00984
00985 if(debug>0)
00986 {
00987 std::string str;
00988 char tmp[1024];
00989 str+="___get_intersecting_faces_list___\n";
00990 str+=str_seed_point;
00991 sprintf(tmp,"\nShould visit %d faces:\n", (int)vector_faces.size());
00992 str+=tmp;
00993
00994 for (size_t i=0; i<vector_faces.size(); i++)
00995 {
00996
00997
00998 CDT::Face_handle fh = get_face_handle_from_t_face(&vector_faces[i]);
00999 if (fh==NULL)continue;
01000
01001
01002 sprintf(tmp,"Face(%ld,%ld,%ld), ", (get_face_handle_from_t_face(&vector_faces[i]))->vertex(0)->info().index, (get_face_handle_from_t_face(&vector_faces[i]))->vertex(1)->info().index, (get_face_handle_from_t_face(&vector_faces[i]))->vertex(2)->info().index);
01003 str+=tmp;
01004 }
01005 ROS_INFO("%s",str.c_str());
01006 }
01007
01008
01009
01010 pc_faces_visited.erase(pc_faces_visited.begin(), pc_faces_visited.end());
01011 for (size_t i=0; i<vector_faces.size(); i++)
01012 {
01013
01014 CDT::Face_handle fh = get_face_handle_from_t_face(&vector_faces[i]);
01015 if (fh==NULL)continue;
01016
01017
01018 pcl::PointXYZ pt;
01019 pt.x = (CGAL::to_double((get_face_handle_from_t_face(&vector_faces[i]))->vertex(0)->point().x()) + CGAL::to_double((get_face_handle_from_t_face(&vector_faces[i]))->vertex(1)->point().x()) + CGAL::to_double((get_face_handle_from_t_face(&vector_faces[i]))->vertex(2)->point().x()))/3;
01020 pt.y = (CGAL::to_double((get_face_handle_from_t_face(&vector_faces[i]))->vertex(0)->point().y()) + CGAL::to_double((get_face_handle_from_t_face(&vector_faces[i]))->vertex(1)->point().y()) + CGAL::to_double((get_face_handle_from_t_face(&vector_faces[i]))->vertex(2)->point().y()))/3;
01021 pt.z = (CGAL::to_double((get_face_handle_from_t_face(&vector_faces[i]))->vertex(0)->info().z) + CGAL::to_double((get_face_handle_from_t_face(&vector_faces[i]))->vertex(1)->info().z) + CGAL::to_double((get_face_handle_from_t_face(&vector_faces[i]))->vertex(2)->info().z))/3;
01022
01023
01024 pc_faces_visited.points.push_back(pt);
01025 }
01026 pcl_ros::transformPointCloud(pc_faces_visited, pc_faces_visited, transform.inverse());
01027
01028
01029 return 1;
01030 }
01031
01032
01033
01034
01035 bool class_constrained_delaunay_triangulation::check_if_face_should_be_inserted(double x0, double y0, double z0, float rgb0,
01036 double x1, double y1, double z1, float rgb1,
01037 double x2, double y2, double z2, float rgb2,
01038 float face_weight, int provenience)
01039 {
01040
01041
01042
01043
01044
01048
01049
01050
01051
01052
01053
01054
01055
01056
01057
01058
01059
01060
01061
01062
01063
01064
01065
01066
01067 return true;
01068 }
01069
01070 int class_constrained_delaunay_triangulation::remove_vertices_inside_triangle(double x0, double y0, double z0, float rgb0,
01071 double x1, double y1, double z1, float rgb1,
01072 double x2, double y2, double z2, float rgb2,
01073 float face_weight, int provenience)
01074 {
01075
01076
01077
01078
01079
01080
01084
01085
01086
01087
01088
01089
01090
01091
01092
01093
01094
01095
01096
01097
01098
01099
01100
01101
01102
01103
01104
01108
01109
01110
01115
01116
01117
01118
01120
01121
01122
01123
01124
01127
01128
01129
01130
01131
01132
01133
01134
01135
01136
01137
01138
01139
01140
01141
01142
01143
01144
01145
01146
01147
01148
01149
01150
01151
01152
01153
01154
01155
01156
01157
01158
01159
01160
01161
01162
01163
01164
01165
01166
01167
01168
01169
01170
01171
01172
01173
01174
01175
01176
01177
01178
01179
01180
01181
01182
01183
01184
01185
01186
01187
01188
01189
01190
01191
01192
01193
01194
01195
01196
01197
01198
01199 return 1;
01200 }
01201
01202 int class_constrained_delaunay_triangulation::remove_intersecting_constrained_edges(double x0, double y0, double z0, float rgb0,
01203 double x1, double y1, double z1, float rgb1,
01204 double x2, double y2, double z2, float rgb2,
01205 float face_weight, int provenience)
01206 {
01207
01208
01209
01210
01211
01212
01213
01214
01215
01219
01220
01221
01222
01223
01224
01225
01226
01227
01228
01229
01230
01231
01232
01233
01234
01235
01236
01237
01238
01239
01240
01241
01242
01243
01244
01245
01246
01247
01248
01249
01250
01251
01252
01253
01254
01255
01256
01257
01258
01259
01260
01261
01262
01263
01264
01265
01266
01267
01268
01269
01270
01271
01272
01273
01274 return 1;
01275 }
01276
01277
01278
01279
01280
01281 #endif
01282