diff --git a/Nef_3/demo/Nef_3/include/CGAL/Nef_3/visual_hull_creator.h b/Nef_3/demo/Nef_3/include/CGAL/Nef_3/visual_hull_creator.h index b777d4faf5b..a241f749a88 100644 --- a/Nef_3/demo/Nef_3/include/CGAL/Nef_3/visual_hull_creator.h +++ b/Nef_3/demo/Nef_3/include/CGAL/Nef_3/visual_hull_creator.h @@ -7,6 +7,7 @@ #include #include #include +#include CGAL_BEGIN_NAMESPACE @@ -22,7 +23,10 @@ class visual_hull_creator : public CGAL::Modifier_base { typedef typename SNC_structure::SM_decorator SM_decorator; typedef typename SNC_structure::Vertex_handle Vertex_handle; + typedef typename SNC_structure::SHalfedge_handle SHalfedge_handle; typedef typename SNC_structure::SVertex_iterator SVertex_iterator; + typedef typename SNC_structure::SHalfedge_around_sface_circulator + SHalfedge_around_sface_circulator; typedef typename SNC_structure::Point_3 Point_3; typedef typename SNC_structure::Plane_3 Plane_3; typedef typename SNC_structure::Vector_3 Vector_3; @@ -35,6 +39,10 @@ class visual_hull_creator : public CGAL::Modifier_base { Plane_3 cut; SNC_structure* sncp; std::list > polygon_list; + int vbase; + int voffset; + int ebase; + int eoffset; private: Plane_3 find_cutoff_plane() { @@ -83,11 +91,58 @@ class visual_hull_creator : public CGAL::Modifier_base { return Plane_3(); } + void add_camera_indexes(SHalfedge_handle se) { + SHalfedge_around_sface_circulator sfc(se), send(sfc); + CGAL_For_all(sfc, send) { + sfc->source()->set_index(vbase+voffset); + ++voffset; + sfc->set_index(ebase+eoffset); + sfc->twin()->set_index(ebase+eoffset+1); + eoffset+=2; + } + } + + template + void add_opposite_indexes(SHalfedge_handle se, + Distance spoints, bool outer) { + SHalfedge_around_sface_circulator sfc(se); + if(spoints > 0) { + sfc->source()->set_index(vbase+voffset+spoints-1); + --voffset; + } else + sfc->source()->set_index(vbase+voffset); + if(outer) { + sfc->set_index(ebase+eoffset); + sfc->twin()->set_index(ebase+eoffset+1); + } else { + sfc->set_index(ebase+eoffset+1); + sfc->twin()->set_index(ebase+eoffset); + } + --sfc; + sfc->source()->set_index(vbase); + if(spoints > 0) { + sfc->set_index(ebase+2*spoints-2); + sfc->twin()->set_index(ebase+2*spoints-1); + } else { + sfc->set_index(ebase); + sfc->twin()->set_index(ebase+1); + ebase+=2; + eoffset-=2; + } + --sfc; + ++vbase; + sfc->source()->set_index(vbase+voffset); + sfc->set_index(ebase); + sfc->twin()->set_index(ebase+1); + } public: visual_hull_creator(Point_3 min, Point_3 max, Point_3 position, std::list > p) : - room_min(min), room_max(max), c_pos(position), polygon_list(p) { } + room_min(min), room_max(max), + c_pos(position), polygon_list(p), + vbase(Index_generator::get_unique_index()), + voffset(0), ebase(vbase), eoffset(0) {} void operator()(SNC_structure& snc) { @@ -105,12 +160,18 @@ class visual_hull_creator : public CGAL::Modifier_base { add_inner_cycle_to_camera(li->begin(), li->end()); } - for(li=polygon_list.begin(); li!=polygon_list.end(); ++li) + for(li=polygon_list.begin(); li!=polygon_list.end(); ++li) { if(li==polygon_list.begin()) { create_outer_cycles_opposites(li->begin(), li->end()); } else { create_inner_cycles_opposites(li->begin(), li->end()); } + ++voffset; + ebase+=2; + eoffset-=2; + } + + while(Index_generator::get_unique_index() < ebase + 2); } template @@ -124,7 +185,9 @@ class visual_hull_creator : public CGAL::Modifier_base { spoints.push_back(Sphere_point(*si-camera->point())); } - C.add_outer_sedge_cycle(camera, spoints.begin(), spoints.end(),false); + SHalfedge_handle se = + C.add_outer_sedge_cycle(camera, spoints.begin(), spoints.end(), false); + add_camera_indexes(se); } template @@ -158,7 +221,12 @@ class visual_hull_creator : public CGAL::Modifier_base { bool orient(CGAL::orientation(*si_prev, *si, *si_next,camera->point()) == CGAL::POSITIVE); - C.add_outer_sedge_cycle(sncp->new_vertex(*si),spoints.begin(), spoints.end(),orient); + SHalfedge_handle se = + C.add_outer_sedge_cycle(sncp->new_vertex(*si),spoints.begin(), spoints.end(), orient); + if(si == points_on_plane.begin()) + add_opposite_indexes(se, points_on_plane.size(), true); + else + add_opposite_indexes(se, 0, true); ++si_prev; if(si_prev==points_on_plane.end()) si_prev=points_on_plane.begin(); } @@ -175,7 +243,9 @@ class visual_hull_creator : public CGAL::Modifier_base { spoints.push_back(Sphere_point(*si-camera->point())); } - C.add_inner_sedge_cycle(camera, spoints.begin(), spoints.end(),false,true); + SHalfedge_handle se = + C.add_inner_sedge_cycle(camera, spoints.begin(), spoints.end(),false,true); + add_camera_indexes(se); } template @@ -209,7 +279,13 @@ class visual_hull_creator : public CGAL::Modifier_base { bool orient(CGAL::orientation(*si_prev, *si, *si_next,camera->point()) == CGAL::NEGATIVE); - C.add_inner_sedge_cycle(sncp->new_vertex(*si),spoints.begin(), spoints.end(),orient,false); + + SHalfedge_handle se = + C.add_inner_sedge_cycle(sncp->new_vertex(*si),spoints.begin(), spoints.end(),orient,false); + if(si == points_on_plane.begin()) + add_opposite_indexes(se, points_on_plane.size(), false); + else + add_opposite_indexes(se, 0, false); ++si_prev; if(si_prev==points_on_plane.end()) si_prev=points_on_plane.begin(); }