예제 #1
0
Matrix3<Real> ImplicitSurface<Real>::GetHessian (const Vector3<Real>& rkP)
    const
{
    Real fFXX = FXX(rkP);
    Real fFXY = FXY(rkP);
    Real fFXZ = FXZ(rkP);
    Real fFYY = FYY(rkP);
    Real fFYZ = FYZ(rkP);
    Real fFZZ = FZZ(rkP);
    return Matrix3<Real>(fFXX,fFXY,fFXZ,fFXY,fFYY,fFYZ,fFXZ,fFYZ,fFZZ);
}
예제 #2
0
Matrix3<Real> ImplicitSurface<Real>::GetHessian (const Vector3<Real>& pos)
    const
{
    Real fxx = FXX(pos);
    Real fxy = FXY(pos);
    Real fxz = FXZ(pos);
    Real fyy = FYY(pos);
    Real fyz = FYZ(pos);
    Real fzz = FZZ(pos);
    return Matrix3<Real>(fxx, fxy, fxz, fxy, fyy, fyz, fxz, fyz, fzz);
}
예제 #3
0
bool ImplicitSurface<Real>::ComputePrincipalCurvatureInfo (
    const Vector3<Real>& rkP, Real& rfCurv0, Real& rfCurv1,
    Vector3<Real>& rkDir0, Vector3<Real>& rkDir1)
{
    // Principal curvatures and directions for implicitly defined surfaces
    // F(x,y,z) = 0.
    //
    // DF = (Fx,Fy,Fz), L = Length(DF)
    //
    // D^2 F = +-           -+
    //         | Fxx Fxy Fxz |
    //         | Fxy Fyy Fyz |
    //         | Fxz Fyz Fzz |
    //         +-           -+
    //
    // adj(D^2 F) = +-                                                 -+
    //              | Fyy*Fzz-Fyz*Fyz  Fyz*Fxz-Fxy*Fzz  Fxy*Fyz-Fxz*Fyy |
    //              | Fyz*Fxz-Fxy*Fzz  Fxx*Fzz-Fxz*Fxz  Fxy*Fxz-Fxx*Fyz |
    //              | Fxy*Fyz-Fxz*Fyy  Fxy*Fxz-Fxx*Fyz  Fxx*Fyy-Fxy*Fxy |
    //              +-                                                 -+
    //
    // Gaussian curvature = [DF^t adj(D^2 F) DF]/L^4
    // 
    // Mean curvature = 0.5*[trace(D^2 F)/L - (DF^t D^2 F DF)/L^3]

    // first derivatives
    Real fFX = FX(rkP);
    Real fFY = FY(rkP);
    Real fFZ = FZ(rkP);
    Real fL = Math<Real>::Sqrt(fFX*fFX + fFY*fFY + fFZ*fFZ);
    if (fL <= Math<Real>::ZERO_TOLERANCE)
    {
        return false;
    }

    Real fFXFX = fFX*fFX;
    Real fFXFY = fFX*fFY;
    Real fFXFZ = fFX*fFZ;
    Real fFYFY = fFY*fFY;
    Real fFYFZ = fFY*fFZ;
    Real fFZFZ = fFZ*fFZ;

    Real fInvL = ((Real)1.0)/fL;
    Real fInvL2 = fInvL*fInvL;
    Real fInvL3 = fInvL*fInvL2;
    Real fInvL4 = fInvL2*fInvL2;

    // second derivatives
    Real fFXX = FXX(rkP);
    Real fFXY = FXY(rkP);
    Real fFXZ = FXZ(rkP);
    Real fFYY = FYY(rkP);
    Real fFYZ = FYZ(rkP);
    Real fFZZ = FZZ(rkP);

    // mean curvature
    Real fMCurv = ((Real)0.5)*fInvL3*(fFXX*(fFYFY+fFZFZ) + fFYY*(fFXFX+fFZFZ)
        + fFZZ*(fFXFX+fFYFY)
        - ((Real)2.0)*(fFXY*fFXFY+fFXZ*fFXFZ+fFYZ*fFYFZ));

    // Gaussian curvature
    Real fGCurv = fInvL4*(fFXFX*(fFYY*fFZZ-fFYZ*fFYZ)
        + fFYFY*(fFXX*fFZZ-fFXZ*fFXZ) + fFZFZ*(fFXX*fFYY-fFXY*fFXY)
        + ((Real)2.0)*(fFXFY*(fFXZ*fFYZ-fFXY*fFZZ)
        + fFXFZ*(fFXY*fFYZ-fFXZ*fFYY)
        + fFYFZ*(fFXY*fFXZ-fFXX*fFYZ)));

    // solve for principal curvatures
    Real fDiscr = Math<Real>::Sqrt(Math<Real>::FAbs(fMCurv*fMCurv-fGCurv));
    rfCurv0 = fMCurv - fDiscr;
    rfCurv1 = fMCurv + fDiscr;

    Real fM00 = ((-(Real)1.0 + fFXFX*fInvL2)*fFXX)*fInvL + (fFXFY*fFXY)*fInvL3
        + (fFXFZ*fFXZ)*fInvL3;
    Real fM01 = ((-(Real)1.0 + fFXFX*fInvL2)*fFXY)*fInvL + (fFXFY*fFYY)*fInvL3
        + (fFXFZ*fFYZ)*fInvL3;
    Real fM02 = ((-(Real)1.0 + fFXFX*fInvL2)*fFXZ)*fInvL + (fFXFY*fFYZ)*fInvL3
        + (fFXFZ*fFZZ)*fInvL3;
    Real fM10 = (fFXFY*fFXX)*fInvL3 + ((-(Real)1.0 + fFYFY*fInvL2)*fFXY)*fInvL
        + (fFYFZ*fFXZ)*fInvL3;
    Real fM11 = (fFXFY*fFXY)*fInvL3 + ((-(Real)1.0 + fFYFY*fInvL2)*fFYY)*fInvL
        + (fFYFZ*fFYZ)*fInvL3;
    Real fM12 = (fFXFY*fFXZ)*fInvL3 + ((-(Real)1.0 + fFYFY*fInvL2)*fFYZ)*fInvL
        + (fFYFZ*fFZZ)*fInvL3;
    Real fM20 = (fFXFZ*fFXX)*fInvL3 + (fFYFZ*fFXY)*fInvL3 + ((-(Real)1.0
        + fFZFZ*fInvL2)*fFXZ)*fInvL;
    Real fM21 = (fFXFZ*fFXY)*fInvL3 + (fFYFZ*fFYY)*fInvL3 + ((-(Real)1.0
        + fFZFZ*fInvL2)*fFYZ)*fInvL;
    Real fM22 = (fFXFZ*fFXZ)*fInvL3 + (fFYFZ*fFYZ)*fInvL3 + ((-(Real)1.0
        + fFZFZ*fInvL2)*fFZZ)*fInvL;

    // solve for principal directions
    Real fTmp1 = fM00 + rfCurv0;
    Real fTmp2 = fM11 + rfCurv0;
    Real fTmp3 = fM22 + rfCurv0;

    Vector3<Real> akU[3];
    Real afLength[3];

    akU[0].X() = fM01*fM12-fM02*fTmp2;
    akU[0].Y() = fM02*fM10-fM12*fTmp1;
    akU[0].Z() = fTmp1*fTmp2-fM01*fM10;
    afLength[0] = akU[0].Length();

    akU[1].X() = fM01*fTmp3-fM02*fM21;
    akU[1].Y() = fM02*fM20-fTmp1*fTmp3;
    akU[1].Z() = fTmp1*fM21-fM01*fM20;
    afLength[1] = akU[1].Length();

    akU[2].X() = fTmp2*fTmp3-fM12*fM21;
    akU[2].Y() = fM12*fM20-fM10*fTmp3;
    akU[2].Z() = fM10*fM21-fM20*fTmp2;
    afLength[2] = akU[2].Length();

    int iMaxIndex = 0;
    Real fMax = afLength[0];
    if (afLength[1] > fMax)
    {
        iMaxIndex = 1;
        fMax = afLength[1];
    }
    if (afLength[2] > fMax)
    {
        iMaxIndex = 2;
    }

    Real fInvLength = ((Real)1.0)/afLength[iMaxIndex];
    akU[iMaxIndex] *= fInvLength;

    rkDir1 = akU[iMaxIndex];
    rkDir0 = rkDir1.UnitCross(Vector3<Real>(fFX,fFY,fFZ));

    return true;
}
예제 #4
0
bool ImplicitSurface<Real>::ComputePrincipalCurvatureInfo (
    const Vector3<Real>& pos, Real& curv0, Real& curv1, Vector3<Real>& dir0,
    Vector3<Real>& dir1)
{
    // Principal curvatures and directions for implicitly defined surfaces
    // F(x,y,z) = 0.
    //
    // DF = (Fx,Fy,Fz), L = Length(DF)
    //
    // D^2 F = +-           -+
    //         | Fxx Fxy Fxz |
    //         | Fxy Fyy Fyz |
    //         | Fxz Fyz Fzz |
    //         +-           -+
    //
    // adj(D^2 F) = +-                                                 -+
    //              | Fyy*Fzz-Fyz*Fyz  Fyz*Fxz-Fxy*Fzz  Fxy*Fyz-Fxz*Fyy |
    //              | Fyz*Fxz-Fxy*Fzz  Fxx*Fzz-Fxz*Fxz  Fxy*Fxz-Fxx*Fyz |
    //              | Fxy*Fyz-Fxz*Fyy  Fxy*Fxz-Fxx*Fyz  Fxx*Fyy-Fxy*Fxy |
    //              +-                                                 -+
    //
    // Gaussian curvature = [DF^t adj(D^2 F) DF]/L^4
    // 
    // Mean curvature = 0.5*[trace(D^2 F)/L - (DF^t D^2 F DF)/L^3]

    // first derivatives
    Real fx = FX(pos);
    Real fy = FY(pos);
    Real fz = FZ(pos);
    Real fLength = Math<Real>::Sqrt(fx*fx + fy*fy + fz*fz);
    if (fLength <= Math<Real>::ZERO_TOLERANCE)
    {
        return false;
    }

    Real fxfx = fx*fx;
    Real fxfy = fx*fy;
    Real fxfz = fx*fz;
    Real fyfy = fy*fy;
    Real fyfz = fy*fz;
    Real fzfz = fz*fz;

    Real invLength = ((Real)1)/fLength;
    Real invLength2 = invLength*invLength;
    Real invLength3 = invLength*invLength2;
    Real invLength4 = invLength2*invLength2;

    // second derivatives
    Real fxx = FXX(pos);
    Real fxy = FXY(pos);
    Real fxz = FXZ(pos);
    Real fyy = FYY(pos);
    Real fyz = FYZ(pos);
    Real fzz = FZZ(pos);

    // mean curvature
    Real meanCurv = ((Real)0.5)*invLength3*(fxx*(fyfy + fzfz) +
        fyy*(fxfx + fzfz) + fzz*(fxfx + fyfy) - ((Real)2)*(fxy*fxfy + fxz*fxfz +
        fyz*fyfz));

    // Gaussian curvature
    Real gaussCurv = invLength4*(fxfx*(fyy*fzz - fyz*fyz)
        + fyfy*(fxx*fzz - fxz*fxz) + fzfz*(fxx*fyy - fxy*fxy)
        + ((Real)2)*(fxfy*(fxz*fyz - fxy*fzz) + fxfz*(fxy*fyz - fxz*fyy)
        + fyfz*(fxy*fxz - fxx*fyz)));

    // solve for principal curvatures
    Real discr = Math<Real>::Sqrt(Math<Real>::FAbs(meanCurv*meanCurv-gaussCurv));
    curv0 = meanCurv - discr;
    curv1 = meanCurv + discr;

    Real m00 = ((-(Real)1 + fxfx*invLength2)*fxx)*invLength +
        (fxfy*fxy)*invLength3 + (fxfz*fxz)*invLength3;
    Real m01 = ((-(Real)1 + fxfx*invLength2)*fxy)*invLength +
        (fxfy*fyy)*invLength3 + (fxfz*fyz)*invLength3;
    Real m02 = ((-(Real)1 + fxfx*invLength2)*fxz)*invLength +
        (fxfy*fyz)*invLength3 + (fxfz*fzz)*invLength3;
    Real m10 = (fxfy*fxx)*invLength3 +
        ((-(Real)1 + fyfy*invLength2)*fxy)*invLength + (fyfz*fxz)*invLength3;
    Real m11 = (fxfy*fxy)*invLength3 +
        ((-(Real)1 + fyfy*invLength2)*fyy)*invLength + (fyfz*fyz)*invLength3;
    Real m12 = (fxfy*fxz)*invLength3 +
        ((-(Real)1 + fyfy*invLength2)*fyz)*invLength + (fyfz*fzz)*invLength3;
    Real m20 = (fxfz*fxx)*invLength3 + (fyfz*fxy)*invLength3 +
        ((-(Real)1 + fzfz*invLength2)*fxz)*invLength;
    Real m21 = (fxfz*fxy)*invLength3 + (fyfz*fyy)*invLength3 +
        ((-(Real)1 + fzfz*invLength2)*fyz)*invLength;
    Real m22 = (fxfz*fxz)*invLength3 + (fyfz*fyz)*invLength3 +
        ((-(Real)1 + fzfz*invLength2)*fzz)*invLength;

    // solve for principal directions
    Real tmp1 = m00 + curv0;
    Real tmp2 = m11 + curv0;
    Real tmp3 = m22 + curv0;

    Vector3<Real> U[3];
    Real lengths[3];

    U[0].X() = m01*m12-m02*tmp2;
    U[0].Y() = m02*m10-m12*tmp1;
    U[0].Z() = tmp1*tmp2-m01*m10;
    lengths[0] = U[0].Length();

    U[1].X() = m01*tmp3-m02*m21;
    U[1].Y() = m02*m20-tmp1*tmp3;
    U[1].Z() = tmp1*m21-m01*m20;
    lengths[1] = U[1].Length();

    U[2].X() = tmp2*tmp3-m12*m21;
    U[2].Y() = m12*m20-m10*tmp3;
    U[2].Z() = m10*m21-m20*tmp2;
    lengths[2] = U[2].Length();

    int maxIndex = 0;
    Real maxValue = lengths[0];
    if (lengths[1] > maxValue)
    {
        maxIndex = 1;
        maxValue = lengths[1];
    }
    if (lengths[2] > maxValue)
    {
        maxIndex = 2;
    }

    invLength = ((Real)1)/lengths[maxIndex];
    U[maxIndex] *= invLength;

    dir1 = U[maxIndex];
    dir0 = dir1.UnitCross(Vector3<Real>(fx, fy, fz));

    return true;
}