Changed the intersection plane quality to use an attribute. Renamed to cover the old unstable function and renamed the old one with an OLD suffix

This commit is contained in:
Paolo Cignoni 2012-12-02 14:51:34 +00:00
parent 7540b29cf5
commit d946a6c390
1 changed files with 16 additions and 8 deletions

View File

@ -103,7 +103,7 @@ bool IntersectionPlaneGrid( GridType & grid, Plane3<ScalarType> 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<ScalarType> 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<ScalarType> pl,
EdgeMeshType & em)
{
std::vector<Point3f> ptVec;
std::vector<Point3f> nmVec;
tri::UpdateQuality<TriMeshType>::VertexFromPlane(m,pl);
typename TriMeshType::template PerVertexAttributeHandle < ScalarType > qH =
tri::Allocator<TriMeshType> :: 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;i<m.face.size();i++)
if(!m.face[i].IsD())
{
@ -152,14 +159,14 @@ bool IntersectionPlaneMeshQuality(TriMeshType & m,
nmVec.clear();
for(int j=0;j<3;++j)
{
if((m.face[i].V0(j)->Q() * 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<TriMeshType> :: template DeletePerVertexAttribute < ScalarType >(m,qH);
return true;
}