diff --git a/Nef_3/include/CGAL/Nef_3/SNC_constructor.h b/Nef_3/include/CGAL/Nef_3/SNC_constructor.h index ba1edc4efc1..cf2326bd199 100644 --- a/Nef_3/include/CGAL/Nef_3/SNC_constructor.h +++ b/Nef_3/include/CGAL/Nef_3/SNC_constructor.h @@ -1958,15 +1958,26 @@ public: CGAL_NEF_TRACEN(""); } + std::vector vertices_to_delete ; Vertex_iterator v; CGAL_forall_vertices(v, *this->sncp()) - if(erase_vertex[v]) { - CGAL_NEF_TRACEN("erase " << v->point()); - if(Infi_box::is_infibox_corner(v->point())) - recreate.push_back(v->point()); - this->sncp()->delete_vertex(v); - res = true; - } + { + if(erase_vertex[v]) + { + CGAL_NEF_TRACEN("erase " << v->point()); + if(Infi_box::is_infibox_corner(v->point())) + recreate.push_back(v->point()); + vertices_to_delete.push_back(v); + res = true; + } + } + + for( typename std::vector::iterator vit = vertices_to_delete.begin() + ; vit != vertices_to_delete.end() + ; ++ vit + ) + this->sncp()->delete_vertex(*vit); + typename std::list::const_iterator pi; for(pi = recreate.begin(); pi != recreate.end(); ++pi) diff --git a/Nef_3/include/CGAL/Nef_3/SNC_decorator.h b/Nef_3/include/CGAL/Nef_3/SNC_decorator.h index f0367bdce4f..71b38e0178f 100644 --- a/Nef_3/include/CGAL/Nef_3/SNC_decorator.h +++ b/Nef_3/include/CGAL/Nef_3/SNC_decorator.h @@ -1459,8 +1459,8 @@ class SNC_decorator : public SNC_const_decorator { Shell_entry_iterator si; CGAL_forall_shells_of(si,voli) { - valid = valid && (si != Shell_entry_iterator() && - SFace_handle(si) != SFace_handle() && + //valid = valid && (si != Shell_entry_iterator() && + valid = valid && (SFace_handle(si) != SFace_handle() && SFace_handle(si) != NULL); valid = valid && (++count <= max); } diff --git a/Nef_3/include/CGAL/Nef_3/SNC_io_parser.h b/Nef_3/include/CGAL/Nef_3/SNC_io_parser.h index 345a08610fc..5238bc13f58 100644 --- a/Nef_3/include/CGAL/Nef_3/SNC_io_parser.h +++ b/Nef_3/include/CGAL/Nef_3/SNC_io_parser.h @@ -1079,13 +1079,13 @@ void SNC_io_parser::read() addInfiBox = (kernel_type == "standard" && Infi_box::extended_kernel()); if(addInfiBox) { - Vertex_of.reserve(vn+8); - Edge_of.reserve(en+24); - Halffacet_of.reserve(fn+12); - Volume_of.reserve(cn+1); - SEdge_of.reserve(sen+48); - SLoop_of.reserve(sln); - SFace_of.reserve(sfn+16); + Vertex_of.resize(vn+8); + Edge_of.resize(en+24); + Halffacet_of.resize(fn+12); + Volume_of.resize(cn+1); + SEdge_of.resize(sen+48); + SLoop_of.resize(sln); + SFace_of.resize(sfn+16); for(i=0; isncp()->new_vertex_only(); for(i=0; isncp()->new_halfedge_only(); for(i=0; isncp()->new_halffacet_only(); @@ -1095,13 +1095,13 @@ void SNC_io_parser::read() for(i=0; isncp()->new_sface_only(); } else { - Vertex_of.reserve(vn); - Edge_of.reserve(en); - Halffacet_of.reserve(fn); - Volume_of.reserve(cn); - SEdge_of.reserve(sen); - SLoop_of.reserve(sln); - SFace_of.reserve(sfn); + Vertex_of.resize(vn); + Edge_of.resize(en); + Halffacet_of.resize(fn); + Volume_of.resize(cn); + SEdge_of.resize(sen); + SLoop_of.resize(sln); + SFace_of.resize(sfn); for(i=0; isncp()->new_vertex_only(); for(i=0; isncp()->new_halfedge_only(); for(i=0; isncp()->new_halffacet_only(); diff --git a/Nef_3/include/CGAL/Nef_3/SNC_simplify.h b/Nef_3/include/CGAL/Nef_3/SNC_simplify.h index ebc4a94d7a2..e9b0e02e261 100644 --- a/Nef_3/include/CGAL/Nef_3/SNC_simplify.h +++ b/Nef_3/include/CGAL/Nef_3/SNC_simplify.h @@ -156,29 +156,36 @@ class SNC_simplify : public SNC_decorator { if(fc.is_shalfedge() ) { SHalfedge_handle e(fc); SHalfedge_around_facet_circulator u(e), eend(e); - CGAL_For_all(u, eend) { - SFace_handle fu = u->incident_sface(), ftu = u->twin()->incident_sface(); - CGAL_NEF_TRACEN("sfUNION of "<index(fu)<<" & "<index(ftu)); - merge_sets( fu, ftu, hash, uf); - SM_decorator SD(&*u->source()->source()); - CGAL_NEF_TRACEN("removing "<index(u)<<" & "<index(u->twin())); - Halfedge_handle src(u->source()), tgt(u->target()); - if ( SD.is_closed_at_source(u) ) - SD.set_face( src, fu); - if ( SD.is_closed_at_source( u->twin()) ) - SD.set_face( tgt, fu); + + //CGAL_For_all(u, eend) { + for ( bool _circ_loop_flag = ! ::CGAL::is_empty_range( u, eend); + _circ_loop_flag; \ + _circ_loop_flag = ( u != eend ) + ) + { + SFace_handle fu = u->incident_sface(), ftu = u->twin()->incident_sface(); + CGAL_NEF_TRACEN("sfUNION of "<index(fu)<<" & "<index(ftu)); + merge_sets( fu, ftu, hash, uf); + SM_decorator SD(&*u->source()->source()); + CGAL_NEF_TRACEN("removing "<index(u)<<" & "<index(u->twin())); + Halfedge_handle src(u->source()), tgt(u->target()); + if ( SD.is_closed_at_source(u) ) + SD.set_face( src, fu); + if ( SD.is_closed_at_source( u->twin()) ) + SD.set_face( tgt, fu); /* TO VERIFY: does is_closed_at_source(u) imply is_isolated(src)? if it is true, the svertex face update is not necesary. */ - SD.delete_edge_pair(u); - if( SD.is_isolated(src)) - // SD.delete_vertex_only(src); - SD.set_face(src,fu); - SM_decorator SD2(&*tgt->source()); - if( SD2.is_isolated(tgt)) - // SD.delete_vertex_only(tgt); - SD2.set_face(tgt,fu); + SHalfedge_around_facet_circulator next = u ; + ++ next ; + SD.delete_edge_pair(u); + if( SD.is_isolated(src)) + SD.set_face(src,fu); + SM_decorator SD2(&*tgt->source()); + if( SD2.is_isolated(tgt)) + SD2.set_face(tgt,fu); + u = next ; /* TO VERIFY: can both svertices be isolated at the same time? */ - } + } } else if(fc.is_shalfloop()) { SHalfloop_handle l(fc); @@ -458,9 +465,10 @@ class SNC_simplify : public SNC_decorator { CGAL_NEF_TRACEN("s2 = " << IO->index(s2)); if( s1 == s2) { CGAL_NEF_TRACEN(IO->index(s1)<<'('<index(s2->twin())<<") to sloop"); + Halffacet_handle facet = s1->facet(); SD.convert_edge_to_loop(s1); CGAL_assertion(SD.shalfloop() != SHalfloop_handle()); - D.add_sloop_to_facet( SD.shalfloop(), s1->facet()); + D.add_sloop_to_facet( SD.shalfloop(), facet); CGAL_NEF_TRACEN(IO->index(s2)<<" removed"); } else { diff --git a/Nef_3/include/CGAL/Nef_3/SNC_structure.h b/Nef_3/include/CGAL/Nef_3/SNC_structure.h index f218e18a5d9..9494b5a29d4 100644 --- a/Nef_3/include/CGAL/Nef_3/SNC_structure.h +++ b/Nef_3/include/CGAL/Nef_3/SNC_structure.h @@ -40,6 +40,9 @@ #include #include +#include +#include + CGAL_BEGIN_NAMESPACE template @@ -691,13 +694,13 @@ public: expensive operation.}*/ SNC_structure() : - boundary_item_(undef_), sm_boundary_item_(undef_), + boundary_item_(boost::none), sm_boundary_item_(boost::none), vertices_(), halfedges_(), halffacets_(), volumes_(), shalfedges_(), shalfloops_(), sfaces_() {} ~SNC_structure() { CGAL_NEF_TRACEN("~SNC_structure: clearing "< bool is_boundary_object(H h) - { return boundary_item_[h]!=undef_; } + { return boundary_item_[h]!=boost::none; } template bool is_sm_boundary_object(H h) - { return sm_boundary_item_[h]!=undef_; } + { return sm_boundary_item_[h]!=boost::none; } template Object_iterator& boundary_item(H h) - { return boundary_item_[h]; } + { return *boundary_item_[h]; } template Object_iterator& sm_boundary_item(H h) - { return sm_boundary_item_[h]; } + { return *sm_boundary_item_[h]; } template void store_boundary_item(H h, Object_iterator o) @@ -765,12 +768,12 @@ public: template void undef_boundary_item(H h) - { CGAL_assertion(boundary_item_[h]!=undef_); - boundary_item_[h] = undef_; } + { CGAL_assertion(boundary_item_[h]!=boost::none); + boundary_item_[h] = boost::none; } template void undef_sm_boundary_item(H h) - { CGAL_assertion(sm_boundary_item_[h]!=undef_); - sm_boundary_item_[h] = undef_; } + { CGAL_assertion(sm_boundary_item_[h]!=boost::none); + sm_boundary_item_[h] = boost::none; } void reset_iterator_hash(Object_iterator it) { SVertex_handle sv; @@ -1335,9 +1338,11 @@ public: protected: void pointer_update(const Self& D); - static Object_iterator undef_; - Generic_handle_map boundary_item_; - Generic_handle_map sm_boundary_item_; + + typedef boost::optional Optional_object_iterator ; + + Generic_handle_map boundary_item_; + Generic_handle_map sm_boundary_item_; Vertex_list vertices_; Halfedge_list halfedges_; @@ -1483,10 +1488,5 @@ pointer_update(const SNC_structure& D) } } -template -typename SNC_structure::Object_iterator -SNC_structure::undef_; - - CGAL_END_NAMESPACE #endif // CGAL_SNC_STRUCTURE_H