diff --git a/EgtGeomKernel.rc b/EgtGeomKernel.rc index cc04e89..0aa6c48 100644 Binary files a/EgtGeomKernel.rc and b/EgtGeomKernel.rc differ diff --git a/ProjectCurveSurfTm.cpp b/ProjectCurveSurfTm.cpp index 8eed4df..b61f079 100644 --- a/ProjectCurveSurfTm.cpp +++ b/ProjectCurveSurfTm.cpp @@ -1,7 +1,7 @@ //---------------------------------------------------------------------------- // EgalTech 2023-2023 //---------------------------------------------------------------------------- -// File : ProjectCurveSurfTm.cpp Data : 31.08.23 Versione : 2.5h3 +// File : ProjectCurveSurfTm.cpp Data : 16.11.23 Versione : 2.5kh3 // Contenuto : Implementazione funzioni proiezione curve su superficie Trimesh. // // @@ -13,10 +13,23 @@ //--------------------------- Include ---------------------------------------- #include "stdafx.h" +#include "DistPointLine.h" #include "GeoConst.h" #include "/EgtDev/Include/EGkIntersLineSurfTm.h" #include "/EgtDev/Include/EGkProjectCurveSurfTm.h" +//---------------------------------------------------------------------------- +static bool +PointsInTolerance( const PNT5AXVECTOR& vPt5ax, int nPrec, int nCurr, int nNext, double dSqTol) +{ + for ( int i = nPrec + 1 ; i < nCurr ; ++ i) { + double dSqDist ; + if ( ! DistPointLine( vPt5ax[i].ptP, vPt5ax[nPrec].ptP, vPt5ax[nNext].ptP).GetSqDist( dSqDist) || dSqDist > dSqTol) + return false ; + } + return true ; +} + //---------------------------------------------------------------------------- bool ProjectCurveOnSurfTm( const ICurve& crCrv, const ISurfTriMesh& tmSurf, const Vector3d& vtDir, double dLinTol, @@ -26,7 +39,7 @@ ProjectCurveOnSurfTm( const ICurve& crCrv, const ISurfTriMesh& tmSurf, const Vec PolyLine PL ; if ( ! crCrv.ApproxWithLines( dLinTol, ANG_TOL_STD_DEG, ICurve::APL_STD, PL)) return false ; - const double MAX_SEG_LEN = 10 ; + const double MAX_SEG_LEN = 1 ; if ( ! PL.AdjustForMaxSegmentLen( MAX_SEG_LEN)) return false ; @@ -36,8 +49,9 @@ ProjectCurveOnSurfTm( const ICurve& crCrv, const ISurfTriMesh& tmSurf, const Vec return false ; IntersParLinesSurfTm intPLSTM( frRefLine, tmSurf) ; - // Riservo spazio nel vettore risultato - vPt5ax.reserve( PL.GetPointNbr()) ; + // Vettore locale dei punti risultanti + PNT5AXVECTOR vMyPt5ax ; + vMyPt5ax.reserve( PL.GetPointNbr()) ; // proietto i punti della polilinea sulla superficie double dU ; @@ -57,10 +71,52 @@ ProjectCurveOnSurfTm( const ICurve& crCrv, const ISurfTriMesh& tmSurf, const Vec Triangle3d trTria ; if ( ! tmSurf.GetTriangle( vIntRes[nI].nT, trTria)) return false ; - vPt5ax.emplace_back( ptInt, trTria.GetN(), dU, 1) ; + vMyPt5ax.emplace_back( ptInt, trTria.GetN(), dU, 1) ; } bFound = PL.GetNextUPoint( &dU, &ptP) ; } + // rimuovo i punti allineati entro la tolleranza + double dSqTol = dLinTol * dLinTol ; + int nPrec = 0 ; + int nCurr = 1 ; + int nNext = 2 ; + while ( nNext < int( vMyPt5ax.size())) { + bool bRemove = false ; + // distanza del punto corrente dal segmento che unisce gli adiacenti + DistPointLine dPL( vMyPt5ax[nCurr].ptP, vMyPt5ax[nPrec].ptP, vMyPt5ax[nNext].ptP) ; + double dSqDist ; + // se distanza inferiore a tolleranza lineare + if ( dPL.GetSqDist( dSqDist) && dSqDist < dSqTol && PointsInTolerance( vMyPt5ax, nPrec, nCurr, nNext, dSqTol)) { + // verifico se errore angolare inferiore a limite + double dPar ; dPL.GetParamAtMinDistPoint( dPar) ; + Vector3d vtNew = Media( vMyPt5ax[nPrec].vtDir, vMyPt5ax[nNext].vtDir, dPar) ; + if ( vtNew.Normalize() && vtNew * vMyPt5ax[nCurr].vtDir > cos( 2 * DEGTORAD)) + bRemove = true ; + } + // se da eliminare + if ( bRemove) { + // dichiaro da eliminare il punto + vMyPt5ax[nCurr].nFlag = -1 ; + // avanzo con corrente e successivo + nCurr = nNext ; + ++ nNext ; + } + // altrimenti da tenere + else { + // avanzo il terzetto di uno step + nPrec = nCurr ; + nCurr = nNext ; + ++ nNext ; + } + } + + // copio i punti rimasti nel vettore di ritorno + vPt5ax.clear() ; + for ( const auto& Pt5ax : vMyPt5ax) { + if ( Pt5ax.nFlag != -1) + vPt5ax.emplace_back( Pt5ax) ; + } + return true ; }