/*===========================================================================*\ * * * OpenMesh * * Copyright (C) 2003 by Computer Graphics Group, RWTH Aachen * * www.openmesh.org * * * *---------------------------------------------------------------------------* * * * License * * * * This library is free software; you can redistribute it and/or modify it * * under the terms of the GNU Lesser General Public License as published * * by the Free Software Foundation, version 2.1. * * * * This library is distributed in the hope that it will be useful, but * * WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the Free Software * * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * * \*===========================================================================*/ //== INCLUDES ================================================================= #include #include #include #include #include #include #include //=== NAMESPACES ============================================================== namespace OpenMesh { namespace IO { //=== INSTANCIATE ============================================================= // register the PLYLoader singleton with MeshLoader _PLYWriter_ __PLYWriterInstance; _PLYWriter_& PLYWriter() { return __PLYWriterInstance; } //=== IMPLEMENTATION ========================================================== _PLYWriter_::_PLYWriter_() { IOManager().register_module(this); } //----------------------------------------------------------------------------- bool _PLYWriter_:: write(const std::string& _filename, BaseExporter& _be, Options _opt) const { // check exporter features if ( !check( _be, _opt ) ) return false; // check writer features if ( _opt.check(Options::FaceNormal) || _opt.check(Options::FaceColor) ) // not supported yet return false; options_ = _opt; // open file std::fstream out(_filename.c_str(), (_opt.check(Options::Binary) ? std::ios_base::binary | std::ios_base::out : std::ios_base::out) ); if (!out) { omerr() << "[PLYWriter] : cannot open file " << _filename << std::endl; return false; } // write to file bool result = (_opt.check(Options::Binary) ? write_binary(out, _be, _opt) : write_ascii(out, _be, _opt)); // return result out.close(); return result; } //----------------------------------------------------------------------------- bool _PLYWriter_:: write_ascii(std::fstream& _out, BaseExporter& _be, Options _opt) const { omlog() << "[PLYWriter] : write ascii file\n"; unsigned int i, j, nV, nF; Vec3f v, n; Vec2f t; OpenMesh::Vec3f c; OpenMesh::Vec4f cA; VertexHandle vh; std::vector vhandles; //writing header _out << "ply" << std::endl; _out << "format ascii 1.0" << std::endl; _out << "element vertex " << _be.n_vertices() << std::endl; _out << "property float32 x" << std::endl; _out << "property float32 y" << std::endl; _out << "property float32 z" << std::endl; if ( _opt.vertex_has_color() ){ _out << "property int32 red" << std::endl; _out << "property int32 green" << std::endl; _out << "property int32 blue" << std::endl; if ( _opt.color_has_alpha() ) _out << "property int32 alpha" << std::endl; } _out << "element face " << _be.n_faces() << std::endl; _out << "property list uint8 int32 vertex_indices" << std::endl; _out << "end_header" << std::endl; // vertex data (point, normals, colors, texcoords) for (i=0, nV=_be.n_vertices(); i vhandles; //writing header _out << "ply" << std::endl; _out << "format "; if ( options_.check(Options::MSB) ) _out << "binary_big_endian "; else _out << "binary_little_endian "; _out << "1.0" << std::endl; _out << "element vertex " << _be.n_vertices() << std::endl; _out << "property float32 x" << std::endl; _out << "property float32 y" << std::endl; _out << "property float32 z" << std::endl; if ( _opt.vertex_has_color() ){ _out << "property int32 red" << std::endl; _out << "property int32 green" << std::endl; _out << "property int32 blue" << std::endl; if ( _opt.color_has_alpha() ) _out << "property int32 alpha" << std::endl; } _out << "element face " << _be.n_faces() << std::endl; _out << "property list uchar int32 vertex_indices" << std::endl; _out << "end_header" << std::endl; // vertex data (point, normals, texcoords) for (i=0, nV=_be.n_vertices(); i vhandles; for (i=0, nF=_be.n_faces(); i