Coupure prévue mardi 3 Août au matin pour maintenance du serveur. Nous faisons au mieux pour que celle-ci soit la plus brève possible.

Commit 71ab26ca authored by Kenneth Vanhoey's avatar Kenneth Vanhoey
Browse files

Import/export for SLF in binary works

parent 6d652049
...@@ -473,7 +473,6 @@ bool exportPlySLFgenericBin(typename PFP::MAP& map, const typename PFP::TVEC3& p ...@@ -473,7 +473,6 @@ bool exportPlySLFgenericBin(typename PFP::MAP& map, const typename PFP::TVEC3& p
AutoAttributeHandler<unsigned int> tableVertLab(map, VERTEX); AutoAttributeHandler<unsigned int> tableVertLab(map, VERTEX);
unsigned int nbDarts = map.getNbDarts() ; unsigned int nbDarts = map.getNbDarts() ;
std::vector<unsigned int> vertices; std::vector<unsigned int> vertices;
...@@ -562,15 +561,24 @@ bool exportPlySLFgenericBin(typename PFP::MAP& map, const typename PFP::TVEC3& p ...@@ -562,15 +561,24 @@ bool exportPlySLFgenericBin(typename PFP::MAP& map, const typename PFP::TVEC3& p
unsigned int vi = vertices[i]; unsigned int vi = vertices[i];
// position // position
for(unsigned int coord = 0 ; coord < 3 ; ++coord) for(unsigned int coord = 0 ; coord < 3 ; ++coord)
out.write((char*)(&(position[vi][coord])), sizeof(float)) ; {
const float& floatofdouble = position[vi][coord] ;
out.write((char*)(&floatofdouble), sizeof(float)) ;
}
// frame // frame
for(unsigned int axis = 0 ; axis < 3 ; ++axis) for(unsigned int axis = 0 ; axis < 3 ; ++axis)
for (unsigned int coord = 0 ; coord < 3 ; ++coord) for (unsigned int coord = 0 ; coord < 3 ; ++coord)
out.write((char*)(&(frame[axis][vi][coord])), sizeof(float)) ; {
const float& floatofdouble = frame[axis][vi][coord] ;
out.write((char*)(&floatofdouble), sizeof(float)) ;
}
// coefficients // coefficients
for (unsigned int channel = 0 ; channel < 3 ; ++channel) for (unsigned int channel = 0 ; channel < 3 ; ++channel)
for(unsigned int coefI = 0 ; coefI < nbCoefs ; ++coefI) for(unsigned int coefI = 0 ; coefI < nbCoefs ; ++coefI)
out.write((char*)(&(coefs[coefI][vi][channel])), sizeof(float)) ; {
const float& floatofdouble = coefs[coefI][vi][channel] ;
out.write((char*)(&floatofdouble), sizeof(float)) ;
}
} }
std::vector<unsigned int>::iterator it = faces.begin(); std::vector<unsigned int>::iterator it = faces.begin();
......
...@@ -650,6 +650,7 @@ bool MeshTablesSurface<PFP>::importPly(const std::string& filename, std::vector< ...@@ -650,6 +650,7 @@ bool MeshTablesSurface<PFP>::importPly(const std::string& filename, std::vector<
template <typename PFP> template <typename PFP>
bool MeshTablesSurface<PFP>::importPlySLFgeneric(const std::string& filename, std::vector<std::string>& attrNames) bool MeshTablesSurface<PFP>::importPlySLFgeneric(const std::string& filename, std::vector<std::string>& attrNames)
{ {
std::cout << "Import PlySLFASCII" << std::endl ;
// Open file // Open file
std::ifstream fp(filename.c_str(), std::ios::in) ; std::ifstream fp(filename.c_str(), std::ios::in) ;
if (!fp.good()) if (!fp.good())
...@@ -680,7 +681,7 @@ bool MeshTablesSurface<PFP>::importPlySLFgeneric(const std::string& filename, st ...@@ -680,7 +681,7 @@ bool MeshTablesSurface<PFP>::importPlySLFgeneric(const std::string& filename, st
bool binormal = false ; bool binormal = false ;
bool normal = false ; bool normal = false ;
unsigned int nbProps = 0 ; // # properties unsigned int nbProps = 0 ; // # properties
unsigned int nbCoefsPerPol = 0 ; // # coefficients per polynomial unsigned int nbCoefs = 0 ; // # coefficients per polynomial
do // go to #faces and count #properties do // go to #faces and count #properties
{ {
fp >> tag ; fp >> tag ;
...@@ -696,11 +697,11 @@ bool MeshTablesSurface<PFP>::importPlySLFgeneric(const std::string& filename, st ...@@ -696,11 +697,11 @@ bool MeshTablesSurface<PFP>::importPlySLFgeneric(const std::string& filename, st
else if (tag == std::string("nx") || tag == std::string("ny") || tag == std::string("nz")) else if (tag == std::string("nx") || tag == std::string("ny") || tag == std::string("nz"))
normal = true ; normal = true ;
if (tag.substr(0,1) == std::string("C") && tag.substr(2,1) == std::string("_")) if (tag.substr(0,1) == std::string("C") && tag.substr(2,1) == std::string("_"))
++nbCoefsPerPol ; ++nbCoefs ;
} while (tag != std::string("face")) ; } while (tag != std::string("face")) ;
unsigned int nbRemainders = nbProps ; // # remaining properties unsigned int nbRemainders = nbProps ; // # remaining properties
nbRemainders -= nbCoefsPerPol + 3*(position==true) + 3*(tangent==true) + 3*(binormal==true) + 3*(normal==true) ; nbRemainders -= nbCoefs + 3*(position==true) + 3*(tangent==true) + 3*(binormal==true) + 3*(normal==true) ;
nbCoefsPerPol /= 3 ; nbCoefs /= 3 ;
fp >> m_nbFaces ; // Read #vertices fp >> m_nbFaces ; // Read #vertices
...@@ -723,8 +724,8 @@ bool MeshTablesSurface<PFP>::importPlySLFgeneric(const std::string& filename, st ...@@ -723,8 +724,8 @@ bool MeshTablesSurface<PFP>::importPlySLFgeneric(const std::string& filename, st
attrNames.push_back(frame[1].name()) ; attrNames.push_back(frame[1].name()) ;
attrNames.push_back(frame[2].name()) ; attrNames.push_back(frame[2].name()) ;
AttributeHandler<typename PFP::VEC3> *SLFcoefs = new AttributeHandler<typename PFP::VEC3>[nbCoefsPerPol] ; AttributeHandler<typename PFP::VEC3> *SLFcoefs = new AttributeHandler<typename PFP::VEC3>[nbCoefs] ;
for (unsigned int i = 0 ; i < nbCoefsPerPol ; ++i) for (unsigned int i = 0 ; i < nbCoefs ; ++i)
{ {
std::stringstream name ; std::stringstream name ;
name << "SLFcoefs_" << i ; name << "SLFcoefs_" << i ;
...@@ -760,9 +761,9 @@ bool MeshTablesSurface<PFP>::importPlySLFgeneric(const std::string& filename, st ...@@ -760,9 +761,9 @@ bool MeshTablesSurface<PFP>::importPlySLFgeneric(const std::string& filename, st
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) // coefficients
for (unsigned int l = 0 ; l < nbCoefsPerPol ; ++l) for (unsigned int l = 0 ; l < nbCoefs ; ++l)
SLFcoefs[l][id][k] = properties[12+(nbCoefsPerPol*k+l)] ; SLFcoefs[l][id][k] = properties[12+(nbCoefs*k+l)] ;
unsigned int cur = 12+3*nbCoefsPerPol ; unsigned int cur = 12+3*nbCoefs ;
for (unsigned int k = 0 ; k < nbRemainders ; ++k) // remaining data for (unsigned int k = 0 ; k < nbRemainders ; ++k) // remaining data
remainders[k][id] = properties[cur + k] ; remainders[k][id] = properties[cur + k] ;
} }
...@@ -826,7 +827,7 @@ bool MeshTablesSurface<PFP>::importPlySLFgenericBin(const std::string& filename, ...@@ -826,7 +827,7 @@ bool MeshTablesSurface<PFP>::importPlySLFgenericBin(const std::string& filename,
bool binormal = false ; bool binormal = false ;
bool normal = false ; bool normal = false ;
unsigned int nbProps = 0 ; // # properties unsigned int nbProps = 0 ; // # properties
unsigned int nbCoefsPerPol = 0 ; // # coefficients per polynomial unsigned int nbCoefs = 0 ; // # coefficients per polynomial
do // go to #faces and count #properties do // go to #faces and count #properties
{ {
fp >> tag ; fp >> tag ;
...@@ -842,11 +843,11 @@ bool MeshTablesSurface<PFP>::importPlySLFgenericBin(const std::string& filename, ...@@ -842,11 +843,11 @@ bool MeshTablesSurface<PFP>::importPlySLFgenericBin(const std::string& filename,
else if (tag == std::string("nx") || tag == std::string("ny") || tag == std::string("nz")) else if (tag == std::string("nx") || tag == std::string("ny") || tag == std::string("nz"))
normal = true ; normal = true ;
if (tag.substr(0,1) == std::string("C") && tag.substr(2,1) == std::string("_")) if (tag.substr(0,1) == std::string("C") && tag.substr(2,1) == std::string("_"))
++nbCoefsPerPol ; ++nbCoefs ;
} while (tag != std::string("face")) ; } while (tag != std::string("face")) ;
unsigned int nbRemainders = nbProps ; // # remaining properties unsigned int nbRemainders = nbProps ; // # remaining properties
nbRemainders -= nbCoefsPerPol + 3*(position==true) + 3*(tangent==true) + 3*(binormal==true) + 3*(normal==true) ; nbRemainders -= nbCoefs + 3*(position==true) + 3*(tangent==true) + 3*(binormal==true) + 3*(normal==true) ;
nbCoefsPerPol /= 3 ; nbCoefs /= 3 ;
fp >> m_nbFaces ; // Read #vertices fp >> m_nbFaces ; // Read #vertices
...@@ -876,8 +877,8 @@ bool MeshTablesSurface<PFP>::importPlySLFgenericBin(const std::string& filename, ...@@ -876,8 +877,8 @@ bool MeshTablesSurface<PFP>::importPlySLFgenericBin(const std::string& filename,
attrNames.push_back(frame[1].name()) ; attrNames.push_back(frame[1].name()) ;
attrNames.push_back(frame[2].name()) ; attrNames.push_back(frame[2].name()) ;
AttributeHandler<typename PFP::VEC3> *SLFcoefs = new AttributeHandler<typename PFP::VEC3>[nbCoefsPerPol] ; AttributeHandler<typename PFP::VEC3> *SLFcoefs = new AttributeHandler<typename PFP::VEC3>[nbCoefs] ;
for (unsigned int i = 0 ; i < nbCoefsPerPol ; ++i) for (unsigned int i = 0 ; i < nbCoefs ; ++i)
{ {
std::stringstream name ; std::stringstream name ;
name << "SLFcoefs_" << i ; name << "SLFcoefs_" << i ;
...@@ -905,17 +906,17 @@ bool MeshTablesSurface<PFP>::importPlySLFgenericBin(const std::string& filename, ...@@ -905,17 +906,17 @@ bool MeshTablesSurface<PFP>::importPlySLFgenericBin(const std::string& filename,
unsigned int id = container.insertLine() ; unsigned int id = container.insertLine() ;
verticesID.push_back(id) ; verticesID.push_back(id) ;
for (unsigned int j = 0 ; j < nbProps ; ++j) // get all properties // for (unsigned int j = 0 ; j < nbProps ; ++j) // get all properties
fp.read((char*)&(properties[j]),sizeof(float)) ; fp.read((char*)properties,nbProps * sizeof(float)) ;
positions[id] = VEC3(properties[0],properties[1],properties[2]) ; // position positions[id] = VEC3(properties[0],properties[1],properties[2]) ; // position
for (unsigned int k = 0 ; k < 3 ; ++k) // frame 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) // coefficients
for (unsigned int l = 0 ; l < nbCoefsPerPol ; ++l) for (unsigned int l = 0 ; l < nbCoefs ; ++l)
SLFcoefs[l][id][k] = properties[12+(nbCoefsPerPol*k+l)] ; SLFcoefs[l][id][k] = properties[12+(nbCoefs*k+l)] ;
unsigned int cur = 12+3*nbCoefsPerPol ; unsigned int cur = 12+3*nbCoefs ;
for (unsigned int k = 0 ; k < nbRemainders ; ++k) // remaining data for (unsigned int k = 0 ; k < nbRemainders ; ++k) // remaining data
remainders[k][id] = properties[cur + k] ; remainders[k][id] = properties[cur + k] ;
} }
......
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