Commit 132c1266 authored by Kenneth Vanhoey's avatar Kenneth Vanhoey

import Ply with color encoded as uint8

parent c94accd2
......@@ -591,6 +591,14 @@ bool MeshTablesSurface<PFP>::importPly(const std::string& filename, std::vector<
return false;
}
AttributeHandler<typename PFP::VEC3> colors = m_map.template getAttribute<typename PFP::VEC3>(VERTEX, "color") ;
if (pid.hasColors())
{
if(!colors.isValid())
colors = m_map.template addAttribute<typename PFP::VEC3>(VERTEX, "color") ;
attrNames.push_back(colors.name()) ;
}
// lecture des nombres de sommets/aretes/faces
m_nbVertices = pid.nbVertices();
m_nbFaces = pid.nbFaces();
......@@ -606,6 +614,16 @@ bool MeshTablesSurface<PFP>::importPly(const std::string& filename, std::vector<
unsigned int id = container.insertLine();
positions[id] = pos;
if (pid.hasColors())
{
Geom::Vector<3, unsigned char> col ;
pid.vertexColorUint8(i, col) ;
colors[id][0] = col[0] ;
colors[id][1] = col[1] ;
colors[id][2] = col[2] ;
colors[id] /= 255.0 ;
}
verticesID.push_back(id);
}
......@@ -650,7 +668,6 @@ bool MeshTablesSurface<PFP>::importPly(const std::string& filename, std::vector<
template <typename PFP>
bool MeshTablesSurface<PFP>::importPlySLFgeneric(const std::string& filename, std::vector<std::string>& attrNames)
{
std::cout << "Import PlySLFASCII" << std::endl ;
// Open file
std::ifstream fp(filename.c_str(), std::ios::in) ;
if (!fp.good())
......@@ -912,13 +929,13 @@ bool MeshTablesSurface<PFP>::importPlySLFgenericBin(const std::string& filename,
positions[id] = VEC3(properties[0],properties[1],properties[2]) ; // position
for (unsigned int k = 0 ; k < 3 ; ++k) // frame
for (unsigned int l = 0 ; l < 3 ; ++l)
frame[k][id][l] = properties[3+(3*k+l)] ;
frame[k][id][l] = (typename PFP::REAL)(properties[3+(3*k+l)]) ;
for (unsigned int k = 0 ; k < 3 ; ++k) // coefficients
for (unsigned int l = 0 ; l < nbCoefs ; ++l)
SLFcoefs[l][id][k] = properties[12+(nbCoefs*k+l)] ;
SLFcoefs[l][id][k] = (typename PFP::REAL)(properties[12+(nbCoefs*k+l)]) ;
unsigned int cur = 12+3*nbCoefs ;
for (unsigned int k = 0 ; k < nbRemainders ; ++k) // remaining data
remainders[k][id] = properties[cur + k] ;
remainders[k][id] = (typename PFP::REAL)(properties[cur + k]) ;
}
m_nbVertices = verticesID.size() ;
delete[] properties ;
......
......@@ -47,7 +47,10 @@ public:
void vertexNormal(int i, VEC& N) { N[0] = vlist[i]->nx; N[1] = vlist[i]->ny; N[2] = vlist[i]->nz;}
template <typename VEC>
void vertexColor(int i, VEC& C) { C[0] = vlist[i]->r; C[1] = vlist[i]->g; C[2] = vlist[i]->b;}
void vertexColorUint8(int i, VEC& C) { C[0] = vlist[i]->red; C[1] = vlist[i]->green; C[2] = vlist[i]->blue;}
template <typename VEC>
void vertexColorFloat32(int i, VEC& C) { C[0] = vlist[i]->r; C[1] = vlist[i]->g; C[2] = vlist[i]->b;}
int nbVertices() { return nverts;}
......@@ -62,7 +65,9 @@ public:
/**
* each vertex has a color vector
*/
bool hasColors() { return per_vertex_color!=0;}
bool hasColors() { return hasColorsUint8() || hasColorsFloat32() ;}
bool hasColorsUint8() { return per_vertex_color_uint8 != 0 ;}
bool hasColorsFloat32() { return per_vertex_color_float32 != 0 ;}
/**
* get the number of edges of a face
......@@ -88,6 +93,7 @@ protected:
typedef struct Vertex {
float x,y,z;
float r,g,b;
unsigned char red,green,blue;
float nx,ny,nz;
void *other_props; /* other properties */
} Vertex;
......@@ -113,7 +119,7 @@ protected:
PlyOtherProp *vert_other,*face_other;
int per_vertex_color;
int per_vertex_color_float32, per_vertex_color_uint8 ;
int has_normals;
};
......
......@@ -37,6 +37,9 @@ PlyProperty PlyImportData::vert_props[] = { /* list of property information for
{(char*) "x", PLY_Float32, PLY_Float32, offsetof(Vertex,x), 0, 0, 0, 0},
{(char*) "y", PLY_Float32, PLY_Float32, offsetof(Vertex,y), 0, 0, 0, 0},
{(char*) "z", PLY_Float32, PLY_Float32, offsetof(Vertex,z), 0, 0, 0, 0},
{(char*) "red", PLY_Uint8, PLY_Uint8, offsetof(Vertex,red), 0, 0, 0, 0},
{(char*) "green", PLY_Uint8, PLY_Uint8, offsetof(Vertex,green), 0, 0, 0, 0},
{(char*) "blue", PLY_Uint8, PLY_Uint8, offsetof(Vertex,blue), 0, 0, 0, 0},
{(char*) "r", PLY_Float32, PLY_Float32, offsetof(Vertex,r), 0, 0, 0, 0},
{(char*) "g", PLY_Float32, PLY_Float32, offsetof(Vertex,g), 0, 0, 0, 0},
{(char*) "b", PLY_Float32, PLY_Float32, offsetof(Vertex,b), 0, 0, 0, 0},
......@@ -57,7 +60,8 @@ PlyImportData::PlyImportData():
flist(NULL),
vert_other(NULL),
face_other(NULL),
per_vertex_color(0),
per_vertex_color_uint8(0),
per_vertex_color_float32(0),
has_normals(0)
{
}
......@@ -126,28 +130,40 @@ bool PlyImportData::read_file(const std::string& filename)
{
PlyProperty *prop;
prop = in_ply->elems[i]->props[j];
if (equal_strings ((char*) "r", prop->name)) {
if (equal_strings ((char*) "red", prop->name)) {
setup_property_ply (in_ply, &vert_props[3]);
per_vertex_color = 1;
per_vertex_color_uint8 = 1;
}
if (equal_strings ((char*) "g", prop->name)) {
if (equal_strings ((char*) "green", prop->name)) {
setup_property_ply (in_ply, &vert_props[4]);
per_vertex_color = 1;
per_vertex_color_uint8 = 1;
}
if (equal_strings ((char*) "b", prop->name)) {
if (equal_strings ((char*) "blue", prop->name)) {
setup_property_ply (in_ply, &vert_props[5]);
per_vertex_color = 1;
per_vertex_color_uint8 = 1;
}
if (equal_strings ((char*) "nx", prop->name)) {
if (equal_strings ((char*) "r", prop->name)) {
setup_property_ply (in_ply, &vert_props[6]);
per_vertex_color_float32 = 1;
}
if (equal_strings ((char*) "g", prop->name)) {
setup_property_ply (in_ply, &vert_props[7]);
per_vertex_color_float32 = 1;
}
if (equal_strings ((char*) "b", prop->name)) {
setup_property_ply (in_ply, &vert_props[8]);
per_vertex_color_float32 = 1;
}
if (equal_strings ((char*) "nx", prop->name)) {
setup_property_ply (in_ply, &vert_props[9]);
has_normals = 1;
}
if (equal_strings ((char*) "ny", prop->name)) {
setup_property_ply (in_ply, &vert_props[7]);
setup_property_ply (in_ply, &vert_props[10]);
has_normals = 1;
}
if (equal_strings ((char*) "nz", prop->name)) {
setup_property_ply (in_ply, &vert_props[8]);
setup_property_ply (in_ply, &vert_props[11]);
has_normals = 1;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment