CHANGE to the VERY USED PointDistanceBase, the basic functor used to find the closest point to a face in all the grids.
It has a bug that could return a nan in some degnerate case where an almost null face has different vertices but the squared distance between them could be zero. Now it should handle also these cases.
This commit is contained in:
parent
b57a747441
commit
f58551601a
|
@ -319,22 +319,26 @@ namespace vcg {
|
||||||
assert((f.cN().SquaredNorm() ==0) || (f.cN().SquaredNorm() > 0.9999 && f.cN().SquaredNorm()<1.0001)); // if you get this assert you have forgot to make a UpdateNormals::PerFaceNormalized(m)
|
assert((f.cN().SquaredNorm() ==0) || (f.cN().SquaredNorm() > 0.9999 && f.cN().SquaredNorm()<1.0001)); // if you get this assert you have forgot to make a UpdateNormals::PerFaceNormalized(m)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(f.cN()==Point3<ScalarType>(0,0,0)) // to correctly manage the case of degenerate triangles we consider them as segments.
|
if(f.cN()==Point3<ScalarType>(0,0,0)) // to correctly manage the case of degenerate triangles we consider them as segments.
|
||||||
{
|
{
|
||||||
Box3<ScalarType> bb;
|
Box3<ScalarType> bb;
|
||||||
f.GetBBox(bb);
|
f.GetBBox(bb);
|
||||||
Segment3<ScalarType> degenTri(bb.min,bb.max);
|
Segment3<ScalarType> degenTri(bb.min,bb.max);
|
||||||
//Point3<ScalarType> closest= ClosestPoint( degenTri, q );
|
Point3<ScalarType> closest;
|
||||||
//ScalarType d = Distance(closest, q);
|
ScalarType d;
|
||||||
Point3<ScalarType> closest;
|
if(bb.Diag()>0)
|
||||||
ScalarType d;
|
vcg::SegmentPointDistance<ScalarType>(degenTri,q,closest,d);
|
||||||
vcg::SegmentPointDistance<ScalarType>(degenTri,q,closest,d);
|
else // very degenerate triangle (just a point)
|
||||||
if( d>dist || d<-dist ) // Risultato peggiore: niente di fatto
|
{
|
||||||
return false;
|
closest = bb.min;
|
||||||
dist=d;
|
d=Distance(q,closest);
|
||||||
p=closest;
|
}
|
||||||
return true;
|
if( d>dist) return false;
|
||||||
}
|
dist=d;
|
||||||
|
p=closest;
|
||||||
|
assert(!math::IsNAN(dist));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
Plane3<ScalarType> fPlane;
|
Plane3<ScalarType> fPlane;
|
||||||
fPlane.Init(f.cP(0),f.cN());
|
fPlane.Init(f.cP(0),f.cN());
|
||||||
|
|
Loading…
Reference in New Issue