From 94cf2123331473f94041dd1c28a2e6861cac46df Mon Sep 17 00:00:00 2001 From: Daniele Bariletti Date: Tue, 9 Jun 2026 12:31:59 +0200 Subject: [PATCH] EgtMachKernel : - spostata funzione per il calcolo IntersLineCyl - rimosso codice di debug. --- MachineLuaCL.cpp | 177 ++++------------------------------------------- 1 file changed, 15 insertions(+), 162 deletions(-) diff --git a/MachineLuaCL.cpp b/MachineLuaCL.cpp index c9019a2..5142d93 100644 --- a/MachineLuaCL.cpp +++ b/MachineLuaCL.cpp @@ -22,6 +22,7 @@ #include "/EgtDev/Include/EGkGeoVector3d.h" #include "/EgtDev/Include/EGkCurveLine.h" #include "/EgtDev/Include/EGkCurveArc.h" +#include "/EgtDev/Include/EGkIntersLineCylinder.h" #include "/EgtDev/Include/EGkGeomDB.h" #include "/EgtDev/Include/EGkLuaAux.h" #include "/EgtDev/Include/EGkStringUtils3d.h" @@ -598,148 +599,35 @@ Machine::LuaEmtGetBackAuxDir( lua_State* L) } struct Cyl { + Cyl( void): frCyl( GLOB_FRM), dH( 0.), dRad( 0.) {;} ; + Cyl( const Frame3d& _frCyl, double _dH, double _dRad, double _dLinTol) : + frCyl( _frCyl), dH( _dH), dRad( _dRad) { ;} + Cyl( const Point3d& _ptBase, const Vector3d& vtZ, double _dH, double _dRad, double _dLinTol) : + dH( _dH), dRad( _dRad){ + frCyl.Set( _ptBase, vtZ); } +public : Frame3d frCyl ; +public: double dH ; double dRad ; - Cyl( void): frCyl( GLOB_FRM), dH( 0.), dRad( 0.) {;} ; - Cyl( const Frame3d& _frCyl, double _dH, double _dRad) : - frCyl( _frCyl), dH( _dH), dRad( _dRad) { ;} }; typedef vector OFFSETCYLVECT ; //---------------------------------------------------------------------------- bool -IsPointInsideCylinder( const Point3d& ptTest, const Cyl& offCyl, double dLinTol = EPS_SMALL) +IsPointInsideCylinder( const Point3d& ptTest, const Cyl& offCyl) { Point3d ptTestLoc = ptTest ; ptTestLoc.ToLoc( offCyl.frCyl) ; if ( ptTestLoc.z > offCyl.dH || ptTestLoc.z < 0) return false ; double dDist = ptTestLoc.x * ptTestLoc.x + ptTestLoc.y * ptTestLoc.y ; - double dRadSq = (offCyl.dRad - dLinTol) * (offCyl.dRad - dLinTol) ; + double dRadSq = offCyl.dRad * offCyl.dRad ; if ( dDist > dRadSq) return false ; return true ; } -//---------------------------------------------------------------------------- -bool -IntersLineCyl( const Point3d& ptLineSt, const Vector3d& vtLineDir, - const Cyl& Cyl, double dLinTol, - Point3d& ptInt1, double& dU1,Vector3d& vtN1, Point3d& ptInt2, double& dU2, Vector3d& vtN2) -{ - // Porto la linea nel riferimento del cilindro - Point3d ptP = GetToLoc( ptLineSt, Cyl.frCyl) ; - Vector3d vtV = GetToLoc( vtLineDir, Cyl.frCyl) ; - - // Determino le eventuali intersezioni con le due basi a quota minima e massima (solo se linea non parallela ad esse) - int nBasInt = 0 ; - if ( abs( vtV.z) > EPS_ZERO) { - // le linee tangenti al cilindro non sono considerate intersecanti - double dEpsRad = dLinTol ; - ptInt1 = ptP + ( ( 0 - ptP.z) / vtV.z) * vtV ; - if ( ptInt1.x * ptInt1.x + ptInt1.y * ptInt1.y < ( Cyl.dRad - dEpsRad) * ( Cyl.dRad - dEpsRad)) { - nBasInt += 1 ; - dU1 = ( ( 0 - ptP.z) / vtV.z) ; - vtN1 = - Z_AX ; - } - ptInt2 = ptP + ( ( Cyl.dH - ptP.z) / vtV.z) * vtV ; - if ( ptInt2.x * ptInt2.x + ptInt2.y * ptInt2.y < ( Cyl.dRad - dEpsRad) * ( Cyl.dRad - dEpsRad)) { - nBasInt += 2 ; - dU2 = ( ( Cyl.dH - ptP.z) / vtV.z) ; - vtN2 = Z_AX ; - } - } - - // Se la linea interseca entrambe le basi, si sono trovate le due intersezioni - if ( nBasInt == 3) { - // Porto i punti e i versori nel riferimento globale - ptInt1.ToGlob( Cyl.frCyl) ; - vtN1.ToGlob( Cyl.frCyl) ; - ptInt2.ToGlob( Cyl.frCyl) ; - vtN2.ToGlob( Cyl.frCyl) ; - // Trovate intersezioni - return true ; - } - - // Determino le intersezioni con la superficie laterale del cilindro - DBLVECTOR vdCoeff{ ptP.x * ptP.x + ptP.y * ptP.y - Cyl.dRad * Cyl.dRad, - 2 * ( ptP.x * vtV.x + ptP.y * vtV.y), - vtV.x * vtV.x + vtV.y * vtV.y} ; - DBLVECTOR vdRoots ; - int nRoot = PolynomialRoots( 2, vdCoeff, vdRoots) ; - - // Elimino le soluzioni cha danno intersezioni fuori dai limiti in Z del cilindro - if ( nRoot == 2) { - double dIntZ2 = ptP.z + vdRoots[1] * vtV.z ; - if ( dIntZ2 < 0 + dLinTol || dIntZ2 > Cyl.dH - dLinTol) - -- nRoot ; - else - dU2 = vdRoots[1] ; - } - if ( nRoot >= 1) { - double dIntZ1 = ptP.z + vdRoots[0] * vtV.z ; - if ( dIntZ1 < 0 + dLinTol || dIntZ1 > Cyl.dH - dLinTol) { - if ( nRoot == 2) - vdRoots[0] = vdRoots[1] ; - -- nRoot ; - } - else - dU1 = vdRoots[0] ; - } - - // Due soluzioni: la retta interseca due volte la superficie laterale - if ( nRoot == 2) { - // Punti di intersezione con la superficie del cilindro - ptInt1 = ptP + vdRoots[0] * vtV ; - ptInt2 = ptP + vdRoots[1] * vtV ; - // Determino le normali - vtN1.Set( ptInt1.x, ptInt1.y, 0) ; - vtN1.Normalize() ; - vtN2.Set( ptInt2.x, ptInt2.y, 0) ; - vtN2.Normalize() ; - // Porto i punti e i versori nel riferimento globale - ptInt1.ToGlob( Cyl.frCyl) ; - vtN1.ToGlob( Cyl.frCyl) ; - ptInt2.ToGlob( Cyl.frCyl) ; - vtN2.ToGlob( Cyl.frCyl) ; - // Trovate intersezioni - return true ; - } - - // Una soluzione : la retta interseca la superficie laterale e un piano - else if ( nRoot == 1) { - // Se piano superiore - if ( nBasInt == 2) { - // Punto di intersezione - ptInt1 = ptP + vdRoots[0] * vtV ; - // Normale alla superficie del cilindro - vtN1.Set( ptInt1.x, ptInt1.y, 0) ; - vtN1.Normalize() ; - } - // altrimenti piano inferiore - else if ( nBasInt == 1) { - // Punto di intersezione - ptInt2 = ptP + vdRoots[0] * vtV ; - // Normale alla superficie del cilindro - vtN2.Set( ptInt2.x, ptInt2.y, 0) ; - vtN2.Normalize() ; - } - // altrimenti niente - else - return false ; - // Porto i punti e i versori nel riferimento globale - ptInt1.ToGlob( Cyl.frCyl) ; - vtN1.ToGlob( Cyl.frCyl) ; - ptInt2.ToGlob( Cyl.frCyl) ; - vtN2.ToGlob( Cyl.frCyl) ; - // Trovate intersezioni - return true ; - } - else - return false ; -} - //---------------------------------------------------------------------------- int Machine::LuaEmtAdjustConcavePartsInPath( lua_State* L) @@ -759,10 +647,6 @@ Machine::LuaEmtAdjustConcavePartsInPath( lua_State* L) const ICurve* pCrvAux = GetCurve( pGeomDB->GetGeoObj(nIdCrvAux)) ; const double dLinTol = 5 * EPS_SMALL ; - ////debug - //int nParent = pGeomDB->GetParentId( nPathId) ; - //int nTempLay = pGeomDB->AddGroup( GDB_ID_NULL, nParent, GLOB_FRM) ; - ////debug while ( nId != GDB_ID_NULL) { if ( pGeomDB->GetGeoType( nId) == CRV_LINE) { int nFlag = 0 ; pGeomDB->GetInfo( nId, "Flg2", nFlag) ; @@ -782,9 +666,6 @@ Machine::LuaEmtAdjustConcavePartsInPath( lua_State* L) OFFSETCYLVECT vCyl ; // creo un cilindro della dimensione del raggio for ( int i = 0 ; i < ssize( vLines) ; ++i) { - //debug - pGeomDB->SetMaterial(vLines[i].first, GREEN) ; - //debug const IGeoVector3d* pGV = GetGeoVector3d( pGeomDB->GetGeoObj( vLines[i].second)) ; if ( pGV == nullptr) @@ -796,7 +677,6 @@ Machine::LuaEmtAdjustConcavePartsInPath( lua_State* L) dPar = round( dPar) ; if ( dPar > 0) { - vCyl.emplace_back() ; Point3d ptStart, ptEnd ; Vector3d vtHeight ; pCrvAux->GetPointD1D2( dPar, ICurve::FROM_MINUS, ptEnd, &vtHeight) ; @@ -805,23 +685,9 @@ Machine::LuaEmtAdjustConcavePartsInPath( lua_State* L) double dHeight = vtHeight.Len() ; // questa altezza dovrebbe coincidere con quella precedentemente calcolata come direzione della linea vtHeight.Normalize() ; - vCyl.back().frCyl.Set( ptStart, vtHeight) ; - vCyl.back().dH = dHeight ; - vCyl.back().dRad = dRad ; - - ////debug - //if ( dPar > 116) { - // pGeomDB->SetGridFrame( vCyl.back().frCyl) ; - // int nIdCrv = ExeCreateCircle( nTempLay, ORIG, dRad, GDB_ID_GRID) ; - // ExeCreateSurfTmByExtrusion( nTempLay, {nIdCrv}, Z_AX * dHeight, 0.005, GDB_ID_GRID) ; - // pGeomDB->Erase( nIdCrv) ; - // - //} - ////debug + vCyl.emplace_back( ptStart, vtHeight, dHeight, dRad, dLinTol) ; } } - ////debug - //pGeomDB->SetGridFrame( GLOB_FRM) ; // controllo l'end di ogni linea per verificare se sta nel cilindro definito da uno degli altri tratti // controllo tutto i punti @@ -839,21 +705,10 @@ Machine::LuaEmtAdjustConcavePartsInPath( lua_State* L) for ( int j = 0 ; j < ssize( vLines) ; ++j) { if ( i == j) continue ; - bool bToErase = IsPointInsideCylinder( ptEnd, vCyl[j], dLinTol) ; + bool bToErase = IsPointInsideCylinder( ptEnd, vCyl[j]) ; if ( bErasedPrev && ! bToErase) bToErase = bToErase || IsPointInsideCylinder( ptStart, vCyl[j]) ; - if ( bToErase) { - //// devo eliminare il corrente e anche il successivo - //pGeomDB->Erase( vLines[i].first) ; - //if ( i < ssize( vLines) - 1) - // pGeomDB->Erase( vLines[i+1].first) ; - - //debug - //coloro solo i tratti che cancello - pGeomDB->SetMaterial( vLines[i].first, YELLOW) ; - pGeomDB->SetMaterial( vLines[i+1].first, YELLOW) ; - //debug - + if ( bToErase) { bErasedSomePart = true ; bErasedPrev = true ; vInters.emplace_back(vLines[i].first,i) ; @@ -891,7 +746,7 @@ Machine::LuaEmtAdjustConcavePartsInPath( lua_State* L) Point3d ptInt1 = P_INVALID, ptInt2 = P_INVALID ; double dU1, dU2 ; Vector3d vtN1, vtN2 ; - if ( IntersLineCyl( ptStart, vtStart * dLen, vCyl[j], dLinTol, ptInt1, dU1, vtN1, ptInt2, dU2, vtN2)) { + if ( IntersLineCyl( ptStart, vtStart * dLen, vCyl[j].frCyl, vCyl[j].dH, vCyl[j].dRad, dU1, ptInt1, vtN1, dU2, ptInt2, vtN2)) { bool bUpdate = ( i == 0 ? dU1 < dUTrim : dU1 > dUTrim) ; bUpdate = bUpdate && ptInt1.IsValid() && dU1 > 0 && dU1 < 1 ; bUpdate = bUpdate && vtN1 * vtStart < 0 ; @@ -919,7 +774,6 @@ Machine::LuaEmtAdjustConcavePartsInPath( lua_State* L) ICurveLine* pCLPrev = GetCurveLine( pGeomDB->GetGeoObj( nPrev)) ; pCLPrev->ModifyEnd( ptTrim) ; } - pGeomDB->SetMaterial( vInters[0].first, RED) ; CamData* camData = GetCamData( pGeomDB->GetUserObj( vInters[0].first)) ; camData->SetEndPoint( ptTrim) ; } @@ -933,7 +787,6 @@ Machine::LuaEmtAdjustConcavePartsInPath( lua_State* L) ICurveLine* pCLNext = GetCurveLine( pGeomDB->GetGeoObj( nNext)) ; pCLNext->ModifyStart( ptTrim) ; } - pGeomDB->SetMaterial( vInters[i].first, RED) ; } } }