Commit 732e6718 authored by Kenneth Vanhoey's avatar Kenneth Vanhoey
Browse files

added generic version of importPLYptm (good for bivariable polynomials of any degree)

parent be31a220
...@@ -110,6 +110,7 @@ public: ...@@ -110,6 +110,7 @@ public:
bool importPly(const std::string& filename, std::vector<std::string>& attrNames); bool importPly(const std::string& filename, std::vector<std::string>& attrNames);
bool importPlyPTM(const std::string& filename, std::vector<std::string>& attrNames); bool importPlyPTM(const std::string& filename, std::vector<std::string>& attrNames);
bool importPlyPTMgeneric(const std::string& filename, std::vector<std::string>& attrNames);
bool importCTM(const std::string& filename, std::vector<std::string>& attrNames); bool importCTM(const std::string& filename, std::vector<std::string>& attrNames);
......
...@@ -99,7 +99,7 @@ bool MeshTablesSurface<PFP>::importMesh(const std::string& filename, std::vector ...@@ -99,7 +99,7 @@ bool MeshTablesSurface<PFP>::importMesh(const std::string& filename, std::vector
break; break;
case ImportSurfacique::PLYPTM: case ImportSurfacique::PLYPTM:
CGoGNout << "TYPE: PLYPTM" << CGoGNendl; CGoGNout << "TYPE: PLYPTM" << CGoGNendl;
return importPlyPTM(filename, attrNames); return importPlyPTMgeneric(filename, attrNames);
break; break;
case ImportSurfacique::OBJ: case ImportSurfacique::OBJ:
CGoGNout << "TYPE: OBJ" << CGoGNendl; CGoGNout << "TYPE: OBJ" << CGoGNendl;
...@@ -513,7 +513,7 @@ bool MeshTablesSurface<PFP>::importPly(const std::string& filename, std::vector< ...@@ -513,7 +513,7 @@ bool MeshTablesSurface<PFP>::importPly(const std::string& filename, std::vector<
m_nbEdges.reserve(m_nbFaces); m_nbEdges.reserve(m_nbFaces);
m_emb.reserve(m_nbVertices*8); m_emb.reserve(m_nbVertices*8);
for (unsigned int i = 0; i < m_nbFaces; ++i) for (unsigned int i = 0 ; i < m_nbFaces ; ++i)
{ {
unsigned int n = pid.getFaceValence(i); unsigned int n = pid.getFaceValence(i);
m_nbEdges.push_back(n); m_nbEdges.push_back(n);
...@@ -527,153 +527,137 @@ bool MeshTablesSurface<PFP>::importPly(const std::string& filename, std::vector< ...@@ -527,153 +527,137 @@ bool MeshTablesSurface<PFP>::importPly(const std::string& filename, std::vector<
return true; return true;
} }
/**
* Import plyPTM (K Vanhoey generic format).
* It can handle polynomials of higher degrees and returns the appropriate attrNames
* @param filename : the file to import;
* @param attrNames : reference that will be filled with the attribute names (depends on degree : 6,10,15 or more names);
* @return bool : success.
*/
template <typename PFP> template <typename PFP>
bool MeshTablesSurface<PFP>::importPlyPTM(const std::string& filename, std::vector<std::string>& attrNames) bool MeshTablesSurface<PFP>::importPlyPTMgeneric(const std::string& filename, std::vector<std::string>& attrNames)
{ {
AttributeHandler<typename PFP::VEC3> positions = m_map.template addAttribute<typename PFP::VEC3>(VERTEX, "position") ; // Open file
attrNames.push_back(positions.name()) ; std::ifstream fp(filename.c_str(), std::ios::in) ;
AttributeHandler<typename PFP::VEC3> frame[3] ;
frame[0] = m_map.template addAttribute<typename PFP::VEC3>(VERTEX, "frame_T") ; // Tangent
frame[1] = m_map.template addAttribute<typename PFP::VEC3>(VERTEX, "frame_B") ; // Bitangent
frame[2] = m_map.template addAttribute<typename PFP::VEC3>(VERTEX, "frame_N") ; // Normal
for (unsigned int i = 0 ; i < 3 ; ++i)
attrNames.push_back(frame[i].name()) ;
AttributeHandler<typename PFP::VEC3> colorPTM[15] ;
colorPTM[0] = m_map.template addAttribute<typename PFP::VEC3>(VERTEX, "colorPTM_a0") ;
colorPTM[1] = m_map.template addAttribute<typename PFP::VEC3>(VERTEX, "colorPTM_a1") ;
colorPTM[2] = m_map.template addAttribute<typename PFP::VEC3>(VERTEX, "colorPTM_a2") ;
colorPTM[3] = m_map.template addAttribute<typename PFP::VEC3>(VERTEX, "colorPTM_a3") ;
colorPTM[4] = m_map.template addAttribute<typename PFP::VEC3>(VERTEX, "colorPTM_a4") ;
colorPTM[5] = m_map.template addAttribute<typename PFP::VEC3>(VERTEX, "colorPTM_a5") ;
colorPTM[6] = m_map.template addAttribute<typename PFP::VEC3>(VERTEX, "colorPTM_a6") ;
colorPTM[7] = m_map.template addAttribute<typename PFP::VEC3>(VERTEX, "colorPTM_a7") ;
colorPTM[8] = m_map.template addAttribute<typename PFP::VEC3>(VERTEX, "colorPTM_a8") ;
colorPTM[9] = m_map.template addAttribute<typename PFP::VEC3>(VERTEX, "colorPTM_a9") ;
colorPTM[10] = m_map.template addAttribute<typename PFP::VEC3>(VERTEX, "colorPTM_a10") ;
colorPTM[11] = m_map.template addAttribute<typename PFP::VEC3>(VERTEX, "colorPTM_a11") ;
colorPTM[12] = m_map.template addAttribute<typename PFP::VEC3>(VERTEX, "colorPTM_a12") ;
colorPTM[13] = m_map.template addAttribute<typename PFP::VEC3>(VERTEX, "colorPTM_a13") ;
colorPTM[14] = m_map.template addAttribute<typename PFP::VEC3>(VERTEX, "colorPTM_a14") ;
for (unsigned int i = 0 ; i < 15 ; ++i)
attrNames.push_back(colorPTM[i].name()) ;
AttributeContainer& container = m_map.getAttributeContainer(VERTEX) ;
std::ifstream fp(filename.c_str(), std::ios::binary);
if (!fp.good()) if (!fp.good())
{ {
std::cerr << "Unable to open file " << filename<< std::endl; CGoGNerr << "Unable to open file " << filename << CGoGNendl ;
return false; return false ;
} }
std::string ligne; // Read quantities : #vertices, #faces, #properties, degree of polynomials
std::string tag; std::string tag ;
fp >> tag; fp >> tag;
if (tag != std::string("ply")) if (tag != std::string("ply")) // verify file type
{ {
std::cerr <<filename<< " is not a ply file !" << std::endl; CGoGNerr << filename << " is not a ply file !" << CGoGNout ;
return false; return false ;
} }
do // go to #vertices
// va au nombre de sommets
do
{ {
fp >> tag; fp >> tag ;
} while (tag != std::string("vertex")); } while (tag != std::string("vertex")) ;
unsigned int nbVertices ;
unsigned int nbp; fp >> nbVertices ; // Read #vertices
fp >> nbp;
// read points
std::vector<unsigned int> verticesID;
verticesID.reserve(nbp);
AttributeHandler<typename PFP::REAL> errors[3] ; unsigned int nbProps = 0 ;
// va au nombre de faces en comptant le nombre de "property" do // go to #faces and count #properties
unsigned int nb_props = 0;
do
{ {
fp >> tag; fp >> tag ;
if (tag == std::string("property")) if (tag == std::string("property"))
nb_props++; ++nbProps ;
if (tag == std::string("errL2")) { } while (tag != std::string("face")) ;
errors[0] = m_map.template addAttribute<typename PFP::REAL>(VERTEX, "errL2") ; fp >> m_nbFaces ; // Read #vertices
errors[1] = m_map.template addAttribute<typename PFP::REAL>(VERTEX, "errLmax") ;
errors[2] = m_map.template addAttribute<typename PFP::REAL>(VERTEX, "stdDev") ;
for (unsigned int i = 0 ; i < 3 ; ++i)
attrNames.push_back(errors[i].name()) ;
}
do // go to end of header
{
fp >> tag ;
} while (tag != std::string("end_header")) ;
} while (tag != std::string("face")); unsigned int nbCoefsPerPol = (nbProps - 12) / 3 ; // get #coefficients per polynomial
fp >> m_nbFaces; // Define containers
m_nbEdges.reserve(m_nbFaces); AttributeHandler<typename PFP::VEC3> positions = m_map.template getAttribute<typename PFP::VEC3>(VERTEX, "position") ;
m_emb.reserve(3*m_nbFaces); if (!positions.isValid())
positions = m_map.template addAttribute<typename PFP::VEC3>(VERTEX, "position") ;
attrNames.push_back(positions.name()) ;
// lecture des sommets AttributeHandler<typename PFP::VEC3> *frame = new AttributeHandler<typename PFP::VEC3>[3] ;
frame[0] = m_map.template addAttribute<typename PFP::VEC3>(VERTEX, "frame_T") ; // Tangent
frame[1] = m_map.template addAttribute<typename PFP::VEC3>(VERTEX, "frame_B") ; // Bitangent
frame[2] = m_map.template addAttribute<typename PFP::VEC3>(VERTEX, "frame_N") ; // Normal
attrNames.push_back(frame[0].name()) ;
attrNames.push_back(frame[1].name()) ;
attrNames.push_back(frame[2].name()) ;
// saute à la fin du header AttributeHandler<typename PFP::VEC3> *colorPTM = new AttributeHandler<typename PFP::VEC3>[nbCoefsPerPol] ;
do for (unsigned int i = 0 ; i < nbCoefsPerPol ; ++i)
{ {
fp >> tag; std::stringstream name ;
} while (tag != std::string("end_header")); name << "colorPTM_a" << i ;
colorPTM[i] = m_map.template addAttribute<typename PFP::VEC3>(VERTEX, name.str()) ;
attrNames.push_back(colorPTM[i].name()) ;
}
float* properties = new float[nb_props]; // Read vertices
std::vector<unsigned int> verticesID ;
verticesID.reserve(nbVertices) ;
for (unsigned int i = 0; i < nbp; ++i) float* properties = new float[nbProps] ;
AttributeContainer& container = m_map.getAttributeContainer(VERTEX) ;
for (unsigned int i = 0 ; i < nbVertices ; ++i) // Read and store properties for current vertex
{ {
unsigned int id = container.insertLine(); unsigned int id = container.insertLine() ;
verticesID.push_back(id); verticesID.push_back(id) ;
for (unsigned int j = 0; j < nb_props; ++j) for (unsigned int j = 0 ; j < nbProps ; ++j) // get all properties
{ fp >> properties[j] ;
fp >> properties[j];
}
positions[id] = VEC3(properties[0],properties[1],properties[2]);
for (unsigned int k = 0 ; k < 3 ; ++k) 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) for (unsigned int l = 0 ; l < 3 ; ++l)
frame[k][id][l] = properties[3+(3*k+l)] ; frame[k][id][l] = properties[3+(3*k+l)] ;
for (unsigned int k = 0 ; k < 3 ; ++k) // coefficients
for (unsigned int k = 0 ; k < 3 ; ++k) for (unsigned int l = 0 ; l < nbCoefsPerPol ; ++l)
for (unsigned int l = 0 ; l < 15 ; ++l) colorPTM[l][id][k] = properties[12+(nbCoefsPerPol*k+l)] ;
colorPTM[l][id][k] = properties[12+(15*k+l)];
if (errors[0].isValid())
for (unsigned int k = 0 ; k < 3 ; ++k)
errors[k][id] = properties[57 + k] ;
} }
m_nbVertices = verticesID.size() ;
delete[] properties ;
m_nbVertices = verticesID.size(); // Read faces index
delete[] properties; m_nbEdges.reserve(m_nbFaces) ;
m_emb.reserve(3*m_nbFaces) ;
// read indices of faces for (unsigned int i = 0 ; i < m_nbFaces ; ++i)
for (unsigned int i = 0; i < m_nbFaces; i++)
{ {
// read the indices vertices of face // read the indices of vertices for current face
int nbe; int nbEdgesForFace ;
fp >> nbe; fp >> nbEdgesForFace ;
m_nbEdges.push_back(nbe); m_nbEdges.push_back(nbEdgesForFace);
int pt; int vertexID ;
for (int j=0; j<nbe; ++j) for (int j=0 ; j < nbEdgesForFace ; ++j)
{ {
fp >> pt; fp >> vertexID ;
m_emb.push_back(verticesID[pt]); m_emb.push_back(verticesID[vertexID]);
} }
} }
fp.close(); // Close file
return true; fp.close() ;
return true ;
} }
/*template <typename PFP> /**
* Import plyPTM (F Larue format).
* It handles only 2nd degree polynomials
* @param filename : the file to import;
* @param attrNames : reference that will be filled with the attribute names (depends on degree);
* @return bool : success.
*/
template <typename PFP>
bool MeshTablesSurface<PFP>::importPlyPTM(const std::string& filename, std::vector<std::string>& attrNames) bool MeshTablesSurface<PFP>::importPlyPTM(const std::string& filename, std::vector<std::string>& attrNames)
{ {
AttributeHandler<typename PFP::VEC3> positions = m_map.template getAttribute<typename PFP::VEC3>(VERTEX, "position") ; AttributeHandler<typename PFP::VEC3> positions = m_map.template getAttribute<typename PFP::VEC3>(VERTEX, "position") ;
...@@ -797,7 +781,7 @@ bool MeshTablesSurface<PFP>::importPlyPTM(const std::string& filename, std::vect ...@@ -797,7 +781,7 @@ bool MeshTablesSurface<PFP>::importPlyPTM(const std::string& filename, std::vect
fp.close(); fp.close();
return true; return true;
}*/ }
template <typename PFP> template <typename PFP>
bool MeshTablesSurface<PFP>::importCTM(const std::string& filename, std::vector<std::string>& attrNames) bool MeshTablesSurface<PFP>::importCTM(const std::string& filename, std::vector<std::string>& attrNames)
......
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