Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 95936249fa | |||
| 2413003ecd | |||
| 740c797779 | |||
| cf5329c29e | |||
| 55504ad2c9 | |||
| 392a5305ec | |||
| 01ee329431 | |||
| d77102539a | |||
| 7e286c1c8e | |||
| 217652e7ac | |||
| 26a1ef5e22 | |||
| 28e31097a9 | |||
| ded589ac0d |
+436
-35
@@ -35,6 +35,8 @@
|
||||
#include "/EgtDev/Include/EGnStringKeyVal.h"
|
||||
#include "/EgtDev/Include/EgtPointerOwner.h"
|
||||
#include "/EgtDev/Include/EgtNumUtils.h"
|
||||
#include "/EgtDev/Include/EgkStmFromCurves.h"
|
||||
#include "/EgtDev/Include/EGkDistPointSurfTm.h"
|
||||
|
||||
using namespace std ;
|
||||
|
||||
@@ -3119,16 +3121,19 @@ Pocketing::AddSpiralOut( const ICurveComposite* pCompo, const Vector3d& vtTool,
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
Pocketing::CalcSpiral( const ICurveComposite* pCompo, int nReg, bool bSplitArcs,
|
||||
ICurveComposite* pMCrv, ICurveComposite* pRCrv)
|
||||
{
|
||||
ICurveComposite* pMCrv, ICurveComposite* pRCrv)
|
||||
{
|
||||
ISurfFlatRegion * pCutRegion = CreateSurfFlatRegion() ; // regione lavorata
|
||||
bool bFirst = true ;
|
||||
|
||||
// inizializzo i risultati
|
||||
pMCrv->Clear() ;
|
||||
pRCrv->Clear() ;
|
||||
|
||||
|
||||
// primo offset pari al raggio utensile + sovramateriale
|
||||
double dTRad = 0.5 * m_TParams.m_dDiam ;
|
||||
double dOffs = dTRad + GetOffsR() ;
|
||||
|
||||
|
||||
// se circonferenza, chiamo la funzione specializzata
|
||||
Point3d ptCen ; Vector3d vtN ; double dRad ; bool bCCW ;
|
||||
if ( pCompo->IsACircle( 100 * EPS_SMALL, ptCen, vtN, dRad, bCCW)) {
|
||||
@@ -3142,20 +3147,24 @@ Pocketing::CalcSpiral( const ICurveComposite* pCompo, int nReg, bool bSplitArcs,
|
||||
else
|
||||
return true ;
|
||||
}
|
||||
|
||||
|
||||
// ciclo di offset verso l'interno
|
||||
const int MAX_ITER = 1000 ;
|
||||
int nIter = 0 ;
|
||||
ICURVEPOVECTOR vOffs ;
|
||||
ICURVEPOVECTOR vCrvStack ;
|
||||
ICURVEPOVECTOR vCrvStack ;
|
||||
DBLVECTOR vRadStack ;
|
||||
PtrOwner<ICurve> pOffs ;
|
||||
PtrOwner<ICurveComposite> pOffs ;
|
||||
double dCurrRad = GetCurveRadius( pCompo) ;
|
||||
|
||||
Vector3d vtExtr ;
|
||||
pCompo->GetExtrusion( vtExtr) ;
|
||||
|
||||
while ( nIter < MAX_ITER) {
|
||||
// calcolo
|
||||
OffsetCurve OffsCrv ;
|
||||
if ( ! OffsCrv.Make( ( nIter == 0 ? (ICurve*) pCompo : pOffs), - dOffs, ICurve::OFF_FILLET) ||
|
||||
( nIter == 0 && nReg == 0 && OffsCrv.GetCurveCount() == 0)) {
|
||||
if ( ( nIter == 0 || ! IsNull( pOffs)) && ! OffsCrv.Make( ( nIter == 0 ? (ICurve*) pCompo : pOffs), - dOffs, ICurve::OFF_FILLET) ||
|
||||
( nIter == 0 && nReg == 0 && OffsCrv.GetCurveCount() == 0)) {
|
||||
m_pMchMgr->SetLastError( 2412, "Error in Pocketing : Offset not computable") ;
|
||||
return false ;
|
||||
}
|
||||
@@ -3163,11 +3172,12 @@ Pocketing::CalcSpiral( const ICurveComposite* pCompo, int nReg, bool bSplitArcs,
|
||||
if ( nIter == 0 && nReg >= OffsCrv.GetCurveCount())
|
||||
return true ;
|
||||
// recupero le curve di offset e le metto sullo stack (se primo offset solo quella voluta)
|
||||
int nCount = 0 ;
|
||||
int nCount = 0 ;
|
||||
ICurve* pCrv = OffsCrv.GetLongerCurve() ;
|
||||
while ( pCrv != nullptr) {
|
||||
bool bOffsOk = ( pCrv != nullptr) ; // indica se ho ottenuto un offset valido nel caso in cui sia stato costruito
|
||||
while ( pCrv != nullptr) {
|
||||
if ( nIter != 0 || nReg == nCount) {
|
||||
vCrvStack.emplace_back( pCrv) ;
|
||||
vCrvStack.emplace_back( pCrv) ;
|
||||
vRadStack.emplace_back( dCurrRad) ;
|
||||
if ( nIter == 0)
|
||||
break ;
|
||||
@@ -3177,42 +3187,70 @@ Pocketing::CalcSpiral( const ICurveComposite* pCompo, int nReg, bool bSplitArcs,
|
||||
pCrv = OffsCrv.GetCurve() ;
|
||||
++ nCount ;
|
||||
}
|
||||
// recupero la prossima curva di offset
|
||||
PtrOwner<ICurve> pNextOffs ;
|
||||
if ( ! vCrvStack.empty()) {
|
||||
// recupero la prossima curva di offset se ho ottenuto un offset valido oppure ho fallito ma non è ulteriormente riducibile
|
||||
PtrOwner<ICurve> pNextOffs ;
|
||||
if ( ! vCrvStack.empty() && ( bOffsOk || dOffs < dTRad + EPS_ZERO)) {
|
||||
pNextOffs.Set( Release( vCrvStack.back())) ;
|
||||
vCrvStack.pop_back() ;
|
||||
dCurrRad = vRadStack.back() ;
|
||||
vRadStack.pop_back() ;
|
||||
}
|
||||
|
||||
double dRad = GetCurveRadius( pNextOffs) ;
|
||||
bool bNextOk = ( dRad > EPS_ZERO && dRad < dCurrRad) ;
|
||||
bool bSmallRad = ( nIter == 0 ? dOffs < dTRad + GetOffsR() + EPS_ZERO : dOffs < dTRad + EPS_ZERO) ;
|
||||
// se completato step di offset, accodo la curva offsettata al percorso di lavoro
|
||||
|
||||
if ( ! IsNull( pOffs) && ( bNextOk || bSmallRad)) {
|
||||
// inserisco l'offset nel vettore
|
||||
vOffs.emplace_back( Release( pOffs)) ;
|
||||
|
||||
// Superficie coperta dal tool quando percorre pOffs
|
||||
OffsetCurve OffsCrvPlus ;
|
||||
OffsCrvPlus.Make( pOffs, m_TParams.m_dDiam / 2 + 5 * EPS_SMALL, ICurve::OFF_FILLET) ;
|
||||
ICurve * pCrvOffPlus = OffsCrvPlus.GetLongerCurve() ;
|
||||
ISurfFlatRegion * pSrf = CreateSurfFlatRegion() ;
|
||||
pSrf->AddExtLoop( pCrvOffPlus) ;
|
||||
|
||||
OffsetCurve OffsCrvMinus ;
|
||||
OffsCrvMinus.Make( pOffs, - m_TParams.m_dDiam / 2 - 5 * EPS_SMALL, ICurve::OFF_FILLET) ;
|
||||
ICurveComposite * pCrvOffMinus = GetCurveComposite( OffsCrvMinus.GetLongerCurve()) ;
|
||||
while ( pCrvOffMinus != nullptr) {
|
||||
if ( GetCurveRadius( pCrvOffMinus) > EPS_ZERO)
|
||||
pSrf->AddIntLoop( pCrvOffMinus) ;
|
||||
pCrvOffMinus = GetCurveComposite( OffsCrvMinus.GetCurve()) ;
|
||||
}
|
||||
|
||||
if ( bFirst) {
|
||||
bFirst = false ;
|
||||
pCutRegion = pSrf->Clone() ;
|
||||
}
|
||||
else
|
||||
pCutRegion->Add( *(pSrf->Clone())) ;
|
||||
|
||||
// inserisco l'offset nel vettore
|
||||
vOffs.emplace_back( Release( pOffs)) ;
|
||||
|
||||
}
|
||||
// se offset va bene
|
||||
|
||||
// se offset va bene
|
||||
if ( bNextOk) {
|
||||
// sistemo per prossimo step
|
||||
dCurrRad = dRad ;
|
||||
pOffs.Set( Release( pNextOffs)) ;
|
||||
pOffs.Set( GetCurveComposite( Release( pNextOffs))) ;
|
||||
// nuovo valore pari allo step
|
||||
dOffs = GetSideStep() ;
|
||||
dOffs = GetSideStep() ;
|
||||
}
|
||||
// se altrimenti riducibile, provo con offset ridotto al raggio utensile
|
||||
else if ( ! bSmallRad) {
|
||||
// nuovo valore pari al raggio
|
||||
dOffs = ( nIter == 0 ? dTRad + GetOffsR() : dTRad) ;
|
||||
}
|
||||
// altrimenti esco
|
||||
else
|
||||
// altrimenti se non ho più curve da analizzare esco
|
||||
else if ( vCrvStack.empty())
|
||||
break ;
|
||||
// incremento contatore iterazioni
|
||||
++ nIter ;
|
||||
}
|
||||
|
||||
|
||||
// calcolo i collegamenti
|
||||
ICURVEPOVECTOR vLinks( vOffs.size()) ;
|
||||
for ( int i = 1 ; i < int( vOffs.size()) ; ++ i) {
|
||||
@@ -3223,14 +3261,40 @@ Pocketing::CalcSpiral( const ICurveComposite* pCompo, int nReg, bool bSplitArcs,
|
||||
vOffs[i]->GetStartPoint( ptEnd) ;
|
||||
// calcolo il collegamento (garantendo che non esca dalla svuotatura)
|
||||
PtrOwner<ICurveComposite> pCrvLink( CreateCurveComposite()) ;
|
||||
if ( CalcBoundedLink( ptStart, ptEnd, vOffs[0], pCrvLink))
|
||||
if ( CalcBoundedLink( ptStart, ptEnd, vOffs[0], pCrvLink)) {
|
||||
|
||||
// Superficie coperta dal tool quando percorre il collegamento
|
||||
const ICurve * pCrvLinkTmp = pCrvLink->GetFirstCurve() ;
|
||||
while ( pCrvLinkTmp != nullptr) {
|
||||
if ( pCrvLinkTmp->GetType() == CRV_LINE) {
|
||||
Point3d ptS, ptE ;
|
||||
pCrvLinkTmp->GetStartPoint( ptS) ;
|
||||
pCrvLinkTmp->GetEndPoint( ptE) ;
|
||||
ICurveComposite * pCrvTmp = CreateCurveComposite() ;
|
||||
pCrvTmp->AddPoint( ptS) ;
|
||||
pCrvTmp->AddLine( ptE) ;
|
||||
pCrvTmp->AddLine( ptS) ;
|
||||
pCrvTmp->SetExtrusion( vtExtr) ;
|
||||
OffsetCurve OffsCrvPlus ;
|
||||
OffsCrvPlus.Make( pCrvTmp, m_TParams.m_dDiam / 2 + 10 * EPS_SMALL, ICurve::OFF_FILLET) ;
|
||||
ICurve * pCrvOffPlus = OffsCrvPlus.GetLongerCurve() ;
|
||||
|
||||
ISurfFlatRegion * pSrf = CreateSurfFlatRegion() ;
|
||||
pSrf->AddExtLoop( pCrvOffPlus) ;
|
||||
pCutRegion->Add( *(pSrf->Clone())) ;
|
||||
}
|
||||
pCrvLinkTmp = pCrvLink->GetNextCurve() ;
|
||||
}
|
||||
|
||||
// Aggiungo il collegamento
|
||||
vLinks[i].Set( Release( pCrvLink)) ;
|
||||
}
|
||||
else {
|
||||
m_pMchMgr->SetLastError( 2413, "Error in Pocketing : Toolpath not computable") ;
|
||||
return false ;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// calcolo il percorso di ritorno
|
||||
if ( vOffs.size() >= 2) {
|
||||
// punti di inizio e fine
|
||||
@@ -3254,8 +3318,14 @@ Pocketing::CalcSpiral( const ICurveComposite* pCompo, int nReg, bool bSplitArcs,
|
||||
m_pMchMgr->SetLastError( 2413, "Error in Pocketing : Toolpath not computable") ;
|
||||
return false ;
|
||||
}
|
||||
}
|
||||
|
||||
// rimuovo aree non lavorate
|
||||
if ( pCutRegion->GetLoopCount( 0) > 1 && ! RemoveUncutRegions( pCutRegion, vOffs)) {
|
||||
m_pMchMgr->SetLastError( 2413, "Error in Pocketing : removal of uncut regions failed") ;
|
||||
return false ;
|
||||
}
|
||||
|
||||
|
||||
// creo il percorso di lavoro a partire dalla raccolta degli offset e dei collegamenti
|
||||
for ( int i = 0 ; i < int( vOffs.size()) ; ++ i) {
|
||||
// se collegamento da aggiungere
|
||||
@@ -3266,16 +3336,16 @@ Pocketing::CalcSpiral( const ICurveComposite* pCompo, int nReg, bool bSplitArcs,
|
||||
// se richiesta percorrenza invertita
|
||||
if ( m_Params.m_bInvert)
|
||||
vOffs[i]->Invert() ;
|
||||
// aggiungo la curva
|
||||
pMCrv->AddCurve( Release( vOffs[i])) ;
|
||||
// aggiungo la curva
|
||||
pMCrv->AddCurve( Release( vOffs[i])) ;
|
||||
}
|
||||
|
||||
|
||||
// verifico il percorso di lavoro
|
||||
if ( pMCrv->GetCurveCount() == 0) {
|
||||
m_pMchMgr->SetLastError( 2413, "Error in Pocketing : Toolpath not computable") ;
|
||||
return false ;
|
||||
}
|
||||
// se necessario, approssimo archi con rette
|
||||
// se necessario, approssimo archi con rette
|
||||
if ( bSplitArcs && ! ApproxWithLines( pMCrv)) {
|
||||
m_pMchMgr->SetLastError( 2421, "Error in Pocketing : Linear Approx not computable") ;
|
||||
return false ;
|
||||
@@ -3283,14 +3353,14 @@ Pocketing::CalcSpiral( const ICurveComposite* pCompo, int nReg, bool bSplitArcs,
|
||||
// eventuale sistemazione archi
|
||||
VerifyArcs( pMCrv) ;
|
||||
|
||||
return true ;
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
Pocketing::CalcBoundedLink( const Point3d& ptStart, const Point3d& ptEnd, const ICurve* pCrvBound,
|
||||
ICurveComposite* pCrvLink)
|
||||
{
|
||||
{
|
||||
// recupero il vettore estrusione
|
||||
Vector3d vtExtr ;
|
||||
pCrvBound->GetExtrusion( vtExtr) ;
|
||||
@@ -3337,8 +3407,8 @@ Pocketing::CalcBoundedLink( const Point3d& ptStart, const Point3d& ptEnd, const
|
||||
// recupero i due possibili percorsi e uso il più corto
|
||||
PtrOwner<ICurve> pCrvA( pCrvBound->CopyParamRange( dOffS, dOffE)) ;
|
||||
PtrOwner<ICurve> pCrvB( pCrvBound->CopyParamRange( dOffE, dOffS)) ;
|
||||
if ( IsNull( pCrvA) || IsNull( pCrvB))
|
||||
return false ;
|
||||
if ( IsNull( pCrvA) || IsNull( pCrvB))
|
||||
return false ;
|
||||
double dLenA ; pCrvA->GetLength( dLenA) ;
|
||||
double dLenB ; pCrvB->GetLength( dLenB) ;
|
||||
if ( dLenA < dLenB) {
|
||||
@@ -3350,7 +3420,7 @@ Pocketing::CalcBoundedLink( const Point3d& ptStart, const Point3d& ptEnd, const
|
||||
}
|
||||
}
|
||||
}
|
||||
pCrvLink->AddCurve( Release( pCompo)) ;
|
||||
pCrvLink->AddCurve( Release( pCompo)) ;
|
||||
return true ;
|
||||
}
|
||||
}
|
||||
@@ -4117,3 +4187,334 @@ Pocketing::VerifyLeadInZigZag( const ICurveComposite* pCompo, const Point3d& ptP
|
||||
return false ;
|
||||
return ( dMinDistPa > 0.5 * m_TParams.m_dDiam - 10 * EPS_SMALL && dMinDistPb > 0.5 * m_TParams.m_dDiam - 10 * EPS_SMALL) ;
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
Pocketing::RemoveUncutRegions( const ISurfFlatRegion * pCutRegion, ICURVEPOVECTOR& vOffs)
|
||||
{
|
||||
// Conservo le curve vOffs originali in vettore Tmp da usare per i calcoli sui percorsi aggiuntivi
|
||||
ICRVCOMPOPOVECTOR vOffsTmp( vOffs.size()) ;
|
||||
for ( size_t i = 0 ; i < vOffs.size() ; i++)
|
||||
vOffsTmp[i].Set( GetCurveComposite( vOffs[i]->Clone())) ;
|
||||
|
||||
ISurfFlatRegion * pNewCutRegion = pCutRegion->Clone() ;
|
||||
bool bAddedPaths = false ;
|
||||
|
||||
// analizzo tutte le aree non lavorate
|
||||
int nLoops = pCutRegion->GetLoopCount(0) ;
|
||||
for ( int i = 1 ; i < nLoops ; i++) {
|
||||
|
||||
// regione non lavorata
|
||||
ICurve * pResidualCrv = pCutRegion->GetLoop( 0, i) ;
|
||||
if ( pResidualCrv == nullptr || ! pResidualCrv->IsValid())
|
||||
continue ;
|
||||
|
||||
// cerco la curva di vOffs su cui andrà il percorso aggiuntivo
|
||||
size_t idx ; // indice della curva in vOffs
|
||||
Point3d ptCrit ; // punto in cui aggiungere il percorso extra
|
||||
double dParCrit ; // parametro corrispondente a ptCrit
|
||||
|
||||
if ( ! FindCurveForPathAdd( pResidualCrv, vOffsTmp, idx, ptCrit, dParCrit))
|
||||
return false ;
|
||||
|
||||
// calcolo la lunghezza del tratto da aggiungere basandomi sull'angolo e sull'overlap
|
||||
Point3d ptNew ;
|
||||
bool bUsePtNew = false ;
|
||||
|
||||
// se sono sul punto di congiunzione fra due curve
|
||||
if ( vOffsTmp[idx]->IsParamAtJoint( dParCrit)) {
|
||||
const ICurve* pCrv1 = dParCrit < EPS_SMALL ? vOffsTmp[idx]->GetLastCurve() : vOffsTmp[idx]->GetCurve( int( dParCrit + 0.5) - 1) ;
|
||||
const ICurve* pCrv2 = vOffsTmp[idx]->GetCurve( int( dParCrit + 0.5)) ;
|
||||
// se le due curve sono due linee
|
||||
if ( pCrv1->GetType() == CRV_LINE && pCrv2->GetType() == CRV_LINE) {
|
||||
// calcolo angolo formato dalle due linee
|
||||
Vector3d vt1, vt2 ;
|
||||
vOffsTmp[idx]->GetPointTang( dParCrit, ICurve::FROM_MINUS, Point3d(), vt1) ;
|
||||
vOffsTmp[idx]->GetPointTang( dParCrit, ICurve::FROM_PLUS, Point3d(), vt2) ;
|
||||
vt2.Invert() ;
|
||||
double dCosAng = vt1 * vt2 ;
|
||||
|
||||
// calcolo lunghezza basandomi sull'angolo e sull'overlap
|
||||
double dAngSin = sqrt( (1 - dCosAng) / 2) ;
|
||||
double dOverlap = 1 - GetSideStep() / m_TParams.m_dDiam ;
|
||||
double dLen = dAngSin > EPS_ANG_SMALL ? (( m_TParams.m_dDiam / 2 - m_TParams.m_dDiam * dOverlap) / dAngSin - m_TParams.m_dDiam / 2) : - 1.0 ;
|
||||
|
||||
Point3d ptCen ;
|
||||
pResidualCrv->GetCentroid( ptCen) ;
|
||||
Vector3d vtDir = ptCen - ptCrit ;
|
||||
vtDir.Normalize() ;
|
||||
ptNew = ptCrit + dLen * vtDir ;
|
||||
bUsePtNew = dLen > 0 ;
|
||||
}
|
||||
}
|
||||
|
||||
// calcolo il percorso aggiuntivo
|
||||
ICurveComposite * pAddPath = CreateCurveComposite() ;
|
||||
if ( ! ComputeAdditionalPath( ptCrit, ptNew, bUsePtNew, pAddPath, pResidualCrv, vOffsTmp[0], pNewCutRegion))
|
||||
return false ;
|
||||
|
||||
// se non ho aggiunto alcun percorso passo alla prossima regione residua
|
||||
if ( pAddPath->GetCurveCount() == 0)
|
||||
continue ;
|
||||
|
||||
// nuova curva di offset con tratti aggiuntivi
|
||||
bAddedPaths = true ;
|
||||
PtrOwner<ICurveComposite> pNewOffs( CreateCurveComposite()) ;
|
||||
double dPar, dParS, dParE ;
|
||||
vOffs[idx]->GetDomain( dParS, dParE) ;
|
||||
vOffs[idx]->GetParamAtPoint( ptCrit, dPar) ;
|
||||
pNewOffs->AddCurve( vOffs[idx]->CopyParamRange( dParS, dPar)) ; // fino al punto critico è il vecchio offset
|
||||
pNewOffs->AddCurve( pAddPath) ; // al punto critico aggiungo il nuovo percorso
|
||||
if ( abs( dPar - dParS) > EPS_SMALL && abs( dPar - dParE) > EPS_SMALL)
|
||||
pNewOffs->AddCurve( vOffs[idx]->CopyParamRange( dPar, dParE)) ; // aggiungo la parte rimanente del vecchio offset
|
||||
|
||||
vOffs[idx].Set( Release( pNewOffs)) ;
|
||||
}
|
||||
|
||||
// Se ho aggiunto nuovi percorsi, verifico se sono rimaste aree non lavorate e le rimuovo
|
||||
if ( bAddedPaths && pNewCutRegion->GetLoopCount( 0) > 1)
|
||||
if ( ! RemoveUncutRegions( pNewCutRegion, vOffs))
|
||||
return false ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
Pocketing::FindCurveForPathAdd( const ICurve* pResidualCrv, const ICRVCOMPOPOVECTOR& vOffs, size_t& nIdxMin, Point3d& ptMinDist,
|
||||
double& dMinDistPar)
|
||||
{
|
||||
nIdxMin = -1 ;
|
||||
double dMinDist = INFINITO ;
|
||||
|
||||
Vector3d vtExtr ;
|
||||
vOffs[0]->GetExtrusion( vtExtr) ;
|
||||
Frame3d frLoc ;
|
||||
frLoc.Set( ORIG, vtExtr) ;
|
||||
// porto le curve in questo riferimento
|
||||
CurveLocal pCrvLoc( pResidualCrv, GLOB_FRM, frLoc) ;
|
||||
|
||||
for ( size_t i = 1 ; i < vOffs.size() ; i ++) {
|
||||
|
||||
// verifico se la parte da rimuovere ( pResidualCrv) è esterna alla regione racchiusa da vOffs[i]
|
||||
CurveLocal pOffsLoc( vOffs[i]->Clone(), GLOB_FRM, frLoc) ;
|
||||
IntersCurveCurve intersCC( *pCrvLoc, *pOffsLoc) ;
|
||||
|
||||
if ( intersCC.GetRegionCurveClassification() != CCREGC_NULL && intersCC.GetRegionCurveClassification() != CCREGC_IN1) {
|
||||
|
||||
double dParS, dParE ;
|
||||
vOffs[i]->GetDomain( dParS, dParE) ;
|
||||
// considero i punti di congiunzione fra le curve di vOffs[i]
|
||||
for ( int j = int( dParS + 0.5) ; j < int( dParE + 0.5) ; j ++) {
|
||||
|
||||
// calcolo il punto più vicino su pResidualCrv
|
||||
Point3d ptCrv ;
|
||||
vOffs[i]->GetPointD1D2( j, ICurve::FROM_MINUS, ptCrv) ;
|
||||
DistPointCurve distPtCrv( ptCrv, *pResidualCrv) ;
|
||||
int nFlag ;
|
||||
Point3d ptResCrv ;
|
||||
distPtCrv.GetMinDistPoint( 0, ptResCrv, nFlag) ;
|
||||
|
||||
// calcolo la distanza come lunghezza del percorso interno alla svuotatura che li congiunge
|
||||
ICurveComposite * pLinkPath = CreateCurveComposite() ;
|
||||
if ( ! CalcBoundedLink( ptCrv, ptResCrv, vOffs[0], pLinkPath))
|
||||
continue ;
|
||||
double dLen ;
|
||||
if ( pLinkPath->GetLength( dLen) && dLen < dMinDist) {
|
||||
dMinDist = dLen ;
|
||||
nIdxMin = i ;
|
||||
ptMinDist = ptCrv ;
|
||||
dMinDistPar = j ;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( nIdxMin == -1 )
|
||||
return false ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
Pocketing::ComputeAdditionalPath( const Point3d ptStart, Point3d ptEnd, bool bUsePtEnd, ICurveComposite * pAddPath,
|
||||
const ICurve * pResidualCrv, const ICurve * pCrvBound, ISurfFlatRegion * pNewCutRegion)
|
||||
{
|
||||
ICurveComposite * pResidualCrvClosed = GetCurveComposite( pResidualCrv->Clone()) ;
|
||||
if ( ! pResidualCrv->IsClosed())
|
||||
pResidualCrvClosed->Close() ;
|
||||
|
||||
// Se chiudendo la curva creo autointersezione, conservo la sottoparte di curva più lunga che non si autointerseca
|
||||
SelfIntersCurve SelfIntersC( *pResidualCrvClosed) ;
|
||||
if ( SelfIntersC.GetIntersCount() == 1) {
|
||||
IntCrvCrvInfo aInfo ;
|
||||
SelfIntersC.GetIntCrvCrvInfo( 0, aInfo) ;
|
||||
double dParS, dParE ;
|
||||
pResidualCrvClosed->GetDomain( dParS, dParE) ;
|
||||
ICurveComposite * pCrvTmp1 = GetCurveComposite( pResidualCrvClosed->CopyParamRange( dParS, aInfo.IciA[0].dU)) ;
|
||||
pCrvTmp1->AddCurve( pResidualCrvClosed->CopyParamRange( aInfo.IciB[0].dU, dParE)) ;
|
||||
ICurveComposite * pCrvTmp2 = GetCurveComposite( pResidualCrvClosed->CopyParamRange( aInfo.IciA[0].dU, aInfo.IciB[0].dU)) ;
|
||||
double dLen1 = 0.0, dLen2 = 0.0 ;
|
||||
pCrvTmp1->GetLength( dLen1) ;
|
||||
pCrvTmp2->GetLength( dLen2) ;
|
||||
|
||||
pResidualCrvClosed = dLen1 > dLen2 ? pCrvTmp1->Clone() : pCrvTmp2->Clone() ;
|
||||
}
|
||||
|
||||
// verifico che area non sia troppo piccola
|
||||
double dArea = 0.0 ;
|
||||
Plane3d plPlane ;
|
||||
if ( pResidualCrvClosed->GetArea( plPlane, dArea) && dArea < 10 * EPS_SMALL)
|
||||
return true ;
|
||||
|
||||
// inverto direzione della curve per essere coerente con pAddSrf quando credo la superficie
|
||||
if ( AreOppositeVectorApprox( plPlane.GetVersN(), pNewCutRegion->GetNormVersor()))
|
||||
pResidualCrvClosed->Invert() ;
|
||||
|
||||
// scelta del punto finale
|
||||
if ( ! bUsePtEnd) {
|
||||
pResidualCrv->GetCentroid( ptEnd) ;
|
||||
|
||||
ISurfTriMesh* pResidualSrfTm = GetSurfTriMeshByFlatContour( pResidualCrvClosed) ;
|
||||
dArea = 0.0 ;
|
||||
if ( pResidualSrfTm != nullptr && pResidualSrfTm->GetArea( dArea) && dArea < 10 * EPS_SMALL)
|
||||
return true ;
|
||||
|
||||
// se regione è abbastanza grande e il centroide non è interno alla regione chiamo la funzione specifica
|
||||
if ( dArea > 5) {
|
||||
DistPointSurfTm DistPtSTm( ptEnd, *pResidualSrfTm) ;
|
||||
Point3d ptMinDist ;
|
||||
if ( DistPtSTm.GetMinDistPoint( ptMinDist) && ! AreSamePointApprox( ptEnd, ptMinDist))
|
||||
return AdditionalPathExternalCentroid( ptStart, pAddPath, pResidualCrvClosed, pCrvBound, pNewCutRegion) ;
|
||||
}
|
||||
}
|
||||
|
||||
// se il punto iniziale e finale coincidono, scelgo un nuovo ptEnd
|
||||
if ( AreSamePointEpsilon( ptStart, ptEnd, 1e-2)) {
|
||||
Point3d ptMid ;
|
||||
pResidualCrv->GetMidPoint( ptMid) ;
|
||||
Vector3d vtDir = ptMid - ptStart ;
|
||||
vtDir.Normalize() ;
|
||||
double len = Dist( ptStart, ptMid) + 10 * EPS_SMALL - m_TParams.m_dDiam / 2 ;
|
||||
ptEnd = ptStart + len * vtDir ;
|
||||
}
|
||||
|
||||
// creo il percorso fra ptStart e ptEnd senza uscire dalla svuotatura
|
||||
if ( ! CalcBoundedLink( ptStart, ptEnd, pCrvBound, pAddPath))
|
||||
return false ;
|
||||
|
||||
ICurveComposite * pReturnPath = pAddPath->Clone() ; // percorso di ritorno
|
||||
pReturnPath->Invert() ;
|
||||
|
||||
// regione svuotata da pAddPath
|
||||
ICurveComposite * pAddPathTmp = CreateCurveComposite() ;
|
||||
pAddPathTmp->AddCurve( pAddPath->Clone()) ;
|
||||
pAddPathTmp->AddCurve( pReturnPath->Clone()) ;
|
||||
Vector3d vtExtr ;
|
||||
pResidualCrv->GetExtrusion( vtExtr) ;
|
||||
pAddPathTmp->SetExtrusion( vtExtr) ;
|
||||
|
||||
OffsetCurve OffsCrv ;
|
||||
OffsCrv.Make( pAddPathTmp, m_TParams.m_dDiam / 2 + 10 * EPS_SMALL, ICurve::OFF_FILLET) ;
|
||||
ICurve * pCrvOffs = OffsCrv.GetLongerCurve() ;
|
||||
ISurfFlatRegion * pToolSrf = CreateSurfFlatRegion() ;
|
||||
pToolSrf->AddExtLoop( pCrvOffs->Clone()) ;
|
||||
while ( OffsCrv.GetCurveCount() != 0) {
|
||||
ICurve * pCrvOffs2 = OffsCrv.GetCurve() ;
|
||||
pToolSrf->AddIntLoop( pCrvOffs2->Clone()) ;
|
||||
}
|
||||
|
||||
// aggiorno la superficie lavorata
|
||||
if ( ! pNewCutRegion->Add( *pToolSrf))
|
||||
return false ;
|
||||
|
||||
// porto le curva in locale per farne intersezione
|
||||
Frame3d frLoc ;
|
||||
frLoc.Set( ORIG, vtExtr) ;
|
||||
CurveLocal pResidualCrvLoc( pResidualCrv, GLOB_FRM, frLoc) ;
|
||||
CurveLocal pOffsCrvLoc( pCrvOffs, GLOB_FRM, frLoc) ;
|
||||
|
||||
IntersCurveCurve intersCC( *pResidualCrvLoc, *pOffsCrvLoc) ;
|
||||
CRVCVECTOR ccClass ;
|
||||
intersCC.GetCurveClassification( 0, ccClass) ;
|
||||
|
||||
// ricorsione su eventuali aree non lavorate rimaste
|
||||
size_t nFirst = 0 ;
|
||||
size_t nLast = ccClass.size() ;
|
||||
|
||||
// verifico se posso trattare in una volta sola la parte inziale e finale della curva
|
||||
if ( pResidualCrv->IsClosed() && ccClass.front().nClass == CRVC_OUT && ccClass.back().nClass == CRVC_OUT) {
|
||||
ICurveComposite* pNewResidualCrv = CreateCurveComposite() ;
|
||||
pNewResidualCrv->AddCurve( pResidualCrv->CopyParamRange( ccClass.back().dParS, ccClass.back().dParE)) ;
|
||||
pNewResidualCrv->AddCurve( pResidualCrv->CopyParamRange( ccClass.front().dParS, ccClass.front().dParE)) ;
|
||||
ICurveComposite * pNewAddPath = CreateCurveComposite() ;
|
||||
if ( ! ComputeAdditionalPath( ptEnd, Point3d(), false, pNewAddPath, pNewResidualCrv, pCrvBound, pNewCutRegion))
|
||||
return false ;
|
||||
pAddPath->AddCurve( pNewAddPath->Clone()) ;
|
||||
|
||||
nFirst = 1 ;
|
||||
nLast = ccClass.size() - 1 ;
|
||||
}
|
||||
|
||||
for ( size_t i = nFirst ; i < nLast ; i++) {
|
||||
if ( ccClass[i].nClass == CRVC_OUT ) {
|
||||
ICurve * pNewResidualCrv = pResidualCrv->CopyParamRange( ccClass[i].dParS, ccClass[i].dParE) ;
|
||||
ICurveComposite * pNewAddPath = CreateCurveComposite() ;
|
||||
if ( ! ComputeAdditionalPath( ptEnd, Point3d(), false, pNewAddPath, pNewResidualCrv, pCrvBound, pNewCutRegion))
|
||||
return false ;
|
||||
pAddPath->AddCurve( pNewAddPath) ;
|
||||
}
|
||||
}
|
||||
|
||||
pAddPath->AddCurve( pReturnPath) ; // percorso di ritorno
|
||||
return true ;
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
Pocketing::AdditionalPathExternalCentroid( const Point3d ptStart, ICurveComposite * pAddPath, ICurveComposite * pResidualCrv,
|
||||
const ICurve * pCrvBound, ISurfFlatRegion * pNewCutRegion)
|
||||
{
|
||||
DistPointCurve distPtCrv( ptStart, *pResidualCrv) ;
|
||||
double dParam ;
|
||||
int nFlag ;
|
||||
Point3d ptEnd ;
|
||||
distPtCrv.GetParamAtMinDistPoint( 0, dParam, nFlag) ;
|
||||
distPtCrv.GetMinDistPoint( 0, ptEnd, nFlag) ;
|
||||
pResidualCrv->ChangeStartPoint( dParam) ;
|
||||
|
||||
if ( ! CalcBoundedLink( ptStart, ptEnd, pCrvBound, pAddPath))
|
||||
return false ;
|
||||
|
||||
ICurveComposite * pReturnPath = pAddPath->Clone() ; // percorso di ritorno
|
||||
pReturnPath->Invert() ;
|
||||
|
||||
pAddPath->AddCurve( pResidualCrv) ;
|
||||
pAddPath->AddCurve( pReturnPath) ;
|
||||
|
||||
// area coperta da pAddPath
|
||||
ISurfFlatRegion * pToolSrf = CreateSurfFlatRegion() ;
|
||||
OffsetCurve OffsCrvPlus ;
|
||||
OffsCrvPlus.Make( pAddPath, m_TParams.m_dDiam / 2 + 5 * EPS_SMALL, ICurve::OFF_FILLET) ;
|
||||
ICurve * pCrvOffPlus = OffsCrvPlus.GetLongerCurve() ;
|
||||
ISurfFlatRegion * pSrf = CreateSurfFlatRegion() ;
|
||||
pToolSrf->AddExtLoop( pCrvOffPlus->Clone()) ;
|
||||
|
||||
OffsetCurve OffsCrvMinus ;
|
||||
OffsCrvMinus.Make( pAddPath, - m_TParams.m_dDiam / 2 - 5 * EPS_SMALL, ICurve::OFF_FILLET) ;
|
||||
ICurveComposite * pCrvOffMinus = GetCurveComposite( OffsCrvMinus.GetLongerCurve()) ;
|
||||
while ( pCrvOffMinus != nullptr) {
|
||||
if ( GetCurveRadius( pCrvOffMinus) > EPS_ZERO)
|
||||
pToolSrf->AddIntLoop( pCrvOffMinus) ;
|
||||
pCrvOffMinus = GetCurveComposite( OffsCrvMinus.GetCurve()) ;
|
||||
}
|
||||
|
||||
// aggiorno la superficie lavorata
|
||||
if ( ! pNewCutRegion->Add( *pToolSrf))
|
||||
return false ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
@@ -18,6 +18,7 @@
|
||||
#include "ToolData.h"
|
||||
#include "/EgtDev/Include/EGkCurveComposite.h"
|
||||
#include "/EgtDev/Include/EgtNumUtils.h"
|
||||
#include "/EgtDev/Include/EgkSurfFlatRegion.h"
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
class Pocketing : public Machining
|
||||
@@ -86,6 +87,13 @@ class Pocketing : public Machining
|
||||
double dDepth, double dElev, double dOkStep, bool bSplitArcs) ;
|
||||
bool CalcSpiral( const ICurveComposite* pCompo, int nReg, bool bSplitArcs,
|
||||
ICurveComposite* pMCrv, ICurveComposite* pRCrv) ;
|
||||
bool RemoveUncutRegions( const ISurfFlatRegion * pCutRegion, ICURVEPOVECTOR& vOffs) ;
|
||||
bool FindCurveForPathAdd( const ICurve * pResidualCrv, const ICRVCOMPOPOVECTOR& vOffs, size_t& nIdxMin, Point3d& ptMinDist,
|
||||
double& dMinDistPar) ;
|
||||
bool ComputeAdditionalPath( const Point3d ptStart, Point3d ptNew, bool bUsePtEnd, ICurveComposite * pAddPath,
|
||||
const ICurve * pResidualCrv, const ICurve * pCrvBound, ISurfFlatRegion * pNewCutRegion) ;
|
||||
bool AdditionalPathExternalCentroid( const Point3d ptStart, ICurveComposite * pAddPath, ICurveComposite * pResidualCrv,
|
||||
const ICurve * pCrvBound, ISurfFlatRegion * pNewCutRegion) ;
|
||||
bool CalcBoundedLink( const Point3d& ptStart, const Point3d& ptEnd, const ICurve* pCrvBound,
|
||||
ICurveComposite* pCrvLink) ;
|
||||
bool CalcCircleSpiral( const Point3d& ptCen, const Vector3d& vtN, double dOutRad, double dIntRad,
|
||||
|
||||
Reference in New Issue
Block a user