Commit 751b9077 authored by Lionel Untereiner's avatar Lionel Untereiner

import mesh for mixed hex/tet meshes

parent 08553e53
......@@ -177,8 +177,8 @@ void MyQT::cb_Open()
// if (v>maxV)
// maxV=v;
if(myMap.isVolumeIncidentToBoundary(d))
color[d] = PFP::VEC3(0,0,0);
//if(myMap.isVolumeIncidentToBoundary(d))
// color[d] = PFP::VEC3(0,0,0);
}
// for (unsigned int i = color.begin(); i != color.end(); color.next(i))
// {
......@@ -422,8 +422,8 @@ int main(int argc, char **argv)
// if (v>maxV)
// maxV=v;
if(myMap.isVolumeIncidentToBoundary(d))
color[d] = PFP::VEC3(0,0,0);
if(myMap.isVolumeIncidentToBoundary(d))
color[d] = PFP::VEC3(1,0.41,0.706);
//else
// color[d] = PFP::VEC3(1.0,0,0);
}
......
......@@ -43,251 +43,251 @@ namespace Import
template <typename PFP>
bool importMesh(typename PFP::MAP& map, MeshTablesSurface<PFP>& mts)
{
typedef typename PFP::MAP MAP;
typedef typename PFP::MAP::IMPL MAP_IMPL;
VertexAutoAttribute< NoTypeNameAttribute< std::vector<Dart> >, MAP_IMPL> vecDartsPerVertex(map, "incidents");
unsigned nbf = mts.getNbFaces();
int index = 0;
// buffer for tempo faces (used to remove degenerated edges)
std::vector<unsigned int> edgesBuffer;
edgesBuffer.reserve(16);
DartMarkerNoUnmark<MAP> m(map) ;
unsigned int vemb = EMBNULL;
auto fsetemb = [&] (Dart d) { map.template initDartEmbedding<VERTEX>(d, vemb); };
// for each face of table
for(unsigned int i = 0; i < nbf; ++i)
{
// store face in buffer, removing degenerated edges
unsigned int nbe = mts.getNbEdgesFace(i);
edgesBuffer.clear();
unsigned int prec = EMBNULL;
for (unsigned int j = 0; j < nbe; ++j)
{
unsigned int em = mts.getEmbIdx(index++);
if (em != prec)
{
prec = em;
edgesBuffer.push_back(em);
}
}
// check first/last vertices
if (edgesBuffer.front() == edgesBuffer.back())
edgesBuffer.pop_back();
// create only non degenerated faces
nbe = edgesBuffer.size();
if (nbe > 2)
{
Dart d = map.newFace(nbe, false);
for (unsigned int j = 0; j < nbe; ++j)
{
vemb = edgesBuffer[j]; // get embedding
map.template foreach_dart_of_orbit<PFP::MAP::VERTEX_OF_PARENT>(d, fsetemb);
m.mark(d) ; // mark on the fly to unmark on second loop
vecDartsPerVertex[vemb].push_back(d); // store incident darts for fast adjacency reconstruction
d = map.phi1(d);
}
}
}
bool needBijectiveCheck = false;
// reconstruct neighbourhood
unsigned int nbBoundaryEdges = 0;
for (Dart d = map.begin(); d != map.end(); map.next(d))
{
if (m.isMarked(d))
{
// darts incident to end vertex of edge
std::vector<Dart>& vec = vecDartsPerVertex[map.phi1(d)];
unsigned int embd = map.template getEmbedding<VERTEX>(d);
Dart good_dart = NIL;
bool firstOK = true;
for (typename std::vector<Dart>::iterator it = vec.begin(); it != vec.end() && good_dart == NIL; ++it)
{
if (map.template getEmbedding<VERTEX>(map.phi1(*it)) == embd)
{
good_dart = *it;
if (good_dart == map.phi2(good_dart))
{
map.sewFaces(d, good_dart, false);
m.template unmarkOrbit<EDGE>(d);
}
else
{
good_dart = NIL;
firstOK = false;
}
}
}
if (!firstOK)
needBijectiveCheck = true;
if (good_dart == NIL)
{
m.template unmarkOrbit<EDGE>(d);
++nbBoundaryEdges;
}
}
}
if (nbBoundaryEdges > 0)
{
unsigned int nbH = map.closeMap();
CGoGNout << "Map closed (" << nbBoundaryEdges << " boundary edges / " << nbH << " holes)" << CGoGNendl;
}
if (needBijectiveCheck)
{
// ensure bijection between topo and embedding
Algo::Topo::bijectiveOrbitEmbedding<VERTEX>(map);
}
return true ;
typedef typename PFP::MAP MAP;
typedef typename PFP::MAP::IMPL MAP_IMPL;
VertexAutoAttribute< NoTypeNameAttribute< std::vector<Dart> >, MAP_IMPL> vecDartsPerVertex(map, "incidents");
unsigned nbf = mts.getNbFaces();
int index = 0;
// buffer for tempo faces (used to remove degenerated edges)
std::vector<unsigned int> edgesBuffer;
edgesBuffer.reserve(16);
DartMarkerNoUnmark<MAP> m(map) ;
unsigned int vemb = EMBNULL;
auto fsetemb = [&] (Dart d) { map.template initDartEmbedding<VERTEX>(d, vemb); };
// for each face of table
for(unsigned int i = 0; i < nbf; ++i)
{
// store face in buffer, removing degenerated edges
unsigned int nbe = mts.getNbEdgesFace(i);
edgesBuffer.clear();
unsigned int prec = EMBNULL;
for (unsigned int j = 0; j < nbe; ++j)
{
unsigned int em = mts.getEmbIdx(index++);
if (em != prec)
{
prec = em;
edgesBuffer.push_back(em);
}
}
// check first/last vertices
if (edgesBuffer.front() == edgesBuffer.back())
edgesBuffer.pop_back();
// create only non degenerated faces
nbe = edgesBuffer.size();
if (nbe > 2)
{
Dart d = map.newFace(nbe, false);
for (unsigned int j = 0; j < nbe; ++j)
{
vemb = edgesBuffer[j]; // get embedding
map.template foreach_dart_of_orbit<PFP::MAP::VERTEX_OF_PARENT>(d, fsetemb);
m.mark(d) ; // mark on the fly to unmark on second loop
vecDartsPerVertex[vemb].push_back(d); // store incident darts for fast adjacency reconstruction
d = map.phi1(d);
}
}
}
bool needBijectiveCheck = false;
// reconstruct neighbourhood
unsigned int nbBoundaryEdges = 0;
for (Dart d = map.begin(); d != map.end(); map.next(d))
{
if (m.isMarked(d))
{
// darts incident to end vertex of edge
std::vector<Dart>& vec = vecDartsPerVertex[map.phi1(d)];
unsigned int embd = map.template getEmbedding<VERTEX>(d);
Dart good_dart = NIL;
bool firstOK = true;
for (typename std::vector<Dart>::iterator it = vec.begin(); it != vec.end() && good_dart == NIL; ++it)
{
if (map.template getEmbedding<VERTEX>(map.phi1(*it)) == embd)
{
good_dart = *it;
if (good_dart == map.phi2(good_dart))
{
map.sewFaces(d, good_dart, false);
m.template unmarkOrbit<EDGE>(d);
}
else
{
good_dart = NIL;
firstOK = false;
}
}
}
if (!firstOK)
needBijectiveCheck = true;
if (good_dart == NIL)
{
m.template unmarkOrbit<EDGE>(d);
++nbBoundaryEdges;
}
}
}
if (nbBoundaryEdges > 0)
{
unsigned int nbH = map.closeMap();
CGoGNout << "Map closed (" << nbBoundaryEdges << " boundary edges / " << nbH << " holes)" << CGoGNendl;
}
if (needBijectiveCheck)
{
// ensure bijection between topo and embedding
Algo::Topo::bijectiveOrbitEmbedding<VERTEX>(map);
}
return true ;
}
template <typename PFP>
bool importMesh(typename PFP::MAP& map, const std::string& filename, std::vector<std::string>& attrNames, bool mergeCloseVertices)
{
MeshTablesSurface<PFP> mts(map);
MeshTablesSurface<PFP> mts(map);
if(!mts.importMesh(filename, attrNames))
return false;
if(!mts.importMesh(filename, attrNames))
return false;
if (mergeCloseVertices)
mts.mergeCloseVertices();
if (mergeCloseVertices)
mts.mergeCloseVertices();
return importMesh<PFP>(map, mts);
return importMesh<PFP>(map, mts);
}
template <typename PFP>
bool importVoxellisation(typename PFP::MAP& map, Algo::Surface::Modelisation::Voxellisation& voxellisation, std::vector<std::string>& attrNames, bool mergeCloseVertices)
{
MeshTablesSurface<PFP> mts(map);
MeshTablesSurface<PFP> mts(map);
if(!mts.importVoxellisation(voxellisation, attrNames))
return false;
if(!mts.importVoxellisation(voxellisation, attrNames))
return false;
if (mergeCloseVertices)
mts.mergeCloseVertices();
if (mergeCloseVertices)
mts.mergeCloseVertices();
return importMesh<PFP>(map, mts);
return importMesh<PFP>(map, mts);
}
template <typename PFP>
bool importMeshSAsV(typename PFP::MAP& map, MeshTablesSurface<PFP>& mts)
{
typedef typename PFP::MAP MAP;
typedef typename PFP::MAP::IMPL MAP_IMPL;
VertexAutoAttribute< NoTypeNameAttribute< std::vector<Dart> >, MAP_IMPL> vecDartsPerVertex(map, "incidents");
unsigned nbf = mts.getNbFaces();
int index = 0;
// buffer for tempo faces (used to remove degenerated edges)
std::vector<unsigned int> edgesBuffer;
edgesBuffer.reserve(16);
DartMarkerNoUnmark<MAP> m(map) ;
unsigned int vemb = EMBNULL;
auto fsetemb = [&] (Dart d) { map.template initDartEmbedding<VERTEX>(d, vemb); };
// for each face of table
for(unsigned int i = 0; i < nbf; ++i)
{
// store face in buffer, removing degenerated edges
unsigned int nbe = mts.getNbEdgesFace(i);
edgesBuffer.clear();
unsigned int prec = EMBNULL;
for (unsigned int j = 0; j < nbe; ++j)
{
unsigned int em = mts.getEmbIdx(index++);
if (em != prec)
{
prec = em;
edgesBuffer.push_back(em);
}
}
// check first/last vertices
if (edgesBuffer.front() == edgesBuffer.back())
edgesBuffer.pop_back();
// create only non degenerated faces
nbe = edgesBuffer.size();
if (nbe > 2)
{
Dart d = map.newFace(nbe, false);
for (unsigned int j = 0; j < nbe; ++j)
{
vemb = edgesBuffer[j]; // get embedding
map.template foreach_dart_of_orbit<PFP::MAP::VERTEX_OF_PARENT2>(d, fsetemb);
m.mark(d) ; // mark on the fly to unmark on second loop
vecDartsPerVertex[vemb].push_back(d); // store incident darts for fast adjacency reconstruction
d = map.phi1(d);
}
}
}
// reconstruct neighbourhood
unsigned int nbBoundaryEdges = 0;
for (Dart d = map.begin(); d != map.end(); map.next(d))
{
if (m.isMarked(d))
{
// darts incident to end vertex of edge
std::vector<Dart>& vec = vecDartsPerVertex[map.phi1(d)];
unsigned int embd = map.template getEmbedding<VERTEX>(d);
Dart good_dart = NIL;
for (typename std::vector<Dart>::iterator it = vec.begin(); it != vec.end() && good_dart == NIL; ++it)
{
if (map.template getEmbedding<VERTEX>(map.phi1(*it)) == embd)
good_dart = *it;
}
if (good_dart != NIL)
{
map.sewFaces(d, good_dart, false);
m.unmarkOrbit<EDGE>(d);
}
else
{
m.unmark(d);
++nbBoundaryEdges;
}
}
}
unsigned int nbH = map.closeMap();
CGoGNout << "Map closed (" << map.template getNbOrbits<FACE>() << " boundary faces / " << nbH << " holes)" << CGoGNendl;
std::cout << "nb darts : " << map.getNbDarts() << std::endl ;
// ensure bijection between topo and embedding
//map.template bijectiveOrbitEmbedding<VERTEX>();
return true ;
typedef typename PFP::MAP MAP;
typedef typename PFP::MAP::IMPL MAP_IMPL;
VertexAutoAttribute< NoTypeNameAttribute< std::vector<Dart> >, MAP_IMPL> vecDartsPerVertex(map, "incidents");
unsigned nbf = mts.getNbFaces();
int index = 0;
// buffer for tempo faces (used to remove degenerated edges)
std::vector<unsigned int> edgesBuffer;
edgesBuffer.reserve(16);
DartMarkerNoUnmark<MAP> m(map) ;
unsigned int vemb = EMBNULL;
auto fsetemb = [&] (Dart d) { map.template initDartEmbedding<VERTEX>(d, vemb); };
// for each face of table
for(unsigned int i = 0; i < nbf; ++i)
{
// store face in buffer, removing degenerated edges
unsigned int nbe = mts.getNbEdgesFace(i);
edgesBuffer.clear();
unsigned int prec = EMBNULL;
for (unsigned int j = 0; j < nbe; ++j)
{
unsigned int em = mts.getEmbIdx(index++);
if (em != prec)
{
prec = em;
edgesBuffer.push_back(em);
}
}
// check first/last vertices
if (edgesBuffer.front() == edgesBuffer.back())
edgesBuffer.pop_back();
// create only non degenerated faces
nbe = edgesBuffer.size();
if (nbe > 2)
{
Dart d = map.newFace(nbe, false);
for (unsigned int j = 0; j < nbe; ++j)
{
vemb = edgesBuffer[j]; // get embedding
map.template foreach_dart_of_orbit<PFP::MAP::VERTEX_OF_PARENT2>(d, fsetemb);
m.mark(d) ; // mark on the fly to unmark on second loop
vecDartsPerVertex[vemb].push_back(d); // store incident darts for fast adjacency reconstruction
d = map.phi1(d);
}
}
}
// reconstruct neighbourhood
unsigned int nbBoundaryEdges = 0;
for (Dart d = map.begin(); d != map.end(); map.next(d))
{
if (m.isMarked(d))
{
// darts incident to end vertex of edge
std::vector<Dart>& vec = vecDartsPerVertex[map.phi1(d)];
unsigned int embd = map.template getEmbedding<VERTEX>(d);
Dart good_dart = NIL;
for (typename std::vector<Dart>::iterator it = vec.begin(); it != vec.end() && good_dart == NIL; ++it)
{
if (map.template getEmbedding<VERTEX>(map.phi1(*it)) == embd)
good_dart = *it;
}
if (good_dart != NIL)
{
map.sewFaces(d, good_dart, false);
m.unmarkOrbit<EDGE>(d);
}
else
{
m.unmark(d);
++nbBoundaryEdges;
}
}
}
unsigned int nbH = map.closeMap();
CGoGNout << "Map closed (" << map.template getNbOrbits<FACE>() << " boundary faces / " << nbH << " holes)" << CGoGNendl;
std::cout << "nb darts : " << map.getNbDarts() << std::endl ;
// ensure bijection between topo and embedding
//map.template bijectiveOrbitEmbedding<VERTEX>();
return true ;
}
template <typename PFP>
bool importMeshSAsV(typename PFP::MAP& map, const std::string& filename, std::vector<std::string>& attrNames)
{
MeshTablesSurface<PFP> mts(map);
MeshTablesSurface<PFP> mts(map);
if(!mts.importMesh(filename, attrNames))
return false;
if(!mts.importMesh(filename, attrNames))
return false;
return importMeshSAsV<PFP>(map, mts);
return importMeshSAsV<PFP>(map, mts);
}
......@@ -306,548 +306,675 @@ namespace Import
template <typename PFP>
bool importMeshSToV(typename PFP::MAP& map, Surface::Import::MeshTablesSurface<PFP>& mts, float dist)
{
typedef typename PFP::MAP MAP;
typedef typename PFP::MAP::IMPL MAP_IMPL;
typedef typename PFP::VEC3 VEC3;
VertexAutoAttribute< NoTypeNameAttribute< std::vector<Dart> >, MAP_IMPL> vecDartsPerVertex(map, "incidents");
unsigned nbf = mts.getNbFaces();
int index = 0;
// buffer for tempo faces (used to remove degenerated edges)
std::vector<unsigned int> edgesBuffer;
edgesBuffer.reserve(16);
DartMarkerNoUnmark<MAP> m(map) ;
unsigned int vemb1 = EMBNULL;
auto fsetemb1 = [&] (Dart d) { map.template initDartEmbedding<VERTEX>(d, vemb1); };
unsigned int vemb2 = EMBNULL;
auto fsetemb2 = [&] (Dart d) { map.template initDartEmbedding<VERTEX>(d, vemb2); };
VertexAttribute<VEC3, MAP_IMPL> position = map.template getAttribute<VEC3, VERTEX>("position");
std::vector<unsigned int > backEdgesBuffer(mts.getNbVertices(), EMBNULL);
// for each face of table -> create a prism
for(unsigned int i = 0; i < nbf; ++i)
{
// store face in buffer, removing degenerated edges
unsigned int nbe = mts.getNbEdgesFace(i);
edgesBuffer.clear();
unsigned int prec = EMBNULL;
for (unsigned int j = 0; j < nbe; ++j)
{
unsigned int em = mts.getEmbIdx(index++);
if (em != prec)
{
prec = em;
edgesBuffer.push_back(em);
}
}
// check first/last vertices
if (edgesBuffer.front() == edgesBuffer.back())
edgesBuffer.pop_back();
// create only non degenerated faces
nbe = edgesBuffer.size();
if (nbe > 2)
{
Dart d = Surface::Modelisation::createPrism<PFP>(map, nbe, false);
//Embed the base faces
for (unsigned int j = 0; j < nbe; ++j)
{
vemb1 = edgesBuffer[j]; // get embedding
if(backEdgesBuffer[vemb1] == EMBNULL)
{
unsigned int emn = map.template newCell<VERTEX>();
map.template copyCell<VERTEX>(emn, vemb1);
backEdgesBuffer[vemb1] = emn;
position[emn] += typename PFP::VEC3(0,0,dist);
}
map.template foreach_dart_of_orbit<PFP::MAP::VERTEX_OF_PARENT>(d, fsetemb1);
//Embed the other base face
Dart d2 = map.phi1(map.phi1(map.phi2(d)));
vemb2 = backEdgesBuffer[vemb1];
map.template foreach_dart_of_orbit<PFP::MAP::VERTEX_OF_PARENT>(d2, fsetemb2);
m.mark(d) ; // mark on the fly to unmark on second loop
vecDartsPerVertex[vemb1].push_back(d); // store incident darts for fast adjacency reconstruction
d = map.phi_1(d);
}
}
}
// reconstruct neighbourhood
unsigned int nbBoundaryEdges = 0;
for (Dart d = map.begin(); d != map.end(); map.next(d))
{
if (m.isMarked(d))
{
// darts incident to end vertex of edge
std::vector<Dart>& vec = vecDartsPerVertex[map.phi1(d)];
unsigned int embd = map.template getEmbedding<VERTEX>(d);
Dart good_dart = NIL;
for (typename std::vector<Dart>::iterator it = vec.begin(); it != vec.end() && good_dart == NIL; ++it)
{
if (map.template getEmbedding<VERTEX>(map.phi1(*it)) == embd)
good_dart = *it;
}
if (good_dart != NIL)
{
map.sewVolumes(map.phi2(d), map.phi2(good_dart), false);
m.unmarkOrbit<EDGE>(d);
}
else
{
m.unmark(d);
++nbBoundaryEdges;
}
}
}
return true ;
typedef typename PFP::MAP MAP;
typedef typename PFP::MAP::IMPL MAP_IMPL;
typedef typename PFP::VEC3 VEC3;
VertexAutoAttribute< NoTypeNameAttribute< std::vector<Dart> >, MAP_IMPL> vecDartsPerVertex(map, "incidents");
unsigned nbf = mts.getNbFaces();
int index = 0;
// buffer for tempo faces (used to remove degenerated edges)
std::vector<unsigned int> edgesBuffer;
edgesBuffer.reserve(16);
DartMarkerNoUnmark<MAP> m(map) ;
unsigned int vemb1 = EMBNULL;