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 94cddb13 authored by Pierre Kraemer's avatar Pierre Kraemer
Browse files

miniTest compile..

parent 498e5870
......@@ -627,8 +627,6 @@ int main(int argc, char** argv)
{
MyGlutWin* mgw = new MyGlutWin(&argc, argv, 1200, 800) ;
mgw->position = myMap.addAttribute<PFP::VEC3>(VERTEX_ORBIT, "position") ;
if(argc < 2)
{
Dart d1 = myMap.newFace(3) ;
......@@ -641,12 +639,13 @@ int main(int argc, char** argv)
char* filename = argv[1] ;
GLint t1 = glutGet(GLUT_ELAPSED_TIME) ;
bool success = Algo::Import::importMesh<PFP>(myMap, filename, mgw->position, Algo::Import::ImportSurfacique::UNKNOWNSURFACE) ;
if(!success)
std::vector<std::string> attrNames ;
if(!Algo::Import::importMesh<PFP>(myMap, filename, attrNames))
{
std::cerr << "could not import "<< filename << std::endl ;
return 1 ;
}
mgw->position = myMap.getAttribute<PFP::VEC3>(VERTEX_ORBIT, attrNames[0]) ;
GLint t2 = glutGet(GLUT_ELAPSED_TIME) ;
GLfloat seconds = (t2 - t1) / 1000.0f ;
std::cout << "import: " << seconds << " sec" << std::endl ;
......
......@@ -47,7 +47,7 @@ namespace Import
* @return a boolean indicating if import was successfull
*/
template <typename PFP>
bool importMesh(typename PFP::MAP& map, const std::string& filename, typename PFP::TVEC3& positions, ImportSurfacique::ImportType kind = ImportSurfacique::UNKNOWNSURFACE);
bool importMesh(typename PFP::MAP& map, const std::string& filename, std::vector<std::string>& attrNames, ImportSurfacique::ImportType kind = ImportSurfacique::UNKNOWNSURFACE);
template <typename PFP>
bool importPLYPTM(typename PFP::MAP& map, const std::string& filename, typename PFP::TVEC3& positions, ImportSurfacique::ImportType kind,
......@@ -57,7 +57,7 @@ bool importPLYPTM(typename PFP::MAP& map, const std::string& filename, typename
* import a volumic mesh
*/
template <typename PFP>
bool importMesh(typename PFP::MAP& map, const std::string& filename, typename PFP::TVEC3& positions, ImportVolumique::ImportType kind= ImportVolumique::UNKNOWNVOLUME);
bool importMesh(typename PFP::MAP& map, const std::string& filename, typename PFP::TVEC3& positions, ImportVolumique::ImportType kind = ImportVolumique::UNKNOWNVOLUME);
//template <typename PFP>
//bool importObjWithTex(typename PFP::MAP& map, const std::string& filename);
......
......@@ -63,11 +63,14 @@ template <typename PFP>
class MeshTablesSurface
{
protected:
typename PFP::MAP& m_map;
unsigned m_nbVertices;
unsigned m_nbFaces;
unsigned int m_lab;
/**
* number of edges per face
*/
......@@ -78,65 +81,49 @@ protected:
*/
std::vector<unsigned int> m_emb;
/**
* we need direct access to container itself to insert new lines while reading points
*/
AttribContainer& m_container;
/**
* table of positions
*/
typename PFP::TVEC3& m_positions;
static ImportSurfacique::ImportType getFileType(const std::string& filename);
void extractMeshRec(const struct aiScene* scene, const struct aiNode* nd, struct aiMatrix4x4* trafo);
void extractMeshRec(AttribContainer& container, AttributeHandler<typename PFP::VEC3>& positions, const struct aiScene* scene, const struct aiNode* nd, struct aiMatrix4x4* trafo);
public:
typedef typename PFP::VEC3 VEC3 ;
typedef typename VEC3::DATA_TYPE DATA_TYPE ;
inline unsigned getNbFaces() const { return m_nbFaces;}
inline unsigned getNbFaces() const { return m_nbFaces; }
inline unsigned getNbVertices() const { return m_nbVertices;}
inline unsigned getNbVertices() const { return m_nbVertices; }
inline short getNbEdgesFace(int i) const { return m_nbEdges[i];}
inline short getNbEdgesFace(int i) const { return m_nbEdges[i]; }
inline unsigned int getEmbIdx(int i) { return m_emb[i];}
inline unsigned int getEmbIdx(int i) { return m_emb[i]; }
bool importTrian(const std::string& filename);
bool importMesh(const std::string& filename, std::vector<std::string>& attrNames, ImportSurfacique::ImportType kind);
bool importTrianBinGz(const std::string& filename);
bool importTrian(const std::string& filename, std::vector<std::string>& attrNames);
bool importOff(const std::string& filename);
bool importTrianBinGz(const std::string& filename, std::vector<std::string>& attrNames);
bool importObj(const std::string& filename);
bool importOff(const std::string& filename, std::vector<std::string>& attrNames);
bool importPly(const std::string& filename);
bool importObj(const std::string& filename, std::vector<std::string>& attrNames);
bool importMesh(const std::string& filename, ImportSurfacique::ImportType kind);
bool importPly(const std::string& filename, std::vector<std::string>& attrNames);
bool importPlyPTM(const std::string& filename, typename PFP::TFRAME& Frame, typename PFP::TRGBFUNCS& RGBfunctions);
bool importPlyPTM(const std::string& filename, std::vector<std::string>& attrNames);
bool importCTM(const std::string& filename);
bool importCTM(const std::string& filename, std::vector<std::string>& attrNames);
bool importASSIMP(const std::string& filename);
bool importASSIMP(const std::string& filename, std::vector<std::string>& attrNames);
/**
* @param container container of vertex orbite
* @param idPositions id of position attribute in the container
* @param idLabels id of label attribute in the container
*/
MeshTablesSurface(AttribContainer& container, typename PFP::TVEC3& positions):
m_container(container), m_positions(positions)
MeshTablesSurface(typename PFP::MAP& map):
m_map(map)
{
}
MeshTablesSurface(AttribContainer& container, typename PFP::TVEC3& positions, const std::string& filename):
m_container(container), m_positions(positions)
{
importMesh(filename);
}
};
......
......@@ -22,7 +22,6 @@
* *
*******************************************************************************/
#include "Algo/Import/importPlyData.h"
#include "openctm.h"
......@@ -44,7 +43,6 @@ namespace Import
template<typename PFP>
ImportSurfacique::ImportType MeshTablesSurface<PFP>::getFileType(const std::string& filename)
{
if ((filename.rfind(".trianbgz")!=std::string::npos) || (filename.rfind(".TRIANBGZ")!=std::string::npos))
return ImportSurfacique::TRIANBGZ;
if ((filename.rfind(".trian")!=std::string::npos) || (filename.rfind(".TRIAN")!=std::string::npos))
......@@ -62,51 +60,58 @@ ImportSurfacique::ImportType MeshTablesSurface<PFP>::getFileType(const std::stri
if ((filename.rfind(".ctm")!=std::string::npos) || (filename.rfind(".OBJ")!=std::string::npos))
return ImportSurfacique::CTM;
return ImportSurfacique::UNKNOWNSURFACE;
}
template<typename PFP>
bool MeshTablesSurface<PFP>::importMesh(const std::string& filename, ImportSurfacique::ImportType kind)
bool MeshTablesSurface<PFP>::importMesh(const std::string& filename, std::vector<std::string>& attrNames, ImportSurfacique::ImportType kind)
{
if (kind == ImportSurfacique::UNKNOWNSURFACE)
kind = getFileType(filename);
std::cout << "TYPE: "<<kind<<std::endl;
attrNames.clear() ;
switch (kind)
{
case ImportSurfacique::TRIAN:
return importTrian(filename);
std::cout << "TYPE: TRIAN" << std::endl;
return importTrian(filename, attrNames);
break;
case ImportSurfacique::TRIANBGZ:
return importTrianBinGz(filename);
std::cout << "TYPE: TRIANBGZ" << std::endl;
return importTrianBinGz(filename, attrNames);
break;
case ImportSurfacique::CTM:
return importCTM(filename);
std::cout << "TYPE: CTM" << std::endl;
return importCTM(filename, attrNames);
break;
case ImportSurfacique::OFF:
return importOff(filename);
std::cout << "TYPE: OFF" << std::endl;
return importOff(filename, attrNames);
break;
case ImportSurfacique::PLY:
return importPly(filename);
std::cout << "TYPE: PLY" << std::endl;
return importPly(filename, attrNames);
break;
case ImportSurfacique::OBJ:
return importObj(filename);
std::cout << "TYPE: OBJ" << std::endl;
return importObj(filename, attrNames);
break;
default:
return importASSIMP(filename);
std::cout << "TYPE: ASSIMP" << std::endl;
return importASSIMP(filename, attrNames);
break;
// default:
// std::cerr << "Not yet supported" << std::endl;
// break;
}
return false;
}
template<typename PFP>
bool MeshTablesSurface<PFP>::importTrian(const std::string& filename)
bool MeshTablesSurface<PFP>::importTrian(const std::string& filename, std::vector<std::string>& attrNames)
{
AttribContainer& container = m_map.getAttributeContainer(VERTEX_CELL) ;
AttributeHandler<typename PFP::VEC3> positions = m_map.template addAttribute<typename PFP::VEC3>(VERTEX_ORBIT, "position") ;
attrNames.push_back(positions.name()) ;
// open file
std::ifstream fp(filename.c_str(), std::ios::in);
if (!fp.good())
......@@ -114,25 +119,22 @@ bool MeshTablesSurface<PFP>::importTrian(const std::string& filename)
std::cerr << "Unable to open file " << filename << std::endl;
return false;
}
// read nb of points
// int nbp;
// read nb of points
fp >> m_nbVertices;
// read points
// read points
std::vector<unsigned int> verticesID;
verticesID.reserve(m_nbVertices);
for (unsigned int i=0; i<m_nbVertices; ++i)
for (unsigned int i = 0; i < m_nbVertices; ++i)
{
VEC3 pos;
fp >> pos[0];
fp >> pos[1];
fp >> pos[2];
// unsigned int id = m_positions.insert(pos);
unsigned int id = m_container.insertLine();
m_positions[id] = pos;
// (*m_labels)[id] = i;
unsigned int id = container.insertLine();
positions[id] = pos;
verticesID.push_back(id);
}
......@@ -141,8 +143,8 @@ bool MeshTablesSurface<PFP>::importTrian(const std::string& filename)
m_nbEdges.reserve(m_nbFaces);
m_emb.reserve(3*m_nbFaces);
// read indices of faces
for (unsigned i=0; i<m_nbFaces; i++)
// read indices of faces
for (unsigned int i = 0; i < m_nbFaces; ++i)
{
m_nbEdges.push_back(3);
// read the three vertices of triangle
......@@ -166,8 +168,12 @@ bool MeshTablesSurface<PFP>::importTrian(const std::string& filename)
}
template<typename PFP>
bool MeshTablesSurface<PFP>::importTrianBinGz(const std::string& filename)
bool MeshTablesSurface<PFP>::importTrianBinGz(const std::string& filename, std::vector<std::string>& attrNames)
{
AttribContainer& container = m_map.getAttributeContainer(VERTEX_CELL) ;
AttributeHandler<typename PFP::VEC3> positions = m_map.template addAttribute<typename PFP::VEC3>(VERTEX_ORBIT, "position") ;
attrNames.push_back(positions.name()) ;
// open file
igzstream fs(filename.c_str(), std::ios::in|std::ios::binary);
......@@ -176,27 +182,26 @@ bool MeshTablesSurface<PFP>::importTrianBinGz(const std::string& filename)
std::cerr << "Unable to open file " << filename << std::endl;
return false;
}
// read nb of points
fs.read(reinterpret_cast<char*>(&m_nbVertices), sizeof(int));
// read points
std::vector<unsigned int> verticesID;
{// juste pour limiter la portee des variables
{ // juste pour limiter la portee des variables
verticesID.reserve(m_nbVertices);
// int labEmb=0;
float* buffer = new float[m_nbVertices*3];
fs.read(reinterpret_cast<char*>(buffer),3*m_nbVertices*sizeof(float));
fs.read(reinterpret_cast<char*>(buffer), 3*m_nbVertices*sizeof(float));
float *ptr = buffer;
for (unsigned int i=0; i<m_nbVertices; ++i)
for (unsigned int i = 0; i < m_nbVertices; ++i)
{
VEC3 pos;
pos[0]= *ptr++;
pos[1]= *ptr++;
pos[2]= *ptr++;
unsigned int id = m_container.insertLine();
m_positions[id] = pos;
// (*m_labels)[id] = i;
unsigned int id = container.insertLine();
positions[id] = pos;
verticesID.push_back(id);
}
......@@ -209,12 +214,12 @@ bool MeshTablesSurface<PFP>::importTrianBinGz(const std::string& filename)
m_emb.reserve(3*m_nbFaces);
// read indices of faces
{// juste pour limiter la portee des variables
{ // juste pour limiter la portee des variables
int* buffer = new int[m_nbFaces*6];
fs.read(reinterpret_cast<char*>(buffer),6*m_nbFaces*sizeof(float));
int *ptr = buffer;
for (unsigned i=0; i<m_nbFaces; i++)
for (unsigned int i = 0; i < m_nbFaces; i++)
{
m_nbEdges.push_back(3);
m_emb.push_back(verticesID[*ptr++]);
......@@ -228,13 +233,17 @@ bool MeshTablesSurface<PFP>::importTrianBinGz(const std::string& filename)
}
template<typename PFP>
bool MeshTablesSurface<PFP>::importOff(const std::string& filename)
bool MeshTablesSurface<PFP>::importOff(const std::string& filename, std::vector<std::string>& attrNames)
{
AttribContainer& container = m_map.getAttributeContainer(VERTEX_CELL) ;
AttributeHandler<typename PFP::VEC3> positions = m_map.template addAttribute<typename PFP::VEC3>(VERTEX_ORBIT, "position") ;
attrNames.push_back(positions.name()) ;
// open file
std::ifstream fp(filename.c_str(), std::ios::in);
if (!fp.good())
{
std::cerr << "Unable to open file " << filename<< std::endl;
std::cerr << "Unable to open file " << filename << std::endl;
return false;
}
......@@ -244,8 +253,8 @@ bool MeshTablesSurface<PFP>::importOff(const std::string& filename)
std::getline (fp, ligne);
if (ligne.rfind("OFF") == std::string::npos)
{
std::cerr << "Problem reading off file: not an off file"<<std::endl;
std::cerr << ligne<<std::endl;
std::cerr << "Problem reading off file: not an off file" << std::endl;
std::cerr << ligne << std::endl;
return false;
}
......@@ -266,12 +275,12 @@ bool MeshTablesSurface<PFP>::importOff(const std::string& filename)
//lecture sommets
std::vector<unsigned int> verticesID;
verticesID.reserve(m_nbVertices);
for (unsigned int i=0; i<m_nbVertices;++i)
for (unsigned int i = 0; i < m_nbVertices;++i)
{
do
{
std::getline (fp, ligne);
} while (ligne.size()==0);
} while (ligne.size() == 0);
std::stringstream oss(ligne);
......@@ -282,25 +291,23 @@ bool MeshTablesSurface<PFP>::importOff(const std::string& filename)
// on peut ajouter ici la lecture de couleur si elle existe
VEC3 pos(x,y,z);
unsigned int id = m_container.insertLine();
m_positions[id] = pos;
// (*m_labels)[id] = i;
unsigned int id = container.insertLine();
positions[id] = pos;
verticesID.push_back(id);
}
// lecture faces
// normalement nbVertices*8 devrait suffire largement
m_nbEdges.reserve(m_nbFaces);
m_emb.reserve(m_nbVertices*8);
for (unsigned i=0; i<m_nbFaces;++i)
for (unsigned int i = 0; i < m_nbFaces; ++i)
{
do
{
std::getline (fp, ligne);
} while (ligne.size()==0);
} while (ligne.size() == 0);
std::stringstream oss(ligne);
int n;
......@@ -320,19 +327,23 @@ bool MeshTablesSurface<PFP>::importOff(const std::string& filename)
}
template <typename PFP>
bool MeshTablesSurface<PFP>::importObj(const std::string& filename)
bool MeshTablesSurface<PFP>::importObj(const std::string& filename, std::vector<std::string>& attrNames)
{
AttribContainer& container = m_map.getAttributeContainer(VERTEX_CELL) ;
AttributeHandler<typename PFP::VEC3> positions = m_map.template addAttribute<typename PFP::VEC3>(VERTEX_ORBIT, "position") ;
attrNames.push_back(positions.name()) ;
// open file
std::ifstream fp(filename.c_str(), std::ios::binary);
if (!fp.good())
{
std::cerr << "Unable to open file " << filename<< std::endl;
std::cerr << "Unable to open file " << filename << std::endl;
return false;
}
// fp.seekg(0,std::ios::end);
// fp.seekg(0, std::ios::end);
// int ab = fp.tellg();
// fp.seekg(0,std::ios::beg);
// fp.seekg(0, std::ios::beg);
// int ac = fp.tellg();
std::string ligne;
......@@ -345,11 +356,10 @@ bool MeshTablesSurface<PFP>::importObj(const std::string& filename)
}while (tag != std::string("v"));
// lecture des sommets
std::vector<unsigned int> verticesID;
verticesID.reserve(102400); // on tape large (400Ko wahouuuuu !!)
int i=0;
unsigned int i = 0;
do
{
if (tag == std::string("v"))
......@@ -363,17 +373,15 @@ bool MeshTablesSurface<PFP>::importObj(const std::string& filename)
VEC3 pos(x,y,z);
unsigned int id = m_container.insertLine();
m_positions[id] = pos;
// (*m_labels)[id] = i;
unsigned int id = container.insertLine();
positions[id] = pos;
verticesID.push_back(id);
i++;
}
fp >> tag;
std::getline (fp, ligne);
std::getline(fp, ligne);
} while (!fp.eof());
m_nbVertices = verticesID.size();
......@@ -393,7 +401,7 @@ bool MeshTablesSurface<PFP>::importObj(const std::string& filename)
m_emb.reserve(verticesID.size()*8);
std::vector<int> table;
table.reserve(64); // 64 cotes pour une face �a devrait suffire
table.reserve(64); // 64 cotes pour une face devrait suffire
m_nbFaces = 0;
do
{
......@@ -406,32 +414,30 @@ bool MeshTablesSurface<PFP>::importObj(const std::string& filename)
std::string str;
oss >> str;
unsigned ind=0;
unsigned int ind = 0;
while ( (str[ind]!='/')&& (ind<str.length()) )
{
ind++;
}
if (ind>0)
if (ind > 0)
{
long index;
std::stringstream iss(str.substr(0,ind));
std::stringstream iss(str.substr(0, ind));
iss >> index;
table.push_back(index);
}
}
int n = table.size();
unsigned int n = table.size();
m_nbEdges.push_back(short(n));
for (int j=0;j<n; ++j)
for (unsigned int j = 0; j < n; ++j)
{
int index=table[j]-1; // les index commencent 1 (boufonnerie d'obj ;)
int index = table[j] - 1; // les index commencent a 1 (boufonnerie d'obj ;)
m_emb.push_back(verticesID[index]);
}
m_nbFaces++;
}
fp >> tag;
std::getline (fp, ligne);
std::getline(fp, ligne);
} while (!fp.eof());
fp.close ();
......@@ -439,13 +445,17 @@ bool MeshTablesSurface<PFP>::importObj(const std::string& filename)
}
template<typename PFP>
bool MeshTablesSurface<PFP>::importPly(const std::string& filename)
bool MeshTablesSurface<PFP>::importPly(const std::string& filename, std::vector<std::string>& attrNames)
{
AttribContainer& container = m_map.getAttributeContainer(VERTEX_CELL) ;
AttributeHandler<typename PFP::VEC3> positions = m_map.template addAttribute<typename PFP::VEC3>(VERTEX_ORBIT, "position") ;
attrNames.push_back(positions.name()) ;
PlyImportData pid;
if (! pid.read_file(filename) )
{
std::cerr << "Unable to open file " << filename<< std::endl;
std::cerr << "Unable to open file " << filename << std::endl;
return false;
}
......@@ -456,14 +466,13 @@ bool MeshTablesSurface<PFP>::importPly(const std::string& filename)
//lecture sommets
std::vector<unsigned int> verticesID;
verticesID.reserve(m_nbVertices);
for (unsigned i=0; i<m_nbVertices;++i)
for (unsigned int i = 0; i < m_nbVertices; ++i)
{
VEC3 pos;
pid.vertexPosition(i,pos);
pid.vertexPosition(i, pos);
unsigned int id = m_container.insertLine();
m_positions[id] = pos;
// (*m_labels)[id] = i;
unsigned int id = container.insertLine();
positions[id] = pos;
verticesID.push_back(id);
}
......@@ -471,134 +480,152 @@ bool MeshTablesSurface<PFP>::importPly(const std::string& filename)
m_nbEdges.reserve(m_nbFaces);
m_emb.reserve(m_nbVertices*8);
for (unsigned i=0; i<m_nbFaces;++i)
for (unsigned int i = 0; i < m_nbFaces; ++i)
{
int n = pid.getFaceValence(i);
unsigned int n = pid.getFaceValence(i);
m_nbEdges.push_back(n);
int* indices = pid.getFaceIndices(i);
for (int j=0;j<n; ++j)
for (unsigned int j = 0; j < n; ++j)
{
m_emb.push_back(verticesID[ indices[j] ]);
m_emb.push_back(verticesID[indices[j]]);
}
}
return true;
}
//template<typename PFP>
//bool MeshTablesSurface<PFP>::importPlyGenASCII(const std::string& filename)
//{
// std::ifstream fp(filename.c_str(), std::ios::binary);
// if (!fp.good())
// {
// std::cerr << "Unable to open file " << filename<< std::endl;
// return false;
// }
//
// std::string ligne;