Fixed issue with PLYReader:

Unsupported properties in ply-file will now be skipped instead of read as x-coordinates.

git-svn-id: http://www.openmesh.org/svnrepo/OpenMesh/trunk@157 fdac6126-5c0c-442c-9429-916003d36597
This commit is contained in:
Mike Kremer
2009-06-09 15:47:49 +00:00
parent bfc96ee8ad
commit d1bd070c35
2 changed files with 564 additions and 607 deletions

View File

@@ -30,19 +30,17 @@
* 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$ *
* * * *
\*===========================================================================*/ \*===========================================================================*/
#define LINE_LEN 4096 #define LINE_LEN 4096
//== INCLUDES ================================================================= //== INCLUDES =================================================================
// OpenMesh // OpenMesh
@@ -68,124 +66,103 @@
namespace OpenMesh { namespace OpenMesh {
namespace IO { namespace IO {
//============================================================================= //=============================================================================
//=== INSTANCIATE ============================================================= //=== INSTANCIATE =============================================================
_PLYReader_ __PLYReaderInstance; _PLYReader_ __PLYReaderInstance;
_PLYReader_& PLYReader() { return __PLYReaderInstance; } _PLYReader_& PLYReader() {
return __PLYReaderInstance;
}
//=== IMPLEMENTATION ========================================================== //=== IMPLEMENTATION ==========================================================
_PLYReader_::_PLYReader_() {
_PLYReader_::_PLYReader_()
{
IOManager().register_module(this); IOManager().register_module(this);
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
bool bool _PLYReader_::read(const std::string& _filename, BaseImporter& _bi, Options& _opt) {
_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) {
{ omerr() << "[PLYReader] : cannot not open file " << _filename << std::endl;
omerr() << "[PLYReader] : cannot not open file "
<< _filename
<< std::endl;
return false; return false;
} }
bool result = read(in, _bi, _opt); bool result = read(in, _bi, _opt);
in.close(); in.close();
return result; return result;
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
bool bool _PLYReader_::read(std::fstream& _in, BaseImporter& _bi, Options& _opt) const {
_PLYReader_::read(std::fstream& _in, BaseImporter& _bi, Options& _opt ) const
{
// 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;
// build options to be returned // build options to be returned
_opt.clear(); _opt.clear();
if (options_.vertex_has_normal() && userOptions_.vertex_has_normal()) _opt += Options::VertexNormal; if (options_.vertex_has_normal() && userOptions_.vertex_has_normal())
if (options_.vertex_has_texcoord() && userOptions_.vertex_has_texcoord()) _opt += Options::VertexTexCoord; _opt += Options::VertexNormal;
if (options_.vertex_has_color() && userOptions_.vertex_has_color()) _opt += Options::VertexColor; if (options_.vertex_has_texcoord() && userOptions_.vertex_has_texcoord())
if (options_.face_has_color() && userOptions_.face_has_color()) _opt += Options::FaceColor; _opt += Options::VertexTexCoord;
if (options_.is_binary()) _opt += Options::Binary; if (options_.vertex_has_color() && userOptions_.vertex_has_color())
_opt += Options::VertexColor;
if (options_.face_has_color() && userOptions_.face_has_color())
_opt += Options::FaceColor;
if (options_.is_binary())
_opt += Options::Binary;
// //force user-choice for the alpha value when reading binary // //force user-choice for the alpha value when reading binary
// if ( options_.is_binary() && userOptions_.color_has_alpha() ) // if ( options_.is_binary() && userOptions_.color_has_alpha() )
// options_ += Options::ColorAlpha; // options_ += Options::ColorAlpha;
return (options_.is_binary() ? return (options_.is_binary() ? read_binary(_in, _bi, swap) : read_ascii(_in, _bi));
read_binary(_in, _bi, swap) :
read_ascii(_in, _bi));
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
bool bool _PLYReader_::read_ascii(std::fstream& _in, BaseImporter& _bi) const {
_PLYReader_::read_ascii(std::fstream& _in, BaseImporter& _bi) const
{
omlog() << "[PLYReader] : read ascii file\n"; omlog() << "[PLYReader] : read ascii file\n";
// Reparse the header // Reparse the header
if ( !can_u_read(_in) ) { if (!can_u_read(_in)) {
omerr() << "[PLYReader] : Unable to parse header\n"; omerr() << "[PLYReader] : Unable to parse header\n";
return false; return false;
} }
unsigned int i, j, k, l, idx; unsigned int i, j, k, l, idx;
unsigned int nV; unsigned int nV;
OpenMesh::Vec3f v; OpenMesh::Vec3f v;
std::string trash; std::string trash;
// OpenMesh::Vec2f t; // OpenMesh::Vec2f t;
OpenMesh::Vec4i c; OpenMesh::Vec4i c;
float tmp; float tmp;
BaseImporter::VHandles vhandles; BaseImporter::VHandles vhandles;
VertexHandle vh; VertexHandle vh;
_bi.reserve(vertexCount_, 3* vertexCount_ , faceCount_);
_bi.reserve(vertexCount_, 3*vertexCount_, faceCount_); if (vertexDimension_ != 3) {
if ( vertexDimension_ != 3 ) {
omerr() << "[PLYReader] : Only vertex dimension 3 is supported." << std::endl; omerr() << "[PLYReader] : Only vertex dimension 3 is supported." << std::endl;
return false; return false;
} }
// read vertices: // read vertices:
for (i=0; i< vertexCount_ && !_in.eof(); ++i) for (i = 0; i < vertexCount_ && !_in.eof(); ++i) {
{
v[0] = 0.0; v[0] = 0.0;
v[1] = 0.0; v[1] = 0.0;
v[2] = 0.0; v[2] = 0.0;
@@ -195,8 +172,8 @@ _PLYReader_::read_ascii(std::fstream& _in, BaseImporter& _bi) const
c[2] = 0; c[2] = 0;
c[3] = 255; c[3] = 255;
for ( uint propertyIndex = 0 ; propertyIndex < vertexPropertyCount_; ++propertyIndex ) { for (uint propertyIndex = 0; propertyIndex < vertexPropertyCount_; ++propertyIndex) {
switch ( vertexPropertyMap_ [ propertyIndex].first ) { switch (vertexPropertyMap_[propertyIndex].first) {
case XCOORD: case XCOORD:
_in >> v[0]; _in >> v[0];
break; break;
@@ -207,48 +184,50 @@ _PLYReader_::read_ascii(std::fstream& _in, BaseImporter& _bi) const
_in >> v[2]; _in >> v[2];
break; break;
case COLORRED: case COLORRED:
if ( vertexPropertyMap_ [ propertyIndex].second == ValueTypeFLOAT32 ){ if (vertexPropertyMap_[propertyIndex].second == ValueTypeFLOAT32) {
_in >> tmp; c[0] = static_cast<OpenMesh::Vec4i::value_type>(tmp * 255.0f); _in >> tmp;
}else c[0] = static_cast<OpenMesh::Vec4i::value_type> (tmp * 255.0f);
} else
_in >> c[0]; _in >> c[0];
break; break;
case COLORGREEN: case COLORGREEN:
if ( vertexPropertyMap_ [ propertyIndex].second == ValueTypeFLOAT32 ){ if (vertexPropertyMap_[propertyIndex].second == ValueTypeFLOAT32) {
_in >> tmp; c[1] = static_cast<OpenMesh::Vec4i::value_type>(tmp * 255.0f); _in >> tmp;
}else c[1] = static_cast<OpenMesh::Vec4i::value_type> (tmp * 255.0f);
} else
_in >> c[1]; _in >> c[1];
break; break;
case COLORBLUE: case COLORBLUE:
if ( vertexPropertyMap_ [ propertyIndex].second == ValueTypeFLOAT32 ){ if (vertexPropertyMap_[propertyIndex].second == ValueTypeFLOAT32) {
_in >> tmp; c[2] = static_cast<OpenMesh::Vec4i::value_type>(tmp * 255.0f); _in >> tmp;
}else c[2] = static_cast<OpenMesh::Vec4i::value_type> (tmp * 255.0f);
} else
_in >> c[2]; _in >> c[2];
break; break;
case COLORALPHA: case COLORALPHA:
if ( vertexPropertyMap_ [ propertyIndex].second == ValueTypeFLOAT32 ){ if (vertexPropertyMap_[propertyIndex].second == ValueTypeFLOAT32) {
_in >> tmp; c[3] = static_cast<OpenMesh::Vec4i::value_type>(tmp * 255.0f); _in >> tmp;
}else c[3] = static_cast<OpenMesh::Vec4i::value_type> (tmp * 255.0f);
} else
_in >> c[3]; _in >> c[3];
break; break;
default : default:
_in >> trash; _in >> trash;
break; break;
} }
} }
vh = _bi.add_vertex(v); vh = _bi.add_vertex(v);
_bi.set_color( vh, Vec4uc( c ) ); _bi.set_color(vh, Vec4uc(c));
} }
// faces // faces
// #N <v1> <v2> .. <v(n-1)> [color spec] // #N <v1> <v2> .. <v(n-1)> [color spec]
for (i=0; i<faceCount_; ++i) for (i = 0; i < faceCount_; ++i) {
{
// nV = number of Vertices for current face // nV = number of Vertices for current face
_in >> nV; _in >> nV;
if (nV == 3) if (nV == 3) {
{
vhandles.resize(3); vhandles.resize(3);
_in >> j; _in >> j;
_in >> k; _in >> k;
@@ -257,12 +236,9 @@ _PLYReader_::read_ascii(std::fstream& _in, BaseImporter& _bi) const
vhandles[0] = VertexHandle(j); vhandles[0] = VertexHandle(j);
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) {
{
_in >> idx; _in >> idx;
vhandles.push_back(VertexHandle(idx)); vhandles.push_back(VertexHandle(idx));
} }
@@ -276,26 +252,25 @@ _PLYReader_::read_ascii(std::fstream& _in, BaseImporter& _bi) const
return true; return true;
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void _PLYReader_::readValue(ValueType _type , std::fstream& _in, float& _value) const{ void _PLYReader_::readValue(ValueType _type, std::fstream& _in, float& _value) const {
switch (_type) { switch (_type) {
case ValueTypeFLOAT32: case ValueTypeFLOAT32:
case ValueTypeFLOAT: case ValueTypeFLOAT:
float32_t tmp; float32_t tmp;
restore( _in , tmp, options_.check(Options::MSB) ); restore(_in, tmp, options_.check(Options::MSB));
_value = tmp; _value = tmp;
break; break;
default : default:
_value = 0.0; _value = 0.0;
std::cerr << "unsupported conversion type to float: " << _type << std::endl; std::cerr << "unsupported conversion type to float: " << _type << std::endl;
break; break;
} }
} }
void _PLYReader_::readValue(ValueType _type , std::fstream& _in, unsigned int& _value) const{ void _PLYReader_::readValue(ValueType _type, std::fstream& _in, unsigned int& _value) const {
int32_t tmp_int32_t; int32_t tmp_int32_t;
uint8_t tmp_uchar; uint8_t tmp_uchar;
@@ -303,21 +278,21 @@ void _PLYReader_::readValue(ValueType _type , std::fstream& _in, unsigned int& _
switch (_type) { switch (_type) {
case ValueTypeINT: case ValueTypeINT:
case ValueTypeINT32: case ValueTypeINT32:
restore( _in , tmp_int32_t, options_.check(Options::MSB) ); restore(_in, tmp_int32_t, options_.check(Options::MSB));
_value = tmp_int32_t; _value = tmp_int32_t;
break; break;
case ValueTypeUCHAR: case ValueTypeUCHAR:
restore( _in , tmp_uchar, options_.check(Options::MSB) ); restore(_in, tmp_uchar, options_.check(Options::MSB));
_value = tmp_uchar; _value = tmp_uchar;
break; break;
default : default:
_value = 0; _value = 0;
std::cerr << "unsupported conversion type to int: " << _type << std::endl; std::cerr << "unsupported conversion type to int: " << _type << std::endl;
break; break;
} }
} }
void _PLYReader_::readValue(ValueType _type , std::fstream& _in, int& _value) const{ void _PLYReader_::readValue(ValueType _type, std::fstream& _in, int& _value) const {
int32_t tmp_int32_t; int32_t tmp_int32_t;
uint8_t tmp_uchar; uint8_t tmp_uchar;
@@ -325,28 +300,26 @@ void _PLYReader_::readValue(ValueType _type , std::fstream& _in, int& _value) co
switch (_type) { switch (_type) {
case ValueTypeINT: case ValueTypeINT:
case ValueTypeINT32: case ValueTypeINT32:
restore( _in , tmp_int32_t, options_.check(Options::MSB) ); restore(_in, tmp_int32_t, options_.check(Options::MSB));
_value = tmp_int32_t; _value = tmp_int32_t;
break; break;
case ValueTypeUCHAR: case ValueTypeUCHAR:
restore( _in , tmp_uchar, options_.check(Options::MSB) ); restore(_in, tmp_uchar, options_.check(Options::MSB));
_value = tmp_uchar; _value = tmp_uchar;
break; break;
default : default:
_value = 0; _value = 0;
std::cerr << "unsupported conversion type to int: " << _type << std::endl; std::cerr << "unsupported conversion type to int: " << _type << std::endl;
break; break;
} }
} }
bool bool _PLYReader_::read_binary(std::fstream& _in, BaseImporter& _bi, bool /*_swap*/) const {
_PLYReader_::read_binary(std::fstream& _in, BaseImporter& _bi, bool /*_swap*/) const
{
omlog() << "[PLYReader] : read binary file format\n"; omlog() << "[PLYReader] : read binary file format\n";
// Reparse the header // Reparse the header
if ( !can_u_read(_in) ) { if (!can_u_read(_in)) {
omerr() << "[PLYReader] : Unable to parse header\n"; omerr() << "[PLYReader] : Unable to parse header\n";
return false; return false;
} }
@@ -359,11 +332,10 @@ _PLYReader_::read_binary(std::fstream& _in, BaseImporter& _bi, bool /*_swap*/) c
OpenMesh::Vec4i c; OpenMesh::Vec4i c;
float tmp; float tmp;
_bi.reserve(vertexCount_, 3*vertexCount_, faceCount_); _bi.reserve(vertexCount_, 3* vertexCount_ , faceCount_);
// read vertices: // read vertices:
for (i=0; i< vertexCount_ && !_in.eof(); ++i) for (i = 0; i < vertexCount_ && !_in.eof(); ++i) {
{
v[0] = 0.0; v[0] = 0.0;
v[1] = 0.0; v[1] = 0.0;
v[2] = 0.0; v[2] = 0.0;
@@ -373,78 +345,73 @@ _PLYReader_::read_binary(std::fstream& _in, BaseImporter& _bi, bool /*_swap*/) c
c[2] = 0; c[2] = 0;
c[3] = 255; c[3] = 255;
for ( uint propertyIndex = 0 ; propertyIndex < vertexPropertyCount_; ++propertyIndex ) { for (uint propertyIndex = 0; propertyIndex < vertexPropertyCount_; ++propertyIndex) {
switch ( vertexPropertyMap_ [ propertyIndex].first ) { switch (vertexPropertyMap_[propertyIndex].first) {
case XCOORD: case XCOORD:
readValue(vertexPropertyMap_ [ propertyIndex].second,_in,v[0]); readValue(vertexPropertyMap_[propertyIndex].second, _in, v[0]);
break; break;
case YCOORD: case YCOORD:
readValue(vertexPropertyMap_ [ propertyIndex].second,_in,v[1]); readValue(vertexPropertyMap_[propertyIndex].second, _in, v[1]);
break; break;
case ZCOORD: case ZCOORD:
readValue(vertexPropertyMap_ [ propertyIndex].second,_in,v[2]); readValue(vertexPropertyMap_[propertyIndex].second, _in, v[2]);
break; break;
case COLORRED: case COLORRED:
if ( vertexPropertyMap_ [ propertyIndex].second == ValueTypeFLOAT32 ){ if (vertexPropertyMap_[propertyIndex].second == ValueTypeFLOAT32) {
readValue(vertexPropertyMap_ [ propertyIndex].second,_in,tmp); readValue(vertexPropertyMap_[propertyIndex].second, _in, tmp);
c[0] = static_cast<OpenMesh::Vec4i::value_type>(tmp * 255.0f); c[0] = static_cast<OpenMesh::Vec4i::value_type> (tmp * 255.0f);
}else } else
readValue(vertexPropertyMap_ [ propertyIndex].second,_in,c[0]); readValue(vertexPropertyMap_[propertyIndex].second, _in, c[0]);
break; break;
case COLORGREEN: case COLORGREEN:
if ( vertexPropertyMap_ [ propertyIndex].second == ValueTypeFLOAT32 ){ if (vertexPropertyMap_[propertyIndex].second == ValueTypeFLOAT32) {
readValue(vertexPropertyMap_ [ propertyIndex].second,_in,tmp); readValue(vertexPropertyMap_[propertyIndex].second, _in, tmp);
c[1] = static_cast<OpenMesh::Vec4i::value_type>(tmp * 255.0f); c[1] = static_cast<OpenMesh::Vec4i::value_type> (tmp * 255.0f);
}else } else
readValue(vertexPropertyMap_ [ propertyIndex].second,_in,c[1]); readValue(vertexPropertyMap_[propertyIndex].second, _in, c[1]);
break; break;
case COLORBLUE: case COLORBLUE:
if ( vertexPropertyMap_ [ propertyIndex].second == ValueTypeFLOAT32 ){ if (vertexPropertyMap_[propertyIndex].second == ValueTypeFLOAT32) {
readValue(vertexPropertyMap_ [ propertyIndex].second,_in,tmp); readValue(vertexPropertyMap_[propertyIndex].second, _in, tmp);
c[2] = static_cast<OpenMesh::Vec4i::value_type>(tmp * 255.0f); c[2] = static_cast<OpenMesh::Vec4i::value_type> (tmp * 255.0f);
}else } else
readValue(vertexPropertyMap_ [ propertyIndex].second,_in,c[2]); readValue(vertexPropertyMap_[propertyIndex].second, _in, c[2]);
break; break;
case COLORALPHA: case COLORALPHA:
if ( vertexPropertyMap_ [ propertyIndex].second == ValueTypeFLOAT32 ){ if (vertexPropertyMap_[propertyIndex].second == ValueTypeFLOAT32) {
readValue(vertexPropertyMap_ [ propertyIndex].second,_in,tmp); readValue(vertexPropertyMap_[propertyIndex].second, _in, tmp);
c[3] = static_cast<OpenMesh::Vec4i::value_type>(tmp * 255.0f); c[3] = static_cast<OpenMesh::Vec4i::value_type> (tmp * 255.0f);
}else } else
readValue(vertexPropertyMap_ [ propertyIndex].second,_in,c[3]); readValue(vertexPropertyMap_[propertyIndex].second, _in, c[3]);
break; break;
default : default:
break; break;
} }
} }
vh = _bi.add_vertex(v); vh = _bi.add_vertex(v);
_bi.set_color( vh, Vec4uc( c ) ); _bi.set_color(vh, Vec4uc(c));
} }
for (i=0; i<faceCount_; ++i) for (i = 0; i < faceCount_; ++i) {
{
// Read number of vertices for the current face // Read number of vertices for the current face
readValue(faceIndexType_,_in,nV); readValue(faceIndexType_, _in, nV);
if (nV == 3) if (nV == 3) {
{
vhandles.resize(3); vhandles.resize(3);
readValue(faceEntryType_,_in,j); readValue(faceEntryType_, _in, j);
readValue(faceEntryType_,_in,k); readValue(faceEntryType_, _in, k);
readValue(faceEntryType_,_in,l); readValue(faceEntryType_, _in, l);
vhandles[0] = VertexHandle(j); vhandles[0] = VertexHandle(j);
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) {
{ readValue(faceEntryType_, _in, idx);
readValue(faceEntryType_,_in,idx);
vhandles.push_back(VertexHandle(idx)); vhandles.push_back(VertexHandle(idx));
} }
} }
@@ -455,19 +422,15 @@ _PLYReader_::read_binary(std::fstream& _in, BaseImporter& _bi, bool /*_swap*/) c
return true; return true;
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
bool _PLYReader_::can_u_read(const std::string& _filename) const bool _PLYReader_::can_u_read(const std::string& _filename) const {
{
// !!! Assuming BaseReader::can_u_parse( std::string& ) // !!! Assuming BaseReader::can_u_parse( std::string& )
// does not call BaseReader::read_magic()!!! // does not call BaseReader::read_magic()!!!
if (BaseReader::can_u_read(_filename)) if (BaseReader::can_u_read(_filename)) {
{
std::ifstream ifs(_filename.c_str()); std::ifstream ifs(_filename.c_str());
if (ifs.is_open() && can_u_read(ifs)) if (ifs.is_open() && can_u_read(ifs)) {
{
ifs.close(); ifs.close();
return true; return true;
} }
@@ -475,22 +438,15 @@ bool _PLYReader_::can_u_read(const std::string& _filename) const
return false; return false;
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
std::string get_property_name(std::string _string1 , std::string _string2 ) { std::string get_property_name(std::string _string1, std::string _string2) {
if ( _string1 == "float32" || if (_string1 == "float32" || _string1 == "uint8" || _string1 == "uchar" || _string1 == "float" || _string1
_string1 == "uint8" || == "int32")
_string1 == "uchar" ||
_string1 == "float" ||
_string1 == "int32")
return _string2; return _string2;
if ( _string2 == "float32" || if (_string2 == "float32" || _string2 == "uint8" || _string2 == "uchar" || _string2 == "float" || _string2
_string2 == "uint8" || == "int32")
_string2 == "uchar" ||
_string2 == "float" ||
_string2 == "int32")
return _string1; return _string1;
std::cerr << "Unsupported entry type" << std::endl; std::cerr << "Unsupported entry type" << std::endl;
@@ -499,16 +455,16 @@ std::string get_property_name(std::string _string1 , std::string _string2 ) {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
_PLYReader_::ValueType get_property_type(std::string _string1 , std::string _string2 ) { _PLYReader_::ValueType get_property_type(std::string _string1, std::string _string2) {
if ( _string1 == "float32" || _string2 == "float32" ) if (_string1 == "float32" || _string2 == "float32")
return _PLYReader_::ValueTypeFLOAT32; return _PLYReader_::ValueTypeFLOAT32;
else if ( _string1 == "uint8" || _string2 == "float32" ) else if (_string1 == "uint8" || _string2 == "float32")
return _PLYReader_::ValueTypeUINT8; return _PLYReader_::ValueTypeUINT8;
else if ( _string1 == "int32" || _string2 == "float32" ) else if (_string1 == "int32" || _string2 == "float32")
return _PLYReader_::ValueTypeINT32; return _PLYReader_::ValueTypeINT32;
else if ( _string1 == "uchar" || _string2 == "uchar" ) else if (_string1 == "uchar" || _string2 == "uchar")
return _PLYReader_::ValueTypeUCHAR; return _PLYReader_::ValueTypeUCHAR;
else if ( _string1 == "float" || _string2 == "float" ) else if (_string1 == "float" || _string2 == "float")
return _PLYReader_::ValueTypeFLOAT; return _PLYReader_::ValueTypeFLOAT;
return _PLYReader_::Unsupported; return _PLYReader_::Unsupported;
@@ -516,8 +472,7 @@ _PLYReader_::ValueType get_property_type(std::string _string1 , std::string _str
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
bool _PLYReader_::can_u_read(std::istream& _is) const bool _PLYReader_::can_u_read(std::istream& _is) const {
{
// Clear per file options // Clear per file options
options_.cleanup(); options_.cleanup();
@@ -527,13 +482,13 @@ bool _PLYReader_::can_u_read(std::istream& _is) const
// read 1st line // read 1st line
std::string line; std::string line;
std::getline(_is,line); std::getline(_is, line);
//Check if this file is really a ply format //Check if this file is really a ply format
if ( line != "PLY" && line != "ply" ) if (line != "PLY" && line != "ply")
return false; return false;
// omlog() << "PLY header found" << std::endl; // omlog() << "PLY header found" << std::endl;
vertexCount_ = 0; vertexCount_ = 0;
faceCount_ = 0; faceCount_ = 0;
@@ -552,17 +507,17 @@ bool _PLYReader_::can_u_read(std::istream& _is) const
_is >> fileType; _is >> fileType;
_is >> version; _is >> version;
if ( _is.bad() ) { if (_is.bad()) {
omerr() << "Defect PLY header detected" << std::endl; omerr() << "Defect PLY header detected" << std::endl;
return false; return false;
} }
if ( fileType == "ascii" ) { if (fileType == "ascii") {
options_ -= Options::Binary; options_ -= Options::Binary;
} else if ( fileType == "binary_little_endian" ){ } else if (fileType == "binary_little_endian") {
options_ += Options::Binary; options_ += Options::Binary;
options_ += Options::LSB; options_ += Options::LSB;
} else if ( fileType == "binary_big_endian" ){ } else if (fileType == "binary_big_endian") {
options_ += Options::Binary; options_ += Options::Binary;
options_ += Options::MSB; options_ += Options::MSB;
} else { } else {
@@ -572,46 +527,46 @@ bool _PLYReader_::can_u_read(std::istream& _is) const
unsigned int streamPos = _is.tellg(); unsigned int streamPos = _is.tellg();
_is >> keyword; _is >> keyword;
while ( keyword != "end_header") { while (keyword != "end_header") {
if ( keyword == "comment" ) { if (keyword == "comment") {
std::getline(_is,line); std::getline(_is, line);
omlog() << "PLY header comment : " << line << std::endl; omlog() << "PLY header comment : " << line << std::endl;
} else if ( keyword == "element") { } else if (keyword == "element") {
_is >> elementName; _is >> elementName;
if ( elementName == "vertex" ) { if (elementName == "vertex") {
_is >> vertexCount_; _is >> vertexCount_;
} else if ( elementName == "face" ){ } else if (elementName == "face") {
_is >> faceCount_; _is >> faceCount_;
} else { } else {
omerr() << "PLY header unsupported element type: " << elementName << std::endl; omerr() << "PLY header unsupported element type: " << elementName << std::endl;
} }
} else if ( keyword == "property") { } else if (keyword == "property") {
std::string tmp1; std::string tmp1;
std::string tmp2; std::string tmp2;
// Read first keyword, as it might be a list // Read first keyword, as it might be a list
_is >> tmp1; _is >> tmp1;
if ( tmp1 == "list" ) { if (tmp1 == "list") {
if ( elementName == "vertex" ) { if (elementName == "vertex") {
omerr() << "List type not supported for vertices!" << std::endl; omerr() << "List type not supported for vertices!" << std::endl;
} else if ( elementName == "face" ) { } else if (elementName == "face") {
_is >> listIndexType; _is >> listIndexType;
_is >> listEntryType; _is >> listEntryType;
_is >> propertyName; _is >> propertyName;
if ( listIndexType == "uint8" ) { if (listIndexType == "uint8") {
faceIndexType_ = ValueTypeUINT8; faceIndexType_ = ValueTypeUINT8;
} else if ( listIndexType == "uchar" ) { } else if (listIndexType == "uchar") {
faceIndexType_ = ValueTypeUCHAR; faceIndexType_ = ValueTypeUCHAR;
} else { } else {
omerr() << "Unsupported Index type for face list: " << listIndexType << std::endl; omerr() << "Unsupported Index type for face list: " << listIndexType << std::endl;
} }
if ( listEntryType == "int32" ) { if (listEntryType == "int32") {
faceEntryType_ = ValueTypeINT32; faceEntryType_ = ValueTypeINT32;
} else if ( listEntryType == "int" ) { } else if (listEntryType == "int") {
faceEntryType_ = ValueTypeINT; faceEntryType_ = ValueTypeINT;
} else { } else {
omerr() << "Unsupported Entry type for face list: " << listEntryType << std::endl; omerr() << "Unsupported Entry type for face list: " << listEntryType << std::endl;
@@ -622,48 +577,50 @@ bool _PLYReader_::can_u_read(std::istream& _is) const
// as this is not a list property, read second value of property // as this is not a list property, read second value of property
_is >> tmp2; _is >> tmp2;
if ( elementName == "vertex" ) { if (elementName == "vertex") {
// Extract name and type of property // Extract name and type of property
// As the order seems to be different in some files, autodetect it. // As the order seems to be different in some files, autodetect it.
ValueType valueType = get_property_type(tmp1,tmp2); ValueType valueType = get_property_type(tmp1, tmp2);
propertyName = get_property_name(tmp1,tmp2); propertyName = get_property_name(tmp1, tmp2);
if ( propertyName == "x" ) { if (propertyName == "x") {
std::pair< VertexProperty, ValueType> entry(XCOORD,valueType); std::pair<VertexProperty, ValueType> entry(XCOORD, valueType);
vertexPropertyMap_[vertexPropertyCount_] = entry; vertexPropertyMap_[vertexPropertyCount_] = entry;
vertexDimension_++; vertexDimension_++;
} else if ( propertyName == "y" ) { } else if (propertyName == "y") {
std::pair< VertexProperty, ValueType> entry(YCOORD,valueType); std::pair<VertexProperty, ValueType> entry(YCOORD, valueType);
vertexPropertyMap_[vertexPropertyCount_] = entry; vertexPropertyMap_[vertexPropertyCount_] = entry;
vertexDimension_++; vertexDimension_++;
} else if ( propertyName == "z" ) { } else if (propertyName == "z") {
std::pair< VertexProperty, ValueType> entry(ZCOORD,valueType); std::pair<VertexProperty, ValueType> entry(ZCOORD, valueType);
vertexPropertyMap_[vertexPropertyCount_] = entry; vertexPropertyMap_[vertexPropertyCount_] = entry;
vertexDimension_++; vertexDimension_++;
} else if ( propertyName == "red" ) { } else if (propertyName == "red") {
std::pair< VertexProperty, ValueType> entry(COLORRED,valueType); std::pair<VertexProperty, ValueType> entry(COLORRED, valueType);
vertexPropertyMap_[vertexPropertyCount_] = entry; vertexPropertyMap_[vertexPropertyCount_] = entry;
options_ += Options::VertexColor; options_ += Options::VertexColor;
} else if ( propertyName == "green" ) { } else if (propertyName == "green") {
std::pair< VertexProperty, ValueType> entry(COLORGREEN,valueType); std::pair<VertexProperty, ValueType> entry(COLORGREEN, valueType);
vertexPropertyMap_[vertexPropertyCount_] = entry; vertexPropertyMap_[vertexPropertyCount_] = entry;
options_ += Options::VertexColor; options_ += Options::VertexColor;
} else if ( propertyName == "blue" ) { } else if (propertyName == "blue") {
std::pair< VertexProperty, ValueType> entry(COLORBLUE,valueType); std::pair<VertexProperty, ValueType> entry(COLORBLUE, valueType);
vertexPropertyMap_[vertexPropertyCount_] = entry; vertexPropertyMap_[vertexPropertyCount_] = entry;
options_ += Options::VertexColor; options_ += Options::VertexColor;
} else if ( propertyName == "alpha" ) { } else if (propertyName == "alpha") {
std::pair< VertexProperty, ValueType> entry(COLORALPHA,valueType); std::pair<VertexProperty, ValueType> entry(COLORALPHA, valueType);
vertexPropertyMap_[vertexPropertyCount_] = entry; vertexPropertyMap_[vertexPropertyCount_] = entry;
options_ += Options::VertexColor; options_ += Options::VertexColor;
options_ += Options::ColorAlpha; options_ += Options::ColorAlpha;
} else { } else {
std::pair<VertexProperty, ValueType> entry(UNSUPPORTED, valueType);
vertexPropertyMap_[vertexPropertyCount_] = entry;
std::cerr << "Unsupported property : " << propertyName << std::endl; std::cerr << "Unsupported property : " << propertyName << std::endl;
} }
vertexPropertyCount_++; vertexPropertyCount_++;
} else if ( elementName == "face" ) { } else if (elementName == "face") {
omerr() << "Properties not supported for faces " << std::endl; omerr() << "Properties not supported for faces " << std::endl;
} }
@@ -675,7 +632,7 @@ bool _PLYReader_::can_u_read(std::istream& _is) const
streamPos = _is.tellg(); streamPos = _is.tellg();
_is >> keyword; _is >> keyword;
if ( _is.bad() ) { if (_is.bad()) {
omerr() << "Error while reading PLY file header" << std::endl; omerr() << "Error while reading PLY file header" << std::endl;
return false; return false;
} }
@@ -683,14 +640,13 @@ bool _PLYReader_::can_u_read(std::istream& _is) const
// As the binary data is directy after the end_header keyword // As the binary data is directy after the end_header keyword
// and the stream removes too many bytes, seek back to the right position // and the stream removes too many bytes, seek back to the right position
if ( options_.is_binary() ) { if (options_.is_binary()) {
_is.seekg(streamPos + 12); _is.seekg(streamPos + 12);
} }
return true; return true;
} }
//============================================================================= //=============================================================================
} // namespace IO } // namespace IO
} // namespace OpenMesh } // namespace OpenMesh

View File

@@ -143,7 +143,8 @@ private:
enum VertexProperty { enum VertexProperty {
XCOORD,YCOORD,ZCOORD, XCOORD,YCOORD,ZCOORD,
TEXX,TEXY, TEXX,TEXY,
COLORRED,COLORGREEN,COLORBLUE,COLORALPHA COLORRED,COLORGREEN,COLORBLUE,COLORALPHA,
UNSUPPORTED
}; };