Commit c040b413 authored by CGoGN GIT Supervisor's avatar CGoGN GIT Supervisor
Browse files

Merge branch 'master' of /home/vanhoey/CGoGN

* 'master' of /home/vanhoey/CGoGN:
  corrections sur gestion des boundingbox
  decimation countdown correction
  added some comments to importPlyPTMgeneric
  separation in two version of importPlyPTM : one with fixed degree polynomials (F Larue) and one for any degree polynomials (K Vanhoey)
  added generic version of importPLYptm (good for bivariable polynomials of any degree)
parents 04d09a3b 98f4c489
......@@ -149,7 +149,7 @@ void decimate(
while(!finished)
{
CGoGNout << "Countdown : " ;
CGoGNout << std::setprecision(8) << (nbVertices - nbWantedVertices) << "\r" << /* flush */ CGoGNendl ;
CGoGNout << std::setprecision(8) << (nbVertices - nbWantedVertices) << "\r" /* flush */ ;
if(!selector->nextEdge(d)) {
CGoGNout << CGoGNendl << "out" << CGoGNendl ;
......
......@@ -26,6 +26,7 @@
#define __EDGESELECTOR_H__
#include "Algo/Decimation/selector.h"
#include "Algo/Geometry/boundingbox.h"
#include "Container/fakeAttribute.h"
#include "Utils/qem.h"
......
......@@ -41,7 +41,7 @@ namespace Geometry
template <typename PFP>
Geom::BoundingBox<typename PFP::VEC3> computeBoundingBox(typename PFP::MAP& map, const typename PFP::TVEC3& position, const FunctorSelect& select = SelectorTrue())
{
Geom::BoundingBox<typename PFP::VEC3> bb(position[map.begin()]) ;
Geom::BoundingBox<typename PFP::VEC3> bb ;
CellMarker vmarker(map, VERTEX);
for(Dart d = map.begin(); d != map.end(); map.next(d))
......
......@@ -50,7 +50,7 @@ namespace Import
namespace ImportSurfacique
{
enum ImportType { UNKNOWNSURFACE, TRIAN, TRIANBGZ, PLY, PLYPTM, OFF, OBJ, CTM, VRML };
enum ImportType { UNKNOWNSURFACE, TRIAN, TRIANBGZ, PLY, PLYPTM, PLYPTMgeneric, OFF, OBJ, CTM, VRML };
}
namespace ImportVolumique
......@@ -110,6 +110,7 @@ public:
bool importPly(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);
......
......@@ -101,6 +101,10 @@ bool MeshTablesSurface<PFP>::importMesh(const std::string& filename, std::vector
CGoGNout << "TYPE: PLYPTM" << CGoGNendl;
return importPlyPTM(filename, attrNames);
break;
case ImportSurfacique::PLYPTMgeneric:
CGoGNout << "TYPE: PLYPTMgeneric" << CGoGNendl;
return importPlyPTMgeneric(filename, attrNames);
break;
case ImportSurfacique::OBJ:
CGoGNout << "TYPE: OBJ" << CGoGNendl;
return importObj(filename, attrNames);
......@@ -513,7 +517,7 @@ bool MeshTablesSurface<PFP>::importPly(const std::string& filename, std::vector<
m_nbEdges.reserve(m_nbFaces);
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);
m_nbEdges.push_back(n);
......@@ -527,153 +531,152 @@ bool MeshTablesSurface<PFP>::importPly(const std::string& filename, std::vector<
return true;
}
/**
* Import plyPTM (K Vanhoey generic format).
* It can handle bivariable polynomials of any degree and returns the appropriate attrNames
* @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
* - 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.
* 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,
* ...
* Hint : N = attrNames.size() - 4 ;
* @return bool : success.
*/
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") ;
attrNames.push_back(positions.name()) ;
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);
// Open file
std::ifstream fp(filename.c_str(), std::ios::in) ;
if (!fp.good())
{
std::cerr << "Unable to open file " << filename<< std::endl;
return false;
CGoGNerr << "Unable to open file " << filename << CGoGNendl ;
return false ;
}
std::string ligne;
std::string tag;
// Read quantities : #vertices, #faces, #properties, degree of polynomials
std::string tag ;
fp >> tag;
if (tag != std::string("ply"))
fp >> tag;
if (tag != std::string("ply")) // verify file type
{
std::cerr <<filename<< " is not a ply file !" << std::endl;
return false;
CGoGNerr << filename << " is not a ply file !" << CGoGNout ;
return false ;
}
// va au nombre de sommets
do
do // go to #vertices
{
fp >> tag;
} while (tag != std::string("vertex"));
unsigned int nbp;
fp >> nbp;
// read points
std::vector<unsigned int> verticesID;
verticesID.reserve(nbp);
fp >> tag ;
} while (tag != std::string("vertex")) ;
unsigned int nbVertices ;
fp >> nbVertices ; // Read #vertices
AttributeHandler<typename PFP::REAL> errors[3] ;
// va au nombre de faces en comptant le nombre de "property"
unsigned int nb_props = 0;
do
unsigned int nbProps = 0 ;
do // go to #faces and count #properties
{
fp >> tag;
fp >> tag ;
if (tag == std::string("property"))
nb_props++;
if (tag == std::string("errL2")) {
errors[0] = m_map.template addAttribute<typename PFP::REAL>(VERTEX, "errL2") ;
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()) ;
}
++nbProps ;
} while (tag != std::string("face")) ;
fp >> m_nbFaces ; // Read #vertices
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;
m_nbEdges.reserve(m_nbFaces);
m_emb.reserve(3*m_nbFaces);
// Define containers
AttributeHandler<typename PFP::VEC3> positions = m_map.template getAttribute<typename PFP::VEC3>(VERTEX, "position") ;
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
do
AttributeHandler<typename PFP::VEC3> *colorPTM = new AttributeHandler<typename PFP::VEC3>[nbCoefsPerPol] ;
for (unsigned int i = 0 ; i < nbCoefsPerPol ; ++i)
{
fp >> tag;
} while (tag != std::string("end_header"));
std::stringstream name ;
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();
verticesID.push_back(id);
for (unsigned int j = 0; j < nb_props; ++j)
{
fp >> properties[j];
}
unsigned int id = container.insertLine() ;
verticesID.push_back(id) ;
positions[id] = VEC3(properties[0],properties[1],properties[2]);
for (unsigned int j = 0 ; j < nbProps ; ++j) // get all properties
fp >> properties[j] ;
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)
frame[k][id][l] = properties[3+(3*k+l)] ;
for (unsigned int k = 0 ; k < 3 ; ++k)
for (unsigned int l = 0 ; l < 15 ; ++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] ;
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)] ;
}
m_nbVertices = verticesID.size() ;
delete[] properties ;
m_nbVertices = verticesID.size();
delete[] properties;
// read indices of faces
for (unsigned int i = 0; i < m_nbFaces; i++)
// Read faces index
m_nbEdges.reserve(m_nbFaces) ;
m_emb.reserve(3*m_nbFaces) ;
for (unsigned int i = 0 ; i < m_nbFaces ; ++i)
{
// read the indices vertices of face
int nbe;
fp >> nbe;
m_nbEdges.push_back(nbe);
// read the indices of vertices for current face
int nbEdgesForFace ;
fp >> nbEdgesForFace ;
m_nbEdges.push_back(nbEdgesForFace);
int pt;
for (int j=0; j<nbe; ++j)
int vertexID ;
for (int j=0 ; j < nbEdgesForFace ; ++j)
{
fp >> pt;
m_emb.push_back(verticesID[pt]);
fp >> vertexID ;
m_emb.push_back(verticesID[vertexID]);
}
}
fp.close();
return true;
// Close file
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 ;
* - 1 attrName for geometric position (VEC3)
* - 3 attrNames for local frame (3xVEC3) : Tangent, Bitangent and Normal vector
* - 6 attrNames for the function coefficients (6xVEC3) : 6 RGB coefficients being successively the constants, the linears (v then u) and the quadratics : a0 + a1*v + a2*u + a3*u*v + a4*v^2 + a5*u^2.
* @return bool : success.
* @return bool : success.
*/
template <typename PFP>
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") ;
......@@ -797,7 +800,7 @@ bool MeshTablesSurface<PFP>::importPlyPTM(const std::string& filename, std::vect
fp.close();
return true;
}*/
}
template <typename PFP>
bool MeshTablesSurface<PFP>::importCTM(const std::string& filename, std::vector<std::string>& attrNames)
......
......@@ -129,6 +129,7 @@ void BoundingBox<VEC>::addPoint(const VEC& p)
{
m_pMin = p ;
m_pMax = p ;
m_initialized = true ;
}
else
{
......
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