mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: Making nearestPointClassify query for triangle.
This is to access the face/edge/point status of the nearest at the same time to ensure a consistent result. Using getVolumeType query in distanceSurface, not simple normal dot-product comparison, fails on edges.
This commit is contained in:
@ -79,21 +79,6 @@ class triangle
|
|||||||
|
|
||||||
PointRef a_, b_, c_;
|
PointRef a_, b_, c_;
|
||||||
|
|
||||||
// Private Member Functions
|
|
||||||
|
|
||||||
//- Fast distance to triangle calculation. From
|
|
||||||
// "Distance Between Point and Trangle in 3D"
|
|
||||||
// David Eberly, Magic Software Inc. Aug. 2002.
|
|
||||||
// Works on function Q giving distance to point and tries to
|
|
||||||
// minimize this.
|
|
||||||
static pointHit nearestPoint
|
|
||||||
(
|
|
||||||
const Point& baseVertex,
|
|
||||||
const vector& E0,
|
|
||||||
const vector& E1,
|
|
||||||
const point& P
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -202,24 +187,27 @@ public:
|
|||||||
const scalar tol = 0.0
|
const scalar tol = 0.0
|
||||||
) const;
|
) const;
|
||||||
|
|
||||||
//- Return nearest point to p on triangle
|
//- Find the nearest point to p on the triangle and classify it:
|
||||||
inline pointHit nearestPoint
|
// + near point (nearType=POINT, nearLabel=0, 1, 2)
|
||||||
(
|
// + near edge (nearType=EDGE, nearLabel=0, 1, 2)
|
||||||
const point& p
|
|
||||||
) const;
|
|
||||||
|
|
||||||
//- Classify point in triangle plane w.r.t. triangle edges.
|
|
||||||
// - inside (true returned)/outside (false returned)
|
|
||||||
// - near point (nearType=POINT, nearLabel=0, 1, 2)
|
|
||||||
// - near edge (nearType=EDGE, nearLabel=0, 1, 2)
|
|
||||||
// Note: edges are counted from starting
|
// Note: edges are counted from starting
|
||||||
// vertex so e.g. edge 2 is from f[2] to f[0]
|
// vertex so e.g. edge 2 is from f[2] to f[0]
|
||||||
// tol is fraction to account for truncation error. Is only used
|
pointHit nearestPointClassify
|
||||||
// when comparing normalized (0..1) numbers.
|
(
|
||||||
|
const point& p,
|
||||||
|
label& nearType,
|
||||||
|
label& nearLabel
|
||||||
|
) const;
|
||||||
|
|
||||||
|
//- Return nearest point to p on triangle
|
||||||
|
inline pointHit nearestPoint(const point& p) const;
|
||||||
|
|
||||||
|
//- Classify nearest point to p in triangle plane
|
||||||
|
// w.r.t. triangle edges and points. Returns inside
|
||||||
|
// (true)/outside (false).
|
||||||
bool classify
|
bool classify
|
||||||
(
|
(
|
||||||
const point& p,
|
const point& p,
|
||||||
const scalar tol,
|
|
||||||
label& nearType,
|
label& nearType,
|
||||||
label& nearLabel
|
label& nearLabel
|
||||||
) const;
|
) const;
|
||||||
|
|||||||
@ -32,158 +32,6 @@ License
|
|||||||
namespace Foam
|
namespace Foam
|
||||||
{
|
{
|
||||||
|
|
||||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
|
||||||
|
|
||||||
template<class Point, class PointRef>
|
|
||||||
pointHit triangle<Point, PointRef>::nearestPoint
|
|
||||||
(
|
|
||||||
const Point& baseVertex,
|
|
||||||
const vector& E0,
|
|
||||||
const vector& E1,
|
|
||||||
const point& P
|
|
||||||
)
|
|
||||||
{
|
|
||||||
// Distance vector
|
|
||||||
const vector D(baseVertex - P);
|
|
||||||
|
|
||||||
// Some geometrical factors
|
|
||||||
const scalar a = E0 & E0;
|
|
||||||
const scalar b = E0 & E1;
|
|
||||||
const scalar c = E1 & E1;
|
|
||||||
|
|
||||||
// Precalculate distance factors
|
|
||||||
const scalar d = E0 & D;
|
|
||||||
const scalar e = E1 & D;
|
|
||||||
const scalar f = D & D;
|
|
||||||
|
|
||||||
// Do classification
|
|
||||||
const scalar det = a*c - b*b;
|
|
||||||
scalar s = b*e - c*d;
|
|
||||||
scalar t = b*d - a*e;
|
|
||||||
|
|
||||||
bool inside = false;
|
|
||||||
|
|
||||||
if (s+t < det)
|
|
||||||
{
|
|
||||||
if (s < 0)
|
|
||||||
{
|
|
||||||
if (t < 0)
|
|
||||||
{
|
|
||||||
// Region 4
|
|
||||||
if (e > 0)
|
|
||||||
{
|
|
||||||
// min on edge t = 0
|
|
||||||
t = 0;
|
|
||||||
s = (d >= 0 ? 0 : (-d >= a ? 1 : -d/a));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// min on edge s=0
|
|
||||||
s = 0;
|
|
||||||
t = (e >= 0 ? 0 : (-e >= c ? 1 : -e/c));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Region 3. Min on edge s = 0
|
|
||||||
s = 0;
|
|
||||||
t = (e >= 0 ? 0 : (-e >= c ? 1 : -e/c));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (t < 0)
|
|
||||||
{
|
|
||||||
// Region 5
|
|
||||||
t = 0;
|
|
||||||
s = (d >= 0 ? 0 : (-d >= a ? 1 : -d/a));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Region 0
|
|
||||||
const scalar invDet = 1/det;
|
|
||||||
s *= invDet;
|
|
||||||
t *= invDet;
|
|
||||||
|
|
||||||
inside = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (s < 0)
|
|
||||||
{
|
|
||||||
// Region 2
|
|
||||||
const scalar tmp0 = b + d;
|
|
||||||
const scalar tmp1 = c + e;
|
|
||||||
if (tmp1 > tmp0)
|
|
||||||
{
|
|
||||||
// min on edge s+t=1
|
|
||||||
const scalar numer = tmp1 - tmp0;
|
|
||||||
const scalar denom = a-2*b+c;
|
|
||||||
s = (numer >= denom ? 1 : numer/denom);
|
|
||||||
t = 1 - s;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// min on edge s=0
|
|
||||||
s = 0;
|
|
||||||
t = (tmp1 <= 0 ? 1 : (e >= 0 ? 0 : - e/c));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (t < 0)
|
|
||||||
{
|
|
||||||
// Region 6
|
|
||||||
const scalar tmp0 = b + d;
|
|
||||||
const scalar tmp1 = c + e;
|
|
||||||
if (tmp1 > tmp0)
|
|
||||||
{
|
|
||||||
// min on edge s+t=1
|
|
||||||
const scalar numer = tmp1 - tmp0;
|
|
||||||
const scalar denom = a-2*b+c;
|
|
||||||
s = (numer >= denom ? 1 : numer/denom);
|
|
||||||
t = 1 - s;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// min on edge t=0
|
|
||||||
t = 0;
|
|
||||||
s = (tmp1 <= 0 ? 1 : (d >= 0 ? 0 : - d/a));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Region 1
|
|
||||||
const scalar numer = c+e-(b+d);
|
|
||||||
if (numer <= 0)
|
|
||||||
{
|
|
||||||
s = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
const scalar denom = a-2*b+c;
|
|
||||||
s = (numer >= denom ? 1 : numer/denom);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
t = 1 - s;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Calculate distance.
|
|
||||||
// Note: Foam::mag used since truncation error causes negative distances
|
|
||||||
// with points very close to one of the triangle vertices.
|
|
||||||
// (Up to -2.77556e-14 seen). Could use +SMALL but that not large enough.
|
|
||||||
|
|
||||||
return pointHit
|
|
||||||
(
|
|
||||||
inside,
|
|
||||||
baseVertex + s*E0 + t*E1,
|
|
||||||
Foam::sqrt
|
|
||||||
(
|
|
||||||
Foam::mag(a*s*s + 2*b*s*t + c*t*t + 2*d*s + 2*e*t + f)
|
|
||||||
),
|
|
||||||
!inside
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
template<class Point, class PointRef>
|
template<class Point, class PointRef>
|
||||||
@ -247,7 +95,7 @@ inline Point triangle<Point, PointRef>::centre() const
|
|||||||
template<class Point, class PointRef>
|
template<class Point, class PointRef>
|
||||||
inline scalar triangle<Point, PointRef>::mag() const
|
inline scalar triangle<Point, PointRef>::mag() const
|
||||||
{
|
{
|
||||||
return ::Foam::mag(normal());
|
return Foam::mag(normal());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -536,7 +384,7 @@ inline pointHit triangle<Point, PointRef>::ray
|
|||||||
inter.setMiss(eligible);
|
inter.setMiss(eligible);
|
||||||
|
|
||||||
// The miss point is the nearest point on the triangle
|
// The miss point is the nearest point on the triangle
|
||||||
inter.setPoint(nearestPoint(a_, E0, E1, p).rawPoint());
|
inter.setPoint(nearestPoint(p).rawPoint());
|
||||||
|
|
||||||
// The distance to the miss is the distance between the
|
// The distance to the miss is the distance between the
|
||||||
// original point and plane of intersection
|
// original point and plane of intersection
|
||||||
@ -633,18 +481,130 @@ inline pointHit triangle<Point, PointRef>::intersection
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class Point, class PointRef>
|
||||||
|
pointHit triangle<Point, PointRef>::nearestPointClassify
|
||||||
|
(
|
||||||
|
const point& p,
|
||||||
|
label& nearType,
|
||||||
|
label& nearLabel
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
// Adapted from:
|
||||||
|
// Real-time collision detection, Christer Ericson, 2005, 136-142
|
||||||
|
|
||||||
|
// Check if P in vertex region outside A
|
||||||
|
vector ab = b_ - a_;
|
||||||
|
vector ac = c_ - a_;
|
||||||
|
vector ap = p - a_;
|
||||||
|
|
||||||
|
scalar d1 = ab & ap;
|
||||||
|
scalar d2 = ac & ap;
|
||||||
|
|
||||||
|
if (d1 <= 0.0 && d2 <= 0.0)
|
||||||
|
{
|
||||||
|
// barycentric coordinates (1, 0, 0)
|
||||||
|
|
||||||
|
nearType = POINT;
|
||||||
|
nearLabel = 0;
|
||||||
|
return pointHit(false, a_, Foam::mag(a_ - p), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if P in vertex region outside B
|
||||||
|
vector bp = p - b_;
|
||||||
|
scalar d3 = ab & bp;
|
||||||
|
scalar d4 = ac & bp;
|
||||||
|
|
||||||
|
if (d3 >= 0.0 && d4 <= d3)
|
||||||
|
{
|
||||||
|
// barycentric coordinates (0, 1, 0)
|
||||||
|
|
||||||
|
nearType = POINT;
|
||||||
|
nearLabel = 1;
|
||||||
|
return pointHit(false, b_, Foam::mag(b_ - p), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if P in edge region of AB, if so return projection of P onto AB
|
||||||
|
scalar vc = d1*d4 - d3*d2;
|
||||||
|
|
||||||
|
if (vc <= 0.0 && d1 >= 0.0 && d3 <= 0.0)
|
||||||
|
{
|
||||||
|
// barycentric coordinates (1-v, v, 0)
|
||||||
|
scalar v = d1/(d1 - d3);
|
||||||
|
|
||||||
|
point nearPt = a_ + v*ab;
|
||||||
|
nearType = EDGE;
|
||||||
|
nearLabel = 0;
|
||||||
|
return pointHit(false, nearPt, Foam::mag(nearPt - p), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if P in vertex region outside C
|
||||||
|
vector cp = p - c_;
|
||||||
|
scalar d5 = ab & cp;
|
||||||
|
scalar d6 = ac & cp;
|
||||||
|
|
||||||
|
if (d6 >= 0.0 && d5 <= d6)
|
||||||
|
{
|
||||||
|
// barycentric coordinates (0, 0, 1)
|
||||||
|
|
||||||
|
nearType = POINT;
|
||||||
|
nearLabel = 2;
|
||||||
|
return pointHit(false, c_, Foam::mag(c_ - p), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if P in edge region of AC, if so return projection of P onto AC
|
||||||
|
scalar vb = d5*d2 - d1*d6;
|
||||||
|
|
||||||
|
if (vb <= 0.0 && d2 >= 0.0 && d6 <= 0.0)
|
||||||
|
{
|
||||||
|
// barycentric coordinates (1-w, 0, w)
|
||||||
|
scalar w = d2/(d2 - d6);
|
||||||
|
|
||||||
|
point nearPt = a_ + w*ac;
|
||||||
|
nearType = EDGE;
|
||||||
|
nearLabel = 2;
|
||||||
|
return pointHit(false, nearPt, Foam::mag(nearPt - p), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if P in edge region of BC, if so return projection of P onto BC
|
||||||
|
scalar va = d3*d6 - d5*d4;
|
||||||
|
|
||||||
|
if (va <= 0.0 && (d4 - d3) >= 0.0 && (d5 - d6) >= 0.0)
|
||||||
|
{
|
||||||
|
// barycentric coordinates (0, 1-w, w)
|
||||||
|
scalar w = (d4 - d3)/((d4 - d3) + (d5 - d6));
|
||||||
|
|
||||||
|
point nearPt = b_ + w*(c_ - b_);
|
||||||
|
nearType = EDGE;
|
||||||
|
nearLabel = 1;
|
||||||
|
return pointHit(false, nearPt, Foam::mag(nearPt - p), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// P inside face region. Compute Q through its barycentric
|
||||||
|
// coordinates (u, v, w)
|
||||||
|
scalar denom = 1.0/(va + vb + vc);
|
||||||
|
scalar v = vb * denom;
|
||||||
|
scalar w = vc * denom;
|
||||||
|
|
||||||
|
// = u*a + v*b + w*c, u = va*denom = 1.0 - v - w
|
||||||
|
|
||||||
|
point nearPt = a_ + ab*v + ac*w;
|
||||||
|
nearType = NONE,
|
||||||
|
nearLabel = -1;
|
||||||
|
return pointHit(true, nearPt, Foam::mag(nearPt - p), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
template<class Point, class PointRef>
|
template<class Point, class PointRef>
|
||||||
inline pointHit triangle<Point, PointRef>::nearestPoint
|
inline pointHit triangle<Point, PointRef>::nearestPoint
|
||||||
(
|
(
|
||||||
const point& p
|
const point& p
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
// Express triangle in terms of baseVertex (point a_) and
|
// Dummy labels
|
||||||
// two edge vectors
|
label nearType = -1;
|
||||||
vector E0 = b_ - a_;
|
label nearLabel = -1;
|
||||||
vector E1 = c_ - a_;
|
|
||||||
|
|
||||||
return nearestPoint(a_, E0, E1, p);
|
return nearestPointClassify(p, nearType, nearLabel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -652,158 +612,12 @@ template<class Point, class PointRef>
|
|||||||
inline bool triangle<Point, PointRef>::classify
|
inline bool triangle<Point, PointRef>::classify
|
||||||
(
|
(
|
||||||
const point& p,
|
const point& p,
|
||||||
const scalar tol,
|
|
||||||
label& nearType,
|
label& nearType,
|
||||||
label& nearLabel
|
label& nearLabel
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
const vector E0 = b_ - a_;
|
return nearestPointClassify(p, nearType, nearLabel).hit();
|
||||||
const vector E1 = c_ - a_;
|
|
||||||
const vector n = 0.5*(E0 ^ E1);
|
|
||||||
|
|
||||||
// Get largest component of normal
|
|
||||||
scalar magX = Foam::mag(n.x());
|
|
||||||
scalar magY = Foam::mag(n.y());
|
|
||||||
scalar magZ = Foam::mag(n.z());
|
|
||||||
|
|
||||||
label i0 = -1;
|
|
||||||
if ((magX >= magY) && (magX >= magZ))
|
|
||||||
{
|
|
||||||
i0 = 0;
|
|
||||||
}
|
}
|
||||||
else if ((magY >= magX) && (magY >= magZ))
|
|
||||||
{
|
|
||||||
i0 = 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
i0 = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get other components
|
|
||||||
label i1 = (i0 + 1) % 3;
|
|
||||||
label i2 = (i1 + 1) % 3;
|
|
||||||
|
|
||||||
|
|
||||||
scalar u1 = E0[i1];
|
|
||||||
scalar v1 = E0[i2];
|
|
||||||
|
|
||||||
scalar u2 = E1[i1];
|
|
||||||
scalar v2 = E1[i2];
|
|
||||||
|
|
||||||
scalar det = v2*u1 - u2*v1;
|
|
||||||
|
|
||||||
scalar u0 = p[i1] - a_[i1];
|
|
||||||
scalar v0 = p[i2] - a_[i2];
|
|
||||||
|
|
||||||
scalar alpha = 0;
|
|
||||||
scalar beta = 0;
|
|
||||||
|
|
||||||
bool hit = false;
|
|
||||||
|
|
||||||
if (Foam::mag(u1) < ROOTVSMALL)
|
|
||||||
{
|
|
||||||
beta = u0/u2;
|
|
||||||
|
|
||||||
alpha = (v0 - beta*v2)/v1;
|
|
||||||
|
|
||||||
hit = ((alpha >= 0) && ((alpha + beta) <= 1));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
beta = (v0*u1 - u0*v1)/det;
|
|
||||||
|
|
||||||
alpha = (u0 - beta*u2)/u1;
|
|
||||||
|
|
||||||
hit = ((alpha >= 0) && ((alpha + beta) <= 1));
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Now alpha, beta are the coordinates in the triangle local coordinate
|
|
||||||
// system E0, E1
|
|
||||||
//
|
|
||||||
|
|
||||||
//Pout<< "alpha:" << alpha << endl;
|
|
||||||
//Pout<< "beta:" << beta << endl;
|
|
||||||
//Pout<< "hit:" << hit << endl;
|
|
||||||
//Pout<< "tol:" << tol << endl;
|
|
||||||
|
|
||||||
if (hit)
|
|
||||||
{
|
|
||||||
// alpha,beta might get negative due to precision errors
|
|
||||||
alpha = max(0.0, min(1.0, alpha));
|
|
||||||
beta = max(0.0, min(1.0, beta));
|
|
||||||
}
|
|
||||||
|
|
||||||
nearType = NONE;
|
|
||||||
nearLabel = -1;
|
|
||||||
|
|
||||||
if (Foam::mag(alpha+beta-1) <= tol)
|
|
||||||
{
|
|
||||||
// On edge between vert 1-2 (=edge 1)
|
|
||||||
|
|
||||||
if (Foam::mag(alpha) <= tol)
|
|
||||||
{
|
|
||||||
nearType = POINT;
|
|
||||||
nearLabel = 2;
|
|
||||||
}
|
|
||||||
else if (Foam::mag(beta) <= tol)
|
|
||||||
{
|
|
||||||
nearType = POINT;
|
|
||||||
nearLabel = 1;
|
|
||||||
}
|
|
||||||
else if ((alpha >= 0) && (alpha <= 1) && (beta >= 0) && (beta <= 1))
|
|
||||||
{
|
|
||||||
nearType = EDGE;
|
|
||||||
nearLabel = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (Foam::mag(alpha) <= tol)
|
|
||||||
{
|
|
||||||
// On edge between vert 2-0 (=edge 2)
|
|
||||||
|
|
||||||
if (Foam::mag(beta) <= tol)
|
|
||||||
{
|
|
||||||
nearType = POINT;
|
|
||||||
nearLabel = 0;
|
|
||||||
}
|
|
||||||
else if (Foam::mag(beta-1) <= tol)
|
|
||||||
{
|
|
||||||
nearType = POINT;
|
|
||||||
nearLabel = 2;
|
|
||||||
}
|
|
||||||
else if ((beta >= 0) && (beta <= 1))
|
|
||||||
{
|
|
||||||
nearType = EDGE;
|
|
||||||
nearLabel = 2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (Foam::mag(beta) <= tol)
|
|
||||||
{
|
|
||||||
// On edge between vert 0-1 (= edge 0)
|
|
||||||
|
|
||||||
if (Foam::mag(alpha) <= tol)
|
|
||||||
{
|
|
||||||
nearType = POINT;
|
|
||||||
nearLabel = 0;
|
|
||||||
}
|
|
||||||
else if (Foam::mag(alpha-1) <= tol)
|
|
||||||
{
|
|
||||||
nearType = POINT;
|
|
||||||
nearLabel = 1;
|
|
||||||
}
|
|
||||||
else if ((alpha >= 0) && (alpha <= 1))
|
|
||||||
{
|
|
||||||
nearType = EDGE;
|
|
||||||
nearLabel = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return hit;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
|
||||||
|
|||||||
@ -35,145 +35,145 @@ defineTypeNameAndDebug(Foam::treeDataTriSurface, 0);
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||||
|
|
||||||
// Fast distance to triangle calculation. From
|
// // Fast distance to triangle calculation. From
|
||||||
// "Distance Between Point and Trangle in 3D"
|
// // "Distance Between Point and Triangle in 3D"
|
||||||
// David Eberly, Magic Software Inc. Aug. 2003.
|
// // David Eberly, Magic Software Inc. Aug. 2003.
|
||||||
// Works on function Q giving distance to point and tries to minimize this.
|
// // Works on function Q giving distance to point and tries to minimize this.
|
||||||
Foam::scalar Foam::treeDataTriSurface::nearestCoords
|
// Foam::scalar Foam::treeDataTriSurface::nearestCoords
|
||||||
(
|
// (
|
||||||
const point& base,
|
// const point& base,
|
||||||
const point& E0,
|
// const point& E0,
|
||||||
const point& E1,
|
// const point& E1,
|
||||||
const scalar a,
|
// const scalar a,
|
||||||
const scalar b,
|
// const scalar b,
|
||||||
const scalar c,
|
// const scalar c,
|
||||||
const point& P,
|
// const point& P,
|
||||||
scalar& s,
|
// scalar& s,
|
||||||
scalar& t
|
// scalar& t
|
||||||
)
|
// )
|
||||||
{
|
// {
|
||||||
// distance vector
|
// // distance vector
|
||||||
const vector D(base - P);
|
// const vector D(base - P);
|
||||||
|
|
||||||
// Precalculate distance factors.
|
// // Precalculate distance factors.
|
||||||
const scalar d = E0 & D;
|
// const scalar d = E0 & D;
|
||||||
const scalar e = E1 & D;
|
// const scalar e = E1 & D;
|
||||||
|
|
||||||
// Do classification
|
// // Do classification
|
||||||
const scalar det = a*c - b*b;
|
// const scalar det = a*c - b*b;
|
||||||
|
|
||||||
s = b*e - c*d;
|
// s = b*e - c*d;
|
||||||
t = b*d - a*e;
|
// t = b*d - a*e;
|
||||||
|
|
||||||
if (s+t < det)
|
// if (s+t < det)
|
||||||
{
|
// {
|
||||||
if (s < 0)
|
// if (s < 0)
|
||||||
{
|
// {
|
||||||
if (t < 0)
|
// if (t < 0)
|
||||||
{
|
// {
|
||||||
//region 4
|
// //region 4
|
||||||
if (e > 0)
|
// if (e > 0)
|
||||||
{
|
// {
|
||||||
//min on edge t = 0
|
// //min on edge t = 0
|
||||||
t = 0;
|
// t = 0;
|
||||||
s = (d >= 0 ? 0 : (-d >= a ? 1 : -d/a));
|
// s = (d >= 0 ? 0 : (-d >= a ? 1 : -d/a));
|
||||||
}
|
// }
|
||||||
else
|
// else
|
||||||
{
|
// {
|
||||||
//min on edge s=0
|
// //min on edge s=0
|
||||||
s = 0;
|
// s = 0;
|
||||||
t = (e >= 0 ? 0 : (-e >= c ? 1 : -e/c));
|
// t = (e >= 0 ? 0 : (-e >= c ? 1 : -e/c));
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
else
|
// else
|
||||||
{
|
// {
|
||||||
//region 3. Min on edge s = 0
|
// //region 3. Min on edge s = 0
|
||||||
s = 0;
|
// s = 0;
|
||||||
t = (e >= 0 ? 0 : (-e >= c ? 1 : -e/c));
|
// t = (e >= 0 ? 0 : (-e >= c ? 1 : -e/c));
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
else if (t < 0)
|
// else if (t < 0)
|
||||||
{
|
// {
|
||||||
//region 5
|
// //region 5
|
||||||
t = 0;
|
// t = 0;
|
||||||
s = (d >= 0 ? 0 : (-d >= a ? 1 : -d/a));
|
// s = (d >= 0 ? 0 : (-d >= a ? 1 : -d/a));
|
||||||
}
|
// }
|
||||||
else
|
// else
|
||||||
{
|
// {
|
||||||
//region 0
|
// //region 0
|
||||||
const scalar invDet = 1/det;
|
// const scalar invDet = 1/det;
|
||||||
s *= invDet;
|
// s *= invDet;
|
||||||
t *= invDet;
|
// t *= invDet;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
else
|
// else
|
||||||
{
|
// {
|
||||||
if (s < 0)
|
// if (s < 0)
|
||||||
{
|
// {
|
||||||
//region 2
|
// //region 2
|
||||||
const scalar tmp0 = b + d;
|
// const scalar tmp0 = b + d;
|
||||||
const scalar tmp1 = c + e;
|
// const scalar tmp1 = c + e;
|
||||||
if (tmp1 > tmp0)
|
// if (tmp1 > tmp0)
|
||||||
{
|
// {
|
||||||
//min on edge s+t=1
|
// //min on edge s+t=1
|
||||||
const scalar numer = tmp1 - tmp0;
|
// const scalar numer = tmp1 - tmp0;
|
||||||
const scalar denom = a-2*b+c;
|
// const scalar denom = a-2*b+c;
|
||||||
s = (numer >= denom ? 1 : numer/denom);
|
// s = (numer >= denom ? 1 : numer/denom);
|
||||||
t = 1 - s;
|
// t = 1 - s;
|
||||||
}
|
// }
|
||||||
else
|
// else
|
||||||
{
|
// {
|
||||||
//min on edge s=0
|
// //min on edge s=0
|
||||||
s = 0;
|
// s = 0;
|
||||||
t = (tmp1 <= 0 ? 1 : (e >= 0 ? 0 : - e/c));
|
// t = (tmp1 <= 0 ? 1 : (e >= 0 ? 0 : - e/c));
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
else if (t < 0)
|
// else if (t < 0)
|
||||||
{
|
// {
|
||||||
//region 6
|
// //region 6
|
||||||
const scalar tmp0 = b + d;
|
// const scalar tmp0 = b + d;
|
||||||
const scalar tmp1 = c + e;
|
// const scalar tmp1 = c + e;
|
||||||
if (tmp1 > tmp0)
|
// if (tmp1 > tmp0)
|
||||||
{
|
// {
|
||||||
//min on edge s+t=1
|
// //min on edge s+t=1
|
||||||
const scalar numer = tmp1 - tmp0;
|
// const scalar numer = tmp1 - tmp0;
|
||||||
const scalar denom = a-2*b+c;
|
// const scalar denom = a-2*b+c;
|
||||||
s = (numer >= denom ? 1 : numer/denom);
|
// s = (numer >= denom ? 1 : numer/denom);
|
||||||
t = 1 - s;
|
// t = 1 - s;
|
||||||
}
|
// }
|
||||||
else
|
// else
|
||||||
{
|
// {
|
||||||
//min on edge t=0
|
// //min on edge t=0
|
||||||
t = 0;
|
// t = 0;
|
||||||
s = (tmp1 <= 0 ? 1 : (d >= 0 ? 0 : - d/a));
|
// s = (tmp1 <= 0 ? 1 : (d >= 0 ? 0 : - d/a));
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
else
|
// else
|
||||||
{
|
// {
|
||||||
//region 1
|
// //region 1
|
||||||
const scalar numer = c+e-(b+d);
|
// const scalar numer = c+e-(b+d);
|
||||||
if (numer <= 0)
|
// if (numer <= 0)
|
||||||
{
|
// {
|
||||||
s = 0;
|
// s = 0;
|
||||||
}
|
// }
|
||||||
else
|
// else
|
||||||
{
|
// {
|
||||||
const scalar denom = a-2*b+c;
|
// const scalar denom = a-2*b+c;
|
||||||
s = (numer >= denom ? 1 : numer/denom);
|
// s = (numer >= denom ? 1 : numer/denom);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
t = 1 - s;
|
// t = 1 - s;
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
// Calculate distance.
|
// // Calculate distance.
|
||||||
// Note: abs should not be needed but truncation error causes problems
|
// // Note: abs should not be needed but truncation error causes problems
|
||||||
// with points very close to one of the triangle vertices.
|
// // with points very close to one of the triangle vertices.
|
||||||
// (seen up to -9e-15). Alternatively add some small value.
|
// // (seen up to -9e-15). Alternatively add some small value.
|
||||||
|
|
||||||
const scalar f = D & D;
|
// const scalar f = D & D;
|
||||||
return Foam::mag(a*s*s + 2*b*s*t + c*t*t + 2*d*s + 2*e*t + f);
|
// return Foam::mag(a*s*s + 2*b*s*t + c*t*t + 2*d*s + 2*e*t + f);
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||||
@ -234,9 +234,7 @@ Foam::label Foam::treeDataTriSurface::getVolumeType
|
|||||||
(
|
(
|
||||||
surface_,
|
surface_,
|
||||||
sample,
|
sample,
|
||||||
pHit.index(),
|
pHit.index()
|
||||||
pHit.hitPoint(),
|
|
||||||
indexedOctree<treeDataTriSurface>::perturbTol()
|
|
||||||
);
|
);
|
||||||
|
|
||||||
if (t == triSurfaceTools::UNKNOWN)
|
if (t == triSurfaceTools::UNKNOWN)
|
||||||
@ -353,39 +351,43 @@ void Foam::treeDataTriSurface::findNearest
|
|||||||
// )
|
// )
|
||||||
//)
|
//)
|
||||||
{
|
{
|
||||||
// Get spanning vectors of triangle
|
// // Get spanning vectors of triangle
|
||||||
vector base(p1);
|
// vector base(p1);
|
||||||
vector E0(p0 - p1);
|
// vector E0(p0 - p1);
|
||||||
vector E1(p2 - p1);
|
// vector E1(p2 - p1);
|
||||||
|
|
||||||
scalar a(E0& E0);
|
// scalar a(E0& E0);
|
||||||
scalar b(E0& E1);
|
// scalar b(E0& E1);
|
||||||
scalar c(E1& E1);
|
// scalar c(E1& E1);
|
||||||
|
|
||||||
// Get nearest point in s,t coordinates (s is along E0, t is along
|
// // Get nearest point in s,t coordinates (s is along E0, t is along
|
||||||
// E1)
|
// // E1)
|
||||||
scalar s;
|
// scalar s;
|
||||||
scalar t;
|
// scalar t;
|
||||||
|
|
||||||
scalar distSqr = nearestCoords
|
// scalar distSqr = nearestCoords
|
||||||
(
|
// (
|
||||||
base,
|
// base,
|
||||||
E0,
|
// E0,
|
||||||
E1,
|
// E1,
|
||||||
a,
|
// a,
|
||||||
b,
|
// b,
|
||||||
c,
|
// c,
|
||||||
sample,
|
// sample,
|
||||||
|
|
||||||
s,
|
// s,
|
||||||
t
|
// t
|
||||||
);
|
// );
|
||||||
|
|
||||||
|
pointHit pHit = triPointRef(p0, p1, p2).nearestPoint(sample);
|
||||||
|
|
||||||
|
scalar distSqr = sqr(pHit.distance());
|
||||||
|
|
||||||
if (distSqr < nearestDistSqr)
|
if (distSqr < nearestDistSqr)
|
||||||
{
|
{
|
||||||
nearestDistSqr = distSqr;
|
nearestDistSqr = distSqr;
|
||||||
minIndex = index;
|
minIndex = index;
|
||||||
nearestPoint = base + s*E0 + t*E1;
|
nearestPoint = pHit.rawPoint();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -60,20 +60,20 @@ class treeDataTriSurface
|
|||||||
|
|
||||||
// Private Member Functions
|
// Private Member Functions
|
||||||
|
|
||||||
//- fast triangle nearest point calculation. Returns point in E0, E1
|
// //- fast triangle nearest point calculation. Returns point in E0, E1
|
||||||
// coordinate system: base + s*E0 + t*E1
|
// // coordinate system: base + s*E0 + t*E1
|
||||||
static scalar nearestCoords
|
// static scalar nearestCoords
|
||||||
(
|
// (
|
||||||
const point& base,
|
// const point& base,
|
||||||
const point& E0,
|
// const point& E0,
|
||||||
const point& E1,
|
// const point& E1,
|
||||||
const scalar a,
|
// const scalar a,
|
||||||
const scalar b,
|
// const scalar b,
|
||||||
const scalar c,
|
// const scalar c,
|
||||||
const point& P,
|
// const point& P,
|
||||||
scalar& s,
|
// scalar& s,
|
||||||
scalar& t
|
// scalar& t
|
||||||
);
|
// );
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|||||||
@ -430,10 +430,7 @@ bool Foam::edgeIntersections::offsetPerturb
|
|||||||
|
|
||||||
point ctr = tri.centre();
|
point ctr = tri.centre();
|
||||||
|
|
||||||
// Get measure for tolerance.
|
tri.classify(pHit.hitPoint(), nearType, nearLabel);
|
||||||
scalar tolDim = 0.001*mag(tri.a() - ctr);
|
|
||||||
|
|
||||||
tri.classify(pHit.hitPoint(), tolDim, nearType, nearLabel);
|
|
||||||
|
|
||||||
if (nearType == triPointRef::POINT || nearType == triPointRef::EDGE)
|
if (nearType == triPointRef::POINT || nearType == triPointRef::EDGE)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -315,7 +315,7 @@ void Foam::surfaceIntersection::classifyHit
|
|||||||
surf2Pts[f2[0]],
|
surf2Pts[f2[0]],
|
||||||
surf2Pts[f2[1]],
|
surf2Pts[f2[1]],
|
||||||
surf2Pts[f2[2]]
|
surf2Pts[f2[2]]
|
||||||
).classify(pHit.hitPoint(), tolDim, nearType, nearLabel);
|
).classify(pHit.hitPoint(), nearType, nearLabel);
|
||||||
|
|
||||||
// Classify points on edge of surface1
|
// Classify points on edge of surface1
|
||||||
label edgeEnd =
|
label edgeEnd =
|
||||||
|
|||||||
@ -43,7 +43,7 @@ Foam::scalar Foam::octreeDataTriSurface::tol(1E-6);
|
|||||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||||
|
|
||||||
// Fast distance to triangle calculation. From
|
// Fast distance to triangle calculation. From
|
||||||
// "Distance Between Point and Trangle in 3D"
|
// "Distance Between Point and Triangle in 3D"
|
||||||
// David Eberly, Magic Software Inc. Aug. 2003.
|
// David Eberly, Magic Software Inc. Aug. 2003.
|
||||||
// Works on function Q giving distance to point and tries to minimize this.
|
// Works on function Q giving distance to point and tries to minimize this.
|
||||||
void Foam::octreeDataTriSurface::nearestCoords
|
void Foam::octreeDataTriSurface::nearestCoords
|
||||||
|
|||||||
@ -234,9 +234,7 @@ void Foam::orientedSurface::propagateOrientation
|
|||||||
(
|
(
|
||||||
s,
|
s,
|
||||||
samplePoint,
|
samplePoint,
|
||||||
nearestFaceI,
|
nearestFaceI
|
||||||
nearestPt,
|
|
||||||
10*SMALL
|
|
||||||
);
|
);
|
||||||
|
|
||||||
if (side == triSurfaceTools::UNKNOWN)
|
if (side == triSurfaceTools::UNKNOWN)
|
||||||
|
|||||||
@ -2121,12 +2121,13 @@ Foam::vector Foam::triSurfaceTools::surfaceNormal
|
|||||||
|
|
||||||
label nearType;
|
label nearType;
|
||||||
label nearLabel;
|
label nearLabel;
|
||||||
|
|
||||||
triPointRef
|
triPointRef
|
||||||
(
|
(
|
||||||
points[f[0]],
|
points[f[0]],
|
||||||
points[f[1]],
|
points[f[1]],
|
||||||
points[f[2]]
|
points[f[2]]
|
||||||
).classify(nearestPt, 1E-6, nearType, nearLabel);
|
).classify(nearestPt, nearType, nearLabel);
|
||||||
|
|
||||||
if (nearType == triPointRef::NONE)
|
if (nearType == triPointRef::NONE)
|
||||||
{
|
{
|
||||||
@ -2199,28 +2200,60 @@ Foam::triSurfaceTools::sideType Foam::triSurfaceTools::surfaceSide
|
|||||||
(
|
(
|
||||||
const triSurface& surf,
|
const triSurface& surf,
|
||||||
const point& sample,
|
const point& sample,
|
||||||
const label nearestFaceI, // nearest face
|
const label nearestFaceI
|
||||||
const point& nearestPoint, // nearest point on nearest face
|
|
||||||
const scalar tol
|
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
const labelledTri& f = surf[nearestFaceI];
|
const labelledTri& f = surf[nearestFaceI];
|
||||||
const pointField& points = surf.points();
|
const pointField& points = surf.points();
|
||||||
|
|
||||||
// Find where point is on triangle. Note tolerance needed. Is relative
|
// Find where point is on triangle.
|
||||||
// one (used in comparing normalized [0..1] triangle coordinates).
|
|
||||||
label nearType, nearLabel;
|
label nearType, nearLabel;
|
||||||
triPointRef
|
|
||||||
|
pointHit pHit = triPointRef
|
||||||
(
|
(
|
||||||
points[f[0]],
|
points[f[0]],
|
||||||
points[f[1]],
|
points[f[1]],
|
||||||
points[f[2]]
|
points[f[2]]
|
||||||
).classify(nearestPoint, tol, nearType, nearLabel);
|
).nearestPointClassify(sample, nearType, nearLabel);
|
||||||
|
|
||||||
|
const point& nearestPoint(pHit.rawPoint());
|
||||||
|
|
||||||
if (nearType == triPointRef::NONE)
|
if (nearType == triPointRef::NONE)
|
||||||
{
|
{
|
||||||
// Nearest to face interior. Use faceNormal to determine side
|
// Nearest to face interior. Use faceNormal to determine side
|
||||||
|
<<<<<<< HEAD
|
||||||
scalar c = (sample - nearestPoint) & surf.faceNormals()[nearestFaceI];
|
scalar c = (sample - nearestPoint) & surf.faceNormals()[nearestFaceI];
|
||||||
|
=======
|
||||||
|
scalar c = sampleNearestVec & surf.faceNormals()[nearestFaceI];
|
||||||
|
|
||||||
|
// If the sample is essentially on the face, do not check for
|
||||||
|
// it being perpendicular.
|
||||||
|
|
||||||
|
if (magSampleNearestVec > SMALL)
|
||||||
|
{
|
||||||
|
c /= magSampleNearestVec*mag(surf.faceNormals()[nearestFaceI]);
|
||||||
|
|
||||||
|
if (mag(c) < 0.99)
|
||||||
|
{
|
||||||
|
FatalErrorIn("triSurfaceTools::surfaceSide")
|
||||||
|
<< "nearestPoint identified as being on triangle face "
|
||||||
|
<< "but vector from nearestPoint to sample is not "
|
||||||
|
<< "perpendicular to the normal." << nl
|
||||||
|
<< "sample: " << sample << nl
|
||||||
|
<< "nearestPoint: " << nearestPoint << nl
|
||||||
|
<< "sample - nearestPoint: " << sample - nearestPoint << nl
|
||||||
|
<< "normal: " << surf.faceNormals()[nearestFaceI] << nl
|
||||||
|
<< "mag(sample - nearestPoint): "
|
||||||
|
<< mag(sample - nearestPoint) << nl
|
||||||
|
<< "normalised dot product: " << c << nl
|
||||||
|
<< "triangle vertices: " << nl
|
||||||
|
<< " " << points[f[0]] << nl
|
||||||
|
<< " " << points[f[1]] << nl
|
||||||
|
<< " " << points[f[2]] << nl
|
||||||
|
<< abort(FatalError);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
>>>>>>> 0bb6ebd... ENH: Making nearestPointClassify query for triangle.
|
||||||
|
|
||||||
if (c > 0)
|
if (c > 0)
|
||||||
{
|
{
|
||||||
@ -2240,26 +2273,26 @@ Foam::triSurfaceTools::sideType Foam::triSurfaceTools::surfaceSide
|
|||||||
label edgeI = surf.faceEdges()[nearestFaceI][nearLabel];
|
label edgeI = surf.faceEdges()[nearestFaceI][nearLabel];
|
||||||
|
|
||||||
// if (debug)
|
// if (debug)
|
||||||
//{
|
{
|
||||||
// // Check order of faceEdges same as face vertices.
|
// Check order of faceEdges same as face vertices.
|
||||||
// const edge& e = surf.edges()[edgeI];
|
const edge& e = surf.edges()[edgeI];
|
||||||
// const labelList& meshPoints = surf.meshPoints();
|
const labelList& meshPoints = surf.meshPoints();
|
||||||
// const edge meshEdge(meshPoints[e[0]], meshPoints[e[1]]);
|
const edge meshEdge(meshPoints[e[0]], meshPoints[e[1]]);
|
||||||
//
|
|
||||||
// if
|
if
|
||||||
// (
|
(
|
||||||
// meshEdge
|
meshEdge
|
||||||
// != edge(f[nearLabel], f[f.fcIndex(nearLabel)])
|
!= edge(f[nearLabel], f[f.fcIndex(nearLabel)])
|
||||||
// )
|
)
|
||||||
// {
|
{
|
||||||
// FatalErrorIn("triSurfaceTools::surfaceSide")
|
FatalErrorIn("triSurfaceTools::surfaceSide")
|
||||||
// << "Edge:" << edgeI << " local vertices:" << e
|
<< "Edge:" << edgeI << " local vertices:" << e
|
||||||
// << " mesh vertices:" << meshEdge
|
<< " mesh vertices:" << meshEdge
|
||||||
// << " not at position " << nearLabel
|
<< " not at position " << nearLabel
|
||||||
// << " in face " << f
|
<< " in face " << f
|
||||||
// << abort(FatalError);
|
<< abort(FatalError);
|
||||||
// }
|
}
|
||||||
//}
|
}
|
||||||
|
|
||||||
return edgeSide(surf, sample, nearestPoint, edgeI);
|
return edgeSide(surf, sample, nearestPoint, edgeI);
|
||||||
}
|
}
|
||||||
@ -2717,7 +2750,14 @@ void Foam::triSurfaceTools::calcInterpolationWeights
|
|||||||
|
|
||||||
triPointRef tri(f.tri(points));
|
triPointRef tri(f.tri(points));
|
||||||
|
|
||||||
pointHit nearest = tri.nearestPoint(samplePt);
|
label nearType, nearLabel;
|
||||||
|
|
||||||
|
pointHit nearest = tri.nearestPointClassify
|
||||||
|
(
|
||||||
|
samplePt,
|
||||||
|
nearType,
|
||||||
|
nearLabel
|
||||||
|
);
|
||||||
|
|
||||||
if (nearest.hit())
|
if (nearest.hit())
|
||||||
{
|
{
|
||||||
@ -2741,14 +2781,6 @@ void Foam::triSurfaceTools::calcInterpolationWeights
|
|||||||
minDistance = nearest.distance();
|
minDistance = nearest.distance();
|
||||||
|
|
||||||
// Outside triangle. Store nearest.
|
// Outside triangle. Store nearest.
|
||||||
label nearType, nearLabel;
|
|
||||||
tri.classify
|
|
||||||
(
|
|
||||||
nearest.rawPoint(),
|
|
||||||
1E-6, // relative tolerance
|
|
||||||
nearType,
|
|
||||||
nearLabel
|
|
||||||
);
|
|
||||||
|
|
||||||
if (nearType == triPointRef::POINT)
|
if (nearType == triPointRef::POINT)
|
||||||
{
|
{
|
||||||
@ -2830,7 +2862,6 @@ Foam::surfaceLocation Foam::triSurfaceTools::classify
|
|||||||
triPointRef(s[triI].tri(s.points())).classify
|
triPointRef(s[triI].tri(s.points())).classify
|
||||||
(
|
(
|
||||||
trianglePoint,
|
trianglePoint,
|
||||||
1E-6,
|
|
||||||
elemType,
|
elemType,
|
||||||
index
|
index
|
||||||
);
|
);
|
||||||
|
|||||||
@ -458,9 +458,7 @@ public:
|
|||||||
(
|
(
|
||||||
const triSurface& surf,
|
const triSurface& surf,
|
||||||
const point& sample,
|
const point& sample,
|
||||||
const label nearestFaceI, // nearest face
|
const label nearestFaceI
|
||||||
const point& nearestPt, // nearest point on nearest face
|
|
||||||
const scalar tol // tolerance for nearness test.
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// Triangulation of faces
|
// Triangulation of faces
|
||||||
|
|||||||
@ -89,20 +89,29 @@ void Foam::distanceSurface::createGeometry()
|
|||||||
|
|
||||||
if (signed_)
|
if (signed_)
|
||||||
{
|
{
|
||||||
vectorField normal;
|
List<searchableSurface::volumeType> volType;
|
||||||
surfPtr_().getNormal(nearest, normal);
|
|
||||||
|
|
||||||
forAll(nearest, i)
|
surfPtr_().getVolumeType(cc, volType);
|
||||||
{
|
|
||||||
vector d(cc[i]-nearest[i].hitPoint());
|
|
||||||
|
|
||||||
if ((d&normal[i]) > 0)
|
forAll(volType, i)
|
||||||
{
|
{
|
||||||
fld[i] = Foam::mag(d);
|
searchableSurface::volumeType vT = volType[i];
|
||||||
|
|
||||||
|
if (vT == searchableSurface::OUTSIDE)
|
||||||
|
{
|
||||||
|
fld[i] = Foam::mag(cc[i] - nearest[i].hitPoint());
|
||||||
|
}
|
||||||
|
else if (vT == searchableSurface::INSIDE)
|
||||||
|
{
|
||||||
|
fld[i] = -Foam::mag(cc[i] - nearest[i].hitPoint());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fld[i] = -Foam::mag(d);
|
FatalErrorIn
|
||||||
|
(
|
||||||
|
"void Foam::distanceSurface::createGeometry()"
|
||||||
|
) << "getVolumeType failure, neither INSIDE or OUTSIDE"
|
||||||
|
<< exit(FatalError);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -132,20 +141,30 @@ void Foam::distanceSurface::createGeometry()
|
|||||||
|
|
||||||
if (signed_)
|
if (signed_)
|
||||||
{
|
{
|
||||||
vectorField normal;
|
List<searchableSurface::volumeType> volType;
|
||||||
surfPtr_().getNormal(nearest, normal);
|
|
||||||
|
|
||||||
forAll(nearest, i)
|
surfPtr_().getVolumeType(cc, volType);
|
||||||
{
|
|
||||||
vector d(cc[i]-nearest[i].hitPoint());
|
|
||||||
|
|
||||||
if ((d&normal[i]) > 0)
|
forAll(volType, i)
|
||||||
{
|
{
|
||||||
fld[i] = Foam::mag(d);
|
searchableSurface::volumeType vT = volType[i];
|
||||||
|
|
||||||
|
if (vT == searchableSurface::OUTSIDE)
|
||||||
|
{
|
||||||
|
fld[i] = Foam::mag(cc[i] - nearest[i].hitPoint());
|
||||||
|
}
|
||||||
|
else if (vT == searchableSurface::INSIDE)
|
||||||
|
{
|
||||||
|
fld[i] = -Foam::mag(cc[i] - nearest[i].hitPoint());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fld[i] = -Foam::mag(d);
|
FatalErrorIn
|
||||||
|
(
|
||||||
|
"void Foam::distanceSurface::createGeometry()"
|
||||||
|
) << "getVolumeType failure, "
|
||||||
|
<< "neither INSIDE or OUTSIDE"
|
||||||
|
<< exit(FatalError);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -179,20 +198,31 @@ void Foam::distanceSurface::createGeometry()
|
|||||||
|
|
||||||
if (signed_)
|
if (signed_)
|
||||||
{
|
{
|
||||||
vectorField normal;
|
List<searchableSurface::volumeType> volType;
|
||||||
surfPtr_().getNormal(nearest, normal);
|
|
||||||
|
|
||||||
forAll(nearest, i)
|
surfPtr_().getVolumeType(pts, volType);
|
||||||
{
|
|
||||||
vector d(pts[i]-nearest[i].hitPoint());
|
|
||||||
|
|
||||||
if ((d&normal[i]) > 0)
|
forAll(volType, i)
|
||||||
{
|
{
|
||||||
pointDistance_[i] = Foam::mag(d);
|
searchableSurface::volumeType vT = volType[i];
|
||||||
|
|
||||||
|
if (vT == searchableSurface::OUTSIDE)
|
||||||
|
{
|
||||||
|
pointDistance_[i] =
|
||||||
|
Foam::mag(pts[i] - nearest[i].hitPoint());
|
||||||
|
}
|
||||||
|
else if (vT == searchableSurface::INSIDE)
|
||||||
|
{
|
||||||
|
pointDistance_[i] =
|
||||||
|
-Foam::mag(pts[i] - nearest[i].hitPoint());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
pointDistance_[i] = -Foam::mag(d);
|
FatalErrorIn
|
||||||
|
(
|
||||||
|
"void Foam::distanceSurface::createGeometry()"
|
||||||
|
) << "getVolumeType failure, neither INSIDE or OUTSIDE"
|
||||||
|
<< exit(FatalError);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user