Commit fc7acde6 authored by Isaak Lim's avatar Isaak Lim
Browse files

- added precision option to openmesh writers

refs #1075

git-svn-id: http://www.openmesh.org/svnrepo/OpenMesh/trunk@746 fdac6126-5c0c-442c-9429-916003d36597
parent 1d6e590a
...@@ -99,12 +99,14 @@ public: ...@@ -99,12 +99,14 @@ public:
/// Write to file _filename. Data source specified by BaseExporter _be. /// Write to file _filename. Data source specified by BaseExporter _be.
virtual bool write(const std::string& _filename, virtual bool write(const std::string& _filename,
BaseExporter& _be, BaseExporter& _be,
Options _opt) const = 0; Options _opt,
std::streamsize _precision = 6) const = 0;
/// Write to std::ostream _os. Data source specified by BaseExporter _be. /// Write to std::ostream _os. Data source specified by BaseExporter _be.
virtual bool write(std::ostream& _os, virtual bool write(std::ostream& _os,
BaseExporter& _be, BaseExporter& _be,
Options _opt) const = 0; Options _opt,
std::streamsize _precision = 6) const = 0;
/// Returns expected size of file if binary format is supported else 0. /// Returns expected size of file if binary format is supported else 0.
virtual size_t binary_size(BaseExporter&, Options) const { return 0; } virtual size_t binary_size(BaseExporter&, Options) const { return 0; }
......
...@@ -4,10 +4,10 @@ ...@@ -4,10 +4,10 @@
* Copyright (C) 2001-2012 by Computer Graphics Group, RWTH Aachen * * Copyright (C) 2001-2012 by Computer Graphics Group, RWTH Aachen *
* www.openmesh.org * * www.openmesh.org *
* * * *
*---------------------------------------------------------------------------* *---------------------------------------------------------------------------*
* This file is part of OpenMesh. * * This file is part of OpenMesh. *
* * * *
* OpenMesh is free software: you can redistribute it and/or modify * * OpenMesh is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as * * it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 3 of * * published by the Free Software Foundation, either version 3 of *
* the License, or (at your option) any later version with the * * the License, or (at your option) any later version with the *
...@@ -30,10 +30,10 @@ ...@@ -30,10 +30,10 @@
* License along with OpenMesh. If not, * * License along with OpenMesh. If not, *
* see <http://www.gnu.org/licenses/>. * * see <http://www.gnu.org/licenses/>. *
* * * *
\*===========================================================================*/ \*===========================================================================*/
/*===========================================================================*\ /*===========================================================================*\
* * * *
* $Revision$ * * $Revision$ *
* $Date$ * * $Date$ *
* * * *
...@@ -80,7 +80,7 @@ _OBJWriter_::_OBJWriter_() { IOManager().register_module(this); } ...@@ -80,7 +80,7 @@ _OBJWriter_::_OBJWriter_() { IOManager().register_module(this); }
bool bool
_OBJWriter_:: _OBJWriter_::
write(const std::string& _filename, BaseExporter& _be, Options _opt) const write(const std::string& _filename, BaseExporter& _be, Options _opt, std::streamsize _precision) const
{ {
std::fstream out(_filename.c_str(), std::ios_base::out ); std::fstream out(_filename.c_str(), std::ios_base::out );
...@@ -91,6 +91,8 @@ write(const std::string& _filename, BaseExporter& _be, Options _opt) const ...@@ -91,6 +91,8 @@ write(const std::string& _filename, BaseExporter& _be, Options _opt) const
return false; return false;
} }
out.precision(_precision);
{ {
#if defined(WIN32) #if defined(WIN32)
std::string::size_type dot = _filename.find_last_of("\\/"); std::string::size_type dot = _filename.find_last_of("\\/");
...@@ -196,7 +198,7 @@ writeMaterial(std::ostream& _out, BaseExporter& _be, Options _opt) const ...@@ -196,7 +198,7 @@ writeMaterial(std::ostream& _out, BaseExporter& _be, Options _opt) const
bool bool
_OBJWriter_:: _OBJWriter_::
write(std::ostream& _out, BaseExporter& _be, Options _opt) const write(std::ostream& _out, BaseExporter& _be, Options _opt, std::streamsize _precision) const
{ {
unsigned int i, j, nV, nF, idx; unsigned int i, j, nV, nF, idx;
Vec3f v, n; Vec3f v, n;
...@@ -209,6 +211,7 @@ write(std::ostream& _out, BaseExporter& _be, Options _opt) const ...@@ -209,6 +211,7 @@ write(std::ostream& _out, BaseExporter& _be, Options _opt) const
omlog() << "[OBJWriter] : write file\n"; omlog() << "[OBJWriter] : write file\n";
_out.precision(_precision);
// check exporter features // check exporter features
if (!check( _be, _opt)) if (!check( _be, _opt))
...@@ -297,18 +300,18 @@ write(std::ostream& _out, BaseExporter& _be, Options _opt) const ...@@ -297,18 +300,18 @@ write(std::ostream& _out, BaseExporter& _be, Options _opt) const
for (j=0; j< vhandles.size(); ++j) for (j=0; j< vhandles.size(); ++j)
{ {
// Write vertex index // Write vertex index
idx = vhandles[j].idx() + 1; idx = vhandles[j].idx() + 1;
_out << " " << idx; _out << " " << idx;
// write separator // write separator
_out << "/" ; _out << "/" ;
// write vertex texture coordinate index // write vertex texture coordinate index
if (_opt.check(Options::VertexTexCoord)) if (_opt.check(Options::VertexTexCoord))
_out << idx; _out << idx;
// write separator // write separator
_out << "/" ; _out << "/" ;
......
...@@ -4,10 +4,10 @@ ...@@ -4,10 +4,10 @@
* Copyright (C) 2001-2012 by Computer Graphics Group, RWTH Aachen * * Copyright (C) 2001-2012 by Computer Graphics Group, RWTH Aachen *
* www.openmesh.org * * www.openmesh.org *
* * * *
*---------------------------------------------------------------------------* *---------------------------------------------------------------------------*
* This file is part of OpenMesh. * * This file is part of OpenMesh. *
* * * *
* OpenMesh is free software: you can redistribute it and/or modify * * OpenMesh is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as * * it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 3 of * * published by the Free Software Foundation, either version 3 of *
* the License, or (at your option) any later version with the * * the License, or (at your option) any later version with the *
...@@ -30,10 +30,10 @@ ...@@ -30,10 +30,10 @@
* License along with OpenMesh. If not, * * License along with OpenMesh. If not, *
* see <http://www.gnu.org/licenses/>. * * see <http://www.gnu.org/licenses/>. *
* * * *
\*===========================================================================*/ \*===========================================================================*/
/*===========================================================================*\ /*===========================================================================*\
* * * *
* $Revision$ * * $Revision$ *
* $Date$ * * $Date$ *
* * * *
...@@ -73,7 +73,7 @@ namespace IO { ...@@ -73,7 +73,7 @@ namespace IO {
//=== IMPLEMENTATION ========================================================== //=== IMPLEMENTATION ==========================================================
/** /**
This class defines the OBJ writer. This class is further singleton'ed This class defines the OBJ writer. This class is further singleton'ed
by SingletonT to OBJWriter. by SingletonT to OBJWriter.
*/ */
...@@ -89,9 +89,9 @@ public: ...@@ -89,9 +89,9 @@ public:
std::string get_description() const { return "Alias/Wavefront"; } std::string get_description() const { return "Alias/Wavefront"; }
std::string get_extensions() const { return "obj"; } std::string get_extensions() const { return "obj"; }
bool write(const std::string&, BaseExporter&, Options) const; bool write(const std::string&, BaseExporter&, Options, std::streamsize _precision = 6) const;
bool write(std::ostream&, BaseExporter&, Options) const; bool write(std::ostream&, BaseExporter&, Options, std::streamsize _precision = 6) const;
size_t binary_size(BaseExporter&, Options) const { return 0; } size_t binary_size(BaseExporter&, Options) const { return 0; }
......
...@@ -4,10 +4,10 @@ ...@@ -4,10 +4,10 @@
* Copyright (C) 2001-2012 by Computer Graphics Group, RWTH Aachen * * Copyright (C) 2001-2012 by Computer Graphics Group, RWTH Aachen *
* www.openmesh.org * * www.openmesh.org *
* * * *
*---------------------------------------------------------------------------* *---------------------------------------------------------------------------*
* This file is part of OpenMesh. * * This file is part of OpenMesh. *
* * * *
* OpenMesh is free software: you can redistribute it and/or modify * * OpenMesh is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as * * it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 3 of * * published by the Free Software Foundation, either version 3 of *
* the License, or (at your option) any later version with the * * the License, or (at your option) any later version with the *
...@@ -30,10 +30,10 @@ ...@@ -30,10 +30,10 @@
* License along with OpenMesh. If not, * * License along with OpenMesh. If not, *
* see <http://www.gnu.org/licenses/>. * * see <http://www.gnu.org/licenses/>. *
* * * *
\*===========================================================================*/ \*===========================================================================*/
/*===========================================================================*\ /*===========================================================================*\
* * * *
* $Revision$ * * $Revision$ *
* $Date$ * * $Date$ *
* * * *
...@@ -78,7 +78,7 @@ _OFFWriter_::_OFFWriter_() { IOManager().register_module(this); } ...@@ -78,7 +78,7 @@ _OFFWriter_::_OFFWriter_() { IOManager().register_module(this); }
bool bool
_OFFWriter_:: _OFFWriter_::
write(const std::string& _filename, BaseExporter& _be, Options _opt) const write(const std::string& _filename, BaseExporter& _be, Options _opt, std::streamsize _precision) const
{ {
// check exporter features // check exporter features
if ( !check( _be, _opt ) ) if ( !check( _be, _opt ) )
...@@ -88,7 +88,7 @@ write(const std::string& _filename, BaseExporter& _be, Options _opt) const ...@@ -88,7 +88,7 @@ write(const std::string& _filename, BaseExporter& _be, Options _opt) const
// check writer features // check writer features
if ( _opt.check(Options::FaceNormal) ) // not supported by format if ( _opt.check(Options::FaceNormal) ) // not supported by format
return false; return false;
// open file // open file
std::fstream out(_filename.c_str(), (_opt.check(Options::Binary) ? std::ios_base::binary | std::ios_base::out std::fstream out(_filename.c_str(), (_opt.check(Options::Binary) ? std::ios_base::binary | std::ios_base::out
: std::ios_base::out) ); : std::ios_base::out) );
...@@ -100,6 +100,7 @@ write(const std::string& _filename, BaseExporter& _be, Options _opt) const ...@@ -100,6 +100,7 @@ write(const std::string& _filename, BaseExporter& _be, Options _opt) const
return false; return false;
} }
out.precision(_precision);
// write header line // write header line
if (_opt.check(Options::VertexTexCoord)) out << "ST"; if (_opt.check(Options::VertexTexCoord)) out << "ST";
...@@ -126,7 +127,7 @@ write(const std::string& _filename, BaseExporter& _be, Options _opt) const ...@@ -126,7 +127,7 @@ write(const std::string& _filename, BaseExporter& _be, Options _opt) const
bool bool
_OFFWriter_:: _OFFWriter_::
write(std::ostream& _os, BaseExporter& _be, Options _opt) const write(std::ostream& _os, BaseExporter& _be, Options _opt, std::streamsize _precision) const
{ {
// check exporter features // check exporter features
if ( !check( _be, _opt ) ) if ( !check( _be, _opt ) )
...@@ -136,8 +137,8 @@ write(std::ostream& _os, BaseExporter& _be, Options _opt) const ...@@ -136,8 +137,8 @@ write(std::ostream& _os, BaseExporter& _be, Options _opt) const
// check writer features // check writer features
if ( _opt.check(Options::FaceNormal) ) // not supported by format if ( _opt.check(Options::FaceNormal) ) // not supported by format
return false; return false;
if (!_os.good()) if (!_os.good())
{ {
omerr() << "[OFFWriter] : cannot write to stream " omerr() << "[OFFWriter] : cannot write to stream "
...@@ -145,6 +146,7 @@ write(std::ostream& _os, BaseExporter& _be, Options _opt) const ...@@ -145,6 +146,7 @@ write(std::ostream& _os, BaseExporter& _be, Options _opt) const
return false; return false;
} }
_os.precision(_precision);
// write header line // write header line
if (_opt.check(Options::VertexTexCoord)) _os << "ST"; if (_opt.check(Options::VertexTexCoord)) _os << "ST";
...@@ -195,16 +197,16 @@ write_ascii(std::ostream& _out, BaseExporter& _be, Options _opt) const ...@@ -195,16 +197,16 @@ write_ascii(std::ostream& _out, BaseExporter& _be, Options _opt) const
{ {
vh = VertexHandle(i); vh = VertexHandle(i);
v = _be.point(vh); v = _be.point(vh);
//Vertex //Vertex
_out << v[0] << " " << v[1] << " " << v[2]; _out << v[0] << " " << v[1] << " " << v[2];
// VertexNormal // VertexNormal
if ( _opt.vertex_has_normal() ) { if ( _opt.vertex_has_normal() ) {
n = _be.normal(vh); n = _be.normal(vh);
_out << " " << n[0] << " " << n[1] << " " << n[2]; _out << " " << n[0] << " " << n[1] << " " << n[2];
} }
// VertexColor // VertexColor
if ( _opt.vertex_has_color() ) { if ( _opt.vertex_has_color() ) {
//with alpha //with alpha
...@@ -217,26 +219,26 @@ write_ascii(std::ostream& _out, BaseExporter& _be, Options _opt) const ...@@ -217,26 +219,26 @@ write_ascii(std::ostream& _out, BaseExporter& _be, Options _opt) const
_out << " " << c[0] << " " << c[1] << " " << c[2]; _out << " " << c[0] << " " << c[1] << " " << c[2];
} }
} }
// TexCoord // TexCoord
if (_opt.vertex_has_texcoord() ) { if (_opt.vertex_has_texcoord() ) {
t = _be.texcoord(vh); t = _be.texcoord(vh);
_out << " " << t[0] << " " << t[1]; _out << " " << t[0] << " " << t[1];
} }
_out << "\n"; _out << "\n";
} }
// faces (indices starting at 0) // faces (indices starting at 0)
if (_be.is_triangle_mesh()) if (_be.is_triangle_mesh())
{ {
for (i=0, nF=_be.n_faces(); i<nF; ++i) for (i=0, nF=_be.n_faces(); i<nF; ++i)
{ {
_be.get_vhandles(FaceHandle(i), vhandles); _be.get_vhandles(FaceHandle(i), vhandles);
_out << 3 << " "; _out << 3 << " ";
_out << vhandles[0].idx() << " "; _out << vhandles[0].idx() << " ";
_out << vhandles[1].idx() << " "; _out << vhandles[1].idx() << " ";
_out << vhandles[2].idx(); _out << vhandles[2].idx();
//face color //face color
...@@ -305,7 +307,7 @@ void _OFFWriter_::writeValue(std::ostream& _out, float value) const { ...@@ -305,7 +307,7 @@ void _OFFWriter_::writeValue(std::ostream& _out, float value) const {
store(_out, tmp, false); store(_out, tmp, false);
} }
bool bool
_OFFWriter_:: _OFFWriter_::
write_binary(std::ostream& _out, BaseExporter& _be, Options _opt) const write_binary(std::ostream& _out, BaseExporter& _be, Options _opt) const
{ {
...@@ -325,18 +327,18 @@ write_binary(std::ostream& _out, BaseExporter& _be, Options _opt) const ...@@ -325,18 +327,18 @@ write_binary(std::ostream& _out, BaseExporter& _be, Options _opt) const
writeValue(_out, (uint) _be.n_faces() ); writeValue(_out, (uint) _be.n_faces() );
writeValue(_out, 0 ); writeValue(_out, 0 );
// vertex data (point, normals, texcoords) // vertex data (point, normals, texcoords)
for (i=0, nV=_be.n_vertices(); i<nV; ++i) for (i=0, nV=_be.n_vertices(); i<nV; ++i)
{ {
vh = VertexHandle(i); vh = VertexHandle(i);
v = _be.point(vh); v = _be.point(vh);
//vertex //vertex
writeValue(_out, v[0]); writeValue(_out, v[0]);
writeValue(_out, v[1]); writeValue(_out, v[1]);
writeValue(_out, v[2]); writeValue(_out, v[2]);
// vertex normal // vertex normal
if ( _opt.vertex_has_normal() ) { if ( _opt.vertex_has_normal() ) {
n = _be.normal(vh); n = _be.normal(vh);
...@@ -360,7 +362,7 @@ write_binary(std::ostream& _out, BaseExporter& _be, Options _opt) const ...@@ -360,7 +362,7 @@ write_binary(std::ostream& _out, BaseExporter& _be, Options _opt) const
writeValue(_out, t[0]); writeValue(_out, t[0]);
writeValue(_out, t[1]); writeValue(_out, t[1]);
} }
} }
// faces (indices starting at 0) // faces (indices starting at 0)
...@@ -426,7 +428,7 @@ binary_size(BaseExporter& _be, Options _opt) const ...@@ -426,7 +428,7 @@ binary_size(BaseExporter& _be, Options _opt) const
size_t _3floats(3*sizeof(float)); size_t _3floats(3*sizeof(float));
size_t _3ui(3*sizeof(unsigned int)); size_t _3ui(3*sizeof(unsigned int));
size_t _4ui(4*sizeof(unsigned int)); size_t _4ui(4*sizeof(unsigned int));
if ( !_opt.is_binary() ) if ( !_opt.is_binary() )
return 0; return 0;
else else
...@@ -441,7 +443,7 @@ binary_size(BaseExporter& _be, Options _opt) const ...@@ -441,7 +443,7 @@ binary_size(BaseExporter& _be, Options _opt) const
header += 1; // N header += 1; // N
data += _be.n_vertices() * _3floats; data += _be.n_vertices() * _3floats;
} }
if ( _opt.vertex_has_color() && _be.has_vertex_colors() ) if ( _opt.vertex_has_color() && _be.has_vertex_colors() )
{ {
header += 1; // C header += 1; // C
...@@ -472,7 +474,7 @@ binary_size(BaseExporter& _be, Options _opt) const ...@@ -472,7 +474,7 @@ binary_size(BaseExporter& _be, Options _opt) const
} }
} }
// face colors // face colors
if ( _opt.face_has_color() && _be.has_face_colors() ){ if ( _opt.face_has_color() && _be.has_face_colors() ){
if ( _opt.color_has_alpha() ) if ( _opt.color_has_alpha() )
......
...@@ -4,10 +4,10 @@ ...@@ -4,10 +4,10 @@
* Copyright (C) 2001-2012 by Computer Graphics Group, RWTH Aachen * * Copyright (C) 2001-2012 by Computer Graphics Group, RWTH Aachen *
* www.openmesh.org * * www.openmesh.org *
* * * *
*---------------------------------------------------------------------------* *---------------------------------------------------------------------------*
* This file is part of OpenMesh. * * This file is part of OpenMesh. *
* * * *
* OpenMesh is free software: you can redistribute it and/or modify * * OpenMesh is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as * * it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 3 of * * published by the Free Software Foundation, either version 3 of *
* the License, or (at your option) any later version with the * * the License, or (at your option) any later version with the *
...@@ -30,10 +30,10 @@ ...@@ -30,10 +30,10 @@
* License along with OpenMesh. If not, * * License along with OpenMesh. If not, *
* see <http://www.gnu.org/licenses/>. * * see <http://www.gnu.org/licenses/>. *
* * * *
\*===========================================================================*/ \*===========================================================================*/
/*===========================================================================*\ /*===========================================================================*\
* * * *
* $Revision$ * * $Revision$ *
* $Date$ * * $Date$ *
* * * *
...@@ -74,8 +74,8 @@ namespace IO { ...@@ -74,8 +74,8 @@ namespace IO {
//=== IMPLEMENTATION ========================================================== //=== IMPLEMENTATION ==========================================================
/** /**
Implementation of the OFF format writer. This class is singleton'ed by Implementation of the OFF format writer. This class is singleton'ed by
SingletonT to OFFWriter. SingletonT to OFFWriter.
By passing Options to the write function you can manipulate the writing behavoir. By passing Options to the write function you can manipulate the writing behavoir.
...@@ -100,9 +100,9 @@ public: ...@@ -100,9 +100,9 @@ public:
std::string get_description() const { return "no description"; } std::string get_description() const { return "no description"; }
std::string get_extensions() const { return "off"; } std::string get_extensions() const { return "off"; }
bool write(const std::string&, BaseExporter&, Options) const; bool write(const std::string&, BaseExporter&, Options, std::streamsize _precision = 6) const;
bool write(std::ostream&, BaseExporter&, Options) const; bool write(std::ostream&, BaseExporter&, Options, std::streamsize _precision = 6) const;
size_t binary_size(BaseExporter& _be, Options _opt) const; size_t binary_size(BaseExporter& _be, Options _opt) const;
......
...@@ -4,10 +4,10 @@ ...@@ -4,10 +4,10 @@
* Copyright (C) 2001-2012 by Computer Graphics Group, RWTH Aachen * * Copyright (C) 2001-2012 by Computer Graphics Group, RWTH Aachen *
* www.openmesh.org * * www.openmesh.org *
* * * *
*---------------------------------------------------------------------------* *---------------------------------------------------------------------------*
* This file is part of OpenMesh. * * This file is part of OpenMesh. *
* * * *
* OpenMesh is free software: you can redistribute it and/or modify * * OpenMesh is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as * * it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 3 of * * published by the Free Software Foundation, either version 3 of *
* the License, or (at your option) any later version with the * * the License, or (at your option) any later version with the *
...@@ -30,10 +30,10 @@ ...@@ -30,10 +30,10 @@
* License along with OpenMesh. If not, * * License along with OpenMesh. If not, *
* see <http://www.gnu.org/licenses/>. * * see <http://www.gnu.org/licenses/>. *
* * * *
\*===========================================================================*/