Commit of the debugged version of Alex' improvement to OpenMesh. File i/o is now done via istream/ostream instances such that direct buffer writing to files (serialization) will also be possible in future releases.
Code is tested. git-svn-id: http://www.openmesh.org/svnrepo/OpenMesh/trunk@221 fdac6126-5c0c-442c-9429-916003d36597
This commit is contained in:
@@ -4,10 +4,10 @@
|
||||
* Copyright (C) 2001-2009 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$ *
|
||||
* *
|
||||
@@ -86,10 +86,10 @@ public:
|
||||
|
||||
/// Destructor
|
||||
virtual ~BaseWriter() {};
|
||||
|
||||
|
||||
/// Return short description of the supported file format.
|
||||
virtual std::string get_description() const = 0;
|
||||
|
||||
|
||||
/// Return file format's extension.
|
||||
virtual std::string get_extensions() const = 0;
|
||||
|
||||
@@ -97,9 +97,14 @@ public:
|
||||
virtual bool can_u_write(const std::string& _filename) const;
|
||||
|
||||
/// 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,
|
||||
Options _opt) const = 0;
|
||||
Options _opt) 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;
|
||||
|
||||
/// Returns expected size of file if binary format is supported else 0.
|
||||
virtual size_t binary_size(BaseExporter&, Options) const { return 0; }
|
||||
|
||||
@@ -149,7 +149,7 @@ int _OBJWriter_::getMaterial(OpenMesh::Vec4f _color) const
|
||||
|
||||
bool
|
||||
_OBJWriter_::
|
||||
writeMaterial(std::fstream& _out, BaseExporter& _be, Options _opt) const
|
||||
writeMaterial(std::ostream& _out, BaseExporter& _be, Options _opt) const
|
||||
{
|
||||
OpenMesh::Vec3f c;
|
||||
OpenMesh::Vec4f cA;
|
||||
@@ -196,7 +196,7 @@ writeMaterial(std::fstream& _out, BaseExporter& _be, Options _opt) const
|
||||
|
||||
bool
|
||||
_OBJWriter_::
|
||||
write(std::fstream& _out, BaseExporter& _be, Options _opt) const
|
||||
write(std::ostream& _out, BaseExporter& _be, Options _opt) const
|
||||
{
|
||||
unsigned int i, j, nV, nF, idx;
|
||||
Vec3f v, n;
|
||||
|
||||
@@ -90,6 +90,8 @@ public:
|
||||
std::string get_extensions() const { return "obj"; }
|
||||
|
||||
bool write(const std::string&, BaseExporter&, Options) const;
|
||||
|
||||
bool write(std::ostream&, BaseExporter&, Options) const;
|
||||
|
||||
size_t binary_size(BaseExporter&, Options) const { return 0; }
|
||||
|
||||
@@ -105,9 +107,9 @@ private:
|
||||
|
||||
int getMaterial(OpenMesh::Vec4f _color) const;
|
||||
|
||||
bool writeMaterial(std::fstream& _out, BaseExporter&, Options) const;
|
||||
bool writeMaterial(std::ostream& _out, BaseExporter&, Options) const;
|
||||
|
||||
|
||||
bool write(std::fstream& _out, BaseExporter&, Options) const;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -121,13 +121,56 @@ write(const std::string& _filename, BaseExporter& _be, Options _opt) const
|
||||
return result;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
bool
|
||||
_OFFWriter_::
|
||||
write(std::ostream& _os, 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;
|
||||
|
||||
|
||||
if (!_os.good())
|
||||
{
|
||||
omerr() << "[OFFWriter] : cannot write to stream "
|
||||
<< std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// write header line
|
||||
if (_opt.check(Options::VertexTexCoord)) _os << "ST";
|
||||
if (_opt.check(Options::VertexColor) || _opt.check(Options::FaceColor)) _os << "C";
|
||||
if (_opt.check(Options::VertexNormal)) _os << "N";
|
||||
_os << "OFF";
|
||||
if (_opt.check(Options::Binary)) _os << " BINARY";
|
||||
_os << "\n";
|
||||
|
||||
|
||||
// write to file
|
||||
bool result = (_opt.check(Options::Binary) ?
|
||||
write_binary(_os, _be, _opt) :
|
||||
write_ascii(_os, _be, _opt));
|
||||
|
||||
|
||||
// return result
|
||||
return result;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
bool
|
||||
_OFFWriter_::
|
||||
write_ascii(std::fstream& _out, BaseExporter& _be, Options _opt) const
|
||||
write_ascii(std::ostream& _out, BaseExporter& _be, Options _opt) const
|
||||
{
|
||||
omlog() << "[OFFWriter] : write ascii file\n";
|
||||
|
||||
@@ -244,19 +287,19 @@ write_ascii(std::fstream& _out, BaseExporter& _be, Options _opt) const
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void _OFFWriter_::writeValue(std::fstream& _out, int value) const {
|
||||
void _OFFWriter_::writeValue(std::ostream& _out, int value) const {
|
||||
|
||||
uint32_t tmp = value;
|
||||
store(_out, tmp, false);
|
||||
}
|
||||
|
||||
void _OFFWriter_::writeValue(std::fstream& _out, unsigned int value) const {
|
||||
void _OFFWriter_::writeValue(std::ostream& _out, unsigned int value) const {
|
||||
|
||||
uint32_t tmp = value;
|
||||
store(_out, tmp, false);
|
||||
}
|
||||
|
||||
void _OFFWriter_::writeValue(std::fstream& _out, float value) const {
|
||||
void _OFFWriter_::writeValue(std::ostream& _out, float value) const {
|
||||
|
||||
float32_t tmp = value;
|
||||
store(_out, tmp, false);
|
||||
@@ -264,7 +307,7 @@ void _OFFWriter_::writeValue(std::fstream& _out, float value) const {
|
||||
|
||||
bool
|
||||
_OFFWriter_::
|
||||
write_binary(std::fstream& _out, BaseExporter& _be, Options _opt) const
|
||||
write_binary(std::ostream& _out, BaseExporter& _be, Options _opt) const
|
||||
{
|
||||
omlog() << "[OFFWriter] : write ascii file\n";
|
||||
|
||||
|
||||
@@ -101,17 +101,19 @@ public:
|
||||
std::string get_extensions() const { return "off"; }
|
||||
|
||||
bool write(const std::string&, BaseExporter&, Options) const;
|
||||
|
||||
bool write(std::ostream&, BaseExporter&, Options) const;
|
||||
|
||||
size_t binary_size(BaseExporter& _be, Options _opt) const;
|
||||
|
||||
|
||||
protected:
|
||||
void writeValue(std::fstream& _out, int value) const;
|
||||
void writeValue(std::fstream& _out, unsigned int value) const;
|
||||
void writeValue(std::fstream& _out, float value) const;
|
||||
void writeValue(std::ostream& _out, int value) const;
|
||||
void writeValue(std::ostream& _out, unsigned int value) const;
|
||||
void writeValue(std::ostream& _out, float value) const;
|
||||
|
||||
bool write_ascii(std::fstream& _in, BaseExporter&, Options) const;
|
||||
bool write_binary(std::fstream& _in, BaseExporter&, Options) const;
|
||||
bool write_ascii(std::ostream& _in, BaseExporter&, Options) const;
|
||||
bool write_binary(std::ostream& _in, BaseExporter&, Options) const;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -103,6 +103,7 @@ public:
|
||||
{ return "om"; }
|
||||
|
||||
bool write(std::ostream&, BaseExporter&, Options) const;
|
||||
|
||||
|
||||
|
||||
size_t binary_size(BaseExporter& _be, Options _opt) const;
|
||||
@@ -116,6 +117,7 @@ protected:
|
||||
bool write(const std::string&, BaseExporter&, Options) const;
|
||||
|
||||
bool write_binary(std::ostream&, BaseExporter&, Options) const;
|
||||
|
||||
|
||||
size_t store_binary_custom_chunk( std::ostream&, const BaseProperty&,
|
||||
OMFormat::Chunk::Entity, bool) const;
|
||||
|
||||
@@ -112,13 +112,47 @@ write(const std::string& _filename, BaseExporter& _be, Options _opt) const
|
||||
return result;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
bool
|
||||
_PLYWriter_::
|
||||
write(std::ostream& _os, BaseExporter& _be, Options _opt) const
|
||||
{
|
||||
// check exporter features
|
||||
if ( !check( _be, _opt ) )
|
||||
return false;
|
||||
|
||||
|
||||
// check writer features
|
||||
if ( _opt.check(Options::FaceNormal) || _opt.check(Options::FaceColor) ) // not supported yet
|
||||
return false;
|
||||
|
||||
options_ = _opt;
|
||||
|
||||
|
||||
if (!_os.good())
|
||||
{
|
||||
omerr() << "[PLYWriter] : cannot write to stream "
|
||||
<< std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
// write to file
|
||||
bool result = (_opt.check(Options::Binary) ?
|
||||
write_binary(_os, _be, _opt) :
|
||||
write_ascii(_os, _be, _opt));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
bool
|
||||
_PLYWriter_::
|
||||
write_ascii(std::fstream& _out, BaseExporter& _be, Options _opt) const
|
||||
write_ascii(std::ostream& _out, BaseExporter& _be, Options _opt) const
|
||||
{
|
||||
omlog() << "[PLYWriter] : write ascii file\n";
|
||||
|
||||
@@ -248,7 +282,7 @@ write_ascii(std::fstream& _out, BaseExporter& _be, Options _opt) const
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void _PLYWriter_::writeValue(ValueType _type, std::fstream& _out, int value) const {
|
||||
void _PLYWriter_::writeValue(ValueType _type, std::ostream& _out, int value) const {
|
||||
|
||||
uint32_t tmp32;
|
||||
uint8_t tmp8;
|
||||
@@ -270,7 +304,7 @@ default :
|
||||
}
|
||||
}
|
||||
|
||||
void _PLYWriter_::writeValue(ValueType _type, std::fstream& _out, unsigned int value) const {
|
||||
void _PLYWriter_::writeValue(ValueType _type, std::ostream& _out, unsigned int value) const {
|
||||
|
||||
uint32_t tmp32;
|
||||
uint8_t tmp8;
|
||||
@@ -292,7 +326,7 @@ default :
|
||||
}
|
||||
}
|
||||
|
||||
void _PLYWriter_::writeValue(ValueType _type, std::fstream& _out, float value) const {
|
||||
void _PLYWriter_::writeValue(ValueType _type, std::ostream& _out, float value) const {
|
||||
|
||||
float32_t tmp;
|
||||
|
||||
@@ -310,7 +344,7 @@ void _PLYWriter_::writeValue(ValueType _type, std::fstream& _out, float value) c
|
||||
|
||||
bool
|
||||
_PLYWriter_::
|
||||
write_binary(std::fstream& _out, BaseExporter& _be, Options _opt) const
|
||||
write_binary(std::ostream& _out, BaseExporter& _be, Options _opt) const
|
||||
{
|
||||
omlog() << "[PLYWriter] : write binary file\n";
|
||||
|
||||
|
||||
@@ -97,6 +97,8 @@ public:
|
||||
|
||||
bool write(const std::string&, BaseExporter&, Options) const;
|
||||
|
||||
bool write(std::ostream&, BaseExporter&, Options) const;
|
||||
|
||||
size_t binary_size(BaseExporter& _be, Options _opt) const;
|
||||
|
||||
enum ValueType {
|
||||
@@ -110,12 +112,12 @@ private:
|
||||
mutable Options options_;
|
||||
|
||||
protected:
|
||||
void writeValue(ValueType _type, std::fstream& _out, int value) const;
|
||||
void writeValue(ValueType _type, std::fstream& _out, unsigned int value) const;
|
||||
void writeValue(ValueType _type, std::fstream& _out, float value) const;
|
||||
void writeValue(ValueType _type, std::ostream& _out, int value) const;
|
||||
void writeValue(ValueType _type, std::ostream& _out, unsigned int value) const;
|
||||
void writeValue(ValueType _type, std::ostream& _out, float value) const;
|
||||
|
||||
bool write_ascii(std::fstream& _in, BaseExporter&, Options) const;
|
||||
bool write_binary(std::fstream& _in, BaseExporter&, Options) const;
|
||||
bool write_ascii(std::ostream& _in, BaseExporter&, Options) const;
|
||||
bool write_binary(std::ostream& _in, BaseExporter&, Options) const;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -113,6 +113,17 @@ write(const std::string& _filename, BaseExporter& _be, Options _opt) const
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
bool
|
||||
_STLWriter_::
|
||||
write(std::ostream& _os, BaseExporter& _be, Options _opt) const
|
||||
{
|
||||
omerr() << "[STLWriter] : STL Streams are not supported " << std::endl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -95,6 +95,8 @@ public:
|
||||
|
||||
bool write(const std::string&, BaseExporter&, Options) const;
|
||||
|
||||
bool write(std::ostream&, BaseExporter&, Options) const;
|
||||
|
||||
size_t binary_size(BaseExporter&, Options) const;
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user