BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/IO/generic_print_polyhedron.h
Go to the documentation of this file.
00001 // Copyright (c) 1997  ETH Zurich (Switzerland).
00002 // All rights reserved.
00003 //
00004 // This file is part of CGAL (www.cgal.org); you may redistribute it under
00005 // the terms of the Q Public License version 1.0.
00006 // See the file LICENSE.QPL distributed with CGAL.
00007 //
00008 // Licensees holding a valid commercial license may use this file in
00009 // accordance with the commercial license agreement provided with the software.
00010 //
00011 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00012 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00013 //
00014 // $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/CGAL-3.5-branch/Polyhedron_IO/include/CGAL/IO/generic_print_polyhedron.h $
00015 // $Id: generic_print_polyhedron.h 28567 2006-02-16 14:30:13Z lsaboret $
00016 // 
00017 //
00018 // Author(s)     : Lutz Kettner  <kettner@mpi-sb.mpg.de>
00019 
00020 #ifndef CGAL_IO_GENERIC_PRINT_POLYHEDRON_H
00021 #define CGAL_IO_GENERIC_PRINT_POLYHEDRON_H 1
00022 
00023 #include <CGAL/basic.h>
00024 #include <CGAL/Inverse_index.h>
00025 #include <iostream>
00026 
00027 CGAL_BEGIN_NAMESPACE
00028 
00029 template <class Polyhedron, class Writer>
00030 void
00031 generic_print_polyhedron( std::ostream&     out, 
00032                           const Polyhedron& P,
00033                           Writer&           writer) {
00034     // writes P to `out' in the format provided by `writer'.
00035     typedef typename Polyhedron::Vertex                                 Vertex;
00036     typedef typename Polyhedron::Vertex_const_iterator                  VCI;
00037     typedef typename Polyhedron::Facet_const_iterator                   FCI;
00038     typedef typename Polyhedron::Halfedge_around_facet_const_circulator HFCC;
00039     // Print header.
00040     writer.write_header( out,
00041                          P.size_of_vertices(),
00042                          P.size_of_halfedges(),
00043                          P.size_of_facets());
00044     for( VCI vi = P.vertices_begin(); vi != P.vertices_end(); ++vi) {
00045         writer.write_vertex( ::CGAL::to_double( vi->point().x()),
00046                              ::CGAL::to_double( vi->point().y()),
00047                              ::CGAL::to_double( vi->point().z()));
00048     }
00049     typedef Inverse_index< VCI> Index;
00050     Index index( P.vertices_begin(), P.vertices_end());
00051     writer.write_facet_header();
00052 
00053     for( FCI fi = P.facets_begin(); fi != P.facets_end(); ++fi) {
00054         HFCC hc = fi->facet_begin();
00055         HFCC hc_end = hc;
00056         std::size_t n = circulator_size( hc);
00057         CGAL_assertion( n >= 3);
00058         writer.write_facet_begin( n);
00059         do {
00060             writer.write_facet_vertex_index( index[ VCI(hc->vertex())]);
00061             ++hc;
00062         } while( hc != hc_end);
00063         writer.write_facet_end();
00064     }
00065     writer.write_footer();
00066 }
00067 
00068 CGAL_END_NAMESPACE
00069 #endif // CGAL_IO_GENERIC_PRINT_POLYHEDRON_H //
00070 // EOF //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines