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:
/// Write to file _filename. Data source specified by BaseExporter _be.
virtual bool write(const std::string& _filename,
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.
virtual bool write(std::ostream& _os,
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.
virtual size_t binary_size(BaseExporter&, Options) const { return 0; }
......
......@@ -80,7 +80,7 @@ _OBJWriter_::_OBJWriter_() { IOManager().register_module(this); }
bool
_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 );
......@@ -91,6 +91,8 @@ write(const std::string& _filename, BaseExporter& _be, Options _opt) const
return false;
}
out.precision(_precision);
{
#if defined(WIN32)
std::string::size_type dot = _filename.find_last_of("\\/");
......@@ -196,7 +198,7 @@ writeMaterial(std::ostream& _out, BaseExporter& _be, Options _opt) const
bool
_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;
Vec3f v, n;
......@@ -209,6 +211,7 @@ write(std::ostream& _out, BaseExporter& _be, Options _opt) const
omlog() << "[OBJWriter] : write file\n";
_out.precision(_precision);
// check exporter features
if (!check( _be, _opt))
......
......@@ -89,9 +89,9 @@ public:
std::string get_description() const { return "Alias/Wavefront"; }
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; }
......
......@@ -78,7 +78,7 @@ _OFFWriter_::_OFFWriter_() { IOManager().register_module(this); }
bool
_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
if ( !check( _be, _opt ) )
......@@ -100,6 +100,7 @@ write(const std::string& _filename, BaseExporter& _be, Options _opt) const
return false;
}
out.precision(_precision);
// write header line
if (_opt.check(Options::VertexTexCoord)) out << "ST";
......@@ -126,7 +127,7 @@ write(const std::string& _filename, BaseExporter& _be, Options _opt) const
bool
_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
if ( !check( _be, _opt ) )
......@@ -145,6 +146,7 @@ write(std::ostream& _os, BaseExporter& _be, Options _opt) const
return false;
}
_os.precision(_precision);
// write header line
if (_opt.check(Options::VertexTexCoord)) _os << "ST";
......
......@@ -100,9 +100,9 @@ public:
std::string get_description() const { return "no description"; }
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;
......
......@@ -91,7 +91,7 @@ _OMWriter_()
bool
_OMWriter_::write(const std::string& _filename, BaseExporter& _be,
Options _opt) const
Options _opt, std::streamsize _precision) const
{
// check whether exporter can give us an OpenMesh BaseKernel
if (!_be.kernel()) return false;
......@@ -104,6 +104,7 @@ _OMWriter_::write(const std::string& _filename, BaseExporter& _be,
_opt += Options::Binary; // only binary format supported
std::ofstream ofs(_filename.c_str(), std::ios::binary);
ofs.precision(_precision);
// check if file is open
if (!ofs.is_open())
......@@ -126,9 +127,10 @@ _OMWriter_::write(const std::string& _filename, BaseExporter& _be,
//-----------------------------------------------------------------------------
bool
_OMWriter_::write(std::ostream& _os, BaseExporter& _be, Options _opt) const
_OMWriter_::write(std::ostream& _os, BaseExporter& _be, Options _opt, std::streamsize _precision) const
{
// std::clog << "[OMWriter]::write( stream )\n";
_os.precision(_precision);
// check exporter features
if ( !check( _be, _opt ) )
......
......@@ -102,7 +102,7 @@ public:
std::string get_extensions() const
{ return "om"; }
bool write(std::ostream&, BaseExporter&, Options) const;
bool write(std::ostream&, BaseExporter&, Options, std::streamsize _precision = 6) const;
......@@ -114,7 +114,7 @@ protected:
static const OMFormat::uchar magic_[3];
static const OMFormat::uint8 version_;
bool write(const std::string&, BaseExporter&, Options) const;
bool write(const std::string&, BaseExporter&, Options, std::streamsize _precision = 6) const;
bool write_binary(std::ostream&, BaseExporter&, Options) const;
......
......@@ -78,7 +78,7 @@ _PLYWriter_::_PLYWriter_() { IOManager().register_module(this); }
bool
_PLYWriter_::
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
if ( !check( _be, _opt ) )
......@@ -115,6 +115,8 @@ write(const std::string& _filename, BaseExporter& _be, Options _opt) const
return false;
}
out.precision(_precision);
// write to file
bool result = (_opt.check(Options::Binary) ?
write_binary(out, _be, _opt) :
......@@ -130,7 +132,7 @@ write(const std::string& _filename, BaseExporter& _be, Options _opt) const
bool
_PLYWriter_::
write(std::ostream& _os, BaseExporter& _be, Options _opt) const
write(std::ostream& _os, BaseExporter& _be, Options _opt, std::streamsize _precision) const
{
// check exporter features
if ( !check( _be, _opt ) )
......@@ -151,6 +153,8 @@ write(std::ostream& _os, BaseExporter& _be, Options _opt) const
return false;
}
_os.precision(_precision);
// write to file
bool result = (_opt.check(Options::Binary) ?
write_binary(_os, _be, _opt) :
......
......@@ -95,9 +95,9 @@ public:
std::string get_description() const { return "PLY polygon file format"; }
std::string get_extensions() const { return "ply"; }
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;
......
......@@ -79,7 +79,7 @@ _STLWriter_::_STLWriter_() { IOManager().register_module(this); }
bool
_STLWriter_::
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
if (!check(_be, _opt)) return false;
......@@ -118,7 +118,7 @@ write(const std::string& _filename, BaseExporter& _be, Options _opt) const
bool
_STLWriter_::
write(std::ostream& _os, BaseExporter& _be, Options _opt) const
write(std::ostream& _os, BaseExporter& _be, Options _opt, std::streamsize _precision) const
{
// check exporter features
if (!check(_be, _opt)) return false;
......@@ -129,6 +129,8 @@ write(std::ostream& _os, BaseExporter& _be, Options _opt) const
_opt.check(Options::FaceColor))
return false;
_os.precision(_precision);
if (_opt & Options::Binary)
return write_stlb(_os, _be, _opt);
else
......@@ -209,7 +211,7 @@ write_stla(const std::string& _filename, BaseExporter& _be, Options /* _opt */)
bool
_STLWriter_::
write_stla(std::ostream& _out, BaseExporter& _be, Options /* _opt */) const
write_stla(std::ostream& _out, BaseExporter& _be, Options /* _opt */, std::streamsize _precision) const
{
omlog() << "[STLWriter] : write ascii file\n";
......@@ -217,7 +219,7 @@ write_stla(std::ostream& _out, BaseExporter& _be, Options /* _opt */) const
Vec3f a, b, c, n;
std::vector<VertexHandle> vhandles;
FaceHandle fh;
std::streamsize prec = _out.precision();
_out.precision(_precision);
// header
......@@ -239,7 +241,6 @@ write_stla(std::ostream& _out, BaseExporter& _be, Options /* _opt */) const
_be.normal(fh) :
((c-b) % (a-b)).normalize());
_out.precision(prec);
_out << "facet normal " << n[0] << " " << n[1] << " " << n[2] << "\nouter loop\n";
_out.precision(10);
_out << "vertex " << a[0] << " " << a[1] << " " << a[2] << "\n";
......@@ -340,7 +341,7 @@ write_stlb(const std::string& _filename, BaseExporter& _be, Options /* _opt */)
bool
_STLWriter_::
write_stlb(std::ostream& _out, BaseExporter& _be, Options /* _opt */) const
write_stlb(std::ostream& _out, BaseExporter& _be, Options /* _opt */, std::streamsize _precision) const
{
omlog() << "[STLWriter] : write binary file\n";
......@@ -349,6 +350,7 @@ write_stlb(std::ostream& _out, BaseExporter& _be, Options /* _opt */) const
Vec3f a, b, c, n;
std::vector<VertexHandle> vhandles;
FaceHandle fh;
_out.precision(_precision);
// write header
......
......@@ -93,17 +93,17 @@ public:
std::string get_description() const { return "Stereolithography Format"; }
std::string get_extensions() const { return "stla stlb"; }
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;
private:
bool write_stla(const std::string&, BaseExporter&, Options) const;
bool write_stla(std::ostream&, BaseExporter&, Options) const;
bool write_stla(std::ostream&, BaseExporter&, Options, std::streamsize _precision = 6) const;
bool write_stlb(const std::string&, BaseExporter&, Options) const;
bool write_stlb(std::ostream&, BaseExporter&, Options) const;
bool write_stlb(std::ostream&, BaseExporter&, Options, std::streamsize _precision = 6) const;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment