diff --git a/SurfRoughing.cpp b/SurfRoughing.cpp index 47c4c23..d375abe 100644 --- a/SurfRoughing.cpp +++ b/SurfRoughing.cpp @@ -232,7 +232,7 @@ SurfRoughing::SurfRoughing( void) m_nStatus = MCH_ST_TO_VERIFY ; m_nPaths = 0 ; m_dMaxHelixRad = INFINITO ; - m_dSubStepToler = 2000 * EPS_SMALL ; // proporzionale al raggio utensile o come parametro ??? + m_dSubStepToler = 2000 * EPS_SMALL ; } //---------------------------------------------------------------------------- @@ -1347,6 +1347,7 @@ SurfRoughing::ProcessPath( int nPathId, int nTempId, int nPvId, int nClId) else continue ; // step fuori dal grezzo, passo al successivo + /* *************************** Silhouette **************************** */ // determino la regione da non lavorare e la sottraggo POLYLINEVECTOR vPL ; @@ -1354,14 +1355,17 @@ SurfRoughing::ProcessPath( int nPathId, int nTempId, int nPvId, int nClId) m_pMchMgr->SetLastError( 3024, "Error in SurfRoughing : region not computable") ; return false ; } - // creo la regione piana dalle PolyLine ricavate dalla Silhouette ; + + // creo la regione piana dalle PolyLine ricavate dalla Silhouette SurfFlatRegionByContours SfrMaker ; for ( auto& PL : vPL) { // recupero la curva dalla silhouette + PolyArc PA ; PtrOwner pSilCrv( CreateCurveComposite()) ; - if ( IsNull( pSilCrv) || - ! pSilCrv->FromPolyLine( PL) || - ! SfrMaker.AddCurve( pSilCrv->Clone())) { + if ( IsNull( pSilCrv)) + return false ; + pSilCrv->FromPolyLine( PL) ; + if ( ! SfrMaker.AddCurve( pSilCrv->Clone())) { m_pMchMgr->SetLastError( 3024, "Error in SurfRoughing : region not computable") ; return false ; } @@ -2227,11 +2231,11 @@ SurfRoughing::SimplifyCurve( ICurveComposite* pCompo) const Point3d ptNewStart, ptNewEnd ; // merge per uniformità - if ( pCompoCL->MergeCurves( 100 * EPS_SMALL, 100 * EPS_ANG_SMALL) && + if ( pCompoCL->MergeCurves( 200 * EPS_SMALL, 200 * EPS_ANG_SMALL) && // rimozione Spikes o Curve Z pCompoCL->RemoveSmallDefects( 150 * EPS_SMALL, 2 * ANG_TOL_STD_DEG, true) && // interpolazione mediante linee ed archi - pCompoCL->ApproxWithArcsEx( 100 * EPS_SMALL, ANG_TOL_STD_DEG, LIN_FEA_STD, PA) && + pCompoCL->ApproxWithArcsEx( 150 * EPS_SMALL, ANG_TOL_STD_DEG, LIN_FEA_STD, PA) && pCompoCL->Clear() && pCompoCL->FromPolyArc( PA) && // controllo aggiuntivo sui punti iniziali e finali che siano gli stessi @@ -2359,7 +2363,7 @@ SurfRoughing::CloseOpenEdgesUnderTolerance( ISurfFlatRegion* pSfr, double dToler /* Nei SubSteps capita spesso che ci siano dei lati aperti molto piccoli o delle sequenze di lati Aperti-Chiusi alternati tutti molto corti ( es. Laurana50K). - Chiudo tutti i lati aperti piccoli + Chiudo tutti i tratti aperti piccoli */ // controllo dei parametri @@ -2420,15 +2424,6 @@ SurfRoughing::CloseOpenEdgesUnderTolerance( ISurfFlatRegion* pSfr, double dToler } // -------------------------------------------------------------------- - //for ( int u = 0 ; u < int( vpCrvs.size()) ; ++ u) { - // if ( vpCrvs[u]->GetTempProp() == 0) - // DrawSimpleCompleteCurve( vpCrvs[u], AQUA) ; - // else if ( vpCrvs[u]->GetTempProp() == 1) - // DrawSimpleCompleteCurve( vpCrvs[u], ORANGE) ; - // else - // DrawSimpleCompleteCurve( vpCrvs[u], GREEN) ; - //} - // scorro tutti i tratti aperti e riconcateno il loop PtrOwner pCrvNewLoop( CreateCurveComposite()) ; if ( IsNull( pCrvNewLoop)) @@ -2487,9 +2482,32 @@ SurfRoughing::ChooseCloseOrOpenEdge( ISurfFlatRegion* pSfr, const ISurfFlatRegio return false ; pSfrRef_Offs->Offset( - 50 * EPS_SMALL, ICurve::OFF_FILLET) ; + // salvo le informazioni del loop relativi alla flatRegion di classificazione + struct SurfRef_Info { + bool bIsExternal = true ; + int nInternalLoops = 0 ; + BBox3d bBox ; + PolyLine PL_Loop ; + } ; + vector vSfrRef_info ; + // assegno le info dei Loop della superficie di riferimento + for ( int c = 0 ; c < pSfrRef_Offs->GetChunkCount() ; ++ c) { + for ( int l = 0 ; l < pSfrRef_Offs->GetLoopCount( c) ; ++ l) { + SurfRef_Info mySurfRef_Info ; + mySurfRef_Info.bIsExternal = ( l == 0) ; + if ( mySurfRef_Info.bIsExternal) + mySurfRef_Info.nInternalLoops = pSfrRef_Offs->GetLoopCount( c) - 1 ; + PtrOwner pCrv( pSfrRef_Offs->GetLoop( c, l)) ; + pCrv->ApproxWithLines( 10 * EPS_SMALL, 15, ICurve::APL_STD, mySurfRef_Info.PL_Loop) ; + if ( ! mySurfRef_Info.bIsExternal) + mySurfRef_Info.PL_Loop.Invert() ; + mySurfRef_Info.PL_Loop.GetLocalBBox( mySurfRef_Info.bBox) ; + vSfrRef_info.emplace_back( mySurfRef_Info) ; + } + } + // per ogni curva dei Loop della FlatRegion vengono presi 4 punti di controllo equidistanti. - // " IL LATO E' APERTO <=> TUTTI I PUNTI DI CONTROLLO NON SONO DENTRO AL GREZZO " - // " IL LATO E' APERTO <=> TUTTI I PUNTI DI CONTROLLO DISTANO MENO DI 25 * EPS_SMALL DALLE FACCE " + // " IL LATO E' APERTO <=> TUTTI I PUNTI DI CONTROLLO NON SONO DENTRO A pSfrRef " const int NUM_POINTS = 4 ; // scorro tutti i loop @@ -2512,9 +2530,31 @@ SurfRoughing::ChooseCloseOrOpenEdge( ISurfFlatRegion* pSfr, const ISurfFlatRegio for ( int p = 0 ; p < NUM_POINTS + 1 ; ++ p) { double dPar = ( 1. / ( 1. * NUM_POINTS)) * p ; Point3d ptPar ; - if ( ! pCrv->GetPointD1D2( dPar, ICurve::FROM_PLUS, ptPar) || - ! VerifyExternalPointSfr( ptPar, pSfrRef_Offs, bIsOut)) + if ( ! pCrv->GetPointD1D2( dPar, ICurve::FROM_PLUS, ptPar)) return false ; + // scorro il vettore relativo alla regione di riferimento + bIsOut = true ; + for ( int nI = 0 ; nI < int( vSfrRef_info.size()) ; ++ nI) { + if ( vSfrRef_info[nI].bIsExternal) { // se loop esterno + if ( vSfrRef_info[nI].bBox.Encloses( ptPar)) { // interno al box del loop + if ( IsPointInsidePolyLine( ptPar, vSfrRef_info[nI].PL_Loop, EPS_SMALL)) { // interno al loop vero e proprio + bool bInsideHole = false ; + // verifico se contenuto in un loop interno al loop esterno corrente + int nIntLoops = vSfrRef_info[nI].nInternalLoops ; + for ( int nJ = 0 ; nJ < nIntLoops ; ++ nJ) { + ++ nI ; + if ( vSfrRef_info[nI].bBox.Encloses( ptPar)) { + if ( IsPointInsidePolyLine( ptPar, vSfrRef_info[nI].PL_Loop, EPS_SMALL)) + bInsideHole = true ; + } + } + // se è contenuto nel loop esterno ma non è contenuto in nessuno dei loop interni allora il punto è interno + if ( ! bInsideHole) + bIsOut = false ; + } + } + } + } if ( ! bIsOut) { pSfr->SetCurveTempProp( c, l, u, 0, 0) ; break ; @@ -2600,34 +2640,4 @@ SurfRoughing::VerifyLeadInZigZag( const ICurveComposite* pCompo, const Point3d& if ( ! DistPointCurve( ptPbL, *pCompo).GetDist( dMinDistPb)) return false ; return ( dMinDistPa > 0.5 * m_TParams.m_dDiam + GetOffsR() - 10 * EPS_SMALL && dMinDistPb > 0.5 * m_TParams.m_dDiam + GetOffsR() - 10 * EPS_SMALL) ; -} - -//---------------------------------------------------------------------------- -bool -SurfRoughing::VerifyExternalPointSfr( const Point3d& pt, const ISurfFlatRegion* pSfr, bool& bIsExternal) const -{ - bIsExternal = true ; - // scorro i Chunk - for ( int i = 0 ; i < pSfr->GetChunkCount() ; ++ i) { - // verifico se è contenuto nel loop esterno - PtrOwner pCrv( pSfr->GetLoop( i, 0)) ; - PolyLine PL ; - pCrv->ApproxWithLines( 10 * EPS_SMALL, 15, ICurve::APL_STD, PL) ; - if ( IsPointInsidePolyLine( pt, PL, EPS_SMALL)) { - bool bInsideHole = false ; - // verifico se è contenuto in un loop interno - for ( int j = 1 ; j < pSfr->GetLoopCount( i) ; ++ j) { - PtrOwner pCrv( pSfr->GetLoop( i, j)) ; - pCrv->ApproxWithLines( 10 * EPS_SMALL, 15, ICurve::APL_STD, PL) ; - PL.Invert() ; - if ( IsPointInsidePolyLine( pt, PL, EPS_SMALL)) - bInsideHole = true ; - } - // se è contenuto nel loop esterno ma non è contenuto in nessuno dei loop interni allora il punto è interno - if ( ! bInsideHole) - bIsExternal = false ; - } - } - - return true ; -} +} \ No newline at end of file diff --git a/SurfRoughing.h b/SurfRoughing.h index 6b643a5..88fbd98 100644 --- a/SurfRoughing.h +++ b/SurfRoughing.h @@ -105,7 +105,6 @@ class SurfRoughing : public Machining ICurveComposite* pRCrv) const ; bool VerifyLeadInHelix( const ICurveComposite* pCompo, const Point3d& ptStart, const Point3d& ptCen, double dRad) ; bool VerifyLeadInZigZag( const ICurveComposite* pCompo, const Point3d& ptPa, const Point3d& ptStart, const Point3d& ptPb) const ; - bool VerifyExternalPointSfr( const Point3d& pt, const ISurfFlatRegion* pSfr, bool& bIsExternal) const ; private : double GetSpeed() const