sm_overlayer.h
来自「CGAL is a collaborative effort of severa」· C头文件 代码 · 共 1,638 行 · 第 1/4 页
H
1,638 行
struct edge_info { Mark m[2]; Mark mf[2]; Object_handle o_supp[2]; bool forw; edge_info() { m[0]=m[1]=mf[0]=mf[1]=Mark(); o_supp[0]=o_supp[1]=Object_handle(); forw=false; } LEDA_MEMORY(edge_info) }; void assoc_info(SHalfedge_handle e) const { geninfo<edge_info>::create(info(e)); geninfo<edge_info>::create(info(twin(e))); } void discard_info(SHalfedge_handle e) const { geninfo<edge_info>::clear(info(e)); geninfo<edge_info>::clear(info(twin(e))); } edge_info& ginfo(SHalfedge_handle e) const { return geninfo<edge_info>::access(info(e)); } Mark& mark(SHalfedge_handle e, int i) const { return ginfo(e).m[i]; } Object_handle& supp_object(SHalfedge_handle e, int i) const // uedge information we store in the smaller one { if (&*e < &*(twin(e))) return ginfo(e).o_supp[i]; else return ginfo(twin(e)).o_supp[i]; } Mark& incident_mark(SHalfedge_handle e, int i) const // biedge information we store in the edge { return ginfo(e).mf[i]; } bool& is_forward(SHalfedge_handle e) const // biedge information we store in the edge { return ginfo(e).forw; } // --------------------------------------------------------------- struct face_info { Mark m[2]; face_info() { m[0]=m[1]=Mark(); } LEDA_MEMORY(face_info) }; void assoc_info(SFace_handle f) const { geninfo<face_info>::create(info(f)); } void discard_info(SFace_handle f) const { geninfo<face_info>::clear(info(f)); } face_info& ginfo(SFace_handle f) const { return geninfo<face_info>::access(info(f)); } Mark& mark(SFace_handle f, int i) const { return ginfo(f).m[i]; } // --------------------------------------------------------------- template <typename Below_accessor> SFace_handle determine_face(SHalfedge_handle e, const std::vector<SHalfedge_handle>& MinimalSHalfedge, const CGAL::Unique_hash_map<SHalfedge_handle,int>& SFaceCycle, const Below_accessor& D) { CGAL_NEF_TRACEN("determine_face "<<PH(e)); int fc = SFaceCycle[e]; SHalfedge_handle e_min = MinimalSHalfedge[fc]; SHalfedge_handle e_below = D.halfedge_below(target(e_min)); if(e_below == SHalfedge_handle()) return SFace_handle(); SFace_handle f = face(e_below); if ( f != SFace_handle() ) return f; // has already a face // e_below also has no face f = determine_face(e_below, MinimalSHalfedge, SFaceCycle,D); if(f != SFace_handle()) link_as_face_cycle(e_below,f); return f; } Sphere_segment segment(SM_const_decorator N, SHalfedge_const_handle e) const { return K.construct_segment( N.point(N.source(e)),N.point(N.target(e)),N.circle(e)); } Sphere_segment trivial_segment(SM_const_decorator N, SVertex_const_handle v) const { Sphere_point p = N.point(v); return K.construct_segment(p,p); } Seg_pair two_segments(SM_const_decorator N, SHalfedge_const_handle e) const // we know that source(e)==target(e) { return N.circle(e).split_at(N.point(N.source(e))); } Seg_pair two_segments(SM_const_decorator N, SHalfloop_const_handle l) const { return N.circle(l).split_at_xy_plane(); } Mark& mark(SVertex_handle h) const { return Base::mark(h); } Mark& mark(SHalfedge_handle h) const { return Base::mark(h); } Mark& mark(SHalfloop_handle h) const { return Base::mark(h); } Mark& mark(SFace_handle h) const { return Base::mark(h); } // --------------------------------------------------------------- // INTERFACE INTERFACE INTERFACE INTERFACE INTERFACE INTERFACE // --------------------------------------------------------------- /*{\Mcreation 6}*/ SM_overlayer(Map* M, const Sphere_kernel& G = Sphere_kernel()) : Base(M), K(G) {} /*{\Mcreate |\Mvar| is a decorator object manipulating the map of |v|.}*/ /*{\Moperations 1.1 1}*/ template <typename Forward_iterator> void create_from_segments( Forward_iterator start, Forward_iterator end); /*{\Mop produces the sphere map which is the overlay of the segments from the iterator range |[start,end)|. \precond |Forward_iterator| has value type |Sphere_segment|.}*/ template <typename Forward_iterator> void create_from_circles(Forward_iterator start, Forward_iterator end); /*{\Mop produces the sphere map which is the overlay of the circles from the iterator range |[start,end)|. \precond |Forward_iterator| has value type |Sphere_circle|.}*/ void create(const Sphere_circle& c); /*{\Mop produces the sphere map which consists of one loop and the two halfspheres incident to it.}*/ void subdivide(const Map* M0, const Map* M1); /*{\Mop constructs the overlay of the sphere maps |M0| and |M1| in |M|, where all objects (vertices, halfedges, faces) of |M| are \emph{enriched} by the marks of the supporting objects of the two input structures: e.g. let |v| be a vertex supported by a node |v0| in |M0| and by a face |f1| in |M1| and |D0|, |D1| be decorators of type |SM_decorator| on |M0|,|M1|. Then |\Mvar.mark(v,0) = D0.mark(v0)| and |\Mvar.mark(v,1) = D1.mark(f1)|.}*/ template <typename Selection> void select(const Selection& SP) const; /*{\Mop sets the marks of all objects according to the selection predicate |SP|. |Selection| has to be a function object type with a function operator\\ [[Mark operator()(Mark m0, Mark m1) const]]\\ For each object |u| of |M| enriched by the marks of the supporting objects according to the previous procedure |subdivide|, after this operation |\Mvar.mark(u) = SP ( \Mvar.mark(u,0),\Mvar.mark(u,1) )|. The additional marks are invalidated afterwards. \precond subdivide() was called before.}*/ void simplify(); /*{\Mop simplifies the structure of |M| according to the marks of its objects. An edge |e| separating two faces |f1| and |f2| and equal marks |mark(e) == mark(f1) == mark(f2)| is removed and the faces are unified. An isolated vertex |v| in a face |f| with |mark(v)==mark(f)| is removed. A vertex |v| with outdegree two, two collinear out-edges |e1|,|e2| and equal marks |mark(v) == mark(e1) == mark(e2)| is removed and the edges are unified.}*/ int check_sphere(const Seg_list& L, bool compute_halfsphere[3][2]) const; template <typename Iterator> void subdivide_segments(Iterator start, Iterator end) const; template <typename Iterator, typename T> void partition_to_halfsphere(Iterator start, Iterator end, Seg_list& L, CGAL::Unique_hash_map<Iterator,T>& M, Sphere_circle xycircle, Sphere_circle yzcircle, bool include_equator) const; template <typename Mark_accessor> void merge_halfsphere_maps(SVertex_handle v1, SVertex_handle v2, const Mark_accessor& D); template <typename Mark_accessor> void merge_nodes(SHalfedge_handle e1, SHalfedge_handle e2, const Mark_accessor& D); template <typename Below_accessor, typename Halfsphere_geometry> void 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); template <typename Below_accessor> void complete_face_support(SVertex_iterator v_start, SVertex_iterator v_end, const Below_accessor& D, std::vector<Mark>& mohs, int offset, bool both=true) const; void set_outer_face_mark(int offset, const std::vector<Mark>& mohs); void dump(std::ostream& os = std::cerr) const { SM_io_parser<Base>::dump(*this,os); }}; // SM_overlayer<SM_decorator>template <typename Map>template <typename Forward_iterator>void SM_overlayer<Map>::create_from_segments(Forward_iterator start, Forward_iterator end){ CGAL_NEF_TRACEN("creating from segment iterator range"); Seg_list L(start,end); Unique_hash_map<Seg_iterator,bool> From_input(false); Seg_iterator it; CGAL_forall_iterators(it,L) From_input[it]=true; Seg_list L_pos,L_neg; partition_to_halfsphere(L.begin(), L.end(), L_pos, From_input, Sphere_circle(0,0,1), Sphere_circle(1,0,0), true); partition_to_halfsphere(L.begin(), L.end(), L_neg, From_input, Sphere_circle(0,0,-1), Sphere_circle(1,0,0), true); //CGAL_NEF_TRACEN("L_pos="<<(MSDEBUG::print_elements(L_pos),"")); //CGAL_NEF_TRACEN("L_neg="<<(MSDEBUG::print_elements(L_neg),"")); typedef SMO_from_segs<Self,Seg_iterator> SM_output; typedef typename Sphere_kernel::Positive_halfsphere_geometry PH_geometry; typedef CGAL::Segment_overlay_traits< Seg_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< Seg_iterator, SM_output, NH_geometry> NHS_traits; typedef CGAL::generic_sweep<NHS_traits> Negative_halfsphere_sweep; SVertex_iterator v; SHalfedge_iterator e; SM_output O(*this,From_input); typedef typename PHS_traits::INPUT Input_range; Positive_halfsphere_sweep SP( Input_range(L_pos.begin(),L_pos.end()),O, PH_geometry()); SP.sweep(); //CGAL_NEF_TRACEN("POS SWEEP\n"<<(dump(std::cerr),"")); v=--this->svertices_end(); e=--this->shalfedges_end(); Negative_halfsphere_sweep SM( Input_range(L_neg.begin(),L_neg.end()),O, NH_geometry()); SM.sweep(); //CGAL_NEF_TRACEN("NEG SWEEP\n"<<(dump(std::cerr),"")); ++v; ++e; // now two CCs of sphere graph are calculated // v = first vertex of CC in negative x-sphere // e = first edge of CC in negative x-sphere create_face_objects(this->shalfedges_begin(), e, this->svertices_begin(), v, O, PH_geometry()); create_face_objects(e, this->shalfedges_end(), v, this->svertices_end(), O, NH_geometry()); SHalfedge_iterator u; CGAL_forall_sedges(u,*this) { Sphere_segment s(point(source(u)),point(target(u))); circle(u) = s.sphere_circle(); circle(twin(u)) = s.sphere_circle().opposite(); } merge_halfsphere_maps(this->svertices_begin(),v,O); this->check_integrity_and_topological_planarity(); O.clear_temporary_vertex_info();}template <typename Map>template <typename Forward_iterator>void SM_overlayer<Map>::create_from_circles(Forward_iterator start, Forward_iterator end){ CGAL_NEF_TRACEN("creating from circle iterator range"); Seg_list L; Unique_hash_map<Seg_iterator,bool> From_input(false); for ( ; start != end; ++start ) { std::pair<Sphere_segment,Sphere_segment> spair = start->split_at_xy_plane(); L.push_back(spair.first); L.push_back(spair.second); } Seg_iterator it; CGAL_forall_iterators(it,L) From_input[it]=true; Seg_list L_pos,L_neg; partition_to_halfsphere(L.begin(), L.end(), L_pos, From_input, Sphere_circle(0,0,1), Sphere_circle(1,0,0), true); partition_to_halfsphere(L.begin(), L.end(), L_neg, From_input, Sphere_circle(0,0,-1), Sphere_circle(1,0,0), true); typedef SMO_from_segs<Self,Seg_iterator> SM_output; typedef typename Sphere_kernel::Positive_halfsphere_geometry PH_geometry; typedef CGAL::Segment_overlay_traits< Seg_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< Seg_iterator, SM_output, NH_geometry> NHS_traits; typedef CGAL::generic_sweep<NHS_traits> Negative_halfsphere_sweep; SVertex_iterator v; SHalfedge_iterator e; SM_output O(*this,From_input); typedef typename PHS_traits::INPUT Input_range; Positive_halfsphere_sweep SP( Input_range(L_pos.begin(),L_pos.end()),O, PH_geometry()); SP.sweep(); //CGAL_NEF_TRACEN("POS SWEEP\n"<<(dump(std::cerr),"")); v=--this->svertices_end(); e=--this->shalfedges_end(); Negative_halfsphere_sweep SM( Input_range(L_neg.begin(),L_neg.end()), O, NH_geometry()); SM.sweep(); //CGAL_NEF_TRACEN("NEG SWEEP\n"<<(dump(std::cerr),"")); ++v; ++e; // now two CCs of sphere graph are calculated // v = first vertex of CC in negative x-sphere // e = first edge of CC in negative x-sphere create_face_objects(this->shalfedges_begin(), e, this->svertices_begin(), v, O, PH_geometry()); create_face_objects(e, this->shalfedges_end(), v, this->svertices_end(), O, NH_geometry()); SHalfedge_iterator u; CGAL_forall_sedges(u,*this) { Sphere_segment s(point(source(u)),point(target(u))); circle(u) = s.sphere_circle(); circle(twin(u)) = s.sphere_circle().opposite(); } merge_halfsphere_maps(this->svertices_begin(),v,O); this->check_integrity_and_topological_planarity(); O.clear_temporary_vertex_info();}template <typename Map>int SM_overlayer<Map>::check_sphere(const Seg_list& L, bool compute_halfsphere[3][2]) const { for(int i=0; i<6; i++) compute_halfsphere[i/2][i%2] = false; CGAL_NEF_TRACEN("compute_halfsphere (at begin)"); for(int i=0; i<6; ++i) CGAL_NEF_TRACEN(" " << i << " : " << compute_halfsphere[i/2][i%2]); typename Seg_list::const_iterator it; CGAL_forall_iterators(it,L) { if(!compute_halfsphere[0][0]) if(it->source().hx()>0 || it->target().hx()>0) compute_halfsphere[0][0] = true; if(!compute_halfsphere[0][1]) if(it->source().hx()<0 || it->target().hx()<0) compute_halfsphere[0][1] = true; if(!compute_halfsphere[1][0]) if(it->source().hy()>0 || it->target().hy()>0) compute_halfsphere[1][0] = true; if(!compute_halfsphere[1][1]) if(it->source().hy()<0 || it->target().hy()<0) compute_halfsphere[1][1] = true; if(!compute_halfsphere[2][0]) if(it->source().hz()>0 || it->target().hz()>0) compute_halfsphere[2][0] = true; if(!compute_halfsphere[2][1]) if(it->source().hz()<0 || it->target().hz()<0) compute_halfsphere[2][1] = true; } CGAL_NEF_TRACEN("compute_halfsphere (after vertices)"); for(int i=0; i<6; ++i) CGAL_NEF_TRACEN(" " << i << " : " << compute_halfsphere[i/2][i%2]); if(!compute_halfsphere[2][0]) { CGAL_forall_iterators(it,L) { if(CGAL::orientation(it->source(),it->target(), Sphere_point(0,0,1), CGAL::ORIGIN+it->sphere_circle().orthogonal_vector()) == CGAL::NEGATIVE) if((it->source().hz()==0 && it->target().hz()==0) || it->is_long()) { compute_halfsphere[2][0] = true; break; } } } if(!compute_halfsphere[2][0]) { compute_halfsphere[2][1] = true; return 4; } if(!compute_halfsphere[2][1]) { CGAL_forall_iterators(it,L) { if(CGAL::orientation(it->source(),it->target(), Sphere_point(0,0,-1), CGAL::ORIGIN+it->sphere_circle().orthogonal_vector()) == CGAL::NEGATIVE) if((it->source().hz()==0 && it->target().hz()==0) || it->is_long()) { compute_halfsphere[2][1] = true; break; } } }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?