mirror of https://github.com/CGAL/cgal
79 lines
2.8 KiB
C++
79 lines
2.8 KiB
C++
// ============================================================================
|
|
//
|
|
// Copyright (c) 1997 The CGAL Consortium
|
|
//
|
|
// This software and related documentation is part of an INTERNAL release
|
|
// of the Computational Geometry Algorithms Library (CGAL). It is not
|
|
// intended for general use.
|
|
//
|
|
// ----------------------------------------------------------------------------
|
|
//
|
|
// release : $CGAL_Revision: $
|
|
// release_date : $CGAL_Date: $
|
|
//
|
|
// file : include/CGAL/IO/generic_print_polyhedron.h
|
|
// package : Polyhedron_IO 2.11 (04 Feb 2000)
|
|
// chapter : Support Library
|
|
//
|
|
// revision : $Revision$
|
|
// revision_date : $Date$
|
|
//
|
|
// author(s) : Lutz Kettner <kettner@mpi-sb.mpg.de>
|
|
// maintainer :
|
|
// coordinator : INRIA, Sophia Antipolis
|
|
//
|
|
// A generic writer for polyhedral surfaces parameterized by file format
|
|
// ============================================================================
|
|
|
|
#ifndef CGAL_IO_GENERIC_PRINT_POLYHEDRON_H
|
|
#define CGAL_IO_GENERIC_PRINT_POLYHEDRON_H 1
|
|
|
|
#include <CGAL/basic.h>
|
|
#include <CGAL/Inverse_index.h>
|
|
#include <iostream>
|
|
|
|
CGAL_BEGIN_NAMESPACE
|
|
|
|
template <class Polyhedron, class Writer>
|
|
void
|
|
generic_print_polyhedron( std::ostream& out,
|
|
const Polyhedron& P,
|
|
Writer& writer) {
|
|
// writes P to `out' in the format provided by `writer'.
|
|
typedef typename Polyhedron::Vertex Vertex;
|
|
typedef typename Polyhedron::Vertex_const_iterator VCI;
|
|
typedef typename Polyhedron::Facet_const_iterator FCI;
|
|
typedef typename Polyhedron::Halfedge_around_facet_const_circulator HFCC;
|
|
// Print header.
|
|
writer.write_header( out,
|
|
P.size_of_vertices(),
|
|
P.size_of_halfedges(),
|
|
P.size_of_facets());
|
|
for( VCI vi = P.vertices_begin(); vi != P.vertices_end(); ++vi) {
|
|
writer.write_vertex( ::CGAL::to_double( vi->point().x()),
|
|
::CGAL::to_double( vi->point().y()),
|
|
::CGAL::to_double( vi->point().z()));
|
|
}
|
|
typedef Inverse_index< VCI> Index;
|
|
Index index( P.vertices_begin(), P.vertices_end());
|
|
writer.write_facet_header();
|
|
|
|
for( FCI fi = P.facets_begin(); fi != P.facets_end(); ++fi) {
|
|
HFCC hc = fi->facet_begin();
|
|
HFCC hc_end = hc;
|
|
std::size_t n = circulator_size( hc);
|
|
CGAL_assertion( n >= 3);
|
|
writer.write_facet_begin( n);
|
|
do {
|
|
writer.write_facet_vertex_index( index[ VCI(hc->vertex())]);
|
|
++hc;
|
|
} while( hc != hc_end);
|
|
writer.write_facet_end();
|
|
}
|
|
writer.write_footer();
|
|
}
|
|
|
|
CGAL_END_NAMESPACE
|
|
#endif // CGAL_IO_GENERIC_PRINT_POLYHEDRON_H //
|
|
// EOF //
|