sm_overlayer.h

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

H
1,638 行
字号
  if(!compute_halfsphere[2][1])    return 5;  if(!compute_halfsphere[0][0]) {    CGAL_forall_iterators(it,L) {      if(CGAL::orientation(it->source(),it->target(), Sphere_point(1,0,0),			   CGAL::ORIGIN+it->sphere_circle().orthogonal_vector())	 == CGAL::NEGATIVE) 	if((it->source().hx()==0 && it->target().hx()==0) || it->is_long()) { 	  compute_halfsphere[0][0] = true;	  break;	}    }  }    if(!compute_halfsphere[0][0]) {    compute_halfsphere[0][1] = true;    return 0;  }    if(!compute_halfsphere[0][1]) {    CGAL_forall_iterators(it,L) {      if(CGAL::orientation(it->source(),it->target(), Sphere_point(-1,0,0),			   CGAL::ORIGIN+it->sphere_circle().orthogonal_vector())	 == CGAL::NEGATIVE) 	if((it->source().hx()==0 && it->target().hx()==0) || it->is_long()) { 	  compute_halfsphere[0][1] = true;	  break;	}    }  }  if(!compute_halfsphere[0][1])    return 1;    if(!compute_halfsphere[1][0]) {    CGAL_forall_iterators(it,L) {      if(CGAL::orientation(it->source(),it->target(), Sphere_point(0,1,0),			   CGAL::ORIGIN+it->sphere_circle().orthogonal_vector())	 == CGAL::NEGATIVE) 	if((it->source().hy()==0 && it->target().hy()==0) || it->is_long()) { 	  compute_halfsphere[1][0] = true;	  break;	}    }  }    if(!compute_halfsphere[1][0]) {    compute_halfsphere[1][1] = true;    return 2;  }    if(!compute_halfsphere[1][1]) {    CGAL_forall_iterators(it,L) {      if(CGAL::orientation(it->source(),it->target(), Sphere_point(0,-1,0),			   CGAL::ORIGIN+it->sphere_circle().orthogonal_vector())	 == CGAL::NEGATIVE) 	if((it->source().hy()==0 && it->target().hy()==0) || it->is_long()) { 	  compute_halfsphere[1][1] = true;	  break;	}    }  }  if(!compute_halfsphere[1][1])    return 3;  return -1;}template <typename Map>void SM_overlayer<Map>::create(const Sphere_circle& c){ SHalfloop_handle l1 = this->new_shalfloop_pair();  SHalfloop_handle l2 = this->twin(l1);  circle(l1) = c; circle(l2) = c.opposite();  SFace_handle f1 = this->new_sface();  SFace_handle f2 = this->new_sface();  link_as_loop(l1,f1);  link_as_loop(l2,f2);}template <typename Map>void SM_overlayer<Map>::subdivide(const Map* M0, const Map* M1){  PI[0] = SM_const_decorator(M0);   PI[1] = SM_const_decorator(M1);  Seg_list L;  Seg_map  From;  for (int i=0; i<2; ++i) {    SVertex_const_iterator v;    CGAL_forall_svertices(v,PI[i]) {      CGAL_NEF_TRACEN(v->point() << " from " << i << " mark " << v->mark());      if ( !PI[i].is_isolated(v) ) continue;      L.push_back(trivial_segment(PI[i],v));      From[--L.end()] = Seg_info(v,i);    }    SHalfedge_const_iterator e;    CGAL_forall_sedges(e,PI[i]) {      if ( source(e) == target(e) ) {        Seg_pair p = two_segments(PI[i],e);        L.push_back(p.first);         L.push_back(p.second);        From[--L.end()] = From[--(--L.end())] = Seg_info(e,i);      } else {        L.push_back(segment(PI[i],e));        From[--L.end()] = Seg_info(e,i);      }    }    if ( PI[i].has_shalfloop() ) {      SHalfloop_const_handle shl = PI[i].shalfloop();      Seg_pair p = two_segments(PI[i],shl);      L.push_back(p.first);       L.push_back(p.second);      From[--L.end()] = From[--(--L.end())] =         Seg_info(shl,i);    }  }  CGAL_assertion_code(typename Seg_list::iterator it);  CGAL_assertion_code(CGAL_forall_iterators(it,L) CGAL_NEF_TRACEN("  "<<*it));  bool compute_halfsphere[3][2];#ifdef CGAL_NEF3_SPHERE_SWEEP_OPTIMIZATION_OFF  int cs = -1;  compute_halfsphere[2][0]=true;  compute_halfsphere[2][1]=true;#else  int cs = check_sphere(L, compute_halfsphere);#endif  CGAL_NEF_TRACEN("compute_halfsphere\n  cs = " << cs);  for(int i=0; i<6; ++i)    CGAL_NEF_TRACEN("  " << i << " : " << compute_halfsphere[i/2][i%2]);  Seg_list L_pos,L_neg;  switch(cs) {  case 1:     partition_to_halfsphere(L.begin(), L.end(), L_pos, From, 			    Sphere_circle(1,0,0), Sphere_circle(0,0,-1),			    compute_halfsphere[0][1]);    break;  case 0:    partition_to_halfsphere(L.begin(), L.end(), L_neg, From, 			    Sphere_circle(-1,0,0), Sphere_circle(0,0,-1),			    compute_halfsphere[0][0]);    break;  case 3:     partition_to_halfsphere(L.begin(), L.end(), L_pos, From, 			    Sphere_circle(0,1,0), Sphere_circle(1,0,0),			    compute_halfsphere[1][1]);    break;  case 2:    partition_to_halfsphere(L.begin(), L.end(), L_neg, From, 			    Sphere_circle(0,-1,0), Sphere_circle(1,0,0), 			    compute_halfsphere[1][0]);    break;  case 5:     partition_to_halfsphere(L.begin(), L.end(), L_pos, From, 			    Sphere_circle(0,0,1), Sphere_circle(1,0,0),			    compute_halfsphere[2][1]);    break;  case 4:    partition_to_halfsphere(L.begin(), L.end(), L_neg, From, 			    Sphere_circle(0,0,-1), Sphere_circle(1,0,0), 			    compute_halfsphere[2][0]);    break;  case -1:    partition_to_halfsphere(L.begin(), L.end(), L_pos, From, 			    Sphere_circle(0,0,1), Sphere_circle(1,0,0), true);    partition_to_halfsphere(L.begin(), L.end(), L_neg, From, 			    Sphere_circle(0,0,-1), Sphere_circle(1,0,0), true);    break;  default: CGAL_assertion_msg(0, "wrong value");  }  cs = cs==-1 ? 2 : cs/2;#ifdef CGAL_NEF3_TIMER_SPHERE_SWEEPS  timer_sphere_sweeps.start();#endif  typedef SMO_from_sm<Self,Seg_iterator,Seg_info> SM_output;  typedef typename Sphere_kernel::Positive_halfsphere_geometry PH_geometry;  typedef typename Sphere_kernel::Negative_halfsphere_geometry NH_geometry;    typedef CGAL::Segment_overlay_traits<     Seg_iterator, SM_output, PH_geometry>  PHS_traits;  typedef CGAL::generic_sweep<PHS_traits> Positive_halfsphere_sweep;      typedef CGAL::Segment_overlay_traits<     Seg_iterator, SM_output, NH_geometry> NHS_traits;  typedef CGAL::generic_sweep<NHS_traits> Negative_halfsphere_sweep;  typedef typename PHS_traits::INPUT Input_range;  SVertex_handle v;  SHalfedge_handle e;  SM_output O(*this,PI,From);   if(compute_halfsphere[cs][0]) {    Positive_halfsphere_sweep SP(	Input_range(L_pos.begin(),L_pos.end()),O,	PH_geometry(cs));    SP.sweep();    v=--this->svertices_end(); e=--this->shalfedges_end();#ifdef CGAL_NEF3_TIMER_SPHERE_SWEEPS    number_of_sphere_sweeps++;#endif  }    if(compute_halfsphere[cs][1]) {    Negative_halfsphere_sweep SM(        Input_range(L_neg.begin(),L_neg.end()),O,        NH_geometry(cs));    SM.sweep();#ifdef CGAL_NEF3_TIMER_SPHERE_SWEEPS    number_of_sphere_sweeps++;#endif  }#ifdef CGAL_NEF3_TIMER_SPHERE_SWEEPS  timer_sphere_sweeps.stop();#endif  if(compute_halfsphere[cs][0]) {    ++v;     ++e;  }  else {    v = this->svertices_begin();     e = this->shalfedges_begin();  }    if(compute_halfsphere[cs][0])    create_face_objects(this->shalfedges_begin(), e, this->svertices_begin(), v, O,                        PH_geometry(cs));  if(compute_halfsphere[cs][1])    create_face_objects(e, this->shalfedges_end(), v, this->svertices_end(), O,			NH_geometry(cs));  SHalfedge_iterator u;  CGAL_forall_shalfedges(u,*this) {    Sphere_segment s(point(source(u)),point(target(u)));    circle(u) = s.sphere_circle();     circle(twin(u)) = s.sphere_circle().opposite();    CGAL_NEF_TRACEN(PH(u) << " with circle " << circle(u));  }  std::vector<Mark> mohs(4);  SM_point_locator L0(M0);  SM_point_locator L1(M1);    L0.marks_of_halfspheres(mohs, 0, cs);  L1.marks_of_halfspheres(mohs, 2, cs);    CGAL_NEF_TRACEN("compute_halfsphrere\n  cs = " << cs << 	 "\n  [cs][0] = " << compute_halfsphere[cs][0] <<	 "\n  [cs][1] = " << compute_halfsphere[cs][1]);  if(compute_halfsphere[cs][0])    complete_face_support(this->svertices_begin(), v, O, mohs, 0, 			  compute_halfsphere[cs][1]);  if(compute_halfsphere[cs][1])    complete_face_support(v, this->svertices_end(), O, mohs, 1,			  compute_halfsphere[cs][0]);  // DEBUG CODE: to do: have all svertices a halfedge below associated?  CGAL_NEF_TRACEN("Vertex info after swep");  CGAL_assertion_code(SVertex_iterator svi);  CGAL_assertion_code(    for(svi=this->svertices_begin(); svi!=this->svertices_end(); svi++) {      CGAL_NEF_TRACEN("vertex "<<point(svi)<<" info "<<info(svi)<<	     " marks "<<mark(svi,0)<<" "<<mark(svi,1));    }  )  if(compute_halfsphere[cs][0] && compute_halfsphere[cs][1])    merge_halfsphere_maps(this->svertices_begin(),v,O);  else    set_outer_face_mark(compute_halfsphere[cs][1], mohs);    this->check_integrity_and_topological_planarity();  CGAL_NEF_TRACEN("subdivided");  CGAL_assertion_code(CGAL_forall_svertices(v,*this) CGAL_NEF_TRACEN(PH(v)));}template <typename Map>void SM_overlayer<Map>::set_outer_face_mark(int offset, const std::vector<Mark>& mohs) {  SFace_handle sf = this->new_sface();  mark(sf, 0) = mohs[offset];  mark(sf, 1) = mohs[offset+2];  SHalfedge_iterator e;  CGAL_forall_shalfedges(e, *this) {    if ( face(e) != SFace_handle() ) continue;    link_as_face_cycle(e,sf);   }    SVertex_handle v;  CGAL_forall_svertices(v, *this) {    if(!is_isolated(v) || face(v) != SFace_handle()) continue;    link_as_isolated_vertex(v,sf);  }}template <typename Map>template <typename Iterator, typename T>void SM_overlayer<Map>::partition_to_halfsphere(Iterator start, Iterator beyond, Seg_list& L, 			CGAL::Unique_hash_map<Iterator,T>& M, 			Sphere_circle xycircle, Sphere_circle yzcircle, 			bool include_equator) const{ CGAL_NEF_TRACEN("partition_to_halfsphere ");//  CGAL_assertion(pos!=0);  Sphere_segment s1,s2;  //  Sphere_circle xycircle(0,0,pos);  if(include_equator) {    while ( start != beyond) {      int i = start->intersection(xycircle,s1,s2);      CGAL_NEF_TRACEN("segment " << start->source() << " " << start->target());      if (i>1) { 	L.push_back(s2); M[--L.end()] = M[start];    	CGAL_NEF_TRACEN(">1 " << s2.source() << " " << s2.target());       }      if (i>0) { 	L.push_back(s1); M[--L.end()] = M[start];    	CGAL_NEF_TRACEN(">0 " << s1.source() << " " << s1.target());       }      ++start;    }  }  else {    while(start != beyond) {      L.push_back(*start);      M[--L.end()] = M[start];      ++start;    }  }  // now all segments are split into hemispheres  // we still have to:  // - split segments containing our special poles y^-, y^+  // - split halfcircles  // - add four equator segments   //  Sphere_circle yzcircle(1,0,0);  typename Seg_list::iterator it, itl;    CGAL_forall_iterators(it,L) { CGAL_NEF_TRACEN("  "<<*it);    if ( equal_as_sets(it->sphere_circle(),xycircle) ) {      CGAL_NEF_TRACEN("  splitting xy seg "<<*it);      bool added=false;      int n1 =  it->intersection(yzcircle,s1,s2);      if (n1 > 1 && !s2.is_degenerate()) { 	M[ L.insert(it,s2) ] = M[it]; 	added=true; 	CGAL_NEF_TRACEN(">1 " << s2.source() << " " << s2.target());       }      if (n1 > 0 && !s1.is_degenerate()) { 	M[ L.insert(it,s1) ] = M[it]; 	added = true; 	CGAL_NEF_TRACEN(">1 " << s1.source() << " " << s1.target());       }      int n2 =  it->intersection(yzcircle.opposite(),s1,s2);      if (n2 > 1 && !s2.is_degenerate()) { 	M[ L.insert(it,s2) ] = M[it]; 	added=true; 	CGAL_NEF_TRACEN(">1 " << s2.source() << " " << s2.target());       }      if (n2 > 0 && !s1.is_degenerate()) { 	M[ L.insert(it,s1) ] = M[it]; 	added=true; 	CGAL_NEF_TRACEN(">1 " << s1.source() << " " << s1.target());       }      if(added) {	itl = it; --it; L.erase(itl); M[itl] = T();      }      // at least one item was appended    }  }  CGAL_forall_iterators(it,L) {    if ( it->is_halfcircle() ) {      CGAL_NEF_TRACEN("  splitting halfcircle "<<*it);      Sphere_segment s1,s2;      it->split_halfcircle(s1,s2);      *it = s2;       M[ L.insert(it,s1) ] = M[it];    }  }  if(include_equator) {    // append 4 xy-equator segments:    Sphere_point S(0,-1,0),N(0,1,0);    Sphere_segment sp(S,N,xycircle);    Sphere_segment sm(S,N,xycircle.opposite());    Sphere_segment s[4];    sp.split_halfcircle(s[0],s[1]);    sm.split_halfcircle(s[2],s[3]);    L.insert(L.end(),s,s+4);  }}template <typename Map>

⌨️ 快捷键说明

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