Commit 1707f09f authored by Isaak Lim's avatar Isaak Lim

- 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
parent d370b6e0
......@@ -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,7 +96,7 @@ read(const std::string& _filename, BaseImporter& _bi, Options& _opt)
_bi.finish();
return ok;
}
// All modules failed to read
return false;
}
......@@ -105,13 +105,13 @@ read(const std::string& _filename, BaseImporter& _bi, Options& _opt)
//-----------------------------------------------------------------------------
bool
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)
......@@ -121,7 +121,7 @@ read(std::istream& _is, const std::string& _ext, BaseImporter& _bi, Options& _op
_bi.finish();
return ok;
}
// All modules failed to read
return false;
}
......@@ -132,11 +132,11 @@ read(std::istream& _is, const std::string& _ext, BaseImporter& _bi, Options& _op
bool
_IOManager_::
write(const std::string& _filename, BaseExporter& _be, Options _opt)
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;
}
}
//=============================================================================
......
......@@ -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$ *
* *
......@@ -78,7 +78,7 @@ namespace IO {
//=== IMPLEMENTATION ==========================================================
/** This is the real IOManager class that is later encapsulated by
/** This is the real IOManager class that is later encapsulated by
SingletonT to enforce its uniqueness. _IOManager_ is not meant to be used
directly by the programmer - the IOManager alias exists for this task.
......@@ -100,7 +100,7 @@ namespace IO {
class OPENMESHDLLEXPORT _IOManager_
{
private:
_IOManager_() {}
friend OPENMESHDLLEXPORT _IOManager_& IOManager();
......@@ -111,46 +111,48 @@ public:
/**
Read a mesh from file _filename. The target data structure is specified
by the given BaseImporter. The \c read method consecutively queries all
of its reader modules. True is returned upon success, false if all
of its reader modules. True is returned upon success, false if all
reader modules failed to interprete _filename.
*/
bool read(const std::string& _filename,
BaseImporter& _bi,
bool read(const std::string& _filename,
BaseImporter& _bi,
Options& _opt);
/**
Read a mesh from open std::istream _is. The target data structure is specified
by the given BaseImporter. The \c sread method consecutively queries all
of its reader modules. True is returned upon success, false if all
of its reader modules. True is returned upon success, false if all
reader modules failed to use _is.
*/
bool read(std::istream& _filename,
const std::string& _ext,
BaseImporter& _bi,
BaseImporter& _bi,
Options& _opt);
/** Write a mesh to file _filename. The source data structure is specified
by the given BaseExporter. The \c save method consecutively queries all
of its writer modules. True is returned upon success, false if all
of its writer modules. True is returned upon success, false if all
writer modules failed to write the requested format.
Options is determined by _filename's extension.
*/
bool write(const std::string& _filename,
bool write(const std::string& _filename,
BaseExporter& _be,
Options _opt=Options::Default);
Options _opt=Options::Default,
std::streamsize _precision = 6);
/** Write a mesh to open std::ostream _os. The source data structure is specified
by the given BaseExporter. The \c save method consecutively queries all
of its writer modules. True is returned upon success, false if all
of its writer modules. True is returned upon success, false if all
writer modules failed to write the requested format.
Options is determined by _filename's extension.
*/
bool write(std::ostream& _filename,
bool write(std::ostream& _filename,
const std::string& _ext,
BaseExporter& _be,
Options _opt=Options::Default);
Options _opt=Options::Default,
std::streamsize _precision = 6);
/// Returns true if the format is supported by one of the reader modules.
bool can_read( const std::string& _format ) const;
......@@ -158,19 +160,19 @@ public:
/// Returns true if the format is supported by one of the writer modules.
bool can_write( const std::string& _format ) const;
size_t binary_size(const std::string& _format,
size_t binary_size(const std::string& _format,
BaseExporter& _be,
Options _opt = Options::Default)
{
const BaseWriter *bw = find_writer(_format);
return bw ? bw->binary_size(_be,_opt) : 0;
}
}
public: //-- QT convenience function ------------------------------------------
/** Returns all readable file extension + descriptions in one string.
File formats are separated by <c>;;</c>.
......@@ -180,7 +182,7 @@ public: //-- QT convenience function ------------------------------------------
/** Returns all writeable file extension + descriptions in one string.
File formats are separated by <c>;;</c>.
File formats are separated by <c>;;</c>.
Convenience function for Qt file dialogs.
*/
const std::string& qt_write_filters() const { return write_filters_; }
......@@ -195,14 +197,14 @@ private:
// collect all writeable file extensions
void update_write_filters();
public: //-- SYSTEM PART------------------------------------------------------
/** Registers a new reader module. A call to this function should be
implemented in the constructor of all classes derived from BaseReader.
implemented in the constructor of all classes derived from BaseReader.
*/
bool register_module(BaseReader* _bl)
{
......@@ -212,9 +214,9 @@ public: //-- SYSTEM PART------------------------------------------------------
}
/** Registers a new writer module. A call to this function should be
implemented in the constructor of all classed derived from BaseWriter.
implemented in the constructor of all classed derived from BaseWriter.
*/
bool register_module(BaseWriter* _bw)
{
......@@ -223,20 +225,20 @@ public: //-- SYSTEM PART------------------------------------------------------
return true;
}
private:
const BaseWriter *find_writer(const std::string& _format);
// stores registered reader modules
std::set<BaseReader*> reader_modules_;
// stores registered writer modules
std::set<BaseWriter*> writer_modules_;
// input filters (e.g. for Qt file dialog)
std::string read_filters_;
// output filters (e.g. for Qt file dialog)
std::string write_filters_;
};
......
......@@ -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$ *
* *
......@@ -79,12 +79,12 @@ namespace IO {
//-----------------------------------------------------------------------------
/** \brief Read a mesh from file _filename.
/** \brief Read a mesh from file _filename.
The file format is determined by the file extension.
The file format is determined by the file extension.
\note If you link statically against OpenMesh, you have to add
the define OM_STATIC_BUILD to your application. This will
\note If you link statically against OpenMesh, you have to add
the define OM_STATIC_BUILD to your application. This will
ensure that readers and writers get initialized correctly.
@param _mesh The target mesh that will be filled with the read data
......@@ -95,22 +95,22 @@ namespace IO {
@return Successful?
*/
template <class Mesh>
bool
bool
read_mesh(Mesh& _mesh,
const std::string& _filename,
bool _clear = true)
const std::string& _filename,
bool _clear = true)
{
Options opt;
return read_mesh(_mesh, _filename, opt, _clear);
}
/** \brief Read a mesh from file _filename.
/** \brief Read a mesh from file _filename.
The file format is determined by the file extension.
The file format is determined by the file extension.
\note If you link statically against OpenMesh, you have to add
the define OM_STATIC_BUILD to your application. This will
\note If you link statically against OpenMesh, you have to add
the define OM_STATIC_BUILD to your application. This will
ensure that readers and writers get initialized correctly.
@param _mesh The target mesh that will be filled with the read data
......@@ -123,25 +123,25 @@ read_mesh(Mesh& _mesh,
@return Successful?
*/
template <class Mesh>
bool
bool
read_mesh(Mesh& _mesh,
const std::string& _filename,
Options& _opt,
bool _clear = true)
const std::string& _filename,
Options& _opt,
bool _clear = true)
{
if (_clear) _mesh.clear();
ImporterT<Mesh> importer(_mesh);
return IOManager().read(_filename, importer, _opt);
return IOManager().read(_filename, importer, _opt);
}
/** \brief Read a mesh from file open std::istream.
/** \brief Read a mesh from file open std::istream.
The file format is determined by parameter _ext. _ext has to include
The file format is determined by parameter _ext. _ext has to include
".[format]" in order to work properly (e.g. ".OFF")
\note If you link statically against OpenMesh, you have to add
the define OM_STATIC_BUILD to your application. This will
\note If you link statically against OpenMesh, you have to add
the define OM_STATIC_BUILD to your application. This will
ensure that readers and writers get initialized correctly.
@param _mesh The target mesh that will be filled with the read data
......@@ -155,16 +155,16 @@ read_mesh(Mesh& _mesh,
@return Successful?
*/
template <class Mesh>
bool
bool
read_mesh(Mesh& _mesh,
std::istream& _is,
const std::string& _ext,
Options& _opt,
bool _clear = true)
Options& _opt,
bool _clear = true)
{
if (_clear) _mesh.clear();
ImporterT<Mesh> importer(_mesh);
return IOManager().read(_is,_ext, importer, _opt);
return IOManager().read(_is,_ext, importer, _opt);
}
......@@ -172,12 +172,12 @@ read_mesh(Mesh& _mesh,
//-----------------------------------------------------------------------------
/** \brief Write a mesh to the file _filename.
/** \brief Write a mesh to the file _filename.
The file format is determined by _filename's extension.
The file format is determined by _filename's extension.
\note If you link statically against OpenMesh, you have to add
the define OM_STATIC_BUILD to your application. This will
\note If you link statically against OpenMesh, you have to add
the define OM_STATIC_BUILD to your application. This will
ensure that readers and writers get initialized correctly.
@param _mesh The mesh that will be written to file
......@@ -188,25 +188,26 @@ read_mesh(Mesh& _mesh,
@return Successful?
*/
template <class Mesh>
bool write_mesh(const Mesh& _mesh,
bool write_mesh(const Mesh& _mesh,
const std::string& _filename,
Options _opt = Options::Default)
{
Options _opt = Options::Default,
std::streamsize _precision = 6)
{
ExporterT<Mesh> exporter(_mesh);
return IOManager().write(_filename, exporter, _opt);
return IOManager().write(_filename, exporter, _opt, _precision);
}
//-----------------------------------------------------------------------------
/** Write a mesh to an open std::ostream.
/** Write a mesh to an open std::ostream.
The file format is determined by parameter _ext. _ext has to include
The file format is determined by parameter _ext. _ext has to include
".[format]" in order to work properly (e.g. ".OFF")
\note If you link statically against OpenMesh, you have to add
the define OM_STATIC_BUILD to your application. This will
\note If you link statically against OpenMesh, you have to add
the define OM_STATIC_BUILD to your application. This will
ensure that readers and writers get initialized correctly.
@param _mesh The mesh that will be written to file
......@@ -218,13 +219,14 @@ bool write_mesh(const Mesh& _mesh,
@return Successful?
*/
template <class Mesh>
bool write_mesh(const Mesh& _mesh,
std::ostream& _os,
const std::string& _ext,
Options _opt = Options::Default)
{
bool write_mesh(const Mesh& _mesh,
std::ostream& _os,
const std::string& _ext,
Options _opt = Options::Default,
std::streamsize _precision = 6)
{
ExporterT<Mesh> exporter(_mesh);
return IOManager().write(_os,_ext, exporter, _opt);