sm_overlayer.h

来自「CGAL is a collaborative effort of severa」· C头文件 代码 · 共 1,638 行 · 第 1/4 页

H
1,638 行
字号
template <typename Below_accessor, typename Halfsphere_geometry>void SM_overlayer<Map>::create_face_objects(SHalfedge_iterator e_start, SHalfedge_iterator e_end,  SVertex_iterator v_start, SVertex_iterator v_end,  const Below_accessor& D,   const Halfsphere_geometry& SG){  CGAL_NEF_TRACEN("create_face_objects()");  if(e_start != e_end) {    CGAL::Unique_hash_map<SHalfedge_handle,int> SFaceCycle(-1);    std::vector<SHalfedge_handle>  MinimalSHalfedge;    SHalfedge_around_sface_circulator hfc(last_out_edge(v_start)),hend(hfc);    CGAL_NEF_TRACEN("equator cycle "<<PH(hfc));    CGAL_For_all(hfc,hend) SFaceCycle[hfc]=0; // outer face cycle = 0    MinimalSHalfedge.push_back(twin(first_out_edge(v_start)));    int i=1;     for (SHalfedge_iterator e = e_start; e != e_end; ++e) {      if ( SFaceCycle[e] >= 0 ) continue; // already assigned      SHalfedge_around_sface_circulator hfc(e),hend(hfc);      SHalfedge_handle e_min = e;      CGAL_NEF_TRACEN("");       CGAL_NEF_TRACEN("  face cycle numbering "<<i);      CGAL_For_all(hfc,hend) {	SFaceCycle[hfc]=i; // assign face cycle number	if ( SG.compare_xy(point(target(hfc)), point(target(e_min))) < 0 )	  e_min = hfc;      	CGAL_NEF_TRACEN(PH(hfc));      } CGAL_NEF_TRACEN("");      MinimalSHalfedge.push_back(e_min);      ++i;    }        for (int j=1; j<i; ++j) {      SHalfedge_handle e = MinimalSHalfedge[j];      CGAL_NEF_TRACEN("  face cycle "<<j<<" minimal halfedge "<<PH(e));      Sphere_point p1 = point(source(e)), 	p2 = point(target(e)), 	p3 = point(target(next(e)));      if ( SG.orientation(p1,p2,p3) > 0 ) { // left_turn => outer face cycle	SFace_handle f = this->new_sface();	link_as_face_cycle(e,f);	CGAL_NEF_TRACEN("  creating new face object "<<&*f<<" bd "<<&*e);      }    }        for (SHalfedge_iterator e = e_start; e != e_end; ++e) {      if ( face(e) != SFace_handle() ) continue;      if ( SFaceCycle[e] == 0 ) continue;      CGAL_NEF_TRACEN("linking hole "<<PH(e));      SFace_handle f = determine_face(e,MinimalSHalfedge,SFaceCycle,D);      if(f != SFace_handle())	link_as_face_cycle(e,f);    }  }      for (SVertex_iterator v = v_start; v != v_end; ++v) {    if ( !is_isolated(v) ) continue;    SHalfedge_handle e_below = D.halfedge_below(v);    CGAL_assertion( e_below != SHalfedge_handle() || e_start == e_end );    if(e_below != SHalfedge_handle())      link_as_isolated_vertex(v,face(e_below));  }}template <typename Map>template <typename Below_accessor>void SM_overlayer<Map>::complete_face_support(SVertex_iterator v_start, SVertex_iterator v_end,  const Below_accessor& D, std::vector<Mark>& mohs, int offset, bool both) const{ CGAL_NEF_TRACEN("complete_face_support");  for (SVertex_iterator v = v_start; v != v_end; ++v) {     CGAL_NEF_TRACEN("VERTEX = "<<PH(v));    Mark m_buffer[2];    SHalfedge_handle e_below = halfedge_below(v);    if ( v == v_start ) {           for (int i=0; i<2; ++i){	m_buffer[i] = mohs[offset+2*i];      }     } else if ( e_below != SHalfedge_handle() ) {      for (int i=0; i<2; ++i) {	CGAL_NEF_TRACEN("edge below "<< PH(e_below) << " " << mark(e_below,i));	m_buffer[i] = incident_mark(e_below,i);      }    } else { // e_below does not exist      //      CGAL_assertion( point(v).hz() == 0 &&       //		   ( offset == 0 ? (point(v).hx() >= 0) : (point(v).hx()<=0)) );      if(!is_isolated(v)) {	if(!both) {	  for (int i=0; i<2; ++i)	    m_buffer[i] = mohs[offset+2*i];		  CGAL_NEF_TRACEN("no edge below ");	} else {	  for (int i=0; i<2; ++i) 	    m_buffer[i] = incident_mark(previous(first_out_edge(v)),i);	}      }    } CGAL_NEF_TRACEN(" faces right-below "<<m_buffer[0]<<" "<<m_buffer[1]);    for (int i=0; i<2; ++i) {      Object_handle o = supp_object(v,i);      if ( o == NULL ) { 	CGAL_NEF_TRACEN("no vertex support"); 	mark(v,i) = m_buffer[i]; continue;       }      SVertex_const_handle vs;      SHalfedge_const_handle es;      SHalfloop_const_handle ls;      if ( CGAL::assign(vs,o) ) { mark(v,i) = PI[i].mark(vs); continue; }      if ( CGAL::assign(es,supp_object(v,i)) ) {        if ( point(source(es)) == point(v) )         { mark(v,i) = PI[i].mark(source(es)); continue; }        if ( point(target(es)) == point(v) )         { mark(v,i) = PI[i].mark(target(es)); continue; }        mark(v,i) = PI[i].mark(es); continue;      }      if ( CGAL::assign(ls,o) ) { 	mark(v,i) = PI[i].mark(ls); 	CGAL_NEF_TRACEN("loop " << PI[i].circle(ls)); continue; }      CGAL_assertion_msg(0,"wrong handle");    } CGAL_NEF_TRACEN(" vertex marks "<<mark(v,0)<<" "<<mark(v,1));    if ( is_isolated(v) ) continue;    SHalfedge_around_svertex_circulator e(first_out_edge(v)), hend(e);    CGAL_For_all(e,hend) {      if ( !is_forward(e) ) break;      CGAL_NEF_TRACEN("  forward edge "<<PH(e));      for (int i=0; i<2; ++i) {        if ( supp_object(e,i) != NULL ) {          SHalfedge_const_handle ei;           if ( CGAL::assign(ei,supp_object(e,i)) ) {             if ( PI[i].circle(ei) != circle(e) ) { ei = PI[i].twin(ei); }            CGAL_assertion( PI[i].circle(ei) == circle(e) );             CGAL_NEF_TRACEN("  supporting edge "<<i<<" "<<PH(ei));            incident_mark(twin(e),i) =              PI[i].mark(PI[i].face(PI[i].twin(ei)));            mark(e,i) = mark(twin(e),i) = PI[i].mark(ei);            incident_mark(e,i) = m_buffer[i] =              PI[i].mark(PI[i].face(ei));           }          SHalfloop_const_handle li;          if ( CGAL::assign(li,supp_object(e,i)) ) {             if ( PI[i].circle(li) != circle(e) ) { li = PI[i].twin(li); }            CGAL_assertion( PI[i].circle(li) == circle(e) );             CGAL_NEF_TRACEN("  supporting loop "<<i<<" "<<PH(li));            incident_mark(twin(e),i) =              PI[i].mark(PI[i].face(PI[i].twin(li)));            mark(e,i) = mark(twin(e),i) = PI[i].mark(li);            incident_mark(e,i) = m_buffer[i] =              PI[i].mark(PI[i].face(li));           }        } else { CGAL_NEF_TRACEN("  support from face below "<<i);	  incident_mark(twin(e),i) = mark(e,i) = mark(twin(e),i) =          incident_mark(e,i) = m_buffer[i];        }      } CGAL_NEF_TRACEN("  face marks "<<m_buffer[0]<<" "<<m_buffer[1]);    }    CGAL_NEF_TRACEN(" mark of "<<PH(v)<<" "<<mark(v,0)<<" "<<mark(v,1));  }   SFace_iterator f;  for (f = this->sfaces_begin(); f != this->sfaces_end(); ++f) {    assoc_info(f);    SFace_cycle_iterator boundary_object(f->sface_cycles_begin());    if (!boundary_object.is_shalfedge() )       CGAL_assertion_msg(0,"Outer face cycle should be first.");    SHalfedge_handle e(boundary_object);    for (int i=0; i<2; ++i) mark(f,i) = incident_mark(e,i);  }}template <typename Map>template <typename Mark_accessor>void SM_overlayer<Map>::merge_nodes(SHalfedge_handle e1, SHalfedge_handle e2,  const Mark_accessor& D){  SVertex_handle v1 = source(e1), v2 = target(e2);  CGAL_NEF_TRACEN("merge_nodes "<<PH(v1)<<PH(v2));  CGAL_assertion(point(v1)==point(v2));  SHalfedge_handle ep1 = previous(e1), en2 = next(e2);  SHalfedge_around_svertex_circulator eav(out_edges(v2)),ee(eav);  CGAL_For_all(eav,ee) { set_source(eav,v1); }  link_as_prev_next_pair(e2,e1);    link_as_prev_next_pair(ep1,en2);   D.assert_equal_marks(v1,v2);  D.discard_info(v2);  delete_vertex_only(v2);}template <typename Map>template <typename Mark_accessor>void SM_overlayer<Map>::merge_halfsphere_maps(SVertex_handle v1, SVertex_handle v2,  const Mark_accessor& D){ CGAL_NEF_TRACEN("merging halfspheres "<<PH(v1)<<PH(v2));  CGAL_assertion(point(v1)==point(v2));  std::list<SHalfedge_pair> L_equator;  SHalfedge_around_sface_circulator     ep(last_out_edge(v1)), en(twin(first_out_edge(v2)));  do {    L_equator.push_back(SHalfedge_pair(ep,en));   merge_nodes(ep,en,D); ++ep; --en;   } while ( source(ep) != v1 );    typename std::list<SHalfedge_pair>::iterator it;  CGAL_forall_iterators(it,L_equator) {     SHalfedge_handle e1 = it->first, e2 = it->second;    SHalfedge_handle e1t = twin(e1), e2t = twin(e2);    CGAL_NEF_TRACEV(PH(e1));CGAL_NEF_TRACEV(PH(e2));    SHalfedge_handle e2tp = previous(e2t);    SHalfedge_handle e2tn = next(e2t);    link_as_prev_next_pair(e2tp,e1);    link_as_prev_next_pair(e1,e2tn);    SFace_handle f = face(e2t);    if ( is_sm_boundary_object(e2t) )    { undo_sm_boundary_object(e2t,f); store_sm_boundary_object(e1,f); }    set_face(e1,f);    if ( e2 == first_out_edge(source(e2)) )      set_first_out_edge(source(e2),e1t);    D.discard_info(e2);    delete_edge_pair_only(e2);  }}template <typename Map>template <typename Selection>void SM_overlayer<Map>::select(const Selection& SP) const{   SVertex_iterator v;  CGAL_forall_svertices(v,*this) {    mark(v) = SP(mark(v,0),mark(v,1));    discard_info(v);   }  SHalfedge_iterator e;  CGAL_forall_sedges(e,*this) {    mark(e) = SP(mark(e,0),mark(e,1));    mark(twin(e)) = SP(mark(twin(e),0),mark(twin(e),1));    CGAL_assertion(mark(e) == mark(twin(e)));    discard_info(e);  }  SFace_iterator f;  CGAL_forall_sfaces(f,*this) {    mark(f) = SP(mark(f,0),mark(f,1));    discard_info(f);  }}template <typename Map>void SM_overlayer<Map>::simplify(){  CGAL_NEF_TRACEN("simplifying");   typedef typename CGAL::Union_find<SFace_handle>::handle Union_find_handle;  CGAL::Unique_hash_map< SFace_handle, Union_find_handle> Pitem(NULL);  CGAL::Unique_hash_map< SVertex_handle, Union_find_handle> Vitem(NULL);  CGAL::Union_find< SFace_handle> UF;    SFace_iterator f;  CGAL_forall_sfaces(f,*this) {     Pitem[f] = UF.make_set(f);     clear_face_cycle_entries(f);  }  if ( this->has_shalfloop() ) {    SHalfloop_handle l = this->shalfloop();    SFace_handle f = *(UF.find(Pitem[face(l)]));    link_as_loop(l,f);    f = *(UF.find(Pitem[face(twin(l))]));    link_as_loop(twin(l),f);  }  SHalfedge_iterator e, en;  for(e = this->shalfedges_begin(); e != this->shalfedges_end(); e = en) {     en = e; ++en; if ( en==twin(e) ) ++en;    CGAL_NEF_TRACEN("can simplify ? " << PH(e));    CGAL_NEF_TRACEN(mark(e) << " " << mark(face(e)) << " " << mark(face(twin(e))));    if (( mark(e) == mark(face(e)) && mark(e) == mark(face(twin(e))))){      CGAL_NEF_TRACEN("deleting "<<PH(e));      if ( !UF.same_set(Pitem[face(e)],			Pitem[face(twin(e))]) ) {		UF.unify_sets( Pitem[face(e)],		       Pitem[face(twin(e))] );	CGAL_NEF_TRACEN("unioning disjoint faces");      }            CGAL_NEF_TRACEN("is_closed_at_source " << is_closed_at_source(e) << 	     " " << is_closed_at_source(twin(e)));            if ( is_closed_at_source(e) )	Vitem[source(e)] = Pitem[face(e)];            if ( is_closed_at_source(twin(e)))	Vitem[target(e)] = Pitem[face(e)];            delete_edge_pair(e);    }  }  CGAL::Unique_hash_map<SHalfedge_handle,bool> linked(false);  for (e = this->shalfedges_begin(); e != this->shalfedges_end(); ++e) {    if ( linked[e] ) continue;    SHalfedge_around_sface_circulator hfc(e),hend(hfc);    SFace_handle f = *(UF.find( Pitem[face(e)]));    CGAL_For_all(hfc,hend) {  set_face(hfc,f); linked[hfc]=true; }    store_sm_boundary_object(e,f);  }  SVertex_iterator v,vn;  for(v = this->svertices_begin(); v != this->svertices_end(); v=vn) {    vn=v; ++vn;    if ( is_isolated(v) ) {          if(Vitem[v] != NULL) {	set_face(v,*(UF.find(Vitem[v])));	CGAL_NEF_TRACEN("incident face of " << PH(v) << " set to " << &*(face(v)));      }      else {	set_face(v, *(UF.find(Pitem[face(v)])));	CGAL_NEF_TRACEN("isolated svertex " << PH(v) << 	       " already has incident face " << &*(face(v)));      }      if ( mark(v) == mark(face(v)) ) {        CGAL_NEF_TRACEN("removing isolated vertex"<<PH(v));        delete_vertex_only(v);        }       else         store_sm_boundary_object(v,face(v)); // isolated, but should stay    } else { // v not isolated      SHalfedge_handle e2 = first_out_edge(v), e1 = previous(e2);      if ( has_outdeg_two(v) &&           mark(v) == mark(e1) && mark(v) == mark(e2) &&           circle(e1) == circle(e2) ) {        CGAL_NEF_TRACEN("collinear at "<<PH(v)<<PH(e1)<<PH(e2));        if ( e1 == e2 ){ CGAL_NEF_TRACEN("edge_to_loop"); convert_edge_to_loop(e1);}        else {CGAL_NEF_TRACEN("merge_edge_pairs"); merge_edge_pairs_at_target(e1); }       }    }  }  SFace_iterator fn;  for (f = fn = this->sfaces_begin(); f != this->sfaces_end(); f=fn) {     ++fn;    Union_find_handle pit = Pitem[f];    if ( UF.find(pit) != pit ) {      CGAL_NEF_TRACEN("delete face " << &*f);      delete_face_only(f);    }  }}template <typename Map>template <typename Iterator>void SM_overlayer<Map>::subdivide_segments(Iterator start, Iterator end) const{typedef SMO_decorator<SM_decorator,Iterator> SM_output;typedef typename Sphere_kernel::Positive_halfsphere_geometry PH_geometry;typedef CGAL::Segment_overlay_traits<           Iterator, SM_output, PH_geometry>  PHS_traits;typedef CGAL::generic_sweep<PHS_traits> Positive_halfsphere_sweep;typedef typename Sphere_kernel::Negative_halfsphere_geometry NH_geometry;typedef CGAL::Segment_overlay_traits<           Iterator, SM_output, NH_geometry> NHS_traits;typedef CGAL::generic_sweep<NHS_traits> Negative_halfsphere_sweep;  std::list<Sphere_segment> Lp,Lm;  partition_xy( start, end, Lp , +1);  partition_xy( start, end, Lm , -1);  // both lists initialized with four quarter segments  // supporting the xy-equator thereby separating the   // two halfspheres   // all other segments in the range are split into their  // connected components with respect to the xy-plane.  //CGAL_NEF_TRACEN("Lp="<<(MSDEBUG::print_elements(Lp),""));  //CGAL_NEF_TRACEN("Lm="<<(MSDEBUG::print_elements(Lm),""));  SVertex_handle v1,v2;  SM_output O(*this);   typedef typename PHS_traits::INPUT Input_range;  Positive_halfsphere_sweep SP(Input_range(Lp.begin(),Lp.end()),O);  SP.sweep();  //CGAL_NEF_TRACEN("POS SWEEP\n"<<(dump(std::cerr),""));  v1= this->vertices_begin(); v2=--this->vertices_end();  Negative_halfsphere_sweep SM(Input_range(Lm.begin(),Lm.end()),O);  SM.sweep();  //CGAL_NEF_TRACEN("NEG SWEEP\n"<<(dump(std::cerr),""));  ++v2;  // now two CCs of sphere graph calculated  // v1 = first node of CC in positive xy-sphere  // v2 = first node of CC in negative xy-sphere  merge_halfsphere_maps(v1,v2,O);  this->check_integrity_and_topological_planarity(false);}CGAL_END_NAMESPACE#endif //CGAL_SM_OVERLAYER_H

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?