get birth faces indices in ImportFromPolyMesh function

This commit is contained in:
alemuntoni 2021-07-07 16:45:15 +02:00
parent 0f320aa671
commit a282947a72
1 changed files with 54 additions and 37 deletions

View File

@ -75,10 +75,16 @@ namespace tri {
}
/**
Import a trianglemesh from a polygon mesh
**/
static void ImportFromPolyMesh(TriMeshType & tm, PolyMeshType & pm)
* @brief Import a trianglemesh from a polygon mesh
* @param tm: output triangle mesh
* @param pm: input polygonal mesh
* @param birthFaces: a mapping that tells, for each face of the triangle mesh,
* which one is its birth face in the polygonal mesh.
*/
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;
@ -99,8 +105,13 @@ namespace tri {
}
std::vector<int> faces;
TessellatePlanarPolygon3(points,faces);
//all the faces we add in tm have as a birth face fi
birthFaces.insert(birthFaces.end(), faces.size()/3, tri::Index(pm, *fi));
for(size_t i = 0; i<faces.size();i+=3){
TriFaceIterator tfi = Allocator<TriMeshType>::AddFace(tm,
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] )) );
@ -115,6 +126,12 @@ namespace tri {
}
}
static void ImportFromPolyMesh(TriMeshType & tm, PolyMeshType & pm)
{
std::vector<unsigned int> dummyVector;
ImportFromPolyMesh(tm, pm, dummyVector);
}
/**
\brief Import a polygon mesh from a triangle mesh