From 1bcff0eb794f41f07ea579da6ec8a2ec81c969e6 Mon Sep 17 00:00:00 2001 From: Dario Sassi Date: Mon, 18 Dec 2023 09:31:31 +0100 Subject: [PATCH] EgtMachKernel : - in svuotatura cambiato calcolo elevazione. --- GeoConst.h | 1 + Milling.cpp | 2 +- Pocketing.cpp | 172 ++++++++++++++++++++++---------------------------- Pocketing.h | 2 +- 4 files changed, 77 insertions(+), 100 deletions(-) diff --git a/GeoConst.h b/GeoConst.h index 8ff565a..d73c9e6 100644 --- a/GeoConst.h +++ b/GeoConst.h @@ -19,6 +19,7 @@ //----------- Costanti per approssimazioni con polilinee o poliarchi -------- const double LIN_TOL_STD = 0.1 ; const double LIN_TOL_MID = 0.05 ; +const double LIN_TOL_RAW = 0.5 ; const double ANG_TOL_MAX_DEG = 90 ; const double ANG_TOL_STD_DEG = 15 ; const double LIN_FEA_STD = 20 ; diff --git a/Milling.cpp b/Milling.cpp index b04a8e4..44f8072 100644 --- a/Milling.cpp +++ b/Milling.cpp @@ -2086,7 +2086,7 @@ Milling::CalcPathElevation( const ICurveComposite* pCompo, const Vector3d& vtToo dRad = max( dRad, MIN_RAD) ; // approssimo la curva con una polilinea PolyLine PL ; - if ( ! pCompo->ApproxWithLines( LIN_TOL_STD, ANG_TOL_MAX_DEG, ICurve::APL_SPECIAL, PL)) + if ( ! pCompo->ApproxWithLines( LIN_TOL_RAW, ANG_TOL_MAX_DEG, ICurve::APL_SPECIAL, PL)) return false ; double const MIN_STEP = 5 ; double const MAX_STEP = 500 ; diff --git a/Pocketing.cpp b/Pocketing.cpp index 9d5b211..e9978ff 100644 --- a/Pocketing.cpp +++ b/Pocketing.cpp @@ -1,7 +1,7 @@ //---------------------------------------------------------------------------- -// EgalTech 2017-2022 +// EgalTech 2017-2023 //---------------------------------------------------------------------------- -// File : Pocketing.cpp Data : 24.08.22 Versione : 2.4h2 +// File : Pocketing.cpp Data : 17.12.23 Versione : 2.5l3 // Contenuto : Implementazione gestione svuotature. // // @@ -32,6 +32,7 @@ #include "/EgtDev/Include/EGkExtText.h" #include "/EgtDev/Include/EGkCurveLocal.h" #include "/EgtDev/Include/EGkDistPointCurve.h" +#include "/EgtDev/Include/EGkPolygonElevation.h" #include "/EgtDev/Include/EGkUserObjFactory.h" #include "/EgtDev/Include/EGkIntervals.h" #include "/EgtDev/Include/EGkStringUtils3d.h" @@ -1582,7 +1583,7 @@ Pocketing::ProcessPath( int nPathId, int nPvId, int nClId) // calcolo l'elevazione massima double dElev ; - if ( CalcRegionElevation( pCompo, vtTool, dDepth, 0.5 * m_TParams.m_dDiam, dElev)) { + if ( CalcRegionElevation( pCompo, vtTool, dDepth, 0.5 * m_TParams.m_dDiam, m_TParams.m_dLen, dElev)) { if ( dElev < EPS_SMALL && AreSameVectorApprox( vtExtr, Z_AX)) { BBox3d b3Crv ; pCompo->GetLocalBBox( b3Crv) ; @@ -1738,109 +1739,84 @@ Pocketing::ProcessPath( int nPathId, int nPvId, int nClId) //---------------------------------------------------------------------------- bool -Pocketing::CalcRegionElevation( const ICurveComposite* pCompo, const Vector3d& vtTool, double dDepth, double dRad, +Pocketing::CalcRegionElevation( const ICurveComposite* pCompo, const Vector3d& vtTool, double dDepth, double dRad, double dLen, double& dElev) const { // inizializzo l'elevazione dElev = 0 ; - // affondamento come vettore - Vector3d vtDepth = vtTool * dDepth ; - // Campiono il contorno - int nMaxInd = pCompo->GetCurveCount() - 1 ; - for ( int i = 0 ; i <= nMaxInd ; ++ i) { - // curva corrente - const ICurve* pCrvC = pCompo->GetCurve( i) ; - Point3d ptStart ; pCrvC->GetStartPoint( ptStart) ; - Point3d ptMid ; pCrvC->GetMidPoint( ptMid) ; - Point3d ptEnd ; pCrvC->GetEndPoint( ptEnd) ; - // elevazione della curva - double dCurrElev ; - if ( GetElevation( m_nPhase, ptStart - vtDepth, ptMid - vtDepth, ptEnd - vtDepth, vtTool, dCurrElev)) { - if ( dCurrElev > dElev) - dElev = dCurrElev ; - } - else { - m_pMchMgr->SetLastError( 2408, "Error in Pocketing : Entity GetElevation") ; - return false ; - } - } - - // Campiono l'interno con una griglia (uso linee parallele a X) - // determino il riferimento di base - Frame3d frPocket ; - Point3d ptCen ; pCompo->GetCentroid( ptCen) ; - frPocket.Set( ptCen, vtTool) ; - // copio il contorno e lo porto nel riferimento - PtrOwner pCompoL( pCompo->Clone()) ; - if ( IsNull( pCompoL) || ! pCompoL->ToLoc( frPocket)) { - m_pMchMgr->SetLastError( 2408, "Error in Pocketing : Entity GetElevation") ; + // approssimo la curva con una polilinea che uso per creare il poligono equivalente + PolyLine PL ; + if ( ! pCompo->ApproxWithLines( LIN_TOL_RAW, ANG_TOL_MAX_DEG, ICurve::APL_SPECIAL, PL)) return false ; + Polygon3d pgFacet ; + if ( ! pgFacet.FromPolyLine( PL)) + return false ; + // aggiungo l'affondamento + pgFacet.Translate( -dDepth * vtTool) ; + + // inizializzo elevazioni per ogni grezzo + INTDBLVECTOR vRawElev ; + // ciclo sui grezzi della fase + int nRawId = m_pMchMgr->GetFirstRawPart() ; + while ( nRawId != GDB_ID_NULL) { + // verifico che il grezzo compaia nella fase + if ( m_pMchMgr->VerifyRawPartPhase( nRawId, m_nPhase)) { + // recupero la trimesh del grezzo + int nStmId = m_pGeomDB->GetFirstNameInGroup( nRawId, MACH_RAW_SOLID) ; + const ISurfTriMesh* pStm = GetSurfTriMesh( m_pGeomDB->GetGeoObj( nStmId)) ; + if ( pStm != nullptr) { + // recupero il riferimento della trimesh + Frame3d frStm ; + m_pGeomDB->GetGlobFrame( nStmId, frStm) ; + // porto il poligono in questo riferimento + Polygon3d pgFacetL = pgFacet ; + pgFacetL.ToLoc( frStm) ; + // calcolo l'elevazione + double dCurrElev ; + if ( ! PolygonElevationInClosedSurfTm( pgFacetL, *pStm, true, dCurrElev)) + return false ; + if ( dCurrElev > EPS_SMALL) + vRawElev.emplace_back( nStmId, dCurrElev) ; + } + } + // passo al grezzo successivo + nRawId = m_pMchMgr->GetNextRawPart( nRawId) ; } - // ingombro del contorno in locale - BBox3d b3Pocket ; - pCompoL->GetLocalBBox( b3Pocket) ; - Point3d ptMin ; double dDimX, dDimY, dDimZ ; - b3Pocket.GetMinDim( ptMin, dDimX, dDimY, dDimZ) ; - // passi in Y - const double STEP = 50 ; - int nYStep = max( int( ceil( ( dDimY - 20 * EPS_SMALL) / STEP)), 2) ; - double dYStep = ( nYStep > 0 ? ( dDimY - 20 * EPS_SMALL) / nYStep : 0) ; - // calcolo le linee di svuotatura - for ( int i = 1 ; i < nYStep ; ++ i) { - // definisco la linea - PtrOwner pLine( CreateCurveLine()) ; - const double EXP_LEN = 1.0 ; - Point3d ptStart( ptMin.x - EXP_LEN, ptMin.y + 10 * EPS_SMALL + i * dYStep, ptMin.z + dDimZ) ; - if ( IsNull( pLine) || ! pLine->SetPVL( ptStart, X_AX, dDimX + 2 * EXP_LEN)) { - m_pMchMgr->SetLastError( 2408, "Error in Pocketing : Entity GetElevation") ; - return false ; - } - // calcolo la classificazione della curva rispetto al contorno - IntersCurveCurve intCC( *pLine, *pCompoL) ; - CRVCVECTOR ccClass ; - if ( intCC.GetCurveClassification( 0, EPS_SMALL, ccClass)) { - // determino gli intervalli di curva interni - Intervals inOk ; - for ( auto& ccOne : ccClass) { - if ( ccOne.nClass == CRVC_IN) { - Point3d ptStart ; - pLine->GetPointD1D2( ccOne.dParS, ICurve::FROM_PLUS, ptStart) ; - ptStart.ToGlob( frPocket) ; - Point3d ptEnd ; - pLine->GetPointD1D2( ccOne.dParE, ICurve::FROM_MINUS, ptEnd) ; - ptEnd.ToGlob( frPocket) ; - // elevazione della curva - double dCurrElev ; - if ( GetElevation( m_nPhase, ptStart - vtDepth, ptEnd - vtDepth, vtTool, dCurrElev)) { - if ( dCurrElev > dElev) - dElev = dCurrElev ; - } - else { - m_pMchMgr->SetLastError( 2408, "Error in Pocketing : Entity GetElevation") ; - return false ; - } - } - } - } - // altrimenti uso tutta la curva + // se trovate elevazioni + if ( ! vRawElev.empty()) { + // ordino il vettore secondo l'elevazione crescente + sort( vRawElev.begin(), vRawElev.end(), []( const INTDBL& a, const INTDBL& b) + { return a.second < b.second ; }) ; + // box dell'insieme delle posizioni utensile all'inizioe + const double MAX_DIST_RAW = 200.0 ; + BBox3d b3Tool ; + pgFacet.GetLocalBBox( b3Tool) ; + b3Tool.Add( b3Tool.GetMin() + dLen * vtTool) ; + b3Tool.Add( b3Tool.GetMax() + dLen * vtTool) ; + if ( vtTool.IsX()) + b3Tool.Expand( 0, dRad, dRad) ; + else if ( vtTool.IsY()) + b3Tool.Expand( dRad, 0, dRad) ; + else if ( vtTool.IsZ()) + b3Tool.Expand( dRad, dRad, 0) ; else { - Point3d ptStart ; - pLine->GetStartPoint( ptStart) ; - ptStart.ToGlob( frPocket) ; - Point3d ptEnd ; - pLine->GetEndPoint( ptEnd) ; - ptEnd.ToGlob( frPocket) ; - // elevazione della curva - double dCurrElev ; - if ( GetElevation( m_nPhase, ptStart - vtDepth, ptEnd - vtDepth, vtTool, dCurrElev)) { - if ( dCurrElev > dElev) - dElev = dCurrElev ; - } - else { - m_pMchMgr->SetLastError( 2408, "Error in Pocketing : Entity GetElevation") ; - return false ; - } + double dExpandX = dRad * sqrt( 1 - vtTool.x * vtTool.x) ; + double dExpandY = dRad * sqrt( 1 - vtTool.y * vtTool.y) ; + double dExpandZ = dRad * sqrt( 1 - vtTool.z * vtTool.z) ; + b3Tool.Expand( dExpandX, dExpandY, dExpandZ) ; + } + b3Tool.Expand( MAX_DIST_RAW) ; + // verifico la reale interferenza dell'utensile con i diversi grezzi + for ( int i = 0 ; i < int( vRawElev.size()) ; ++ i) { + // box del grezzo + BBox3d b3Raw ; + m_pGeomDB->GetGlobalBBox( vRawElev[i].first, b3Raw) ; + // confronto con il box dell'utensile nella posizione precedente + BBox3d b3CurrTool = b3Tool ; + b3CurrTool.Translate( dElev * vtTool) ; + if ( b3Raw.Overlaps( b3CurrTool)) + dElev = vRawElev[i].second ; } } diff --git a/Pocketing.h b/Pocketing.h index c62df12..bd2e724 100644 --- a/Pocketing.h +++ b/Pocketing.h @@ -72,7 +72,7 @@ class Pocketing : public Machining bool ResetCurveAllTempProp( ICurve* pCurve) ; bool Chain( int nGrpDestId) ; bool ProcessPath( int nPathId, int nPvId, int nClId) ; - bool CalcRegionElevation( const ICurveComposite* pCompo, const Vector3d& vtTool, double dDepth, double dRad, double& dElev) const ; + bool CalcRegionElevation( const ICurveComposite* pCompo, const Vector3d& vtTool, double dDepth, double dRad, double dLen, double& dElev) const ; bool VerifyPathFromBottom( const ICurveComposite* pCompo, const Vector3d& vtTool) ; bool GeneratePocketingPv( int nPathId, const ICurveComposite* pCompo) ; bool AddZigZag( const ICurveComposite* pCompo, const Vector3d& vtTool, const Vector3d& vtExtr,