/*===========================================================================*\ * * * 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 OFFLoader singleton with MeshLoader _OFFWriter_ __OFFWriterInstance; _OFFWriter_& OFFWriter() { return __OFFWriterInstance; } //=== IMPLEMENTATION ========================================================== _OFFWriter_::_OFFWriter_() { IOManager().register_module(this); } //----------------------------------------------------------------------------- bool _OFFWriter_:: 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) ) // not supported by format return false; // 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() << "[OFFWriter] : cannot open file " << _filename << std::endl; return false; } // write header line if (_opt.check(Options::VertexTexCoord)) out << "ST"; if (_opt.check(Options::VertexColor) || _opt.check(Options::FaceColor)) out << "C"; if (_opt.check(Options::VertexNormal)) out << "N"; out << "OFF"; if (_opt.check(Options::Binary)) out << " BINARY"; out << "\n"; // 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 _OFFWriter_:: write_ascii(std::fstream& _out, BaseExporter& _be, Options _opt) const { omlog() << "[OFFWriter] : write ascii file\n"; unsigned int i, j, nV, nF; Vec3f v, n; Vec2f t; OpenMesh::Vec3i c; OpenMesh::Vec4i cA; VertexHandle vh; std::vector vhandles; // #vertices, #faces _out << _be.n_vertices() << " "; _out << _be.n_faces() << " "; _out << 0 << "\n"; // vertex data (point, normals, colors, texcoords) for (i=0, nV=_be.n_vertices(); i vhandles; // #vertices, #faces writeValue(_out, (uint)_be.n_vertices() ); writeValue(_out, (uint) _be.n_faces() ); writeValue(_out, 0 ); // vertex data (point, normals, texcoords) for (i=0, nV=_be.n_vertices(); i vhandles; for (i=0, nF=_be.n_faces(); i