diff --git a/vcg/complex/algorithms/polygonal_algorithms.h b/vcg/complex/algorithms/polygonal_algorithms.h index aca16c15..6288798a 100644 --- a/vcg/complex/algorithms/polygonal_algorithms.h +++ b/vcg/complex/algorithms/polygonal_algorithms.h @@ -951,6 +951,64 @@ public: ClosePos=closeTest; } } + + static void Triangulate(PolyMeshType &poly_m,size_t IndexF) + { + + CoordType bary=vcg::PolyBarycenter(poly_m.face[IndexF]); + size_t sizeV=poly_m.face[IndexF].VN(); + + //add the new vertex + vcg::tri::Allocator::AddVertex(poly_m,bary); + VertexType *newV=&poly_m.vert.back(); + + std::vector ToUpdateF; + + //then reupdate the faces + for (size_t j=0;j<(sizeV-1);j++) + { + VertexType * v0=poly_m.face[IndexF].V0(j); + VertexType * v1=poly_m.face[IndexF].V1(j); + VertexType * v2=newV; + + vcg::tri::Allocator::AddFaces(poly_m,1); + + poly_m.face.back().Alloc(3); + poly_m.face.back().V(0)=v0; + poly_m.face.back().V(1)=v1; + poly_m.face.back().V(2)=v2; + ToUpdateF.push_back(poly_m.face.size()-1); + } + VertexType * v0=poly_m.face[IndexF].V0((sizeV-1)); + VertexType * v1=poly_m.face[IndexF].V1((sizeV-1)); + poly_m.face[IndexF].Dealloc(); + poly_m.face[IndexF].Alloc(3); + poly_m.face[IndexF].V(0)=v0; + poly_m.face[IndexF].V(1)=v1; + poly_m.face[IndexF].V(2)=newV; + ToUpdateF.push_back(IndexF); + } + + + static void Triangulate(PolyMeshType &poly_m) + { + size_t size0=poly_m.face.size(); + for (size_t i=0;i + static void TriangulateToTriMesh(PolyMeshType &poly_m,TriMeshType &triangle_mesh) + { + triangle_mesh.Clear(); + + PolyMeshType PolySwap; + vcg::tri::Append::Mesh(PolySwap,poly_m); + Triangulate(PolySwap); + + //then copy onto the triangle mesh + vcg::tri::Append::Mesh(triangle_mesh,PolySwap); + } }; }//end namespace vcg