EgtGeomKernel :

- nuova versione VM 5 assi per caso lama e 3 assi.
This commit is contained in:
Daniele Bariletti
2025-06-03 15:48:37 +02:00
parent 529fa2e4a0
commit f03adb9206
2 changed files with 105 additions and 100 deletions
+102 -96
View File
@@ -1120,26 +1120,17 @@ GetAlongAcrossRotation( const Vector3d& vtDir1, const Vector3d& vtDir2, const Ve
//----------------------------------------------------------------------------
bool
VolZmap::UpdateMaxMin( Point3d ptBez, Vector3d vtN, double& dMin, double& dMax, Point3d& ptMin, Point3d& ptMax, Vector3d& vtMin, Vector3d& vtMax,
int& nSurfIdMax, int& nSurfIdMin, const int nSurfId) const
VolZmap::UpdateMaxMin( Point3d ptBez, Vector3d vtN, double& dMin, double& dMax, Point3d& ptMin, Point3d& ptMax, Vector3d& vtMin, Vector3d& vtMax) const
{
if ( ptBez.z > dMax) {
bool bCorrectUpdate = ! (ptBez.z - dMax < 2 && ( (nSurfIdMax == CuttingSurface::TOOL && nSurfId == CuttingSurface::TOP_BOT_BZ) || (nSurfIdMax == CuttingSurface::TOP_BOT_BZ && nSurfId == CuttingSurface::TOOL))) ;
if ( bCorrectUpdate) {
dMax = ptBez.z ;
ptMax = ptBez ;
vtMax = -vtN ; // inverto il segno della normale, perché devo passare la normale della supercie tagliata, non di quella di taglio
nSurfIdMax = nSurfId ;
}
dMax = ptBez.z ;
ptMax = ptBez ;
vtMax = -vtN ; // inverto il segno della normale, perché devo passare la normale della supercie tagliata, non di quella di taglio
}
if ( ptBez.z < dMin) {
bool bCorrectUpdate = ! (dMin - ptBez.z < 2 && ( (nSurfIdMin == CuttingSurface::TOOL && nSurfId == CuttingSurface::TOP_BOT_BZ) || (nSurfIdMin == CuttingSurface::TOP_BOT_BZ && nSurfId == CuttingSurface::TOOL))) ;
if ( bCorrectUpdate) {
dMin = ptBez.z ;
ptMin = ptBez ;
vtMin = -vtN ; // inverto il segno della normale, perché devo passare la normale della supercie tagliata, non di quella di taglio
nSurfIdMin = nSurfId ;
}
dMin = ptBez.z ;
ptMin = ptBez ;
vtMin = -vtN ; // inverto il segno della normale, perché devo passare la normale della supercie tagliata, non di quella di taglio
}
return true ;
}
@@ -1174,17 +1165,18 @@ VolZmap::InitializeAuxPoints( Point3d ptTop1s[3], Point3d ptTop1e[3], Point3d pt
//----------------------------------------------------------------------------
bool
VolZmap::GenTool_5AxisMilling( int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtLs, const Vector3d& vtLe, int nToolNum, const int nPhase)
VolZmap::GenTool_5AxisMilling( int nGrid, const PNTVECTOR& ptS, const PNTVECTOR& ptE, const VCT3DVECTOR& vtLs, const VCT3DVECTOR& vtLe, int nToolNum, const int nPhase)
{
// Controllo utensile
if ( m_nCurrTool < 0 || m_nCurrTool >= int( m_vTool.size()))
return false ;
Tool& CurrTool = m_vTool[m_nCurrTool] ;
int nStepCnt = ptS.size() ;
// Descrizione geometrica del moto
Point3d ptI = ptS ;
Point3d ptF = ptE ;
Vector3d vtMove = ptE - ptS ;
PNTVECTOR ptI = ptS ;
PNTVECTOR ptF = ptE ;
// Vettore delle normali agli archi
const VCT3DVECTOR& vArcNorm = CurrTool.GetArcNormalVec() ;
// Poinché l'asse utensile è parallelo all'asse Z, definisco un sistema di
@@ -1247,19 +1239,19 @@ VolZmap::GenTool_5AxisMilling( int nGrid, const Point3d& ptS, const Point3d& ptE
else if ( ptStart.x > ptEnd.x) {
double dMaxRad = ptStart.x ;
double dMinRad = ptEnd.x ;
CompConus_5AxisMilling( nGrid, ptI, ptF, vtLs, vtLe, dHeight, dMaxRad, dMinRad,
bTapB, bTapT, vtNormSt, vtNormEn, nToolNum, nPhase) ;
//CompConus_5AxisMilling( nGrid, ptI, ptF, vtLs, vtLe, dHeight, dMaxRad, dMinRad,
// bTapB, bTapT, vtNormSt, vtNormEn, nToolNum, nPhase) ;
}
// altrimenti X crescente, è un cono con vettore opposto a quello dell'utensile
else {
double dMaxRad = ptEnd.x ;
double dMinRad = ptStart.x ;
Point3d ptIn = ptI - vtLs * dHeight ;
Point3d ptFn = ptF - vtLe * dHeight ;
//Point3d ptIn = ptI - vtLs * dHeight ;
//Point3d ptFn = ptF - vtLe * dHeight ;
vtNormEn.z = -vtNormEn.z ;
vtNormSt.z = -vtNormSt.z ;
CompConus_5AxisMilling( nGrid, ptIn, ptFn, - vtLs, -vtLe, dHeight, dMaxRad, dMinRad,
bTapT, bTapB, vtNormEn, vtNormSt, nToolNum, nPhase) ;
//CompConus_5AxisMilling( nGrid, ptIn, ptFn, - vtLs, -vtLe, dHeight, dMaxRad, dMinRad,
// bTapT, bTapB, vtNormEn, vtNormSt, nToolNum, nPhase) ;
}
// Passo alla curva successiva
pPrevCurve = pCurve ;
@@ -1280,11 +1272,11 @@ VolZmap::GenTool_5AxisMilling( int nGrid, const Point3d& ptS, const Point3d& ptE
Point3d ptEnd ; pArc->GetEndPoint( ptEnd) ;
Point3d ptCen = pArc->GetCenter() ;
double dRadius = pArc->GetRadius() ;
// Determino le posizioni iniziale e finale del centro della sfera
Point3d ptCenS = ptI - vtLs * ( ptStart.y - ptCen.y) ;
Point3d ptCenE = ptF - vtLe * ( ptStart.y - ptCen.y) ;
// Eseguo l'asportazione del materiale
CompBall_Milling( nGrid, ptCenS, ptCenE, dRadius, nToolNum) ;
//// Determino le posizioni iniziale e finale del centro della sfera
//Point3d ptCenS = ptI - vtLs * ( ptStart.y - ptCen.y) ;
//Point3d ptCenE = ptF - vtLe * ( ptStart.y - ptCen.y) ;
//// Eseguo l'asportazione del materiale
//CompBall_Milling( nGrid, ptCenS, ptCenE, dRadius, nToolNum) ;
// aggiorno l'altezza
dHeight = abs( ptStart.y - ptEnd.y) ;
// Passo alla curva successiva
@@ -1294,8 +1286,10 @@ VolZmap::GenTool_5AxisMilling( int nGrid, const Point3d& ptS, const Point3d& ptE
// Determino le posizioni iniziale e finale del componente successivo
dCumHeight += dHeight ;
ptI = ptS - vtLs * dCumHeight ;
ptF = ptE - vtLe * dCumHeight ;
for( int j = 0 ; j < nStepCnt ; ++j) {
ptI[j] = ptS[j] - vtLs[j] * dCumHeight ;
ptF[j] = ptE[j] - vtLe[j] * dCumHeight ;
}
}
return true ;
@@ -1308,7 +1302,7 @@ static int nCount = 0 ;
//----------------------------------------------------------------------------
bool
VolZmap::Comp_5AxisMilling( int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtLs, const Vector3d& vtLe,
VolZmap::Comp_5AxisMilling( int nGrid, const PNTVECTOR& ptS, const PNTVECTOR& ptE, const VCT3DVECTOR& vtLs, const VCT3DVECTOR& vtLe,
double dHeight, double dMaxRad, double dMinRad, int nToolNum)
{
// tolgo il volume spazzato dal tool durante il movimento
@@ -1515,7 +1509,6 @@ VolZmap::Comp_5AxisMilling( int nGrid, const Point3d& ptS, const Point3d& ptE, c
Point3d ptMin, ptMax ;
double dMin = INFINITO, dMax = -10 ;
Vector3d vtMin, vtMax ;
int nSurfIdMin = CuttingSurface::NONE, nSurfIdMax = CuttingSurface::NONE ;
// interseco con le bilineari
for( int s = 0 ; s < nTotSurf ; ++s) {
@@ -1537,7 +1530,7 @@ VolZmap::Comp_5AxisMilling( int nGrid, const Point3d& ptS, const Point3d& ptE, c
Point3d ptBez1 ;
Vector3d vtN1 ;
vSurfBez[s]->GetPointNrmD1D2(dU1, dV1, ISurfBezier::Side::FROM_MINUS, ISurfBezier::Side::FROM_MINUS, ptBez1, vtN1) ;
UpdateMaxMin( ptBez1, vtN1, dMin, dMax, ptMin, ptMax, vtMin, vtMax, nSurfIdMax, nSurfIdMin, CuttingSurface::TOP_BOT_BZ) ;
UpdateMaxMin( ptBez1, vtN1, dMin, dMax, ptMin, ptMax, vtMin, vtMax) ;
}
}
if ( nRoots > 1 && vdRoots[1] > 0 - EPS_ZERO && vdRoots[1] < 1 + EPS_ZERO) {
@@ -1547,7 +1540,7 @@ VolZmap::Comp_5AxisMilling( int nGrid, const Point3d& ptS, const Point3d& ptE, c
Point3d ptBez2 ;
Vector3d vtN2 ;
vSurfBez[s]->GetPointNrmD1D2(dU2, dV2, ISurfBezier::Side::FROM_MINUS, ISurfBezier::Side::FROM_MINUS, ptBez2, vtN2) ;
UpdateMaxMin( ptBez2, vtN2, dMin, dMax, ptMin, ptMax, vtMin, vtMax, nSurfIdMax, nSurfIdMin, CuttingSurface::TOP_BOT_BZ) ;
UpdateMaxMin( ptBez2, vtN2, dMin, dMax, ptMin, ptMax, vtMin, vtMax) ;
}
}
}
@@ -1564,8 +1557,8 @@ VolZmap::Comp_5AxisMilling( int nGrid, const Point3d& ptS, const Point3d& ptE, c
Point3d pt1, pt2 ;
Vector3d vt1, vt2 ;
if ( IntersLineCylinder( r, Z_AX, frStartCyl, dHeight, dMaxRad, false, false, pt1, vt1, pt2, vt2)) {
UpdateMaxMin( pt1, -vt1, dMin, dMax, ptMin, ptMax, vtMin, vtMax, nSurfIdMax, nSurfIdMin, CuttingSurface::TOOL) ;
UpdateMaxMin( pt2, -vt2, dMin, dMax, ptMin, ptMax, vtMin, vtMax, nSurfIdMax, nSurfIdMin, CuttingSurface::TOOL) ;
UpdateMaxMin( pt1, -vt1, dMin, dMax, ptMin, ptMax, vtMin, vtMax) ;
UpdateMaxMin( pt2, -vt2, dMin, dMax, ptMin, ptMax, vtMin, vtMax) ;
}
}
if ( bbEndCyl.SqDistFromPointXY( r) < EPS_ZERO) {
@@ -1574,8 +1567,8 @@ VolZmap::Comp_5AxisMilling( int nGrid, const Point3d& ptS, const Point3d& ptE, c
Point3d pt1, pt2 ;
Vector3d vt1, vt2 ;
if ( IntersLineCylinder( r, Z_AX, frEndCyl, dHeight, dMaxRad, false, false, pt1, vt1, pt2, vt2)){
UpdateMaxMin( pt1, -vt1, dMin, dMax, ptMin, ptMax, vtMin, vtMax, nSurfIdMax, nSurfIdMin, CuttingSurface::TOOL) ;
UpdateMaxMin( pt2, -vt2, dMin, dMax, ptMin, ptMax, vtMin, vtMax, nSurfIdMax, nSurfIdMin, CuttingSurface::TOOL) ;
UpdateMaxMin( pt1, -vt1, dMin, dMax, ptMin, ptMax, vtMin, vtMax) ;
UpdateMaxMin( pt2, -vt2, dMin, dMax, ptMin, ptMax, vtMin, vtMax) ;
}
}
}
@@ -1587,8 +1580,8 @@ VolZmap::Comp_5AxisMilling( int nGrid, const Point3d& ptS, const Point3d& ptE, c
Point3d pt1, pt2 ;
Vector3d vt1, vt2 ;
if ( IntersLineConus( r, Z_AX, frStartCon, dTan, dMinH, dMaxH, false, false, pt1, vt1, pt2, vt2)) {
UpdateMaxMin( pt1, -vt1, dMin, dMax, ptMin, ptMax, vtMin, vtMax, nSurfIdMax, nSurfIdMin, CuttingSurface::TOOL) ;
UpdateMaxMin( pt2, -vt2, dMin, dMax, ptMin, ptMax, vtMin, vtMax, nSurfIdMax, nSurfIdMin, CuttingSurface::TOOL) ;
UpdateMaxMin( pt1, -vt1, dMin, dMax, ptMin, ptMax, vtMin, vtMax) ;
UpdateMaxMin( pt2, -vt2, dMin, dMax, ptMin, ptMax, vtMin, vtMax) ;
}
}
if ( bbEndCyl.SqDistFromPointXY( r) < EPS_ZERO) {
@@ -1597,8 +1590,8 @@ VolZmap::Comp_5AxisMilling( int nGrid, const Point3d& ptS, const Point3d& ptE, c
Point3d pt1, pt2 ;
Vector3d vt1, vt2 ;
if ( IntersLineConus( r, Z_AX, frEndCon, dTan, dMinH, dMaxH, false, false, pt1, vt1, pt2, vt2)) {
UpdateMaxMin( pt1, -vt1, dMin, dMax, ptMin, ptMax, vtMin, vtMax, nSurfIdMax, nSurfIdMin, CuttingSurface::TOOL) ;
UpdateMaxMin( pt2, -vt2, dMin, dMax, ptMin, ptMax, vtMin, vtMax, nSurfIdMax, nSurfIdMin, CuttingSurface::TOOL) ;
UpdateMaxMin( pt1, -vt1, dMin, dMax, ptMin, ptMax, vtMin, vtMax) ;
UpdateMaxMin( pt2, -vt2, dMin, dMax, ptMin, ptMax, vtMin, vtMax) ;
}
}
}
@@ -1612,7 +1605,7 @@ VolZmap::Comp_5AxisMilling( int nGrid, const Point3d& ptS, const Point3d& ptE, c
//----------------------------------------------------------------------------
bool
VolZmap::CompCyl_5AxisMilling( int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtLs, const Vector3d& vtLe,
VolZmap::CompCyl_5AxisMilling( int nGrid, const PNTVECTOR& ptS, const PNTVECTOR& ptE, const VCT3DVECTOR& vtLs, const VCT3DVECTOR& vtLe,
double dHeight, double dRadius, int nToolNum, const int nPhase)
{
bool bOk = true ;
@@ -1747,7 +1740,7 @@ VolZmap::Conus_5AxisMilling( int nGrid, const Point3d& ptS, const Point3d& ptE,
//----------------------------------------------------------------------------
bool
VolZmap::SelectGeneralMotion( int nGrid, const Point3d& ptPs, const Point3d& ptPe, const Vector3d& vtLs, const Vector3d& vtLe, const int nPhase)
VolZmap::SelectGeneralMotion( int nGrid, const PNTVECTOR& ptPs, const PNTVECTOR& ptPe, const VCT3DVECTOR& vtLs, const VCT3DVECTOR& vtLe, const int nPhase)
{
// Controllo utensile
if ( m_nCurrTool < 0 || m_nCurrTool >= int( m_vTool.size()))
@@ -1757,12 +1750,12 @@ VolZmap::SelectGeneralMotion( int nGrid, const Point3d& ptPs, const Point3d& ptP
switch ( CurrTool.GetType()) {
case Tool::GEN :
return GenTool_5AxisMilling( nGrid, ptPs, ptPe, vtLs, vtLe, CurrTool.GetToolNum(), nPhase) ;
case Tool::CYLMILL :
return Cyl_5AxisMilling( nGrid, ptPs, ptPe, vtLs, vtLe, CurrTool.GetToolNum(), nPhase) ;
case Tool::BALLMILL :
return CylBall_5AxisMilling( nGrid, ptPs, ptPe, vtLs, vtLe, CurrTool.GetToolNum(), nPhase) ;
case Tool::CONEMILL :
return Conus_5AxisMilling( nGrid, ptPs, ptPe, vtLs, vtLe, CurrTool.GetToolNum(), nPhase) ;
//case Tool::CYLMILL :
// return Cyl_5AxisMilling( nGrid, ptPs, ptPe, vtLs, vtLe, CurrTool.GetToolNum(), nPhase) ;
//case Tool::BALLMILL :
// return CylBall_5AxisMilling( nGrid, ptPs, ptPe, vtLs, vtLe, CurrTool.GetToolNum(), nPhase) ;
//case Tool::CONEMILL :
// return Conus_5AxisMilling( nGrid, ptPs, ptPe, vtLs, vtLe, CurrTool.GetToolNum(), nPhase) ;
case Tool::MORTISER :
return false ; // in realtà potremmo accettare un moto con un angolo solo along
case Tool::CHISEL :
@@ -1787,15 +1780,9 @@ VolZmap::MillingGeneralMotionStep( const Point3d& ptPs, const Vector3d& vtDs, co
bool bOk = true ;
//////// debug - vecchia modalità
Point3d ptSt = ptPs ;
//////// debug - vecchia modalità
Point3d ptSti = ptPs ;
Vector3d vtDSi = vtDs ;
double dCorr = 0.05 * 1. / nStepCnt ; // creo una sovrapposizone tra uno step e il successivo
dCorr = 0. ; // tolgo la sovrapposizione
for ( int i = 0 ; i <= nStepCnt && bOk ; ++ i) {
//Point3d ptSt = ptPs ;
//for ( int i = 0 ; i <= nStepCnt && bOk ; ++ i)
//{
////////// debug - vecchia modalità
// double dPosCoeff, dDirCoeff ;
// if ( i < nStepCnt) {
@@ -1815,8 +1802,24 @@ VolZmap::MillingGeneralMotionStep( const Point3d& ptPs, const Vector3d& vtDs, co
//// aggiorno prossimo inizio
// ptSt = ptEn ;
////////// debug - vecchia modalità
//}
//////// debug - vecchia modalità
Point3d ptSti = ptPs ;
Vector3d vtDSi = vtDs ;
double dCorr = 0.05 * 1. / nStepCnt ; // creo una sovrapposizone tra uno step e il successivo
dCorr = 0. ;
BIPNTVECTOR vPntStep( nStepCnt) ;
vector<pair<Vector3d, Vector3d>> vDirStep( nStepCnt) ;
vector<Point3d[N_MAPS]> ptLs( nStepCnt) ;
vector<Point3d[N_MAPS]> ptLe( nStepCnt) ;
vector<Vector3d[N_MAPS]> vtLs( nStepCnt) ;
vector<Vector3d[N_MAPS]> vtLe( nStepCnt) ;
for ( int i = 0 ; i <= nStepCnt && bOk ; ++ i) {
//// replico il tutto ma tenendo degli step più ampi e usando i veri vettori di start e end del tratto
double dPosCoeffE, dDirCoeffE, dPosCoeffS, dDirCoeffS ;
dPosCoeffS = double( i) / (nStepCnt + 1) ;
@@ -1837,42 +1840,45 @@ VolZmap::MillingGeneralMotionStep( const Point3d& ptPs, const Vector3d& vtDs, co
nPhase = VolZmap::MillingPhase::COUNT_END_VOL ;
Point3d ptLs[N_MAPS] ;
Point3d ptLe[N_MAPS] ;
Vector3d vtLs[N_MAPS] ;
Vector3d vtLe[N_MAPS] ;
InitializePointsAndVectors( ptSti, ptEni, vtDSi, vtDEi, ptLs, ptLe, vtLs, vtLe) ;
///// decommentare solo per debug
for( int j = 0 ; j < N_MAPS; ++j)
SelectGeneralMotion( j, ptLs[j], ptLe[j], vtLs[j],vtLe[j], nPhase) ;
//// Ciclo sulle mappe
//vector< future<bool>> vRes ;
//vRes.resize( m_nMapNum) ;
//for ( int j = 0 ; j < m_nMapNum ; ++ j) {
// vRes[j] = async( launch::async, &VolZmap::SelectGeneralMotion, this, j, cref( ptLs[j]), cref( ptLe[j]), cref( vtLs[j]), cref( vtLe[j]), nPhase) ;
//}
//bool bOk = true ;
//int nTerminated = 0 ;
//while ( nTerminated < m_nMapNum) {
// for ( int j = 0 ; j < m_nMapNum ; ++ j) {
// if ( vRes[j].valid() && vRes[j].wait_for( chrono::nanoseconds{ 1}) == future_status::ready) {
// bOk = vRes[j].get() && bOk ;
// ++ nTerminated ;
// }
// }
//}
////debug
//if ( i == 1)
// return true ;
////debug
InitializePointsAndVectors( ptSti, ptEni, vtDSi, vtDEi, &ptLs[i], ptLe[i], vtLs[i], vtLe[i]) ;
}
//debug
SaveGeoObj( vGeo, "D:/Temp/VirtualMilling/5axisAdvanced/finalApprox.nge", 2) ;
//debug
///// decommentare solo per debug
for( int j = 0 ; j < N_MAPS; ++j) {
PNTVECTOR ptLs_j( nStepCnt) ;
PNTVECTOR ptLe_j( nStepCnt) ;
VCT3DVECTOR vtLs_j( nStepCnt) ;
VCT3DVECTOR vtLe_j( nStepCnt) ;
for ( int z = 0 ; z < nStepCnt ; ++z) {
ptLs_j[z] = ptLs[z][j] ;
ptLe_j[z] = ptLe[z][j] ;
vtLs_j[z] = vtLs[z][j] ;
vtLe_j[z] = vtLe[z][j] ;
}
SelectGeneralMotion( j, ptLs_j, ptLe_j, vtLs_j,vtLe_j, nPhase) ;
}
//// Ciclo sulle mappe
//vector< future<bool>> vRes ;
//vRes.resize( m_nMapNum) ;
//for ( int j = 0 ; j < m_nMapNum ; ++ j) {
// vRes[j] = async( launch::async, &VolZmap::SelectGeneralMotion, this, j, cref( ptLs[j]), cref( ptLe[j]), cref( vtLs[j]), cref( vtLe[j]), nPhase) ;
//}
//bool bOk = true ;
//int nTerminated = 0 ;
//while ( nTerminated < m_nMapNum) {
// for ( int j = 0 ; j < m_nMapNum ; ++ j) {
// if ( vRes[j].valid() && vRes[j].wait_for( chrono::nanoseconds{ 1}) == future_status::ready) {
// bOk = vRes[j].get() && bOk ;
// ++ nTerminated ;
// }
// }
//}
////debug
// SaveGeoObj( vGeo, "D:/Temp/VirtualMilling/5axisAdvanced/finalApprox.nge", 2) ;
////debug
return bOk ;
}