EgtMachKernel :

- migliorie varie.
This commit is contained in:
Riccardo Elitropi
2023-09-13 13:20:55 +02:00
parent 4e23dbe156
commit cee893f4ca
2 changed files with 245 additions and 209 deletions
+240 -205
View File
@@ -1521,7 +1521,7 @@ Pocketing::ProcessPath( int nAuxId, int nPvId, int nClId)
SurfFlatRegionByContours SrfByC ; // superificie totale generata da tutte le curve concatenate
Plane3d plAux ; bool bFirstPlane = true ; // piano Ausiliario per verificare che le curve siano complanari
Vector3d vtExtr ;
double dThick = -INFINITO ; // spessore più grande tra le curve
double dThick = -INFINITO ; // spessore più grande tra le curve
int nPathId = m_pGeomDB->GetFirstGroupInGroup( nAuxId) ;
// indici da associare alla SurfFlatRegion da svuotare :
@@ -1581,7 +1581,7 @@ Pocketing::ProcessPath( int nAuxId, int nPvId, int nClId)
pCompoOriCrv->SetExtrusion( vtExtr_p) ;
pCompoOriCrv->SetThickness( dThick_p) ;
// setto come proprietà temperanea il suo Id
// setto come proprietà temperanea il suo Id
pCompoOriCrv->SetTempProp( nProp0, 0) ; // a tutta la curva ( id selezionato )
pCompoOriCrv->SetTempProp( nProp1, 1) ; // a tutta la curva ( se Trimesh, faccia adiacente )
@@ -1632,6 +1632,18 @@ Pocketing::ProcessPath( int nAuxId, int nPvId, int nClId)
dThick = -dThick ;
}
// controllo se la superificie contiene lati aperti interno al grezzo
// 1) recupero la Trimesh del grezzo
PtrOwner<ISurfTriMesh> pStmRaw( CreateSurfTriMesh()) ;
if ( IsNull( pStmRaw))
return false ;
pStmRaw->DoCompacting() ;
if ( ! GetStmRawPart( nProp0, pStmRaw))
return false ;
// 2) Imposto TmpProp1 = -2 a tutti i lati aperti ( TmpProp0 = 1 ) interno al grezzo
if ( ! DetectOpenEdgeInsideRaw ( pSrfPock, pStmRaw))
return false ;
// recupero il box del grezzo in globale
BBox3d b3Raw ;
BBox3d b3Chunk ; pSrfPock->GetBBox( GLOB_FRM, b3Chunk) ;
@@ -1823,6 +1835,111 @@ Pocketing::ProcessPath( int nAuxId, int nPvId, int nClId)
}
//----------------------------------------------------------------------------
bool
Pocketing::DetectOpenEdgeInsideRaw ( ISurfFlatRegion* pSfr, const ISurfTriMesh* pStmRaw ) {
// controllo dei parametri
if ( pSfr == nullptr || ! pSfr->IsValid() || pSfr->GetChunkCount() == 0 ||
pStmRaw == nullptr || ! pStmRaw->IsValid() || pStmRaw->GetTriangleCount() == 0)
return false ;
// ricavo il piano della svuotatura
Vector3d vtN = pSfr->GetNormVersor() ;
Point3d ptC ;
if ( ! pSfr->GetCentroid( ptC)) {
PtrOwner<ICurveComposite> pCrvCompo( ConvertCurveToComposite( pSfr->GetLoop( 0, 0))) ;
if ( IsNull( pCrvCompo) ||
! pCrvCompo->IsValid() ||
! pCrvCompo->GetStartPoint( ptC))
return false ;
}
Plane3d plPock ; plPock.Set( ptC, vtN) ;
if ( ! plPock.IsValid())
return false ;
// taglio il grezzo con il piano di svuotatura
PtrOwner<ISurfTriMesh> pStmRaw_Clone( CloneSurfTriMesh( pStmRaw)) ;
if ( IsNull( pStmRaw_Clone) || ! pStmRaw_Clone->IsValid() ||
! pStmRaw_Clone->Cut( plPock, true) ||
IsNull( pStmRaw_Clone) || ! pStmRaw_Clone->IsValid())
return false ;
if ( pStmRaw_Clone->GetTriangleCount() == 0)
return true ;
// estraggo i bordi liberi, così facendo posso ricavare una Flat Region nel piano di svuotatura.
// Userò questa FlatRegion come insieme per confrontare i lati aperti interni ad essa
PtrOwner<ISurfFlatRegion> pSfrRawCheck( CreateSurfFlatRegion()) ;
if ( IsNull( pSfrRawCheck))
return false ;
SurfFlatRegionByContours SrfBC ;
// 1) estraggo i Loop del grezzo tagliato
POLYLINEVECTOR vPL ;
pStmRaw_Clone->GetLoops( vPL) ;
for ( int i = 0 ; i < ( int)vPL.size() ; ++ i) {
PtrOwner<ICurveComposite> pCrvLoop( CreateCurveComposite()) ;
if ( IsNull( pCrvLoop))
return false ;
pCrvLoop->FromPolyLine( vPL[i]) ;
if ( pCrvLoop->IsValid())
SrfBC.AddCurve( Release( pCrvLoop)) ;
}
// 2) ricavo la FlatRegion per il controllo delle curve e creo quella da restiruire alla fine
pSfrRawCheck.Set( SrfBC.GetSurf()) ;
if ( IsNull( pSfrRawCheck) || ! pSfrRawCheck->IsValid())
return false ;
SurfFlatRegionByContours SfrBC_Final ;
// 3) per ogni Chunk-c della FlatRegion da svuotare, controllo le TmpProp delle curve
bool bChanged = false ;
for ( int c = 0 ; c < pSfr->GetChunkCount() ; ++ c) {
// 3.1) estraggo il bordo esterno ( controllo solo quello )
PtrOwner<ICurveComposite> pCrvExt( ConvertCurveToComposite( pSfr->GetLoop( c, 0))) ;
if ( IsNull( pCrvExt) || ! pCrvExt->IsValid())
return false ;
// 3.2) scorro tutte le curve cambiando la TmpProp1 se necessario
for ( int u = 0 ; u < pCrvExt->GetCurveCount() ; ++ u) {
// 3.2.1) ricavo la curva u-esima
PtrOwner<ICurve> pCrv_u( pCrvExt->GetCurve( u)->Clone()) ;
if ( IsNull( pCrv_u) || ! pCrv_u->IsValid())
return false ;
// 3.2.2) continuo solo se è aperta
if ( pCrv_u->GetTempProp( 0) != 1)
continue ;
// 3.2.3) classifico la curva con la FlatRegion ricavata dal grezzo
CRVCVECTOR ccClass ;
if ( pSfrRawCheck->GetCurveClassification( *pCrv_u, 1500 * EPS_SMALL, ccClass)) {
if (( int)ccClass.size() == 1 && ccClass[0].nClass == CRVC_IN) {
// 3.2.4) se interna, cambio le TmpProps
pCrvExt->SetCurveTempProp( u, -2, 1) ;
// 3.2.5) aggiorno il Flag
bChanged = true ;
}
}
}
// 3.3) aggiungo il loopEsterno modificato
SfrBC_Final.AddCurve( Release( pCrvExt)) ;
// 3.4) aggiungo eventuali isole
for ( int l = 1 ; l < pSfr->GetLoopCount( c) ; ++ l)
SfrBC_Final.AddCurve( pSfr->GetLoop( c, l)) ;
}
// 4) se non ho modificato nulla, allora esco
if ( ! bChanged)
return true ;
// 5) altrimenti sostituisco la FlatRegion
PtrOwner<ISurfFlatRegion> pSfrFinal( SfrBC_Final.GetSurf()) ;
if ( ! IsNull( pSfrFinal) && pSfrFinal->IsValid()) {
pSfr->Clear() ;
pSfr->CopyFrom( pSfrFinal) ;
}
// 6) controllo validità
return pSfr != nullptr && pSfr->IsValid() && pSfr->GetChunkCount() != 0 ;
}
//----------------------------------------------------------------------------
bool
Pocketing::CalcRegionElevation( const ICurveComposite* pCompo, const Vector3d& vtTool, double dDepth, double dRad,
@@ -9706,9 +9823,6 @@ Pocketing::GetParamsAtEachStep( ISURFFRPOVECTOR& vSrfSliced, vector<ICRVCOMPOPOV
// ED ESTENSIONE PRESSO LATI APERTI
for ( int j = 1 ; j <= int( vVtTrasl.size()) ; ++ j) {
//if ( j != 7)
// continue ;
// vettore traslazione corrente
Vector3d vtTrasl = vVtTrasl[j-1] ;
// vettore delle curve con Flag per lati aperti
@@ -9728,6 +9842,7 @@ Pocketing::GetParamsAtEachStep( ISURFFRPOVECTOR& vSrfSliced, vector<ICRVCOMPOPOV
return false ;
pSrfToPock.Set( Release( pSrfNewChunk_c)) ;
}
continue ;
// adatto la superficie dello step corrente con la geometria del grezzo
if ( AdaptSfrWithRaw( pSrfToPock, vtTrasl, pStmRaw, vCrvOEF, bChanged, j, dStep, 500 * EPS_SMALL, m_pStmShape)) {
@@ -9756,7 +9871,7 @@ Pocketing::GetParamsAtEachStep( ISURFFRPOVECTOR& vSrfSliced, vector<ICRVCOMPOPOV
return false ;
}
// ======================================================================================
return true ;
return false ;
}
// --------------------------------------------------------------------------
@@ -9967,46 +10082,31 @@ Pocketing::ProjectEdgesOfSelectedStm( const ISurfFlatRegion* pSrfToPock, const I
return false ;
pSrfBorderExt->AddExtLoop( pCrvBorder->Clone()) ;
// b) creazione del piano di svuotatura ( piano passante per la faccia selezionata sulla Trimesh)
// b) creazione del piano di svuotatura ( piano passante per la faccia selezionata sulla TriMesh)
Point3d ptC ; pSrfToPock->GetCentroid( ptC) ;
Vector3d vtN = pSrfToPock->GetNormVersor() ;
Plane3d plPock ; plPock.Set( ptC, vtN) ;
if ( ! plPock.IsValid())
return false ;
// c) ciclo su tutte le facce della trimesh ( tranne quella selezionata) e proietto sul piano della svuotatura
for ( int f = 0 ; f < pStmORIG->GetFacetCount() ; ++ f) {
if ( f == nFacet)
continue ;
// c) creo una copia della TriMesh originale togliendo la faccia selezionata
PtrOwner<ISurfTriMesh> pStmORIG_noSelFace( CloneSurfTriMesh( pStmORIG)) ;
if ( IsNull( pStmORIG_noSelFace) || ! pStmORIG_noSelFace->IsValid() ||
! pStmORIG_noSelFace->RemoveFacet( nFacet))
return false ;
if ( IsNull( pStmORIG_noSelFace) ||
! pStmORIG_noSelFace->IsValid() ||
pStmORIG_noSelFace->GetTriangleCount() == 0)
return true ; // <--- tutti i lati sono aperti !
// c.1) estraggo il bordo della faccia -> Curve composita
POLYLINEVECTOR vPL ;
pStmORIG->GetFacetLoops( f, vPL) ;
PtrOwner<ICurveComposite> pCrvBorder( CreateCurveComposite()) ;
if ( IsNull( pCrvBorder))
// d) proietto tutto sul piano di svuotatura e aggiungo la faccia selezionata
PtrOwner<ISurfFlatRegion> pSfrProj( CreateSurfFlatRegion()) ;
if ( IsNull( pSfrProj) ||
! ProjectStmOnPlane( pStmORIG_noSelFace, plPock, pSfrProj))
return false ;
if ( ! IsNull( pSfrProj) && pSfrProj->IsValid() && pSfrProj->GetChunkCount() != 0)
if ( ! pSrfBorderExt->Add( *pSfrProj))
return false ;
pCrvBorder->FromPolyLine( vPL[0]) ; // ( non considero le isole nelle facce laterali della Trimesh)
pCrvBorder->MergeCurves( 10 * EPS_SMALL, 10 * EPS_ANG_SMALL) ;
// c.2) proietto questa curva nel piano della faccia selezionata
PtrOwner<ICurve> pCrvProj( ProjectCurveOnPlane( *pCrvBorder, plPock)) ;
if ( IsNull( pCrvProj) || ! pCrvProj->IsValid())
return false ;
// c.3) creo la FlatRegion associata
PtrOwner<ISurfFlatRegion> pSfrTemp( CreateSurfFlatRegion()) ;
if ( IsNull( pSfrTemp))
return false ;
pSfrTemp->AddExtLoop( pCrvProj->Clone()) ;
// se valida...
if ( pSfrTemp->IsValid()) {
// oriento
if ( AreOppositeVectorApprox( pSfrTemp->GetNormVersor(), vtN))
pSfrTemp->Invert() ;
// aggiorno la superificie di proeizione
pSrfBorderExt->Add( *pSfrTemp) ;
}
}
// d) se valida, restituisco
if ( pSrfBorderExt->IsValid())
@@ -10063,6 +10163,11 @@ Pocketing::GetAdaptedSfrByTrimesh( const ISurfFlatRegion* pSrfExtended, const IS
if ( ! plProj.IsValid())
return false ;
// 5) taglio la TriMesh originale togliendo tutto ciò che sta sotto al piano di proiezione
PtrOwner<ISurfTriMesh> pStmORIG_forCut( CloneSurfTriMesh( pStmORIG)) ;
if ( IsNull( pStmORIG_forCut) || ! pStmORIG_forCut->IsValid())
return false ;
// 4) Taglio
if ( pStmExtended->CutWithOtherSurf( *pStmORIG, false, true)) {
@@ -10071,14 +10176,9 @@ Pocketing::GetAdaptedSfrByTrimesh( const ISurfFlatRegion* pSrfExtended, const IS
if ( ! IsNull( pStmExtended) && pStmExtended->GetTriangleCount() == 0)
pStmExtended.Set( CloneSurfTriMesh( pSfrORIG->GetAuxSurf())) ;
// 5) taglio la TriMesh originale togliendo tutto ciò che sta sotto al piano di proiezione
PtrOwner<ISurfTriMesh> pStmORIG_forCut( CloneSurfTriMesh( pStmORIG)) ;
if ( IsNull( pStmORIG_forCut) || ! pStmORIG_forCut->IsValid())
return false ;
if ( pStmORIG_forCut->Cut( plProj, true)) {
// 6) Proeizione della TriMesh tagliata sul piano di svuotatura
// 7) Proeizione della TriMesh tagliata sul piano di svuotatura
if ( ! ProjectStmOnPlane( pStmORIG_forCut, plProj, pSfrProjUP))
return false ;
@@ -10098,6 +10198,8 @@ Pocketing::GetAdaptedSfrByTrimesh( const ISurfFlatRegion* pSrfExtended, const IS
return false ;
// 2) Sottrazione
if ( AreOppositeVectorApprox( pSfrExtended->GetNormVersor(), pSfrProjUP->GetNormVersor()))
pSfrProjUP->Invert() ;
if ( pSfrProjUP->IsValid() &&
! pSfrExtended->Subtract( *pSfrProjUP))
return false ;
@@ -10120,25 +10222,46 @@ Pocketing::GetAdaptedSfrByTrimesh( const ISurfFlatRegion* pSrfExtended, const IS
else {
// 2.5.1) apro i lati che fanno overlap con la superficie di pSfrProjUp \ pSfrORIG
ICRVCOMPOPOVECTOR vCrvWithTmpProps ;
if ( vtTrasl.IsSmall())
int a = 9 ;
if ( ! ManageTmpPropForAdaptingStm( pSfrProjUP, pSfrORIG, pSrfExtended_cl, vtTrasl, vCrvWithTmpProps))
if ( ! ManageTmpPropForAdaptingStm( pStmORIG_forCut, pSfrORIG, pSfrProjUP, pSrfExtended_cl,
vtTrasl, vCrvWithTmpProps))
return false ;
Vector3d vtN = pSrfExtended_cl->GetNormVersor() ;
//Vector3d vtN = pSrfExtended_cl->GetNormVersor() ;
// 2.5.2) uso il Loop esterno della superficie originale come riferimento
if ( ! SetTmpPropWithRawProjectedFaces( pCrvLoop, vAllCrv, vtN))
return false ;
for ( int i = 0 ; i < ( int)vAllCrv.size() ; ++ i)
vCrvWithTmpProps.emplace_back( vAllCrv[i]->Clone()) ;
for ( int i = 0 ; i < ( int)vCrvWithTmpProps.size() && ! vtTrasl.IsSmall() ; ++ i) {
for ( int u = 0 ; u < pCrvLoop->GetCurveCount() ; ++ u) {
//if ( ! SetTmpPropWithRawProjectedFaces( pCrvLoop, vAllCrv, vtN))
// return false ;
//for ( int i = 0 ; i < ( int)vAllCrv.size() ; ++ i)
// vCrvWithTmpProps.emplace_back( vAllCrv[i]->Clone()) ;
for ( int u = 0 ; u < pCrvLoop->GetCurveCount() ; ++ u) {
bool bFound = false ;
for ( int i = 0 ; i < ( int)vCrvWithTmpProps.size() && !bFound ; ++ i) {
int nStat ;
if ( ! SetTmpPropByOverlap( pCrvLoop, u, vCrvWithTmpProps[i], nStat, 250 * EPS_SMALL))
return false ;
if ( SetTmpPropByOverlap( pCrvLoop, u, vCrvWithTmpProps[i], nStat, 250 * EPS_SMALL) &&
nStat == 1)
bFound = true ;
}
if ( ! bFound) {
PtrOwner<ICurve> pCrv_u( pCrvLoop->GetCurve( u)->Clone()) ;
Point3d ptS, ptM, ptE ;
pCrv_u->GetStartPoint( ptS) ;
pCrv_u->GetEndPoint( ptE) ;
pCrv_u->GetMidPoint( ptM) ;
PtrOwner<ISurfTriMesh> pStmNoSelFace( CloneSurfTriMesh( pStmORIG)) ;
if ( ! pStmNoSelFace->RemoveFacet( nTmpProp1))
return false ;
DistPointSurfTm dPStm1( ptS, *pStmNoSelFace) ;
DistPointSurfTm dPStm2( ptM, *pStmNoSelFace) ;
DistPointSurfTm dPStm3( ptE, *pStmNoSelFace) ;
double dDist1, dDist2, dDist3 ;
pCrvLoop->SetCurveTempProp( u, 0, 0) ;
if ( dPStm1.GetDist( dDist1) && dDist1 > 250 * EPS_SMALL)
pCrvLoop->SetCurveTempProp( u, 1, 0) ;
else if ( dPStm2.GetDist( dDist2) && dDist2 > 250 * EPS_SMALL)
pCrvLoop->SetCurveTempProp( u, 1, 0) ;
else if ( dPStm3.GetDist( dDist3) && dDist3 > 250 * EPS_SMALL)
pCrvLoop->SetCurveTempProp( u, 1, 0) ;
}
}
}
// 2.6) riporto le proprietà
pCrvLoop->SetTempProp( nTmpProp0, 0) ;
@@ -10157,25 +10280,22 @@ Pocketing::GetAdaptedSfrByTrimesh( const ISurfFlatRegion* pSrfExtended, const IS
return false ;
pNewSrfPock->CopyFrom( pSfrFINAL) ;
PtrOwner<ISurfFlatRegion> pSrf_toDraw( CloneSurfFlatRegion( pNewSrfPock)) ;
int a = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pSrf_toDraw->Clone()) ;
m_pGeomDB->SetMaterial( a, AQUA) ;
for ( int c = 0 ; c < pSrf_toDraw->GetChunkCount() ; ++ c) {
for ( int l = 0 ; l < pSrf_toDraw->GetLoopCount( c) ; ++ l) {
const ICurveComposite* pCrvCompo( GetCurveComposite( pSrf_toDraw->GetLoop( c, l))) ;
for ( int u = 0 ; u < pCrvCompo->GetCurveCount() ; ++ u) {
int nProp0 ; pCrvCompo->GetCurveTempProp( u, nProp0, 0) ;
int nProp1 ; pCrvCompo->GetCurveTempProp( u, nProp1, 1) ;
int aaa = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pCrvCompo->GetCurve( u)->Clone()) ;
if ( nProp1 != -99)
m_pGeomDB->SetMaterial( aaa, nProp0 == 0 ? BLUE : RED) ;
else
m_pGeomDB->SetMaterial( aaa, Color( 1.0, 0.5, 0.0)) ;
}
}
}
// 8) DISEGNO =========== TOGLIEREEEEEEEEEEEEEEEEEEEEEEEE ================================
PtrOwner<ISurfFlatRegion> pSrf_toDraw( CloneSurfFlatRegion( pNewSrfPock)) ;
int a = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pSrf_toDraw->Clone()) ;
m_pGeomDB->SetMaterial( a, Color( 0.0, 0.0, 1.0, 0.45)) ;
for ( int c = 0 ; c < pSrf_toDraw->GetChunkCount() ; ++ c) {
for ( int l = 0 ; l < pSrf_toDraw->GetLoopCount( c) ; ++ l) {
PtrOwner<ICurveComposite> pCrvCompo( GetCurveComposite( pSrf_toDraw->GetLoop( c, l))) ;
for ( int u = 0 ; u < pCrvCompo->GetCurveCount() ; ++ u) {
int nProp0 ; pCrvCompo->GetCurveTempProp( u, nProp0, 0) ;
int nProp1 ; pCrvCompo->GetCurveTempProp( u, nProp1, 1) ;
int aaa = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pCrvCompo->GetCurve( u)->Clone()) ;
m_pGeomDB->SetMaterial( aaa, nProp0 == 0 ? BLUE : RED) ;
}
}
}
// ===================================================================
pNewSrfPock->Translate( -vtTrasl) ;
return pNewSrfPock != nullptr && pNewSrfPock->IsValid() && pNewSrfPock->GetChunkCount() > 0 ;
@@ -10184,57 +10304,29 @@ Pocketing::GetAdaptedSfrByTrimesh( const ISurfFlatRegion* pSrfExtended, const IS
//----------------------------------------------------------------------------
bool
Pocketing::ManageTmpPropForAdaptingStm( const ISurfFlatRegion* pSfrProjUP, const ISurfFlatRegion* pSfrORIG,
const ISurfFlatRegion* pSrfExtended, const Vector3d& vtTrasl, ICRVCOMPOPOVECTOR& vCrvWithTmpProps)
Pocketing::ManageTmpPropForAdaptingStm( const ISurfTriMesh* pStmORIG, const ISurfFlatRegion* pSfrORIG,
const ISurfFlatRegion* pSfrProjUP, const ISurfFlatRegion* pSrfExtended,
const Vector3d& vtTrasl, ICRVCOMPOPOVECTOR& vCrvWithTmpProps)
{
ICRVCOMPOPOVECTOR vCrvLoops ;
PtrOwner<ISurfFlatRegion> pSrfCheck( CloneSurfFlatRegion( pSrfExtended)) ;
if ( ! IsNull( pSrfCheck) && pSrfCheck->IsValid())
if ( pSrfCheck->Subtract( *pSfrORIG) && ! IsNull( pSrfCheck) && pSrfCheck->IsValid())
for ( int c = 0 ; c < pSrfCheck->GetChunkCount() ; ++ c)
for ( int l = 0 ; l < pSrfCheck->GetLoopCount( c) ; ++ l)
vCrvLoops.emplace_back( ConvertCurveToComposite( pSrfCheck->GetLoop( c, l))) ;
for ( int c = 0 ; c < pSfrORIG->GetChunkCount() ; ++ c) {
PtrOwner<ICurveComposite> pCrvCompoLoop( ConvertCurveToComposite( pSfrProjUP->GetLoop( c, 0))) ;
for ( int u = 0 ; u < pCrvCompoLoop->GetCurveCount() ; ++ u)
pCrvCompoLoop->SetCurveTempProp( u, 0, 0) ;
vCrvWithTmpProps.emplace_back( Release( pCrvCompoLoop)) ;
}
for ( int i = 0 ; i < vCrvLoops.size() ; ++ i)
m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, vCrvLoops[i]->Clone()) ;
PtrOwner<ISurfFlatRegion> pSfrForMyCrv( CloneSurfFlatRegion( pSrfExtended)) ;
if ( ! IsNull( pSfrForMyCrv) && pSfrForMyCrv->IsValid()) {
if ( pSfrForMyCrv->Subtract( *pSfrORIG) && ! IsNull( pSfrForMyCrv) && pSfrForMyCrv->IsValid()) {
if ( pSfrForMyCrv->IsValid()) {
for ( int cc = 0 ; cc < pSfrForMyCrv->GetChunkCount() ; ++ cc) {
for ( int ll = 0 ; ll < pSfrForMyCrv->GetLoopCount( cc) ; ++ ll) {
PtrOwner<ICurveComposite> pMyCrv( ConvertCurveToComposite( pSfrForMyCrv->GetLoop( cc, ll))) ;
if ( IsNull( pMyCrv) || ! pMyCrv->IsValid())
return false ;
for ( int u = 0 ; u < pMyCrv->GetCurveCount() ; ++ u) {
PtrOwner<ICurve> pCrv( pMyCrv->GetCurve( u)->Clone()) ;
if ( IsNull( pCrv) || ! pCrv->IsValid())
return false ;
bool bIsOpen = false ;
for ( int i = 0 ; i < ( int)vCrvLoops.size() && ! bIsOpen ; ++ i) {
int nStat = 0 ;
if ( CheckSimpleOverlap( pCrv, vCrvLoops[i], nStat, 250 * EPS_SMALL) && nStat == 1)
bIsOpen = true ;
}
pMyCrv->SetCurveTempProp( u, bIsOpen ? 1 : 0, 0) ;
}
for ( int u = 0 ; u < pMyCrv->GetCurveCount() ; ++ u) {
int TP = 0 ; pMyCrv->GetCurveTempProp( u, TP, 0) ;
int a = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pMyCrv->GetCurve( u)->Clone()) ;
m_pGeomDB->SetMaterial( a, TP == 0 ? BLACK : WHITE) ;
}
vCrvWithTmpProps.emplace_back( Release( pMyCrv)) ;
}
}
if ( pSfrProjUP != nullptr && pSfrProjUP->IsValid()) {
for ( int c = 0 ; c < pSfrProjUP->GetChunkCount() ; ++ c) {
for ( int l = 0 ; l < pSfrProjUP->GetLoopCount( c) ; ++ l) {
PtrOwner<ICurveComposite> pCrvCompoLoop( ConvertCurveToComposite( pSfrProjUP->GetLoop( c, l))) ;
for ( int u = 0 ; u < pCrvCompoLoop->GetCurveCount() ; ++ u)
pCrvCompoLoop->SetCurveTempProp( u, 0, 0) ;
vCrvWithTmpProps.emplace_back( Release( pCrvCompoLoop)) ;
}
}
}
return true ;
}
@@ -10281,9 +10373,6 @@ Pocketing::ProjectStmOnPlane( const ISurfTriMesh* pStmAbove, const Plane3d plPoc
return true ; // non ho nulla da proiettare
pStmRef.Set( pStmRef_Easy->Clone()) ;
//int a = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pStmRef->Clone()) ;
//m_pGeomDB->SetMaterial( a, AQUA) ;
// 3) scalo la superficie rispetto al sistema di riferimento ( mettendo a 0 la componente vtN)
pStmRef->ToLoc( frPlane) ;
if ( ! pStmRef->Scale( GLOB_FRM, 1., 1., 0.))
@@ -10333,14 +10422,19 @@ Pocketing::ProjectStmOnPlane( const ISurfTriMesh* pStmAbove, const Plane3d plPoc
if ( ! GetSfrByStm( pStmUp, pSfrUp, plPock, V_NULL, 0., 0.))
return false ;
if ( ! IsNull( pStmDown) && pStmDown->IsValid() && pStmDown->GetTriangleCount() > 0)
if ( ! pStmDown->Invert())
if ( pStmDown->Invert())
if ( ! GetSfrByStm( pStmDown, pSfrUp1, plPock, V_NULL, 0., 0.))
return false ;
// 7) Controllo validità e creo la FlatRegion da restituire
if ( ! IsNull( pSfrUp) && pSfrUp->IsValid()) // se Up valida, allora inizio a sostituire
if ( ! IsNull( pSfrUp) && pSfrUp->IsValid()) { // se Up valida, allora inizio a sostituire
if ( AreOppositeVectorApprox( pSfrUp->GetNormVersor(), plPock.GetVersN()))
pSfrUp->Invert() ;
pSfrProj->CopyFrom( pSfrUp) ;
}
if ( ! IsNull( pSfrUp1) && pSfrUp1->IsValid()) { // se Down valida...
if ( AreOppositeVectorApprox( pSfrUp1->GetNormVersor(), plPock.GetVersN()))
pSfrUp1->Invert() ;
if ( pSfrProj != nullptr && pSfrProj->IsValid()) { // e Up valida -> aggiungo
if ( ! pSfrProj->Add( *pSfrUp1))
return false ;
@@ -10349,6 +10443,7 @@ Pocketing::ProjectStmOnPlane( const ISurfTriMesh* pStmAbove, const Plane3d plPoc
pSfrProj->CopyFrom( pSfrUp1) ;
}
return pSfrProj != nullptr && pSfrProj->IsValid() && pSfrProj->GetChunkCount() != 0 ;
}
@@ -10553,20 +10648,13 @@ Pocketing::SubtractFinalShape( ISurfFlatRegion* pSfrCurr, const Vector3d& vtTras
else
return false ;
// Sottraggo alla regione si svuotatura la proeizione della superificie Shape
// Sottraggo alla regione di svuotatura la proeizione della superificie Shape
PtrOwner<ISurfFlatRegion> pSfrCurr_c( CloneSurfFlatRegion( pSfrCurr)) ;
if ( IsNull( pSfrCurr_c) || ! pSfrCurr_c->IsValid())
return false ;
//int W = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pSfrCurr_c->Clone()) ;
//m_pGeomDB->SetMaterial( W, WHITE) ;
//int F = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pSfrShape_c->Clone()) ;
//m_pGeomDB->SetMaterial( F, BLACK) ;
if ( ! pSfrCurr_c->Subtract( *pSfrShape_c))
return false ;
//int G = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pSfrCurr_c->Clone()) ;
//m_pGeomDB->SetMaterial( G, GRAY) ;
// ricalcolo le TmpProp
SurfFlatRegionByContours sfrBC ;
@@ -12348,13 +12436,12 @@ Pocketing::ProjectRaw( ISurfFlatRegion* pSrf, const Vector3d& vtTrasl,
// NB. Nella Travi ci possono essere dei lati aperti dovuti all'allineamento di più TriMesh per una
// svuotatura lunga in una direzione, questi li considero chiusi per la proeizione...
//PtrOwner<ISurfFlatRegion> pSfr_Act( CreateSurfFlatRegion()) ;
//if ( IsNull( pSfr_Act))
//return false ;
//ICRVCOMPOPOVECTOR vCrvOpenToClose ;
//if ( ! CloseOpenSidesInsideRawForProjection( pSrf_clone_ChunkC, pStmRaw, pSfr_Act, vCrvOpenToClose))
// return false ;
//pSrf_clone_ChunkC.Set( Release( pSfr_Act)) ;
PtrOwner<ISurfFlatRegion> pSfr_Act( CreateSurfFlatRegion()) ;
if ( IsNull( pSfr_Act))
return false ;
if ( ! CloseOpenSidesInsideRawForProjection( pSrf_clone_ChunkC, pStmRaw, pSfr_Act))
return false ;
pSrf_clone_ChunkC.Set( Release( pSfr_Act)) ;
// ricavo la FlatRegion della proiezione di ogni faccia del grezzo tagliato dal
// semipiano positivo definito dal chunk c allo step attuale ( vtTrasl)
@@ -12468,8 +12555,11 @@ Pocketing::ProjectRaw( ISurfFlatRegion* pSrf, const Vector3d& vtTrasl,
//----------------------------------------------------------------------------
bool
Pocketing::CloseOpenSidesInsideRawForProjection( const ISurfFlatRegion* pSfrAct, const ISurfTriMesh* pStmRaw,
ISurfFlatRegion* pSfrMod, ICRVCOMPOPOVECTOR& vCrvMod)
ISurfFlatRegion* pSfrMod)
{
// NB. I LATI APERTI INIZIALI INTERNI AL GREZZO HANNO TmpProp0 = 1 e TmpProp1 = -2
// controllo dei parametri
if ( pSfrAct == nullptr || ! pSfrAct->IsValid() || pSfrAct->GetChunkCount() == 0)
return false ;
@@ -12477,58 +12567,15 @@ Pocketing::CloseOpenSidesInsideRawForProjection( const ISurfFlatRegion* pSfrAct,
return true ;
else if ( ! pStmRaw->IsValid() || pStmRaw->GetTriangleCount() == 0)
return false ;
// inzialmente la nuova superficie è uguale alla precedente
pSfrMod->CopyFrom( pSfrAct) ;
// ricavo il piano della svuotatura
Vector3d vtN = pSfrAct->GetNormVersor() ;
Point3d ptC ;
if ( ! pSfrAct->GetCentroid( ptC)) {
PtrOwner<ICurveComposite> pCrvCompo( ConvertCurveToComposite( pSfrAct->GetLoop( 0, 0))) ;
if ( IsNull( pCrvCompo) ||
! pCrvCompo->IsValid() ||
! pCrvCompo->GetStartPoint( ptC))
return false ;
}
Plane3d plPock ; plPock.Set( ptC, vtN) ;
if ( ! plPock.IsValid())
return false ;
// taglio il grezzo e ricavo il controno libero
PtrOwner<ISurfTriMesh> pStmRaw_Clone( CloneSurfTriMesh( pStmRaw)) ;
if ( IsNull( pStmRaw_Clone) || ! pStmRaw_Clone->IsValid())
return false ;
if ( ! pStmRaw_Clone->Cut( plPock, true))
return false ;
if ( IsNull( pStmRaw_Clone) || ! pStmRaw_Clone->IsValid())
return true ;
// creazione FlatRegion
PtrOwner<ISurfFlatRegion> pSfrRawCheck( CreateSurfFlatRegion()) ;
if ( IsNull( pSfrRawCheck))
return false ;
SurfFlatRegionByContours SrfBC ;
// estraggo i Loop del grezzo tagliato
POLYLINEVECTOR vPL ;
pStmRaw_Clone->GetLoops( vPL) ;
for ( int i = 0 ; i < ( int)vPL.size() ; ++ i) {
PtrOwner<ICurveComposite> pCrvLoop( CreateCurveComposite()) ;
if ( IsNull( pCrvLoop))
return false ;
pCrvLoop->FromPolyLine( vPL[i]) ;
if ( pCrvLoop->IsValid())
SrfBC.AddCurve( Release( pCrvLoop)) ;
}
// ricavo la FlatRegion per il controllo delle curve
pSfrRawCheck.Set( SrfBC.GetSurf()) ;
if ( IsNull( pSfrRawCheck) || ! pSfrRawCheck->IsValid())
return true ;
// FlatRegion finale da restituire
SurfFlatRegionByContours SfrBC_Final ;
// per ogni Chunk-c
bool bIsChaned = false ; // flag per campire se qualche curva aperta è stata chiusa
for ( int c = 0 ; c < pSfrAct->GetChunkCount() ; ++ c) {
// estraggo il bordo esterno ( controllo solo quello )
PtrOwner<ICurveComposite> pCrvExt( ConvertCurveToComposite( pSfrAct->GetLoop( c, 0))) ;
@@ -12541,22 +12588,10 @@ Pocketing::CloseOpenSidesInsideRawForProjection( const ISurfFlatRegion* pSfrAct,
PtrOwner<ICurve> pCrv_u( pCrvExt->GetCurve( u)->Clone()) ;
if ( IsNull( pCrv_u) || ! pCrv_u->IsValid())
return false ;
// continuo solo se è aperta
if ( pCrv_u->GetTempProp( 0) == 0)
continue ;
// classifico la curva con la FlatRegion ricavata dal grezzo
CRVCVECTOR ccClass ;
if ( pSfrRawCheck->GetCurveClassification( *pCrv_u, 1500 * EPS_SMALL, ccClass)) {
if (( int)ccClass.size() == 1 && ccClass[0].nClass == CRVC_IN) {
// se interna, la chiudo e salvo tale curva nel vettore
pCrvExt->SetCurveTempProp( u, 0, 0) ;
PtrOwner<ICurveComposite> pCrvCompo_u( ConvertCurveToComposite( pCrv_u->Clone())) ;
if ( IsNull( pCrvCompo_u) || ! pCrvCompo_u->IsValid())
return false ;
vCrvMod.emplace_back( Release( pCrvCompo_u)) ; // salvata con TmpProp0 = 1 ( aperta)
}
// chiudo la curva u-esima solo se lato aperto ( TmpProp0 = 1) e da chiudere ( TmpProp1 = -2 )
if ( pCrv_u->GetTempProp( 0) == 1 && pCrv_u->GetTempProp( 1) == -2) {
pCrvExt->SetCurveTempProp( u, 0, 0) ; // chiudo temporaneamente
bIsChaned = true ;
}
}
@@ -12569,10 +12604,10 @@ Pocketing::CloseOpenSidesInsideRawForProjection( const ISurfFlatRegion* pSfrAct,
}
// se nulla è stato modificato, allora esco
if (( int)vCrvMod.size() == 0)
if ( ! bIsChaned)
return true ;
// altrimenti, ritorno la superificie con i lati aperti interno al grezzo modificati a chiusi
// altrimenti, ritorno la superificie con i lati aperti interni al grezzo ( TmpProp0 = 1 e TmpProp1 = 1 ) modificati a chiusi
PtrOwner<ISurfFlatRegion> pSfrFinal( SfrBC_Final.GetSurf()) ;
if ( ! IsNull( pSfrFinal) && pSfrFinal->IsValid()) {
pSfrMod->Clear() ;
+5 -4
View File
@@ -81,6 +81,7 @@ class Pocketing : public Machining
bool GeneratePocketingPv( int nPathId, const ISurfFlatRegion* pSrfPock) ;
bool CheckSelectedId( void) ;
bool DetectShape( int nId, Frame3d frPocket) ;
bool DetectOpenEdgeInsideRaw ( ISurfFlatRegion* pSfr, const ISurfTriMesh* pStmRaw ) ;
// =========================== MIGLIORIE GENERALI ====================
bool ModifyCurveToSmoothed( ICurveComposite* pCrvOffset, double dRightPer, double dleftPer) ;
@@ -129,10 +130,10 @@ class Pocketing : public Machining
const ISurfFlatRegion* pSrfOrig, int nStep, double dStep,
double dAreaToll = 500 * EPS_SMALL) ;
bool CloseOpenSidesInsideRawForProjection( const ISurfFlatRegion* pSfrAct, const ISurfTriMesh* pStmRaw,
ISurfFlatRegion* pSfrMod, ICRVCOMPOPOVECTOR& vCrvMod) ;
bool ManageTmpPropForAdaptingStm( const ISurfFlatRegion* pSfrprojUp, const ISurfFlatRegion* pSfrORIG,
const ISurfFlatRegion* pSrfExtended, const Vector3d& vtTrasl,
ICRVCOMPOPOVECTOR& vCrvWithTmpProps) ;
ISurfFlatRegion* pSfrMod) ;
bool ManageTmpPropForAdaptingStm( const ISurfTriMesh* pStmORIG, const ISurfFlatRegion* pSfrORIG,
const ISurfFlatRegion* pSfrProjUP, const ISurfFlatRegion* pSrfExtended,
const Vector3d& vtTrasl, ICRVCOMPOPOVECTOR& vCrvWithTmpProps) ;
bool SubtractFinalShape( ISurfFlatRegion* pSfrCurr, const Vector3d& vtTrasl, const ISurfTriMesh* pStmShape) ;
bool AdjustAngleForProjectedFace( const ISurfFlatRegion* pSrfFaceT, ICurveComposite* pCrvEdgeBorder, double dAngle) ;
bool SetOpenOrCloseEdge( ISurfFlatRegion* pSrfTP, const ISurfFlatRegion* pSrfForCrvs, const ISurfFlatRegion* pSrfOrig,