From 1c3d7bf2a6e61dda69fc648bbc3684e4765e146f Mon Sep 17 00:00:00 2001 From: Dario Sassi Date: Tue, 14 Jan 2025 08:45:26 +0100 Subject: [PATCH] EgtGeomKernel : - piccole migliorie alle funzioni ProjectCurveOnSurfTm. --- ProjectCurveSurfTm.cpp | 96 ++++++++++++++++++++---------------------- 1 file changed, 45 insertions(+), 51 deletions(-) diff --git a/ProjectCurveSurfTm.cpp b/ProjectCurveSurfTm.cpp index d04e6ab..ce1682c 100644 --- a/ProjectCurveSurfTm.cpp +++ b/ProjectCurveSurfTm.cpp @@ -139,10 +139,7 @@ ProjectCurveOnSurfTm( const ICurve& crCrv, const ISurfTriMesh& tmSurf, const Vec if ( ! tmSurf.GetTriangle( vIntRes[nI].nT, trTria)) return false ; Vector3d vtN ; - double dU, dV, dW ; - if ( BarycentricCoord( ptInt, trTria, dU, dV, dW)) - vtN = dU * trTria.GetVertexNorm( 0) + dV * trTria.GetVertexNorm( 1) + dW * trTria.GetVertexNorm( 2) ; - if ( ! vtN.Normalize()) + if ( ! CalcNormal( ptInt, trTria, vtN)) vtN = trTria.GetN() ; // aggiungo al vettore dei proiettati vMyPt5ax.emplace_back( ptInt, vtN, dPar, 1) ; @@ -215,10 +212,7 @@ ProjectCurveOnSurfTm( const ICurve& crCrv, const ISurfTriMesh& tmSurf, const IGe if ( ! tmSurf.GetTriangle( vIntRes[nI].nT, trTria)) return false ; Vector3d vtN ; - double dU, dV, dW ; - if ( BarycentricCoord( ptInt, trTria, dU, dV, dW)) - vtN = dU * trTria.GetVertexNorm( 0) + dV * trTria.GetVertexNorm( 1) + dW * trTria.GetVertexNorm( 2) ; - if ( ! vtN.Normalize()) + if ( ! CalcNormal( ptInt, trTria, vtN)) vtN = trTria.GetN() ; // aggiungo al vettore dei proiettati vMyPt5ax.emplace_back( ptInt, vtN, vtLine, dPar, 1) ; @@ -296,10 +290,7 @@ ProjectCurveOnSurfTm( const ICurve& crCrv, const ISurfTriMesh& tmSurf, const ICu if ( ! tmSurf.GetTriangle( vIntRes[nI].nT, trTria)) return false ; Vector3d vtN ; - double dU, dV, dW ; - if ( BarycentricCoord( ptInt, trTria, dU, dV, dW)) - vtN = dU * trTria.GetVertexNorm( 0) + dV * trTria.GetVertexNorm( 1) + dW * trTria.GetVertexNorm( 2) ; - if ( ! vtN.Normalize()) + if ( ! CalcNormal( ptInt, trTria, vtN)) vtN = trTria.GetN() ; // aggiungo al vettore dei proiettati vMyPt5ax.emplace_back( ptInt, vtN, vtLine, dPar, 1) ; @@ -354,48 +345,51 @@ ProjectCurveOnSurfTm( const ICurve& crCrv, const ISurfTriMesh& tmSurf, const ISu Point3d ptMin ; int nTriaMin ; if ( dPS.GetMinDistPoint( ptMin) && dPS.GetMinDistTriaIndex ( nTriaMin)) { - // intersezione della retta di minima distanza con la superficie + // recupero direzione della retta di minima distanza, altrimenti normale alla superficie Vector3d vtLine = ptP - ptMin ; double dLineLen = vtLine.Len() ; - if ( dLineLen > EPS_SMALL) { + if ( dLineLen > EPS_SMALL) vtLine /= dLineLen ; - ILSIVECTOR vIntRes ; - if ( IntersLineSurfTm( ptP, vtLine, dLineLen, tmSurf, vIntRes, false)) { - // cerco la prima intersezione valida a partire dall'ultima (č la pių alta) - int nI = int( vIntRes.size()) - 1 ; - while ( nI >= 0 && abs( vIntRes[nI].dCosDN) < COS_ANG_LIM) - --nI ; - // se trovata - if ( nI >= 0) { - // calcolo il punto - Point3d ptInt ; - if ( vIntRes[nI].nILTT == ILTT_SEGM || vIntRes[nI].nILTT == ILTT_SEGM_ON_EDGE) - ptInt = vIntRes[nI].ptI2 ; - else - ptInt = vIntRes[nI].ptI ; - // calcolo la normale (si calcola smooth, in caso di errore si prende quella del triangolo) - Triangle3dEx trTria ; - if ( ! tmSurf.GetTriangle( vIntRes[nI].nT, trTria)) - return false ; - Vector3d vtN ; - double dU, dV, dW ; - if ( BarycentricCoord( ptInt, trTria, dU, dV, dW)) - vtN = dU * trTria.GetVertexNorm( 0) + dV * trTria.GetVertexNorm( 1) + dW * trTria.GetVertexNorm( 2) ; - if ( ! vtN.Normalize()) - vtN = trTria.GetN() ; - // calcolo la normale della superficie guida - Triangle3dEx trGuide ; - if ( ! tmRef.GetTriangle( nTriaMin, trGuide)) - return false ; - Vector3d vtN2 ; - double dU2, dV2, dW2 ; - if ( BarycentricCoord( ptMin, trGuide, dU2, dV2, dW2)) - vtN2 = dU2 * trGuide.GetVertexNorm( 0) + dV2 * trGuide.GetVertexNorm( 1) + dW2 * trGuide.GetVertexNorm( 2) ; - if ( ! vtN2.Normalize()) - vtN2 = trGuide.GetN() ; - // aggiungo al vettore dei proiettati - vMyPt5ax.emplace_back( ptInt, vtN, vtN2, dPar, 1) ; - } + else { + // calcolo la normale della superficie guida + Triangle3dEx trGuide ; + if ( ! tmRef.GetTriangle( nTriaMin, trGuide)) + return false ; + if ( ! CalcNormal( ptMin, trGuide, vtLine)) + vtLine = trGuide.GetN() ; + dLineLen = 100 ; + } + // intersezione della retta con la superficie + ILSIVECTOR vIntRes ; + if ( IntersLineSurfTm( ptP, vtLine, dLineLen, tmSurf, vIntRes, false)) { + // cerco la prima intersezione valida a partire dall'ultima (č la pių alta) + int nI = int( vIntRes.size()) - 1 ; + while ( nI >= 0 && abs( vIntRes[nI].dCosDN) < COS_ANG_LIM) + --nI ; + // se trovata + if ( nI >= 0) { + // calcolo il punto + Point3d ptInt ; + if ( vIntRes[nI].nILTT == ILTT_SEGM || vIntRes[nI].nILTT == ILTT_SEGM_ON_EDGE) + ptInt = vIntRes[nI].ptI2 ; + else + ptInt = vIntRes[nI].ptI ; + // calcolo la normale (si calcola smooth, in caso di errore si prende quella del triangolo) + Triangle3dEx trTria ; + if ( ! tmSurf.GetTriangle( vIntRes[nI].nT, trTria)) + return false ; + Vector3d vtN ; + if ( ! CalcNormal( ptMin, trTria, vtN)) + vtN = trTria.GetN() ; + // calcolo la normale della superficie guida + Triangle3dEx trGuide ; + if ( ! tmRef.GetTriangle( nTriaMin, trGuide)) + return false ; + Vector3d vtN2 ; + if ( ! CalcNormal( ptMin, trGuide, vtN2)) + vtN2 = trGuide.GetN() ; + // aggiungo al vettore dei proiettati + vMyPt5ax.emplace_back( ptInt, vtN, vtN2, dPar, 1) ; } } }