- added precision option to MeshIO and IOManager

refs #1157

git-svn-id: http://www.openmesh.org/svnrepo/OpenMesh/trunk@748 fdac6126-5c0c-442c-9429-916003d36597
This commit is contained in:
Isaak Lim
2012-10-15 13:52:32 +00:00
parent d370b6e06c
commit 1707f09f0d
3 changed files with 142 additions and 138 deletions

View File

@@ -4,10 +4,10 @@
* Copyright (C) 2001-2012 by Computer Graphics Group, RWTH Aachen *
* www.openmesh.org *
* *
*---------------------------------------------------------------------------*
*---------------------------------------------------------------------------*
* 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 *
* published by the Free Software Foundation, either version 3 of *
* the License, or (at your option) any later version with the *
@@ -30,10 +30,10 @@
* License along with OpenMesh. If not, *
* see <http://www.gnu.org/licenses/>. *
* *
\*===========================================================================*/
\*===========================================================================*/
/*===========================================================================*\
* *
* *
* $Revision$ *
* $Date$ *
* *
@@ -69,7 +69,7 @@ _IOManager_ *__IOManager_instance = 0;
_IOManager_& IOManager()
{
if (!__IOManager_instance)
__IOManager_instance = new _IOManager_();
@@ -80,13 +80,13 @@ _IOManager_& IOManager()
//-----------------------------------------------------------------------------
bool
bool
_IOManager_::
read(const std::string& _filename, BaseImporter& _bi, Options& _opt)
{
{
std::set<BaseReader*>::const_iterator it = reader_modules_.begin();
std::set<BaseReader*>::const_iterator it_end = reader_modules_.end();
// Try all registered modules
for(; it != it_end; ++it)
if ((*it)->can_u_read(_filename))
@@ -96,32 +96,7 @@ read(const std::string& _filename, BaseImporter& _bi, Options& _opt)
_bi.finish();
return ok;
}
// All modules failed to read
return false;
}
//-----------------------------------------------------------------------------
bool
_IOManager_::
read(std::istream& _is, const std::string& _ext, BaseImporter& _bi, Options& _opt)
{
std::set<BaseReader*>::const_iterator it = reader_modules_.begin();
std::set<BaseReader*>::const_iterator it_end = reader_modules_.end();
// Try all registered modules
for(; it != it_end; ++it)
if ((*it)->BaseReader::can_u_read(_ext)) //Use the extension check only (no file existence)
{
_bi.prepare();
bool ok = (*it)->read(_is, _bi, _opt);
_bi.finish();
return ok;
}
// All modules failed to read
return false;
}
@@ -132,11 +107,36 @@ read(std::istream& _is, const std::string& _ext, BaseImporter& _bi, Options& _op
bool
_IOManager_::
write(const std::string& _filename, BaseExporter& _be, Options _opt)
read(std::istream& _is, const std::string& _ext, BaseImporter& _bi, Options& _opt)
{
std::set<BaseReader*>::const_iterator it = reader_modules_.begin();
std::set<BaseReader*>::const_iterator it_end = reader_modules_.end();
// Try all registered modules
for(; it != it_end; ++it)
if ((*it)->BaseReader::can_u_read(_ext)) //Use the extension check only (no file existence)
{
_bi.prepare();
bool ok = (*it)->read(_is, _bi, _opt);
_bi.finish();
return ok;
}
// All modules failed to read
return false;
}
//-----------------------------------------------------------------------------
bool
_IOManager_::
write(const std::string& _filename, BaseExporter& _be, Options _opt, std::streamsize _precision)
{
std::set<BaseWriter*>::const_iterator it = writer_modules_.begin();
std::set<BaseWriter*>::const_iterator it_end = writer_modules_.end();
if ( it == it_end )
{
omerr() << "[OpenMesh::IO::_IOManager_] No writing modules available!\n";
@@ -148,10 +148,10 @@ write(const std::string& _filename, BaseExporter& _be, Options _opt)
{
if ((*it)->can_u_write(_filename))
{
return (*it)->write(_filename, _be, _opt);
return (*it)->write(_filename, _be, _opt, _precision);
}
}
// All modules failed to save
return false;
}
@@ -161,11 +161,11 @@ write(const std::string& _filename, BaseExporter& _be, Options _opt)
bool
_IOManager_::
write(std::ostream& _os,const std::string &_ext, BaseExporter& _be, Options _opt)
write(std::ostream& _os,const std::string &_ext, BaseExporter& _be, Options _opt, std::streamsize _precision)
{
std::set<BaseWriter*>::const_iterator it = writer_modules_.begin();
std::set<BaseWriter*>::const_iterator it_end = writer_modules_.end();
if ( it == it_end )
{
omerr() << "[OpenMesh::IO::_IOManager_] No writing modules available!\n";
@@ -177,10 +177,10 @@ write(std::ostream& _os,const std::string &_ext, BaseExporter& _be, Options _opt
{
if ((*it)->BaseWriter::can_u_write(_ext)) //Restrict test to the extension check
{
return (*it)->write(_os, _be, _opt);
return (*it)->write(_os, _be, _opt, _precision);
}
}
// All modules failed to save
return false;
}
@@ -188,18 +188,18 @@ write(std::ostream& _os,const std::string &_ext, BaseExporter& _be, Options _opt
//-----------------------------------------------------------------------------
bool
bool
_IOManager_::
can_read( const std::string& _format ) const
{
std::set<BaseReader*>::const_iterator it = reader_modules_.begin();
std::set<BaseReader*>::const_iterator it_end = reader_modules_.end();
std::string filename = "dummy." + _format;
for(; it != it_end; ++it)
if ((*it)->can_u_read(filename))
return true;
return false;
}
@@ -214,12 +214,12 @@ can_write( const std::string& _format ) const
std::set<BaseWriter*>::const_iterator it = writer_modules_.begin();
std::set<BaseWriter*>::const_iterator it_end = writer_modules_.end();
std::string filename = "dummy." + _format;
// Try all registered modules
for(; it != it_end; ++it)
if ((*it)->can_u_write(filename))
return true;
return false;
}
@@ -232,7 +232,7 @@ _IOManager_::
find_writer(const std::string& _format)
{
using std::string;
string::size_type dot = _format.rfind('.');
string ext;
@@ -240,11 +240,11 @@ find_writer(const std::string& _format)
ext = _format;
else
ext = _format.substr(dot+1,_format.length()-(dot+1));
std::set<BaseWriter*>::const_iterator it = writer_modules_.begin();
std::set<BaseWriter*>::const_iterator it_end = writer_modules_.end();
std::string filename = "dummy." + ext;
// Try all registered modules
for(; it != it_end; ++it)
if ((*it)->can_u_write(filename))
@@ -252,7 +252,7 @@ find_writer(const std::string& _format)
return NULL;
}
//-----------------------------------------------------------------------------
@@ -265,7 +265,7 @@ update_read_filters()
it_end = reader_modules_.end();
std::string all = "";
std::string filters = "";
for(; it != it_end; ++it)
{
// Initialized with space, as a workaround for debug build with clang on mac
@@ -273,19 +273,19 @@ update_read_filters()
std::string tmp = " ";
filters += (*it)->get_description() + " (";
std::istringstream iss((*it)->get_extensions());
while (iss && !iss.eof() && (iss >> tmp) )
{
tmp = " *." + tmp; filters += tmp; all += tmp;
tmp = " *." + tmp; filters += tmp; all += tmp;
}
filters += " );;";
}
all = "All files ( " + all + " );;";
read_filters_ = all + filters;
}
@@ -301,7 +301,7 @@ update_write_filters()
it_end = writer_modules_.end();
std::string all;
std::string filters;
for(; it != it_end; ++it)
{
// Initialized with space, as a workaround for debug build with clang on mac
@@ -319,7 +319,7 @@ update_write_filters()
all = "All files ( " + all + " );;";
write_filters_ = all + filters;
}
}
//=============================================================================