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

📄 snc_io_parser.h

📁 很多二维 三维几何计算算法 C++ 类库
💻 H
📖 第 1 页 / 共 5 页
字号:
template <typename EW>bool SNC_io_parser<EW>::check_sep(const char* sep) const{  char c;   do in.get(c); while (isspace(c));  while (*sep != '\0') {     if (*sep != c) {      in.putback(c);      return false;    }    ++sep; in.get(c);  }  in.putback(c);  return true;  }template <typename EW>bool SNC_io_parser<EW>::test_string(std::string s) const {  std::string s2;  in >> s2;  return (s==s2);}template <typename EW>void SNC_io_parser<EW>::print() const{   out << "Selective Nef Complex" << std::endl;  if(this->is_extended_kernel() && (!reduce || !this->is_bounded()))    out << "extended" << std::endl;  else    out << "standard" << std::endl;  out << "vertices   " << VL.size() << std::endl;  out << "halfedges  " << EL.size() << std::endl;  out << "facets     " << FL.size() << std::endl;  out << "volumes    " << CL.size() << std::endl;  out << "shalfedges " << SEL.size() << std::endl;  out << "shalfloops " << SLL.size() << std::endl;  out << "sfaces     " << SFL.size() << std::endl;  if (verbose)     out << "/* Vertex: index { svs sve ses see sfs sfe sl,"        << " mark, point } */\n";  typename std::list<Vertex_iterator>::const_iterator v;  for(v=VL.begin();v!=VL.end();v++)    print_vertex(*v);  if (verbose)   out << "/* Edge: index { twin, source, isolated incident_object,"      << " mark } */\n";  typename std::list<Halfedge_iterator>::const_iterator e;  for(e=EL.begin();e!=EL.end();e++)    print_edge(*e);  if (verbose)   out << "/* Facet: index { twin, fclist, ivlist, volume | plane } mark */\n";  typename std::list<Halffacet_iterator>::const_iterator f;  for(f=FL.begin();f!=FL.end();f++)    print_facet(*f);  if (verbose)   out << "/* Volume: index { shlist } mark  */\n";  typename std::list<Volume_iterator>::const_iterator c;  for(c=CL.begin();c!=CL.end();c++)    print_volume(*c);  if (verbose)   out << "/* SEdge: index { twin, sprev, snext, source, sface,"      << " prev, next, facet } */\n";  typename std::list<SHalfedge_iterator>::const_iterator se;  for(se=SEL.begin();se!=SEL.end();se++)    print_sedge(*se);  if (verbose)   out << "/* SLoop: index { twin, sface, facet } */" << std::endl;  typename std::list<SHalfloop_iterator>::const_iterator sl;  for(sl=SLL.begin();sl!=SLL.end();sl++)    print_sloop(*sl);  if (verbose)   out << "/* SFace: index { fclist, ivlist, sloop, volume } */" << std::endl;  typename std::list<SFace_iterator>::const_iterator sf;  for(sf=SFL.begin();sf!=SFL.end();sf++)    print_sface(*sf);  out << "/* end Selective Nef complex */" << std::endl;}template <typename EW>void SNC_io_parser<EW>::read(){   if ( !check_sep("Selective Nef Complex") )      CGAL_assertion_msg(0,"SNC_io_parser::read: no SNC header.");  std::string kernel_type;  in >> kernel_type;  CGAL_assertion(kernel_type == "standard" || kernel_type == "extended");  if ( !(check_sep("vertices") && (in >> vn)) )     CGAL_assertion_msg(0,"SNC_io_parser::read: wrong vertex line.");  if ( !(check_sep("halfedges") && (in >> en) && (en%2==0)) )    CGAL_assertion_msg(0,"SNC_io_parser::read: wrong edge line.");  if ( !(check_sep("facets") && (in >> fn) && (fn%2==0)) )    CGAL_assertion_msg(0,"SNC_io_parser::read: wrong facet line.");  if ( !(check_sep("volumes") && (in >> cn)) )    CGAL_assertion_msg(0,"SNC_io_parser::read: wrong volume line.");  if ( !(check_sep("shalfedges") && (in >> sen)) )    CGAL_assertion_msg(0,"SNC_io_parser::read: wrong sedge line.");  if ( !(check_sep("shalfloops") && (in >> sln)) )    CGAL_assertion_msg(0,"SNC_io_parser::read: wrong sloop line.");  if ( !(check_sep("sfaces") && (in >> sfn)) )    CGAL_assertion_msg(0,"SNC_io_parser::read: wrong sface line.");  addInfiBox = (kernel_type == "standard" && Infi_box::extended_kernel());  for(i=0; i<vn; ++i)  Vertex_of.push_back(this->sncp()->new_vertex_only());  for(i=0; i<en; ++i)  Edge_of.push_back(this->sncp()->new_halfedge_only());  for(i=0; i<fn; ++i)  Halffacet_of.push_back(this->sncp()->new_halffacet_only());  for(i=0; i<cn; ++i)  Volume_of.push_back(this->sncp()->new_volume_only());  for(i=0; i<sen; ++i) SEdge_of.push_back(this->sncp()->new_shalfedge_only());  for(i=0; i<sln; ++i) SLoop_of.push_back(this->sncp()->new_shalfloop_only());  for(i=0; i<sfn; ++i) SFace_of.push_back(this->sncp()->new_sface_only());  if(addInfiBox) {    Volume_of.push_back(this->sncp()->new_volume_only());    read_items<Standard_kernel>(1);    add_infi_box();  } else    read_items<Kernel>(0);}template <typename EW>template <typename K>void SNC_io_parser<EW>::read_items(int plus01) {  typename std::vector<Vertex_iterator>::iterator vi;  for(vi=Vertex_of.begin(); vi!=Vertex_of.end(); ++vi) {    if (!read_vertex<K>(*vi))      CGAL_assertion_msg(0,"SNC_io_parser::read: error in node line");  }  typename std::vector<Halfedge_iterator>::iterator ei;  for(ei=Edge_of.begin(); ei!=Edge_of.end(); ++ei) {    if (!read_edge<K>(*ei))      CGAL_assertion_msg(0,"SNC_io_parser::read: error in edge line");  }  typename std::vector<Halffacet_iterator>::iterator fi;  for(fi=Halffacet_of.begin(); fi!=Halffacet_of.end(); ++fi) {    if (!read_facet<K>(*fi))      CGAL_assertion_msg(0,"SNC_io_parser::read: error in facet line");  }  typename std::vector<Volume_iterator>::iterator ci;  for(ci=Volume_of.begin()+plus01; ci!=Volume_of.end(); ++ci) {    if (!read_volume(*ci))      CGAL_assertion_msg(0,"SNC_io_parser::read: error in volume line");  }  typename std::vector<SHalfedge_iterator>::iterator sei;  for(sei=SEdge_of.begin(); sei!=SEdge_of.end(); ++sei) {    if (!read_sedge<K>(*sei))      CGAL_assertion_msg(0,"SNC_io_parser::read: error in sedge line");  }  typename std::vector<SHalfloop_iterator>::iterator sli;  for(sli=SLoop_of.begin(); sli!=SLoop_of.end(); ++sli) {    if (!read_sloop<K>(*sli))      CGAL_assertion_msg(0,"SNC_io_parser::read: error in sloop line");  }  typename std::vector<SFace_iterator>::iterator sfi;  for(sfi=SFace_of.begin(); sfi!=SFace_of.end(); ++sfi) {    if (!read_sface(*sfi))      CGAL_assertion_msg(0,"SNC_io_parser::read: error in sface line");  }  SNC_constructor C(*this->sncp());  C.assign_indices(); }template <typename EW>void SNC_io_parser<EW>::print_vertex(Vertex_handle v) const{ // syntax: index { svs sve, ses see, sfs sfe, sl | point } mark  SM_decorator SD(&*v);  out << index(v) << " { ";  if(sorted) {        output_sorted_indexes(v->svertices_begin(), 			  v->svertices_end(), EI);    output_sorted_indexes(v->shalfedges_begin(), 			  v->shalfedges_end(), SEI);    output_sorted_indexes(v->sfaces_begin(), 			  v->sfaces_end(), SFI);    out << index(SD.shalfloop()) << " | ";  }  else {    out     << index(v->svertices_begin()) << " "    << index(v->svertices_last()) << ", "    << index(v->shalfedges_begin()) << " "    << index(v->shalfedges_last()) << ", "    << index(v->sfaces_begin()) << " "    << index(v->sfaces_last()) << ", "    << index(SD.shalfloop()) << " | ";  }  if(reduce) {    Standard_point p(Infi_box::standard_point(v->point()));    out << p.hx() << " " << p.hy() << " " << p.hz() << " " << p.hw();  }  else    Geometry_io<typename Kernel::Kernel_tag, Kernel>::print_point(out, v->point());  out << " } "  << v->mark() << std::endl;}template <typename EW>template <typename K>bool SNC_io_parser<EW>::read_vertex(Vertex_handle vh) {  bool OK = true;  int index;  typename K::RT hx, hy, hz, hw;  in >> index;  OK = OK && test_string("{");  vh->sncp() = this->sncp();    in >> index;  vh->svertices_begin() = (index >= 0 ? Edge_of[index] : this->svertices_end());  in >> index;  vh->svertices_last()  = index >= 0 ? Edge_of[index] : this->svertices_end();  OK = OK && test_string(",");  in >> index;  vh->shalfedges_begin() = index >= 0 ? SEdge_of[index] : this->shalfedges_end();  in >> index;  vh->shalfedges_last()  = index >= 0 ? SEdge_of[index] : this->shalfedges_end();  OK = OK && test_string(",");  in >> index;  vh->sfaces_begin() = index >= 0 ? SFace_of[index] : this->sfaces_end();  in >> index;  vh->sfaces_last()  = index >= 0 ? SFace_of[index] : this->sfaces_end();  OK = OK && test_string(",");  in >> index;  vh->shalfloop() = index >= 0 ? SLoop_of[index] : this->shalfloops_end();  OK = OK && test_string("|");  //  in >> hx >> hy >> hz >> hw;  //  vh->point() = Point_3(hx,hy,hz,hw);  vh->point() =     Geometry_io<typename K::Kernel_tag, Kernel>::template read_point<Kernel, K>(in);  OK = OK && test_string("}");  in >> vh->mark();    return OK;}template <typename EW>void SNC_io_parser<EW>::print_edge(Halfedge_handle e) const{ // syntax: index { twin, source, isolated incident_object | spoint } mark  SM_decorator D(&*e->source());  out << index(e) << " { " << index(e->twin()) << ", "      << index(e->source()) << ", ";  if ( D.is_isolated(e) ) out << "1 " << index(e->incident_sface());  else out << "0 " << index(e->out_sedge());  out << " | ";  if(reduce) {    Standard_vector p(Infi_box::standard_vector(e->vector()));    out << p.hx() << " " << p.hy() << " " << p.hz() << " " << p.hw();  }  else    Geometry_io<typename Kernel::Kernel_tag, Kernel>::print_point(out, (Point_3) e->point());  out << " } "<< e->mark() << std::endl;}template <typename EW>template <typename K>bool SNC_io_parser<EW>::read_edge(Halfedge_handle eh) {  bool OK = true;  int index;  typename K::RT hx,hy,hz,hw;    in >> index;  OK = OK && test_string("{");    in >> index;  eh->twin() = Edge_of[index];  OK = OK && test_string(",");  in >> index;  eh->center_vertex() = Vertex_of[index];  OK = OK && test_string(",");  in >> index;  if(index == 0) {    in >> index;    eh->out_sedge() = SEdge_of[index];  } else {     in >> index;    eh->incident_sface() = SFace_of[index];  }  OK = OK && test_string("|");  //    in >> hx >> hy >> hz >> hw;  //    eh->point() = Sphere_point(hx,hy,hz);  eh->point() =     Geometry_io<typename K::Kernel_tag, Kernel>::template read_point<Kernel,K>(in);  OK = OK && test_string("}");  in >> eh->mark();  return OK;}template <typename EW>void SNC_io_parser<EW>::print_facet(Halffacet_handle f) const{ // syntax: index { twin, fclist, ivlist, volume | plane } mark  out << index(f) << " { ";   out << index(f->twin()) << ", ";  Halffacet_cycle_iterator it;   CGAL_forall_facet_cycles_of(it,f)    if ( it.is_shalfedge() ) out << index(SHalfedge_handle(it)) << ' ';  out << ", ";  CGAL_forall_facet_cycles_of(it,f)    if ( it.is_shalfloop() ) out << index(SHalfloop_handle(it)) << ' ';  out << ", " << index(f->incident_volume()) << " | ";  if(reduce) {    Standard_plane p(Infi_box::standard_plane(f->plane()));    out << p.a() << " " << p.b() << " " << p.c() << " " << p.d();  }  else    Geometry_io<typename Kernel::Kernel_tag, Kernel>::print_plane(out, f->plane());  out << " } " << f->mark() << std::endl;}template <typename EW>template <typename K>bool SNC_io_parser<EW>::read_facet(Halffacet_handle fh) {  bool OK = true;  int index;  char cc;  typename K::RT a,b,c,d;  in >> index;  OK = OK && test_string("{");    in >> index;  fh->twin() = Halffacet_of[index];  OK = OK && test_string(",");    in >> cc;  while(isdigit(cc)) {    in.putback(cc);    in >> index;    fh->boundary_entry_objects().push_back(SEdge_of[index]);    in >> cc;  }    in >> cc;  while(isdigit(cc)) {    in.putback(cc);    in >> index;    fh->boundary_entry_objects().push_back(SLoop_of[index]);    in >> cc;  }    in >> index;  fh->incident_volume() = Volume_of[index+addInfiBox];  OK = OK && test_string("|");  //  in >> a >> b >> c >> d;  //  fh->plane() = Plane_3(a,b,c,d);  fh->plane() =     Geometry_io<typename K::Kernel_tag, Kernel>::    template read_plane<Kernel, K>(in);  OK = OK && test_string("}");  in >> fh->mark();  return OK;}template <typename EW>void SNC_io_parser<EW>::print_volume(Volume_handle c) const{ // syntax: index { shlist } mark  out << index(c) << " { ";   Shell_entry_iterator it;  CGAL_forall_shells_of(it,c)     if(!reduce || Infi_box::is_standard(SFace_handle(it)->center_vertex()->point()))      out << index(SFace_handle(it)) << ' ';  out << "} " << c->mark() << std::endl;}template <typename EW>bool SNC_io_parser<EW>::read_volume(Volume_handle ch) {  bool OK = true;  int index;  char cc;    in >> index;  OK = OK && test_string("{");

⌨️ 快捷键说明

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