BWAPI
|
00001 // Copyright (c) 1997 Utrecht University (The Netherlands), 00002 // ETH Zurich (Switzerland), Freie Universitaet Berlin (Germany), 00003 // INRIA Sophia-Antipolis (France), Martin-Luther-University Halle-Wittenberg 00004 // (Germany), Max-Planck-Institute Saarbruecken (Germany), RISC Linz (Austria), 00005 // and Tel-Aviv University (Israel). All rights reserved. 00006 // 00007 // This file is part of CGAL (www.cgal.org); you can redistribute it and/or 00008 // modify it under the terms of the GNU Lesser General Public License as 00009 // published by the Free Software Foundation; version 2.1 of the License. 00010 // See the file LICENSE.LGPL distributed with CGAL. 00011 // 00012 // Licensees holding a valid commercial license may use this file in 00013 // accordance with the commercial license agreement provided with the software. 00014 // 00015 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 00016 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00017 // 00018 // $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/CGAL-3.5-branch/Stream_support/include/CGAL/IO/File_writer_OFF.h $ 00019 // $Id: File_writer_OFF.h 35787 2007-01-24 17:16:05Z spion $ 00020 // 00021 // 00022 // Author(s) : Lutz Kettner <kettner@mpi-sb.mpg.de> 00023 00024 #ifndef CGAL_IO_FILE_WRITER_OFF_H 00025 #define CGAL_IO_FILE_WRITER_OFF_H 1 00026 00027 #include <CGAL/IO/binary_file_io.h> 00028 #include <CGAL/IO/File_header_OFF.h> 00029 #include <iostream> 00030 #include <cstddef> 00031 00032 CGAL_BEGIN_NAMESPACE 00033 00034 class File_writer_OFF { 00035 std::ostream* m_out; 00036 File_header_OFF m_header; 00037 public: 00038 File_writer_OFF( bool verbose = false) : m_header( verbose) {} 00039 File_writer_OFF( const File_header_OFF& h) : m_header( h) {} 00040 00041 std::ostream& out() { return *m_out; } 00042 File_header_OFF& header() { return m_header; } 00043 const File_header_OFF& header() const { return m_header; } 00044 00045 void write_header( std::ostream& out, 00046 std::size_t vertices, 00047 std::size_t halfedges, 00048 std::size_t facets, 00049 bool normals = false); 00050 void write_footer() { 00051 if ( m_header.ascii() && m_header.comments()) 00052 out() << "\n\n# End of OFF #"; 00053 out() << std::endl; 00054 } 00055 void write_vertex( const double& x, const double& y, const double& z) { 00056 if ( m_header.binary()) { 00057 I_Binary_write_big_endian_float32( out(), float(x)); 00058 I_Binary_write_big_endian_float32( out(), float(y)); 00059 I_Binary_write_big_endian_float32( out(), float(z)); 00060 } else { 00061 out() << '\n' << x << ' ' << y << ' ' << z; 00062 } 00063 } 00064 void write_normal( const double& x, const double& y, const double& z) { 00065 if ( m_header.binary()) { 00066 I_Binary_write_big_endian_float32( out(), float(x)); 00067 I_Binary_write_big_endian_float32( out(), float(y)); 00068 I_Binary_write_big_endian_float32( out(), float(z)); 00069 } else { 00070 out() << ' ' << ' ' << x << ' ' << y << ' ' << z; 00071 } 00072 } 00073 void write_facet_header() { 00074 if ( m_header.ascii()) { 00075 if ( m_header.no_comments()) 00076 out() << '\n'; 00077 else { 00078 out() << "\n\n# " << m_header.size_of_facets() 00079 << " facets\n"; 00080 out() << "# ------------------------------------------" 00081 "\n\n"; 00082 } 00083 } 00084 } 00085 void write_facet_begin( std::size_t no) { 00086 if ( m_header.binary()) 00087 I_Binary_write_big_endian_integer32( out(), no); 00088 else 00089 out() << no << ' '; 00090 } 00091 void write_facet_vertex_index( std::size_t index) { 00092 if ( m_header.binary()) 00093 I_Binary_write_big_endian_integer32( out(), index); 00094 else 00095 out() << ' ' << index; 00096 } 00097 void write_facet_end() { 00098 if ( m_header.binary()) 00099 I_Binary_write_big_endian_integer32( out(), 0); 00100 else 00101 out() << '\n'; 00102 } 00103 }; 00104 00105 CGAL_END_NAMESPACE 00106 #endif // CGAL_IO_FILE_WRITER_OFF_H // 00107 // EOF //