sm_io_parser.h

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

H
468
字号
// 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.//// $Source: /CVSROOT/CGAL/Packages/Nef_S2/include/CGAL/Nef_S2/SM_io_parser.h,v $// $Revision: 1.11.4.1 $ $Date: 2004/12/06 12:51:15 $// $Name:  $//// Author(s)     : Michael Seel  <seel@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>CGAL_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::SHalfedge_handle     SHalfedge_handle;  typedef typename Decorator_traits::SFace_handle         SFace_handle;  typedef typename Decorator_traits::SHalfloop_handle     SHalfloop_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_handle>   VI;  CGAL::Object_index<SHalfedge_handle> EI;  CGAL::Object_index<SFace_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(char* sep);  void print_vertex(SVertex_handle) const;  void print_edge(SHalfedge_handle) const;  void print_loop(SHalfloop_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_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_handle v) const { return VI(v,verbose); }std::string index(SHalfedge_handle e) const { return EI(e,verbose); }std::string index(SHalfloop_handle l) const { if (verbose)  return (l==this->shalfloop()? "l0" : "l1");  else return (l==this->shalfloop()? "0" : "1");}std::string index(SFace_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(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(face(v));  else                  out << "0 " << index(first_out_edge(v));  out  << ", " << mark(v) << ", " << point(v) <<  "}\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 }  out << index(e) << " { "      << index(twin(e)) << ", "       << index(previous(e)) << ", " << index(next(e)) << ", "      << index(source(e)) << ", " << index(face(e)) << ", "      << mark(e) << ", " << circle(e) << " }\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[twin(e)]);  set_prev(e,Edge_of[epr]);  set_next(e,Edge_of[ene]);  set_source(e,SVertex_of[v]);

⌨️ 快捷键说明

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