EgtMachKernel :

- in sgrossature di superfici, correzione errori su PlaneZ.
This commit is contained in:
Riccardo Elitropi
2024-10-25 13:28:27 +02:00
parent 3df4b5a210
commit f1b66dc020
2 changed files with 74 additions and 36 deletions
+72 -35
View File
@@ -90,7 +90,9 @@ using namespace std ;
static string KEY_SURF_POCK = "SurfPock_" ;
static string KEY_SURF_LIMIT = "SurfLimit_" ;
#define ENABLE_DEBUG 0
#define ENABLE_DEBUG_SFR 0
#define ENABLE_DEBUG_FEEDS 0
static string _DEBUG_GROUP_TERRACE = "Terraces" ;
static string _DEBUG_GROUP_FEED = "Feeds" ;
bool _DEBUG_CLEAR_GROUP_TERRACE = TRUE ;
@@ -1301,7 +1303,7 @@ SurfRoughing::ProcessPath( int nPathId, int nTempId, int nPvId, int nClId)
// se richiesto PlaneZ detection, aggiungo altri step intermedi ( planeZSteps )
PLANEZFACEVECTOR vPlaneZ ;
if ( m_bDetectPlaneZ) {
if ( ! DetectPlaneZ( vpStm, fr_pCompo, vtTool, vPlaneZ))
if ( ! DetectPlaneZ( vpStm, fr_pCompo, vtTool, vPlaneZ, - GetOffsL(), dDepth - GetOffsL()))
return false ;
}
@@ -1347,13 +1349,13 @@ SurfRoughing::ProcessPath( int nPathId, int nTempId, int nPvId, int nClId)
}
}
INTDBLVECTOR vExtraStep ; // Depth per PlaneZ e SubSteps
for ( int i = 0 ; i <= nSubStep ; ++ i)
for ( int i = 0 ; i < nSubStep ; ++ i)
vExtraStep.emplace_back( make_pair( -1, - ( i + 1) * dSubStep)) ;
if ( nSubStep != -1) {
for ( int i = 0 ; i < int( vPlaneZ.size()) ; ++ i)
vExtraStep.emplace_back( make_pair( i, vPlaneZ[i].second)) ;
sort( vExtraStep.begin(), vExtraStep.end(), []( const INTDBL& a, const INTDBL& b)
{ return a.first < b.first ; }) ;
{ return a.second > b.second ; }) ;
}
// ... e poi gli step extra
int nIndRef = 0 ; // ( step base sottostante allo step extra corrente )
@@ -1471,6 +1473,9 @@ SurfRoughing::ProcessPath( int nPathId, int nTempId, int nPvId, int nClId)
if ( ! IsNull( pSfrRef) && pSfrRef->IsValid())
pSfrRef->Offset( OFFS_CORR_OPEN_EDGES + GetOffsR(), ICurve::OFF_FILLET) ; // correzione
// cerco il Chunk nC-esimo della silhouette da rimuovere
PtrOwner<ISurfFlatRegion> pSfrPlaneZ( CreateSurfFlatRegion()) ;
if ( IsNull( pSfrPlaneZ))
return false ;
for ( int nC = 0 ; nC < pSfrSil->GetChunkCount() ; ++ nC) {
PtrOwner<ISurfFlatRegion> pSfrSilChunk( pSfrSil->CloneChunk( nC)) ;
PtrOwner<ISurfFlatRegion> pSfrMyFace( CloneSurfFlatRegion( it->pSfrPlaneZ)) ;
@@ -1479,23 +1484,30 @@ SurfRoughing::ProcessPath( int nPathId, int nTempId, int nPvId, int nClId)
return false ;
pSfrMyFace->Intersect( *pSfrSilChunk) ;
if ( ! IsNull( pSfrMyFace) && pSfrMyFace->IsValid()) {
delete( it->pSfrPlaneZ) ;
double dSilIslDepth = it->dDepth + SIL_DEPTH_TOL ;
bool bOkSil_isl = false ;
PtrOwner<ISurfFlatRegion> pSfrSilIslands( GetSfrSilhouette( pCavParSilh, dSilIslDepth, SILH_TOL, bOkSil_isl)) ;
if ( ! bOkSil_isl) {
m_pMchMgr->SetLastError( 3024, "Error in SurfRoughing : region not computable") ;
return false ;
}
if ( ! IsNull( pSfrSilIslands) && pSfrSilIslands->IsValid()) {
pSfrSilIslands->Offset( GetOffsR(), ICurve::OFF_CHAMFER) ;
pSfrSilChunk->Subtract( *pSfrSilIslands) ;
it->pSfrRemoved = CloneSurfFlatRegion( pSfr) ;
if ( it->pSfrRemoved != nullptr && it->pSfrRemoved->IsValid())
it->pSfrRemoved->Subtract( *pSfrSilIslands) ;
}
it->pSfrPlaneZ = Release( pSfrSilChunk) ;
break ;
if ( pSfrPlaneZ->IsValid() && pSfrPlaneZ->GetChunkCount() > 0)
pSfrPlaneZ->Add( *pSfrSilChunk) ;
else
pSfrPlaneZ.Set( pSfrSilChunk) ;
}
}
if ( ! IsNull( pSfrPlaneZ) && pSfrPlaneZ->IsValid()) {
delete( it->pSfrPlaneZ) ;
it->pSfrPlaneZ = nullptr ;
double dSilIslDepth = it->dDepth + SIL_DEPTH_TOL ;
bool bOkSil_isl = false ;
PtrOwner<ISurfFlatRegion> pSfrSilIslands( GetSfrSilhouette( pCavParSilh, dSilIslDepth, SILH_TOL, bOkSil_isl)) ;
if ( ! bOkSil_isl) {
m_pMchMgr->SetLastError( 3024, "Error in SurfRoughing : region not computable") ;
return false ;
}
if ( ! IsNull( pSfrSilIslands) && pSfrSilIslands->IsValid()) {
pSfrSilIslands->Offset( GetOffsR(), ICurve::OFF_CHAMFER) ;
pSfrPlaneZ->Subtract( *pSfrSilIslands) ;
delete( it->pSfrRemoved) ;
it->pSfrRemoved = CloneSurfFlatRegion( pSfr) ;
if ( it->pSfrRemoved != nullptr && it->pSfrRemoved->IsValid())
it->pSfrRemoved->Subtract( *pSfrSilIslands) ;
it->pSfrPlaneZ = Release( pSfrPlaneZ) ;
}
}
if ( it->pSfrPlaneZ != nullptr && it->pSfrPlaneZ->IsValid())
@@ -1546,6 +1558,10 @@ SurfRoughing::ProcessPath( int nPathId, int nTempId, int nPvId, int nClId)
double dZLocFeedCoef = GetAdaptedCoeffFeed( ( it->bSubStep || it->bPlaneZStep), it->dDepth, dStep) ;
pSfr->SetTempParam( dZLocFeedCoef, 1) ;
#if ENABLE_DEBUG_SFR
DrawLoopsSurf( pSfr, false, Color( .0, 1., 0., .5), false, 0) ;
#endif
// la salvo nel gruppo temporaneo
int nNew_SfrPock_Id = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nTempId, Release( pSfr)) ;
if ( nNew_SfrPock_Id == GDB_ID_NULL) {
@@ -1615,7 +1631,7 @@ SurfRoughing::ProcessPath( int nPathId, int nTempId, int nPvId, int nClId)
//----------------------------------------------------------------------------
bool
SurfRoughing::DetectPlaneZ( const CISURFTMPVECTOR& vpStm, const Frame3d& frCompo, const Vector3d& vtTool,
PLANEZFACEVECTOR& vPlaneZ) const
PLANEZFACEVECTOR& vPlaneZ, double dMinDepth, double dMaxDepth) const
{
// se non richiesta analisi planeZ, esco
vPlaneZ.clear() ;
@@ -1634,12 +1650,15 @@ SurfRoughing::DetectPlaneZ( const CISURFTMPVECTOR& vpStm, const Frame3d& frCompo
if ( ! vpStm[i]->GetFacetCenter( nF, ptCen, vtFaceN) ||
! AreSameVectorEpsilon( vtTool, vtFaceN, 25 * EPS_SMALL))
continue ;
// se area troppo piccola, non la considero ( almeno area come faccia utensile)
double dArea = 0. ;
if ( ! vpStm[i]->GetFacetArea( nF, dArea) || dArea < PIGRECO * pow( m_TParams.m_dDiam / 2, 2))
continue ;
// se faccia parallela a vtTool, ricavo la sua depth ( ptCen.z)
ptCen.ToLoc( frCompo) ;
// se fuori dal range, non la considero
if ( abs( ptCen.z) < dMinDepth + 2 * EPS_SMALL || abs( ptCen.z) > dMaxDepth - 2 * EPS_SMALL)
continue ;
// se area troppo piccola, non la considero ( almeno area come faccia utensile)
double dArea = 0. ;
if ( ! vpStm[i]->GetFacetArea( nF, dArea) || dArea < PIGRECO * m_TParams.m_dDiam * m_TParams.m_dDiam / 4.)
continue ;
// recupero la superficie piana della faccia
POLYLINEVECTOR vPL ;
if ( ! vpStm[i]->GetFacetLoops( nF, vPL))
@@ -1647,11 +1666,11 @@ SurfRoughing::DetectPlaneZ( const CISURFTMPVECTOR& vpStm, const Frame3d& frCompo
PtrOwner<ISurfFlatRegion> pSfrFace( CreateSurfFlatRegion()) ;
if ( IsNull( pSfrFace))
return false ;
for ( int k = 0 ; k < int( vPL.size()) ; ++ k) {
for ( int j = 0 ; j < int( vPL.size()) ; ++ j) {
PtrOwner<ICurveComposite> pCompoLoop( CreateCurveComposite()) ;
if ( IsNull( pCompoLoop) || ! pCompoLoop->FromPolyLine( vPL[k]))
if ( IsNull( pCompoLoop) || ! pCompoLoop->FromPolyLine( vPL[j]))
return false ;
if ( k == 0) {
if ( j == 0) {
if ( ! pSfrFace->AddExtLoop( Release( pCompoLoop)))
return false ;
}
@@ -1662,10 +1681,20 @@ SurfRoughing::DetectPlaneZ( const CISURFTMPVECTOR& vpStm, const Frame3d& frCompo
}
if ( ! pSfrFace->IsValid())
continue ;
// definisco un nuovo Step di tipo PlaneZ
vPlaneZ.resize( vPlaneZ.size() + 1) ;
vPlaneZ.back().first.Set( pSfrFace) ;
vPlaneZ.back().second = ptCen.z ;
// controllo se ho già trovato una faccia su un piano simile
bool bSamePlaneZ = false ;
for ( int j = 0 ; j < int( vPlaneZ.size()) && ! bSamePlaneZ ; ++ j) {
if ( abs( ptCen.z - vPlaneZ[j].second) < 2 * EPS_SMALL) {
bSamePlaneZ = true ;
vPlaneZ[j].first->Add( *pSfrFace) ;
}
}
if ( ! bSamePlaneZ) {
// definisco un nuovo Step di tipo PlaneZ
vPlaneZ.resize( vPlaneZ.size() + 1) ;
vPlaneZ.back().first.Set( pSfrFace) ;
vPlaneZ.back().second = ptCen.z ;
}
}
}
@@ -2213,6 +2242,9 @@ SurfRoughing::AddPocket( const INTINTVECTOR& vPocket, const Vector3d& vtTool, do
ICurveLine* pLine = GetCurveLine( pCurve) ;
Point3d ptP3 = pLine->GetEnd() ;
Vector3d vtMove ; pLine->GetStartDir( vtMove) ;
#if ENABLE_DEBUG_FEEDS
DrawFeed( pLine, dCoeffFeed * GetRightFeed( vtMove, vtTool)) ;
#endif
SetFeed( dCoeffFeed * GetRightFeed( vtMove, vtTool)) ;
if ( AddLinearMove( ptP3) == GDB_ID_NULL)
return false ;
@@ -2224,6 +2256,9 @@ SurfRoughing::AddPocket( const INTINTVECTOR& vPocket, const Vector3d& vtTool, do
Vector3d vtN = pArc->GetNormVersor() ;
Point3d ptP3 ;
pArc->GetEndPoint( ptP3) ;
#if ENABLE_DEBUG_FEEDS
DrawFeed( pArc, dCoeffFeed * GetFeed()) ;
#endif
SetFeed( dCoeffFeed * GetFeed()) ;
if ( AddArcMove( ptP3, ptCen, dAngCen, vtN) == GDB_ID_NULL)
return false ;
@@ -3195,7 +3230,9 @@ SurfRoughing::DrawLoopsSurf( const ISurfFlatRegion* pSfr, bool bUniform, Color C
if ( pSfr == nullptr || ! pSfr->IsValid())
return ;
int nInd = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pSfr->Clone()) ;
int nIdGroup = m_pGeomDB->AddGroup( GDB_ID_NULL, GDB_ID_ROOT, GLOB_FRM) ;
int nIdLayer = m_pGeomDB->AddGroup( GDB_ID_NULL, nIdGroup, GLOB_FRM) ;
int nInd = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nIdLayer, pSfr->Clone()) ;
m_pGeomDB->SetMaterial( nInd, Color( 0., 255., 0., .5)) ;
for ( int nC = 0 ; nC < pSfr->GetChunkCount() ; ++ nC) {
for ( int nL = 0 ; nL < pSfr->GetLoopCount( nC) ; ++ nL) {
@@ -3203,7 +3240,7 @@ SurfRoughing::DrawLoopsSurf( const ISurfFlatRegion* pSfr, bool bUniform, Color C
for ( int nU = 0 ; nU < pCrvCompo->GetCurveCount() ; ++ nU) {
int nProp0 ; pCrvCompo->GetCurveTempProp( nU, nProp0, 0) ;
int nProp1 ; pCrvCompo->GetCurveTempProp( nU, nProp1, 1) ;
int nInd = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pCrvCompo->GetCurve( nU)->Clone()) ;
int nInd = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nIdLayer, pCrvCompo->GetCurve( nU)->Clone()) ;
m_pGeomDB->SetMaterial( nInd, bUniform ? WHITE : ( nProp0 == 0 ? BLUE : RED)) ;
}
}
+2 -1
View File
@@ -107,7 +107,8 @@ class SurfRoughing : public Machining
bool GetCurves( SelData Id, ICURVEPLIST& lstPC) ;
bool Chain( int nGrpDestId) ;
bool ProcessPath( int nPathId, int nTempId, int nPvId, int nClId) ;
bool DetectPlaneZ( const CISURFTMPVECTOR& vpStm, const Frame3d& frCompo, const Vector3d& vtTool, PLANEZFACEVECTOR& vPlaneZ) const ;
bool DetectPlaneZ( const CISURFTMPVECTOR& vpStm, const Frame3d& frCompo, const Vector3d& vtTool, PLANEZFACEVECTOR& vPlaneZ,
double dMinDepth, double dMaxDepth) const ;
bool CalcPaths( const INTINTVECTOR& vPocket, STEPINFOSRVECTOR& vStepInfo) const ;
bool AddPocket( const INTINTVECTOR& vPocket, const Vector3d& vtTool, double dElev, double dStep, double dSubStep, bool bSplitArcs) ;
bool AddApproach( const Point3d& ptP, const Vector3d& vtTool, double dSafeZ, double dElev, double dAppr, bool bOutStart) ;