From ed4a9ec745020b3e4eba054f4ce8142cd57b008b Mon Sep 17 00:00:00 2001 From: Riccardo Elitropi Date: Fri, 31 Mar 2023 17:08:38 +0200 Subject: [PATCH] EgtMachKernel : - primo prototipo per funzione Feed. --- Pocketing.cpp | 162 ++++++++++++++++++++++++++++++++++++++++++++++---- Pocketing.h | 9 +++ 2 files changed, 161 insertions(+), 10 deletions(-) diff --git a/Pocketing.cpp b/Pocketing.cpp index 46fa231..488f208 100644 --- a/Pocketing.cpp +++ b/Pocketing.cpp @@ -98,6 +98,7 @@ using namespace std ; static string KEY_OPEN = "OPEN" ; static const std::string BOX_NAME = "Box" ; static int LINK_CURVE_PROP = -3 ; +static int FEED_DIVISOR = 1000 ; //---------------------------------------------------------------------------- USEROBJ_REGISTER( GetOperationClass( OPER_POCKETING), Pocketing) ; @@ -1236,7 +1237,7 @@ Pocketing::GetCurves( SelData Id, ICURVEPLIST& lstPC) INTVECTOR vBannedId{ -1, nFacet} ; // 2) scorro tutte le curve del bordo esterno - for( int j = 0 ; j < pCrvCompo->GetCurveCount() ; ++j) { + for( int j = 0 ; j < pCrvCompo->GetCurveCount() ; ++ j) { int nProp = 0 ; // 3) controllo che nella seconda temp prop ho una faccia adiancente non giĆ  considerata da un altro bordo // e creo un vettore con gli Id delle facce del bordo laterale adiacente alla curva j della pCrvCompo @@ -4429,6 +4430,9 @@ Pocketing::AddSpiralIn( const ISurfFlatRegion* pSrfPock, /*PNTVECTOR vPtStart,*/ && ( j % 2 == 0)) pMCrv->Invert() ; + // superficie per scelta Feed + PtrOwner pSrfForFeed( CreateSurfFlatRegion()) ; + // ciclo sulle curve elementari for ( int i = 0 ; i <= nMaxInd ; ++ i) { // curva corrente @@ -4992,7 +4996,6 @@ Pocketing::CalcSpiral( const ISurfFlatRegion* pSrfPock, int& nReg, Point3d& ptSt PtrOwner pSrfPrec( CloneSurfFlatRegion( pSrfToWork)) ; // regione precedente if( IsNull( pSrfAct) || IsNull( pSrfPrec) || pSrfAct->GetChunkCount() == 0 || pSrfPrec->GetChunkCount() == 0) return false ; - PtrOwner pCutRegion( CreateSurfFlatRegion()) ; // regione lavorata dall'utensile while ( nIter < MAX_ITER) { // salvo la regione @@ -5011,7 +5014,7 @@ Pocketing::CalcSpiral( const ISurfFlatRegion* pSrfPock, int& nReg, Point3d& ptSt int nChunks = pSrfAct->GetChunkCount(); - for ( int i = 0 ; i < nChunks; ++ i) { + for ( int i = 0 ; i < nChunks ; ++ i) { // per ogni chunk... int nLoops = pSrfAct->GetLoopCount( i) ; for ( int j = 0 ; j < nLoops ; ++ j) { @@ -5023,9 +5026,9 @@ Pocketing::CalcSpiral( const ISurfFlatRegion* pSrfPock, int& nReg, Point3d& ptSt bool bInsert = true ; if( ! CheckIfOffsetIsNecessary( ptoCCBorder, dOffs, ( int)vOffs.size(), nIter, vtExtr, bInsert)) return false ; - if ( bInsert) + if ( bInsert) { vOffs.emplace_back( Release( ptoCCBorder)) ; - + } PtrOwner ptoCCExtBorder( GetCurveComposite( pSrfAct->GetLoop( i, j))) ; if ( nIter == 0) { // salvo il bordo per i link (non invertiti) vOffsFirstCurve.emplace_back( Release( ptoCCExtBorder)) ; @@ -5185,7 +5188,6 @@ Pocketing::CalcSpiral( const ISurfFlatRegion* pSrfPock, int& nReg, Point3d& ptSt // 3) controllo eventuali parti non svuotate... PtrOwner pSrfToCut( CreateSurfFlatRegion()) ; if ( GetUnclearedRegion( vOffsFirstCurve, vOffs, vLinks, pSrfToCut)) { - m_pGeomDB->AddGeoObj(GDB_ID_NULL, GDB_ID_ROOT, pSrfToCut->Clone()) ; // 4) Modifico i percorsi if ( ! RemoveExtraParts( pSrfToCut, vOffs, vOffsClosedCurves, vOffsFirstCurve, vLinks)) return false ; @@ -10308,12 +10310,15 @@ Pocketing::CheckIfOffsetIsNecessary( const ICurveComposite* pCrvOffs, const doub const int nIter, const Vector3d& vtN, bool& bInsert) { - return true ; // controllo dei parametri if ( pCrvOffs == nullptr || ! pCrvOffs->IsValid() || pCrvOffs->GetCurveCount() == 0 || dOffs < EPS_SMALL) return false ; bInsert = true ; // di base inserisco + // controllo se richiesta ottimizzazione sul numero di Offsets + if ( ! m_bOptOffset) + return true ; + if ( nIter != 0) { // controllo se sono almeno al secondo offset... // per ogni curva controllo se il controOffset + 5 * EPS_SMALL genera una regione ... @@ -10328,9 +10333,8 @@ Pocketing::CheckIfOffsetIsNecessary( const ICurveComposite* pCrvOffs, const doub else return true ; - // <- primo test - - if( OffsCrv.GetCurveCount() > 1) + // controllo se richista ottimizzazione per Offsets mediante centroidi e medial Axis + if( ! m_bOptOffsetCM || OffsCrv.GetCurveCount() > 1) return true ; PtrOwner pCrvOffLonger( OffsCrv.GetLongerCurve()) ; @@ -10381,3 +10385,141 @@ Pocketing::CheckIfOffsetIsNecessary( const ICurveComposite* pCrvOffs, const doub return true ; } + +//---------------------------------------------------------------------------- +bool +Pocketing::SetApproxFeedAsTmpProp0( const int nPocketType, ICurveComposite* pCrv, ICurveComposite* pCrvOriOffSpiral, + const int nCrvType, const bool bIsFirst, const ISurfFlatRegion* PSrfRemoved, + const ICurveComposite* pCrvOrig, const double dOffs, const double dMinFeed, + const double dMaxFeed) +{ + + // ===================================================================================================== + // nCrvType : 0 -> Curva Caratteristica | 1 -> Link | 2 -> Bordo di finitura + // ===================================================================================================== + + double dFeed = dMinFeed ; + INTVECTOR vIndCrvOE ; + + for ( int u = 0 ; u < pCrv->GetCurveCount() ; ++ u) { + const ICurve* pCrvAct = pCrv->GetCurve( u) ; + if ( pCrvAct != nullptr) { + int nStat = 0 ; + // controllo se ho la sottocurva che coincide con un lato aperto + if ( CheckSimpleOverlap( pCrvAct, pCrvOrig, nStat, 1500 * EPS_SMALL) && nStat == 1) { + pCrv->SetCurveTempProp( u, FEED_DIVISOR * 0.5 * ( dMaxFeed + dMinFeed)) ; + vIndCrvOE.push_back( u) ; + } + // controllo che la sottocurva non sia una curva per zona non svuotata + else if( nCrvType == POCKET_SUB_SPIRALIN || nCrvType == POCKET_SUB_SPIRALOUT) { + if ( CheckSimpleOverlap( pCrvAct, pCrvOriOffSpiral, nStat, 10 * EPS_SMALL) && nStat == 0) { + pCrv->SetCurveTempProp( u, FEED_DIVISOR * dMaxFeed ) ; + vIndCrvOE.push_back( u) ; + } + } + } + } + + switch ( nPocketType) + { + case POCKET_SUB_SPIRALIN : + case POCKET_SUB_SPIRALOUT : + switch ( nCrvType) + { + case 0 : // Curva di Offset + if ( bIsFirst) + dFeed = dMinFeed ; + else // ... + dFeed = dMinFeed + (( dMaxFeed - dMinFeed) / ( m_TParams.m_dDiam / 2) ) * dOffs ; + case 1 : // Link + if ( PSrfRemoved != nullptr && PSrfRemoved->IsValid() && PSrfRemoved->GetChunkCount() != 0 && + pCrv != nullptr && pCrv->IsValid() && pCrv->GetCurveCount() != 0) { + CRVCVECTOR ccClass ; + if ( PSrfRemoved->GetCurveClassification( *pCrv, EPS_SMALL, ccClass)) { + double dLenInside = EPS_SMALL ; double dLenOutSide = EPS_SMALL ; + + for ( int i = 0 ; i < ( int)ccClass.size() ; ++ i) { + double dLen = EPS_SMALL ; + PtrOwner pCrvSub( pCrv->CopyParamRange( ccClass[i].dParS, ccClass[i].dParE)) ; + if ( ! IsNull( pCrvSub) && pCrvSub->IsValid()) + pCrvSub->GetLength( dLen) ; + else + dFeed = dMinFeed ; + + if ( ccClass[i].nClass == CRVC_IN) + dLenInside += dLen ; + else + dLenOutSide += dLen ; + } + + if ( dLenInside < 100 * EPS_SMALL) // curva circa tutta fuori + dFeed = dMaxFeed ; + else if ( dLenOutSide < 100 * EPS_ANG_SMALL) // curva circa tutta dentro + dFeed = dMinFeed ; + else + dFeed = dMinFeed + ( dLenOutSide / ( dLenInside + dLenOutSide)) * ( dMaxFeed - dMinFeed) ; + } + else + dFeed = dMinFeed ; + } + else + dFeed = dMinFeed ; + default : + break ; + } + break ; + case POCKET_SUB_ZIGZAG : + switch ( nCrvType ) + { + case 0 : // Linea percorso ZigZag + if ( bIsFirst) + dFeed = dMinFeed ; + else + dFeed = dMinFeed + (( dMaxFeed - dMinFeed) / ( m_TParams.m_dDiam / 2)) * dOffs ; + case 1 : // Link + dFeed = dMaxFeed ; + case 2 : // Bordo di finitura + dFeed = dMinFeed + ( 2.0 / 3.0) * ( dMaxFeed - dMinFeed) ; + default : + break ; + } + break ; + case POCKET_SUB_ONEWAY : + switch ( nCrvType ) + { + case 0 : // Linea percorso OneWay + if ( bIsFirst) + dFeed = dMinFeed ; + else + dFeed = dMinFeed + (( dMaxFeed - dMinFeed) / ( m_TParams.m_dDiam / 2)) * dOffs ; + case 2 : // Bordo di finitura + dFeed = dMaxFeed ; + default : + break ; + } + default : + break ; + } + + for ( int u = 0 ; u < ( int)pCrv->GetCurveCount() ; ++ u) { + if ( find( vIndCrvOE.begin(), vIndCrvOE.end(), u) == vIndCrvOE.end()) + pCrv->SetCurveTempProp( u, dFeed * FEED_DIVISOR, 0) ; + } + + return true ; +} + +//---------------------------------------------------------------------------- +bool +Pocketing::GetDynamicClearedRegion( ISurfFlatRegion* pSrfPrec, const ICurveComposite* pCrv) +{ + PtrOwner pCrvPath( pCrv->Clone()) ; + if ( IsNull( pCrvPath)) + return false ; + PtrOwner PSrfRemoved( GetSurfFlatRegionFromFatCurve( Release( pCrvPath), m_TParams.m_dDiam / 2, true, false)) ; + if ( pSrfPrec->GetChunkCount() == 0) + pSrfPrec->CopyFrom( Release( PSrfRemoved)) ; + else + pSrfPrec->Add( *Release( PSrfRemoved)) ; + return true ; +} diff --git a/Pocketing.h b/Pocketing.h index 1857dbd..bfc37eb 100644 --- a/Pocketing.h +++ b/Pocketing.h @@ -160,6 +160,7 @@ class Pocketing : public Machining const int nOffsCount, const Vector3d& vtN, bool& bInsert) ; bool GetUnclearedRegion( ICRVCOMPOPOVECTOR& vFirstOffs, ICRVCOMPOPOVECTOR& vCrvs, ICURVEPOVECTOR& vLinks, ISurfFlatRegion* pSrfToCut) ; + bool GetDynamicClearedRegion( ISurfFlatRegion* pSrfPrec, const ICurveComposite* pCrv) ; bool RemoveFirstLoopFromSfr( ISurfFlatRegion* pSrfOrig ) ; bool RemoveExtraParts( ISurfFlatRegion* pSrfToCut, ICRVCOMPOPOVECTOR& vOffs, ICRVCOMPOPOVECTOR& vOffsClosedCurves, ICRVCOMPOPOVECTOR& vOffsFirstCurve, ICURVEPOVECTOR& vLinks) ; @@ -202,6 +203,10 @@ class Pocketing : public Machining // ========================================================================= // ============================ IN/OUT ===================================== + bool SetApproxFeedAsTmpProp0( const int nPocketType, ICurveComposite* pCrv, ICurveComposite* pCrvOriOffSpiral, + const int nCrvType, const bool bIsFirst, const ISurfFlatRegion* PSrfRemoved, + const ICurveComposite* pCrvOrig, const double dOffs, const double dMinFeed, + const double dMaxFeed) ; bool VerifyLeadInHelix( ISurfFlatRegion* pSrfChunk, const Point3d& ptCen, double dRad) const ; bool VerifyLeadInZigZag( ISurfFlatRegion* pSrfChunk, const Point3d& ptPa, const Point3d& ptPb) const ; bool CalcDistanceFromRawSurface( int nPhase, const Point3d& ptP, const Vector3d& vtDir, double& dDist, Vector3d& vtNorm) ; @@ -279,5 +284,9 @@ class Pocketing : public Machining Vector3d m_vtAggrBottom ; // vettore direzione ausiliaria aggregato da sotto AggrBottom m_AggrBottom ; // dati eventuale aggregato da sotto bool m_bOpenOutRaw ; // flag forzatura lati aperti sempre fuori dal grezzo + bool m_bOptOffset = true ; // flag per ottimizzazione numero di Offset necessari + bool m_bOptOffsetCM = false ; // flag per ottimizzazione numero di Offset necessari con centroidi e medial Axis + double m_dDiam_Prec ; // diametro utensile per precedente svuotatura + double m_dOffsetR_Prec ; // Offset radiale della svuotatura precedente } ; \ No newline at end of file