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:
Mike Kremer
2009-11-17 13:54:16 +00:00
parent 86b53bf930
commit efa67fbcfc
24 changed files with 512 additions and 242 deletions

View File

@@ -102,6 +102,31 @@ read(const std::string& _filename, BaseImporter& _bi, Options& _opt)
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
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;
}
//-----------------------------------------------------------------------------
bool bool
_IOManager_:: _IOManager_::
write(const std::string& _filename, BaseExporter& _be, Options _opt) write(const std::string& _filename, BaseExporter& _be, Options _opt)
@@ -128,6 +153,34 @@ write(const std::string& _filename, BaseExporter& _be, Options _opt)
return false; return false;
} }
//-----------------------------------------------------------------------------
bool
_IOManager_::
write(std::ostream& _os,const std::string &_ext, BaseExporter& _be, Options _opt)
{
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";
return false;
}
// Try all registered modules
for(; it != it_end; ++it)
{
if ((*it)->BaseWriter::can_u_write(_ext)) //Restrict test to the extension check
{
return (*it)->write(_os, _be, _opt);
}
}
// All modules failed to save
return false;
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------

View File

@@ -118,6 +118,16 @@ public:
BaseImporter& _bi, BaseImporter& _bi,
Options& _opt); 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
reader modules failed to use _is.
*/
bool read(std::istream& _filename,
const std::string& _ext,
BaseImporter& _bi,
Options& _opt);
/** Write a mesh to file _filename. The source data structure is specified /** Write a mesh to file _filename. The source data structure is specified
@@ -130,6 +140,16 @@ public:
BaseExporter& _be, BaseExporter& _be,
Options _opt=Options::Default); Options _opt=Options::Default);
/** 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
writer modules failed to write the requested format.
Options is determined by _filename's extension.
*/
bool write(std::ostream& _filename,
const std::string& _ext,
BaseExporter& _be,
Options _opt=Options::Default);
/// Returns true if the format is supported by one of the reader modules. /// Returns true if the format is supported by one of the reader modules.

View File

@@ -107,6 +107,23 @@ read_mesh(Mesh& _mesh,
} }
/** Read a mesh from file open std::istream. The file format is determined by
parameter _ext. _ext has to include ".[format]" in order to work properly */
template <class Mesh>
bool
read_mesh(Mesh& _mesh,
std::istream& _is,
const std::string& _ext,
Options& _opt,
bool _clear = true)
{
if (_clear) _mesh.clear();
ImporterT<Mesh> importer(_mesh);
return IOManager().read(_is,_ext, importer, _opt);
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@@ -124,6 +141,22 @@ bool write_mesh(const Mesh& _mesh, const std::string& _filename,
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
/** Write a mesh to an open std::ostream. The file format is determined
by _ext. */
template <class Mesh>
bool write_mesh(const Mesh& _mesh,
std::ostream& _os,
const std::string& _ext,
Options _opt = Options::Default)
{
ExporterT<Mesh> exporter(_mesh);
return IOManager().write(_os,_ext, exporter, _opt);
}
//-----------------------------------------------------------------------------
template <class Mesh> template <class Mesh>
size_t binary_size(const Mesh& _mesh, const std::string& _format, size_t binary_size(const Mesh& _mesh, const std::string& _format,
Options _opt = Options::Default) Options _opt = Options::Default)

View File

@@ -111,6 +111,14 @@ public:
BaseImporter& _bi, BaseImporter& _bi,
Options& _opt) = 0; Options& _opt) = 0;
/** Reads a mesh given by a std::stream. This method usually uses the same stream reading method
that read uses. Options can be passed via _opt. After execution _opt contains the Options
that were available
*/
virtual bool read(std::istream& _is,
BaseImporter& _bi,
Options& _opt) = 0;
/// Returns true if reader can parse _filename (checks extension) /// Returns true if reader can parse _filename (checks extension)
virtual bool can_u_read(const std::string& _filename) const; virtual bool can_u_read(const std::string& _filename) const;

View File

