diff --git a/Trimming.cpp b/Trimming.cpp index ea7dd6a..f8c0f99 100644 --- a/Trimming.cpp +++ b/Trimming.cpp @@ -304,9 +304,9 @@ ApproxBorder( ICurveComposite& CrvCompo, double dLinTol, double dAngTol) SaveGeoObj( VT, VC, "C:\\Temp\\RawEdge.nge") ; #endif - // Dalla Curva Grezza, analizzo i suoi estremi e calcolo le Patch + // Dalla Curva Grezza, recupero i suoi punti grezzi e le sue Patch PolyLine PL ; - if ( ! CrvCompo.ApproxWithLines( dLinTol, dAngTol, ICurve::APL_SPECIAL, PL)) + if ( ! CrvCompo.ApproxWithLines( EPS_SMALL, EPS_ANG_SMALL, ICurve::APL_SPECIAL, PL)) return false ; POLYLINEVECTOR vPL ; if ( ! GetPointSetByAngTol( PL, dAngTol, vPL)) @@ -371,7 +371,7 @@ ApproxBorder( ICurveComposite& CrvCompo, double dLinTol, double dAngTol) //----------------------------------------------------------------------------- // ---------------------------------------------------------------------------- -// Funzione per controllare e sistemare le curve di bordo di una riagata Bezier +// Funzione per controllare e sistemare le curve di bordo di una rigata Bezier static bool ManageRuledBorders( ICurveComposite* pCompoEdge1, ICurveComposite* pCompoEdge2) { @@ -3572,8 +3572,9 @@ GetTrimmingFinalBorders( ICRVCOMPOPOVECTOR& vCompoBezierEdges, double dLinTol, d // Funzione per ricavare i bordi a partire da un insieme di superfici; questi vengono // calcolati mediante analisi delle normali lungo il bordo delle Patches di Surfs bool -GetTrimmingFinalBorders( CISURFPVECTOR& vpSurf, const SELVECTOR& vSurfFaces, double dLinTol, - double dAngTol, double dThick, ICRVCOMPOPOVECTOR& vCompoBezierEdges) +GetTrimmingFinalBorders( CISURFPVECTOR& vpSurf, const SELVECTOR& vSurfFaces, double dSurfLinTol, + double dSurfAngTol, double dLinTol, double dAngTol, double dThick, + ICRVCOMPOPOVECTOR& vCompoBezierEdges) { // Pulizia dei parametri di ritorno vCompoBezierEdges.clear() ; @@ -3595,7 +3596,7 @@ GetTrimmingFinalBorders( CISURFPVECTOR& vpSurf, const SELVECTOR& vSurfFaces, dou // Controllo sulla tolleranza angolare double dMyAngTol = Clamp( dAngTol, 1., 45.) ; - // Recupero la superficie TriMesh complessiva [migliorabile] + // Recupero la superficie TriMesh complessiva PtrOwner pStm( nullptr) ; if ( int( vpSurf.size()) == 1) { const ISurf* pSurf = vpSurf[0] ; @@ -3607,7 +3608,7 @@ GetTrimmingFinalBorders( CISURFPVECTOR& vpSurf, const SELVECTOR& vSurfFaces, dou else if ( nType == SRF_BEZIER) { const ISurfBezier* pSurfBz = GetSurfBezier( pSurf) ; if ( pSurfBz != nullptr) - pStm.Set( CloneBasicSurfTriMesh( pSurfBz->GetApproxSurf( dMyLinTol))) ; + pStm.Set( CloneBasicSurfTriMesh( pSurfBz->GetApproxSurf( dSurfLinTol))) ; } } else { @@ -3622,7 +3623,7 @@ GetTrimmingFinalBorders( CISURFPVECTOR& vpSurf, const SELVECTOR& vSurfFaces, dou const ISurfBezier* pSrfBz = GetSurfBezier( pSurf) ; if ( pSrfBz == nullptr) return false ; - PtrOwner pStmTmp( pSrfBz->GetApproxSurf( dMyLinTol)) ; + PtrOwner pStmTmp( pSrfBz->GetApproxSurf( dSurfLinTol)) ; if ( ! IsNull( pStmTmp) && pStmTmp->IsValid()) mySoup.AddSurfTriMesh( *pStmTmp) ; } @@ -3660,8 +3661,12 @@ GetTrimmingFinalBorders( CISURFPVECTOR& vpSurf, const SELVECTOR& vSurfFaces, dou erase_if( vCompoBezierEdges, []( ICurveComposite* pBezierEdge) { return ( pBezierEdge == nullptr || ! pBezierEdge->IsValid() || pBezierEdge->GetCurveCount() == 0) ; }) ; - for ( int i = 0 ; i < ssize( vCompoBezierEdges) - 1 ; i += 2) + for ( int i = 0 ; i < ssize( vCompoBezierEdges) - 1 ; i += 2) { ManageRuledBorders( vCompoBezierEdges[i], vCompoBezierEdges[i+1]) ; + // Essendo l'Offset fatto in negativo, entrambe le curve vanno invertite + vCompoBezierEdges[i]->Invert() ; + vCompoBezierEdges[i+1]->Invert() ; + } return true ; } @@ -3729,8 +3734,6 @@ GetTrimmingSurfBzSyncPoints( const ICurve* pCrvEdge1, const ICurve* pCrvEdge2, // Verifica validità delle curve per la creazione della Bezier rigata PtrOwner pCompoEdge1( ConvertCurveToComposite( pCrvEdge1->Clone())) ; PtrOwner pCompoEdge2( ConvertCurveToComposite( pCrvEdge2->Clone())) ; - if ( ! ManageRuledBorders( pCompoEdge1, pCompoEdge2)) - return false ; vSyncPoints.clear() ; // Controllo sulla tolleranza lineare @@ -4152,25 +4155,41 @@ GetTrimmingAdjSurfs( const CISURFPVECTOR& vSurf, const CISURFPVECTOR& vOtherSurf BIPNTVECTOR vPtAPtB ; vPtAPtB.reserve( MAX_POINTS + 1) ; CurveComposite& currCompoPatch = vSurfPatches[nSurf].CompoPathces[nCurrPatch] ; CurveComposite& otherCompoPatch = vSurfPatches[nOtherSurf].CompoPathces[nOtherPatch] ; - double dLen = 0.; - currCompoPatch.GetLength( dLen) ; - for ( int i = 0 ; bTangent && i <= MAX_POINTS ; ++ i) { - double dU = 0. ; - currCompoPatch.GetParamAtLength( ( dLen / MAX_POINTS) * i, dU) ; - Point3d ptCurr ; - currCompoPatch.GetPointD1D2( dU, ICurve::FROM_MINUS, ptCurr) ; - Point3d ptOther ; - int nFlag = 0 ; - DistPointCurve( ptCurr, otherCompoPatch).GetMinDistPoint( 0., ptOther, nFlag) ; - // Recupero le due normali sulle curva patch campionate - Vector3d vtNCurr = V_INVALID, vtNOther = V_INVALID ; - if ( ! GetNormalAtPoint( pCurrSurf, ptCurr, vtNCurr) || - ! GetNormalAtPoint( pOtherSurf, ptOther, vtNOther)) - return false ; - bTangent = ( vtNCurr * vtNOther > cos( ( dFaceAngTol - EPS_ANG_SMALL) * DEGTORAD)) ; + bTangent = ( currCompoPatch.IsValid() && otherCompoPatch.IsValid()) ; + if ( bTangent) { + double dLen = 0.; + currCompoPatch.GetLength( dLen) ; + for ( int i = 0 ; bTangent && i <= MAX_POINTS ; ++ i) { + double dU = 0. ; + currCompoPatch.GetParamAtLength( ( dLen / MAX_POINTS) * i, dU) ; + Point3d ptCurr ; + currCompoPatch.GetPointD1D2( dU, ICurve::FROM_MINUS, ptCurr) ; + Point3d ptOther ; + int nFlag = 0 ; + if ( ! DistPointCurve( ptCurr, otherCompoPatch).GetMinDistPoint( 0., ptOther, nFlag)) + bTangent = false ; + // Recupero le due normali sulle curva patch campionate + Vector3d vtNCurr = V_INVALID, vtNOther = V_INVALID ; + if ( ! GetNormalAtPoint( pCurrSurf, ptCurr, vtNCurr) || + ! GetNormalAtPoint( pOtherSurf, ptOther, vtNOther)) + return false ; + bTangent = ( vtNCurr * vtNOther > cos( ( dFaceAngTol - EPS_ANG_SMALL) * DEGTORAD)) ; + } } // Se superficie in tangenza, aggiorno i parametri if ( bTangent) { + #if DEBUG_SIMPLE_PATCHES + VC.clear() ; VT.clear() ; + VT.emplace_back( pCurrSurf->Clone()) ; + VC.emplace_back( LIME) ; + VT.emplace_back( pOtherSurf->Clone()) ; + VC.emplace_back( GREEN) ; + VT.emplace_back( currCompoPatch.Clone()) ; + VC.emplace_back( RED) ; + VT.emplace_back( otherCompoPatch.Clone()) ; + VC.emplace_back( BLUE) ; + SaveGeoObj( VT, VC, "C:\\Temp\\Test.nge") ; + #endif vSurfToCheck.emplace_back( nOtherSurf) ; nextPatch.bErase = true ; if ( nOtherSurf >= int( vSurf.size()) &&