Commit 4ccb7712 authored by Mike Kremer's avatar Mike Kremer

Converted all tabs into 4 whitespaces.

git-svn-id: http://www.openmesh.org/svnrepo/OpenMesh/trunk@249 fdac6126-5c0c-442c-9429-916003d36597
parent de9594ca
......@@ -73,14 +73,14 @@ namespace IO {
_PLYReader_ __PLYReaderInstance;
_PLYReader_& PLYReader() {
return __PLYReaderInstance;
return __PLYReaderInstance;
}
//=== IMPLEMENTATION ==========================================================
_PLYReader_::_PLYReader_() {
IOManager().register_module(this);
IOManager().register_module(this);
}
//-----------------------------------------------------------------------------
......@@ -88,18 +88,18 @@ _PLYReader_::_PLYReader_() {
bool _PLYReader_::read(const std::string& _filename, BaseImporter& _bi, Options& _opt) {
std::fstream in(_filename.c_str(), (options_.is_binary() ? std::ios_base::binary | std::ios_base::in
: std::ios_base::in));
std::fstream in(_filename.c_str(), (options_.is_binary() ? std::ios_base::binary | std::ios_base::in
: std::ios_base::in));
if (!in.is_open() || !in.good()) {
omerr() << "[PLYReader] : cannot not open file " << _filename << std::endl;
return false;
}
if (!in.is_open() || !in.good()) {
omerr() << "[PLYReader] : cannot not open file " << _filename << std::endl;
return false;
}
bool result = read(in, _bi, _opt);
bool result = read(in, _bi, _opt);
in.close();
return result;
in.close();
return result;
}
//-----------------------------------------------------------------------------
......@@ -112,35 +112,35 @@ bool _PLYReader_::read(std::istream& _in, BaseImporter& _bi, Options& _opt) {
return false;
}
// filter relevant options for reading
bool swap = _opt.check(Options::Swap);
// filter relevant options for reading
bool swap = _opt.check(Options::Swap);
userOptions_ = _opt;
userOptions_ = _opt;
// build options to be returned
_opt.clear();
// build options to be returned
_opt.clear();
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;
}
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;
}
// //force user-choice for the alpha value when reading binary
// if ( options_.is_binary() && userOptions_.color_has_alpha() )
// options_ += Options::ColorAlpha;
// //force user-choice for the alpha value when reading binary
// if ( options_.is_binary() && userOptions_.color_has_alpha() )
// options_ += Options::ColorAlpha;
return (options_.is_binary() ? read_binary(_in, _bi, swap) : read_ascii(_in, _bi));
return (options_.is_binary() ? read_binary(_in, _bi, swap) : read_ascii(_in, _bi));
}
......@@ -150,251 +150,251 @@ bool _PLYReader_::read(std::istream& _in, BaseImporter& _bi, Options& _opt) {
bool _PLYReader_::read_ascii(std::istream& _in, BaseImporter& _bi) const {
omlog() << "[PLYReader] : read ascii file\n";
// 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;
OpenMesh::Vec3f v;
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;
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;
case TEXX:
_in >> t[0];
break;
case TEXY:
_in >> t[1];
break;
case COLORRED:
if (vertexPropertyMap_[propertyIndex].second == ValueTypeFLOAT32) {
_in >> tmp;
c[0] = static_cast<OpenMesh::Vec4i::value_type> (tmp * 255.0f);
} else
_in >> c[0];
break;
case COLORGREEN:
if (vertexPropertyMap_[propertyIndex].second == ValueTypeFLOAT32) {
_in >> tmp;
c[1] = static_cast<OpenMesh::Vec4i::value_type> (tmp * 255.0f);
} else
_in >> c[1];
break;
case COLORBLUE:
if (vertexPropertyMap_[propertyIndex].second == ValueTypeFLOAT32) {
_in >> tmp;
c[2] = static_cast<OpenMesh::Vec4i::value_type> (tmp * 255.0f);
} else
_in >> c[2];
break;
case COLORALPHA:
if (vertexPropertyMap_[propertyIndex].second == ValueTypeFLOAT32) {
_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);
_bi.set_texcoord(vh, t);
_bi.set_color(vh, Vec4uc(c));
}
// 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;
omlog() << "[PLYReader] : read ascii file\n";
// 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;
OpenMesh::Vec3f v;
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;
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;
case TEXX:
_in >> t[0];
break;
case TEXY:
_in >> t[1];
break;
case COLORRED:
if (vertexPropertyMap_[propertyIndex].second == ValueTypeFLOAT32) {
_in >> tmp;
c[0] = static_cast<OpenMesh::Vec4i::value_type> (tmp * 255.0f);
} else
_in >> c[0];
break;
case COLORGREEN:
if (vertexPropertyMap_[propertyIndex].second == ValueTypeFLOAT32) {
_in >> tmp;
c[1] = static_cast<OpenMesh::Vec4i::value_type> (tmp * 255.0f);
} else
_in >> c[1];
break;
case COLORBLUE:
if (vertexPropertyMap_[propertyIndex].second == ValueTypeFLOAT32) {
_in >> tmp;
c[2] = static_cast<OpenMesh::Vec4i::value_type> (tmp * 255.0f);
} else
_in >> c[2];
break;
case COLORALPHA:
if (vertexPropertyMap_[propertyIndex].second == ValueTypeFLOAT32) {
_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);
_bi.set_texcoord(vh, t);
_bi.set_color(vh, Vec4uc(c));
}
// 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;
}
//-----------------------------------------------------------------------------
bool _PLYReader_::read_binary(std::istream& _in, BaseImporter& _bi, bool /*_swap*/) const {
omlog() << "[PLYReader] : read binary file format\n";
// 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;
OpenMesh::Vec3f v; // Vertex
OpenMesh::Vec2f t; // TexCoords
BaseImporter::VHandles vhandles;
VertexHandle vh;
OpenMesh::Vec4i c; // Color
float tmp;
_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;
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;
case TEXX:
readValue(vertexPropertyMap_[propertyIndex].second, _in, t[0]);
break;
case TEXY:
readValue(vertexPropertyMap_[propertyIndex].second, _in, t[1]);
break;
case COLORRED:
if (vertexPropertyMap_[propertyIndex].second == ValueTypeFLOAT32) {
readValue(vertexPropertyMap_[propertyIndex].second, _in, tmp);
c[0] = static_cast<OpenMesh::Vec4i::value_type> (tmp * 255.0f);
} else
readValue(vertexPropertyMap_[propertyIndex].second, _in, c[0]);
break;
case COLORGREEN:
if (vertexPropertyMap_[propertyIndex].second == ValueTypeFLOAT32) {
readValue(vertexPropertyMap_[propertyIndex].second, _in, tmp);
c[1] = static_cast<OpenMesh::Vec4i::value_type> (tmp * 255.0f);
} else
readValue(vertexPropertyMap_[propertyIndex].second, _in, c[1]);
break;
case COLORBLUE:
if (vertexPropertyMap_[propertyIndex].second == ValueTypeFLOAT32) {
readValue(vertexPropertyMap_[propertyIndex].second, _in, tmp);
c[2] = static_cast<OpenMesh::Vec4i::value_type> (tmp * 255.0f);
} else
readValue(vertexPropertyMap_[propertyIndex].second, _in, c[2]);
break;
case COLORALPHA:
if (vertexPropertyMap_[propertyIndex].second == ValueTypeFLOAT32) {
readValue(vertexPropertyMap_[propertyIndex].second, _in, tmp);
c[3] = static_cast<OpenMesh::Vec4i::value_type> (tmp * 255.0f);
} else
readValue(vertexPropertyMap_[propertyIndex].second, _in, c[3]);
break;
default:
break;
}
}
vh = _bi.add_vertex(v);
_bi.set_texcoord(vh, t);
_bi.set_color(vh, Vec4uc(c));
}
for (i = 0; i < faceCount_; ++i) {
// Read number of vertices for the current face
readValue(faceIndexType_, _in, nV);
if (nV == 3) {
vhandles.resize(3);
readValue(faceEntryType_, _in, j);
readValue(faceEntryType_, _in, k);
readValue(faceEntryType_, _in, l);
vhandles[0] = VertexHandle(j);
vhandles[1] = VertexHandle(k);
vhandles[2] = VertexHandle(l);
} else {
vhandles.clear();
for (j = 0; j < nV; ++j) {
readValue(faceEntryType_, _in, idx);
vhandles.push_back(VertexHandle(idx));
}
}
FaceHandle fh = _bi.add_face(vhandles);
}
return true;
omlog() << "[PLYReader] : read binary file format\n";
// 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;
OpenMesh::Vec3f v; // Vertex
OpenMesh::Vec2f t; // TexCoords
BaseImporter::VHandles vhandles;
VertexHandle vh;
OpenMesh::Vec4i c; // Color
float tmp;
_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;
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;
case TEXX:
readValue(vertexPropertyMap_[propertyIndex].second, _in, t[0]);
break;
case TEXY:
readValue(vertexPropertyMap_[propertyIndex].second, _in, t[1]);
break;
case COLORRED:
if (vertexPropertyMap_[propertyIndex].second == ValueTypeFLOAT32) {
readValue(vertexPropertyMap_[propertyIndex].second, _in, tmp);
c[0] = static_cast<OpenMesh::Vec4i::value_type> (tmp * 255.0f);
} else
readValue(vertexPropertyMap_[propertyIndex].second, _in, c[0]);
break;
case COLORGREEN:
if (vertexPropertyMap_[propertyIndex].second == ValueTypeFLOAT32) {
readValue(vertexPropertyMap_[propertyIndex].second, _in, tmp);
c[1] = static_cast<OpenMesh::Vec4i::value_type> (tmp * 255.0f);
} else
readValue(vertexPropertyMap_[propertyIndex].second, _in, c[1]);
break;
case COLORBLUE:
if (vertexPropertyMap_[propertyIndex].second == ValueTypeFLOAT32) {
readValue(vertexPropertyMap_[propertyIndex].second, _in, tmp);
c[2] = static_cast<OpenMesh::Vec4i::value_type> (tmp * 255.0f);
} else
readValue(vertexPropertyMap_[propertyIndex].second, _in, c[2]);
break;
case COLORALPHA:
if (vertexPropertyMap_[propertyIndex].second == ValueTypeFLOAT32) {
readValue(vertexPropertyMap_[propertyIndex].second, _in, tmp);
c[3] = static_cast<OpenMesh::Vec4i::value_type> (tmp * 255.0f);
} else
readValue(vertexPropertyMap_[propertyIndex].second, _in, c[3]);
break;
default:
break;
}
}
vh = _bi.add_vertex(v);
_bi.set_texcoord(vh, t);
_bi.set_color(vh, Vec4uc(c));
}
for (i = 0; i < faceCount_; ++i) {
// Read number of vertices for the current face
readValue(faceIndexType_, _in, nV);
if (nV == 3) {
vhandles.resize(3);
readValue(faceEntryType_, _in, j);
readValue(faceEntryType_, _in, k);
readValue(faceEntryType_, _in, l);
vhandles[0] = VertexHandle(j);
vhandles[1] = VertexHandle(k);
vhandles[2] = VertexHandle(l);
} else {
vhandles.clear();
for (j = 0; j < nV; ++j) {
readValue(faceEntryType_, _in, idx);
vhandles.push_back(VertexHandle(idx));
}
}
FaceHandle fh = _bi.add_face(vhandles);
}
return true;
}
//-----------------------------------------------------------------------------
......@@ -405,295 +405,295 @@ bool _PLYReader_::read_binary(std::istream& _in, BaseImporter& _bi, bool /*_swap
void _PLYReader_::readValue(ValueType _type, std::istream& _in, float& _value) const {
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;
}
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;
}
}
void _PLYReader_::readValue(ValueType _type, std::istream& _in, unsigned int& _value) const {
int32_t tmp_int32_t;
uint8_t tmp_uchar;
switch (_type) {
case ValueTypeINT:
case ValueTypeINT32:
restore(_in, tmp_int32_t, options_.check(Options::MSB));
_value = tmp_int32_t;
break;
case ValueTypeUCHAR:
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;
}
int32_t tmp_int32_t;
uint8_t tmp_uchar;