⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 snc_io_parser.h

📁 很多二维 三维几何计算算法 C++ 类库
💻 H
📖 第 1 页 / 共 5 页
字号:
    out << p;  }  };template <typename SNC_structure_>class SNC_io_parser : public SNC_decorator<SNC_structure_>{ typedef SNC_structure_ SNC_structure;  typedef CGAL::SNC_io_parser<SNC_structure_> Self;  typedef CGAL::SNC_decorator<SNC_structure_> Base;  typedef typename Base::SNC_constructor SNC_constructor;  typedef typename SNC_structure::Sphere_map  Sphere_map;  typedef CGAL::SM_decorator<Sphere_map>      SM_decorator;  typedef typename SNC_structure::Infi_box    Infi_box;  typedef typename Infi_box::Standard_kernel  Standard_kernel;public:  typedef typename SNC_structure::Vertex_iterator Vertex_iterator;   typedef typename SNC_structure::Vertex_handle Vertex_handle;  typedef typename SNC_structure::Halfedge_iterator Halfedge_iterator;   typedef typename SNC_structure::Halfedge_handle Halfedge_handle;  typedef typename SNC_structure::Halffacet_iterator Halffacet_iterator;   typedef typename SNC_structure::Halffacet_handle Halffacet_handle;  typedef typename SNC_structure::Volume_iterator Volume_iterator;   typedef typename SNC_structure::Volume_handle Volume_handle;  typedef typename SNC_structure::SVertex_iterator SVertex_iterator;   typedef typename SNC_structure::SVertex_handle SVertex_handle;  typedef typename SNC_structure::SHalfedge_iterator SHalfedge_iterator;   typedef typename SNC_structure::SHalfedge_handle SHalfedge_handle;  typedef typename SNC_structure::SFace_iterator SFace_iterator;   typedef typename SNC_structure::SFace_handle SFace_handle;  typedef typename SNC_structure::SHalfloop_iterator SHalfloop_iterator;   typedef typename SNC_structure::SHalfloop_handle SHalfloop_handle;  typedef typename SNC_structure::Object_iterator Object_iterator;   typedef typename SNC_structure::Object_handle Object_handle;  typedef typename SNC_structure::SFace_cycle_iterator SFace_cycle_iterator;  typedef typename SNC_structure::Halffacet_cycle_iterator Halffacet_cycle_iterator;  typedef typename SNC_structure::Shell_entry_iterator Shell_entry_iterator;  typedef typename SNC_structure::SHalfedge_around_svertex_circulator                                   SHalfedge_around_svertex_circulator;  typedef typename SNC_structure::SHalfedge_around_sface_circulator                                   SHalfedge_around_sface_circulator;  typedef typename SNC_structure::SHalfedge_around_facet_circulator                                   SHalfedge_around_facet_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;  typedef typename SNC_structure::Sphere_point Sphere_point;  typedef typename SNC_structure::Sphere_segment Sphere_segment;  typedef typename SNC_structure::Sphere_circle Sphere_circle;  typedef typename SNC_structure::Mark Mark;  typedef typename SNC_structure::Kernel Kernel;  typedef typename Kernel::RT RT;  typedef typename Infi_box::Standard_point  Standard_point;  typedef typename Infi_box::Standard_vector Standard_vector;  typedef typename Infi_box::Standard_plane  Standard_plane;  typedef void* GenPtr; private:  std::istream& in; std::ostream& out;  bool verbose;  bool reduce;  bool sorted;  bool addInfiBox;  CGAL::Object_index<Vertex_iterator> VI;    CGAL::Object_index<Halfedge_iterator> EI;  CGAL::Object_index<Halffacet_iterator>    FI;  CGAL::Object_index<Volume_iterator>   CI;  CGAL::Object_index<SHalfedge_iterator> SEI;  CGAL::Object_index<SHalfloop_iterator>   SLI;  CGAL::Object_index<SFace_iterator>     SFI;  std::list<Vertex_iterator> VL;  std::list<Halfedge_iterator> EL;  std::list<Halffacet_iterator> FL;  std::list<Volume_iterator> CL;  std::list<SHalfedge_iterator> SEL;  std::list<SHalfloop_iterator> SLL;  std::list<SFace_iterator> SFL;  std::vector<Vertex_iterator>   Vertex_of;  std::vector<Halfedge_iterator> Edge_of;  std::vector<Halffacet_iterator>    Halffacet_of;  std::vector<Volume_iterator>   Volume_of;  std::vector<SVertex_iterator>  SVertex_of;   std::vector<SHalfedge_iterator> SEdge_of;  std::vector<SHalfloop_iterator> SLoop_of;  std::vector<SFace_iterator>     SFace_of;  long i,vn,en,fn,cn,sen,sln,sfn;public:  SNC_io_parser(std::istream& is, SNC_structure& W);  SNC_io_parser(std::ostream& os, SNC_structure& W, 		bool sort=false, bool reduce_ = false);  std::string index(Vertex_iterator v) const  { return VI(v,verbose); }   std::string index(Halfedge_iterator e) const   { return EI(e,verbose); }  std::string index(Halffacet_iterator f) const   { return FI(f,verbose); }  std::string index(Volume_iterator c) const   { return CI(c,verbose); }  std::string index(SHalfedge_iterator e) const   { return SEI(e,verbose); }  std::string index(SHalfloop_iterator l) const   { return SLI(l,verbose); }  std::string index(SFace_iterator f) const   { return SFI(f,verbose); }  std::string index(Object_iterator o) const  { if( o == 0 )      return this->string("undef");    Vertex_iterator v;    Halfedge_iterator e;    Halffacet_iterator f;    Volume_iterator c;    SHalfedge_iterator se;    SHalfloop_iterator sl;    SFace_iterator sf;    if( CGAL::assign( v, *o))      return index(v);    else if( CGAL::assign( e, *o))      return index(e);    else if( CGAL::assign( f, *o))      return index(f);    else if( CGAL::assign( c, *o))      return index(c);    else if( CGAL::assign( se, *o))      return index(se);    else if( CGAL::assign( sl, *o))      return index(sl);    else if( CGAL::assign( sf, *o))      return index(sf);    return this->string("unknown object");  }  bool check_sep(const char* sep) const;  bool test_string(std::string s) const;  void print_vertex(Vertex_handle) const;  void print_edge(Halfedge_handle) const;  void print_facet(Halffacet_handle) const;  void print_volume(Volume_handle) const;  void print_sedge(SHalfedge_handle) const;  void print_sloop(SHalfloop_handle) const;  void print_sface(SFace_handle) const;  void print() const;  void print_local_graph(Vertex_handle) const;  template <typename NT> bool read_vertex(Vertex_handle);  template <typename NT> bool read_edge(Halfedge_handle);  template <typename NT> bool read_facet(Halffacet_handle);  bool read_volume(Volume_handle);  template <typename NT> bool read_svertex(SVertex_handle);  template <typename NT> bool read_sedge(SHalfedge_handle);  template <typename NT> bool read_sloop(SHalfloop_handle);  bool read_sface(SFace_handle);  void add_infi_box();  void read();  template <typename K> void read_items(int);  static void dump(SNC_structure& W, std::ostream& os = std::cerr, bool sort = false)  { Self O(os,W, sort); O.print(); }  template <typename Iter, typename Index>    void output_sorted_indexes(Iter begin, Iter end, Index i) const {    int low = i[begin];    int high = low;    for(Iter it=begin; it != end; it++) {      if(i[it] < low) low = i[it];      if(i[it] > high) high = i[it];    }    out << low << " " << high << ", ";  }};template <typename EW>SNC_io_parser<EW>::SNC_io_parser(std::istream& is, SNC_structure& W) :   Base(W), in(is), out(std::cout) {   W.clear();  CGAL_assertion(W.is_empty());  verbose = false; }template <typename EW>SNC_io_parser<EW>::SNC_io_parser(std::ostream& os, SNC_structure& W, 				 bool sort, bool reduce_) :   Base(W), in(std::cin), out(os),  FI(W.halffacets_begin(),W.halffacets_end(),'F'),  CI(W.volumes_begin(),W.volumes_end(),'C'),  SEI(W.shalfedges_begin(),W.shalfedges_end(),'e'),  SLI(W.shalfloops_begin(),W.shalfloops_end(),'l'),  SFI(W.sfaces_begin(),W.sfaces_end(),'f'),  vn(W.number_of_vertices()),   en(W.number_of_halfedges()),   fn(W.number_of_halffacets()),  cn(W.number_of_volumes()),  sen(W.number_of_shalfedges()),  sln(W.number_of_shalfloops()),  sfn(W.number_of_sfaces()){   verbose = (out.iword(CGAL::IO::mode) != CGAL::IO::ASCII &&             out.iword(CGAL::IO::mode) != CGAL::IO::BINARY);    sorted = sort;  reduce = reduce_;  reduce = reduce && this->is_extended_kernel() && this->is_bounded();  sorted = sorted || reduce;  Vertex_iterator vi;   CGAL_forall_vertices(vi, *this->sncp()) {    VL.push_back(vi);    if(sorted) {      vi->point() = normalized(vi->point());      if(vi->has_shalfloop() && 	 sort_sloops<SNC_structure>(*this->sncp())(vi->shalfloop()->twin(),						   vi->shalfloop()))	vi->shalfloop() = vi->shalfloop()->twin();    }  }  if(sorted) {    VL.sort(sort_vertices<SNC_structure>(*this->sncp()));  }    if(reduce)    for(int k=0; k<4; k++){      VL.pop_front(); VL.pop_back();    }  int i = 0;  typename std::list<Vertex_iterator>::iterator vl;  for(vl = VL.begin(); vl != VL.end(); vl++)    VI[*vl] = i++;    SM_decorator SD;  Halfedge_iterator ei;   CGAL_forall_halfedges(ei, *this->sncp()) {    EL.push_back(ei);    if(sorted) {      //      std::cerr << ei->point() << " | " << normalized(ei->point()) << " |";      ei->point() = normalized(ei->point());      //      std::cerr << ei->point() << std::endl;      sort_sedges<SNC_structure> sortSE(*this->sncp());      SHalfedge_handle new_outedge = ei->out_sedge();      SHalfedge_around_svertex_circulator cb(new_outedge), ce(cb);      CGAL_For_all(cb,ce) {	if(cb != new_outedge && sortSE(cb,new_outedge))	  new_outedge = cb;      }      ei->out_sedge() = new_outedge;    }  }  if(sorted) EL.sort(sort_edges<SNC_structure>(*this->sncp()));  if(reduce)    for(int k=0; k<12; k++){      EL.pop_front(); EL.pop_back();    }  i = 0;  typename std::list<Halfedge_iterator>::iterator el;  for(el = EL.begin(); el != EL.end(); el++)    EI[*el] = i++;  Halffacet_iterator fi;   CGAL_forall_halffacets(fi, *this->sncp()){    if(sorted) {      sort_sedges<SNC_structure> sortSE(*this->sncp());      Halffacet_cycle_iterator fc;      for(fc = fi->facet_cycles_begin(); 	  fc != fi->facet_cycles_end(); ++fc) {	if(fc.is_shalfedge()) {	  SHalfedge_handle se(fc);	  if(this->sncp()->is_boundary_object(se))	    this->sncp()->undef_boundary_item(se);	  SHalfedge_around_facet_circulator sfc(fc), send(sfc);	  CGAL_For_all(sfc, send) {	    if(sortSE(sfc, se))	      se = sfc;	  }	  this->sncp()->store_boundary_item(se,fc);	  *fc = se;	}      }      fi->plane() = normalized(fi->plane());      fi->boundary_entry_objects().sort(sort_facet_cycle_entries<Base>((Base) *this));    }    FL.push_back(fi);  }  if(sorted) FL.sort(sort_facets<SNC_structure>(*this->sncp()));  if(reduce) {    for(int k=0; k<6; k++){      FL.pop_front();      FL.pop_back();    }  }  i = 0;  typename std::list<Halffacet_iterator>::iterator fl;  for(fl = FL.begin(); fl != FL.end(); fl++)    FI[*fl] = i++;  SHalfedge_iterator sei;   CGAL_forall_shalfedges(sei, *this->sncp()) {    SEL.push_back(sei);    if(sorted)      sei->circle() = normalized(sei->circle());  }  if(sorted) SEL.sort(sort_sedges<SNC_structure>(*this->sncp()));  if(reduce)    for(int k=0; k<24; k++){      SEL.pop_front(); SEL.pop_back();    }  i = 0;  typename std::list<SHalfedge_iterator>::iterator sel;  for(sel = SEL.begin(); sel != SEL.end(); sel++)    SEI[*sel] = i++;  SHalfloop_iterator sli;   CGAL_forall_shalfloops(sli, *this->sncp()) {    SLL.push_back(sli);    if(sorted)      sli->circle() = normalized(sli->circle());  }  if(sorted) SLL.sort(sort_sloops<SNC_structure>(*this->sncp()));  i = 0;  typename std::list<SHalfloop_iterator>::iterator sll;  for(sll = SLL.begin(); sll != SLL.end(); sll++)    SLI[*sll] = i++;  SFace_iterator sfi;   CGAL_forall_sfaces(sfi, *this->sncp()) {    if(sorted) {      SFace_cycle_iterator fc;      CGAL_forall_sface_cycles_of(fc, sfi) {	if(fc.is_shalfedge()) {	  SHalfedge_handle se(fc);	  if(this->sncp()->is_sm_boundary_object(se))	    this->sncp()->undef_sm_boundary_item(se);	  SHalfedge_around_sface_circulator cb(se), ce(cb);	  CGAL_For_all(cb,ce) {	    if(cb->source() != se->source()) {	      if(lexicographically_xyz_smaller(cb->source()->twin()->source()->point(),					       se->source()->twin()->source()->point()))		se = cb;	    }	    else 	      if(lexicographically_xyz_smaller(cb->twin()->source()->twin()->source()->point(),					       se->twin()->source()->twin()->source()->point()))		se = cb;	  }	  this->sncp()->store_sm_boundary_item(se,fc);	  *fc = se;	}      }      sfi->boundary_entry_objects().sort(sort_sface_cycle_entries<Base>((Base) *this));    }    SFL.push_back(sfi);  }  if(sorted) SFL.sort(sort_sfaces<SNC_structure>(*this->sncp()));  if(reduce)    for(int k=0; k<8; k++){      SFL.pop_front(); SFL.pop_back();    }  i = 0;  typename std::list<SFace_iterator>::iterator sfl;  for(sfl = SFL.begin(); sfl != SFL.end(); sfl++)    SFI[*sfl] = i++;  Volume_iterator ci;   CGAL::Unique_hash_map<SFace_handle,bool> Done(false);  find_minimal_sface_of_shell<SNC_structure> findMinSF(*this->sncp(),Done);  CGAL_forall_volumes(ci, *this->sncp()) {    if(sorted) {      Shell_entry_iterator it;      CGAL_forall_shells_of(it,ci) {	findMinSF.minimal_sface() = SFace_handle(it);	visit_shell_objects(SFace_handle(it),findMinSF);	*it = findMinSF.minimal_sface();      }      ci->shell_entry_objects().sort(sort_shell_entries<Base>((Base)*this));    }     CL.push_back(ci);  }   if(sorted) CL.sort(sort_volumes<SNC_structure>(*this->sncp()));  if(reduce)    CL.pop_front();  i = 0;  typename std::list<Volume_iterator>::iterator cl;  for(cl = CL.begin(); cl != CL.end(); cl++)    CI[*cl] = i++;  VI[W.vertices_end()]=-2;  EI[W.halfedges_end()]=-2;  FI[W.halffacets_end()]=-2;  CI[W.volumes_end()]=-2;  SEI[W.shalfedges_end()]=-2;  SLI[W.shalfloops_end()]=-2;  SFI[W.sfaces_end()]=-2;}

⌨️ 快捷键说明

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