From 2e26b732088e4fc83c6eea290a2ed9a43d284f8c Mon Sep 17 00:00:00 2001 From: Riccardo Elitropi Date: Mon, 5 May 2025 16:57:20 +0200 Subject: [PATCH] EgtGeomKernel : - in CalcPocketing piccola modifica per la creazione delle curve a ricciolo per aree non svuotate. --- CalcPocketing.cpp | 124 +++++++++++++++++++++++++++++----------------- 1 file changed, 78 insertions(+), 46 deletions(-) diff --git a/CalcPocketing.cpp b/CalcPocketing.cpp index 7d292b9..1760426 100644 --- a/CalcPocketing.cpp +++ b/CalcPocketing.cpp @@ -86,6 +86,8 @@ typedef vector VICRVCOMPOPOVECTOR ; #include "EgtDev/Include/EGkGeoPoint3d.h" #include "EgtDev/Include/EGkGeoVector3d.h" string sPockDebug = "C:\\Temp\\PockDebug.nge" ; + vector VT ; + vector VC ; //---------------------------------------------------------------------------- // Debug Functions //---------------------------------------------------------------------------- @@ -4534,7 +4536,7 @@ ModifyCurveToSmoothed( ICurveComposite* pCrv, const PocketParams& PockParams, do // aggiungo la curva 'tagliata per il raccordo' } - // imposto la proprietà di raccord + // imposto la proprietà di raccordo vCrvArcs[i]->SetTempProp( TEMP_PROP_SMOOTH, 1) ; if ( ! pCrvCO_temp->AddCurve( vCrvArcs[i]->Clone())) // aggiungo l'arco di raccordo return false ; @@ -5093,26 +5095,41 @@ RemoveExtraParts( const ISurfFlatRegion* pSfrUncleared, ICRVCOMPOPOVECTOR& vOffs double dRefDist = INFINITO - 1 ; Point3d ptCloser ; // serve nel caso non bastasse la curva a ricciolo per svuotare il chunk nC-esimo int nFlag ; + bool bFirstOffs = false ; for ( int i = 0 ; i < int( vOffs.size()) ; ++ i) { - // se la curva è di primo Offset, allora la salto + // recupero il punto iniziale della curva Point3d ptCheck ; vOffs[i]->GetStartPoint( ptCheck) ; - bool bSkip = false ; - for ( int j = 0 ; j < int( vOffsFirstCurve.size()) && ! bSkip ; ++ j) { - if ( PockParams.nType == POCKET_SPIRALIN || PockParams.nType == POCKET_SPIRALOUT) - bSkip = ( vOffsFirstCurve[j]->IsPointOn( ptCheck, 100 * EPS_SMALL)) ; - else if ( PockParams.nType == POCKET_CONFORMAL_ZIGZAG) + // nel caso di Conformal, escludo le curve di primo Offset dalla ricerca + if ( PockParams.nType == POCKET_CONFORMAL_ZIGZAG) { + bool bSkip = false ; + for ( int j = 0 ; j < int( vOffsFirstCurve.size()) && ! bSkip ; ++ j) bSkip = ( vOffs[i]->GetTempProp( 0) == 0) ; + if ( bSkip) + continue ; } - if ( bSkip) - continue ; - // se la curva contiene il centroide, allora la salto + // se la curva contiene il centroide, allora la salto; l'idea è che il ricciolo sia esterno + // alla curva int nSide ; + bool bCurrFirstOffs = false ; DistPointCurve DistPtCrv( ptCentroid, *vOffs[i]) ; if ( DistPtCrv.GetSideAtMinDistPoint( EPS_SMALL, Z_AX, nSide)) { + // nel caso Spiral if ( PockParams.nType == POCKET_SPIRALIN || PockParams.nType == POCKET_SPIRALOUT) { - if ( nSide == ( ! PockParams.bInvert ? MDS_LEFT : MDS_RIGHT)) - continue ; + // controllo se la curva in questione è di primo Offset, in questo caso devo determinare + // se MDS_LEFT o MDS_RIGHT + for ( int j = 0 ; j < int( vOffsFirstCurve.size()) && ! bCurrFirstOffs ; ++ j) + bCurrFirstOffs = ( vOffsFirstCurve[j]->IsPointOn( ptCheck, 100 * EPS_SMALL)) ; + // se non è di primo Offset, allora ho già la classificazione MDS_ + if ( ! bCurrFirstOffs) { + if ( nSide == ( ! PockParams.bInvert ? MDS_LEFT : MDS_RIGHT)) + continue ; + } + // se di primo Offset allora non controllo MDS_ + /* NB. Se fosse esterna al loop 0 allora non ha senso, esattamente come se fosse interna alla isole + * La cosa si complica se avessi più Offset, Ma dato che cerco la cura più vicina dovrei + * considerare in automatico le curve di Offset appartenenti al chunk in esame */ } + // nel caso Conformal else if ( PockParams.nType == POCKET_CONFORMAL_ZIGZAG) { if ( nSide == vOffs[i]->GetTempProp( 1)) continue ; @@ -5123,6 +5140,7 @@ RemoveExtraParts( const ISurfFlatRegion* pSfrUncleared, ICRVCOMPOPOVECTOR& vOffs if ( DistPtCrv.GetSqDist( dCurrDist) && dCurrDist < dRefDist) { dRefDist = dCurrDist ; nInd = i ; + bFirstOffs = bCurrFirstOffs ; DistPtCrv.GetMinDistPoint( EPS_SMALL, ptCloser, nFlag) ; } } @@ -5140,7 +5158,13 @@ RemoveExtraParts( const ISurfFlatRegion* pSfrUncleared, ICRVCOMPOPOVECTOR& vOffs continue ; // determino se la curva è di raccordo o meno - bool bIsSmoothCrv = ( PockParams.bSmooth && pCrv->GetTempProp( 1) == TEMP_PROP_SMOOTH) ; + bool bIsSmoothCrv = false ; + // se non di primo Offset allora leggo la proprietà + if ( ! bFirstOffs) + bIsSmoothCrv = ( PockParams.bSmooth && pCrv->GetTempProp( 1) == TEMP_PROP_SMOOTH) ; + else + // controllo se la sottocurva è un raccordo di Offset + bIsSmoothCrv = ( pCrv->GetTempProp( 1) > 0) ; // clono la curva di Offset corrente ( in questo modo non modifico l'originale) PtrOwner pMyOffs( CloneCurveComposite( vOffs[nInd])) ; @@ -5223,7 +5247,6 @@ RemoveExtraParts( const ISurfFlatRegion* pSfrUncleared, ICRVCOMPOPOVECTOR& vOffs else { // definisco il versore entrante ed uscente // definisco il punto di entrata e di uscita ( sono coincidenti) - // definisco il parametro di entrata e di uscita ( sono coincidenti) dURef1 = dURef ; dURef2 = dURef ; if ( ! vOffs[nInd]->GetPointD1D2( dURef1, ICurve::FROM_MINUS, ptMain, &vt1) || @@ -5231,34 +5254,39 @@ RemoveExtraParts( const ISurfFlatRegion* pSfrUncleared, ICRVCOMPOPOVECTOR& vOffs continue ; vt1.Normalize() ; vt2.Normalize() ; } - // se i due vettori sono tra loro paralleli... + // recupero le due direzioni per i Biarchi bool bSameDir = AreSameVectorEpsilon( vt1, vt2, 2 * EPS_SMALL) ; + // se parallele, allora trasformo in una circonferenza if ( bSameDir) { - vt1 = ( ptCentroid + ( PockParams.dSideStep / 4 * vt1)) - ptCloser ; - vt2 = ( ptCentroid - ( PockParams.dSideStep / 4 * vt2)) - ptCloser ; - vt2.Invert() ; + if ( ! CalcBoundedSmoothedLink( ptMain, V_INVALID, ptCentroid, V_INVALID, 0., vOffsFirstCurve, PockParams, pCrvCurl)) + continue ; + Vector3d vtStartCheck ; pCrvCurl->GetStartDir( vtStartCheck) ; + if ( AreOppositeVectorApprox( vtStartCheck, vt1)) + pCrvCurl->Invert() ; } + // se distinte... + else { + // calcolo la direzione tra pt1 e ptCentroid + Vector3d vtDir = ( ptCentroid - ptMain) ; vtDir.Normalize() ; + vtDir.Rotate( Z_AX, ANG_RIGHT) ; + double dAngMain ; bool bDet ; + vt1.GetRotation( vt2, Z_AX, dAngMain, bDet) ; + if ( dAngMain > - EPS_ZERO) + vtDir.Invert() ; + // calcolo i due Biarchi di raccordo + PtrOwner pCrvBiArc1( CreateCurveComposite()) ; + PtrOwner pCrvBiArc2( CreateCurveComposite()) ; + if ( IsNull( pCrvBiArc1) || IsNull( pCrvBiArc2) || + ! CalcBoundedSmoothedLink( ptMain, vt1, ptCentroid, vtDir, bSameDir ? 0. : 0.5, vOffsFirstCurve, PockParams, pCrvBiArc1) || + ! CalcBoundedSmoothedLink( ptCentroid, vtDir, ptMain, vt2, bSameDir ? 0. : 0.5, vOffsFirstCurve, PockParams, pCrvBiArc2)) + continue ; - // calcolo la direzione tra pt1 e ptCentroid - Vector3d vtDir = ( ptCentroid - ptMain) ; vtDir.Normalize() ; - vtDir.Rotate( Z_AX, ANG_RIGHT) ; - double dAngMain ; bool bDet ; - vt1.GetRotation( vt2, Z_AX, dAngMain, bDet) ; - if ( dAngMain > - EPS_ZERO) - vtDir.Invert() ; - // calcolo i due Biarchi di raccordo - PtrOwner pCrvBiArc1( CreateCurveComposite()) ; - PtrOwner pCrvBiArc2( CreateCurveComposite()) ; - if ( IsNull( pCrvBiArc1) || IsNull( pCrvBiArc2) || - ! CalcBoundedSmoothedLink( ptMain, vt1, ptCentroid, vtDir, 0.5, vOffsFirstCurve, PockParams, pCrvBiArc1) || - ! CalcBoundedSmoothedLink( ptCentroid, vtDir, ptMain, vt2, 0.5, vOffsFirstCurve, PockParams, pCrvBiArc2)) - continue ; - - // aggiorno la curva a ricciolo - if ( ! pCrvCurl->AddCurve( Release( pCrvBiArc1)) || - ! pCrvCurl->AddCurve( Release( pCrvBiArc2)) || - ! pCrvCurl->IsValid()) - continue ; + // aggiorno la curva a ricciolo + if ( ! pCrvCurl->AddCurve( Release( pCrvBiArc1)) || + ! pCrvCurl->AddCurve( Release( pCrvBiArc2)) || + ! pCrvCurl->IsValid()) + continue ; + } // controllo se devo raccordarmi con Offset if ( bIsSmoothCrv) @@ -5366,10 +5394,10 @@ RemoveExtraParts( const ISurfFlatRegion* pSfrUncleared, ICRVCOMPOPOVECTOR& vOffs // aggiungo il tratto finale di Offset pCrvTest->AddCurve( ConvertCurveToBasicComposite( pMyOffs->CopyParamRange( dURef2, pMyOffs->GetCurveCount()))) ; // nel caso di direzioni parallele manca uno smusso - if ( bSameDir) { - double dSmoothPar = PockParams.dRad / 8. ; - ModifyCurveToSmoothed( pCrvTest, PockParams, dSmoothPar, dSmoothPar, false) ; - } + //if ( bSameDir) { + // double dSmoothPar = PockParams.dRad / 8. ; + // ModifyCurveToSmoothed( pCrvTest, PockParams, dSmoothPar, dSmoothPar, false) ; + //} // provo a controllare che i punti inzili e finali coincidano, in caso aggiorno il nuovo Offset Point3d ptStart_Old ; vOffs[nInd]->GetStartPoint( ptStart_Old) ; Point3d ptEnd_Old ; vOffs[nInd]->GetEndPoint( ptEnd_Old) ; @@ -5670,6 +5698,7 @@ CalcSpiral( const ISurfFlatRegion* pSrfPock, const PocketParams& PockParams, int return false ; double dOffsPrec = 0. ; + int nCrvFirstOffs = 0 ; while ( nIter < MAX_ITER) { // ricavo la regione piana da VRONI PtrOwner pSfrOffsVR( pSrfAct->CreateOffsetSurf( - dOffs, ICurve::OFF_FILLET)) ; @@ -5692,7 +5721,7 @@ CalcSpiral( const ISurfFlatRegion* pSrfPock, const PocketParams& PockParams, int pSfrOffsVR.Set( pSrfAct->Clone()) ; } - // numero di Chunk attuali ( alla prima iterazione è l'nReg-esimo) + // numero di Chunk e Loops attuali ( alla prima iterazione è l'nReg-esimo) int nChunks = pSfrOffsVR->GetChunkCount() ; for ( int i = 0 ; i < nChunks ; ++ i) { @@ -5722,6 +5751,9 @@ CalcSpiral( const ISurfFlatRegion* pSrfPock, const PocketParams& PockParams, int } } } + // ricavo il numero di curve ottenute di primo Offset + if ( nIter == 0) + nCrvFirstOffs = int( vOffs.size()) ; // controllo se serve un raggio più piccolo di svuotatura bool bSmallRad = ( nIter == 0 ? dOffs < PockParams.dRad + EPS_ZERO : dOffs - dOffsPrec < PockParams.dRad + EPS_ZERO) ; @@ -5777,11 +5809,11 @@ CalcSpiral( const ISurfFlatRegion* pSrfPock, const PocketParams& PockParams, int for ( int i = 0 ; i < int( vOffs.size()) && PockParams.bInvert ; ++ i) vOffs[i]->Invert() ; - // smusso le curve di offset ( ad eccezione della prima; le isole sono automaticamente smussate) + // smusso le curve di offset ( ad eccezione di quelle di primo Offset) ICRVCOMPOPOVECTOR vOffsClosedCurves( vOffs.size()) ; // vettore con tutte le curve di Offset Chiuse double dSmoothPar = PockParams.dRad / 8 ; for ( int i = 0 ; i < int( vOffs.size()) ; ++ i) { - if ( i != 0) + if ( i >= nCrvFirstOffs) ModifyCurveToSmoothed( vOffs[i], PockParams, dSmoothPar, dSmoothPar, false) ; vOffs[i]->MergeCurves( 10 * EPS_SMALL, 10 * EPS_ANG_SMALL, true, true) ; vOffsClosedCurves[i].Set( vOffs[i]->Clone()) ; @@ -5807,7 +5839,7 @@ CalcSpiral( const ISurfFlatRegion* pSrfPock, const PocketParams& PockParams, int // controllo eventuali parti non svuotate ( e setto la Feed degli Offset e dei Link)... PtrOwner pSfrUncleared( CreateSurfFlatRegion()) ; if ( GetUnclearedRegionAndSetFeed( vOffsFirstCurve, vOffs, vLinks, vCrvOrigChunkLoops[0], PockParams, pSfrUncleared)) { - // Modifico i percorsi + // modifico i percorsi if ( ! RemoveExtraParts( pSfrUncleared, vOffs, vOffsFirstCurve, PockParams)) return false ; }