Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 11 additions & 22 deletions include/core-mesh/meshIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,25 +115,22 @@ void MeshIO<FloatType>::loadFromPLY( const std::string& filename, MeshData<Float

delete [] data;

size = 1+3*4; //typically 1 uchar for numVertices per triangle, 3 * int for indices
// size of the #vertices/face field, uchar=1, int=4
// need to support int field, for eg. PLY files coming from PoissonRecon's SurfaceTrimmer.exe
unsigned int verticesPerFaceFieldSize = header.m_properties["verticesPerFace"][0].byteSize;
//typically 1 uchar for numVertices per triangle, 3 * int for indices
size = verticesPerFaceFieldSize + 3*4;
data = new char[size*header.m_numFaces];
file.read(data, size*header.m_numFaces);
for (unsigned int i = 0; i < header.m_numFaces; i++) {
mesh.m_FaceIndicesVertices[i][0] = ((int*)&data[i*size+1])[0];
mesh.m_FaceIndicesVertices[i][1] = ((int*)&data[i*size+1])[1];
mesh.m_FaceIndicesVertices[i][2] = ((int*)&data[i*size+1])[2];

//mesh.m_FaceIndicesVertices[i].push_back(((int*)&data[i*size+1])[0]);
//mesh.m_FaceIndicesVertices[i].push_back(((int*)&data[i*size+1])[1]);
//mesh.m_FaceIndicesVertices[i].push_back(((int*)&data[i*size+1])[2]);
for (unsigned int i = 0; i < header.m_numFaces; i++) {
// go to the line containing i'th face, then skip the first field (#vertices/face)
unsigned int offset = i * size + verticesPerFaceFieldSize;
mesh.m_FaceIndicesVertices[i][0] = ((int*)&data[offset])[0];
mesh.m_FaceIndicesVertices[i][1] = ((int*)&data[offset])[1];
mesh.m_FaceIndicesVertices[i][2] = ((int*)&data[offset])[2];
}

//if (mesh.m_Colors.size() == 0) {
// mesh.m_Colors.resize(header.m_NumVertices);
// for (size_t i = 0; i < mesh.m_Colors.size(); i++) {
// mesh.m_Colors[i] = vec3f(0.5f, 0.5f, 0.5f);
// }
//}
delete [] data;

}
Expand Down Expand Up @@ -164,14 +161,6 @@ void MeshIO<FloatType>::loadFromPLY( const std::string& filename, MeshData<Float
}
mesh.m_FaceIndicesVertices.push_back(face);
}

//if (mesh.m_Colors.size() == 0) {
// mesh.m_Colors.resize(header.m_NumVertices);
// for (size_t i = 0; i < mesh.m_Colors.size(); i++) {
// mesh.m_Colors[i] = vec3f(0.5f, 0.5f, 0.5f);
// }
//}

}
}

Expand Down
40 changes: 33 additions & 7 deletions include/core-mesh/plyHeader.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,23 @@ namespace ml {
}
}

static unsigned int getByteSizeFromNameType(const std::string& nameType) {
/*
nameType: double/float/int/uint/char/uchar/short/ushort
return: number of bytes occupied by this type
*/
unsigned int size;

if (nameType == "double") size = 8;
else if (nameType == "float" || nameType == "int" || nameType == "uint") size = 4;
else if (nameType == "ushort" || nameType == "short") size = 2;
else if (nameType == "uchar" || nameType == "char") size = 1;
else {
throw MLIB_EXCEPTION("unkown data type");
}
return size;
}

static void PlyHeaderLine(const std::string& line, PlyHeader& header, std::string& activeElement) {

std::stringstream ss(line);
Expand Down Expand Up @@ -80,15 +97,24 @@ namespace ml {
if (p.name == "red") header.m_bHasColors = true;
}

if (p.nameType == "double") p.byteSize = 8;
else if (p.nameType == "float" || p.nameType == "int" || p.nameType == "uint") p.byteSize = 4;
else if (p.nameType == "ushort" || p.nameType == "short") p.byteSize = 2;
else if (p.nameType == "uchar" || p.nameType == "char") p.byteSize = 1;
else {
throw MLIB_EXCEPTION("unkown data type");
}
p.byteSize = getByteSizeFromNameType(p.nameType);
header.m_properties[activeElement].push_back(p);
}
// read the line about face indices
//eg: property list uchar int vertex_indices
//eg: property list int int vertex_indices
else if (util::endsWith(line, "vertex_indices") || util::endsWith(line, "vertex_index")) {
PlyHeader::PlyPropertyHeader p;
std::string ignore;
// "list"
ss >> ignore;
// uchar/int
ss >> p.nameType;
// create our own name for this
p.name = "verticesPerFace";
p.byteSize = getByteSizeFromNameType(p.nameType);
header.m_properties[p.name].push_back(p);
}
else {
//property belonging to unknown element
}
Expand Down