diff --git a/vcg/complex/algorithms/intersection.h b/vcg/complex/algorithms/intersection.h index fc7fac68..3aff52ed 100644 --- a/vcg/complex/algorithms/intersection.h +++ b/vcg/complex/algorithms/intersection.h @@ -103,7 +103,7 @@ bool IntersectionPlaneGrid( GridType & grid, Plane3 plane, std::vect it is not safe to put epsilon to 0. */ template < typename TriMeshType, typename EdgeMeshType, class ScalarType > -bool IntersectionPlaneMesh(TriMeshType & m, +bool IntersectionPlaneMeshOld(TriMeshType & m, Plane3 pl, EdgeMeshType & em) { @@ -134,17 +134,24 @@ bool IntersectionPlaneMesh(TriMeshType & m, /** \brief More stable version of the IntersectionPlaneMesh function * * This version of the make a first pass storing the distance to the plane - * into vertex quality and then use this value to compute in a safe way the + * into a vertex attribute and then use this value to compute in a safe way the * intersection. */ template < typename TriMeshType, typename EdgeMeshType, class ScalarType > -bool IntersectionPlaneMeshQuality(TriMeshType & m, +bool IntersectionPlaneMesh(TriMeshType & m, Plane3 pl, EdgeMeshType & em) { std::vector ptVec; std::vector nmVec; - tri::UpdateQuality::VertexFromPlane(m,pl); + + typename TriMeshType::template PerVertexAttributeHandle < ScalarType > qH = + tri::Allocator :: template AddPerVertexAttribute < ScalarType >(m,"TemporaryPlaneDistance"); + + typename TriMeshType::VertexIterator vi; + for(vi=m.vert.begin();vi!=m.vert.end();++vi) if(!(*vi).IsD()) + qH[vi] =SignedDistancePlanePoint(pl,(*vi).cP()); + for(size_t i=0;iQ() * m.face[i].V1(j)->Q())<0) + if((qH[m.face[i].V0(j)] * qH[m.face[i].V1(j)])<0) { const Point3f &p0 = m.face[i].V0(j)->cP(); const Point3f &p1 = m.face[i].V1(j)->cP(); const Point3f &n0 = m.face[i].V0(j)->cN(); const Point3f &n1 = m.face[i].V1(j)->cN(); - float q0 = m.face[i].V0(j)->Q(); - float q1 = m.face[i].V1(j)->Q(); + float q0 = qH[m.face[i].V0(j)]; + float q1 = qH[m.face[i].V1(j)]; // printf("Intersection ( %3.2f %3.2f %3.2f )-( %3.2f %3.2f %3.2f )\n",p0[0],p0[1],p0[2],p1[0],p1[1],p1[2]); Point3f pp; Segment3f seg(p0,p1); @@ -168,7 +175,7 @@ bool IntersectionPlaneMeshQuality(TriMeshType & m, Point3f nn =(n0*fabs(q1) + n1*fabs(q0))/fabs(q0-q1); nmVec.push_back(nn); } - if(m.face[i].V(j)->Q()==0) ptVec.push_back(m.face[i].V(j)->cP()); + if(qH[m.face[i].V(j)]==0) ptVec.push_back(m.face[i].V(j)->cP()); } if(ptVec.size()>=2) { @@ -184,6 +191,7 @@ bool IntersectionPlaneMeshQuality(TriMeshType & m, em.edge.back().V(1) = &(*vi); } } + tri::Allocator :: template DeletePerVertexAttribute < ScalarType >(m,qH); return true; }