EgtMachKernel :

- ottimizzazioni offset per centroidi e medial Axis
- ottimizzazione percorsi di medial Axis ( raccordi con centroidi ).
This commit is contained in:
Riccardo Elitropi
2023-03-30 18:01:05 +02:00
parent 0911f167b1
commit 25b940927e
2 changed files with 58 additions and 76 deletions
+57 -76
View File
@@ -5185,6 +5185,7 @@ Pocketing::CalcSpiral( const ISurfFlatRegion* pSrfPock, int& nReg, Point3d& ptSt
// 3) controllo eventuali parti non svuotate...
PtrOwner<ISurfFlatRegion> 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 ;
@@ -5260,7 +5261,8 @@ Pocketing::CalcSpiral( const ISurfFlatRegion* pSrfPock, int& nReg, Point3d& ptSt
//----------------------------------------------------------------------------
bool
Pocketing::ModifyCurveToSmoothed( ICurveComposite* pCrv, double dRightPer, double dLeftPer) {
Pocketing::ModifyCurveToSmoothed( ICurveComposite* pCrv, double dRightPer, double dLeftPer)
{
// controllo parametri
if ( pCrv == nullptr)
@@ -6446,10 +6448,10 @@ Pocketing::RemoveExtraPartByMedialAxis( const ISurfFlatRegion* pChunkToCut, ICRV
return false ;
// creo un percorso chiuso ...
PtrOwner<ICurveComposite> pCrvPathClosed( CloneCurveComposite( pCrvPath)) ;
if ( IsNull( pCrvPathClosed))
return false ;
pCrvPathClosed->AddCurve( pCrvCoBackLink->Clone()) ; // percorso chiuso con tutti i medial Axis Collegati
//PtrOwner<ICurveComposite> pCrvPathClosed( CloneCurveComposite( pCrvPath)) ;
//if ( IsNull( pCrvPathClosed))
// return false ;
//pCrvPathClosed->AddCurve( pCrvCoBackLink->Clone()) ; // percorso chiuso con tutti i medial Axis Collegati
// se ho trovato dei centroidi li unisco nei punti più vicini a questo percorso
for ( int i = 0 ; i < int( vPtCentroid.size()) ; ++ i) {
@@ -6458,16 +6460,21 @@ Pocketing::RemoveExtraPartByMedialAxis( const ISurfFlatRegion* pChunkToCut, ICRV
Point3d ptClosestOnPath ; int nFlag ;
if ( ! DistPointCurve( vPtCentroid[i], *pCrvPath).GetMinDistPoint( EPS_SMALL, ptClosestOnPath, nFlag))
return false ;
// 2) lo imposto come punto iniziale della curva chiusa
// 2) spezzo la curva al paramtro del punto più vicino
double dU ;
if ( ! pCrvPathClosed->GetParamAtPoint( ptClosestOnPath, dU))
if ( ! pCrvPath->GetParamAtPoint( ptClosestOnPath, dU))
return false ;
pCrvPath->ChangeStartPoint( dU) ;
// 3) prendo il vettore tangente al percorso nel punto PtClosestOnPath
Vector3d vtTanCpt ;
PtrOwner<ICurveComposite> pCrvCoHelpToTan( pCrvPathClosed->Clone()) ;
if( IsNull( pCrvCoHelpToTan) || ! pCrvCoHelpToTan->GetStartDir( vtTanCpt))
PtrOwner<ICurveComposite> pCrvA( GetCurveComposite( pCrvPath->CopyParamRange( 0, dU))) ;
if( IsNull( pCrvA))
return false ;
PtrOwner<ICurveComposite> pCrvB( GetCurveComposite( pCrvPath->CopyParamRange( dU, pCrvPath->GetCurveCount()))) ;
if( IsNull( pCrvB))
return false ;
// 3) prendo il vettore tangente al percorso nel punto trovato nel pCrvPath
Vector3d vtTanCpt ; Point3d ptH ;
if ( ! pCrvPath->GetPointTang( dU, ICurve::FROM_MINUS, ptH, vtTanCpt))
return false ;
// 4) collego i due punti (centroide e punto più vicino alla curva)
@@ -6476,28 +6483,16 @@ Pocketing::RemoveExtraPartByMedialAxis( const ISurfFlatRegion* pChunkToCut, ICRV
return false ;
if ( ! CalcBoundedSmootedLink( ptClosestOnPath, vtTanCpt, vPtCentroid[i], vtTanCpt, 0, vOffsFirstCurve, pCrvPath1))
if( ! CalcBoundedLink( ptClosestOnPath, vPtCentroid[i], vOffsFirstCurve, pCrvPath1))
if ( ! CalcBoundedLink( ptClosestOnPath, vPtCentroid[i], vOffsFirstCurve, pCrvPath1))
return false ;
if ( ! pCrvPathClosed->AddCurve( pCrvPath1->Clone())) {
pCrvPath->Clear() ;
pCrvPath->AddCurve( Release( pCrvA)) ;
if( ! pCrvPath->AddCurve( Release( pCrvPath1)))
return false ;
}
pCrvPath->AddCurve( Release( pCrvB)) ;
}
// riprendo il punto iniziale
double dU ;
if ( ! pCrvPathClosed->GetParamAtPoint( ptSOriginal, dU))
return false ;
pCrvPathClosed->ChangeStartPoint( dU) ;
// riprendo il punto finale
if ( ! pCrvPathClosed->GetParamAtPoint( ptEOriginal, dU))
return false ;
PtrOwner<ICurveComposite> ptCrvPathWithCut( GetCurveComposite( pCrvPathClosed->CopyParamRange( 0, dU))) ;
if ( ! IsNull( ptCrvPathWithCut) && ptCrvPathWithCut->IsValid()) {
pCrvPath->Clear() ;
pCrvPath->AddCurve( Release( ptCrvPathWithCut)) ;
}
// la curva resitituita è una curva aperta che ha come primo punto il punto iniziale del primo medialAxis
// la curva restituita collega tutti i medial Axis tra di loro
// la curva restitutita collega tutti i centroidi con delle circonferenze
@@ -8818,10 +8813,12 @@ Pocketing::AdaptSfrWithRaw( ISurfFlatRegion* pSrf, Vector3d vtTrasl, ICRVCOMPOPO
// 4) aggiungo le curve alla nuova superificie
pSrfFinal->AddExtLoop( Release( pCrvExt)) ;
for ( int i = 0 ; i < ( int)vCrvIsl.size() ; ++i)
for ( int i = 0 ; i < ( int)vCrvIsl.size() ; ++ i)
pSrfFinal->AddIntLoop( Release( vCrvIsl[i])) ;
}
// se parametrri Off+ sOTTR
// restituisco la nuova superificie
pSrf->Clear() ;
pSrf->CopyFrom( pSrfFinal) ;
@@ -10310,11 +10307,12 @@ bool
Pocketing::CheckIfOffsetIsNecessary( const ICurveComposite* pCrvOffs, const double dOffs, const int nOffsCount,
const int nIter, const Vector3d& vtN, bool& bInsert)
{
return true ;
// controllo dei parametri
if ( pCrvOffs == nullptr || ! pCrvOffs->IsValid() || pCrvOffs->GetCurveCount() == 0 || dOffs <= 0)
if ( pCrvOffs == nullptr || ! pCrvOffs->IsValid() || pCrvOffs->GetCurveCount() == 0 || dOffs < EPS_SMALL)
return false ;
bInsert = true ; // di base inserisco
bool bDoTheSame = false ;
if ( nIter != 0) { // controllo se sono almeno al secondo offset...
@@ -10330,8 +10328,9 @@ Pocketing::CheckIfOffsetIsNecessary( const ICurveComposite* pCrvOffs, const doub
else
return true ;
if ( ! OffsCrv.Make( pCrvOffs, abs( m_TParams.m_dDiam / 2 - dOffs) < 5 * EPS_SMALL ?
5 * EPS_SMALL : abs( - m_TParams.m_dDiam / 2 + dOffs) + 5 * EPS_SMALL , ICurve::OFF_FILLET))
// <- primo test
if( OffsCrv.GetCurveCount() > 1)
return true ;
PtrOwner<ICurve> pCrvOffLonger( OffsCrv.GetLongerCurve()) ;
@@ -10348,54 +10347,36 @@ Pocketing::CheckIfOffsetIsNecessary( const ICurveComposite* pCrvOffs, const doub
CRVCVECTOR ccClass ;
IntersCurveCurve intCC( *pCrvOffLonger, *pCrvTool) ;
intCC.GetCurveClassification( 1, EPS_SMALL, ccClass) ;
if (( int)ccClass.size() == 1 && ccClass[0].nClass == CRVC_OUT && nOffsCount > 0) {
if (( int)ccClass.size() == 1 && ccClass[0].nClass == CRVC_OUT) {
// CENTROIDE
bInsert = false ;
return true ;
}
ICRVCOMPOPOVECTOR vCrvInside ;
for ( int p = 0 ; p < ( int)ccClass.size() ; ++ p) {
if ( ccClass[p].nClass == CRVC_OUT) {
pCrvTool->ChangeStartPoint( 0.5 * ( ccClass[p].dParS + ccClass[p].dParE)) ;
break ;
}
}
// <- secondo test
IntersCurveCurve intCC1( *pCrvOffLonger, *pCrvTool) ;
intCC1.GetCurveClassification( 1, EPS_SMALL, ccClass) ;
bool bFirst = true ;
Point3d ptA, ptB ;
if (( int)ccClass.size() == 5 && nOffsCount > 0) {
// CENTROIDE
for ( int u = 0 ; u < ( int)ccClass.size() ; ++ u) {
if ( ccClass[u].nClass == CRVC_IN) {
if ( bFirst) {
pCrvTool->GetPointD1D2( 0.5 * ( ccClass[u].dParS + ccClass[u].dParE), ICurve::FROM_MINUS, ptA) ;
bFirst = false ;
}
else
pCrvTool->GetPointD1D2( 0.5 * ( ccClass[u].dParS + ccClass[u].dParE), ICurve::FROM_MINUS, ptB) ;
}
}
Frame3d frLoc ; frLoc.Set( ptC, vtN, ptA - ptB) ;
if( ! frLoc.IsValid())
return true ;
BBox3d bBox ;
pCrvOffLonger->GetBBox( frLoc, bBox) ;
double dDimX = bBox.GetDimX() ;
double dDimY = bBox.GetDimY() ;
if( dDimX < m_TParams.m_dDiam - 100 * EPS_SMALL ||
dDimY < m_TParams.m_dDiam - 100 * EPS_SMALL) {
bInsert = false ;
return true ;
}
}
else
PolyLine pl ;
if ( ! pCrvOffLonger->ApproxWithLines( 100 * EPS_SMALL, ANG_TOL_STD_DEG, ICurve::APL_STD, pl))
return true ;
Vector3d vtX ;
double dLen = 0 ; double dHeight = 0 ;
if( ! pl.GetMinAreaRectangleXY( ptC, vtX, dLen, dHeight))
return true ;
Frame3d frLoc ; frLoc.Set( ptC, vtN, vtX) ;
if( ! frLoc.IsValid())
return true ;
BBox3d bBox ;
frLoc.Invert() ;
pCrvOffLonger->GetBBox( frLoc, bBox) ;
double dDimX = bBox.GetDimX() ;
double dDimY = bBox.GetDimY() ;
if( dDimX < m_TParams.m_dDiam - 100 * EPS_SMALL ||
dDimY < m_TParams.m_dDiam - 100 * EPS_SMALL) {
bInsert = false ;
return true ;
}
}
return true ;
+1
View File
@@ -279,4 +279,5 @@ 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
} ;