EgtMachKernel :

- test codice per Isole aperte ed intersezioni grezzo con esse
- migliorie alle curve.
This commit is contained in:
Riccardo Elitropi
2023-06-13 14:33:25 +02:00
parent d46f94f8da
commit 1060a10491
2 changed files with 181 additions and 136 deletions
+177 -132
View File
@@ -1304,7 +1304,6 @@ Pocketing::GetCurves( SelData Id, ICURVEPLIST& lstPC)
// la restituisco
lstPC.emplace_back( Release( pCrvCompo)) ;
}
return true ;
}
// se altrimenti regione
@@ -1582,10 +1581,6 @@ Pocketing::ProcessPath( int nAuxId, int nPvId, int nClId)
if ( IsNull( pCompoOriCrv))
return false ;
// unisco le parti allineate (tranne inizio-fine se chiusa)
if ( ! pCompoOriCrv->MergeCurves( 10 * EPS_SMALL, 10 * EPS_ANG_SMALL, false, true))
return false ;
// ricavo le proprietà della curva
nProp0 = pCompoOriCrv->GetTempProp( 0) ; // id selezionato
nProp1 = pCompoOriCrv->GetTempProp( 1) ; // lato adiancente per Trimesh
@@ -1598,8 +1593,8 @@ Pocketing::ProcessPath( int nAuxId, int nPvId, int nClId)
}
// annullo i flag di tratto aperto
for ( int i = 0; i < int( pCompoOriCrv->GetCurveCount()) ; ++i)
pCompoOriCrv->SetCurveTempProp( i, 0, 0) ; // alla sottocurva
for ( int i = 0 ; i < int( pCompoOriCrv->GetCurveCount()) ; ++i)
pCompoOriCrv->SetCurveTempProp( i, 0, 0) ; // alla sottocurva
// aggiorno flag per lati aperti
if ( bSomeOpen) {
@@ -1609,6 +1604,17 @@ Pocketing::ProcessPath( int nAuxId, int nPvId, int nClId)
pCompoOriCrv->SetCurveTempProp( j, 1, 0) ; // alla sottocurva
}
// unisco le parti allineate (tranne inizio-fine se chiusa)
if ( ! pCompoOriCrv->MergeCurves( 10 * EPS_SMALL, 10 * EPS_ANG_SMALL, false, true))
return false ;
for ( int u = 0 ; u < pCompoOriCrv->GetCurveCount() ; ++ u)
{
int nProp ; pCompoOriCrv->GetCurveTempProp( u, nProp, 0) ;
int OOOO = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pCompoOriCrv->GetCurve( u)->Clone()) ;
m_pGeomDB->SetMaterial( OOOO, nProp == 0 ? BLUE : RED) ;
}
// recupero estrusione e spessore
Vector3d vtExtr_p = Z_AX ;
pCompoOriCrv->GetExtrusion( vtExtr_p) ;
@@ -1635,6 +1641,9 @@ Pocketing::ProcessPath( int nAuxId, int nPvId, int nClId)
pCompoOriCrv->SetTempProp( nProp0, 0) ; // a tutta la curva ( id selezionato )
pCompoOriCrv->SetTempProp( nProp1, 1) ; // a tutta la curva ( se Trimesh, faccia adiacente )
//int r = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pCompoOriCrv->Clone()) ;
//m_pGeomDB->SetMaterial( r, RED) ;
// controllo che le curve siano complanari e con stessa estrusione (la prima come riferimento)
Plane3d plAct ;
pCompoOriCrv->IsFlat( plAct) ;
@@ -1648,15 +1657,18 @@ Pocketing::ProcessPath( int nAuxId, int nPvId, int nClId)
}
else {
Vector3d vtN1, vtN2 ;
if ( abs( plAct.GetDist() - plAux.GetDist()) < EPS_SMALL
if ( abs( plAct.GetDist() - plAux.GetDist()) < 5 * EPS_SMALL
&& AreSameOrOppositeVectorApprox( plAct.GetVersN(), plAux.GetVersN()) // se stessa normale
&& AreSameVectorApprox( vtExtr, vtExtr_p)) { // se stessa estrusione
SrfByC.AddCurve( pCompoOriCrv->Clone()) ;
PtrOwner<ICurve> pCrvProjected( ProjectCurveOnPlane( *pCompoOriCrv, plAux)) ;
pCrvProjected->SetExtrusion( vtExtr) ;
// prendo Thickness Massima tra tutte le curve dei chunks
double dCurrThink ;
pCompoOriCrv->GetThickness( dCurrThink) ;
if ( dCurrThink > dThick)
dThick = dCurrThink ;
double dCurrThick ;
pCompoOriCrv->GetThickness( dCurrThick) ;
if ( dCurrThick > dThick)
dThick = dCurrThick ;
pCrvProjected->SetThickness( dCurrThick) ;
SrfByC.AddCurve( pCrvProjected->Clone()) ;
}
}
@@ -4433,7 +4445,7 @@ Pocketing::AddSpiralIn( const ISurfFlatRegion* pSrfPock, /*PNTVECTOR vPtStart,*/
}
// ---------------------------------------------------------------------------------------------
Point3d ptP1 ; // per LeadIn()
Point3d ptP1 ; // per LeadIn
// ciclo su tutti gli step
for ( int j = 1 ; j <= nStep ; ++ j) {
@@ -5184,8 +5196,10 @@ Pocketing::CalcSpiral( const ISurfFlatRegion* pSrfPock, int& nReg, Point3d& ptSt
while ( nIter < MAX_ITER) {
// salvo la regione
pSrfPrec.Set( pSrfAct->Clone()) ;
if ( ! pSrfAct->Offset( - dOffs, ICurve::OFF_FILLET))
if ( ! pSrfAct->Offset( - dOffs, ICurve::OFF_FILLET)) {
m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pSrfPrec->Clone()) ;
return false ;
}
// estraggo il contorno della FlatRegion (ciclo i Chunks e prendo i rispettivi Loops)
if ( nIter == 0) {
@@ -6830,11 +6844,13 @@ Pocketing::CalcBoundedLink( const Point3d& ptStart, const Point3d& ptEnd, ICRVCO
//------------------------------------------------------------------------------
bool
Pocketing::CalcBoundedSmootedLink( const Point3d& ptStart, const Vector3d& vtStart, const Point3d& ptEnd, const Vector3d& vtEnd, double dParMeet, ICRVCOMPOPOVECTOR& vOffIslands, ICurveComposite* pCrvLink) {
Pocketing::CalcBoundedSmootedLink( const Point3d& ptStart, const Vector3d& vtStart, const Point3d& ptEnd,
const Vector3d& vtEnd, double dParMeet, ICRVCOMPOPOVECTOR& vOffIslands,
ICurveComposite* pCrvLink)
{
// creo il BiArc che unisce i due punti
double dAngStart, dAngEnd ;
vtStart.GetAngleXY( X_AX, dAngStart) ;
vtStart.GetAngleXY( X_AX, dAngStart) ;
vtEnd.GetAngleXY( X_AX, dAngEnd) ;
PtrOwner<ICurve> pBiArcLink ;
if ( dParMeet != 0)
@@ -6884,18 +6900,17 @@ Pocketing::CalcBoundedSmootedLink( const Point3d& ptStart, const Vector3d& vtSta
Point3d ptS ;
pCompo->GetPointD1D2( ccClass[j].dParS, ICurve::FROM_PLUS, ptS) ;
double dOffS ;
vOffIslands[i]->GetParamAtPoint( ptS, dOffS) ;
vOffIslands[i]->GetParamAtPoint( ptS, dOffS, 1500 * EPS_SMALL) ;
Point3d ptE ;
pCompo->GetPointD1D2( ccClass[j].dParE, ICurve::FROM_MINUS, ptE) ;
double dOffE ;
vOffIslands[i]->GetParamAtPoint( ptE, dOffE) ;
vOffIslands[i]->GetParamAtPoint( ptE, dOffE, 1500 * EPS_SMALL) ;
// recupero i due possibili percorsi e uso il più corto
PtrOwner<ICurve> pCrvA( GetCurve( vOffIslands[i]->CopyParamRange( dOffS, dOffE))) ;
PtrOwner<ICurve> pCrvB( GetCurve( vOffIslands[i]->CopyParamRange( dOffE, dOffS))) ;
if ( IsNull( pCrvA) || IsNull( pCrvB)) {
return false ;
}
if ( IsNull( pCrvA) || IsNull( pCrvB))
return CalcBoundedLink( ptStart, ptEnd, vOffIslands, pCrvLink) ;
double dLenA ; pCrvA->GetLength( dLenA) ;
double dLenB ; pCrvB->GetLength( dLenB) ;
@@ -6903,29 +6918,30 @@ Pocketing::CalcBoundedSmootedLink( const Point3d& ptStart, const Vector3d& vtSta
if ( j != 0) {
if ( dLenA < dLenB) {
if ( ! pCompoHelp->AddCurve( Release( pCrvA)))
return false ;
return CalcBoundedLink( ptStart, ptEnd, vOffIslands, pCrvLink) ;
}
else {
pCrvB->Invert() ;
if ( ! pCompoHelp->AddCurve( Release( pCrvB)))
return false ;
return CalcBoundedLink( ptStart, ptEnd, vOffIslands, pCrvLink) ;
}
}
else {
pCrvB->Invert() ;
if ( ! pCompoHelp->AddCurve( Release( pCrvB)))
return false ;
return CalcBoundedLink( ptStart, ptEnd, vOffIslands, pCrvLink) ;
}
}
else { // se non interseco
if ( ! pCompoHelp->AddCurve( pCompo->CopyParamRange( ccClass[j].dParS, ccClass[j].dParE)))
return false ;
return CalcBoundedLink( ptStart, ptEnd, vOffIslands, pCrvLink) ;
}
}
pCompo->Clear() ;
if ( ! pCompo->AddCurve( pCompoHelp->Clone()))
return false ;
if ( ! CalcBoundedLink( ptStart, ptEnd, vOffIslands, pCrvLink))
return false ;
}
@@ -8654,8 +8670,8 @@ Pocketing::AdjustContourWithOpenEdges( ICurveComposite* pCompo, const ICRVCOMPOP
PtrOwner<ICurveComposite> 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) ;
@@ -8664,8 +8680,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<ICurveComposite> pCompo_clone( CloneCurveComposite( pCompo)) ;
@@ -8711,8 +8727,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)
@@ -8761,8 +8777,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)
@@ -8808,8 +8824,8 @@ Pocketing::AdjustContourWithOpenEdges( ICurveComposite* pCompo, const ICRVCOMPOP
}
// 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 ;
@@ -8834,13 +8850,13 @@ Pocketing::AdjustPathOutsideRawForOpenEdges( const ICurveComposite* pCompo, cons
PtrOwner<ICurveComposite> 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<ICurveComposite> 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<ICurveComposite> pCrvOpen( CloneCurveComposite( pCompo)) ;
pCrvOpen->TrimStartEndAtParam( dUTrimS, dUTrimE) ;
PtrOwner<ICurveComposite> pCompo_noOpenCrv( CloneCurveComposite( pCompo_Succ)) ;
@@ -8870,8 +8886,8 @@ Pocketing::AdjustPathOutsideRawForOpenEdges( const ICurveComposite* pCompo, cons
PtrOwner<ISurfFlatRegion> 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
@@ -8916,8 +8932,6 @@ Pocketing::AdjustPathOutsideRawForOpenEdges( const ICurveComposite* pCompo, cons
// 7) trasformo la curva in composita
PtrOwner<ICurveComposite> pCompoPartInOffs( CreateCurveComposite()) ;
pCompoPartInOffs->AddCurve( pOffLongestCrv->Clone()) ;
int r = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pCompoPartInOffs->Clone()) ;
m_pGeomDB->SetMaterial( r, RED) ;
// 8) creo due rette che collegano i punti iniziali e finali della curva originale e di quella con offset
PtrOwner<ICurveLine> pLineS( CreateCurveLine()) ;
PtrOwner<ICurveLine> pLineE( CreateCurveLine()) ;
@@ -8942,8 +8956,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() ;
@@ -8960,8 +8974,8 @@ 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<ICurveComposite> pCrvNewBorder( GetCurveComposite( pSfrInc->GetLoop( 0, 0))) ;
@@ -8972,8 +8986,8 @@ Pocketing::AdjustPathOutsideRawForOpenEdges( const ICurveComposite* pCompo, cons
double dUEND ; pCrvNewBorder->GetParamAtPoint( ptEND, dUEND) ;
pCrvNewBorder->TrimEndAtParam( dUEND) ;
int bb = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pCrvNewBorder->Clone()) ; //
m_pGeomDB->SetMaterial( bb, BLUE) ; //
//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)
@@ -9240,14 +9254,13 @@ 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
if ( m_IntersRaw) {
if ( m_bIntersRaw) {
if ( ! IntersSurfWithRaw( pSrf, pStmRaw, vtTrasl, bChanged))
return false ;
}
// proietto il grezzo
if ( m_ProjectRaw) {
if ( m_bProjectRaw) {
if ( ! ProjectRaw( pSrf, vtTrasl, pStmRaw))
return false ;
}
@@ -9307,7 +9320,6 @@ Pocketing::AdaptSfrWithRaw( ISurfFlatRegion* pSrf, Vector3d vtTrasl, ICRVCOMPOPO
PtrOwner<ISurfFlatRegion> pSfrHelp( SfrBC.GetSurf()) ;
if ( IsNull( pSfrHelp) || ! pSfrHelp->IsValid())
return false ;
m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pSfrHelp->Clone()) ;
pCrvExt.Set( GetCurveComposite( pSfrHelp->GetLoop( 0, 0))) ;
for ( int l = 1 ; l < pSfrHelp->GetLoopCount( 0) ; ++ l) {
PtrOwner<ICurveComposite> pCrvClosedIsland( GetCurveComposite( pSfrHelp->GetLoop( 0, l))) ;
@@ -9349,7 +9361,7 @@ Pocketing::AdaptSfrWithRaw( ISurfFlatRegion* pSrf, Vector3d vtTrasl, ICRVCOMPOPO
// 5.2) sistemo la superificie
ICRVCOMPOPOVECTOR vCrvNULL ;
if ( ! AdjustContourWithOpenEdges( pCrvIsl, vCrvNULL, m_dDiam_Prec > 0 ? m_dDiam_Prec : m_TParams.m_dDiam,
m_dDiam_Prec > 0 ? m_dOffsetR_Prec : GetOffsR())) {
m_dDiam_Prec > 0 ? m_dOffsetR_Prec : GetOffsR())) {
m_pMchMgr->SetLastError( 2430, "Error in Pocketing : adjust open edges failed") ;
return false ;
}
@@ -9359,9 +9371,8 @@ Pocketing::AdaptSfrWithRaw( ISurfFlatRegion* pSrf, Vector3d vtTrasl, ICRVCOMPOPO
// 6) Creo la nuova superificie da svuotare
pSrfFinal->AddExtLoop( Release( pCrvExt)) ;
for ( int i = 0 ; i < ( int)vCrvModIsland.size() ; ++ i) {
for ( int i = 0 ; i < ( int)vCrvModIsland.size() ; ++ i)
pSrfFinal->AddIntLoop( Release( vCrvModIsland[i])) ;
}
}
// se superificie già lavorata in precedenza ...
@@ -9370,7 +9381,6 @@ Pocketing::AdaptSfrWithRaw( ISurfFlatRegion* pSrf, Vector3d vtTrasl, ICRVCOMPOPO
return false ;
}
// aggiorno la superificie
pSrf->Clear() ;
pSrf->CopyFrom( pSrfFinal) ;
@@ -9384,8 +9394,7 @@ Pocketing::IntersSurfWithRaw( ISurfFlatRegion* pSfrPock, const ISurfTriMesh* pSt
bool& bIsChanged, double dAreaToll)
{
bIsChanged = false ;
// trasformo in Trimesh la superificie da svuotare ( per sottrazione con il grezzo )
// trasformo in Trimesh la superificie da svuotare ( per sottrazione con il grezzo)
PtrOwner<ISurfTriMesh> pStm( CloneSurfTriMesh( pSfrPock->GetAuxSurf())) ;
if ( IsNull( pStm))
return false ;
@@ -9409,13 +9418,12 @@ Pocketing::IntersSurfWithRaw( ISurfFlatRegion* pSfrPock, const ISurfTriMesh* pSt
return true ;
}
// calcolo la nuova area e la confronto con la precedente ( capisco se la superificie è cambiata o meno )
// calcolo la nuova area e la confronto con la precedente ( capisco se la superificie è cambiata o meno)
double dAreaAfter = 0 ;
if ( ! pStm->GetArea( dAreaAfter) || abs( dAreaBefore - dAreaAfter) < dAreaToll)
return true ; // se la superificie non è cambiata, allora lascio tutto inviariato...
bIsChanged = true ;
// se le Aree sono cambiate, allora la superificie da svuotare interseca il grezzo
// ------------- creo la FlatRegion come sottrazione delle sue superifici -------------
// imposto i loop per la nuova FlatRegion dai loop della superificie Trimesh ottenuta per sottrazione
@@ -9425,17 +9433,35 @@ Pocketing::IntersSurfWithRaw( ISurfFlatRegion* pSfrPock, const ISurfTriMesh* pSt
double dThick ; pCrvEL->GetThickness( dThick) ;
Vector3d vtExtr ; pCrvEL->GetExtrusion( vtExtr) ;
// determino il piano su cui giace la superificie originale della svuotatura ( traslato)
Plane3d plPock ;
Vector3d vtN = pSfrPock->GetNormVersor() ;
Point3d ptC ; pSfrPock->GetCentroid( ptC) ;
plPock.Set( ptC, vtN) ;
if ( ! plPock.IsValid())
return false ;
plPock.Translate( vtTrasl) ;
// creo la nuova superificie da svuotare come FlatRegion
SurfFlatRegionByContours SrfChunkDef ;
POLYLINEVECTOR vPl ;
pStm->GetLoops( vPl) ;
for ( int i = 0 ; i < ( int)vPl.size() ; ++ i) {
// recupero la curva composita
PolyLine pl = vPl[i] ;
PtrOwner<ICurveComposite> pCrv( CreateCurveComposite()) ;
pCrv->FromPolyLine( pl) ;
pCrv->SetExtrusion( vtExtr) ;
pCrv->SetThickness( dThick) ;
SrfChunkDef.AddCurve( Release( pCrv)) ; // aggiungo le curve
// la converto in una semplice cruva per proiettarla su piano della svuotatura
// dato che le curve sono prese da una trimesh, le riproietto sul piano traslato per sicurezza e per evitare approssimazioni
double dS, dE ;
pCrv->GetDomain( dS, dE) ;
PtrOwner<ICurve> pCrv_c( pCrv->CopyParamRange( dS, dE)) ;
if ( IsNull( pCrv_c) || ! pCrv_c->IsValid())
return false ;
PtrOwner<ICurve> pCrv_proj( ProjectCurveOnPlane( *pCrv_c, plPock)) ;
SrfChunkDef.AddCurve( Release( pCrv_proj)) ; // aggiungo le curve proiettate
}
PtrOwner<ISurfFlatRegion> pSrfByCurves( SrfChunkDef.GetSurf()) ;
@@ -9473,14 +9499,13 @@ Pocketing::SetOpenOrCloseEdge( ISurfFlatRegion* pSrfTP, const ISurfFlatRegion* p
int nExtLoop = pSrfOrig->GetChunkCount() ;
ICRVCOMPOPOVECTOR vCrvAll ;
for ( int c = 0 ; c < ( int)pSrfOrig->GetChunkCount() ; ++ c) {
for ( int c = 0 ; c < ( int)pSrfOrig->GetChunkCount() ; ++ c)
vCrvAll.emplace_back( GetCurveComposite( pSrfOrig->GetLoop( c, 0))) ;
}
for ( int c = 0 ; c < ( int)pSrfOrig->GetChunkCount() ; ++ c)
for ( int l = 1 ; l < ( int)pSrfOrig->GetLoopCount( c) ; ++ l)
vCrvAll.emplace_back( GetCurveComposite( pSrfOrig->GetLoop( c, l))) ;
// superificie da ritornare ( aggiornata )
// superificie da ritornare ( aggiornata)
SurfFlatRegionByContours pSrfMod ;
// NB. Se sto svuotando un Chunk della superificie, quando lo interseco con il grezzo potrei ottenere più Chunks...
@@ -9494,7 +9519,6 @@ Pocketing::SetOpenOrCloseEdge( ISurfFlatRegion* pSrfTP, const ISurfFlatRegion* p
pCrv->MergeCurves( 10 * EPS_SMALL, 10 * EPS_ANG_SMALL) ;
for ( int i = 0 ; i < pCrv->GetCurveCount() ; ++ i) {
//const ICurve* pCrv_i = pCrv->GetCurve( i) ;
pCrv->SetCurveTempProp( i, -1, 0) ; // setto proprietà da definire di default
for ( int j = 0 ; j < ( int)vCrvAll.size() ; ++ j) {
int nStat = 0 ;
@@ -9586,7 +9610,8 @@ Pocketing::GetCurveByOverlap( const ICurve* pCrv_, const ICurveComposite* pCrvCo
//----------------------------------------------------------------------------
bool
Pocketing::CheckBoundingPointForIslands( ICurveComposite* pCrvCurr, int nInd, const ICRVCOMPOPOVECTOR& vCrvAll, int nIndFI, bool bFlag)
Pocketing::CheckBoundingPointForIslands( ICurveComposite* pCrvCurr, int nInd, const ICRVCOMPOPOVECTOR& vCrvAll,
int nIndFI, bool bFlag)
{
// controllo dei parametri
if ( pCrvCurr == nullptr || ( int)vCrvAll.size() == 0)
@@ -9602,10 +9627,20 @@ Pocketing::CheckBoundingPointForIslands( ICurveComposite* pCrvCurr, int nInd, co
// scorro tutto il vettore di curve interne ( le isole )
for ( int i = nIndFI ; i < ( int)vCrvAll.size() ; ++ i){
if ( vCrvAll[i]->IsPointOn( ptS, 1000 * EPS_SMALL))
nIS = i ;
if ( vCrvAll[i]->IsPointOn( ptE, 1000 * EPS_SMALL))
nIE = i ;
if ( vCrvAll[i]->IsPointOn( ptS, 1000 * EPS_SMALL)) {
double dUS ; vCrvAll[i]->GetParamAtPoint( ptS, dUS, 1000 * EPS_SMALL) ;
dUS = ceil( dUS) ;
int nProp ; vCrvAll[i]->GetCurveTempProp( dUS, nProp, 0) ;
if ( nProp == 0)
nIS = i ;
}
if ( vCrvAll[i]->IsPointOn( ptE, 1000 * EPS_SMALL)) {
double dUE ; vCrvAll[i]->GetParamAtPoint( ptE, dUE, 1000 * EPS_SMALL) ;
dUE = ceil( dUE) ;
int nProp ; vCrvAll[i]->GetCurveTempProp( dUE, nProp, 0) ;
if ( nProp == 0)
nIE = i ;
}
if ( nIS != -1 && nIE != -1)
break ;
}
@@ -9662,7 +9697,7 @@ bool
Pocketing::GetStmRawPart( int nId, ISurfTriMesh* pSrfTMRaw, Frame3d frPocket)
{
// controllo se ho i flag abilitati
if ( !m_IntersRaw && !m_ProjectRaw)
if ( !m_bIntersRaw && !m_bProjectRaw)
return true ;
// controllo MachManager e database geometrico
@@ -9974,7 +10009,7 @@ Pocketing::GetProjStmBoxOnSfr( const ISurfFlatRegion* pSfr, const ISurfTriMesh*
if ( ! pCrv->GetCentroid( ptCen)) // punto
if ( ! pCrv->GetStartPoint( ptCen))
return false ;
Vector3d vtNorm = pSfrPock->GetNormVersor() ; // normale
Vector3d vtNorm = pSfrPock->GetNormVersor() ; // normale
if ( vtNorm.IsSmall())
return false ;
plProj.Set( ptCen, -vtNorm) ; // così taglio tutto cià che sta nel semipiano negativo
@@ -10029,7 +10064,8 @@ Pocketing::GetProjStmBoxOnSfr( const ISurfFlatRegion* pSfr, const ISurfTriMesh*
//----------------------------------------------------------------------------
bool
Pocketing::ProjectRaw( ISurfFlatRegion* pSrf, const Vector3d& vtTrasl, const ISurfTriMesh* pStmRaw)
Pocketing::ProjectRaw( ISurfFlatRegion* pSrf, const Vector3d& vtTrasl,
const ISurfTriMesh* pStmRaw)
{
// controllo dei paramtri
if ( pSrf == nullptr || ! pSrf->IsValid() || pSrf->GetChunkCount() == 0 ||
@@ -10079,10 +10115,13 @@ Pocketing::ProjectRaw( ISurfFlatRegion* pSrf, const Vector3d& vtTrasl, const ISu
return false ;
frLoc.Set( ptOri, vtZ) ;
// porto le superifici nel nuovo frame
// porto le superifici e isole con lati aperte nel nuovo frame
pSrf->ToLoc( frLoc) ;
pSrfOnPlPlus->ToLoc( frLoc) ;
//int G = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pSrfOnPlPlus->Clone()) ;
//m_pGeomDB->SetMaterial( G, GREEN) ;
// creo la superificie finale da restituire
SurfFlatRegionByContours pSrfAfterProj ;
@@ -10126,8 +10165,8 @@ Pocketing::ProjectRaw( ISurfFlatRegion* pSrf, const Vector3d& vtTrasl, const ISu
pCrvExtSfr->ChangeStartPoint( u) ;
}
}
if ( ! bCEFound) { // se la curva ha tutti lati aperti, allora la imposto uguale alla proiezione del grezzo
// se la curva ha tutti lati aperti, allora la imposto uguale alla proiezione del grezzo ed esco
if ( ! bCEFound) {
pCrvExtSfr->Clear() ;
pCrvExtProj->ToGlob( frLoc) ;
pCrvExtSfr->AddCurve( Release( pCrvExtProj)) ;
@@ -10146,56 +10185,66 @@ Pocketing::ProjectRaw( ISurfFlatRegion* pSrf, const Vector3d& vtTrasl, const ISu
}
pSrf->Clear() ;
pSrf->CopyFrom( pSrf_h) ;
pSrf->Translate( -vtTrasl) ;
pSrf->Translate( - vtTrasl) ;
return true ;
}
//int O = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pCrvExtProj->Clone()) ;
//m_pGeomDB->SetMaterial( O, ORANGE) ;
//int R = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pCrvExtSfr->Clone()) ;
//m_pGeomDB->SetMaterial( R, RED) ;
// scorro tutte le curve del contorno, cercando di raccordare linearmente i tratti aperti
// con il bordo della proiezione ( in modo da estendere la superficie da svuotare
bool bIsLastOpen = false ;
for( int c = 0 ; c < pCrvExtSfr->GetCurveCount() || bIsLastOpen ; ++c) {
for ( int c = 0 ; c < pCrvExtSfr->GetCurveCount() || bIsLastOpen ; ++c) {
// recupero la curva c-esima
PtrOwner<ICurve> pCrv( pCrvExtSfr->GetCurve( bIsLastOpen ? 0 : c)->Clone()) ;
if( IsNull( pCrv))
if ( IsNull( pCrv))
return false ;
//if( pCrv->GetTempProp() == 1 && ! GetCurveByOverlap( pCrv, pCrvExtProj, nIndC)) {
// controllo se fa overlap con il bordo della proiezione e/o con il bordo di un isola aperta
int nStat1 = 0 ;
if ( ! CheckSimpleOverlap( pCrv, pCrvExtProj, nStat1))
return false ;
// se lato aperto e non sulla curva esterna di proiezione...
if ( pCrv->GetTempProp() == 1 && nStat1 == 0) {
// se lato aperto e non sulla curva esterna di proiezione ...
++ nCont ;
if( nCont == 1) { // ... e primo lato aperto trovato
if ( nCont == 1) { // ... e primo lato aperto trovato
// creo la retta
pCrvLS->Set( ptS, ptS + vtS * 10000) ;
// creo la retta iniziale di raccordo
pCrvLS->Set( ptS, ptS + vtS * 10000) ;
//int CC = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pCrvLS->Clone()) ;
//m_pGeomDB->SetMaterial( CC, AQUA) ;
// la spezzo alla prima intersezione con il grezzo
CRVCVECTOR ccClass ;
if ( pSrfOnPlPlus->GetCurveClassification( *pCrvLS, EPS_SMALL, ccClass) &&
( ccClass[0].nClass == CRVC_IN || ccClass[0].nClass == CRVC_ON_P || ccClass[0].nClass == CRVC_ON_M)) {
pCrvLS.Set( GetCurveLine( pCrvLS->CopyParamRange( 0, ccClass[0].dParE))) ;
pCrvLS->SetTempProp( ccClass[0].nClass == CRVC_IN ? 0 : 1) ;
}
else if (( int) ccClass.size() == 0) // retta iniziale degenere ad un punto
nStat = 1 ;
else { // esco ...
pSrf->ToGlob( frLoc) ;
pSrf->Translate( -vtTrasl) ;
return true ;
}
// la spezzo alla prima intersezione con il grezzo
CRVCVECTOR ccClass ;
if ( pSrfOnPlPlus->GetCurveClassification( *pCrvLS, EPS_SMALL, ccClass) &&
( ccClass[0].nClass == CRVC_IN || ccClass[0].nClass == CRVC_ON_P || ccClass[0].nClass == CRVC_ON_M)) {
pCrvLS.Set( GetCurveLine( pCrvLS->CopyParamRange( 0, ccClass[0].dParE))) ;
pCrvLS->SetTempProp( ccClass[0].nClass == CRVC_IN ? 0 : 1) ;
}
else if (( int) ccClass.size() == 0) // retta iniziale degenere ad un punto
nStat = 1 ;
else { // esco ...
pSrf->ToGlob( frLoc) ;
pSrf->Translate( -vtTrasl) ;
return true ;
}
// nel caso in cui la retta tocca la curva della svuotatura n volte...
IntersCurveCurve intCCOpt( *pCrvLS, *pCrvExtSfr) ;
if ( intCCOpt.GetCurveClassification( 0, EPS_SMALL, ccClass) && ( int)ccClass.size() > 1) {
pSrf->ToGlob( frLoc) ;
pSrf->Translate( -vtTrasl) ;
return true ; // migliorare !
}
// nel caso in cui la retta tocca la curva della svuotatura n volte...
IntersCurveCurve intCCOpt( *pCrvLS, *pCrvExtSfr) ;
if ( intCCOpt.GetCurveClassification( 0, EPS_SMALL, ccClass) && ( int)ccClass.size() > 1) {
// salto questa proiezione, proviene da isole aperte
pSrf->ToGlob( frLoc) ;
pSrf->Translate( -vtTrasl) ;
return true ;
}
// se ultima curva ...
if ( c == pCrvExtSfr->GetCurveCount() - 1)
bIsLastOpen = true ;
// se ultima curva ...
if ( c == pCrvExtSfr->GetCurveCount() - 1)
bIsLastOpen = true ;
}
}
else {
@@ -10205,8 +10254,10 @@ Pocketing::ProjectRaw( ISurfFlatRegion* pSrf, const Vector3d& vtTrasl, const ISu
pCrv->GetStartDir( vtE) ; vtE = -vtE ;
pCrv->GetStartPoint( ptE) ;
// setto la retta
// setto la retta finale di raccordo
pCrvLE->Set( ptE, ptE + vtE * 10000) ;
//int BB = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pCrvLE->Clone()) ;
//m_pGeomDB->SetMaterial( BB, BLUE) ;
// la spezzo alla prima intersezione con il grezzo
CRVCVECTOR ccClass ;
@@ -10220,14 +10271,17 @@ Pocketing::ProjectRaw( ISurfFlatRegion* pSrf, const Vector3d& vtTrasl, const ISu
else { // esco...
pSrf->ToGlob( frLoc) ;
pSrf->Translate( -vtTrasl) ;
return true ;
return true ; // migliorare
}
// nel caso in cui la retta tocca la curva della svuotatura n volte...
IntersCurveCurve intCCOpt( *pCrvLE, *pCrvExtSfr) ;
if ( intCCOpt.GetCurveClassification( 0, EPS_SMALL, ccClass) && ( int)ccClass.size() > 1)
return true ; // migliorare
if ( intCCOpt.GetCurveClassification( 0, EPS_SMALL, ccClass) && ( int)ccClass.size() > 1) {
// salto questa proiezione, proviene da isole aperte
pSrf->ToGlob( frLoc) ;
pSrf->Translate( -vtTrasl) ;
return true ;
}
int nCrv = pCrvExtSfr->GetCurveCount() ; // memorizzo il numero di curve attuali
PNTVECTOR vPtTan{ ptS, ptE} ;
@@ -10240,7 +10294,7 @@ Pocketing::ProjectRaw( ISurfFlatRegion* pSrf, const Vector3d& vtTrasl, const ISu
nCont = 0 ;
pCrv->GetEndDir( vtS) ;
pCrv->GetEndPoint( ptS) ;
if( bIsLastOpen)
if ( bIsLastOpen)
bIsLastOpen = false ;
}
}
@@ -10249,7 +10303,7 @@ Pocketing::ProjectRaw( ISurfFlatRegion* pSrf, const Vector3d& vtTrasl, const ISu
pCrvExtSfr->SetExtrusion( vtExtr) ;
pCrvExtSfr->SetThickness( dthick) ;
pSrfAfterProj.AddCurve( Release( pCrvExtSfr)) ;
for( int i = 0 ; i < ( int)vCrvIsl.size() ; ++ i) {
for ( int i = 0 ; i < ( int)vCrvIsl.size() ; ++ i) {
vCrvIsl[i]->SetExtrusion( vtExtr) ;
vCrvIsl[i]->SetThickness( dthick) ;
pSrfAfterProj.AddCurve( Release( vCrvIsl[i])) ;
@@ -10754,15 +10808,6 @@ Pocketing::SetTmpPropByOverlap( ICurveComposite* pCrv_, int nInd, const ICurveCo
pCrvOri->GetParamAtPoint( ptS, dUS, dToll) ;
pCrvOri->GetParamAtPoint( ptE, dUE, dToll) ;
//double dLen_useless ; pCrv->GetLength( dLen_useless) ;
//if ( dLen_useless > 74.8 && dLen_useless < 75) {
// int w = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pCrvOri->Clone()) ;
// m_pGeomDB->SetMaterial( w, WHITE) ;
// int o = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pCrv->Clone()) ;
// m_pGeomDB->SetMaterial( o, ORANGE) ;
//}
// controllare questa funzione, con 50 funziona la C, ma non la passata con il tool a 75 !
int nRealDUS = ( int)floor( dUS) ;
int nRealDUE = ( int)ceil( dUE) ;
@@ -11637,7 +11682,7 @@ Pocketing::AssignDefaultFeed( ICurveComposite* pCrv) {
bool
Pocketing::DrawColoredCrvForFeedTest( ICurve* pCurve, double dFeed)
{
return true ;
//return true ;
if ( abs( dFeed - GetMinFeed()) < EPS_SMALL) {
int rosso = m_pGeomDB->AddGeoObj(GDB_ID_NULL, GDB_ID_ROOT, pCurve->Clone()) ;
m_pGeomDB->SetMaterial( rosso, RED) ;
+4 -4
View File
@@ -109,7 +109,7 @@ class Pocketing : public Machining
double dToll = 1500 * EPS_SMALL) ;
bool SetTmpPropByOverlap( ICurveComposite* pCrv, int nInd, const ICurveComposite* pCrvOri, int& nStat,
double dToll = 1500 * EPS_SMALL) ;
bool CheckBoundingPointForIslands ( ICurveComposite* pCrv, int nInd, const ICRVCOMPOPOVECTOR& vCrvAll, int nIndFI,
bool CheckBoundingPointForIslands( ICurveComposite* pCrv, int nInd, const ICRVCOMPOPOVECTOR& vCrvAll, int nIndFI,
bool bFlag) ;
bool GetCoeffLinArc( const ICurveArc* pArc, double dDiam, double& dSubArc) ;
bool GetParamOnOpenSide( const ICurveComposite* pCompo,const ICRVCOMPOPOVECTOR& vCrvIsl, Point3d& ptMid, Vector3d& vtMidOut) ;
@@ -310,12 +310,12 @@ class Pocketing : public Machining
AggrBottom m_AggrBottom ; // dati eventuale aggregato da sotto
bool m_bOpenOutRaw ; // flag forzatura lati aperti sempre fuori dal grezzo
double m_dOpenMinSafe ; // minima distanza di sicurezza di attacco su lato aperto
bool m_IntersRaw = true ; // flag per intersezione con grezzo
bool m_ProjectRaw = true ; // flag di proiezione del grezzo
bool m_bIntersRaw = true ; // flag per intersezione con grezzo
bool m_bProjectRaw = true ; // flag di proiezione del 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
bool m_bAssignFeed = true ; // flag per controllo della Feed
double m_dDiam_Prec = 0.0 ; // diametro utensile per precedente svuotatura
double m_dDiam_Prec = 0.0 ; // diametro utensile per precedente svuotatura
double m_dOffsetR_Prec = 0.0 ; // Offset radiale della svuotatura precedente
} ;