Commit 448152a5 authored by untereiner's avatar untereiner

end merging hexa import into MeshTableVolume : TODO -> optimize

parent db1e08e4
......@@ -161,19 +161,8 @@ void MyQT::cb_Open()
// myMap.closeMap();
// }
// }
/*
if(extension == std::string(".msh"))
{
if(!Algo::Volume::Import::importMSH<PFP>(myMap,filename, attrNames))
{
std::cerr << "could not import " << filename << std::endl ;
return;
}
else
position = myMap.getAttribute<PFP::VEC3,VERTEX>(attrNames[0]);
}
else
{*/
// else
// {
if(!Algo::Volume::Import::importMesh<PFP>(myMap, filename, attrNames))
{
std::cerr << "could not import " << filename << std::endl ;
......@@ -416,28 +405,15 @@ int main(int argc, char **argv)
}
else
{
if(extension == std::string(".nas"))
{
if(!Algo::Volume::Import::importNAS<PFP>(myMap,filename, attrNames))
{
std::cerr << "could not import " << filename << std::endl ;
return 1;
}
else
position = myMap.getAttribute<PFP::VEC3,VERTEX>(attrNames[0]);
}
else
{
*/
if(!Algo::Volume::Import::importMesh<PFP>(myMap, filename, attrNames))
*/
if(!Algo::Volume::Import::importMesh<PFP>(myMap, filename, attrNames))
{
std::cerr << "could not import " << filename << std::endl ;
return 1;
}
else
position = myMap.getAttribute<PFP::VEC3,VERTEX>(attrNames[0]) ;
//}
// }
color = myMap.addAttribute<PFP::VEC3, VOLUME>("color");
......
......@@ -81,6 +81,7 @@ bool importChoupi(const std::string& filename, const std::vector<typename PFP::V
namespace Volume
{
namespace Import
{
......@@ -112,25 +113,6 @@ bool importMeshToExtrude(typename PFP::MAP& map, const std::string& filename, st
template <typename PFP>
bool importMeshSAsV(typename PFP::MAP& map, const std::string& filename, std::vector<std::string>& attrNames);
/**
* TODO ADD TO MeshTablesVolume
*/
//template <typename PFP>
//bool importMSH(typename PFP::MAP& the_map, const std::string& filename, std::vector<std::string>& attrNames, float scaleFactor = 1.0f);
template <typename PFP>
bool importVTU(typename PFP::MAP& the_map, const std::string& filename, std::vector<std::string>& attrNames, float scaleFactor = 1.0f);
template <typename PFP>
bool importNAS(typename PFP::MAP& the_map, const std::string& filename, std::vector<std::string>& attrNames, float scaleFactor = 1.0f);
template <typename PFP>
bool importVBGZ(typename PFP::MAP& the_map, const std::string& filename, std::vector<std::string>& attrNames, float scaleFactor = 1.0f);
} // Import
} // Volume
......@@ -144,13 +126,7 @@ bool importVBGZ(typename PFP::MAP& the_map, const std::string& filename, std::ve
#include "Algo/Import/importChoupi.hpp"
//#include "Algo/Import/importMSH.hpp"
#include "Algo/Import/importVTU.hpp"
#include "Algo/Import/importNAS.hpp"
#include "Algo/Import/importVBGZ.hpp"
//#include "Algo/Import/importMoka.hpp"
//#include "Algo/Import/importObjTex.hpp"
#endif
......@@ -546,7 +546,7 @@ bool importMesh(typename PFP::MAP& map, MeshTablesVolume<PFP>& mtv)
//for each volume of table
for(unsigned int i = 0 ; i < nbv ; ++i)
{
{
// store volume in buffer, removing degenated faces
unsigned int nbf = mtv.getNbFacesVolume(i);
......@@ -563,7 +563,7 @@ bool importMesh(typename PFP::MAP& map, MeshTablesVolume<PFP>& mtv)
}
if(nbf == 4) //tetrahedral case
{
{
Dart d = Surface::Modelisation::createTetrahedron<PFP>(map,false);
// Embed three "base" vertices
......@@ -603,7 +603,7 @@ bool importMesh(typename PFP::MAP& map, MeshTablesVolume<PFP>& mtv)
}
else if(nbf == 5) //pyramidal case
{
{
Dart d = Surface::Modelisation::createQuadrangularPyramid<PFP>(map,false);
// 1.
......@@ -657,7 +657,7 @@ bool importMesh(typename PFP::MAP& map, MeshTablesVolume<PFP>& mtv)
vecDartsPerVertex[em].push_back(dd); m.mark(dd);
}
else if(nbf == 6) //prism case
{
{
Dart d = Surface::Modelisation::createTriangularPrism<PFP>(map,false);
// 1.
......@@ -721,7 +721,7 @@ bool importMesh(typename PFP::MAP& map, MeshTablesVolume<PFP>& mtv)
}
else if(nbf == 8) //hexahedral case
{
{
Dart d = Surface::Modelisation::createHexahedron<PFP>(map,false);
// 1.
......@@ -806,7 +806,8 @@ bool importMesh(typename PFP::MAP& map, MeshTablesVolume<PFP>& mtv)
} //end of hexa
}
std::cout << " elements created " << std::endl;
std::cout << " elements created " << std::endl;
//reconstruct neighbourhood
unsigned int nbBoundaryFaces = 0 ;
for (Dart d = map.begin(); d != map.end(); map.next(d))
......
......@@ -199,13 +199,13 @@ private:
bool importVBGZ(const std::string& filename, std::vector<std::string>& attrNames);
//TODO Moka / OVM not working
//bool importMoka(const std::string& filename, std::vector<std::string>& attrNames);
//bool importOVM(const std::string& filename, std::vector<std::string>& attrNames);
public:
//static ImportType getFileType(const std::string& filename);
inline unsigned getNbVertices() const { return m_nbVertices; }
inline unsigned getNbVolumes() const { return m_nbVolumes; }
......
......@@ -24,6 +24,10 @@
#include "Geometry/orientation.h"
#include <libxml/encoding.h>
#include <libxml/xmlwriter.h>
#include <libxml/parser.h>
namespace CGoGN
{
......@@ -36,63 +40,90 @@ namespace Volume
namespace Import
{
inline float floatFromNas(std::string& s_v)
{
float x = 0.0f;
std::size_t pos1 = s_v.find_last_of('-');
if ((pos1!=std::string::npos) && (pos1!=0))
{
std::string res = s_v.substr(0,pos1) + "e" + s_v.substr(pos1,8-pos1);
x = atof(res.c_str());
}
else
{
std::size_t pos2 = s_v.find_last_of('+');
if ((pos2!=std::string::npos) && (pos2!=0))
{
std::string res = s_v.substr(0,pos2) + "e" + s_v.substr(pos2,8-pos2);
x = atof(res.c_str());
}
else
{
x = atof(s_v.c_str());
}
}
return x;
}
template <typename PFP>
bool MeshTablesVolume<PFP>::importMesh(const std::string& filename, std::vector<std::string>& attrNames)
{
ImportType kind = getFileType(filename);
attrNames.clear() ;
attrNames.clear() ;
switch (kind)
{
case TET:
return importTet(filename, attrNames);
break;
case OFF:
{
size_t pos = filename.rfind(".");
std::string fileEle = filename;
fileEle.erase(pos);
fileEle.append(".ele");
return importOFFWithELERegions(filename, fileEle, attrNames);
break;
}
case NODE:
{
size_t pos = filename.rfind(".");
std::string fileEle = filename;
fileEle.erase(pos);
fileEle.append(".ele");
return importNodeWithELERegions(filename, fileEle, attrNames);
break;
}
case TETMESH:
return importTetmesh(filename, attrNames);
break;
case TS:
return importTs(filename, attrNames);
break;
case MSH:
return importMSH(filename, attrNames);
break;
case VTU:
//return importVTU(filename, attrNames);
break;
case NAS:
return importNAS(filename, attrNames);
break;
case VBGZ:
//return importVBGZ>(filename, attrNames);
break;
// case ImportVolumique::MOKA:
// return importMoka(filename,attrNames);
// break;
// case OVM:
// return importOVM(filename, attrNames);
// break;
default:
CGoGNerr << "Not yet supported" << CGoGNendl;
break;
case TET:
return importTet(filename, attrNames);
break;
case OFF:
{
size_t pos = filename.rfind(".");
std::string fileEle = filename;
fileEle.erase(pos);
fileEle.append(".ele");
return importOFFWithELERegions(filename, fileEle, attrNames);
break;
}
case NODE:
{
size_t pos = filename.rfind(".");
std::string fileEle = filename;
fileEle.erase(pos);
fileEle.append(".ele");
return importNodeWithELERegions(filename, fileEle, attrNames);
break;
}
case TETMESH:
return importTetmesh(filename, attrNames);
break;
case TS:
return importTs(filename, attrNames);
break;
case MSH:
return importMSH(filename, attrNames);
break;
case VTU:
return importVTU(filename, attrNames);
break;
case NAS:
return importNAS(filename, attrNames);
break;
case VBGZ:
return importVBGZ(filename, attrNames);
break;
// case ImportVolumique::MOKA:
// return importMoka(filename,attrNames);
// break;
// case OVM:
// return importOVM(filename, attrNames);
// break;
default:
CGoGNerr << "Not yet supported" << CGoGNendl;
break;
}
return false;
}
......@@ -100,12 +131,12 @@ bool MeshTablesVolume<PFP>::importMesh(const std::string& filename, std::vector<
template <typename PFP>
bool MeshTablesVolume<PFP>::importTet(const std::string& filename, std::vector<std::string>& attrNames)
{
VertexAttribute<VEC3> position = m_map.template getAttribute<VEC3, VERTEX>("position") ;
VertexAttribute<VEC3> position = m_map.template getAttribute<VEC3, VERTEX>("position") ;
if (!position.isValid())
position = m_map.template addAttribute<VEC3, VERTEX>("position") ;
if (!position.isValid())
position = m_map.template addAttribute<VEC3, VERTEX>("position") ;
attrNames.push_back(position.name()) ;
attrNames.push_back(position.name()) ;
AttributeContainer& container = m_map.template getAttributeContainer<VERTEX>() ;
......@@ -117,23 +148,23 @@ bool MeshTablesVolume<PFP>::importTet(const std::string& filename, std::vector<s
return false;
}
std::string ligne;
std::string ligne;
// reading number of vertices
std::getline (fp, ligne);
std::stringstream oss(ligne);
oss >> m_nbVertices;
oss >> m_nbVertices;
// reading number of tetrahedra
std::getline (fp, ligne);
std::stringstream oss2(ligne);
oss2 >> m_nbVolumes;
oss2 >> m_nbVolumes;
//reading vertices
std::vector<unsigned int> verticesID;
verticesID.reserve(m_nbVertices);
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
{
......@@ -147,169 +178,169 @@ bool MeshTablesVolume<PFP>::importTet(const std::string& filename, std::vector<s
oss >> y;
oss >> z;
// TODO : if required read other vertices attributes here
VEC3 pos(x,y,z);
VEC3 pos(x,y,z);
unsigned int id = container.insertLine();
position[id] = pos;
position[id] = pos;
verticesID.push_back(id);
verticesID.push_back(id);
}
// reading volumes
m_nbFaces.reserve(m_nbVolumes*4);
m_emb.reserve(m_nbVolumes*12);
// reading volumes
m_nbFaces.reserve(m_nbVolumes*4);
m_emb.reserve(m_nbVolumes*12);
for (unsigned int i = 0; i < m_nbVolumes ; ++i)
{
do
{
std::getline (fp, ligne);
} while (ligne.size()==0);
do
{
std::getline (fp, ligne);
} while (ligne.size()==0);
std::stringstream oss(ligne);
int n;
oss >> n; // type of volumes
//tetrahedron
if(n == 4)
{
m_nbFaces.push_back(4);
int s0,s1,s2,s3;
oss >> s0;
oss >> s1;
oss >> s2;
oss >> s3;
typename PFP::VEC3 P = position[verticesID[s0]];
typename PFP::VEC3 A = position[verticesID[s1]];
typename PFP::VEC3 B = position[verticesID[s2]];
typename PFP::VEC3 C = position[verticesID[s3]];
if (Geom::testOrientation3D<typename PFP::VEC3>(P,A,B,C) == Geom::UNDER)
{
int ui = s1;
s1 = s2;
s2 = ui;
}
m_emb.push_back(verticesID[s0]);
m_emb.push_back(verticesID[s1]);
m_emb.push_back(verticesID[s2]);
m_emb.push_back(verticesID[s3]);
}
//pyramid
else if(n == 5)
{
m_nbFaces.push_back(5);
int s0,s1,s2,s3,s4;
oss >> s0;
oss >> s1;
oss >> s2;
oss >> s3;
oss >> s4;
m_emb.push_back(verticesID[s0]);
m_emb.push_back(verticesID[s1]);
m_emb.push_back(verticesID[s2]);
m_emb.push_back(verticesID[s3]);
m_emb.push_back(verticesID[s4]);
}
//prism
else if(n == 6)
{
m_nbFaces.push_back(6);
int s0,s1,s2,s3,s4,s5;
oss >> s0;
oss >> s1;
oss >> s2;
oss >> s3;
oss >> s4;
oss >> s5;
typename PFP::VEC3 P = position[verticesID[s4]];
typename PFP::VEC3 A = position[verticesID[s0]];
typename PFP::VEC3 B = position[verticesID[s1]];
typename PFP::VEC3 C = position[verticesID[s2]];
if (Geom::testOrientation3D<typename PFP::VEC3>(P,A,B,C) == Geom::OVER)
{
int ui = s0;
s0 = s4;
s4 = ui;
ui = s1;
s1 = s5;
s5 = ui;
ui = s2;
s2 = s3;
s3 = ui;
}
m_emb.push_back(verticesID[s0]);
m_emb.push_back(verticesID[s1]);
m_emb.push_back(verticesID[s2]);
m_emb.push_back(verticesID[s3]);
m_emb.push_back(verticesID[s4]);
m_emb.push_back(verticesID[s5]);
}
//hexahedron
else if(n == 8)
{
m_nbFaces.push_back(8);
int s0,s1,s2,s3,s4,s5,s6,s7;
oss >> s0;
oss >> s1;
oss >> s2;
oss >> s3;
oss >> s4;
oss >> s5;
oss >> s6;
oss >> s7;
typename PFP::VEC3 P = position[verticesID[s4]];
typename PFP::VEC3 A = position[verticesID[s0]];
typename PFP::VEC3 B = position[verticesID[s1]];
typename PFP::VEC3 C = position[verticesID[s2]];
if (Geom::testOrientation3D<typename PFP::VEC3>(P,A,B,C) == Geom::OVER)
{
int ui = s0;
s0 = s3;
s3 = ui;
ui = s1;
s1 = s2;
s2 = ui;
ui = s4;
s4 = s7;
s7 = ui;
ui = s5;
s5 = s6;
s6 = ui;
}
m_emb.push_back(verticesID[s0]);
m_emb.push_back(verticesID[s1]);
m_emb.push_back(verticesID[s2]);
m_emb.push_back(verticesID[s3]);
m_emb.push_back(verticesID[s4]);
m_emb.push_back(verticesID[s5]);
m_emb.push_back(verticesID[s6]);
m_emb.push_back(verticesID[s7]);
}
}
oss >> n; // type of volumes
//tetrahedron
if(n == 4)
{
m_nbFaces.push_back(4);
int s0,s1,s2,s3;
oss >> s0;
oss >> s1;
oss >> s2;
oss >> s3;
typename PFP::VEC3 P = position[verticesID[s0]];
typename PFP::VEC3 A = position[verticesID[s1]];
typename PFP::VEC3 B = position[verticesID[s2]];
typename PFP::VEC3 C = position[verticesID[s3]];
if (Geom::testOrientation3D<typename PFP::VEC3>(P,A,B,C) == Geom::UNDER)
{
int ui = s1;
s1 = s2;
s2 = ui;
}
m_emb.push_back(verticesID[s0]);
m_emb.push_back(verticesID[s1]);
m_emb.push_back(verticesID[s2]);
m_emb.push_back(verticesID[s3]);
}
//pyramid
else if(n == 5)
{
m_nbFaces.push_back(5);
int s0,s1,s2,s3,s4;
oss >> s0;
oss >> s1;
oss >> s2;
oss >> s3;
oss >> s4;
m_emb.push_back(verticesID[s0]);
m_emb.push_back(verticesID[s1]);
m_emb.push_back(verticesID[s2]);
m_emb.push_back(verticesID[s3]);
m_emb.push_back(verticesID[s4]);
}
//prism
else if(n == 6)
{
m_nbFaces.push_back(6);
int s0,s1,s2,s3,s4,s5;
oss >> s0;
oss >> s1;
oss >> s2;
oss >> s3;
oss >> s4;
oss >> s5;
typename PFP::VEC3 P = position[verticesID[s4]];
typename PFP::VEC3 A = position[verticesID[s0]];
typename PFP::VEC3 B = position[verticesID[s1]];
typename PFP::VEC3 C = position[verticesID[s2]];
if (Geom::testOrientation3D<typename PFP::VEC3>(P,A,B,C) == Geom::OVER)
{
int ui = s0;
s0 = s4;
s4 = ui;
ui = s1;
s1 = s5;
s5 = ui;
ui = s2;
s2 = s3;