@@ -112,7 +112,7 @@ read(const std::string& _filename, BaseImporter& _bi, Options& _opt)
{ {
std::fstream in( _filename.c_str(), std::ios_base::in ); std::fstream in( _filename.c_str(), std::ios_base::in );
if (!in) if (!in.is_open() || !in.good())
{ {
omerr() << "[OBJReader] : cannot not open file " omerr() << "[OBJReader] : cannot not open file "
<< _filename << _filename
@@ -137,7 +137,6 @@ read(const std::string& _filename, BaseImporter& _bi, Options& _opt)
return result; return result;
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
bool bool
@@ -264,7 +263,7 @@ read_material(std::fstream& _in)
bool bool
_OBJReader_:: _OBJReader_::
read(std::fstream& _in, BaseImporter& _bi, Options& _opt) read(std::istream& _in, BaseImporter& _bi, Options& _opt)
{ {
omlog() << "[OBJReader] : read file\n"; omlog() << "[OBJReader] : read file\n";

View File

@@ -94,6 +94,10 @@ public:
BaseImporter& _bi, BaseImporter& _bi,
Options& _opt); Options& _opt);
bool read(std::istream& _in,
BaseImporter& _bi,
Options& _opt);
private: private:
#ifndef DOXY_IGNORE_THIS #ifndef DOXY_IGNORE_THIS
@@ -163,8 +167,6 @@ private:
private: private:
bool read(std::fstream& _in, BaseImporter& _bi, Options& _opt);
std::string path_; std::string path_;
}; };

View File

@@ -57,6 +57,8 @@
#include <OpenMesh/Core/IO/SR_store.hh> #include <OpenMesh/Core/IO/SR_store.hh>
//STL //STL
#include <iostream>
#include <ios>
#include <fstream> #include <fstream>
#include <memory> #include <memory>
@@ -97,32 +99,39 @@ bool
_OFFReader_::read(const std::string& _filename, BaseImporter& _bi, _OFFReader_::read(const std::string& _filename, BaseImporter& _bi,
Options& _opt) Options& _opt)
{ {
std::fstream in(_filename.c_str(), (options_.is_binary() ? std::ios_base::binary | std::ios_base::in std::ifstream ifile(_filename.c_str(), (options_.is_binary() ? std::ios::binary | std::ios::in
: std::ios_base::in) ); : std::ios::in) );
if (!in) if (!ifile.is_open() || !ifile.good())
{ {
omerr() << "[OFFReader] : cannot not open file " omerr() << "[OFFReader] : cannot not open file "
<< _filename << _filename
<< std::endl; << std::endl;
return false; return false;
} }
assert(ifile);
bool result = read(in, _bi, _opt); bool result = read(ifile, _bi, _opt);
ifile.close();
in.close();
return result; return result;
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
bool bool
_OFFReader_::read(std::fstream& _in, BaseImporter& _bi, Options& _opt ) const _OFFReader_::read(std::istream& _in, BaseImporter& _bi, Options& _opt )
{ {
if (!_in.good())
{
omerr() << "[OMReader] : cannot not use stream "
<< std::endl;
return false;
}
// filter relevant options for reading // filter relevant options for reading
bool swap = _opt.check( Options::Swap ); bool swap = _opt.check( Options::Swap );
@@ -153,7 +162,7 @@ _OFFReader_::read(std::fstream& _in, BaseImporter& _bi, Options& _opt ) const
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
bool bool
_OFFReader_::read_ascii(std::fstream& _in, BaseImporter& _bi) const _OFFReader_::read_ascii(std::istream& _in, BaseImporter& _bi) const
{ {
@@ -380,21 +389,21 @@ int _OFFReader_::getColorType(std::string& _line, bool _texCoordsAvailable) cons
return count; return count;
} }
void _OFFReader_::readValue(std::fstream& _in, float& _value) const{ void _OFFReader_::readValue(std::istream& _in, float& _value) const{
float32_t tmp; float32_t tmp;
restore( _in , tmp, false ); //assuming LSB byte order restore( _in , tmp, false ); //assuming LSB byte order
_value = tmp; _value = tmp;
} }
void _OFFReader_::readValue(std::fstream& _in, int& _value) const{ void _OFFReader_::readValue(std::istream& _in, int& _value) const{
uint32_t tmp; uint32_t tmp;
restore( _in , tmp, false ); //assuming LSB byte order restore( _in , tmp, false ); //assuming LSB byte order
_value = tmp; _value = tmp;
} }
void _OFFReader_::readValue(std::fstream& _in, unsigned int& _value) const{ void _OFFReader_::readValue(std::istream& _in, unsigned int& _value) const{
uint32_t tmp; uint32_t tmp;
restore( _in , tmp, false ); //assuming LSB byte order restore( _in , tmp, false ); //assuming LSB byte order
@@ -402,7 +411,7 @@ void _OFFReader_::readValue(std::fstream& _in, unsigned int& _value) const{
} }
bool bool
_OFFReader_::read_binary(std::fstream& _in, BaseImporter& _bi, bool /*_swap*/) const _OFFReader_::read_binary(std::istream& _in, BaseImporter& _bi, bool /*_swap*/) const
{ {
omlog() << "[OFFReader] : read binary file\n"; omlog() << "[OFFReader] : read binary file\n";

View File

@@ -130,19 +130,18 @@ public:
bool can_u_read(const std::string& _filename) const; bool can_u_read(const std::string& _filename) const;
bool read(std::istream& _in, BaseImporter& _bi, Options& _opt );
private: private:
bool can_u_read(std::istream& _is) const; bool can_u_read(std::istream& _is) const;
bool read(std::fstream& _in, BaseImporter& _bi, Options& _opt ) const; bool read_ascii(std::istream& _in, BaseImporter& _bi) const;
bool read_ascii(std::fstream& _in, BaseImporter& _bi) const; bool read_binary(std::istream& _in, BaseImporter& _bi, bool swap) const;
bool read_binary(std::fstream& _in, BaseImporter& _bi, bool swap) const;
void readValue(std::fstream& _in, float& _value) const; void readValue(std::istream& _in, float& _value) const;
void readValue(std::fstream& _in, int& _value) const; void readValue(std::istream& _in, int& _value) const;
void readValue(std::fstream& _in, unsigned int& _value) const; void readValue(std::istream& _in, unsigned int& _value) const;
int getColorType(std::string & _line, bool _texCoordsAvailable) const; int getColorType(std::string & _line, bool _texCoordsAvailable) const;

View File

@@ -95,7 +95,7 @@ _OMReader_::read(const std::string& _filename,
// Open file // Open file
std::ifstream ifs( _filename.c_str(), std::ios::binary ); std::ifstream ifs( _filename.c_str(), std::ios::binary );
if (!ifs.is_open()) if (!ifs.is_open() || !ifs.good())
{ {
omerr() << "[OMReader] : cannot not open file " omerr() << "[OMReader] : cannot not open file "
<< _filename << _filename
@@ -112,17 +112,33 @@ _OMReader_::read(const std::string& _filename,
return result; return result;
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
bool bool
_OMReader_::read(std::istream& _is, BaseImporter& _bi, Options& _opt ) const _OMReader_::read(std::istream& _is,
BaseImporter& _bi,
Options& _opt)
{ {
// currently only binary file format is supported // check whether importer can give us an OpenMesh BaseKernel
_opt += Options::Binary; if (!_bi.kernel()) return false;
return read_binary( _is, _bi, _opt );
_opt += Options::Binary; // only binary format supported!
if (!_is.good())
{
omerr() << "[OMReader] : cannot read from stream "
<< std::endl;
return false;
}
// Pass stream to read method, remember result
bool result = read_binary(_is, _bi, _opt);
if(result) _opt += Options::Binary;
return result;
} }

View File

@@ -95,6 +95,11 @@ public:
BaseImporter& _bi, BaseImporter& _bi,
Options& _opt ); Options& _opt );
//! Stream Reader for std::istream input in binary format
bool read(std::istream& _is,
BaseImporter& _bi,
Options& _opt );
virtual bool can_u_read(const std::string& _filename) const; virtual bool can_u_read(const std::string& _filename) const;
virtual bool can_u_read(std::istream& _is) const; virtual bool can_u_read(std::istream& _is) const;
@@ -103,7 +108,6 @@ private:
bool supports( const OMFormat::uint8 version ) const; bool supports( const OMFormat::uint8 version ) const;
bool read(std::istream& _is, BaseImporter& _bi, Options& _opt ) const;
bool read_ascii(std::istream& _is, BaseImporter& _bi, Options& _opt) const; bool read_ascii(std::istream& _is, BaseImporter& _bi, Options& _opt) const;
bool read_binary(std::istream& _is, BaseImporter& _bi, Options& _opt) const; bool read_binary(std::istream& _is, BaseImporter& _bi, Options& _opt) const;

View File

@@ -87,10 +87,11 @@ _PLYReader_::_PLYReader_() {
bool _PLYReader_::read(const std::string& _filename, BaseImporter& _bi, Options& _opt) { bool _PLYReader_::read(const std::string& _filename, BaseImporter& _bi, Options& _opt) {
std::fstream in(_filename.c_str(), (options_.is_binary() ? std::ios_base::binary | std::ios_base::in std::fstream in(_filename.c_str(), (options_.is_binary() ? std::ios_base::binary | std::ios_base::in
: std::ios_base::in)); : std::ios_base::in));
if (!in) { if (!in.is_open() || !in.good()) {
omerr() << "[PLYReader] : cannot not open file " << _filename << std::endl; omerr() << "[PLYReader] : cannot not open file " << _filename << std::endl;
return false; return false;
} }
@@ -104,7 +105,13 @@ bool _PLYReader_::read(const std::string& _filename, BaseImporter& _bi, Options&
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
bool _PLYReader_::read(std::fstream& _in, BaseImporter& _bi, Options& _opt) const { bool _PLYReader_::read(std::istream& _in, BaseImporter& _bi, Options& _opt) {
if (!_in.good()) {
omerr() << "[PLYReader] : cannot not use stream" << std::endl;
return false;
}
// filter relevant options for reading // filter relevant options for reading
bool swap = _opt.check(Options::Swap); bool swap = _opt.check(Options::Swap);
@@ -137,9 +144,11 @@ bool _PLYReader_::read(std::fstream& _in, BaseImporter& _bi, Options& _opt) cons
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
bool _PLYReader_::read_ascii(std::fstream& _in, BaseImporter& _bi) const { bool _PLYReader_::read_ascii(std::istream& _in, BaseImporter& _bi) const {
omlog() << "[PLYReader] : read ascii file\n"; omlog() << "[PLYReader] : read ascii file\n";
@@ -269,7 +278,7 @@ bool _PLYReader_::read_ascii(std::fstream& _in, BaseImporter& _bi) const {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
bool _PLYReader_::read_binary(std::fstream& _in, BaseImporter& _bi, bool /*_swap*/) const { bool _PLYReader_::read_binary(std::istream& _in, BaseImporter& _bi, bool /*_swap*/) const {
omlog() << "[PLYReader] : read binary file format\n"; omlog() << "[PLYReader] : read binary file format\n";
@@ -394,7 +403,7 @@ bool _PLYReader_::read_binary(std::fstream& _in, BaseImporter& _bi, bool /*_swap
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void _PLYReader_::readValue(ValueType _type, std::fstream& _in, float& _value) const { void _PLYReader_::readValue(ValueType _type, std::istream& _in, float& _value) const {
switch (_type) { switch (_type) {
case ValueTypeFLOAT32: case ValueTypeFLOAT32:
@@ -410,7 +419,7 @@ void _PLYReader_::readValue(ValueType _type, std::fstream& _in, float& _value) c
} }
} }
void _PLYReader_::readValue(ValueType _type, std::fstream& _in, unsigned int& _value) const { void _PLYReader_::readValue(ValueType _type, std::istream& _in, unsigned int& _value) const {
int32_t tmp_int32_t; int32_t tmp_int32_t;
uint8_t tmp_uchar; uint8_t tmp_uchar;
@@ -432,7 +441,7 @@ void _PLYReader_::readValue(ValueType _type, std::fstream& _in, unsigned int& _v
} }
} }
void _PLYReader_::readValue(ValueType _type, std::fstream& _in, int& _value) const { void _PLYReader_::readValue(ValueType _type, std::istream& _in, int& _value) const {
int32_t tmp_int32_t; int32_t tmp_int32_t;
uint8_t tmp_uchar; uint8_t tmp_uchar;

View File

@@ -103,6 +103,10 @@ public:
BaseImporter& _bi, BaseImporter& _bi,
Options& _opt); Options& _opt);
bool read(std::istream& _is,
BaseImporter& _bi,
Options& _opt);
bool can_u_read(const std::string& _filename) const; bool can_u_read(const std::string& _filename) const;
enum ValueType { enum ValueType {
@@ -116,15 +120,14 @@ private:
bool can_u_read(std::istream& _is) const; bool can_u_read(std::istream& _is) const;
bool read(std::fstream& _in, BaseImporter& _bi, Options& _opt ) const; bool read_ascii(std::istream& _in, BaseImporter& _bi) const;
bool read_ascii(std::fstream& _in, BaseImporter& _bi) const; bool read_binary(std::istream& _in, BaseImporter& _bi, bool swap) const;
bool read_binary(std::fstream& _in, BaseImporter& _bi, bool swap) const;
float readToFloatValue(ValueType _type , std::fstream& _in) const; float readToFloatValue(ValueType _type , std::fstream& _in) const;
void readValue(ValueType _type , std::fstream& _in, float& _value) const; void readValue(ValueType _type , std::istream& _in, float& _value) const;
void readValue(ValueType _type , std::fstream& _in, unsigned int& _value) const; void readValue(ValueType _type , std::istream& _in, unsigned int& _value) const;
void readValue(ValueType _type , std::fstream& _in, int& _value) const; void readValue(ValueType _type , std::istream& _in, int& _value) const;
//available options for reading //available options for reading
mutable Options options_; mutable Options options_;

View File

@@ -137,6 +137,17 @@ read(const std::string& _filename, BaseImporter& _bi, Options& _opt)
return result; return result;
} }
bool
_STLReader_::read(std::istream& _is,
BaseImporter& _bi,
Options& _opt)
{
omerr() << "[OMReader] : STL Streams are not supported " << std::endl;
return false;
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@@ -178,7 +189,6 @@ read_stla(const std::string& _filename, BaseImporter& _bi) const
{ {
omlog() << "[STLReader] : read ascii file\n"; omlog() << "[STLReader] : read ascii file\n";
FILE* in = fopen(_filename.c_str(), "r"); FILE* in = fopen(_filename.c_str(), "r");
if (!in) if (!in)
{ {
@@ -254,7 +264,6 @@ read_stlb(const std::string& _filename, BaseImporter& _bi) const
{ {
omlog() << "[STLReader] : read binary file\n"; omlog() << "[STLReader] : read binary file\n";
FILE* in = fopen(_filename.c_str(), "rb"); FILE* in = fopen(_filename.c_str(), "rb");
if (!in) if (!in)
{ {

View File

@@ -102,6 +102,9 @@ public:
BaseImporter& _bi, BaseImporter& _bi,
Options& _opt); Options& _opt);
bool read(std::istream& _in,
BaseImporter& _bi,
Options& _opt);
/** Set the threshold to be used for considering two point to be equal. /** Set the threshold to be used for considering two point to be equal.
Can be used to merge small gaps */ Can be used to merge small gaps */

View File

@@ -99,7 +99,12 @@ 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) 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. /// 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; }

View File

@@ -149,7 +149,7 @@ int _OBJWriter_::getMaterial(OpenMesh::Vec4f _color) const
bool bool
_OBJWriter_:: _OBJWriter_::
writeMaterial(std::fstream& _out, BaseExporter& _be, Options _opt) const writeMaterial(std::ostream& _out, BaseExporter& _be, Options _opt) const
{ {
OpenMesh::Vec3f c; OpenMesh::Vec3f c;
OpenMesh::Vec4f cA; OpenMesh::Vec4f cA;
@@ -196,7 +196,7 @@ writeMaterial(std::fstream& _out, BaseExporter& _be, Options _opt) const
bool bool
_OBJWriter_:: _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; unsigned int i, j, nV, nF, idx;
Vec3f v, n; Vec3f v, n;

View File

@@ -91,6 +91,8 @@ public:
bool write(const std::string&, BaseExporter&, Options) const; bool write(const std::string&, BaseExporter&, Options) const;
bool write(std::ostream&, BaseExporter&, Options) const;
size_t binary_size(BaseExporter&, Options) const { return 0; } size_t binary_size(BaseExporter&, Options) const { return 0; }
private: private:
@@ -105,9 +107,9 @@ private:
int getMaterial(OpenMesh::Vec4f _color) const; 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;
}; };

View File

@@ -121,13 +121,56 @@ write(const std::string& _filename, BaseExporter& _be, Options _opt) const
return result; 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 bool
_OFFWriter_:: _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"; 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; uint32_t tmp = value;
store(_out, tmp, false); 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; uint32_t tmp = value;
store(_out, tmp, false); 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; float32_t tmp = value;
store(_out, tmp, false); store(_out, tmp, false);
@@ -264,7 +307,7 @@ void _OFFWriter_::writeValue(std::fstream& _out, float value) const {
bool bool
_OFFWriter_:: _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"; omlog() << "[OFFWriter] : write ascii file\n";

View File

@@ -102,16 +102,18 @@ public:
bool write(const std::string&, BaseExporter&, Options) const; bool write(const std::string&, BaseExporter&, Options) const;
bool write(std::ostream&, BaseExporter&, Options) const;
size_t binary_size(BaseExporter& _be, Options _opt) const; size_t binary_size(BaseExporter& _be, Options _opt) const;
protected: protected:
void writeValue(std::fstream& _out, int value) const; void writeValue(std::ostream& _out, int value) const;
void writeValue(std::fstream& _out, unsigned int value) const; void writeValue(std::ostream& _out, unsigned int value) const;
void writeValue(std::fstream& _out, float value) const; void writeValue(std::ostream& _out, float value) const;
bool write_ascii(std::fstream& _in, BaseExporter&, Options) const; bool write_ascii(std::ostream& _in, BaseExporter&, Options) const;
bool write_binary(std::fstream& _in, BaseExporter&, Options) const; bool write_binary(std::ostream& _in, BaseExporter&, Options) const;
}; };

View File

@@ -105,6 +105,7 @@ public:
bool write(std::ostream&, BaseExporter&, Options) const; bool write(std::ostream&, BaseExporter&, Options) const;
size_t binary_size(BaseExporter& _be, Options _opt) const; size_t binary_size(BaseExporter& _be, Options _opt) const;
@@ -117,6 +118,7 @@ protected:
bool write_binary(std::ostream&, BaseExporter&, Options) const; bool write_binary(std::ostream&, BaseExporter&, Options) const;
size_t store_binary_custom_chunk( std::ostream&, const BaseProperty&, size_t store_binary_custom_chunk( std::ostream&, const BaseProperty&,
OMFormat::Chunk::Entity, bool) const; OMFormat::Chunk::Entity, bool) const;
}; };

View File

@@ -112,13 +112,47 @@ write(const std::string& _filename, BaseExporter& _be, Options _opt) const
return result; 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 bool
_PLYWriter_:: _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"; 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; uint32_t tmp32;
uint8_t tmp8; 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; uint32_t tmp32;
uint8_t tmp8; 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; float32_t tmp;
@@ -310,7 +344,7 @@ void _PLYWriter_::writeValue(ValueType _type, std::fstream& _out, float value) c
bool bool
_PLYWriter_:: _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"; omlog() << "[PLYWriter] : write binary file\n";

View File

@@ -97,6 +97,8 @@ public:
bool write(const std::string&, BaseExporter&, Options) const; bool write(const std::string&, BaseExporter&, Options) const;
bool write(std::ostream&, BaseExporter&, Options) const;
size_t binary_size(BaseExporter& _be, Options _opt) const; size_t binary_size(BaseExporter& _be, Options _opt) const;
enum ValueType { enum ValueType {
@@ -110,12 +112,12 @@ private:
mutable Options options_; mutable Options options_;
protected: protected:
void writeValue(ValueType _type, std::fstream& _out, int value) const; void writeValue(ValueType _type, std::ostream& _out, int value) const;
void writeValue(ValueType _type, std::fstream& _out, unsigned int value) const; void writeValue(ValueType _type, std::ostream& _out, unsigned int value) const;
void writeValue(ValueType _type, std::fstream& _out, float value) const; void writeValue(ValueType _type, std::ostream& _out, float value) const;
bool write_ascii(std::fstream& _in, BaseExporter&, Options) const; bool write_ascii(std::ostream& _in, BaseExporter&, Options) const;
bool write_binary(std::fstream& _in, BaseExporter&, Options) const; bool write_binary(std::ostream& _in, BaseExporter&, Options) const;
}; };

View File

@@ -113,6 +113,17 @@ write(const std::string& _filename, BaseExporter& _be, Options _opt) const
return false; return false;
} }
//-----------------------------------------------------------------------------
bool
_STLWriter_::
write(std::ostream& _os, BaseExporter& _be, Options _opt) const
{
omerr() << "[STLWriter] : STL Streams are not supported " << std::endl;
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------

View File

@@ -95,6 +95,8 @@ public:
bool write(const std::string&, BaseExporter&, Options) const; bool write(const std::string&, BaseExporter&, Options) const;
bool write(std::ostream&, BaseExporter&, Options) const;
size_t binary_size(BaseExporter&, Options) const; size_t binary_size(BaseExporter&, Options) const;
private: private: