EgtGeomKernel :

- miglioria gestione box (Oriented BB).
- pulizia codice.
This commit is contained in:
Daniele Bariletti
2025-10-09 10:25:58 +02:00
parent 433f486091
commit 7968a4e5ed
+29 -64
View File
@@ -1332,7 +1332,7 @@ struct SurfBezForInters {
//----------------------------------------------------------------------------
static bool
IntersLineBezierSurfSet( const Point3d& ptLineStart, const Vector3d& vtLineDir,
const vector<SurfBezForInters>& vSurfBez, const BBox3d& bbVol, PNTVEC3DVECTOR& vInters, INTVECTOR& vSurfInters,
const vector<SurfBezForInters>& vSurfBez, const BBox3d& bbVol, const Frame3d& frVol, PNTVEC3DVECTOR& vInters, INTVECTOR& vSurfInters,
const Vector3d& vtN, DBLDBLVECTOR& vInterv)
{
Point3d r = ptLineStart ;
@@ -1353,16 +1353,21 @@ IntersLineBezierSurfSet( const Point3d& ptLineStart, const Vector3d& vtLineDir,
// calcolo se un intevallo sul dexel interseca il box dell'intero volume spazzato
bool bIntersVol = false ;
for ( int k = 0 ; k < int(vInterv.size()) && ! bIntersVol; ++k) {
INTDBLVECTOR vIntersDash ;
IntersLineBox( r + q* vInterv[k].first, r + q * vInterv[k].second, bbVol, vIntersDash, true) ;
bIntersVol = vIntersDash.size() > 0 ;
{
Point3d rLoc = r;
Vector3d qLoc = q;
rLoc.ToLoc(frVol);
qLoc.ToLoc(frVol);
for (int k = 0; k < int(vInterv.size()) && !bIntersVol; ++k) {
INTDBLVECTOR vIntersDash;
IntersLineBox(rLoc + qLoc * vInterv[k].first, rLoc + qLoc * vInterv[k].second, bbVol, vIntersDash, true);
bIntersVol = vIntersDash.size() > 0;
}
}
// se non sono stati passati gli intervalli allora vuol dire che lo spillone interseca
if ( vInterv.size() == 0)
bIntersVol = true ;
INTVECTOR vIntersCalc ; // debug
if( bIntersVol) {
// interseco con le bezier
for ( int s = 0 ; s < int( vSurfBez.size()) ; ++s) {
@@ -1390,8 +1395,6 @@ IntersLineBezierSurfSet( const Point3d& ptLineStart, const Vector3d& vtLineDir,
// verifico che lo spillone faccia interferenza con il box della superficie
if ( bCalcInters) {
vIntersCalc.push_back( s) ; // debug
// se la linea è parallela all'asse X o Y allora ruoto tutto di 45 gradi rispetto a Z
Vector3d a3, a2, a1, a0, b3, b2, b1, b0 ;
if ( ! bNeedToRot) {
@@ -1519,7 +1522,7 @@ IntersLineBezierSurfSet( const Point3d& ptLineStart, const Vector3d& vtLineDir,
return true ;
}
#if true
#if false
#define TEST
#endif
@@ -1528,21 +1531,12 @@ bool
VolZmap::Comp_5AxisMilling( int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtLs, const Vector3d& vtLe,
double dHeight, double dMaxRad, double dMinRad, int nToolNum, int n5AxisType)
{
static int nStepWithCalc = 0;
static int nStepCounter = 0;
static bool bStepAlreadyCounted = false;
// tolgo il volume spazzato dal tool durante il movimento
// Verifica sull'interferenza con lo Zmap
int nStartI, nStartJ, nEndI, nEndJ ;
if ( ! TestCompoBBox( nGrid, ptS, ptE, vtLs, vtLe, dMaxRad, dMinRad, dHeight, nStartI, nStartJ, nEndI, nEndJ))
return true ;
//debug
if (nGrid == 0 && abs(vtLe.y) < EPS_SMALL && vtLe.x < 0)
int b = 0;
//debug
// vettori di riferimento per trovare i punti ausiliari
int nDegU = 3 ; int nDegV = 1 ;
@@ -1561,8 +1555,6 @@ VolZmap::Comp_5AxisMilling( int nGrid, const Point3d& ptS, const Point3d& ptE, c
int nSurfInd = 0 ;
vector<SurfBezForInters> vSurfBez( nTotSurf) ;
// box dell'intero volume spazzato, nel riferimento globale
BBox3d bbVol = GetCylMoveRotBBox( ptS, ptE, vtLs, vtLe, dMaxRad, dHeight) ;
double dSide = 0 ;
// punti di riferimento sul tool
@@ -1576,6 +1568,10 @@ VolZmap::Comp_5AxisMilling( int nGrid, const Point3d& ptS, const Point3d& ptE, c
Vector3d vtDirTop = ptE - ptS ;
Vector3d vtDirTip = ptP2T - ptP1T ;
// box dell'intero volume spazzato, nel riferimento object oriented
BBox3d bbVol ;
Frame3d frVol ; frVol.Set(ptS, vtLs, vtDirTop) ;
// punti sul top e tip del tool che servono per costruire le bilineare di congiunzione tra step
PNTVECTOR vPntTipStartFront(3) ;
PNTVECTOR vPntTipEndFront(3) ;
@@ -1889,10 +1885,6 @@ VolZmap::Comp_5AxisMilling( int nGrid, const Point3d& ptS, const Point3d& ptE, c
}
}
//debug
vector<IGeoObj*> vGeo;
//debug
// inizializzo le superfici bilineari e i parametri per le intersezioni
for ( int z = 0 ; z < int( vvPtCtrl.size()) ; ++z) {
vSurfBez[nSurfInd].sBez.Init( nDegU, nDegV, nSpanU, nSpanV, bRat) ;
@@ -1935,8 +1927,7 @@ VolZmap::Comp_5AxisMilling( int nGrid, const Point3d& ptS, const Point3d& ptE, c
vtDirX = vvPtCtrl[z][7] - vvPtCtrl[z][3];
}
// calcolo il box in un riferimento che usi come asse x la direzione P01 - P00 ( proiettata sul piano perperndicolare a Z)
// calcolo il box in un riferimento che usi come asse x la direzione P10 - P00 o P11 - P01 ( proiettata sul piano perperndicolare a Z)
if ( vSurfBez[nSurfInd].frBox.Set( ORIG, vtDirZ, vtDirX)) {
// porto tutti i punti in quel riferimento e calcolo il box
PNTVECTOR vPtCtrlLoc = vvPtCtrl[z] ;
@@ -1945,27 +1936,15 @@ VolZmap::Comp_5AxisMilling( int nGrid, const Point3d& ptS, const Point3d& ptE, c
vSurfBez[nSurfInd].bbSurfOriented.Add( vPtCtrlLoc) ;
}
#ifdef TEST
if (nGrid == 0)
vGeo.push_back(vSurfBez[nSurfInd].sBez.Clone());
#endif
// aggiungo i punti al box del volume spazzato
PNTVECTOR vPtCtrlLoc = vvPtCtrl[z] ;
for (int p = 0; p < int(vPtCtrlLoc.size()); ++p)
vPtCtrlLoc[p].ToLoc(frVol);
bbVol.Add(vPtCtrlLoc) ;
++ nSurfInd ;
}
#ifdef TEST
if (nGrid == 0) {
bStepAlreadyCounted = false;
++nStepCounter;
}
if (false) {
vector<Color> vCol(nTotSurf);
fill(vCol.begin(), vCol.end(), Color(255, 128, 0));
SaveGeoObj(vGeo, vCol, "D:/Temp/VirtualMilling/5axisAdvanced/finalApprox.nge");
}
#endif
// scorro tutti gli spilloni interessati
int j = 0 ;
int nLastForwardJ = -1 ;
@@ -1983,24 +1962,6 @@ VolZmap::Comp_5AxisMilling( int nGrid, const Point3d& ptS, const Point3d& ptE, c
} ;
vector<IntervalsToSubtract> vIntervalsToSubtr ;
#ifdef TEST
//debug
if (nStepCounter >= 153 && false) {
if (nGrid == 2)
int d = 0;
if (nStepCounter == 153) {
int a = 0;
if (nGrid == 0) {
vector<Color> vCol(nTotSurf);
fill(vCol.begin(), vCol.end(), Color(255, 128, 0));
SaveGeoObj(vGeo, vCol, "D:/Temp/VirtualMilling/5axisAdvanced/finalApprox.nge");
}
}
}
//debug
#endif
for ( int i = nStartI ; i <= nEndI ; ++ i) {
nLastForwardJ = -1 ;
j = nStartJ ;
@@ -2022,7 +1983,7 @@ VolZmap::Comp_5AxisMilling( int nGrid, const Point3d& ptS, const Point3d& ptE, c
vInterv.emplace_back( vDexel[k].dMin, vDexel[k].dMax) ;
if ( vDexel.size() != 0) {
IntersLineBezierSurfSet( r, q, vSurfBez, bbVol, vInters, vSurfInters, vtLs, vInterv) ;
IntersLineBezierSurfSet( r, q, vSurfBez, bbVol, frVol, vInters, vSurfInters, vtLs, vInterv) ;
if ( vInters.size() > 2) {
SortGroupInters( vInters, vStartEnds, Z_AX) ;
@@ -2046,7 +2007,7 @@ VolZmap::Comp_5AxisMilling( int nGrid, const Point3d& ptS, const Point3d& ptE, c
INTVECTOR vSurfX ;
INTINTVECTOR vStartEndsX ;
bool bXInclude = false ;
IntersLineBezierSurfSet( ptLineStart, vtLineStart, vSurfBez, bbVol, vIntersX, vSurfX, V_NULL, vEmpty) ;
IntersLineBezierSurfSet( ptLineStart, vtLineStart, vSurfBez, bbVol, frVol, vIntersX, vSurfX, V_NULL, vEmpty) ;
if ( vIntersX.size() > 1) {
SortGroupInters( vIntersX, vStartEndsX, X_AX) ;
if ( vStartEndsX.size() != 0)
@@ -2060,7 +2021,7 @@ VolZmap::Comp_5AxisMilling( int nGrid, const Point3d& ptS, const Point3d& ptE, c
INTVECTOR vSurfY ;
INTINTVECTOR vStartEndsY ;
bool bYInclude = false ;
IntersLineBezierSurfSet( ptLineStart, vtLineStart, vSurfBez, bbVol, vIntersY, vSurfY, V_NULL, vEmpty) ;
IntersLineBezierSurfSet( ptLineStart, vtLineStart, vSurfBez, bbVol, frVol, vIntersY, vSurfY, V_NULL, vEmpty) ;
if ( vIntersY.size() > 1) {
SortGroupInters( vIntersY, vStartEndsY, Y_AX) ;
if ( vStartEndsY.size() != 0)
@@ -2397,7 +2358,11 @@ VolZmap::MillingGeneralMotionStep( const Point3d& ptPs, const Vector3d& vtDs, co
InitializePointsAndVectors( ptSti, ptEni, vtDSi, vtDEi, ptLs, ptLe, vtLs, vtLe) ;
// Standard è multithread
#ifdef _DEBUG
constexpr bool MULTITHREAD = false ;
#else
constexpr bool MULTITHREAD = true ;
#endif
if ( MULTITHREAD) {
// Ciclo sulle mappe
vector<future<bool>> vRes( m_nMapNum) ;