From 4e2df909610ac20a56100ce3b13e4f8ef4129560 Mon Sep 17 00:00:00 2001 From: Riccardo Elitropi Date: Fri, 16 Jun 2023 13:45:33 +0200 Subject: [PATCH] EgtMachKernel : - Isole aperte generate da lati aperti - migliorie alle approssimazioni degli archi. --- Pocketing.cpp | 153 ++++++++++++++++++++++++++++++++------------------ Pocketing.h | 2 +- 2 files changed, 99 insertions(+), 56 deletions(-) diff --git a/Pocketing.cpp b/Pocketing.cpp index de502ff..dc1de0b 100644 --- a/Pocketing.cpp +++ b/Pocketing.cpp @@ -8609,7 +8609,7 @@ Pocketing::GetParamOnOpenSide( const ICurveComposite* pCompo, const ICRVCOMPOPOV //---------------------------------------------------------------------------- bool -Pocketing::AdjustContourWithOpenEdges( ICurveComposite* pCompo, const ICRVCOMPOPOVECTOR& vCrvIsl, +Pocketing::AdjustContourWithOpenEdges( ICurveComposite* pCompo, ICRVCOMPOPOVECTOR& vCrvIsl, double dTool_Diam, double dOffR) { @@ -8659,12 +8659,26 @@ Pocketing::AdjustContourWithOpenEdges( ICurveComposite* pCompo, const ICRVCOMPOP m_pMchMgr->SetLastError( 2412, "Error in Pocketing : Offset not computable") ; return false ; } - vpCrvs[i].Set( OffsCrv.GetLongerCurve()) ; + int nCrv_offs = OffsCrv.GetCurveCount() ; + PtrOwner pCrvlonger( OffsCrv.GetLongerCurve()) ; + while ( ! IsNull( pCrvlonger)) { + if ( pCrvlonger->IsClosed() && nCrv_offs > 1) { + PtrOwner pCrvCompo( CreateCurveComposite()) ; + pCrvCompo->AddCurve( Release( pCrvlonger)) ; + for ( int u = 0 ; u < pCrvCompo->GetCurveCount() ; ++ u) + pCrvCompo->SetCurveTempProp( u, 1, 0) ; + vCrvIsl.emplace_back( pCrvCompo->Clone()) ; + } + else + vpCrvs[i].Set( Release( pCrvlonger)) ; + pCrvlonger.Set( OffsCrv.GetLongerCurve()) ; + } + PtrOwner pCrvRange( CreateCurveComposite()) ; pCrvRange->AddCurve( vpCrvs[i]->Clone()) ; - int W = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pCrvRange->Clone()) ; - m_pGeomDB->SetMaterial( W, WHITE) ; + //int W = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pCrvRange->Clone()) ; + //m_pGeomDB->SetMaterial( W, WHITE) ; for ( int j = 0 ; j < pCrvRange->GetCurveCount() ; ++ j) pCrvRange->SetCurveTempProp( j, 1, 0) ; @@ -8673,8 +8687,8 @@ Pocketing::AdjustContourWithOpenEdges( ICurveComposite* pCompo, const ICRVCOMPOP } } - int green = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pCompo->Clone()) ; - m_pGeomDB->SetMaterial( green, GREEN) ; + //int green = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pCompo->Clone()) ; + //m_pGeomDB->SetMaterial( green, GREEN) ; // clono la pCompo PtrOwner pCompo_clone( CloneCurveComposite( pCompo)) ; @@ -8705,8 +8719,8 @@ Pocketing::AdjustContourWithOpenEdges( ICurveComposite* pCompo, const ICRVCOMPOP AdjustPathOutsideRawForOpenEdges( pCompo_clone, vCrvIsl, pHHHH, ptS, ptE, dRad, dDiam, pCrvNew) ; vpCrvs[i].Set( Release( pCrvNew)) ; vpCrvs[i]->GetStartPoint( ptStart) ; - int BRO = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, vpCrvs[i]->Clone()) ; - m_pGeomDB->SetMaterial( BRO, BROWN) ; + //int BRO = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, vpCrvs[i]->Clone()) ; + //m_pGeomDB->SetMaterial( BRO, BROWN) ; // ----------------------------------------------------------------------------------- // determino la curva ad amo @@ -8723,8 +8737,8 @@ Pocketing::AdjustContourWithOpenEdges( ICurveComposite* pCompo, const ICRVCOMPOP if ( IsNull( pJCrv)) return false ; pJCrv->AddCurve( Release( pCrvArc)) ; - int y = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pJCrv->Clone()) ; - m_pGeomDB->SetMaterial( y, YELLOW) ; + //int y = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pJCrv->Clone()) ; + //m_pGeomDB->SetMaterial( y, YELLOW) ; // assegno alle sue sottocurve la proprietà di curva aperta //for ( int u = 0 ; u < pJCrv->GetCurveCount() ; ++ u) @@ -8773,8 +8787,8 @@ Pocketing::AdjustContourWithOpenEdges( ICurveComposite* pCompo, const ICRVCOMPOP pJCrv->AddLine( ptArc) ;; pJCrv->AddArcTg( ptStart) ; - int a = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pJCrv->Clone()) ; - m_pGeomDB->SetMaterial( a, ORANGE) ; + //int a = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pJCrv->Clone()) ; + //m_pGeomDB->SetMaterial( a, ORANGE) ; // assegno alle sue sottocurve la proprietà di curva aperta for ( int u = 0 ; u < pJCrv->GetCurveCount() ; ++ u) @@ -8787,8 +8801,8 @@ Pocketing::AdjustContourWithOpenEdges( ICurveComposite* pCompo, const ICRVCOMPOP if ( pCompo->GetCurveCount() >= 2) pLCrv->AddCurve( pCompo->GetPrevCurve()->Clone(), false) ; double dUL = pLCrv->GetCurveCount() ; - int A = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pLCrv->Clone()) ; - m_pGeomDB->SetMaterial( A, AQUA) ; + //int A = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pLCrv->Clone()) ; + //m_pGeomDB->SetMaterial( A, AQUA) ; pJCrv->ToLoc( frPocket) ; pLCrv->ToLoc( frPocket) ; @@ -8817,14 +8831,14 @@ Pocketing::AdjustContourWithOpenEdges( ICurveComposite* pCompo, const ICRVCOMPOP // aggiungo la curva pCompo->AddCurve( ::Release( vpCrvs[i]), true, 10 * EPS_SMALL) ; - int p = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pCompo->Clone()) ; - m_pGeomDB->SetMaterial( p, PURPLE) ; + //int p = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pCompo->Clone()) ; + //m_pGeomDB->SetMaterial( p, PURPLE) ; } // non dovrebbe esserci un gap, ma meglio prevenire problemi pCompo->Close() ; - int LI = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pCompo->Clone()) ; - m_pGeomDB->SetMaterial( LI, LIME) ; + //int LI = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pCompo->Clone()) ; + //m_pGeomDB->SetMaterial( LI, LIME) ; return true ; @@ -8849,13 +8863,13 @@ Pocketing::AdjustPathOutsideRawForOpenEdges( const ICurveComposite* pCompo, cons PtrOwner pCompo_Prec( CloneCurveComposite( pCompo)) ; pCompo_Prec->GetParamAtPoint( ptCrvOpenS, dUTrimS) ; pCompo_Prec->TrimEndAtParam( dUTrimS) ; - int B = m_pGeomDB->AddGeoObj(GDB_ID_NULL, GDB_ID_ROOT, pCompo_Prec->Clone()) ; // - m_pGeomDB->SetMaterial( B, BLACK) ; // + //int B = m_pGeomDB->AddGeoObj(GDB_ID_NULL, GDB_ID_ROOT, pCompo_Prec->Clone()) ; // + //m_pGeomDB->SetMaterial( B, BLACK) ; // PtrOwner pCompo_Succ( CloneCurveComposite( pCompo)) ; pCompo_Succ->GetParamAtPoint( ptCrvOpenE, dUTrimE) ; pCompo_Succ->TrimStartAtParam( dUTrimE) ; - int Bl = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pCompo_Succ->Clone()) ; // - m_pGeomDB->SetMaterial( Bl, BLUE) ; // + //int Bl = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pCompo_Succ->Clone()) ; // + //m_pGeomDB->SetMaterial( Bl, BLUE) ; // PtrOwner pCrvOpen( CloneCurveComposite( pCompo)) ; pCrvOpen->TrimStartEndAtParam( dUTrimS, dUTrimE) ; PtrOwner pCompo_noOpenCrv( CloneCurveComposite( pCompo_Succ)) ; @@ -8885,8 +8899,8 @@ Pocketing::AdjustPathOutsideRawForOpenEdges( const ICurveComposite* pCompo, cons PtrOwner pSfrInc( GetSurfFlatRegionFromFatCurve( Release( pCrvOpen_clone), dRad, true, false)) ; if ( IsNull( pSfrInc) || ! pSfrInc->IsValid()) return false ; - int arancione = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pSfrInc->Clone()) ; // - m_pGeomDB->SetMaterial( arancione, ORANGE) ; // + //int arancione = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pSfrInc->Clone()) ; // + //m_pGeomDB->SetMaterial( arancione, ORANGE) ; // // -------------- AGGIORNAMENTO DELLA REGIONE DI INFLUENZA -------------- // creo un vettore con la pCompo senza lato aperto e le isole contenute al suo interno @@ -8950,8 +8964,8 @@ Pocketing::AdjustPathOutsideRawForOpenEdges( const ICurveComposite* pCompo, cons pCrvCurrPartIn->Invert() ; // inversione del tratto interno pCrvExtBorder->AddCurve( Release( pCrvCurrPartIn)) ; // aggiunta del tratto interno - int rrr = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pCrvExtBorder->Clone()) ; - m_pGeomDB->SetMaterial( rrr, RED) ; + //int rrr = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pCrvExtBorder->Clone()) ; + //m_pGeomDB->SetMaterial( rrr, RED) ; if ( pCrvExtBorder->IsClosed()) { // 9) Creo la nuova regione da aggiungere a quella di influenza @@ -8959,8 +8973,8 @@ Pocketing::AdjustPathOutsideRawForOpenEdges( const ICurveComposite* pCompo, cons if ( IsNull( pSfrExpan)) return false ; pSfrExpan->AddExtLoop( Release( pCrvExtBorder)) ; - int green = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pSfrExpan->Clone()) ; // - m_pGeomDB->SetMaterial( green, GREEN) ; // + //int green = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pSfrExpan->Clone()) ; // + //m_pGeomDB->SetMaterial( green, GREEN) ; // if ( pSfrExpan->IsValid()) { if ( AreOppositeVectorApprox( pSfrExpan->GetNormVersor(), vtExtr)) pSfrExpan->Invert() ; @@ -8977,20 +8991,30 @@ Pocketing::AdjustPathOutsideRawForOpenEdges( const ICurveComposite* pCompo, cons return false ; } - int brown = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pSfrInc->Clone()) ; // - m_pGeomDB->SetMaterial( brown, BROWN) ; // + //int brown = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pSfrInc->Clone()) ; // + //m_pGeomDB->SetMaterial( brown, BROWN) ; // // RECUPERO DELLA CURVA DI BORDO ESTERNA DA AGGIUNGERE ALLA SVUOTATURA PtrOwner pCrvNewBorder( GetCurveComposite( pSfrInc->GetLoop( 0, 0))) ; if ( IsNull( pCrvNewBorder)) return false ; - double dUSTART ; pCrvNewBorder->GetParamAtPoint( ptSTART, dUSTART, 1500 * EPS_SMALL) ; + //int bl = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pCrvNewBorder->Clone()) ; // + //m_pGeomDB->SetMaterial( bl, BLACK) ; + double dUSTART ; pCrvNewBorder->GetParamAtPoint( ptSTART, dUSTART, 5000 * EPS_SMALL) ; pCrvNewBorder->ChangeStartPoint( dUSTART) ; - double dUEND ; pCrvNewBorder->GetParamAtPoint( ptEND, dUEND, 1500 * EPS_SMALL) ; + double dUEND ; pCrvNewBorder->GetParamAtPoint( ptEND, dUEND, 5000 * EPS_SMALL) ; pCrvNewBorder->TrimEndAtParam( dUEND) ; - int bb = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pCrvNewBorder->Clone()) ; // - m_pGeomDB->SetMaterial( bb, BLUE) ; // + //IGeoPoint3d* ptSff( CreateGeoPoint3d()) ; ptSff->Set( ptSTART) ; + //int LIM = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, ptSff) ; + //m_pGeomDB->SetMaterial( LIM, LIME) ; + //IGeoPoint3d* ptEff( CreateGeoPoint3d()) ; ptEff->Set( ptEND) ; + //int AQU = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, ptEff) ; + //m_pGeomDB->SetMaterial( AQU, AQUA) ; + + + //int bb = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pCrvNewBorder->Clone()) ; // + //m_pGeomDB->SetMaterial( bb, BLUE) ; // pNewCrv->Clear() ; pNewCrv->AddCurve( Release( pCrvNewBorder)) ; for ( int u = 0 ; u < pNewCrv->GetCurveCount() ; ++ u) @@ -9258,15 +9282,22 @@ Pocketing::AdaptSfrWithRaw( ISurfFlatRegion* pSrf, Vector3d vtTrasl, ICRVCOMPOPO // se il grezzo è stato trovato, allora controllo intersezioni e proiezioni per lati aperti if ( pStmRaw->IsValid() || pStmRaw->GetTriangleCount() > 0) { // interseco la superificie con il grezzo + //int g = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pSrf->Clone()) ; + //m_pGeomDB->SetMaterial( g, GREEN) ; if ( m_bIntersRaw) { if ( ! IntersSurfWithRaw( pSrf, pStmRaw, vtTrasl, bChanged)) return false ; } + //int l = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pSrf->Clone()) ; + //m_pGeomDB->SetMaterial( l, LIME) ; + //return false ; // proietto il grezzo if ( m_bProjectRaw) { if ( ! ProjectRaw( pSrf, vtTrasl, pStmRaw)) return false ; } + int p = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pSrf->Clone()) ; + m_pGeomDB->SetMaterial( p, PURPLE) ; // aggiusto i bordi nel caso di Tool non cilindrico // --- } @@ -9277,10 +9308,6 @@ Pocketing::AdaptSfrWithRaw( ISurfFlatRegion* pSrf, Vector3d vtTrasl, ICRVCOMPOPO if ( IsNull( pSrfFinal) || IsNull( pSrf_noOpenEdge)) return false ; - - int l = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pSrf->Clone()) ; - m_pGeomDB->SetMaterial( l, LIME) ; - // per ogni Chunck della superificie ottenuta... for ( int c = 0 ; c < pSrf->GetChunkCount() ; ++ c) { @@ -9338,7 +9365,6 @@ Pocketing::AdaptSfrWithRaw( ISurfFlatRegion* pSrf, Vector3d vtTrasl, ICRVCOMPOPO } } - // 5) Controllo i bordi delle isole ottenute e modifico quelli in cui sono presenti lati aperti for ( int i = 0 ; i < ( int)vCrvIsl.size() ; ++ i) { bSomeOpen = false ; @@ -9377,11 +9403,25 @@ Pocketing::AdaptSfrWithRaw( ISurfFlatRegion* pSrf, Vector3d vtTrasl, ICRVCOMPOPO } // 6) Creo la nuova superificie da svuotare - pSrfFinal->AddExtLoop( Release( pCrvExt)) ; + // NB. I vari chunk, dopo esseresi allargati nei lati aperti, potrebbero unirsi tra loro in alcuni parti... + SurfFlatRegionByContours SfrBC_Def ; + SfrBC_Def.AddCurve( Release( pCrvExt)) ; for ( int i = 0 ; i < ( int)vCrvModIsland.size() ; ++ i) - pSrfFinal->AddIntLoop( Release( vCrvModIsland[i])) ; + SfrBC_Def.AddCurve( Release( vCrvModIsland[i])) ; + + PtrOwner pSrfHelp_( SfrBC_Def.GetSurf()) ; + int ll = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pSrfHelp_->Clone()) ; + m_pGeomDB->SetMaterial( ll, LIME) ; + + + if ( pSrfFinal->GetChunkCount() == 0) + pSrfFinal.Set( pSrfHelp_) ; + else + pSrfFinal->Add( *pSrfHelp_) ; + } + // se superificie già lavorata in precedenza ... if ( m_dDiam_Prec > 0) { if ( ! GetNewSrfByAnotherPocketing( pSrfFinal, pSrf_noOpenEdge)) @@ -9392,18 +9432,8 @@ Pocketing::AdaptSfrWithRaw( ISurfFlatRegion* pSrf, Vector3d vtTrasl, ICRVCOMPOPO pSrf->Clear() ; pSrf->CopyFrom( pSrfFinal) ; - - for ( int c = 0 ; c < pSrf->GetChunkCount() ; ++ c) { - for ( int l = 0 ; l < pSrf->GetLoopCount( c) ; ++ l) { - PtrOwner pCrvCompo( GetCurveComposite( pSrf->GetLoop( c, l))) ; - for ( int u = 0 ; u < pCrvCompo->GetCurveCount() ; ++ u) - { - int nProp ; pCrvCompo->GetCurveTempProp( u, nProp, 0) ; - int OOOO = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pCrvCompo->GetCurve( u)->Clone()) ; - m_pGeomDB->SetMaterial( OOOO, nProp == 0 ? BLUE : RED) ; - } - } - } + //int o = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pSrf->Clone()) ; + //m_pGeomDB->SetMaterial( o, ORANGE) ; return pSrf->IsValid() && pSrf->GetChunkCount() != 0 ; } @@ -9466,11 +9496,24 @@ Pocketing::IntersSurfWithRaw( ISurfFlatRegion* pSfrPock, const ISurfTriMesh* pSt SurfFlatRegionByContours SrfChunkDef ; POLYLINEVECTOR vPl ; pStm->GetLoops( vPl) ; + //int p = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pStm->Clone()) ; + //m_pGeomDB->SetMaterial( p, PURPLE) ; + for ( int i = 0 ; i < ( int)vPl.size() ; ++ i) { // recupero la curva composita - PolyLine pl = vPl[i] ; + PolyLine PL = vPl[i] ; PtrOwner pCrv( CreateCurveComposite()) ; - pCrv->FromPolyLine( pl) ; + pCrv->FromPolyLine( PL) ; + //int b = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pCrv->Clone()) ; + //m_pGeomDB->SetMaterial( b, BLUE) ; + // essendo una curva derivante da un'intersezione di trimes ho una composita derivante da una polyLine, + // devo recuperare gli archi + PolyArc PA ; + pCrv->ApproxWithArcsEx( 500 * EPS_SMALL, ANG_TOL_STD_DEG, LIN_FEA_STD, PA) ; + pCrv->Clear() ; + pCrv->FromPolyArc( PA) ; + //int r = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pCrv->Clone()) ; + //m_pGeomDB->SetMaterial( r, RED) ; pCrv->SetExtrusion( vtExtr) ; pCrv->SetThickness( dThick) ; // la converto in una semplice cruva per proiettarla su piano della svuotatura diff --git a/Pocketing.h b/Pocketing.h index a60fb08..f9171a4 100644 --- a/Pocketing.h +++ b/Pocketing.h @@ -113,7 +113,7 @@ class Pocketing : public Machining bool bFlag) ; bool GetCoeffLinArc( const ICurveArc* pArc, double dDiam, double& dSubArc) ; bool GetParamOnOpenSide( const ICurveComposite* pCompo,const ICRVCOMPOPOVECTOR& vCrvIsl, Point3d& ptMid, Vector3d& vtMidOut) ; - bool AdjustContourWithOpenEdges( ICurveComposite* pCompo, const ICRVCOMPOPOVECTOR& vCrvIsl, + bool AdjustContourWithOpenEdges( ICurveComposite* pCompo, ICRVCOMPOPOVECTOR& vCrvIsl, double dDiam, double dOffR) ; bool AdjustPathOutsideRawForOpenEdges( const ICurveComposite* pCompo, const ICRVCOMPOPOVECTOR& vCrvIsland, ICurveComposite* pCrvOpenOffs, const Point3d& ptCrvOpenS,