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
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -129,7 +139,17 @@ public:
|
|||||||
bool write(const std::string& _filename,
|
bool write(const std::string& _filename,
|
||||||
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.
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
@@ -110,6 +110,14 @@ public:
|
|||||||
virtual bool read(const std::string& _filename,
|
virtual bool read(const std::string& _filename,
|
||||||
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)
|
||||||
|
|||||||
@@ -4,10 +4,10 @@
|
|||||||
* Copyright (C) 2001-2009 by Computer Graphics Group, RWTH Aachen *
|
* Copyright (C) 2001-2009 by Computer Graphics Group, RWTH Aachen *
|
||||||
* www.openmesh.org *
|
* www.openmesh.org *
|
||||||
* *
|
* *
|
||||||
*---------------------------------------------------------------------------*
|
*---------------------------------------------------------------------------*
|
||||||
* This file is part of OpenMesh. *
|
* 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 *
|
* it under the terms of the GNU Lesser General Public License as *
|
||||||
* published by the Free Software Foundation, either version 3 of *
|
* published by the Free Software Foundation, either version 3 of *
|
||||||
* the License, or (at your option) any later version with the *
|
* the License, or (at your option) any later version with the *
|
||||||
@@ -30,10 +30,10 @@
|
|||||||
* License along with OpenMesh. If not, *
|
* License along with OpenMesh. If not, *
|
||||||
* see <http://www.gnu.org/licenses/>. *
|
* see <http://www.gnu.org/licenses/>. *
|
||||||
* *
|
* *
|
||||||
\*===========================================================================*/
|
\*===========================================================================*/
|
||||||
|
|
||||||
/*===========================================================================*\
|
/*===========================================================================*\
|
||||||
* *
|
* *
|
||||||
* $Revision$ *
|
* $Revision$ *
|
||||||
* $Date$ *
|
* $Date$ *
|
||||||
* *
|
* *
|
||||||
@@ -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";
|
||||||
|
|
||||||
|
|||||||
@@ -4,10 +4,10 @@
|
|||||||
* Copyright (C) 2001-2009 by Computer Graphics Group, RWTH Aachen *
|
* Copyright (C) 2001-2009 by Computer Graphics Group, RWTH Aachen *
|
||||||
* www.openmesh.org *
|
* www.openmesh.org *
|
||||||
* *
|
* *
|
||||||
*---------------------------------------------------------------------------*
|
*---------------------------------------------------------------------------*
|
||||||
* This file is part of OpenMesh. *
|
* 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 *
|
* it under the terms of the GNU Lesser General Public License as *
|
||||||
* published by the Free Software Foundation, either version 3 of *
|
* published by the Free Software Foundation, either version 3 of *
|
||||||
* the License, or (at your option) any later version with the *
|
* the License, or (at your option) any later version with the *
|
||||||
@@ -30,10 +30,10 @@
|
|||||||
* License along with OpenMesh. If not, *
|
* License along with OpenMesh. If not, *
|
||||||
* see <http://www.gnu.org/licenses/>. *
|
* see <http://www.gnu.org/licenses/>. *
|
||||||
* *
|
* *
|
||||||
\*===========================================================================*/
|
\*===========================================================================*/
|
||||||
|
|
||||||
/*===========================================================================*\
|
/*===========================================================================*\
|
||||||
* *
|
* *
|
||||||
* $Revision$ *
|
* $Revision$ *
|
||||||
* $Date$ *
|
* $Date$ *
|
||||||
* *
|
* *
|
||||||
@@ -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_;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -4,10 +4,10 @@
|
|||||||
* Copyright (C) 2001-2009 by Computer Graphics Group, RWTH Aachen *
|
* Copyright (C) 2001-2009 by Computer Graphics Group, RWTH Aachen *
|
||||||
* www.openmesh.org *
|
* www.openmesh.org *
|
||||||
* *
|
* *
|
||||||
*---------------------------------------------------------------------------*
|
*---------------------------------------------------------------------------*
|
||||||
* This file is part of OpenMesh. *
|
* 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 *
|
* it under the terms of the GNU Lesser General Public License as *
|
||||||
* published by the Free Software Foundation, either version 3 of *
|
* published by the Free Software Foundation, either version 3 of *
|
||||||
* the License, or (at your option) any later version with the *
|
* the License, or (at your option) any later version with the *
|
||||||
@@ -30,10 +30,10 @@
|
|||||||
* License along with OpenMesh. If not, *
|
* License along with OpenMesh. If not, *
|
||||||
* see <http://www.gnu.org/licenses/>. *
|
* see <http://www.gnu.org/licenses/>. *
|
||||||
* *
|
* *
|
||||||
\*===========================================================================*/
|
\*===========================================================================*/
|
||||||
|
|
||||||
/*===========================================================================*\
|
/*===========================================================================*\
|
||||||
* *
|
* *
|
||||||
* $Revision$ *
|
* $Revision$ *
|
||||||
* $Date$ *
|
* $Date$ *
|
||||||
* *
|
* *
|
||||||
@@ -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>
|
||||||
|
|
||||||
@@ -84,48 +86,55 @@ _OFFReader_& OFFReader() { return __OFFReaderInstance; }
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
_OFFReader_::_OFFReader_()
|
_OFFReader_::_OFFReader_()
|
||||||
{
|
{
|
||||||
IOManager().register_module(this);
|
IOManager().register_module(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
bool
|
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 );
|
||||||
|
|
||||||
|
|
||||||
userOptions_ = _opt;
|
userOptions_ = _opt;
|
||||||
|
|
||||||
@@ -152,13 +161,13 @@ _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
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
omlog() << "[OFFReader] : read ascii file\n";
|
omlog() << "[OFFReader] : read ascii file\n";
|
||||||
|
|
||||||
unsigned int i, j, k, l, idx;
|
unsigned int i, j, k, l, idx;
|
||||||
unsigned int nV, nF, dummy;
|
unsigned int nV, nF, dummy;
|
||||||
OpenMesh::Vec3f v, n;
|
OpenMesh::Vec3f v, n;
|
||||||
@@ -186,9 +195,9 @@ omlog() << "[OFFReader] : read ascii file\n";
|
|||||||
{
|
{
|
||||||
// Always read VERTEX
|
// Always read VERTEX
|
||||||
_in >> v[0]; _in >> v[1]; _in >> v[2];
|
_in >> v[0]; _in >> v[1]; _in >> v[2];
|
||||||
|
|
||||||
vh = _bi.add_vertex(v);
|
vh = _bi.add_vertex(v);
|
||||||
|
|
||||||
//perhaps read NORMAL
|
//perhaps read NORMAL
|
||||||
if ( options_.vertex_has_normal() ){
|
if ( options_.vertex_has_normal() ){
|
||||||
|
|
||||||
@@ -236,7 +245,7 @@ omlog() << "[OFFReader] : read ascii file\n";
|
|||||||
_bi.set_color( vh, color_cast<Vec4uc, Vec4f>(c4f) );
|
_bi.set_color( vh, color_cast<Vec4uc, Vec4f>(c4f) );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
std::cerr << "Error in file format (colorType = " << colorType << ")\n";
|
std::cerr << "Error in file format (colorType = " << colorType << ")\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -266,7 +275,7 @@ omlog() << "[OFFReader] : read ascii file\n";
|
|||||||
vhandles[1] = VertexHandle(k);
|
vhandles[1] = VertexHandle(k);
|
||||||
vhandles[2] = VertexHandle(l);
|
vhandles[2] = VertexHandle(l);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
vhandles.clear();
|
vhandles.clear();
|
||||||
for (j=0; j<nV; ++j)
|
for (j=0; j<nV; ++j)
|
||||||
@@ -275,7 +284,7 @@ omlog() << "[OFFReader] : read ascii file\n";
|
|||||||
vhandles.push_back(VertexHandle(idx));
|
vhandles.push_back(VertexHandle(idx));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FaceHandle fh = _bi.add_face(vhandles);
|
FaceHandle fh = _bi.add_face(vhandles);
|
||||||
|
|
||||||
//perhaps read face COLOR
|
//perhaps read face COLOR
|
||||||
@@ -287,7 +296,7 @@ omlog() << "[OFFReader] : read ascii file\n";
|
|||||||
|
|
||||||
int colorType = getColorType(line, false );
|
int colorType = getColorType(line, false );
|
||||||
|
|
||||||
std::stringstream stream( line );
|
std::stringstream stream( line );
|
||||||
|
|
||||||
std::string trash;
|
std::string trash;
|
||||||
|
|
||||||
@@ -316,7 +325,7 @@ omlog() << "[OFFReader] : read ascii file\n";
|
|||||||
_bi.set_color( fh, color_cast<Vec4uc, Vec4f>(c4f) );
|
_bi.set_color( fh, color_cast<Vec4uc, Vec4f>(c4f) );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
std::cerr << "Error in file format (colorType = " << colorType << ")\n";
|
std::cerr << "Error in file format (colorType = " << colorType << ")\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -369,7 +378,7 @@ int _OFFReader_::getColorType(std::string& _line, bool _texCoordsAvailable) cons
|
|||||||
//get first item
|
//get first item
|
||||||
found = _line.find(" ");
|
found = _line.find(" ");
|
||||||
std::string c1 = _line.substr (0,found);
|
std::string c1 = _line.substr (0,found);
|
||||||
|
|
||||||
if (c1.find(".") != std::string::npos){
|
if (c1.find(".") != std::string::npos){
|
||||||
if (count == 3)
|
if (count == 3)
|
||||||
count = 5;
|
count = 5;
|
||||||
@@ -380,32 +389,32 @@ 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
|
||||||
_value = tmp;
|
_value = tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
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";
|
||||||
|
|
||||||
unsigned int i, j, k, l, idx;
|
unsigned int i, j, k, l, idx;
|
||||||
unsigned int nV, nF, dummy;
|
unsigned int nV, nF, dummy;
|
||||||
OpenMesh::Vec3f v, n;
|
OpenMesh::Vec3f v, n;
|
||||||
@@ -426,16 +435,16 @@ _OFFReader_::read_binary(std::fstream& _in, BaseImporter& _bi, bool /*_swap*/) c
|
|||||||
|
|
||||||
_bi.reserve(nV, 3*nV, nF);
|
_bi.reserve(nV, 3*nV, nF);
|
||||||
|
|
||||||
// read vertices: coord [hcoord] [normal] [color] [texcoord]
|
// read vertices: coord [hcoord] [normal] [color] [texcoord]
|
||||||
for (i=0; i<nV && !_in.eof(); ++i)
|
for (i=0; i<nV && !_in.eof(); ++i)
|
||||||
{
|
{
|
||||||
// Always read Vertex
|
// Always read Vertex
|
||||||
readValue(_in, v[0]);
|
readValue(_in, v[0]);
|
||||||
readValue(_in, v[1]);
|
readValue(_in, v[1]);
|
||||||
readValue(_in, v[2]);
|
readValue(_in, v[2]);
|
||||||
|
|
||||||
vh = _bi.add_vertex(v);
|
vh = _bi.add_vertex(v);
|
||||||
|
|
||||||
if ( options_.vertex_has_normal() ) {
|
if ( options_.vertex_has_normal() ) {
|
||||||
readValue(_in, n[0]);
|
readValue(_in, n[0]);
|
||||||
readValue(_in, n[1]);
|
readValue(_in, n[1]);
|
||||||
@@ -444,7 +453,7 @@ _OFFReader_::read_binary(std::fstream& _in, BaseImporter& _bi, bool /*_swap*/) c
|
|||||||
if ( userOptions_.vertex_has_normal() )
|
if ( userOptions_.vertex_has_normal() )
|
||||||
_bi.set_normal(vh, n);
|
_bi.set_normal(vh, n);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( options_.vertex_has_color() ) {
|
if ( options_.vertex_has_color() ) {
|
||||||
//with alpha
|
//with alpha
|
||||||
if ( options_.color_has_alpha() ){
|
if ( options_.color_has_alpha() ){
|
||||||
@@ -465,7 +474,7 @@ _OFFReader_::read_binary(std::fstream& _in, BaseImporter& _bi, bool /*_swap*/) c
|
|||||||
_bi.set_color( vh, Vec3uc( c ) );
|
_bi.set_color( vh, Vec3uc( c ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( options_.vertex_has_texcoord()) {
|
if ( options_.vertex_has_texcoord()) {
|
||||||
readValue(_in, t[0]);
|
readValue(_in, t[0]);
|
||||||
readValue(_in, t[1]);
|
readValue(_in, t[1]);
|
||||||
@@ -474,7 +483,7 @@ _OFFReader_::read_binary(std::fstream& _in, BaseImporter& _bi, bool /*_swap*/) c
|
|||||||
_bi.set_texcoord(vh, t);
|
_bi.set_texcoord(vh, t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// faces
|
// faces
|
||||||
// #N <v1> <v2> .. <v(n-1)> [color spec]
|
// #N <v1> <v2> .. <v(n-1)> [color spec]
|
||||||
// So far color spec is unsupported!
|
// So far color spec is unsupported!
|
||||||
@@ -494,7 +503,7 @@ _OFFReader_::read_binary(std::fstream& _in, BaseImporter& _bi, bool /*_swap*/) c
|
|||||||
vhandles[1] = VertexHandle(k);
|
vhandles[1] = VertexHandle(k);
|
||||||
vhandles[2] = VertexHandle(l);
|
vhandles[2] = VertexHandle(l);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
vhandles.clear();
|
vhandles.clear();
|
||||||
for (j=0; j<nV; ++j)
|
for (j=0; j<nV; ++j)
|
||||||
@@ -503,7 +512,7 @@ _OFFReader_::read_binary(std::fstream& _in, BaseImporter& _bi, bool /*_swap*/) c
|
|||||||
vhandles.push_back(VertexHandle(idx));
|
vhandles.push_back(VertexHandle(idx));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FaceHandle fh = _bi.add_face(vhandles);
|
FaceHandle fh = _bi.add_face(vhandles);
|
||||||
|
|
||||||
//face color
|
//face color
|
||||||
@@ -550,7 +559,7 @@ bool _OFFReader_::can_u_read(const std::string& _filename) const
|
|||||||
{
|
{
|
||||||
ifs.close();
|
ifs.close();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -558,7 +567,7 @@ bool _OFFReader_::can_u_read(const std::string& _filename) const
|
|||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
bool _OFFReader_::can_u_read(std::istream& _is) const
|
bool _OFFReader_::can_u_read(std::istream& _is) const
|
||||||
{
|
{
|
||||||
options_.cleanup();
|
options_.cleanup();
|
||||||
@@ -589,7 +598,7 @@ bool _OFFReader_::can_u_read(std::istream& _is) const
|
|||||||
|
|
||||||
if ( ( remainingChars > 0 ) && ( p[0] == 'n') )
|
if ( ( remainingChars > 0 ) && ( p[0] == 'n') )
|
||||||
{ vertexDimensionTooHigh = true; ++p; --remainingChars; }
|
{ vertexDimensionTooHigh = true; ++p; --remainingChars; }
|
||||||
|
|
||||||
if ( ( remainingChars < 3 ) || (!(p[0] == 'O' && p[1] == 'F' && p[2] == 'F') ) )
|
if ( ( remainingChars < 3 ) || (!(p[0] == 'O' && p[1] == 'F' && p[2] == 'F') ) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|||||||
@@ -4,10 +4,10 @@
|
|||||||
* Copyright (C) 2001-2009 by Computer Graphics Group, RWTH Aachen *
|
* Copyright (C) 2001-2009 by Computer Graphics Group, RWTH Aachen *
|
||||||
* www.openmesh.org *
|
* www.openmesh.org *
|
||||||
* *
|
* *
|
||||||
*---------------------------------------------------------------------------*
|
*---------------------------------------------------------------------------*
|
||||||
* This file is part of OpenMesh. *
|
* 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 *
|
* it under the terms of the GNU Lesser General Public License as *
|
||||||
* published by the Free Software Foundation, either version 3 of *
|
* published by the Free Software Foundation, either version 3 of *
|
||||||
* the License, or (at your option) any later version with the *
|
* the License, or (at your option) any later version with the *
|
||||||
@@ -30,10 +30,10 @@
|
|||||||
* License along with OpenMesh. If not, *
|
* License along with OpenMesh. If not, *
|
||||||
* see <http://www.gnu.org/licenses/>. *
|
* see <http://www.gnu.org/licenses/>. *
|
||||||
* *
|
* *
|
||||||
\*===========================================================================*/
|
\*===========================================================================*/
|
||||||
|
|
||||||
/*===========================================================================*\
|
/*===========================================================================*\
|
||||||
* *
|
* *
|
||||||
* $Revision$ *
|
* $Revision$ *
|
||||||
* $Date$ *
|
* $Date$ *
|
||||||
* *
|
* *
|
||||||
@@ -83,8 +83,8 @@ class BaseImporter;
|
|||||||
//== IMPLEMENTATION ===========================================================
|
//== IMPLEMENTATION ===========================================================
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Implementation of the OFF format reader. This class is singleton'ed by
|
Implementation of the OFF format reader. This class is singleton'ed by
|
||||||
SingletonT to OFFReader.
|
SingletonT to OFFReader.
|
||||||
|
|
||||||
By passing Options to the read function you can manipulate the reading behavoir.
|
By passing Options to the read function you can manipulate the reading behavoir.
|
||||||
@@ -123,29 +123,28 @@ public:
|
|||||||
std::string get_description() const { return "Object File Format"; }
|
std::string get_description() const { return "Object File Format"; }
|
||||||
std::string get_extensions() const { return "off"; }
|
std::string get_extensions() const { return "off"; }
|
||||||
std::string get_magic() const { return "OFF"; }
|
std::string get_magic() const { return "OFF"; }
|
||||||
|
|
||||||
bool read(const std::string& _filename,
|
bool read(const std::string& _filename,
|
||||||
BaseImporter& _bi,
|
BaseImporter& _bi,
|
||||||
Options& _opt);
|
Options& _opt);
|
||||||
|
|
||||||
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::istream& _in, float& _value) const;
|
||||||
void readValue(std::fstream& _in, float& _value) const;
|
void readValue(std::istream& _in, int& _value) const;
|
||||||
void readValue(std::fstream& _in, int& _value) const;
|
void readValue(std::istream& _in, unsigned int& _value) const;
|
||||||
void readValue(std::fstream& _in, unsigned int& _value) const;
|
|
||||||
|
|
||||||
int getColorType(std::string & _line, bool _texCoordsAvailable) const;
|
int getColorType(std::string & _line, bool _texCoordsAvailable) const;
|
||||||
|
|
||||||
//available options for reading
|
//available options for reading
|
||||||
mutable Options options_;
|
mutable Options options_;
|
||||||
//options that the user wants to read
|
//options that the user wants to read
|
||||||
|
|||||||
@@ -4,10 +4,10 @@
|
|||||||
* Copyright (C) 2001-2009 by Computer Graphics Group, RWTH Aachen *
|
* Copyright (C) 2001-2009 by Computer Graphics Group, RWTH Aachen *
|
||||||
* www.openmesh.org *
|
* www.openmesh.org *
|
||||||
* *
|
* *
|
||||||
*---------------------------------------------------------------------------*
|
*---------------------------------------------------------------------------*
|
||||||
* This file is part of OpenMesh. *
|
* 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 *
|
* it under the terms of the GNU Lesser General Public License as *
|
||||||
* published by the Free Software Foundation, either version 3 of *
|
* published by the Free Software Foundation, either version 3 of *
|
||||||
* the License, or (at your option) any later version with the *
|
* the License, or (at your option) any later version with the *
|
||||||
@@ -30,10 +30,10 @@
|
|||||||
* License along with OpenMesh. If not, *
|
* License along with OpenMesh. If not, *
|
||||||
* see <http://www.gnu.org/licenses/>. *
|
* see <http://www.gnu.org/licenses/>. *
|
||||||
* *
|
* *
|
||||||
\*===========================================================================*/
|
\*===========================================================================*/
|
||||||
|
|
||||||
/*===========================================================================*\
|
/*===========================================================================*\
|
||||||
* *
|
* *
|
||||||
* $Revision$ *
|
* $Revision$ *
|
||||||
* $Date$ *
|
* $Date$ *
|
||||||
* *
|
* *
|
||||||
@@ -75,15 +75,15 @@ _OMReader_& OMReader() { return __OMReaderInstance; }
|
|||||||
|
|
||||||
_OMReader_::_OMReader_()
|
_OMReader_::_OMReader_()
|
||||||
{
|
{
|
||||||
IOManager().register_module(this);
|
IOManager().register_module(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
_OMReader_::read(const std::string& _filename,
|
_OMReader_::read(const std::string& _filename,
|
||||||
BaseImporter& _bi,
|
BaseImporter& _bi,
|
||||||
Options& _opt)
|
Options& _opt)
|
||||||
{
|
{
|
||||||
@@ -95,42 +95,58 @@ _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
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pass stream to read method, remember result
|
// Pass stream to read method, remember result
|
||||||
bool result = read(ifs, _bi, _opt);
|
bool result = read(ifs, _bi, _opt);
|
||||||
|
|
||||||
// close input stream
|
// close input stream
|
||||||
ifs.close();
|
ifs.close();
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
_OMReader_::read(std::istream& _is,
|
||||||
|
BaseImporter& _bi,
|
||||||
|
Options& _opt)
|
||||||
|
{
|
||||||
|
// check whether importer can give us an OpenMesh BaseKernel
|
||||||
|
if (!_bi.kernel()) return false;
|
||||||
|
|
||||||
|
|
||||||
|
_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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
bool
|
|
||||||
_OMReader_::read(std::istream& _is, BaseImporter& _bi, Options& _opt ) const
|
|
||||||
{
|
|
||||||
// currently only binary file format is supported
|
|
||||||
_opt += Options::Binary;
|
|
||||||
|
|
||||||
return read_binary( _is, _bi, _opt );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool
|
bool
|
||||||
_OMReader_::read_ascii( std::istream& /* _is */, BaseImporter& /* _bi */,
|
_OMReader_::read_ascii( std::istream& /* _is */, BaseImporter& /* _bi */,
|
||||||
Options& /* _opt */) const
|
Options& /* _opt */) const
|
||||||
{
|
{
|
||||||
// not supported yet!
|
// not supported yet!
|
||||||
@@ -140,14 +156,14 @@ _OMReader_::read_ascii( std::istream& /* _is */, BaseImporter& /* _bi */,
|
|||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool
|
bool
|
||||||
_OMReader_::read_binary( std::istream& _is, BaseImporter& _bi,
|
_OMReader_::read_binary( std::istream& _is, BaseImporter& _bi,
|
||||||
Options& _opt) const
|
Options& _opt) const
|
||||||
{
|
{
|
||||||
bool swap = _opt.check(Options::Swap) || (Endian::local() == Endian::MSB);
|
bool swap = _opt.check(Options::Swap) || (Endian::local() == Endian::MSB);
|
||||||
|
|
||||||
// intialize byte counter
|
// intialize byte counter
|
||||||
bytes_ = 0;
|
bytes_ = 0;
|
||||||
|
|
||||||
bytes_ += restore( _is, header_, swap );
|
bytes_ += restore( _is, header_, swap );
|
||||||
|
|
||||||
@@ -172,7 +188,7 @@ _OMReader_::read_binary( std::istream& _is, BaseImporter& _bi,
|
|||||||
data_bytes = bytes_;
|
data_bytes = bytes_;
|
||||||
switch( chunk_header_.entity_ )
|
switch( chunk_header_.entity_ )
|
||||||
{
|
{
|
||||||
case OMFormat::Chunk::Entity_Vertex:
|
case OMFormat::Chunk::Entity_Vertex:
|
||||||
if (!read_binary_vertex_chunk( _is, _bi, _opt, swap ))
|
if (!read_binary_vertex_chunk( _is, _bi, _opt, swap ))
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
@@ -214,13 +230,13 @@ _OMReader_::can_u_read(const std::string& _filename) const
|
|||||||
{
|
{
|
||||||
std::ifstream ifile( _filename.c_str() );
|
std::ifstream ifile( _filename.c_str() );
|
||||||
if ( ifile && can_u_read( ifile ) )
|
if ( ifile && can_u_read( ifile ) )
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool
|
bool
|
||||||
_OMReader_::can_u_read(std::istream& _is) const
|
_OMReader_::can_u_read(std::istream& _is) const
|
||||||
{
|
{
|
||||||
@@ -231,7 +247,7 @@ _OMReader_::can_u_read(std::istream& _is) const
|
|||||||
while( evt.size() < 4 )
|
while( evt.size() < 4 )
|
||||||
evt.push_back( static_cast<char>(_is.get()) );
|
evt.push_back( static_cast<char>(_is.get()) );
|
||||||
|
|
||||||
// put back all read characters
|
// put back all read characters
|
||||||
std::vector<char>::reverse_iterator it = evt.rbegin();
|
std::vector<char>::reverse_iterator it = evt.rbegin();
|
||||||
while (it != evt.rend() )
|
while (it != evt.rend() )
|
||||||
_is.putback( *it++ );
|
_is.putback( *it++ );
|
||||||
@@ -254,14 +270,14 @@ _OMReader_::can_u_read(std::istream& _is) const
|
|||||||
default: // ?
|
default: // ?
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 4th characters encodes the version
|
// 4th characters encodes the version
|
||||||
return supports( hdr->version_ );
|
return supports( hdr->version_ );
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool
|
bool
|
||||||
_OMReader_::supports( const OMFormat::uint8 /* version */ ) const
|
_OMReader_::supports( const OMFormat::uint8 /* version */ ) const
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
@@ -270,16 +286,16 @@ _OMReader_::supports( const OMFormat::uint8 /* version */ ) const
|
|||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool
|
bool
|
||||||
_OMReader_::read_binary_vertex_chunk( std::istream &_is,
|
_OMReader_::read_binary_vertex_chunk( std::istream &_is,
|
||||||
BaseImporter &_bi,
|
BaseImporter &_bi,
|
||||||
Options &_opt,
|
Options &_opt,
|
||||||
bool _swap) const
|
bool _swap) const
|
||||||
{
|
{
|
||||||
using OMFormat::Chunk;
|
using OMFormat::Chunk;
|
||||||
|
|
||||||
assert( chunk_header_.entity_ == Chunk::Entity_Vertex );
|
assert( chunk_header_.entity_ == Chunk::Entity_Vertex );
|
||||||
|
|
||||||
OpenMesh::Vec3f v3f;
|
OpenMesh::Vec3f v3f;
|
||||||
OpenMesh::Vec2f v2f;
|
OpenMesh::Vec2f v2f;
|
||||||
OpenMesh::Vec3uc v3uc; // rgb
|
OpenMesh::Vec3uc v3uc; // rgb
|
||||||
@@ -290,7 +306,7 @@ _OMReader_::read_binary_vertex_chunk( std::istream &_is,
|
|||||||
switch (chunk_header_.type_)
|
switch (chunk_header_.type_)
|
||||||
{
|
{
|
||||||
case Chunk::Type_Pos:
|
case Chunk::Type_Pos:
|
||||||
assert( OMFormat::dimensions(chunk_header_)
|
assert( OMFormat::dimensions(chunk_header_)
|
||||||
== size_t(OpenMesh::Vec3f::dim()) );
|
== size_t(OpenMesh::Vec3f::dim()) );
|
||||||
|
|
||||||
for (; vidx < header_.n_vertices_ && !_is.eof(); ++vidx)
|
for (; vidx < header_.n_vertices_ && !_is.eof(); ++vidx)
|
||||||
@@ -300,9 +316,9 @@ _OMReader_::read_binary_vertex_chunk( std::istream &_is,
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
||||||
case Chunk::Type_Normal:
|
case Chunk::Type_Normal:
|
||||||
assert( OMFormat::dimensions(chunk_header_)
|
assert( OMFormat::dimensions(chunk_header_)
|
||||||
== size_t(OpenMesh::Vec3f::dim()) );
|
== size_t(OpenMesh::Vec3f::dim()) );
|
||||||
|
|
||||||
_opt += Options::VertexNormal;
|
_opt += Options::VertexNormal;
|
||||||
@@ -313,9 +329,9 @@ _OMReader_::read_binary_vertex_chunk( std::istream &_is,
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
||||||
case Chunk::Type_Texcoord:
|
case Chunk::Type_Texcoord:
|
||||||
assert( OMFormat::dimensions(chunk_header_)
|
assert( OMFormat::dimensions(chunk_header_)
|
||||||
== size_t(OpenMesh::Vec2f::dim()) );
|
== size_t(OpenMesh::Vec2f::dim()) );
|
||||||
|
|
||||||
_opt += Options::VertexTexCoord;
|
_opt += Options::VertexTexCoord;
|
||||||
@@ -324,14 +340,14 @@ _OMReader_::read_binary_vertex_chunk( std::istream &_is,
|
|||||||
bytes_ += vector_restore( _is, v2f, _swap );
|
bytes_ += vector_restore( _is, v2f, _swap );
|
||||||
_bi.set_texcoord(VertexHandle(vidx), v2f);
|
_bi.set_texcoord(VertexHandle(vidx), v2f);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Chunk::Type_Color:
|
case Chunk::Type_Color:
|
||||||
|
|
||||||
assert( OMFormat::dimensions(chunk_header_) == 3 );
|
assert( OMFormat::dimensions(chunk_header_) == 3 );
|
||||||
|
|
||||||
_opt += Options::VertexColor;
|
_opt += Options::VertexColor;
|
||||||
|
|
||||||
for (; vidx < header_.n_vertices_ && !_is.eof(); ++vidx)
|
for (; vidx < header_.n_vertices_ && !_is.eof(); ++vidx)
|
||||||
{
|
{
|
||||||
bytes_ += vector_restore( _is, v3uc, _swap );
|
bytes_ += vector_restore( _is, v3uc, _swap );
|
||||||
@@ -340,8 +356,8 @@ _OMReader_::read_binary_vertex_chunk( std::istream &_is,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case Chunk::Type_Custom:
|
case Chunk::Type_Custom:
|
||||||
|
|
||||||
bytes_ +=
|
bytes_ +=
|
||||||
restore_binary_custom_data( _is,
|
restore_binary_custom_data( _is,
|
||||||
_bi.kernel()->_get_vprop( property_name_ ),
|
_bi.kernel()->_get_vprop( property_name_ ),
|
||||||
header_.n_vertices_,
|
header_.n_vertices_,
|
||||||
@@ -354,7 +370,7 @@ _OMReader_::read_binary_vertex_chunk( std::istream &_is,
|
|||||||
default: // skip unknown chunks
|
default: // skip unknown chunks
|
||||||
{
|
{
|
||||||
omerr() << "Unknown chunk type ignored!\n";
|
omerr() << "Unknown chunk type ignored!\n";
|
||||||
size_t size_of = header_.n_vertices_
|
size_t size_of = header_.n_vertices_
|
||||||
* OMFormat::vector_size(chunk_header_);
|
* OMFormat::vector_size(chunk_header_);
|
||||||
_is.ignore( size_of );
|
_is.ignore( size_of );
|
||||||
bytes_ += size_of;
|
bytes_ += size_of;
|
||||||
@@ -369,8 +385,8 @@ _OMReader_::read_binary_vertex_chunk( std::istream &_is,
|
|||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool
|
bool
|
||||||
_OMReader_::read_binary_face_chunk( std::istream &_is,
|
_OMReader_::read_binary_face_chunk( std::istream &_is,
|
||||||
BaseImporter &_bi,
|
BaseImporter &_bi,
|
||||||
Options &_opt,
|
Options &_opt,
|
||||||
bool _swap ) const
|
bool _swap ) const
|
||||||
{
|
{
|
||||||
@@ -395,7 +411,7 @@ _OMReader_::read_binary_face_chunk( std::istream &_is,
|
|||||||
case 'T': nV = 3; break;
|
case 'T': nV = 3; break;
|
||||||
case 'Q': nV = 4; break;
|
case 'Q': nV = 4; break;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (; fidx < header_.n_faces_; ++fidx)
|
for (; fidx < header_.n_faces_; ++fidx)
|
||||||
{
|
{
|
||||||
if ( header_.mesh_ == 'P' )
|
if ( header_.mesh_ == 'P' )
|
||||||
@@ -403,8 +419,8 @@ _OMReader_::read_binary_face_chunk( std::istream &_is,
|
|||||||
|
|
||||||
vhandles.clear();
|
vhandles.clear();
|
||||||
for (size_t j=0; j<nV; ++j)
|
for (size_t j=0; j<nV; ++j)
|
||||||
{
|
{
|
||||||
bytes_ += restore( _is, vidx,
|
bytes_ += restore( _is, vidx,
|
||||||
Chunk::Integer_Size(chunk_header_.bits_),
|
Chunk::Integer_Size(chunk_header_.bits_),
|
||||||
_swap );
|
_swap );
|
||||||
|
|
||||||
@@ -418,7 +434,7 @@ _OMReader_::read_binary_face_chunk( std::istream &_is,
|
|||||||
|
|
||||||
|
|
||||||
case Chunk::Type_Normal:
|
case Chunk::Type_Normal:
|
||||||
assert( OMFormat::dimensions(chunk_header_)
|
assert( OMFormat::dimensions(chunk_header_)
|
||||||
== size_t(OpenMesh::Vec3f::dim()) );
|
== size_t(OpenMesh::Vec3f::dim()) );
|
||||||
|
|
||||||
_opt += Options::FaceNormal;
|
_opt += Options::FaceNormal;
|
||||||
@@ -434,7 +450,7 @@ _OMReader_::read_binary_face_chunk( std::istream &_is,
|
|||||||
|
|
||||||
assert( OMFormat::dimensions(chunk_header_) == 3 );
|
assert( OMFormat::dimensions(chunk_header_) == 3 );
|
||||||
|
|
||||||
_opt += Options::FaceColor;
|
_opt += Options::FaceColor;
|
||||||
for (; fidx < header_.n_faces_ && !_is.eof(); ++fidx)
|
for (; fidx < header_.n_faces_ && !_is.eof(); ++fidx)
|
||||||
{
|
{
|
||||||
bytes_ += vector_restore( _is, v3uc, _swap );
|
bytes_ += vector_restore( _is, v3uc, _swap );
|
||||||
@@ -444,8 +460,8 @@ _OMReader_::read_binary_face_chunk( std::istream &_is,
|
|||||||
|
|
||||||
|
|
||||||
case Chunk::Type_Custom:
|
case Chunk::Type_Custom:
|
||||||
|
|
||||||
bytes_ +=
|
bytes_ +=
|
||||||
restore_binary_custom_data( _is,
|
restore_binary_custom_data( _is,
|
||||||
_bi.kernel()->_get_fprop( property_name_ ),
|
_bi.kernel()->_get_fprop( property_name_ ),
|
||||||
header_.n_faces_,
|
header_.n_faces_,
|
||||||
@@ -454,13 +470,13 @@ _OMReader_::read_binary_face_chunk( std::istream &_is,
|
|||||||
fidx = header_.n_faces_;
|
fidx = header_.n_faces_;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default: // skip unknown chunks
|
default: // skip unknown chunks
|
||||||
{
|
{
|
||||||
omerr() << "Unknown chunk type ignore!\n";
|
omerr() << "Unknown chunk type ignore!\n";
|
||||||
size_t size_of = OMFormat::chunk_data_size(header_, chunk_header_);
|
size_t size_of = OMFormat::chunk_data_size(header_, chunk_header_);
|
||||||
_is.ignore( size_of );
|
_is.ignore( size_of );
|
||||||
bytes_ += size_of;
|
bytes_ += size_of;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return fidx == header_.n_faces_;
|
return fidx == header_.n_faces_;
|
||||||
@@ -470,8 +486,8 @@ _OMReader_::read_binary_face_chunk( std::istream &_is,
|
|||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool
|
bool
|
||||||
_OMReader_::read_binary_edge_chunk( std::istream &_is,
|
_OMReader_::read_binary_edge_chunk( std::istream &_is,
|
||||||
BaseImporter &_bi,
|
BaseImporter &_bi,
|
||||||
Options &/*_opt */,
|
Options &/*_opt */,
|
||||||
bool _swap ) const
|
bool _swap ) const
|
||||||
{
|
{
|
||||||
@@ -483,9 +499,9 @@ _OMReader_::read_binary_edge_chunk( std::istream &_is,
|
|||||||
|
|
||||||
switch( chunk_header_.type_ )
|
switch( chunk_header_.type_ )
|
||||||
{
|
{
|
||||||
case Chunk::Type_Custom:
|
case Chunk::Type_Custom:
|
||||||
|
|
||||||
bytes_ +=
|
bytes_ +=
|
||||||
restore_binary_custom_data( _is,
|
restore_binary_custom_data( _is,
|
||||||
_bi.kernel()->_get_eprop( property_name_ ),
|
_bi.kernel()->_get_eprop( property_name_ ),
|
||||||
header_.n_edges_,
|
header_.n_edges_,
|
||||||
@@ -507,8 +523,8 @@ _OMReader_::read_binary_edge_chunk( std::istream &_is,
|
|||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool
|
bool
|
||||||
_OMReader_::read_binary_halfedge_chunk( std::istream &_is,
|
_OMReader_::read_binary_halfedge_chunk( std::istream &_is,
|
||||||
BaseImporter &_bi,
|
BaseImporter &_bi,
|
||||||
Options &/* _opt */,
|
Options &/* _opt */,
|
||||||
bool _swap ) const
|
bool _swap ) const
|
||||||
{
|
{
|
||||||
@@ -522,11 +538,11 @@ _OMReader_::read_binary_halfedge_chunk( std::istream &_is,
|
|||||||
{
|
{
|
||||||
case Chunk::Type_Custom:
|
case Chunk::Type_Custom:
|
||||||
|
|
||||||
bytes_ +=
|
bytes_ +=
|
||||||
restore_binary_custom_data( _is,
|
restore_binary_custom_data( _is,
|
||||||
_bi.kernel()->_get_hprop( property_name_ ),
|
_bi.kernel()->_get_hprop( property_name_ ),
|
||||||
2*header_.n_edges_,
|
2*header_.n_edges_,
|
||||||
_swap );
|
_swap );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -544,8 +560,8 @@ _OMReader_::read_binary_halfedge_chunk( std::istream &_is,
|
|||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool
|
bool
|
||||||
_OMReader_::read_binary_mesh_chunk( std::istream &_is,
|
_OMReader_::read_binary_mesh_chunk( std::istream &_is,
|
||||||
BaseImporter &_bi,
|
BaseImporter &_bi,
|
||||||
Options & /* _opt */,
|
Options & /* _opt */,
|
||||||
bool _swap ) const
|
bool _swap ) const
|
||||||
{
|
{
|
||||||
@@ -558,13 +574,13 @@ _OMReader_::read_binary_mesh_chunk( std::istream &_is,
|
|||||||
switch( chunk_header_.type_ )
|
switch( chunk_header_.type_ )
|
||||||
{
|
{
|
||||||
case Chunk::Type_Custom:
|
case Chunk::Type_Custom:
|
||||||
|
|
||||||
bytes_ +=
|
bytes_ +=
|
||||||
restore_binary_custom_data( _is,
|
restore_binary_custom_data( _is,
|
||||||
_bi.kernel()->_get_mprop( property_name_ ),
|
_bi.kernel()->_get_mprop( property_name_ ),
|
||||||
1,
|
1,
|
||||||
_swap );
|
_swap );
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -581,10 +597,10 @@ _OMReader_::read_binary_mesh_chunk( std::istream &_is,
|
|||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
size_t
|
size_t
|
||||||
_OMReader_::restore_binary_custom_data( std::istream& _is, BaseProperty* _bp,
|
_OMReader_::restore_binary_custom_data( std::istream& _is, BaseProperty* _bp,
|
||||||
size_t _n_elem, bool _swap) const
|
size_t _n_elem, bool _swap) const
|
||||||
{
|
{
|
||||||
assert( !_bp || (_bp->name() == property_name_) );
|
assert( !_bp || (_bp->name() == property_name_) );
|
||||||
|
|
||||||
using OMFormat::Chunk;
|
using OMFormat::Chunk;
|
||||||
@@ -605,7 +621,7 @@ _OMReader_::restore_binary_custom_data( std::istream& _is, BaseProperty* _bp,
|
|||||||
|
|
||||||
if ( ((n_bytes == BaseProperty::UnknownSize) || (n_bytes == block_size)) &&
|
if ( ((n_bytes == BaseProperty::UnknownSize) || (n_bytes == block_size)) &&
|
||||||
(_bp->element_size() == BaseProperty::UnknownSize ||
|
(_bp->element_size() == BaseProperty::UnknownSize ||
|
||||||
(_n_elem * _bp->element_size() == block_size) ) )
|
(_n_elem * _bp->element_size() == block_size) ) )
|
||||||
{
|
{
|
||||||
#if defined(OM_DEBUG)
|
#if defined(OM_DEBUG)
|
||||||
bytes += (b=_bp->restore( _is, _swap ));
|
bytes += (b=_bp->restore( _is, _swap ));
|
||||||
@@ -621,7 +637,7 @@ _OMReader_::restore_binary_custom_data( std::istream& _is, BaseProperty* _bp,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
omerr() << "Warning! Property " << _bp->name() << " not loaded: "
|
omerr() << "Warning! Property " << _bp->name() << " not loaded: "
|
||||||
<< "Mismatching data sizes!n";
|
<< "Mismatching data sizes!n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -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_;
|
||||||
|
|||||||
@@ -4,10 +4,10 @@
|
|||||||
* Copyright (C) 2001-2009 by Computer Graphics Group, RWTH Aachen *
|
* Copyright (C) 2001-2009 by Computer Graphics Group, RWTH Aachen *
|
||||||
* www.openmesh.org *
|
* www.openmesh.org *
|
||||||
* *
|
* *
|
||||||
*---------------------------------------------------------------------------*
|
*---------------------------------------------------------------------------*
|
||||||
* This file is part of OpenMesh. *
|
* 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 *
|
* it under the terms of the GNU Lesser General Public License as *
|
||||||
* published by the Free Software Foundation, either version 3 of *
|
* published by the Free Software Foundation, either version 3 of *
|
||||||
* the License, or (at your option) any later version with the *
|
* the License, or (at your option) any later version with the *
|
||||||
@@ -30,10 +30,10 @@
|
|||||||
* License along with OpenMesh. If not, *
|
* License along with OpenMesh. If not, *
|
||||||
* see <http://www.gnu.org/licenses/>. *
|
* see <http://www.gnu.org/licenses/>. *
|
||||||
* *
|
* *
|
||||||
\*===========================================================================*/
|
\*===========================================================================*/
|
||||||
|
|
||||||
/*===========================================================================*\
|
/*===========================================================================*\
|
||||||
* *
|
* *
|
||||||
* $Revision$ *
|
* $Revision$ *
|
||||||
* $Date$ *
|
* $Date$ *
|
||||||
* *
|
* *
|
||||||
@@ -76,17 +76,17 @@ _STLReader_& STLReader() { return __STLReaderInstance; }
|
|||||||
|
|
||||||
|
|
||||||
_STLReader_::
|
_STLReader_::
|
||||||
_STLReader_()
|
_STLReader_()
|
||||||
: eps_(FLT_MIN)
|
: eps_(FLT_MIN)
|
||||||
{
|
{
|
||||||
IOManager().register_module(this);
|
IOManager().register_module(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
_STLReader_::
|
_STLReader_::
|
||||||
read(const std::string& _filename, BaseImporter& _bi, Options& _opt)
|
read(const std::string& _filename, BaseImporter& _bi, Options& _opt)
|
||||||
{
|
{
|
||||||
@@ -118,15 +118,15 @@ read(const std::string& _filename, BaseImporter& _bi, Options& _opt)
|
|||||||
_opt -= Options::Binary;
|
_opt -= Options::Binary;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case STLB:
|
case STLB:
|
||||||
{
|
{
|
||||||
result = read_stlb(_filename, _bi);
|
result = read_stlb(_filename, _bi);
|
||||||
_opt += Options::Binary;
|
_opt += Options::Binary;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
result = false;
|
result = false;
|
||||||
break;
|
break;
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
@@ -151,9 +162,9 @@ public:
|
|||||||
|
|
||||||
bool operator()( const Vec3f& _v0, const Vec3f& _v1 ) const
|
bool operator()( const Vec3f& _v0, const Vec3f& _v1 ) const
|
||||||
{
|
{
|
||||||
if (fabs(_v0[0] - _v1[0]) <= eps_)
|
if (fabs(_v0[0] - _v1[0]) <= eps_)
|
||||||
{
|
{
|
||||||
if (fabs(_v0[1] - _v1[1]) <= eps_)
|
if (fabs(_v0[1] - _v1[1]) <= eps_)
|
||||||
{
|
{
|
||||||
return (_v0[2] < _v1[2] - eps_);
|
return (_v0[2] < _v1[2] - eps_);
|
||||||
}
|
}
|
||||||
@@ -172,17 +183,16 @@ private:
|
|||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
_STLReader_::
|
_STLReader_::
|
||||||
read_stla(const std::string& _filename, BaseImporter& _bi) const
|
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)
|
||||||
{
|
{
|
||||||
omerr() << "[STLReader] : cannot not open file "
|
omerr() << "[STLReader] : cannot not open file "
|
||||||
<< _filename
|
<< _filename
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
return false;
|
return false;
|
||||||
@@ -200,15 +210,15 @@ read_stla(const std::string& _filename, BaseImporter& _bi) const
|
|||||||
std::map<Vec3f, VertexHandle, CmpVec> vMap(comp);
|
std::map<Vec3f, VertexHandle, CmpVec> vMap(comp);
|
||||||
std::map<Vec3f, VertexHandle, CmpVec>::iterator vMapIt;
|
std::map<Vec3f, VertexHandle, CmpVec>::iterator vMapIt;
|
||||||
|
|
||||||
|
|
||||||
while (in && !feof(in) && fgets(line, 100, in))
|
while (in && !feof(in) && fgets(line, 100, in))
|
||||||
{
|
{
|
||||||
for (p=line; isspace(*p) && *p!='\0'; ++p) {}; // skip white-space
|
for (p=line; isspace(*p) && *p!='\0'; ++p) {}; // skip white-space
|
||||||
|
|
||||||
if ((strncmp(p, "outer", 5) == 0) || (strncmp(p, "OUTER", 5) == 0))
|
if ((strncmp(p, "outer", 5) == 0) || (strncmp(p, "OUTER", 5) == 0))
|
||||||
{
|
{
|
||||||
vhandles.clear();
|
vhandles.clear();
|
||||||
|
|
||||||
for (i=0; i<3; ++i)
|
for (i=0; i<3; ++i)
|
||||||
{
|
{
|
||||||
fgets(line, 100, in);
|
fgets(line, 100, in);
|
||||||
@@ -223,7 +233,7 @@ read_stla(const std::string& _filename, BaseImporter& _bi) const
|
|||||||
vhandles.push_back(VertexHandle(cur_idx));
|
vhandles.push_back(VertexHandle(cur_idx));
|
||||||
vMap[v] = VertexHandle(cur_idx++);
|
vMap[v] = VertexHandle(cur_idx++);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
// Yes : get index from map
|
// Yes : get index from map
|
||||||
vhandles.push_back(vMapIt->second);
|
vhandles.push_back(vMapIt->second);
|
||||||
}
|
}
|
||||||
@@ -248,17 +258,16 @@ read_stla(const std::string& _filename, BaseImporter& _bi) const
|
|||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
_STLReader_::
|
_STLReader_::
|
||||||
read_stlb(const std::string& _filename, BaseImporter& _bi) const
|
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)
|
||||||
{
|
{
|
||||||
omerr() << "[STLReader] : cannot not open file "
|
omerr() << "[STLReader] : cannot not open file "
|
||||||
<< _filename
|
<< _filename
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
return false;
|
return false;
|
||||||
@@ -275,7 +284,7 @@ read_stlb(const std::string& _filename, BaseImporter& _bi) const
|
|||||||
std::map<Vec3f, VertexHandle, CmpVec> vMap;
|
std::map<Vec3f, VertexHandle, CmpVec> vMap;
|
||||||
std::map<Vec3f, VertexHandle, CmpVec>::iterator vMapIt;
|
std::map<Vec3f, VertexHandle, CmpVec>::iterator vMapIt;
|
||||||
|
|
||||||
|
|
||||||
// check size of types
|
// check size of types
|
||||||
if ((sizeof(float) != 4) || (sizeof(int) != 4)) {
|
if ((sizeof(float) != 4) || (sizeof(int) != 4)) {
|
||||||
omerr() << "[STLReader] : wrong type size\n";
|
omerr() << "[STLReader] : wrong type size\n";
|
||||||
@@ -286,11 +295,11 @@ read_stlb(const std::string& _filename, BaseImporter& _bi) const
|
|||||||
union { unsigned int i; unsigned char c[4]; } endian_test;
|
union { unsigned int i; unsigned char c[4]; } endian_test;
|
||||||
endian_test.i = 1;
|
endian_test.i = 1;
|
||||||
swapFlag = (endian_test.c[3] == 1);
|
swapFlag = (endian_test.c[3] == 1);
|
||||||
|
|
||||||
// read number of triangles
|
// read number of triangles
|
||||||
fread(dummy, 1, 80, in);
|
fread(dummy, 1, 80, in);
|
||||||
nT = read_int(in, swapFlag);
|
nT = read_int(in, swapFlag);
|
||||||
|
|
||||||
// read triangles
|
// read triangles
|
||||||
while (nT)
|
while (nT)
|
||||||
{
|
{
|
||||||
@@ -314,18 +323,18 @@ read_stlb(const std::string& _filename, BaseImporter& _bi) const
|
|||||||
vhandles.push_back(VertexHandle(cur_idx));
|
vhandles.push_back(VertexHandle(cur_idx));
|
||||||
vMap[v] = VertexHandle(cur_idx++);
|
vMap[v] = VertexHandle(cur_idx++);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
// Yes : get index from map
|
// Yes : get index from map
|
||||||
vhandles.push_back(vMapIt->second);
|
vhandles.push_back(vMapIt->second);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Add face only if it is not degenerated
|
// Add face only if it is not degenerated
|
||||||
if ((vhandles[0] != vhandles[1]) &&
|
if ((vhandles[0] != vhandles[1]) &&
|
||||||
(vhandles[0] != vhandles[2]) &&
|
(vhandles[0] != vhandles[2]) &&
|
||||||
(vhandles[1] != vhandles[2]))
|
(vhandles[1] != vhandles[2]))
|
||||||
_bi.add_face(vhandles);
|
_bi.add_face(vhandles);
|
||||||
|
|
||||||
fread(dummy, 1, 2, in);
|
fread(dummy, 1, 2, in);
|
||||||
--nT;
|
--nT;
|
||||||
}
|
}
|
||||||
@@ -355,7 +364,7 @@ check_stl_type(const std::string& _filename) const
|
|||||||
endian_test.i = 1;
|
endian_test.i = 1;
|
||||||
bool swapFlag = (endian_test.c[3] == 1);
|
bool swapFlag = (endian_test.c[3] == 1);
|
||||||
|
|
||||||
|
|
||||||
// read number of triangles
|
// read number of triangles
|
||||||
char dummy[100];
|
char dummy[100];
|
||||||
fread(dummy, 1, 80, in);
|
fread(dummy, 1, 80, in);
|
||||||
|
|||||||
@@ -4,10 +4,10 @@
|
|||||||
* Copyright (C) 2001-2009 by Computer Graphics Group, RWTH Aachen *
|
* Copyright (C) 2001-2009 by Computer Graphics Group, RWTH Aachen *
|
||||||
* www.openmesh.org *
|
* www.openmesh.org *
|
||||||
* *
|
* *
|
||||||
*---------------------------------------------------------------------------*
|
*---------------------------------------------------------------------------*
|
||||||
* This file is part of OpenMesh. *
|
* 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 *
|
* it under the terms of the GNU Lesser General Public License as *
|
||||||
* published by the Free Software Foundation, either version 3 of *
|
* published by the Free Software Foundation, either version 3 of *
|
||||||
* the License, or (at your option) any later version with the *
|
* the License, or (at your option) any later version with the *
|
||||||
@@ -30,10 +30,10 @@
|
|||||||
* License along with OpenMesh. If not, *
|
* License along with OpenMesh. If not, *
|
||||||
* see <http://www.gnu.org/licenses/>. *
|
* see <http://www.gnu.org/licenses/>. *
|
||||||
* *
|
* *
|
||||||
\*===========================================================================*/
|
\*===========================================================================*/
|
||||||
|
|
||||||
/*===========================================================================*\
|
/*===========================================================================*\
|
||||||
* *
|
* *
|
||||||
* $Revision$ *
|
* $Revision$ *
|
||||||
* $Date$ *
|
* $Date$ *
|
||||||
* *
|
* *
|
||||||
@@ -79,8 +79,8 @@ class BaseImporter;
|
|||||||
//== IMPLEMENTATION ===========================================================
|
//== IMPLEMENTATION ===========================================================
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Implementation of the STL format reader. This class is singleton'ed by
|
Implementation of the STL format reader. This class is singleton'ed by
|
||||||
SingletonT to STLReader.
|
SingletonT to STLReader.
|
||||||
*/
|
*/
|
||||||
class _STLReader_ : public BaseReader
|
class _STLReader_ : public BaseReader
|
||||||
@@ -94,14 +94,17 @@ public:
|
|||||||
virtual ~_STLReader_() {};
|
virtual ~_STLReader_() {};
|
||||||
|
|
||||||
|
|
||||||
std::string get_description() const
|
std::string get_description() const
|
||||||
{ return "Stereolithography Interface Format"; }
|
{ return "Stereolithography Interface Format"; }
|
||||||
std::string get_extensions() const { return "stl stla stlb"; }
|
std::string get_extensions() const { return "stl stla stlb"; }
|
||||||
|
|
||||||
bool read(const std::string& _filename,
|
bool read(const std::string& _filename,
|
||||||
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 */
|
||||||
@@ -111,7 +114,7 @@ public:
|
|||||||
float epsilon() const { return eps_; }
|
float epsilon() const { return eps_; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
enum STL_Type { STLA, STLB, NONE };
|
enum STL_Type { STLA, STLB, NONE };
|
||||||
|
|||||||
@@ -4,10 +4,10 @@
|
|||||||
* Copyright (C) 2001-2009 by Computer Graphics Group, RWTH Aachen *
|
* Copyright (C) 2001-2009 by Computer Graphics Group, RWTH Aachen *
|
||||||
* www.openmesh.org *
|
* www.openmesh.org *
|
||||||
* *
|
* *
|
||||||
*---------------------------------------------------------------------------*
|
*---------------------------------------------------------------------------*
|
||||||
* This file is part of OpenMesh. *
|
* 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 *
|
* it under the terms of the GNU Lesser General Public License as *
|
||||||
* published by the Free Software Foundation, either version 3 of *
|
* published by the Free Software Foundation, either version 3 of *
|
||||||
* the License, or (at your option) any later version with the *
|
* the License, or (at your option) any later version with the *
|
||||||
@@ -30,10 +30,10 @@
|
|||||||
* License along with OpenMesh. If not, *
|
* License along with OpenMesh. If not, *
|
||||||
* see <http://www.gnu.org/licenses/>. *
|
* see <http://www.gnu.org/licenses/>. *
|
||||||
* *
|
* *
|
||||||
\*===========================================================================*/
|
\*===========================================================================*/
|
||||||
|
|
||||||
/*===========================================================================*\
|
/*===========================================================================*\
|
||||||
* *
|
* *
|
||||||
* $Revision$ *
|
* $Revision$ *
|
||||||
* $Date$ *
|
* $Date$ *
|
||||||
* *
|
* *
|
||||||
@@ -86,10 +86,10 @@ public:
|
|||||||
|
|
||||||
/// Destructor
|
/// Destructor
|
||||||
virtual ~BaseWriter() {};
|
virtual ~BaseWriter() {};
|
||||||
|
|
||||||
/// Return short description of the supported file format.
|
/// Return short description of the supported file format.
|
||||||
virtual std::string get_description() const = 0;
|
virtual std::string get_description() const = 0;
|
||||||
|
|
||||||
/// Return file format's extension.
|
/// Return file format's extension.
|
||||||
virtual std::string get_extensions() const = 0;
|
virtual std::string get_extensions() const = 0;
|
||||||
|
|
||||||
@@ -97,9 +97,14 @@ public:
|
|||||||
virtual bool can_u_write(const std::string& _filename) const;
|
virtual bool can_u_write(const std::string& _filename) const;
|
||||||
|
|
||||||
/// 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; }
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -90,6 +90,8 @@ public:
|
|||||||
std::string get_extensions() const { return "obj"; }
|
std::string get_extensions() const { return "obj"; }
|
||||||
|
|
||||||
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; }
|
||||||
|
|
||||||
@@ -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;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -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";
|
||||||
|
|
||||||
|
|||||||
@@ -101,17 +101,19 @@ public:
|
|||||||
std::string get_extensions() const { return "off"; }
|
std::string get_extensions() const { return "off"; }
|
||||||
|
|
||||||
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;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -103,6 +103,7 @@ public:
|
|||||||
{ return "om"; }
|
{ return "om"; }
|
||||||
|
|
||||||
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;
|
||||||
@@ -116,6 +117,7 @@ protected:
|
|||||||
bool write(const std::string&, BaseExporter&, Options) const;
|
bool write(const std::string&, BaseExporter&, Options) const;
|
||||||
|
|
||||||
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;
|
||||||
|
|||||||
@@ -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";
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|||||||
@@ -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:
|
||||||
|
|||||||
Reference in New Issue
Block a user