diff --git a/vcg/complex/algorithms/convex_hull.h b/vcg/complex/algorithms/convex_hull.h index a260c79f..8521e7da 100644 --- a/vcg/complex/algorithms/convex_hull.h +++ b/vcg/complex/algorithms/convex_hull.h @@ -57,8 +57,8 @@ private: // Initialize the convex hull with the biggest tetraedron created using the vertices of the input mesh static void InitConvexHull(InputMesh& mesh, CHMesh& convexHull) { - typename CHMesh:: template PerVertexAttributeHandle indexInputVertex = Allocator::template GetPerVertexAttribute(mesh, std::string("indexInput")); - InputVertexPointer v[3]; + typename CHMesh:: template PerVertexAttributeHandle indexInputVertex = Allocator::template GetPerVertexAttribute(convexHull, std::string("indexInput")); + InputVertexPointer v[3]; //Find the 6 points with min/max coordinate values InputVertexIterator vi = mesh.vert.begin(); std::vector minMax(6, &(*vi)); @@ -109,7 +109,7 @@ private: for (int i = 0; i < 3; i++) { (*chVi).P().Import(v[i]->P()); - indexInputVertex[chVi] = vcg::tri::Index(mesh, v[i]); + indexInputVertex[chVi] = 0; chVi++; } CHFaceIterator fi = vcg::tri::Allocator::AddFace(convexHull, 0, 1, 2); @@ -169,11 +169,11 @@ public: vcg::tri::RequireFFAdjacency(convexHull); vcg::tri::RequirePerFaceNormal(convexHull); vcg::tri::Allocator::CompactVertexVector(mesh); - typename CHMesh:: template PerVertexAttributeHandle indexInputVertex = Allocator::template GetPerVertexAttribute(mesh, std::string("indexInput")); + typename CHMesh:: template PerVertexAttributeHandle indexInputVertex = Allocator::template GetPerVertexAttribute(convexHull, std::string("indexInput")); if (mesh.vert.size() < 4) return false; InitConvexHull(mesh, convexHull); - + //Build list of visible vertices for each convex hull face and find the furthest vertex for each face std::vector> listVertexPerFace(convexHull.face.size()); std::vector furthestVexterPerFace(convexHull.face.size(), std::make_pair((InputVertexPointer)NULL, 0.0f)); @@ -236,7 +236,7 @@ public: { CHVertexIterator vi = vcg::tri::Allocator::AddVertices(convexHull, 1); (*vi).P().Import((*vertex).P()); - indexInputVertex[vi] = vcg::tri::Index(mesh, vertex); + indexInputVertex[vi] = vcg::tri::Index(mesh, vertex); } //Add a new face for each border @@ -322,7 +322,8 @@ public: } } } - tri::UpdateTopology::ClearFaceFace(convexHull); + + tri::UpdateTopology::ClearFaceFace(convexHull); vcg::tri::Allocator::CompactFaceVector(convexHull); vcg::tri::Clean::RemoveUnreferencedVertex(convexHull); return true;