2009-02-06 13:37:46 +00:00
|
|
|
/*===========================================================================*\
|
|
|
|
|
* *
|
|
|
|
|
* OpenMesh *
|
2014-02-05 09:01:07 +00:00
|
|
|
* Copyright (C) 2001-2014 by Computer Graphics Group, RWTH Aachen *
|
2009-02-06 13:37:46 +00:00
|
|
|
* www.openmesh.org *
|
|
|
|
|
* *
|
2009-06-09 15:47:49 +00:00
|
|
|
*---------------------------------------------------------------------------*
|
2009-06-04 08:46:29 +00:00
|
|
|
* This file is part of OpenMesh. *
|
2009-02-06 13:37:46 +00:00
|
|
|
* *
|
2009-06-09 15:47:49 +00:00
|
|
|
* OpenMesh is free software: you can redistribute it and/or modify *
|
2009-06-04 08:46:29 +00:00
|
|
|
* it under the terms of the GNU Lesser General Public License as *
|
|
|
|
|
* published by the Free Software Foundation, either version 3 of *
|
|
|
|
|
* the License, or (at your option) any later version with the *
|
|
|
|
|
* following exceptions: *
|
2009-02-06 13:37:46 +00:00
|
|
|
* *
|
2009-06-04 08:46:29 +00:00
|
|
|
* If other files instantiate templates or use macros *
|
|
|
|
|
* or inline functions from this file, or you compile this file and *
|
|
|
|
|
* link it with other files to produce an executable, this file does *
|
|
|
|
|
* not by itself cause the resulting executable to be covered by the *
|
|
|
|
|
* GNU Lesser General Public License. This exception does not however *
|
|
|
|
|
* invalidate any other reasons why the executable file might be *
|
|
|
|
|
* covered by the GNU Lesser General Public License. *
|
2009-02-06 13:37:46 +00:00
|
|
|
* *
|
2009-06-04 08:46:29 +00:00
|
|
|
* OpenMesh is distributed in the hope that it will be useful, *
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
|
* GNU Lesser General Public License for more details. *
|
2009-02-06 13:37:46 +00:00
|
|
|
* *
|
2009-06-04 08:46:29 +00:00
|
|
|
* You should have received a copy of the GNU LesserGeneral Public *
|
|
|
|
|
* License along with OpenMesh. If not, *
|
|
|
|
|
* see <http://www.gnu.org/licenses/>. *
|
|
|
|
|
* *
|
2009-06-09 15:47:49 +00:00
|
|
|
\*===========================================================================*/
|
2009-06-04 08:46:29 +00:00
|
|
|
|
|
|
|
|
/*===========================================================================*\
|
2009-06-09 15:47:49 +00:00
|
|
|
* *
|
2009-06-04 08:46:29 +00:00
|
|
|
* $Revision$ *
|
|
|
|
|
* $Date$ *
|
2009-02-06 13:37:46 +00:00
|
|
|
* *
|
2009-06-09 15:47:49 +00:00
|
|
|
\*===========================================================================*/
|
2009-02-06 13:37:46 +00:00
|
|
|
|
|
|
|
|
#define LINE_LEN 4096
|
|
|
|
|
|
|
|
|
|
//== INCLUDES =================================================================
|
|
|
|
|
|
|
|
|
|
// OpenMesh
|
|
|
|
|
#include <OpenMesh/Core/System/config.h>
|
|
|
|
|
#include <OpenMesh/Core/System/omstream.hh>
|
|
|
|
|
#include <OpenMesh/Core/IO/reader/PLYReader.hh>
|
|
|
|
|
#include <OpenMesh/Core/IO/importer/BaseImporter.hh>
|
|
|
|
|
#include <OpenMesh/Core/IO/IOManager.hh>
|
|
|
|
|
#include <OpenMesh/Core/Utils/color_cast.hh>
|
|
|
|
|
#include <OpenMesh/Core/IO/SR_store.hh>
|
|
|
|
|
|
|
|
|
|
//STL
|
|
|
|
|
#include <fstream>
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
|
|
#ifndef WIN32
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
//=== NAMESPACES ==============================================================
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace OpenMesh {
|
|
|
|
|
namespace IO {
|
|
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
|
|
//=== INSTANCIATE =============================================================
|
|
|
|
|
|
|
|
|
|
|
2009-06-09 15:47:49 +00:00
|
|
|
_PLYReader_ __PLYReaderInstance;
|
|
|
|
|
_PLYReader_& PLYReader() {
|
2009-12-07 10:26:25 +00:00
|
|
|
return __PLYReaderInstance;
|
2009-06-09 15:47:49 +00:00
|
|
|
}
|
2009-02-06 13:37:46 +00:00
|
|
|
|
|
|
|
|
//=== IMPLEMENTATION ==========================================================
|
|
|
|
|
|
|
|
|
|
|
2009-06-09 15:47:49 +00:00
|
|
|
_PLYReader_::_PLYReader_() {
|
2009-12-07 10:26:25 +00:00
|
|
|
IOManager().register_module(this);
|
2009-12-07 10:31:37 +00:00
|
|
|
|
|
|
|
|
// Store sizes in byte of each property type
|
|
|
|
|
scalar_size_[ValueTypeINT8] = 1;
|
|
|
|
|
scalar_size_[ValueTypeUINT8] = 1;
|
|
|
|
|
scalar_size_[ValueTypeINT16] = 2;
|
|
|
|
|
scalar_size_[ValueTypeUINT16] = 2;
|
|
|
|
|
scalar_size_[ValueTypeINT32] = 4;
|
|
|
|
|
scalar_size_[ValueTypeUINT32] = 4;
|
|
|
|
|
scalar_size_[ValueTypeFLOAT32] = 4;
|
|
|
|
|
scalar_size_[ValueTypeFLOAT64] = 8;
|
|
|
|
|
|
|
|
|
|
scalar_size_[ValueTypeCHAR] = 1;
|
|
|
|
|
scalar_size_[ValueTypeUCHAR] = 1;
|
|
|
|
|
scalar_size_[ValueTypeSHORT] = 2;
|
|
|
|
|
scalar_size_[ValueTypeUSHORT] = 2;
|
|
|
|
|
scalar_size_[ValueTypeINT] = 4;
|
|
|
|
|
scalar_size_[ValueTypeUINT] = 4;
|
|
|
|
|
scalar_size_[ValueTypeFLOAT] = 4;
|
|
|
|
|
scalar_size_[ValueTypeDOUBLE] = 8;
|
2009-02-06 13:37:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
2009-06-09 15:47:49 +00:00
|
|
|
bool _PLYReader_::read(const std::string& _filename, BaseImporter& _bi, Options& _opt) {
|
2009-11-17 13:54:16 +00:00
|
|
|
|
2011-11-28 10:38:24 +00:00
|
|
|
std::fstream in(_filename.c_str(), (std::ios_base::binary | std::ios_base::in) );
|
2009-02-06 13:37:46 +00:00
|
|
|
|
2009-12-07 10:26:25 +00:00
|
|
|
if (!in.is_open() || !in.good()) {
|
|
|
|
|
omerr() << "[PLYReader] : cannot not open file " << _filename << std::endl;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2009-02-06 13:37:46 +00:00
|
|
|
|
2009-12-07 10:26:25 +00:00
|
|
|
bool result = read(in, _bi, _opt);
|
2009-02-06 13:37:46 +00:00
|
|
|
|
2009-12-07 10:26:25 +00:00
|
|
|
in.close();
|
|
|
|
|
return result;
|
2009-02-06 13:37:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
2009-11-17 13:54:16 +00:00
|
|
|
bool _PLYReader_::read(std::istream& _in, BaseImporter& _bi, Options& _opt) {
|
|
|
|
|
|
|
|
|
|
if (!_in.good()) {
|
|
|
|
|
omerr() << "[PLYReader] : cannot not use stream" << std::endl;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-07 10:26:25 +00:00
|
|
|
// filter relevant options for reading
|
|
|
|
|
bool swap = _opt.check(Options::Swap);
|
2009-02-06 13:37:46 +00:00
|
|
|
|
2009-12-07 10:26:25 +00:00
|
|
|
userOptions_ = _opt;
|
2009-02-06 13:37:46 +00:00
|
|
|
|
2009-12-07 10:26:25 +00:00
|
|
|
// build options to be returned
|
|
|
|
|
_opt.clear();
|
2009-02-06 13:37:46 +00:00
|
|
|
|
2009-12-07 10:26:25 +00:00
|
|
|
if (options_.vertex_has_normal() && userOptions_.vertex_has_normal()) {
|
|
|
|
|
_opt += Options::VertexNormal;
|
|
|
|
|
}
|
|
|
|
|
if (options_.vertex_has_texcoord() && userOptions_.vertex_has_texcoord()) {
|
|
|
|
|
_opt += Options::VertexTexCoord;
|
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
}
|
2013-03-01 15:32:46 +00:00
|
|
|
if (options_.color_is_float()) {
|
|
|
|
|
_opt += Options::ColorFloat;
|
|
|
|
|
}
|
2009-02-06 13:37:46 +00:00
|
|
|
|
2009-12-07 10:26:25 +00:00
|
|
|
// //force user-choice for the alpha value when reading binary
|
|
|
|
|
// if ( options_.is_binary() && userOptions_.color_has_alpha() )
|
|
|
|
|
// options_ += Options::ColorAlpha;
|
2009-02-06 13:37:46 +00:00
|
|
|
|
2012-10-08 11:44:29 +00:00
|
|
|
return (options_.is_binary() ? read_binary(_in, _bi, swap, _opt) : read_ascii(_in, _bi, _opt));
|
2009-02-06 13:37:46 +00:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2009-11-17 13:54:16 +00:00
|
|
|
|
|
|
|
|
|
2009-02-06 13:37:46 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2012-10-08 11:44:29 +00:00
|
|
|
bool _PLYReader_::read_ascii(std::istream& _in, BaseImporter& _bi, const Options& _opt) const {
|
2009-06-09 15:47:49 +00:00
|
|
|
|
2009-12-07 10:26:25 +00:00
|
|
|
// Reparse the header
|
|
|
|
|
if (!can_u_read(_in)) {
|
|
|
|
|
omerr() << "[PLYReader] : Unable to parse header\n";
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned int i, j, k, l, idx;
|
|
|
|
|
unsigned int nV;
|
2011-11-25 15:08:38 +00:00
|
|
|
OpenMesh::Vec3f v, n;
|
2009-12-07 10:26:25 +00:00
|
|
|
std::string trash;
|
|
|
|
|
OpenMesh::Vec2f t;
|
|
|
|
|
OpenMesh::Vec4i c;
|
|
|
|
|
float tmp;
|
|
|
|
|
BaseImporter::VHandles vhandles;
|
|
|
|
|
VertexHandle vh;
|
|
|
|
|
|
|
|
|
|
_bi.reserve(vertexCount_, 3* vertexCount_ , faceCount_);
|
|
|
|
|
|
|
|
|
|
if (vertexDimension_ != 3) {
|
|
|
|
|
omerr() << "[PLYReader] : Only vertex dimension 3 is supported." << std::endl;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// read vertices:
|
|
|
|
|
for (i = 0; i < vertexCount_ && !_in.eof(); ++i) {
|
|
|
|
|
v[0] = 0.0;
|
|
|
|
|
v[1] = 0.0;
|
|
|
|
|
v[2] = 0.0;
|
|
|
|
|
|
2011-11-25 15:08:38 +00:00
|
|
|
n[0] = 0.0;
|
|
|
|
|
n[1] = 0.0;
|
|
|
|
|
n[2] = 0.0;
|
|
|
|
|
|
2009-12-07 10:26:25 +00:00
|
|
|
t[0] = 0.0;
|
|
|
|
|
t[1] = 0.0;
|
|
|
|
|
|
|
|
|
|
c[0] = 0;
|
|
|
|
|
c[1] = 0;
|
|
|
|
|
c[2] = 0;
|
|
|
|
|
c[3] = 255;
|
|
|
|
|
|
|
|
|
|
for (uint propertyIndex = 0; propertyIndex < vertexPropertyCount_; ++propertyIndex) {
|
|
|
|
|
switch (vertexPropertyMap_[propertyIndex].first) {
|
|
|
|
|
case XCOORD:
|
|
|
|
|
_in >> v[0];
|
|
|
|
|
break;
|
|
|
|
|
case YCOORD:
|
|
|
|
|
_in >> v[1];
|
|
|
|
|
break;
|
|
|
|
|
case ZCOORD:
|
|
|
|
|
_in >> v[2];
|
|
|
|
|
break;
|
2011-11-25 15:08:38 +00:00
|
|
|
case XNORM:
|
|
|
|
|
_in >> n[0];
|
|
|
|
|
break;
|
|
|
|
|
case YNORM:
|
|
|
|
|
_in >> n[1];
|
|
|
|
|
break;
|
|
|
|
|
case ZNORM:
|
|
|
|
|
_in >> n[2];
|
|
|
|
|
break;
|
2009-12-07 10:26:25 +00:00
|
|
|
case TEXX:
|
|
|
|
|
_in >> t[0];
|
|
|
|
|
break;
|
|
|
|
|
case TEXY:
|
|
|
|
|
_in >> t[1];
|
|
|
|
|
break;
|
|
|
|
|
case COLORRED:
|
2009-12-07 10:31:37 +00:00
|
|
|
if (vertexPropertyMap_[propertyIndex].second == ValueTypeFLOAT32 ||
|
|
|
|
|
vertexPropertyMap_[propertyIndex].second == ValueTypeFLOAT) {
|
2009-12-07 10:26:25 +00:00
|
|
|
_in >> tmp;
|
|
|
|
|
c[0] = static_cast<OpenMesh::Vec4i::value_type> (tmp * 255.0f);
|
|
|
|
|
} else
|
|
|
|
|
_in >> c[0];
|
|
|
|
|
break;
|
|
|
|
|
case COLORGREEN:
|
2009-12-07 10:31:37 +00:00
|
|
|
if (vertexPropertyMap_[propertyIndex].second == ValueTypeFLOAT32 ||
|
|
|
|
|
vertexPropertyMap_[propertyIndex].second == ValueTypeFLOAT) {
|
2009-12-07 10:26:25 +00:00
|
|
|
_in >> tmp;
|
|
|
|
|
c[1] = static_cast<OpenMesh::Vec4i::value_type> (tmp * 255.0f);
|
|
|
|
|
} else
|
|
|
|
|
_in >> c[1];
|
|
|
|
|
break;
|
|
|
|
|
case COLORBLUE:
|
2009-12-07 10:31:37 +00:00
|
|
|
if (vertexPropertyMap_[propertyIndex].second == ValueTypeFLOAT32 ||
|
|
|
|
|
vertexPropertyMap_[propertyIndex].second == ValueTypeFLOAT) {
|
2009-12-07 10:26:25 +00:00
|
|
|
_in >> tmp;
|
|
|
|
|
c[2] = static_cast<OpenMesh::Vec4i::value_type> (tmp * 255.0f);
|
|
|
|
|
} else
|
|
|
|
|
_in >> c[2];
|
|
|
|
|
break;
|
|
|
|
|
case COLORALPHA:
|
2009-12-07 10:31:37 +00:00
|
|
|
if (vertexPropertyMap_[propertyIndex].second == ValueTypeFLOAT32 ||
|
|
|
|
|
vertexPropertyMap_[propertyIndex].second == ValueTypeFLOAT) {
|
2009-12-07 10:26:25 +00:00
|
|
|
_in >> tmp;
|
|
|
|
|
c[3] = static_cast<OpenMesh::Vec4i::value_type> (tmp * 255.0f);
|
|
|
|
|
} else
|
|
|
|
|
_in >> c[3];
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
_in >> trash;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vh = _bi.add_vertex(v);
|
2012-10-08 11:44:29 +00:00
|
|
|
if (_opt.vertex_has_normal())
|
|
|
|
|
_bi.set_normal(vh, n);
|
|
|
|
|
if (_opt.vertex_has_texcoord())
|
|
|
|
|
_bi.set_texcoord(vh, t);
|
|
|
|
|
if (_opt.vertex_has_color())
|
|
|
|
|
_bi.set_color(vh, Vec4uc(c));
|
2009-12-07 10:26:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// faces
|
|
|
|
|
// #N <v1> <v2> .. <v(n-1)> [color spec]
|
|
|
|
|
for (i = 0; i < faceCount_; ++i) {
|
|
|
|
|
// nV = number of Vertices for current face
|
|
|
|
|
_in >> nV;
|
|
|
|
|
|
|
|
|
|
if (nV == 3) {
|
|
|
|
|
vhandles.resize(3);
|
|
|
|
|
_in >> j;
|
|
|
|
|
_in >> k;
|
|
|
|
|
_in >> l;
|
|
|
|
|
|
|
|
|
|
vhandles[0] = VertexHandle(j);
|
|
|
|
|
vhandles[1] = VertexHandle(k);
|
|
|
|
|
vhandles[2] = VertexHandle(l);
|
|
|
|
|
} else {
|
|
|
|
|
vhandles.clear();
|
|
|
|
|
for (j = 0; j < nV; ++j) {
|
|
|
|
|
_in >> idx;
|
|
|
|
|
vhandles.push_back(VertexHandle(idx));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FaceHandle fh = _bi.add_face(vhandles);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// File was successfully parsed.
|
|
|
|
|
return true;
|
2009-02-06 13:37:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2012-10-08 11:44:29 +00:00
|
|
|
bool _PLYReader_::read_binary(std::istream& _in, BaseImporter& _bi, bool /*_swap*/, const Options& _opt) const {
|
2009-06-09 15:47:49 +00:00
|
|
|
|
2009-12-07 10:26:25 +00:00
|
|
|
// Reparse the header
|
|
|
|
|
if (!can_u_read(_in)) {
|
|
|
|
|
omerr() << "[PLYReader] : Unable to parse header\n";
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned int i, j, k, l, idx;
|
|
|
|
|
unsigned int nV;
|
2011-12-01 16:55:24 +00:00
|
|
|
OpenMesh::Vec3f v, n; // Vertex
|
|
|
|
|
OpenMesh::Vec2f t; // TexCoords
|
2009-12-07 10:26:25 +00:00
|
|
|
BaseImporter::VHandles vhandles;
|
2011-12-01 16:55:24 +00:00
|
|
|
VertexHandle vh;
|
|
|
|
|
OpenMesh::Vec4i c; // Color
|
|
|
|
|
float tmp;
|
2009-12-07 10:26:25 +00:00
|
|
|
|
|
|
|
|
_bi.reserve(vertexCount_, 3* vertexCount_ , faceCount_);
|
|
|
|
|
|
|
|
|
|
// read vertices:
|
|
|
|
|
for (i = 0; i < vertexCount_ && !_in.eof(); ++i) {
|
|
|
|
|
v[0] = 0.0;
|
|
|
|
|
v[1] = 0.0;
|
|
|
|
|
v[2] = 0.0;
|
|
|
|
|
|
2011-11-25 15:08:38 +00:00
|
|
|
n[0] = 0.0;
|
|
|
|
|
n[1] = 0.0;
|
|
|
|
|
n[2] = 0.0;
|
|
|
|
|
|
2009-12-07 10:26:25 +00:00
|
|
|
t[0] = 0.0;
|
|
|
|
|
t[1] = 0.0;
|
|
|
|
|
|
|
|
|
|
c[0] = 0;
|
|
|
|
|
c[1] = 0;
|
|
|
|
|
c[2] = 0;
|
|
|
|
|
c[3] = 255;
|
|
|
|
|
|
|
|
|
|
for (uint propertyIndex = 0; propertyIndex < vertexPropertyCount_; ++propertyIndex) {
|
|
|
|
|
switch (vertexPropertyMap_[propertyIndex].first) {
|
|
|
|
|
case XCOORD:
|
|
|
|
|
readValue(vertexPropertyMap_[propertyIndex].second, _in, v[0]);
|
|
|
|
|
break;
|
|
|
|
|
case YCOORD:
|
|
|
|
|
readValue(vertexPropertyMap_[propertyIndex].second, _in, v[1]);
|
|
|
|
|
break;
|
|
|
|
|
case ZCOORD:
|
|
|
|
|
readValue(vertexPropertyMap_[propertyIndex].second, _in, v[2]);
|
|
|
|
|
break;
|
2011-11-25 15:08:38 +00:00
|
|
|
case XNORM:
|
|
|
|
|
readValue(vertexPropertyMap_[propertyIndex].second, _in, n[0]);
|
|
|
|
|
break;
|
|
|
|
|
case YNORM:
|
|
|
|
|
readValue(vertexPropertyMap_[propertyIndex].second, _in, n[1]);
|
|
|
|
|
break;
|
|
|
|
|
case ZNORM:
|
|
|
|
|
readValue(vertexPropertyMap_[propertyIndex].second, _in, n[2]);
|
|
|
|
|
break;
|
2009-12-07 10:26:25 +00:00
|
|
|
case TEXX:
|
|
|
|
|
readValue(vertexPropertyMap_[propertyIndex].second, _in, t[0]);
|
|
|
|
|
break;
|
|
|
|
|
case TEXY:
|
|
|
|
|
readValue(vertexPropertyMap_[propertyIndex].second, _in, t[1]);
|
|
|
|
|
break;
|
|
|
|
|
case COLORRED:
|
2009-12-07 10:31:37 +00:00
|
|
|
if (vertexPropertyMap_[propertyIndex].second == ValueTypeFLOAT32 ||
|
|
|
|
|
vertexPropertyMap_[propertyIndex].second == ValueTypeFLOAT) {
|
2009-12-07 10:26:25 +00:00
|
|
|
readValue(vertexPropertyMap_[propertyIndex].second, _in, tmp);
|
|
|
|
|
|
|
|
|
|
c[0] = static_cast<OpenMesh::Vec4i::value_type> (tmp * 255.0f);
|
|
|
|
|
} else
|
2009-12-07 10:31:37 +00:00
|
|
|
readInteger(vertexPropertyMap_[propertyIndex].second, _in, c[0]);
|
|
|
|
|
|
2009-12-07 10:26:25 +00:00
|
|
|
break;
|
|
|
|
|
case COLORGREEN:
|
2009-12-07 10:31:37 +00:00
|
|
|
if (vertexPropertyMap_[propertyIndex].second == ValueTypeFLOAT32 ||
|
|
|
|
|
vertexPropertyMap_[propertyIndex].second == ValueTypeFLOAT) {
|
2009-12-07 10:26:25 +00:00
|
|
|
readValue(vertexPropertyMap_[propertyIndex].second, _in, tmp);
|
|
|
|
|
c[1] = static_cast<OpenMesh::Vec4i::value_type> (tmp * 255.0f);
|
|
|
|
|
} else
|
2009-12-07 10:31:37 +00:00
|
|
|
readInteger(vertexPropertyMap_[propertyIndex].second, _in, c[1]);
|
|
|
|
|
|
2009-12-07 10:26:25 +00:00
|
|
|
break;
|
|
|
|
|
case COLORBLUE:
|
2009-12-07 10:31:37 +00:00
|
|
|
if (vertexPropertyMap_[propertyIndex].second == ValueTypeFLOAT32 ||
|
|
|
|
|
vertexPropertyMap_[propertyIndex].second == ValueTypeFLOAT) {
|
2009-12-07 10:26:25 +00:00
|
|
|
readValue(vertexPropertyMap_[propertyIndex].second, _in, tmp);
|
|
|
|
|
c[2] = static_cast<OpenMesh::Vec4i::value_type> (tmp * 255.0f);
|
|
|
|
|
} else
|
2009-12-07 10:31:37 +00:00
|
|
|
readInteger(vertexPropertyMap_[propertyIndex].second, _in, c[2]);
|
|
|
|
|
|
2009-12-07 10:26:25 +00:00
|
|
|
break;
|
|
|
|
|
case COLORALPHA:
|
2009-12-07 10:31:37 +00:00
|
|
|
if (vertexPropertyMap_[propertyIndex].second == ValueTypeFLOAT32 ||
|
|
|
|
|
vertexPropertyMap_[propertyIndex].second == ValueTypeFLOAT) {
|
2009-12-07 10:26:25 +00:00
|
|
|
readValue(vertexPropertyMap_[propertyIndex].second, _in, tmp);
|
|
|
|
|
c[3] = static_cast<OpenMesh::Vec4i::value_type> (tmp * 255.0f);
|
|
|
|
|
} else
|
2009-12-07 10:31:37 +00:00
|
|
|
readInteger(vertexPropertyMap_[propertyIndex].second, _in, c[3]);
|
|
|
|
|
|
2009-12-07 10:26:25 +00:00
|
|
|
break;
|
|
|
|
|
default:
|
2009-12-07 10:31:37 +00:00
|
|
|
// Read unsupported property
|
|
|
|
|
consume_input(_in, scalar_size_[vertexPropertyMap_[propertyIndex].second]);
|
2009-12-07 10:26:25 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vh = _bi.add_vertex(v);
|
2012-10-08 11:44:29 +00:00
|
|
|
if (_opt.vertex_has_normal())
|
|
|
|
|
_bi.set_normal(vh, n);
|
|
|
|
|
if (_opt.vertex_has_texcoord())
|
|
|
|
|
_bi.set_texcoord(vh, t);
|
|
|
|
|
if (_opt.vertex_has_color())
|
|
|
|
|
_bi.set_color(vh, Vec4uc(c));
|
2009-12-07 10:26:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < faceCount_; ++i) {
|
|
|
|
|
// Read number of vertices for the current face
|
|
|
|
|
readValue(faceIndexType_, _in, nV);
|
|
|
|
|
|
|
|
|
|
if (nV == 3) {
|
|
|
|
|
vhandles.resize(3);
|
2009-12-07 10:31:37 +00:00
|
|
|
readInteger(faceEntryType_, _in, j);
|
|
|
|
|
readInteger(faceEntryType_, _in, k);
|
|
|
|
|
readInteger(faceEntryType_, _in, l);
|
2009-12-07 10:26:25 +00:00
|
|
|
|
|
|
|
|
vhandles[0] = VertexHandle(j);
|
|
|
|
|
vhandles[1] = VertexHandle(k);
|
|
|
|
|
vhandles[2] = VertexHandle(l);
|
|
|
|
|
} else {
|
|
|
|
|
vhandles.clear();
|
|
|
|
|
for (j = 0; j < nV; ++j) {
|
2009-12-07 10:31:37 +00:00
|
|
|
readInteger(faceEntryType_, _in, idx);
|
2009-12-07 10:26:25 +00:00
|
|
|
vhandles.push_back(VertexHandle(idx));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FaceHandle fh = _bi.add_face(vhandles);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
2009-02-06 13:37:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2009-06-12 12:46:12 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
2009-11-17 13:54:16 +00:00
|
|
|
void _PLYReader_::readValue(ValueType _type, std::istream& _in, float& _value) const {
|
2009-06-12 12:46:12 +00:00
|
|
|
|
2009-12-07 10:26:25 +00:00
|
|
|
switch (_type) {
|
|
|
|
|
case ValueTypeFLOAT32:
|
|
|
|
|
case ValueTypeFLOAT:
|
|
|
|
|
float32_t tmp;
|
|
|
|
|
restore(_in, tmp, options_.check(Options::MSB));
|
|
|
|
|
_value = tmp;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
_value = 0.0;
|
|
|
|
|
std::cerr << "unsupported conversion type to float: " << _type << std::endl;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2009-06-12 12:46:12 +00:00
|
|
|
}
|
|
|
|
|
|
2009-12-07 10:31:37 +00:00
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void _PLYReader_::readValue(ValueType _type, std::istream& _in, double& _value) const {
|
|
|
|
|
|
|
|
|
|
switch (_type) {
|
2012-10-08 11:44:29 +00:00
|
|
|
|
2009-12-07 10:31:37 +00:00
|
|
|
case ValueTypeFLOAT64:
|
|
|
|
|
|
|
|
|
|
case ValueTypeDOUBLE:
|
|
|
|
|
|
|
|
|
|
float64_t tmp;
|
|
|
|
|
restore(_in, tmp, options_.check(Options::MSB));
|
|
|
|
|
_value = tmp;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
|
|
_value = 0.0;
|
|
|
|
|
std::cerr << "unsupported conversion type to double: " << _type << std::endl;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
2009-11-17 13:54:16 +00:00
|
|
|
void _PLYReader_::readValue(ValueType _type, std::istream& _in, unsigned int& _value) const {
|
2009-06-12 12:46:12 +00:00
|
|
|
|
2009-12-07 10:31:37 +00:00
|
|
|
uint32_t tmp_uint32_t;
|
|
|
|
|
uint16_t tmp_uint16_t;
|
2009-12-07 10:26:25 +00:00
|
|
|
uint8_t tmp_uchar;
|
|
|
|
|
|
|
|
|
|
switch (_type) {
|
2009-12-07 10:31:37 +00:00
|
|
|
|
|
|
|
|
case ValueTypeUINT:
|
|
|
|
|
|
|
|
|
|
case ValueTypeUINT32:
|
2012-10-08 11:44:29 +00:00
|
|
|
|
2009-12-07 10:31:37 +00:00
|
|
|
restore(_in, tmp_uint32_t, options_.check(Options::MSB));
|
|
|
|
|
_value = tmp_uint32_t;
|
|
|
|
|
|
2009-12-07 10:26:25 +00:00
|
|
|
break;
|
2009-12-07 10:31:37 +00:00
|
|
|
|
|
|
|
|
case ValueTypeUSHORT:
|
|
|
|
|
|
|
|
|
|
case ValueTypeUINT16:
|
|
|
|
|
|
|
|
|
|
restore(_in, tmp_uint16_t, options_.check(Options::MSB));
|
|
|
|
|
_value = tmp_uint16_t;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case ValueTypeUCHAR:
|
|
|
|
|
|
|
|
|
|
case ValueTypeUINT8:
|
|
|
|
|
|
|
|
|
|
restore(_in, tmp_uchar, options_.check(Options::MSB));
|
|
|
|
|
_value = tmp_uchar;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
|
|
_value = 0;
|
|
|
|
|
std::cerr << "unsupported conversion type to unsigned int: " << _type << std::endl;
|
|
|
|
|
|
|
|
|
|
break;
|
2009-12-07 10:26:25 +00:00
|
|
|
}
|
2009-06-12 12:46:12 +00:00
|
|
|
}
|
|
|
|
|
|
2009-12-07 10:31:37 +00:00
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
2009-11-17 13:54:16 +00:00
|
|
|
void _PLYReader_::readValue(ValueType _type, std::istream& _in, int& _value) const {
|
2009-06-12 12:46:12 +00:00
|
|
|
|
2009-12-07 10:26:25 +00:00
|
|
|
int32_t tmp_int32_t;
|
2009-12-07 10:31:37 +00:00
|
|
|
int16_t tmp_int16_t;
|
|
|
|
|
int8_t tmp_char;
|
|
|
|
|
|
|
|
|
|
switch (_type) {
|
|
|
|
|
|
|
|
|
|
case ValueTypeINT:
|
|
|
|
|
|
|
|
|
|
case ValueTypeINT32:
|
|
|
|
|
|
|
|
|
|
restore(_in, tmp_int32_t, options_.check(Options::MSB));
|
|
|
|
|
_value = tmp_int32_t;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case ValueTypeSHORT:
|
|
|
|
|
|
|
|
|
|
case ValueTypeINT16:
|
|
|
|
|
|
|
|
|
|
restore(_in, tmp_int16_t, options_.check(Options::MSB));
|
|
|
|
|
_value = tmp_int16_t;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case ValueTypeCHAR:
|
|
|
|
|
|
|
|
|
|
case ValueTypeINT8:
|
|
|
|
|
|
|
|
|
|
restore(_in, tmp_char, options_.check(Options::MSB));
|
|
|
|
|
_value = tmp_char;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
|
|
_value = 0;
|
|
|
|
|
std::cerr << "unsupported conversion type to int: " << _type << std::endl;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void _PLYReader_::readInteger(ValueType _type, std::istream& _in, int& _value) const {
|
|
|
|
|
|
|
|
|
|
int32_t tmp_int32_t;
|
|
|
|
|
uint32_t tmp_uint32_t;
|
|
|
|
|
int8_t tmp_char;
|
2009-12-07 10:26:25 +00:00
|
|
|
uint8_t tmp_uchar;
|
|
|
|
|
|
|
|
|
|
switch (_type) {
|
2009-12-07 10:31:37 +00:00
|
|
|
|
|
|
|
|
case ValueTypeINT:
|
|
|
|
|
|
|
|
|
|
case ValueTypeINT32:
|
|
|
|
|
|
|
|
|
|
restore(_in, tmp_int32_t, options_.check(Options::MSB));
|
|
|
|
|
_value = tmp_int32_t;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case ValueTypeUINT:
|
|
|
|
|
|
|
|
|
|
case ValueTypeUINT32:
|
|
|
|
|
|
|
|
|
|
restore(_in, tmp_uint32_t, options_.check(Options::MSB));
|
|
|
|
|
_value = tmp_uint32_t;
|
2012-10-08 11:44:29 +00:00
|
|
|
|
2009-12-07 10:31:37 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case ValueTypeCHAR:
|
|
|
|
|
|
|
|
|
|
case ValueTypeINT8:
|
|
|
|
|
|
|
|
|
|
restore(_in, tmp_char, options_.check(Options::MSB));
|
|
|
|
|
_value = tmp_char;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case ValueTypeUCHAR:
|
|
|
|
|
|
|
|
|
|
case ValueTypeUINT8:
|
|
|
|
|
|
|
|
|
|
restore(_in, tmp_uchar, options_.check(Options::MSB));
|
|
|
|
|
_value = tmp_uchar;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
|
|
_value = 0;
|
|
|
|
|
std::cerr << "unsupported conversion type to int: " << _type << std::endl;
|
|
|
|
|
|
|
|
|
|
break;
|
2009-12-07 10:26:25 +00:00
|
|
|
}
|
2009-06-12 12:46:12 +00:00
|
|
|
}
|
|
|
|
|
|
2009-12-07 10:31:37 +00:00
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void _PLYReader_::readInteger(ValueType _type, std::istream& _in, unsigned int& _value) const {
|
|
|
|
|
|
|
|
|
|
int32_t tmp_int32_t;
|
|
|
|
|
uint32_t tmp_uint32_t;
|
|
|
|
|
int8_t tmp_char;
|
|
|
|
|
uint8_t tmp_uchar;
|
|
|
|
|
|
|
|
|
|
switch (_type) {
|
|
|
|
|
|
|
|
|
|
case ValueTypeUINT:
|
|
|
|
|
|
|
|
|
|
case ValueTypeUINT32:
|
|
|
|
|
|
|
|
|
|
restore(_in, tmp_uint32_t, options_.check(Options::MSB));
|
|
|
|
|
_value = tmp_uint32_t;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case ValueTypeINT:
|
|
|
|
|
|
|
|
|
|
case ValueTypeINT32:
|
|
|
|
|
|
|
|
|
|
restore(_in, tmp_int32_t, options_.check(Options::MSB));
|
|
|
|
|
_value = tmp_int32_t;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case ValueTypeUCHAR:
|
|
|
|
|
|
|
|
|
|
case ValueTypeUINT8:
|
|
|
|
|
|
|
|
|
|
restore(_in, tmp_uchar, options_.check(Options::MSB));
|
|
|
|
|
_value = tmp_uchar;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case ValueTypeCHAR:
|
|
|
|
|
|
|
|
|
|
case ValueTypeINT8:
|
|
|
|
|
|
|
|
|
|
restore(_in, tmp_char, options_.check(Options::MSB));
|
|
|
|
|
_value = tmp_char;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
|
|
_value = 0;
|
|
|
|
|
std::cerr << "unsupported conversion type to unsigned int: " << _type << std::endl;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2009-06-12 12:46:12 +00:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
2009-12-07 10:31:37 +00:00
|
|
|
|
2009-06-09 15:47:49 +00:00
|
|
|
bool _PLYReader_::can_u_read(const std::string& _filename) const {
|
2012-10-08 11:44:29 +00:00
|
|
|
|
2009-12-07 10:26:25 +00:00
|
|
|
// !!! Assuming BaseReader::can_u_parse( std::string& )
|
|
|
|
|
// does not call BaseReader::read_magic()!!!
|
|
|
|
|
|
|
|
|
|
if (BaseReader::can_u_read(_filename)) {
|
|
|
|
|
std::ifstream ifs(_filename.c_str());
|
|
|
|
|
if (ifs.is_open() && can_u_read(ifs)) {
|
|
|
|
|
ifs.close();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
2009-02-06 13:37:46 +00:00
|
|
|
}
|
|
|
|
|
|
2009-12-07 10:31:37 +00:00
|
|
|
|
|
|
|
|
|
2009-02-06 13:37:46 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2009-06-09 15:47:49 +00:00
|
|
|
std::string get_property_name(std::string _string1, std::string _string2) {
|
2012-10-08 11:44:29 +00:00
|
|
|
|
2009-12-07 10:31:37 +00:00
|
|
|
if (_string1 == "float32" || _string1 == "float64" || _string1 == "float" || _string1 == "double" ||
|
|
|
|
|
_string1 == "int8" || _string1 == "uint8" || _string1 == "char" || _string1 == "uchar" ||
|
|
|
|
|
_string1 == "int32" || _string1 == "uint32" || _string1 == "int" || _string1 == "uint" ||
|
|
|
|
|
_string1 == "int16" || _string1 == "uint16" || _string1 == "short" || _string1 == "ushort")
|
2009-12-07 10:26:25 +00:00
|
|
|
return _string2;
|
2009-06-09 15:47:49 +00:00
|
|
|
|
2009-12-07 10:31:37 +00:00
|
|
|
if (_string2 == "float32" || _string2 == "float64" || _string2 == "float" || _string2 == "double" ||
|
|
|
|
|
_string2 == "int8" || _string2 == "uint8" || _string2 == "char" || _string2 == "uchar" ||
|
|
|
|
|
_string2 == "int32" || _string2 == "uint32" || _string2 == "int" || _string2 == "uint" ||
|
|
|
|
|
_string2 == "int16" || _string2 == "uint16" || _string2 == "short" || _string2 == "ushort")
|
2009-12-07 10:26:25 +00:00
|
|
|
return _string1;
|
2009-06-09 15:47:49 +00:00
|
|
|
|
2009-12-07 10:31:37 +00:00
|
|
|
|
2009-12-07 10:26:25 +00:00
|
|
|
std::cerr << "Unsupported entry type" << std::endl;
|
|
|
|
|
return "Unsupported";
|
2009-02-06 13:37:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2009-06-09 15:47:49 +00:00
|
|
|
_PLYReader_::ValueType get_property_type(std::string _string1, std::string _string2) {
|
2009-12-07 10:31:37 +00:00
|
|
|
|
2009-12-07 10:26:25 +00:00
|
|
|
if (_string1 == "float32" || _string2 == "float32")
|
2009-12-07 10:31:37 +00:00
|
|
|
|
2009-12-07 10:26:25 +00:00
|
|
|
return _PLYReader_::ValueTypeFLOAT32;
|
2009-12-07 10:31:37 +00:00
|
|
|
|
|
|
|
|
else if (_string1 == "float64" || _string2 == "float64")
|
|
|
|
|
|
|
|
|
|
return _PLYReader_::ValueTypeFLOAT64;
|
|
|
|
|
|
|
|
|
|
else if (_string1 == "float" || _string2 == "float")
|
|
|
|
|
|
|
|
|
|
return _PLYReader_::ValueTypeFLOAT;
|
|
|
|
|
|
|
|
|
|
else if (_string1 == "double" || _string2 == "double")
|
|
|
|
|
|
|
|
|
|
return _PLYReader_::ValueTypeDOUBLE;
|
|
|
|
|
|
|
|
|
|
else if (_string1 == "int8" || _string2 == "int8")
|
|
|
|
|
|
|
|
|
|
return _PLYReader_::ValueTypeINT8;
|
|
|
|
|
|
|
|
|
|
else if (_string1 == "uint8" || _string2 == "uint8")
|
|
|
|
|
|
2009-12-07 10:26:25 +00:00
|
|
|
return _PLYReader_::ValueTypeUINT8;
|
2009-12-07 10:31:37 +00:00
|
|
|
|
|
|
|
|
else if (_string1 == "char" || _string2 == "char")
|
|
|
|
|
|
|
|
|
|
return _PLYReader_::ValueTypeCHAR;
|
|
|
|
|
|
2009-12-07 10:26:25 +00:00
|
|
|
else if (_string1 == "uchar" || _string2 == "uchar")
|
2009-12-07 10:31:37 +00:00
|
|
|
|
2009-12-07 10:26:25 +00:00
|
|
|
return _PLYReader_::ValueTypeUCHAR;
|
2009-12-07 10:31:37 +00:00
|
|
|
|
|
|
|
|
else if (_string1 == "int32" || _string2 == "int32")
|
|
|
|
|
|
|
|
|
|
return _PLYReader_::ValueTypeINT32;
|
|
|
|
|
|
|
|
|
|
else if (_string1 == "uint32" || _string2 == "uint32")
|
|
|
|
|
|
|
|
|
|
return _PLYReader_::ValueTypeUINT32;
|
|
|
|
|
|
|
|
|
|
else if (_string1 == "int" || _string2 == "int")
|
|
|
|
|
|
|
|
|
|
return _PLYReader_::ValueTypeINT;
|
|
|
|
|
|
|
|
|
|
else if (_string1 == "uint" || _string2 == "uint")
|
|
|
|
|
|
|
|
|
|
return _PLYReader_::ValueTypeUINT;
|
|
|
|
|
|
|
|
|
|
else if (_string1 == "int16" || _string2 == "int16")
|
|
|
|
|
|
|
|
|
|
return _PLYReader_::ValueTypeINT16;
|
|
|
|
|
|
|
|
|
|
else if (_string1 == "uint16" || _string2 == "uint16")
|
|
|
|
|
|
|
|
|
|
return _PLYReader_::ValueTypeUINT16;
|
|
|
|
|
|
|
|
|
|
else if (_string1 == "short" || _string2 == "short")
|
|
|
|
|
|
|
|
|
|
return _PLYReader_::ValueTypeSHORT;
|
|
|
|
|
|
|
|
|
|
else if (_string1 == "ushort" || _string2 == "ushort")
|
|
|
|
|
|
|
|
|
|
return _PLYReader_::ValueTypeUSHORT;
|
2009-12-07 10:26:25 +00:00
|
|
|
|
|
|
|
|
return _PLYReader_::Unsupported;
|
2009-02-06 13:37:46 +00:00
|
|
|
}
|
|
|
|
|
|
2009-12-07 10:31:37 +00:00
|
|
|
|
2009-02-06 13:37:46 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2009-06-09 15:47:49 +00:00
|
|
|
bool _PLYReader_::can_u_read(std::istream& _is) const {
|
2009-12-07 10:31:37 +00:00
|
|
|
|
2009-12-07 10:26:25 +00:00
|
|
|
// Clear per file options
|
|
|
|
|
options_.cleanup();
|
|
|
|
|
|
|
|
|
|
// clear vertex property map, will be recreated
|
|
|
|
|
vertexPropertyMap_.clear();
|
|
|
|
|
vertexPropertyCount_ = 0;
|
|
|
|
|
|
|
|
|
|
// read 1st line
|
|
|
|
|
std::string line;
|
|
|
|
|
std::getline(_is, line);
|
2011-11-28 11:46:16 +00:00
|
|
|
trim(line);
|
2009-12-07 10:26:25 +00:00
|
|
|
|
|
|
|
|
//Check if this file is really a ply format
|
|
|
|
|
if (line != "PLY" && line != "ply")
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
vertexCount_ = 0;
|
|
|
|
|
faceCount_ = 0;
|
|
|
|
|
vertexDimension_ = 0;
|
|
|
|
|
|
|
|
|
|
std::string keyword;
|
|
|
|
|
std::string fileType;
|
|
|
|
|
std::string elementName = "";
|
|
|
|
|
std::string propertyName;
|
|
|
|
|
std::string listIndexType;
|
|
|
|
|
std::string listEntryType;
|
|
|
|
|
float version;
|
|
|
|
|
|
|
|
|
|
_is >> keyword;
|
|
|
|
|
_is >> fileType;
|
|
|
|
|
_is >> version;
|
|
|
|
|
|
|
|
|
|
if (_is.bad()) {
|
|
|
|
|
omerr() << "Defect PLY header detected" << std::endl;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (fileType == "ascii") {
|
|
|
|
|
options_ -= Options::Binary;
|
|
|
|
|
} else if (fileType == "binary_little_endian") {
|
|
|
|
|
options_ += Options::Binary;
|
|
|
|
|
options_ += Options::LSB;
|
2009-12-07 10:31:37 +00:00
|
|
|
//if (Endian::local() == Endian::MSB)
|
|
|
|
|
|
|
|
|
|
// options_ += Options::Swap;
|
2009-12-07 10:26:25 +00:00
|
|
|
} else if (fileType == "binary_big_endian") {
|
|
|
|
|
options_ += Options::Binary;
|
|
|
|
|
options_ += Options::MSB;
|
2009-12-07 10:31:37 +00:00
|
|
|
//if (Endian::local() == Endian::LSB)
|
|
|
|
|
|
|
|
|
|
// options_ += Options::Swap;
|
2009-12-07 10:26:25 +00:00
|
|
|
} else {
|
|
|
|
|
omerr() << "Unsupported PLY format: " << fileType << std::endl;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-26 15:49:14 +00:00
|
|
|
std::streamoff streamPos = _is.tellg();
|
2009-12-07 10:26:25 +00:00
|
|
|
_is >> keyword;
|
|
|
|
|
while (keyword != "end_header") {
|
|
|
|
|
|
|
|
|
|
if (keyword == "comment") {
|
|
|
|
|
std::getline(_is, line);
|
|
|
|
|
} else if (keyword == "element") {
|
|
|
|
|
_is >> elementName;
|
|
|
|
|
if (elementName == "vertex") {
|
|
|
|
|
_is >> vertexCount_;
|
|
|
|
|
} else if (elementName == "face") {
|
|
|
|
|
_is >> faceCount_;
|
|
|
|
|
} else {
|
|
|
|
|
omerr() << "PLY header unsupported element type: " << elementName << std::endl;
|
|
|
|
|
}
|
|
|
|
|
} else if (keyword == "property") {
|
|
|
|
|
std::string tmp1;
|
|
|
|
|
std::string tmp2;
|
|
|
|
|
|
|
|
|
|
// Read first keyword, as it might be a list
|
|
|
|
|
_is >> tmp1;
|
|
|
|
|
|
|
|
|
|
if (tmp1 == "list") {
|
|
|
|
|
if (elementName == "vertex") {
|
|
|
|
|
omerr() << "List type not supported for vertices!" << std::endl;
|
|
|
|
|
} else if (elementName == "face") {
|
|
|
|
|
_is >> listIndexType;
|
|
|
|
|
_is >> listEntryType;
|
|
|
|
|
_is >> propertyName;
|
|
|
|
|
|
|
|
|
|
if (listIndexType == "uint8") {
|
|
|
|
|
faceIndexType_ = ValueTypeUINT8;
|
|
|
|
|
} else if (listIndexType == "uchar") {
|
|
|
|
|
faceIndexType_ = ValueTypeUCHAR;
|
|
|
|
|
} else {
|
|
|
|
|
omerr() << "Unsupported Index type for face list: " << listIndexType << std::endl;
|
2014-05-07 11:43:53 +00:00
|
|
|
return false;
|
2009-12-07 10:26:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (listEntryType == "int32") {
|
|
|
|
|
faceEntryType_ = ValueTypeINT32;
|
|
|
|
|
} else if (listEntryType == "int") {
|
|
|
|
|
faceEntryType_ = ValueTypeINT;
|
2014-05-07 11:43:53 +00:00
|
|
|
} else if (listEntryType == "uint32") {
|
|
|
|
|
faceEntryType_ = ValueTypeUINT32;
|
|
|
|
|
} else if (listEntryType == "uint") {
|
|
|
|
|
faceEntryType_ = ValueTypeUINT;
|
2009-12-07 10:26:25 +00:00
|
|
|
} else {
|
|
|
|
|
omerr() << "Unsupported Entry type for face list: " << listEntryType << std::endl;
|
2014-05-07 11:43:53 +00:00
|
|
|
return false;
|
2009-12-07 10:26:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// as this is not a list property, read second value of property
|
|
|
|
|
_is >> tmp2;
|
|
|
|
|
|
|
|
|
|
if (elementName == "vertex") {
|
|
|
|
|
// Extract name and type of property
|
|
|
|
|
// As the order seems to be different in some files, autodetect it.
|
|
|
|
|
ValueType valueType = get_property_type(tmp1, tmp2);
|
|
|
|
|
propertyName = get_property_name(tmp1, tmp2);
|
|
|
|
|
|
|
|
|
|
if (propertyName == "x") {
|
|
|
|
|
std::pair<VertexProperty, ValueType> entry(XCOORD, valueType);
|
|
|
|
|
vertexPropertyMap_[vertexPropertyCount_] = entry;
|
|
|
|
|
vertexDimension_++;
|
|
|
|
|
} else if (propertyName == "y") {
|
|
|
|
|
std::pair<VertexProperty, ValueType> entry(YCOORD, valueType);
|
|
|
|
|
vertexPropertyMap_[vertexPropertyCount_] = entry;
|
|
|
|
|
vertexDimension_++;
|
|
|
|
|
} else if (propertyName == "z") {
|
|
|
|
|
std::pair<VertexProperty, ValueType> entry(ZCOORD, valueType);
|
|
|
|
|
vertexPropertyMap_[vertexPropertyCount_] = entry;
|
|
|
|
|
vertexDimension_++;
|
2011-11-25 15:08:38 +00:00
|
|
|
} else if (propertyName == "nx") {
|
|
|
|
|
std::pair<VertexProperty, ValueType> entry(XNORM, valueType);
|
|
|
|
|
vertexPropertyMap_[vertexPropertyCount_] = entry;
|
|
|
|
|
options_ += Options::VertexNormal;
|
|
|
|
|
} else if (propertyName == "ny") {
|
|
|
|
|
std::pair<VertexProperty, ValueType> entry(YNORM, valueType);
|
|
|
|
|
vertexPropertyMap_[vertexPropertyCount_] = entry;
|
|
|
|
|
options_ += Options::VertexNormal;
|
|
|
|
|
} else if (propertyName == "nz") {
|
|
|
|
|
std::pair<VertexProperty, ValueType> entry(ZNORM, valueType);
|
|
|
|
|
vertexPropertyMap_[vertexPropertyCount_] = entry;
|
|
|
|
|
options_ += Options::VertexNormal;
|
2009-12-07 10:26:25 +00:00
|
|
|
} else if (propertyName == "u" || propertyName == "s") {
|
|
|
|
|
std::pair<VertexProperty, ValueType> entry(TEXX, valueType);
|
|
|
|
|
vertexPropertyMap_[vertexPropertyCount_] = entry;
|
|
|
|
|
options_ += Options::VertexTexCoord;
|
|
|
|
|
} else if (propertyName == "v" || propertyName == "t") {
|
|
|
|
|
std::pair<VertexProperty, ValueType> entry(TEXY, valueType);
|
|
|
|
|
vertexPropertyMap_[vertexPropertyCount_] = entry;
|
|
|
|
|
options_ += Options::VertexTexCoord;
|
|
|
|
|
} else if (propertyName == "red") {
|
|
|
|
|
std::pair<VertexProperty, ValueType> entry(COLORRED, valueType);
|
|
|
|
|
vertexPropertyMap_[vertexPropertyCount_] = entry;
|
|
|
|
|
options_ += Options::VertexColor;
|
2013-03-01 15:32:46 +00:00
|
|
|
if (valueType == ValueTypeFLOAT || valueType == ValueTypeFLOAT32)
|
|
|
|
|
options_ += Options::ColorFloat;
|
2009-12-07 10:26:25 +00:00
|
|
|
} else if (propertyName == "green") {
|
|
|
|
|
std::pair<VertexProperty, ValueType> entry(COLORGREEN, valueType);
|
|
|
|
|
vertexPropertyMap_[vertexPropertyCount_] = entry;
|
|
|
|
|
options_ += Options::VertexColor;
|
2013-03-01 15:32:46 +00:00
|
|
|
if (valueType == ValueTypeFLOAT || valueType == ValueTypeFLOAT32)
|
|
|
|
|
options_ += Options::ColorFloat;
|
2009-12-07 10:26:25 +00:00
|
|
|
} else if (propertyName == "blue") {
|
|
|
|
|
std::pair<VertexProperty, ValueType> entry(COLORBLUE, valueType);
|
|
|
|
|
vertexPropertyMap_[vertexPropertyCount_] = entry;
|
|
|
|
|
options_ += Options::VertexColor;
|
2013-03-01 15:32:46 +00:00
|
|
|
if (valueType == ValueTypeFLOAT || valueType == ValueTypeFLOAT32)
|
|
|
|
|
options_ += Options::ColorFloat;
|
2010-11-18 07:20:06 +00:00
|
|
|
} else if (propertyName == "diffuse_red") {
|
|
|
|
|
std::pair<VertexProperty, ValueType> entry(COLORRED, valueType);
|
|
|
|
|
vertexPropertyMap_[vertexPropertyCount_] = entry;
|
|
|
|
|
options_ += Options::VertexColor;
|
2013-03-01 15:32:46 +00:00
|
|
|
if (valueType == ValueTypeFLOAT || valueType == ValueTypeFLOAT32)
|
|
|
|
|
options_ += Options::ColorFloat;
|
2010-11-18 07:20:06 +00:00
|
|
|
} else if (propertyName == "diffuse_green") {
|
|
|
|
|
std::pair<VertexProperty, ValueType> entry(COLORGREEN, valueType);
|
|
|
|
|
vertexPropertyMap_[vertexPropertyCount_] = entry;
|
|
|
|
|
options_ += Options::VertexColor;
|
2013-03-01 15:32:46 +00:00
|
|
|
if (valueType == ValueTypeFLOAT || valueType == ValueTypeFLOAT32)
|
|
|
|
|
options_ += Options::ColorFloat;
|
2010-11-18 07:20:06 +00:00
|
|
|
} else if (propertyName == "diffuse_blue") {
|
|
|
|
|
std::pair<VertexProperty, ValueType> entry(COLORBLUE, valueType);
|
|
|
|
|
vertexPropertyMap_[vertexPropertyCount_] = entry;
|
2012-10-08 11:44:29 +00:00
|
|
|
options_ += Options::VertexColor;
|
2013-03-01 15:32:46 +00:00
|
|
|
if (valueType == ValueTypeFLOAT || valueType == ValueTypeFLOAT32)
|
|
|
|
|
options_ += Options::ColorFloat;
|
2009-12-07 10:26:25 +00:00
|
|
|
} else if (propertyName == "alpha") {
|
|
|
|
|
std::pair<VertexProperty, ValueType> entry(COLORALPHA, valueType);
|
|
|
|
|
vertexPropertyMap_[vertexPropertyCount_] = entry;
|
|
|
|
|
options_ += Options::VertexColor;
|
|
|
|
|
options_ += Options::ColorAlpha;
|
2013-03-01 15:32:46 +00:00
|
|
|
if (valueType == ValueTypeFLOAT || valueType == ValueTypeFLOAT32)
|
|
|
|
|
options_ += Options::ColorFloat;
|
2009-12-07 10:26:25 +00:00
|
|
|
} else {
|
|
|
|
|
std::pair<VertexProperty, ValueType> entry(UNSUPPORTED, valueType);
|
|
|
|
|
vertexPropertyMap_[vertexPropertyCount_] = entry;
|
|
|
|
|
std::cerr << "Unsupported property : " << propertyName << std::endl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vertexPropertyCount_++;
|
|
|
|
|
|
|
|
|
|
} else if (elementName == "face") {
|
|
|
|
|
omerr() << "Properties not supported for faces " << std::endl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
omlog() << "Unsupported keyword : " << keyword << std::endl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
streamPos = _is.tellg();
|
|
|
|
|
_is >> keyword;
|
|
|
|
|
if (_is.bad()) {
|
|
|
|
|
omerr() << "Error while reading PLY file header" << std::endl;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// As the binary data is directy after the end_header keyword
|
|
|
|
|
// and the stream removes too many bytes, seek back to the right position
|
|
|
|
|
if (options_.is_binary()) {
|
|
|
|
|
_is.seekg(streamPos + 12);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
2009-02-06 13:37:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
|
} // namespace IO
|
|
|
|
|
} // namespace OpenMesh
|
|
|
|
|
//=============================================================================
|