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

📄 sm_io_parser.h

📁 很多二维 三维几何计算算法 C++ 类库
💻 H
📖 第 1 页 / 共 2 页
字号:
// Copyright (c) 1997-2002  Max-Planck-Institute Saarbruecken (Germany).// All rights reserved.//// This file is part of CGAL (www.cgal.org); you may redistribute it under// the terms of the Q Public License version 1.0.// See the file LICENSE.QPL distributed with CGAL.//// Licensees holding a valid commercial license may use this file in// accordance with the commercial license agreement provided with the software.//// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.//// $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/CGAL-3.3-branch/Nef_S2/include/CGAL/Nef_S2/SM_io_parser.h $// $Id: SM_io_parser.h 36990 2007-03-10 12:49:21Z spion $// //// Author(s)     : Michael Seel  <seel@mpi-sb.mpg.de>//                 Peter Hachenberger <hachenberger@mpi-sb.mpg.de>#ifndef CGAL_SM_IO_PARSER_H#define CGAL_SM_IO_PARSER_H#include <CGAL/Nef_S2/SM_decorator.h>#include <CGAL/Nef_2/Object_index.h>#include <CGAL/Nef_S2/SM_decorator_traits.h>#include <vector>#include <iostream>#if defined(BOOST_MSVC)#  pragma warning(push)#  pragma warning(disable:4355) // complaint about using 'this' to#endif                          // initialize a memberCGAL_BEGIN_NAMESPACE/*{\Moptions outfile=SM_io_parser.man }*//*{\Manpage {SM_io_parser}{Decorator_}{IO of embedded maps}{IO}}*//*{\Mdefinition An instance |\Mvar| of the data type |\Mname| is adecorator to provide input and output of a embedded map.  |\Mtype| isgeneric with respect to the |Decorator_| parameter.  |Decorator_| hasto be a decorator model of our |SM_decorator| concept.}*//*{\Mgeneralization SM_decorator}*/template <typename Decorator_>class SM_io_parser : public Decorator_{  typedef Decorator_                         Base;  typedef typename Decorator_::Sphere_point  Sphere_point;  typedef typename Decorator_::Sphere_circle Sphere_circle;  typedef typename Decorator_::Mark          Mark;  typedef typename Decorator_::Decorator_traits  Decorator_traits;  typedef typename Decorator_traits::SVertex_iterator     SVertex_iterator;  typedef typename Decorator_traits::SHalfedge_iterator   SHalfedge_iterator;  typedef typename Decorator_traits::SFace_iterator       SFace_iterator;  typedef typename Decorator_traits::SVertex_handle             SVertex_handle;  typedef typename Decorator_traits::SVertex_const_handle       SVertex_const_handle;  typedef typename Decorator_traits::SHalfedge_handle           SHalfedge_handle;  typedef typename Decorator_traits::SHalfedge_const_handle     SHalfedge_const_handle;  typedef typename Decorator_traits::SFace_const_handle         SFace_const_handle;  typedef typename Decorator_traits::SFace_handle               SFace_handle;  typedef typename Decorator_traits::SHalfloop_handle           SHalfloop_handle;  typedef typename Decorator_traits::SHalfloop_const_handle     SHalfloop_const_handle;  typedef typename Decorator_traits::SFace_cycle_iterator SFace_cycle_iterator;  typedef typename Decorator_traits::SHalfedge_around_svertex_circulator                                     SHalfedge_around_svertex_circulator;  std::istream& in; std::ostream& out;  bool verbose;  // a reference to the IO object  CGAL::Object_index<SVertex_const_handle>   VI;  CGAL::Object_index<SHalfedge_const_handle> EI;  CGAL::Object_index<SFace_const_handle>     FI;  std::vector<SVertex_handle>        SVertex_of;  std::vector<SHalfedge_handle>      Edge_of;  std::vector<SFace_handle>          SFace_of;  SHalfloop_handle                   Loop_of[2];  // object mapping for input  int vn,en,ln,fn,i;  // the number of objects  bool check_sep(const char* sep);  void print_vertex(SVertex_handle) const;  void print_edge(SHalfedge_handle) const;  void print_loop(SHalfloop_const_handle) const;  void print_face(SFace_handle) const;  bool read_vertex(SVertex_handle);  bool read_edge(SHalfedge_handle);  bool read_loop(SHalfloop_handle);  bool read_face(SFace_handle);  void debug_vertex(SVertex_handle) const;  void debug_edge(SHalfedge_handle) const;  void debug_loop(SHalfloop_const_handle) const;public:/*{\Mcreation 3}*/SM_io_parser(std::istream& is, const Base& D);/*{\Mcreate creates an instance |\Mvar| of type |\Mname|to input |H| from |is|.}*/SM_io_parser(std::ostream& os, const Base& D);/*{\Mcreate creates an instance |\Mvar| of type |\Mname|to output |H| to |os|.}*//*{\Moperations 2 3}*/void print() const;/*{\Mop prints |H| to |os|.}*/void read();/*{\Mop reads |H| from |is|.}*/void debug() const;void print_faces() const;std::string index(SVertex_const_handle v) const { return VI(v,verbose); }std::string index(SHalfedge_const_handle e) const { return EI(e,verbose); }std::string index(SHalfloop_const_handle l) const { if (verbose)  return (l==this->shalfloop()? "l0" : "l1");  else return (l==this->shalfloop()? "0" : "1");}std::string index(SFace_const_handle f) const { return FI(f,verbose); }static void dump(const Decorator_& D, std::ostream& os = std::cerr);/*{\Mstatic prints the plane map decorated by |D| to |os|.}*/}; // SM_io_parser<Decorator_>template <typename Decorator_>SM_io_parser<Decorator_>::SM_io_parser(std::istream& iin, const Base& H) :  Base(H), in(iin), out(std::cout), verbose(0),   vn(0), en(0), fn(0), ln(0){ this->clear(); }template <typename Decorator_>SM_io_parser<Decorator_>::SM_io_parser(std::ostream& iout, const Base& D)   : Base(D), in(std::cin), out(iout),   VI(this->svertices_begin(),this->svertices_end(),'v'),  EI(this->shalfedges_begin(),this->shalfedges_end(),'e'),  FI(this->sfaces_begin(),this->sfaces_end(),'f'),  vn(this->number_of_svertices()),   en(this->number_of_shalfedges()),   ln(this->number_of_shalfloops()),  fn(this->number_of_sfaces()){ verbose = (out.iword(CGAL::IO::mode) != CGAL::IO::ASCII &&             out.iword(CGAL::IO::mode) != CGAL::IO::BINARY);}//-----------------------------------------------------------------------------// OUTPUT AND INPUT://-----------------------------------------------------------------------------template <typename Decorator_>bool SM_io_parser<Decorator_>::check_sep(const char* sep){  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 Decorator_>void SM_io_parser<Decorator_>::print_vertex(SVertex_handle v) const{  // syntax: index { isolated incident_object, mark, point }  out << index(v) << " { ";  if ( is_isolated(v) ) out << "1 " << index(v->incident_sface());  else                  out << "0 " << index(first_out_edge(v));  out  << ", " << v->mark() << ", " << v->point() <<  "}\n";}template <typename Decorator_>bool SM_io_parser<Decorator_>::read_vertex(SVertex_handle v){   // precondition: nodes exist  // syntax: index { isolated incident_object, mark, point}  int n; bool iso; int f; Mark m; Sphere_point p;   if ( !(in >> n) ||       !check_sep("{") ||       !(in >> iso) ||       !(in >> f) ||       !check_sep(",") ||       !(in >> m) ||       !check_sep(",") ||       !(in >> p) ||       !check_sep("}") ) return false;   if (iso) set_face(v,SFace_of[f]);  else     set_first_out_edge(v,Edge_of[f]);  mark(v) = m; point(v) = p;  return true; }template <typename Decorator_>void SM_io_parser<Decorator_>::print_edge(SHalfedge_handle e) const{ // syntax: index { twin, prev, next, source, face, mark, circle }  Decorator_ D;  out << index(e) << " { "      << index(e->twin()) << ", "       << index(e->sprev()) << ", " << index(e->snext()) << ", "      << index(e->source()) << ", " << index(e->incident_sface()) << ", "      << e->mark() << ", " << e->circle() << " }\n";}template <typename Decorator_>bool SM_io_parser<Decorator_>::read_edge(SHalfedge_handle e){ // syntax: index { twin, prev, next, source, face, mark, circle }  int n, eo, epr, ene, v, f; bool m; Sphere_circle k;  if ( !(in >> n) ||       !check_sep("{") ||       !(in >> eo) || !check_sep(",") ||       !(in >> epr) || !check_sep(",") ||       !(in >> ene) || !check_sep(",") ||       !(in >> v) || !check_sep(",") ||       !(in >> f) || !check_sep(",") ||       !(in >> m) || !check_sep(",") ||       !(in >> k) || !check_sep("}") )    return false;  CGAL_assertion_msg      (eo >= 0 && eo < en && epr >= 0 && epr < en && ene >= 0 && ene < en &&      v >= 0 && v < vn && f >= 0 && f < fn ,      "wrong index in read_edge");    // precond: features exist!  CGAL_assertion(EI[e->twin()]);

⌨️ 快捷键说明

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