Brève interruption de service ce midi pour augmentation de la mémoire 🤞

Commit 0b8f3dc2 authored by Kenneth Vanhoey's avatar Kenneth Vanhoey

update of importPlyPTMgeneric : support any format having pos+frame+functions+residual

parent 0693c89c
......@@ -548,15 +548,17 @@ bool MeshTablesSurface<PFP>::importPly(const std::string& filename, std::vector<
* @param filename the file to import;
* @param attrNames reference that will be filled with the attribute names
* the number of attrNames returned depends on the degree of the polynomials :
* - 1 attrName for geometric position (VEC3)
* - 3 attrNames for local frame (3xVEC3) : Tangent, Bitangent and Normal vector
* - 1 attrName for geometric position (VEC3) : name = "position" ;
* - 3 attrNames for local frame (3xVEC3) : names are "Frame_T" (Tangent), "Frame_B" (Binormal) and "Frame_N" (Normal) ;
* - N attrNames for the function coefficients (NxVEC3) : N RGB coefficients being successively the constants, the linears (v then u), the quadratics, etc. : : a0 + a1*v + a2*u + a3*u*v + a4*v^2 + a5*u^2.
* Their names are : "colorPTM_a<i>" (where <i> is a number from 0 to N-1).
* N = 1 for constant polynomial,
* N = 3 for linear polynomial,
* N = 6 for quadratic polynomial,
* N = 10 for cubic degree polynomial,
* N = 15 for 4th degree polynomial,
* ...
* - K remaining attributes named "remainderNo<k>" where k is an integer from 0 to K-1.
* Hint : N = attrNames.size() - 4 ;
* @return bool : success.
*/
......@@ -588,13 +590,33 @@ bool MeshTablesSurface<PFP>::importPlyPTMgeneric(const std::string& filename, st
unsigned int nbVertices ;
fp >> nbVertices ; // Read #vertices
unsigned int nbProps = 0 ;
bool position = false ;
bool tangent = false ;
bool binormal = false ;
bool normal = false ;
unsigned int nbProps = 0 ; // # properties
unsigned int nbCoefsPerPol = 0 ; // # coefficients per polynomial
do // go to #faces and count #properties
{
fp >> tag ;
if (tag == std::string("property"))
++nbProps ;
if (tag == std::string("x") || tag == std::string("y") || tag == std::string("z"))
position = true ;
else if (tag == std::string("tx") || tag == std::string("ty") || tag == std::string("tz"))
tangent = true ;
else if (tag == std::string("bx") || tag == std::string("by") || tag == std::string("bz"))
binormal = true ;
else if (tag == std::string("nx") || tag == std::string("ny") || tag == std::string("nz"))
normal = true ;
else if (tag.substr(2,2) == std::string("_a"))
++nbCoefsPerPol ;
} while (tag != std::string("face")) ;
unsigned int nbRemainders = nbProps ; // # remaining properties
nbRemainders -= nbCoefsPerPol + 3*(position==true) + 3*(tangent==true) + 3*(binormal==true) + 3*(normal==true) ;
nbCoefsPerPol /= 3 ;
fp >> m_nbFaces ; // Read #vertices
do // go to end of header
......@@ -602,8 +624,6 @@ bool MeshTablesSurface<PFP>::importPlyPTMgeneric(const std::string& filename, st
fp >> tag ;
} while (tag != std::string("end_header")) ;
unsigned int nbCoefsPerPol = (nbProps - 12) / 3 ; // get #coefficients per polynomial
// Define containers
AttributeHandler<typename PFP::VEC3> positions = m_map.template getAttribute<typename PFP::VEC3>(VERTEX, "position") ;
if (!positions.isValid())
......@@ -627,6 +647,15 @@ bool MeshTablesSurface<PFP>::importPlyPTMgeneric(const std::string& filename, st
attrNames.push_back(colorPTM[i].name()) ;
}
AttributeHandler<typename PFP::REAL> *remainders = new AttributeHandler<typename PFP::REAL>[nbRemainders] ;
for (unsigned int i = 0 ; i < nbRemainders ; ++i)
{
std::stringstream name ;
name << "remainderNo" << i ;
remainders[i] = m_map.template addAttribute<typename PFP::REAL>(VERTEX, name.str()) ;
attrNames.push_back(remainders[i].name()) ;
}
// Read vertices
std::vector<unsigned int> verticesID ;
verticesID.reserve(nbVertices) ;
......@@ -648,6 +677,9 @@ bool MeshTablesSurface<PFP>::importPlyPTMgeneric(const std::string& filename, st
for (unsigned int k = 0 ; k < 3 ; ++k) // coefficients
for (unsigned int l = 0 ; l < nbCoefsPerPol ; ++l)
colorPTM[l][id][k] = properties[12+(nbCoefsPerPol*k+l)] ;
unsigned int cur = 12+3*nbCoefsPerPol ;
for (unsigned int k = 0 ; k < nbRemainders ; ++k) // remaining data
remainders[k][id] = properties[cur + k] ;
}
m_nbVertices = verticesID.size() ;
delete[] properties ;
......
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