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:
@@ -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
|
||||
_IOManager_::
|
||||
write(const std::string& _filename, BaseExporter& _be, Options _opt)
|
||||
@@ -128,6 +153,34 @@ write(const std::string& _filename, BaseExporter& _be, Options _opt)
|
||||
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;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -118,6 +118,16 @@ public:
|
||||
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
|
||||
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
|
||||
@@ -130,6 +140,16 @@ public:
|
||||
BaseExporter& _be,
|
||||
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.
|
||||
|
||||
@@ -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>
|
||||
size_t binary_size(const Mesh& _mesh, const std::string& _format,
|
||||
Options _opt = Options::Default)
|
||||
|
||||
@@ -111,6 +111,14 @@ public:
|
||||
BaseImporter& _bi,
|
||||
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)
|
||||
virtual bool can_u_read(const std::string& _filename) const;
|
||||
|
||||
@@ -112,7 +112,7 @@ read(const std::string& _filename, BaseImporter& _bi, Options& _opt)
|
||||
{
|
||||
std::fstream in( _filename.c_str(), std::ios_base::in );
|
||||
|
||||
if (!in)
|
||||
if (!in.is_open() || !in.good())
|
||||
{
|
||||
omerr() << "[OBJReader] : cannot not open file "
|
||||
<< _filename
|
||||
@@ -137,7 +137,6 @@ read(const std::string& _filename, BaseImporter& _bi, Options& _opt)
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
bool
|
||||
@@ -264,7 +263,7 @@ read_material(std::fstream& _in)
|
||||
|
||||
bool
|
||||
_OBJReader_::
|
||||
read(std::fstream& _in, BaseImporter& _bi, Options& _opt)
|
||||
read(std::istream& _in, BaseImporter& _bi, Options& _opt)
|
||||
{
|
||||
omlog() << "[OBJReader] : read file\n";
|
||||
|
||||
|
||||
@@ -94,6 +94,10 @@ public:
|
||||
BaseImporter& _bi,
|
||||
Options& _opt);
|
||||
|
||||
bool read(std::istream& _in,
|
||||
BaseImporter& _bi,
|
||||
Options& _opt);
|
||||
|
||||
private:
|
||||
|
||||
#ifndef DOXY_IGNORE_THIS
|
||||
@@ -163,8 +167,6 @@ private:
|
||||
|
||||
private:
|
||||
|
||||
bool read(std::fstream& _in, BaseImporter& _bi, Options& _opt);
|
||||
|
||||
std::string path_;
|
||||
|
||||
};
|
||||
|
||||
@@ -57,6 +57,8 @@
|
||||
#include <OpenMesh/Core/IO/SR_store.hh>
|
||||
|
||||
//STL
|
||||
#include <iostream>
|
||||
#include <ios>
|
||||
#include <fstream>
|
||||
#include <memory>
|
||||
|
||||
@@ -97,32 +99,39 @@ bool
|
||||
_OFFReader_::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::ios_base::in) );
|
||||
std::ifstream ifile(_filename.c_str(), (options_.is_binary() ? std::ios::binary | std::ios::in
|
||||
: std::ios::in) );
|
||||
|
||||
if (!in)
|
||||
if (!ifile.is_open() || !ifile.good())
|
||||
{
|
||||
omerr() << "[OFFReader] : cannot not open file "
|
||||
<< _filename
|
||||
<< std::endl;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
assert(ifile);
|
||||
|
||||
bool result = read(in, _bi, _opt);
|
||||
bool result = read(ifile, _bi, _opt);
|
||||
|
||||
|
||||
in.close();
|
||||
ifile.close();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
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
|
||||
bool swap = _opt.check( Options::Swap );
|
||||
|
||||
@@ -153,7 +162,7 @@ _OFFReader_::read(std::fstream& _in, BaseImporter& _bi, Options& _opt ) const
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
void _OFFReader_::readValue(std::fstream& _in, float& _value) const{
|
||||
void _OFFReader_::readValue(std::istream& _in, float& _value) const{
|
||||
float32_t tmp;
|
||||
|
||||
restore( _in , tmp, false ); //assuming LSB byte order
|
||||
_value = tmp;
|
||||
}
|
||||
|
||||
void _OFFReader_::readValue(std::fstream& _in, int& _value) const{
|
||||
void _OFFReader_::readValue(std::istream& _in, int& _value) const{
|
||||
uint32_t tmp;
|
||||
|
||||
restore( _in , tmp, false ); //assuming LSB byte order
|
||||
_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;
|
||||
|
||||
restore( _in , tmp, false ); //assuming LSB byte order
|
||||
@@ -402,7 +411,7 @@ void _OFFReader_::readValue(std::fstream& _in, unsigned int& _value) const{
|
||||
}
|
||||
|
||||
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";
|
||||
|
||||
|
||||
@@ -130,19 +130,18 @@ public:
|
||||
|
||||
bool can_u_read(const std::string& _filename) const;
|
||||
|
||||
|
||||
bool read(std::istream& _in, BaseImporter& _bi, Options& _opt );
|
||||
|
||||
private:
|
||||
|
||||
bool can_u_read(std::istream& _is) const;
|
||||
|
||||
bool read(std::fstream& _in, BaseImporter& _bi, Options& _opt ) const;
|
||||
bool read_ascii(std::fstream& _in, BaseImporter& _bi) const;
|
||||
bool read_binary(std::fstream& _in, BaseImporter& _bi, bool swap) const;
|
||||
bool read_ascii(std::istream& _in, BaseImporter& _bi) const;
|
||||
bool read_binary(std::istream& _in, BaseImporter& _bi, bool swap) const;
|
||||
|
||||
void readValue(std::fstream& _in, float& _value) const;
|
||||
void readValue(std::fstream& _in, int& _value) const;
|
||||
void readValue(std::fstream& _in, unsigned int& _value) const;
|
||||
void readValue(std::istream& _in, float& _value) const;
|
||||
void readValue(std::istream& _in, int& _value) const;
|
||||
void readValue(std::istream& _in, unsigned int& _value) const;
|
||||
|
||||
int getColorType(std::string & _line, bool _texCoordsAvailable) const;
|
||||
|
||||
|
||||
@@ -95,7 +95,7 @@ _OMReader_::read(const std::string& _filename,
|
||||
|
||||
// Open file
|
||||
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 "
|
||||
<< _filename
|
||||
@@ -112,17 +112,33 @@ _OMReader_::read(const std::string& _filename,
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
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
|
||||
_opt += Options::Binary;
|
||||
// check whether importer can give us an OpenMesh BaseKernel
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -95,6 +95,11 @@ public:
|
||||
BaseImporter& _bi,
|
||||
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(std::istream& _is) const;
|
||||
|
||||
@@ -103,7 +108,6 @@ private:
|
||||
|
||||
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_binary(std::istream& _is, BaseImporter& _bi, Options& _opt) const;
|
||||
|
||||
|
||||
@@ -87,10 +87,11 @@ _PLYReader_::_PLYReader_() {
|
||||
|
||||
|
||||
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::ios_base::in));
|
||||
|
||||
if (!in) {
|
||||
if (!in.is_open() || !in.good()) {
|
||||
omerr() << "[PLYReader] : cannot not open file " << _filename << std::endl;
|
||||
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
|
||||
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";
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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) {
|
||||
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;
|
||||
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;
|
||||
uint8_t tmp_uchar;
|
||||
|
||||
@@ -103,6 +103,10 @@ public:
|
||||
BaseImporter& _bi,
|
||||
Options& _opt);
|
||||
|
||||
bool read(std::istream& _is,
|
||||
BaseImporter& _bi,
|
||||
Options& _opt);
|
||||
|
||||
bool can_u_read(const std::string& _filename) const;
|
||||
|
||||
enum ValueType {
|
||||
@@ -116,15 +120,14 @@ private:
|
||||
|
||||
bool can_u_read(std::istream& _is) const;
|
||||
|
||||
bool read(std::fstream& _in, BaseImporter& _bi, Options& _opt ) const;
|
||||
bool read_ascii(std::fstream& _in, BaseImporter& _bi) const;
|
||||
bool read_binary(std::fstream& _in, BaseImporter& _bi, bool swap) const;
|
||||
bool read_ascii(std::istream& _in, BaseImporter& _bi) const;
|
||||
bool read_binary(std::istream& _in, BaseImporter& _bi, bool swap) const;
|
||||
|
||||
float readToFloatValue(ValueType _type , std::fstream& _in) const;
|
||||
|
||||
void readValue(ValueType _type , std::fstream& _in, float& _value) const;
|
||||
void readValue(ValueType _type , std::fstream& _in, unsigned int& _value) const;
|
||||
void readValue(ValueType _type , std::fstream& _in, int& _value) const;
|
||||
void readValue(ValueType _type , std::istream& _in, float& _value) const;
|
||||
void readValue(ValueType _type , std::istream& _in, unsigned int& _value) const;
|
||||
void readValue(ValueType _type , std::istream& _in, int& _value) const;
|
||||
|
||||
//available options for reading
|
||||
mutable Options options_;
|
||||
|
||||
@@ -137,6 +137,17 @@ read(const std::string& _filename, BaseImporter& _bi, Options& _opt)
|
||||
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";
|
||||
|
||||
|
||||
FILE* in = fopen(_filename.c_str(), "r");
|
||||
if (!in)
|
||||
{
|
||||
@@ -254,7 +264,6 @@ read_stlb(const std::string& _filename, BaseImporter& _bi) const
|
||||
{
|
||||
omlog() << "[STLReader] : read binary file\n";
|
||||
|
||||
|
||||
FILE* in = fopen(_filename.c_str(), "rb");
|
||||
if (!in)
|
||||
{
|
||||
|
||||
@@ -102,6 +102,9 @@ public:
|
||||
BaseImporter& _bi,
|
||||
Options& _opt);
|
||||
|
||||
bool read(std::istream& _in,
|
||||
BaseImporter& _bi,
|
||||
Options& _opt);
|
||||
|
||||
/** Set the threshold to be used for considering two point to be equal.
|
||||
Can be used to merge small gaps */
|
||||
|
||||
@@ -101,6 +101,11 @@ public:
|
||||
BaseExporter& _be,
|
||||
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;
|
||||
|
||||
@@ -91,6 +91,8 @@ public:
|
||||
|
||||
bool write(const std::string&, BaseExporter&, Options) const;
|
||||
|
||||
bool write(std::ostream&, BaseExporter&, Options) const;
|
||||
|
||||
size_t binary_size(BaseExporter&, Options) const { return 0; }
|
||||
|
||||
private:
|
||||
@@ -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";
|
||||
|
||||
|
||||
@@ -102,16 +102,18 @@ 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;
|
||||
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -105,6 +105,7 @@ public:
|
||||
bool write(std::ostream&, BaseExporter&, Options) const;
|
||||
|
||||
|
||||
|
||||
size_t binary_size(BaseExporter& _be, Options _opt) const;
|
||||
|
||||
|
||||
@@ -117,6 +118,7 @@ protected:
|
||||
|
||||
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