get birth faces indices in ImportFromPolyMesh function
This commit is contained in:
parent
0f320aa671
commit
a282947a72
|
@ -74,46 +74,63 @@ namespace tri {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Import a trianglemesh from a polygon mesh
|
* @brief Import a trianglemesh from a polygon mesh
|
||||||
**/
|
* @param tm: output triangle mesh
|
||||||
static void ImportFromPolyMesh(TriMeshType & tm, PolyMeshType & pm)
|
* @param pm: input polygonal mesh
|
||||||
{
|
* @param birthFaces: a mapping that tells, for each face of the triangle mesh,
|
||||||
tri::RequirePolygonalMesh(pm);
|
* which one is its birth face in the polygonal mesh.
|
||||||
std::vector<typename PolyMeshType::CoordType> points;
|
*/
|
||||||
|
static void ImportFromPolyMesh(TriMeshType& tm, PolyMeshType& pm, std::vector<unsigned int>& birthFaces)
|
||||||
|
{
|
||||||
|
birthFaces.clear();
|
||||||
|
birthFaces.reserve(pm.FN()); //at least the same face number of the polymesh
|
||||||
|
tri::RequirePolygonalMesh(pm);
|
||||||
|
std::vector<typename PolyMeshType::CoordType> points;
|
||||||
|
|
||||||
// the vertices are the same, simply import them
|
// the vertices are the same, simply import them
|
||||||
PolyVertexIterator vi;
|
PolyVertexIterator vi;
|
||||||
TriVertexIterator tvi = Allocator<TriMeshType>::AddVertices(tm,pm.vert.size());
|
TriVertexIterator tvi = Allocator<TriMeshType>::AddVertices(tm,pm.vert.size());
|
||||||
int cnt = 0;
|
int cnt = 0;
|
||||||
for(tvi = tm.vert.begin(),vi = pm.vert.begin(); tvi != tm.vert.end(); ++tvi,++vi,++cnt)
|
for(tvi = tm.vert.begin(),vi = pm.vert.begin(); tvi != tm.vert.end(); ++tvi,++vi,++cnt)
|
||||||
if(!(*vi).IsD()) (*tvi).ImportData(*vi); else tri::Allocator<TriMeshType>::DeleteVertex(tm,(*tvi));
|
if(!(*vi).IsD()) (*tvi).ImportData(*vi); else tri::Allocator<TriMeshType>::DeleteVertex(tm,(*tvi));
|
||||||
|
|
||||||
for(PolyFaceIterator fi = pm.face.begin(); fi != pm.face.end(); ++fi)
|
for(PolyFaceIterator fi = pm.face.begin(); fi != pm.face.end(); ++fi)
|
||||||
{
|
{
|
||||||
if(!((*fi).IsD())){
|
if(!((*fi).IsD())){
|
||||||
points.clear();
|
points.clear();
|
||||||
for(int i = 0; i < (*fi).VN(); ++i) {
|
for(int i = 0; i < (*fi).VN(); ++i) {
|
||||||
typename PolyMeshType::VertexType * v = (*fi).V(i);
|
typename PolyMeshType::VertexType * v = (*fi).V(i);
|
||||||
points.push_back(v->P());
|
points.push_back(v->P());
|
||||||
}
|
}
|
||||||
std::vector<int> faces;
|
std::vector<int> faces;
|
||||||
TessellatePlanarPolygon3(points,faces);
|
TessellatePlanarPolygon3(points,faces);
|
||||||
for(size_t i = 0; i<faces.size();i+=3){
|
|
||||||
TriFaceIterator tfi = Allocator<TriMeshType>::AddFace(tm,
|
|
||||||
tri::Index(pm,(*fi).V( faces[i+0] )),
|
|
||||||
tri::Index(pm,(*fi).V( faces[i+1] )),
|
|
||||||
tri::Index(pm,(*fi).V( faces[i+2] )) );
|
|
||||||
|
|
||||||
tfi->ImportData(*fi);
|
//all the faces we add in tm have as a birth face fi
|
||||||
// set the F flags
|
birthFaces.insert(birthFaces.end(), faces.size()/3, tri::Index(pm, *fi));
|
||||||
if( (faces[i ]+1)%points.size() != size_t(faces[i+1])) (*tfi).SetF(0);
|
|
||||||
if( (faces[i+1]+1)%points.size() != size_t(faces[i+2])) (*tfi).SetF(1);
|
for(size_t i = 0; i<faces.size();i+=3){
|
||||||
if( (faces[i+2]+1)%points.size() != size_t(faces[i ])) (*tfi).SetF(2);
|
TriFaceIterator tfi = Allocator<TriMeshType>::AddFace(
|
||||||
}
|
tm,
|
||||||
}
|
tri::Index(pm,(*fi).V( faces[i+0] )),
|
||||||
}
|
tri::Index(pm,(*fi).V( faces[i+1] )),
|
||||||
}
|
tri::Index(pm,(*fi).V( faces[i+2] )) );
|
||||||
|
|
||||||
|
tfi->ImportData(*fi);
|
||||||
|
// set the F flags
|
||||||
|
if( (faces[i ]+1)%points.size() != size_t(faces[i+1])) (*tfi).SetF(0);
|
||||||
|
if( (faces[i+1]+1)%points.size() != size_t(faces[i+2])) (*tfi).SetF(1);
|
||||||
|
if( (faces[i+2]+1)%points.size() != size_t(faces[i ])) (*tfi).SetF(2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ImportFromPolyMesh(TriMeshType & tm, PolyMeshType & pm)
|
||||||
|
{
|
||||||
|
std::vector<unsigned int> dummyVector;
|
||||||
|
ImportFromPolyMesh(tm, pm, dummyVector);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue