From c3abaf803696621102f9a24ae697a513d59ac715 Mon Sep 17 00:00:00 2001 From: gianpaolopalma Date: Tue, 20 Oct 2015 11:13:11 +0000 Subject: [PATCH] Add features: to store for each vertex of the convex hull the vertex index of the original mesh --- vcg/complex/algorithms/convex_hull.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/vcg/complex/algorithms/convex_hull.h b/vcg/complex/algorithms/convex_hull.h index 60262140..fa1caa34 100644 --- a/vcg/complex/algorithms/convex_hull.h +++ b/vcg/complex/algorithms/convex_hull.h @@ -57,6 +57,7 @@ private: // Initialize the convex hull with the biggest tetraedron created using the vertices of the input mesh static void InitConvexHull(InputMesh& mesh, CHMesh& convexHull) { + CMesh::PerVertexAttributeHandle indexInputVertex = vcg::tri::Allocator::GetPerVertexAttribute(mesh, std::string("indexInput")); InputVertexPointer v[3]; //Find the 6 points with min/max coordinate values InputVertexIterator vi = mesh.vert.begin(); @@ -108,6 +109,7 @@ private: for (int i = 0; i < 3; i++) { (*chVi).P().Import(v[i]->P()); + indexInputVertex[chVi] = vcg::tri::Index(mesh, v[i]); chVi++; } CHFaceIterator fi = vcg::tri::Allocator::AddFace(convexHull, 0, 1, 2); @@ -140,6 +142,7 @@ private: //Create the other 3 faces of the tetrahedron chVi = vcg::tri::Allocator::AddVertices(convexHull, 1); (*chVi).P().Import(v4->P()); + indexInputVertex[chVi] = vcg::tri::Index(mesh, v4); fi = vcg::tri::Allocator::AddFace(convexHull, &convexHull.vert[3], convexHull.face[0].V0(1), convexHull.face[0].V0(0)); (*fi).N() = vcg::NormalizedTriangleNormal(*fi); fi = vcg::tri::Allocator::AddFace(convexHull, &convexHull.vert[3], convexHull.face[0].V1(1), convexHull.face[0].V1(0)); @@ -155,6 +158,8 @@ public: /** Return the convex hull of the input mesh using the Quickhull algorithm. + For each vertex of the convex hull the algorithm stores the vertex index + of the original mesh in attribute "indexInput". "The quickhull algorithm for convex hulls" by C. Bradford Barber et al. ACM Transactions on Mathematical Software, Volume 22 Issue 4, Dec. 1996 @@ -164,6 +169,7 @@ public: vcg::tri::RequireFFAdjacency(convexHull); vcg::tri::RequirePerFaceNormal(convexHull); vcg::tri::Allocator::CompactVertexVector(mesh); + CMesh::PerVertexAttributeHandle indexInputVertex = vcg::tri::Allocator::GetPerVertexAttribute(mesh, std::string("indexInput")); if (mesh.vert.size() < 4) return false; InitConvexHull(mesh, convexHull); @@ -230,6 +236,7 @@ public: { CHVertexIterator vi = vcg::tri::Allocator::AddVertices(convexHull, 1); (*vi).P().Import((*vertex).P()); + indexInputVertex[vi] = vcg::tri::Index(mesh, vertex); } //Add a new face for each border