diff --git a/EgtGeomKernel.rc b/EgtGeomKernel.rc index 38cd294..8ec6562 100644 Binary files a/EgtGeomKernel.rc and b/EgtGeomKernel.rc differ diff --git a/VolZmap.h b/VolZmap.h index 93047ab..064c388 100644 --- a/VolZmap.h +++ b/VolZmap.h @@ -99,7 +99,7 @@ class VolZmap : public IVolZmap, public IGeoObjRW { return m_nDexVoxRatio ; } bool ChangeResolution( int nDexVoxRatio) override ; void SetShowEdges( bool bShow) override - { m_bShowEdges = bShow ; // qui � necessario far ricreare la grafica + { m_bShowEdges = bShow ; // qui è necessario far ricreare la grafica m_OGrMgr.Clear() ; } bool GetShowEdges( void) const override { return m_bShowEdges ; } @@ -484,39 +484,28 @@ class VolZmap : public IVolZmap, public IGeoObjRW bool OffsetFillet( double dOffs) ; bool OffsetSharped( double dOffs, int nType) ; - public : - // ------------------------- ENUM ---------------------------------------------------------------- - enum MillingPhase { - COUNT_START_VOL = 0 , - ONLY_LATERAL_SURF = 1 , - COUNT_END_VOL = 2 , - COUNT_START_END = 3 - } ; - - enum Move5Axis{ - ALONG_CONVEX = 0 , - ALONG_CONCAVE = 1 , - ACROSS = 2 , - NO_BASE_INTERS = 3 - } ; - - enum CuttingSurface { - NONE = -1, - TOOL = 0 , - BZ = 1 , - LATERAL = 2 - } ; - private : - enum Status { ERR = 0, OK = 1, TO_VERIFY = 2} ; - enum Shape { GENERIC = 0, BOX = 1, EXTRUSION = 2, OFFSET = 3} ; + enum Move5Axis { + ALONG_CONVEX = 0 , + ALONG_CONCAVE = 1 , + ACROSS = 2 , + NO_BASE_INTERS = 3} ; + enum Status { + ERR = 0, + OK = 1, + TO_VERIFY = 2} ; + enum Shape { + GENERIC = 0, + BOX = 1, + EXTRUSION = 2, + OFFSET = 3} ; static const int N_MAPS = 3 ; static const int N_VOXBLOCK = 32 ; private : ObjGraphicsMgr m_OGrMgr ; // gestore grafica dell'oggetto Status m_nStatus ; // stato - int m_nTempProp[2] ; // vettore propriet� temporanee + int m_nTempProp[2] ; // vettore proprietà temporanee double m_dTempParam[2] ; // vettore parametri temporanei bool m_bShowEdges ; // flag di visualizzazione spigoli vivi Frame3d m_MapFrame ; // riferimento intrinseco dello Zmap @@ -550,8 +539,8 @@ class VolZmap : public IVolZmap, public IGeoObjRW mutable BOOLVECTOR m_BlockToUpdate ; mutable INTVECTOR m_BlockUpdatingCounter ; - int m_nConnectedCompoCount ; // Se == - 1 il numero di componenti non � noto - // Se >= 0 � il numero di componenti connesse + int m_nConnectedCompoCount ; // Se == - 1 il numero di componenti non è noto + // Se >= 0 è il numero di componenti connesse mutable std::vector m_InterBlockVox ; mutable SharpTriaMatrix m_InterBlockOriginalSharpTria ; diff --git a/VolZmapCreation.cpp b/VolZmapCreation.cpp index fca89e5..7a5358b 100644 --- a/VolZmapCreation.cpp +++ b/VolZmapCreation.cpp @@ -875,7 +875,7 @@ VolZmap::CreateFromTriMesh( const ISurfTriMesh& Surf, double dStep, bool bTriDex IntersParLinesSurfTm intPLSTM( frMapFrame, Surf) ; // Standarda è multithread - const bool MULTITHREAD = true ; + constexpr bool MULTITHREAD = true ; if ( MULTITHREAD) { // Numero massimo di thread diff --git a/VolZmapGraphics.cpp b/VolZmapGraphics.cpp index bb37919..3d5b849 100644 --- a/VolZmapGraphics.cpp +++ b/VolZmapGraphics.cpp @@ -951,7 +951,7 @@ VolZmap::UpdateTripleMapGraphics( void) const } // Standarda è multithread - const bool MULTITHREAD = true ; + constexpr bool MULTITHREAD = true ; if ( MULTITHREAD) { // Calcolo i triangoli sui blocchi diff --git a/VolZmapVolume.cpp b/VolZmapVolume.cpp index 31d6d5f..5a86031 100644 --- a/VolZmapVolume.cpp +++ b/VolZmapVolume.cpp @@ -801,7 +801,7 @@ VolZmap::AddMissingIntervalsInVoxel( VolZmap* VolZmapRef, int nGrid, int nI, int nToolNum, true) ; } - // ----------- griglia precedente ----------- + // ----------- griglia precedente ----------- { int nMyGrid = ( nGrid + 2) % 3 ; int nMyI = nK ; @@ -826,16 +826,16 @@ VolZmap::AddMissingIntervalsInVoxel( VolZmap* VolZmapRef, int nGrid, int nI, int inline BBox3d GetCylMoveBBox( const Point3d& ptP1, const Point3d& ptP2, const Vector3d& vtV, double dRad, double dH) { - // Determinazione delle posizioni della punta del componente nelle posizioni iniziale e finale + // Determinazione delle posizioni della punta del componente nelle posizioni iniziale e finale Point3d ptP1T = ptP1 - dH * vtV ; Point3d ptP2T = ptP2 - dH * vtV ; - // Calcolo del box del movimento dell'asse + // Calcolo del box del movimento dell'asse BBox3d b3Box ; b3Box.Add( ptP1) ; b3Box.Add( ptP1T) ; b3Box.Add( ptP2) ; b3Box.Add( ptP2T) ; - // Aggiungo ingombro raggio + // Aggiungo ingombro raggio if ( AreSameOrOppositeVectorApprox( vtV, X_AX)) b3Box.Expand( 0, dRad, dRad) ; else if ( AreSameOrOppositeVectorApprox( vtV, Y_AX)) @@ -848,7 +848,7 @@ GetCylMoveBBox( const Point3d& ptP1, const Point3d& ptP2, const Vector3d& vtV, d double dExpandZ = dRad * sqrt( 1 - vtV.z * vtV.z) ; b3Box.Expand( dExpandX, dExpandY, dExpandZ) ; } - // Restituisco il box calcolato + // Restituisco il box calcolato return b3Box ; } @@ -856,15 +856,15 @@ GetCylMoveBBox( const Point3d& ptP1, const Point3d& ptP2, const Vector3d& vtV, d inline BBox3d GetCylMoveRotBBox( const Point3d& ptP1, const Point3d& ptP2, const Vector3d& vtV1, const Vector3d& vtV2, double dRad, double dH) { - // Determinazione dei punti più laterali del tool, rispetto alla direzione di movimento - // per la testa e per la punta del tool + // Determinazione dei punti più laterali del tool, rispetto alla direzione di movimento + // per la testa e per la punta del tool Point3d ptP1T = ptP1 - dH * vtV1 ; Point3d ptP2T = ptP2 - dH * vtV2 ; Vector3d vtDirTop = ptP2 - ptP1 ; Vector3d vtDirTip = ptP2T - ptP1T ; - // determino i punti laterali del top e del bottom(tip), nella posizione di partenza + // determino i punti laterali del top e del bottom(tip), nella posizione di partenza Vector3d vtAuxTopS = vtV1 ^ vtDirTop ; vtAuxTopS.Normalize() ; vtAuxTopS *= dRad ; @@ -877,7 +877,7 @@ GetCylMoveRotBBox( const Point3d& ptP1, const Point3d& ptP2, const Vector3d& vtV Point3d ptPBottom1 = ptP1T + vtAuxBottomS ; Point3d ptPBottom2 = ptP1T - vtAuxBottomS ; - // determino i punti laterali del top e del bottom(tip), nella posizione di arrivo + // determino i punti laterali del top e del bottom(tip), nella posizione di arrivo Vector3d vtAuxTopE = vtV2 ^ vtDirTop ; vtAuxTopE.Normalize() ; vtAuxTopE *= dRad ; @@ -890,14 +890,14 @@ GetCylMoveRotBBox( const Point3d& ptP1, const Point3d& ptP2, const Vector3d& vtV Point3d ptPBottom3 = ptP2T + vtAuxBottomE ; Point3d ptPBottom4 = ptP2T - vtAuxBottomE ; - // calcolo anche i punti estremi iniziali e finali dei cilindri + // calcolo anche i punti estremi iniziali e finali dei cilindri Point3d ptTopEnd, ptBottomEnd, ptTopStart, ptBottomStart ; ptTopEnd = ptP2 + vtDirTop * dRad ; ptBottomEnd = ptP2T + vtDirTip * dRad ; ptTopStart = ptP1 - vtDirTop * dRad ; ptBottomStart = ptP1T - vtDirTip * dRad ; - // Calcolo del box del volume spazzato dal tool + // Calcolo del box del volume spazzato dal tool BBox3d b3Box ; b3Box.Add( ptPTop1) ; b3Box.Add( ptPTop2) ; @@ -912,7 +912,7 @@ GetCylMoveRotBBox( const Point3d& ptP1, const Point3d& ptP2, const Vector3d& vtV b3Box.Add( ptTopStart) ; b3Box.Add( ptBottomStart) ; - // Restituisco il box calcolato + // Restituisco il box calcolato return b3Box ; } @@ -920,60 +920,61 @@ GetCylMoveRotBBox( const Point3d& ptP1, const Point3d& ptP2, const Vector3d& vtV inline BBox3d GetSphereMoveBBox( const Point3d& ptP1, const Point3d& ptP2, double dRad) { - // Calcolo del box del movimento del centro + // Calcolo del box del movimento del centro BBox3d b3Box ; b3Box.Add( ptP1) ; b3Box.Add( ptP2) ; - // Aggiungo ingombro raggio + // Aggiungo ingombro raggio b3Box.Expand( dRad) ; - // Restituisco il box calcolato + // Restituisco il box calcolato return b3Box ; } //---------------------------------------------------------------------------- inline bool VolZmap::TestToolBBox( int nGrid, const Point3d& ptP1, const Point3d& ptP2, const Vector3d& vtV, - int& nStI, int& nStJ, int& nEnI, int& nEnJ) + int& nStI, int& nStJ, int& nEnI, int& nEnJ) { - // Controllo utensile + // Controllo utensile if ( m_nCurrTool < 0 || m_nCurrTool >= int( m_vTool.size())) return false ; Tool& CurrTool = m_vTool[m_nCurrTool] ; - return TestCompoBBox( nGrid, ptP1, ptP2, vtV, V_NULL, CurrTool.GetRadius(), CurrTool.GetTipRadius(), CurrTool.GetHeigth(), - nStI, nStJ, nEnI, nEnJ) ; + return TestCompoBBox( nGrid, ptP1, ptP2, vtV, V_NULL, + CurrTool.GetRadius(), CurrTool.GetTipRadius(), CurrTool.GetHeigth(), + nStI, nStJ, nEnI, nEnJ) ; } //---------------------------------------------------------------------------- inline bool VolZmap::TestCompoBBox( int nGrid, const Point3d& ptP1, const Point3d& ptP2, const Vector3d& vtV, const Vector3d& vtV2, - double dRad, double dTipRad, double dHei, - int& nStI, int& nStJ, int& nEnI, int& nEnJ) + double dRad, double dTipRad, double dHei, + int& nStI, int& nStJ, int& nEnI, int& nEnJ) { - // I punti e i vettori devono essere nel sistema di riferimento opportuno + // I punti e i vettori devono essere nel sistema di riferimento opportuno - // Controllo sull'ammissibilità del numero di griglia + // Controllo sull'ammissibilità del numero di griglia if ( nGrid < 0 || nGrid > 2) return false ; - // BBox dello Zmap + // BBox dello Zmap BBox3d b3Zmap( 0, 0, m_dMinZ[nGrid], m_nNx[nGrid] * m_dStep, m_nNy[nGrid] * m_dStep, m_dMaxZ[nGrid]) ; - // BBox dell'utensile nel suo movimento + // BBox dell'utensile nel suo movimento double dMaxRad = max( dRad, dTipRad) ; BBox3d b3Box ; if ( vtV.IsSmall()) b3Box = GetSphereMoveBBox( ptP1, ptP2, dRad) ; - else if( AreSameVectorExact(vtV2, V_NULL)) + else if( AreSameVectorExact( vtV2, V_NULL)) b3Box = GetCylMoveBBox( ptP1, ptP2, vtV, dMaxRad, dHei) ; else b3Box = GetCylMoveRotBBox( ptP1, ptP2, vtV, vtV2, dRad, dHei) ; - // Verifica dell'interferenza dell'utensile con lo Zmap - if ( ! b3Zmap.FindIntersection( b3Box, b3Box)) + // Verifica dell'interferenza dell'utensile con lo Zmap + if ( ! b3Zmap.Overlaps( b3Box)) return false ; - // Limiti su indici + // Limiti su indici nStI = max( 0, int( b3Box.GetMin().x / m_dStep)) ; nEnI = min( m_nNx[nGrid] - 1, int( b3Box.GetMax().x / m_dStep)) ; nStJ = max( 0, int( b3Box.GetMin().y / m_dStep)) ; @@ -985,19 +986,19 @@ VolZmap::TestCompoBBox( int nGrid, const Point3d& ptP1, const Point3d& ptP2, con //---------------------------------------------------------------------------- inline bool VolZmap::TestParaBBox( int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtD, const Vector3d& vtA, - double dLenX, double dLenY, double dLenZ, - int& nStI, int& nStJ, int& nEnI, int& nEnJ) + double dLenX, double dLenY, double dLenZ, + int& nStI, int& nStJ, int& nEnI, int& nEnJ) { - // I punti e i vettori devono essere nel sistema di riferimento opportuno + // I punti e i vettori devono essere nel sistema di riferimento opportuno - // Determino le posizioni iniziale e - // finale della punta dell'utensile. + // Determino le posizioni iniziale e + // finale della punta dell'utensile. Point3d ptSTip = ptS - vtD * dLenZ ; Point3d ptETip = ptE - vtD * dLenZ ; double dSemiDiag = sqrt( dLenX * dLenX + dLenY * dLenY) / 2 ; - // Determinazione dei limiti del più piccolo parallelepipedo contenente il movimento + // Determinazione dei limiti del più piccolo parallelepipedo contenente il movimento double dMinX = min( min( ptS.x, ptSTip.x), min( ptE.x, ptETip.x)) - dSemiDiag ; double dMinY = min( min( ptS.y, ptSTip.y), min( ptE.y, ptETip.y)) - dSemiDiag ; double dMinZ = min( min( ptS.z, ptSTip.z), min( ptE.z, ptETip.z)) - dSemiDiag ; @@ -1013,7 +1014,7 @@ VolZmap::TestParaBBox( int nGrid, const Point3d& ptS, const Point3d& ptE, const double dMinZValue = m_dMinZ[nGrid] ; double dMaxZValue = m_dMaxZ[nGrid] ; - // Verifica dell'interferenza dell'utensile con lo Zmap + // Verifica dell'interferenza dell'utensile con lo Zmap if ( dMaxX < EPS_SMALL || dMinX > dMaxXValue - EPS_SMALL) return false ; if ( dMaxY < EPS_SMALL || dMinY > dMaxYValue - EPS_SMALL) @@ -1021,7 +1022,7 @@ VolZmap::TestParaBBox( int nGrid, const Point3d& ptS, const Point3d& ptE, const if ( dMaxZ < dMinZValue + EPS_SMALL || dMinZ > dMaxZValue - EPS_SMALL) return false ; - // Limiti su indici + // Limiti su indici nStI = ( dMinX < EPS_SMALL ? 0 : int( dMinX / m_dStep)) ; nEnI = ( dMaxX > dMaxXValue - EPS_SMALL ? nMaxNx - 1 : int( dMaxX / m_dStep)) ; nStJ = ( dMinY < EPS_SMALL ? 0 : int( dMinY / m_dStep)) ; @@ -1172,37 +1173,39 @@ VolZmap::InitializeAuxPoints( Point3d ptTop1s[3], Point3d ptTop1e[3], Point3d pt //---------------------------------------------------------------------------- bool -VolZmap::GenTool_5AxisMilling( int nGrid, const PNTVECTOR& ptS, const PNTVECTOR& ptE, const VCT3DVECTOR& vtLs, const VCT3DVECTOR& vtLe, int nToolNum, int n5AxisType) +VolZmap::GenTool_5AxisMilling( int nGrid, const PNTVECTOR& ptS, const PNTVECTOR& ptE, + const VCT3DVECTOR& vtLs, const VCT3DVECTOR& vtLe, int nToolNum, int n5AxisType) { - // Controllo utensile + // 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 + // Descrizione geometrica del moto PNTVECTOR ptI = ptS ; PNTVECTOR ptF = ptE ; - // Vettore delle normali agli archi + // Vettore delle normali agli archi const VCT3DVECTOR& vArcNorm = CurrTool.GetArcNormalVec() ; - // Poinché l'asse utensile è parallelo all'asse Z, definisco un sistema di - // riferimento ad hoc in cui le normali agli archi giacciano nel piano XZ. + // Poiché l'asse utensile è parallelo all'asse Z, definisco un sistema di + // riferimento ad hoc in cui le normali agli archi giacciano nel piano XZ. Frame3d frNormFrame ; frNormFrame.Set( ORIG, X_AX, -Z_AX, Y_AX) ; - // Ciclo sulle curve del profilo + + // Ciclo sulle curve del profilo const CurveComposite& ToolProfile = CurrTool.GetApproxOutline() ; - int c = - 1 ; + int nCrv = -1 ; const ICurve* pPrevCurve = nullptr ; - const ICurve* pCurve = ToolProfile.GetCurve( ++ c) ; - double dCumHeight = 0 ; // altezza cumulativa dei tratti già considerati + const ICurve* pCurve = ToolProfile.GetCurve( ++ nCrv) ; + double dCumHeight = 0 ; // altezza cumulativa dei tratti già considerati while ( pCurve != nullptr) { double dHeight = 0 ; - // Se segmento + // Se segmento if ( pCurve->GetType() == CRV_LINE) { - // Recupero gli estremi + // Recupero gli estremi const ICurveLine* pLine = GetCurveLine( pCurve) ; Point3d ptStart = pLine->GetStart() ; Point3d ptEnd = pLine->GetEnd() ; @@ -1214,10 +1217,10 @@ VolZmap::GenTool_5AxisMilling( int nGrid, const PNTVECTOR& ptS, const PNTVECTOR& vtNormSt.ToLoc( frNormFrame) ; vtNormEn.ToLoc( frNormFrame) ; } - // Ne determino l'altezza + // Ne determino l'altezza dHeight = abs( ptStart.y - ptEnd.y) ; if ( dHeight > EPS_SMALL) { - // verifiche curva precedente per eventuale tappo sopra + // verifiche curva precedente per eventuale tappo sopra bool bTapT = true ; if ( pPrevCurve != nullptr && pPrevCurve->GetType() == CRV_LINE) { const ICurveLine* pOthLine = GetCurveLine( pPrevCurve) ; @@ -1226,9 +1229,9 @@ VolZmap::GenTool_5AxisMilling( int nGrid, const PNTVECTOR& ptS, const PNTVECTOR& if ( abs( ptOthStart.y - ptOthEnd.y) < EPS_SMALL && ptOthStart.x < ptOthEnd.x) bTapT = false ; } - // verifiche curva successiva per eventuale tappo sotto + // verifiche curva successiva per eventuale tappo sotto bool bTapB = true ; - const ICurve* pNextCurve = ToolProfile.GetCurve( ++ c) ; + const ICurve* pNextCurve = ToolProfile.GetCurve( ++ nCrv) ; if ( pNextCurve != nullptr && pNextCurve->GetType() == CRV_LINE) { const ICurveLine* pOthLine = GetCurveLine( pNextCurve) ; Point3d ptOthStart = pOthLine->GetStart() ; @@ -1236,20 +1239,20 @@ VolZmap::GenTool_5AxisMilling( int nGrid, const PNTVECTOR& ptS, const PNTVECTOR& if ( abs( ptOthStart.y - ptOthEnd.y) < EPS_SMALL && ptOthStart.x > ptOthEnd.x) bTapB = false ; } - // Se X costante, è un cilindro + // Se X costante, è un cilindro if ( abs( ptStart.x - ptEnd.x) < EPS_SMALL) { double dRadius = ptStart.x ; if ( dRadius > 10 * EPS_SMALL) CompCyl_5AxisMilling( nGrid, ptI, ptF, vtLs, vtLe, dHeight, dRadius, nToolNum, n5AxisType) ; } - // se altrimenti X decrescente, è un cono con vettore equiverso a quello dell'utensile + // se altrimenti X decrescente, è un cono con vettore equiverso a quello dell'utensile 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, n5AxisType) ; } - // altrimenti X crescente, è un cono con vettore opposto a quello dell'utensile + // altrimenti X crescente, è un cono con vettore opposto a quello dell'utensile else { double dMaxRad = ptEnd.x ; double dMinRad = ptStart.x ; @@ -1270,40 +1273,40 @@ VolZmap::GenTool_5AxisMilling( int nGrid, const PNTVECTOR& ptS, const PNTVECTOR& CompConus_5AxisMilling( nGrid, ptIn, ptFn, vNewVtLs, vNewVtLe, dHeight, dMaxRad, dMinRad, bTapT, bTapB, vtNormEn, vtNormSt, nToolNum, n5AxisType) ; } - // Passo alla curva successiva + // Passo alla curva successiva pPrevCurve = pCurve ; pCurve = pNextCurve ; } else { - // Passo alla curva successiva + // Passo alla curva successiva pPrevCurve = pCurve ; - pCurve = ToolProfile.GetCurve( ++ c) ; + pCurve = ToolProfile.GetCurve( ++ nCrv) ; } } - // Se arco + // Se arco else if ( pCurve->GetType() == CRV_ARC) { - // Recupero estremi, centro e raggio + // Recupero estremi, centro e raggio const ICurveArc* pArc = GetCurveArc( pCurve) ; Point3d ptStart ; pArc->GetStartPoint( ptStart) ; Point3d ptEnd ; pArc->GetEndPoint( ptEnd) ; Point3d ptCen = pArc->GetCenter() ; double dRadius = pArc->GetRadius() ; - // Determino le posizioni iniziale e finale del centro della sfera + // Determino le posizioni iniziale e finale del centro della sfera Point3d ptCenS = ptI.front() - vtLs.front() * ( ptStart.y - ptCen.y ) ; Point3d ptCenE = ptF.back() - vtLe.back() * ( ptStart.y - ptCen.y ) ; - // Eseguo l'asportazione del materiale + // Eseguo l'asportazione del materiale CompBall_Milling( nGrid, ptCenS, ptCenE, dRadius, nToolNum) ; - // aggiorno l'altezza + // aggiorno l'altezza dHeight = abs( ptStart.y - ptEnd.y) ; - // Passo alla curva successiva + // Passo alla curva successiva pPrevCurve = pCurve ; - pCurve = ToolProfile.GetCurve( ++ c) ; + pCurve = ToolProfile.GetCurve( ++ nCrv) ; } - // Determino le posizioni iniziale e finale del componente successivo + // Determino le posizioni iniziale e finale del componente successivo dCumHeight += dHeight ; - for( int j = 0 ; j < nStepCnt ; ++j) { + for ( int j = 0 ; j < nStepCnt ; ++j) { ptI[j] = ptS[j] - vtLs[j] * dCumHeight ; ptF[j] = ptE[j] - vtLe[j] * dCumHeight ; } @@ -1312,13 +1315,15 @@ VolZmap::GenTool_5AxisMilling( int nGrid, const PNTVECTOR& ptS, const PNTVECTOR& return true ; } +//---------------------------------------------------------------------------- static void -SortGroupInters( PNTVEC3DVECTOR& vInters, INTINTVECTOR& vStartEnds, const Vector3d& vMainAx) { - if( AreSameVectorExact(vMainAx, Z_AX)) +SortGroupInters( PNTVEC3DVECTOR& vInters, INTINTVECTOR& vStartEnds, const Vector3d& vMainAx) +{ + if ( AreSameVectorExact(vMainAx, Z_AX)) sort( vInters.begin(), vInters.end(), [](PNTVEC3D& a, PNTVEC3D& b) { return a.first.z < b.first.z ; }) ; - else if( AreSameVectorExact(vMainAx, Y_AX)) + else if ( AreSameVectorExact(vMainAx, Y_AX)) sort( vInters.begin(), vInters.end(), [](PNTVEC3D& a, PNTVEC3D& b) { return a.first.y < b.first.y ; }) ; - else if( AreSameVectorExact(vMainAx, X_AX)) + else if ( AreSameVectorExact(vMainAx, X_AX)) sort( vInters.begin(), vInters.end(), [](PNTVEC3D& a, PNTVEC3D& b) { return a.first.x < b.first.x ; }) ; // devo controllare che le intersezioni estreme abbiano direzione opposta // in caso contrario potrei avere ad uno dei due estremi due punti quasi coincidenti e stare prendendo per più esterno quello con la normale sbagliata @@ -1327,7 +1332,7 @@ SortGroupInters( PNTVEC3DVECTOR& vInters, INTINTVECTOR& vStartEnds, const Vector // se ad uno dei due estremi trovo due punti quasi coincidenti scambio le normali dei due punti di intersezione bool bAtStart = false ; bool bAtEnd = false ; - if( AreSameVectorExact(vMainAx, Z_AX)) { + if ( AreSameVectorExact(vMainAx, Z_AX)) { bAtStart = (vInters[0].first.z - vInters[1].first.z) < EPS_SMALL ; bAtEnd = (vInters.back().first.z - vInters.end()[-2].first.z) < EPS_SMALL ; } @@ -1339,12 +1344,12 @@ SortGroupInters( PNTVEC3DVECTOR& vInters, INTINTVECTOR& vStartEnds, const Vector bAtStart = (vInters[0].first.x - vInters[1].first.x) < EPS_SMALL ; bAtEnd = (vInters.back().first.x - vInters.end()[-2].first.x) < EPS_SMALL ; } - if( bAtStart && vInters.size() == 2) + if ( bAtStart && vInters.size() == 2) return ; - if( bAtStart) + if ( bAtStart) swap( vInters[0].second, vInters[1].second) ; - else if( bAtEnd) + else if ( bAtEnd) swap( vInters.back().second, vInters.end()[-2].second) ; } @@ -1361,10 +1366,10 @@ SortGroupInters( PNTVEC3DVECTOR& vInters, INTINTVECTOR& vStartEnds, const Vector break ; } // sennò scorro finché non trovo l'uscita più lontana ( prima di un altro ingresso o eventualmente l'ultima inters) - else if( bDirStart != bDir) + else if ( bDirStart != bDir) bFirstEndFound = true ; // se trovo di nuovo un'intersezione orientata come la prima dello spillone allora ho un nuovo start e posso chiudere l'intervallo precedente - else if( bFirstEndFound && bDirStart == bDir) { + else if ( bFirstEndFound && bDirStart == bDir) { pStartEnd.second = w - 1 ; bFirstEndFound = false ; vStartEnds.push_back(pStartEnd) ; @@ -1374,6 +1379,7 @@ SortGroupInters( PNTVEC3DVECTOR& vInters, INTINTVECTOR& vStartEnds, const Vector } } +//---------------------------------------------------------------------------- struct SurfBezForInters { SurfBezier sBez ; BBox3d bbSurfZ ; @@ -1383,14 +1389,13 @@ struct SurfBezForInters { Frame3d frXMainDim ; Frame3d frYMainDim ; Vector3d a3, a2, a1, a0, b3, b2, b1, b0 ; -}; - -typedef std::pair DBLDBL ; +} ; +//---------------------------------------------------------------------------- static bool IntersLineBezierSurfSet( const Point3d& ptLineStart, const Vector3d& vtLineDir, const vector& vSurfBez, PNTVEC3DVECTOR& vInters, INTVECTOR& vSurfInters, - const Vector3d& vtN, vector& vInterv) + const Vector3d& vtN, DBLDBLVECTOR& vInterv) { Point3d r = ptLineStart ; Vector3d q = vtLineDir ; @@ -1399,72 +1404,73 @@ IntersLineBezierSurfSet( const Point3d& ptLineStart, const Vector3d& vtLineDir, bool bNeedToRotY = AreSameVectorApprox( q, Y_AX) ; bool bNeedToRot = bNeedToRotX || bNeedToRotY ; Frame3d frRot ; - if( bNeedToRotX) + if ( bNeedToRotX) frRot.Set( ORIG, X_AX) ; - if( bNeedToRotY) + if ( bNeedToRotY) frRot.Set( ORIG, Y_AX) ; if ( bNeedToRot) { r.ToLoc( frRot) ; q.ToLoc( frRot) ; } - //salvo un vettore di flag per tenere traccia delle superfici con cui ho trovato delle intersezioni + // salvo un vettore di flag per tenere traccia delle superfici con cui ho trovato delle intersezioni BOOLVECTOR vbAlreadyCalc( vSurfBez.size()) ; fill( vbAlreadyCalc.begin(), vbAlreadyCalc.end(), false) ; bool bCalcAll = false ; - Reiterate : - // interseco con le bezier - for( int s = 0 ; s < int( vSurfBez.size()) ; ++s) { - // se ho già trovato l'intersezione con questa superficie vado avanti - if( vbAlreadyCalc[s]) +Reiterate : + + // interseco con le bezier + for ( int s = 0 ; s < int( vSurfBez.size()) ; ++s) { + // se ho già trovato l'intersezione con questa superficie vado avanti + if ( vbAlreadyCalc[s]) continue ; const SurfBezForInters& srf = vSurfBez[s] ; BBox3d bbox ; bool bNotValid = false ; Point3d rLoc = r ; - if( ! bNeedToRot) { + if ( ! bNeedToRot) { bbox = srf.bbSurfZ ; - if( srf.frZMainDim.IsValid()) + if ( srf.frZMainDim.IsValid()) rLoc.ToLoc( srf.frZMainDim) ; } - else if( bNeedToRotX) { - if( srf.frXMainDim.IsValid()) { + else if ( bNeedToRotX) { + if ( srf.frXMainDim.IsValid()) { bbox = srf.bbSurfX ; - rLoc.LocToLoc(frRot, srf.frXMainDim) ; + rLoc.LocToLoc( frRot, srf.frXMainDim) ; } else bNotValid = true ; } - else if( bNeedToRotY) { - if( srf.frYMainDim.IsValid()) { + else if ( bNeedToRotY) { + if ( srf.frYMainDim.IsValid()) { bbox = srf.bbSurfY ; - rLoc.LocToLoc(frRot, srf.frYMainDim) ; + rLoc.LocToLoc( frRot, srf.frYMainDim) ; } else bNotValid = true ; } - if( bNotValid) { + if ( bNotValid) { bbox = srf.bbSurfZ ; - bbox.ToLoc(frRot) ; + bbox.ToLoc( frRot) ; } INTDBLVECTOR vIntBoxBox ; bool bCalcInters = false ; int nInterv = -1 ; - if( vInterv.size() > 0 && !bCalcAll ) { + if ( vInterv.size() > 0 && ! bCalcAll) { Point3d ptMin = bbox.GetMin(), ptMax = bbox.GetMax() ; - for ( int k = 0 ; k < int(vInterv.size()) && ! bCalcInters; ++k) { - bCalcInters = ( vInterv[k].first >= ptMin.z && vInterv[k].first <= ptMax.z) || // minimo compreso nel box - (vInterv[k].second >= ptMin.z && vInterv[k].second <= ptMax.z) || // massimo compreso nel box - (vInterv[k].first < ptMin.z && ptMax.z < vInterv[k].second) ; // intervallo comprende il box - if( bCalcInters) + for ( int k = 0 ; k < int( vInterv.size()) && ! bCalcInters; ++k) { + bCalcInters = ( vInterv[k].first >= ptMin.z && vInterv[k].first <= ptMax.z) || // minimo compreso nel box + ( vInterv[k].second >= ptMin.z && vInterv[k].second <= ptMax.z) || // massimo compreso nel box + ( vInterv[k].first < ptMin.z && ptMax.z < vInterv[k].second) ; // intervallo comprende il box + if ( bCalcInters) nInterv = k ; } - bCalcInters = bCalcInters && bbox.SqDistFromPointXY( rLoc) < EPS_ZERO ; + bCalcInters = ( bCalcInters && bbox.SqDistFromPointXY( rLoc) < EPS_ZERO) ; } else - bCalcInters = bbox.SqDistFromPointXY( rLoc) < EPS_ZERO ; + bCalcInters = ( bbox.SqDistFromPointXY( rLoc) < EPS_ZERO) ; // verifico che lo spillone faccia interferenza con il box della superficie if ( bCalcInters) { @@ -1506,7 +1512,7 @@ IntersLineBezierSurfSet( const Point3d& ptLineStart, const Vector3d& vtLineDir, } DBLVECTOR vdCoeff, vdRoots ; - // coefficienti dal grado più basso al grado più alto + // coefficienti dal grado più basso al grado più alto vdCoeff = { // c0 q.x*q.z*a0.y*b0.z - q.x*q.y*a0.z*b0.z // 3 - r.z*q.x*q.z*a0.y + r.z*q.x*q.y*a0.z + // 3 @@ -1559,15 +1565,15 @@ IntersLineBezierSurfSet( const Point3d& ptLineStart, const Vector3d& vtLineDir, q.y*q.z*a3.z*b3.x - q.z*q.z*a3.y*b3.x + // 4 q.z*q.z*a3.x*b3.y - q.y*q.z*a3.x*b3.z - q.x*q.z*a3.z*b3.y + q.x*q.y*a3.z*b3.z} ; // 5 int nRoots = PolynomialRoots( 6, vdCoeff, vdRoots) ; - for( int w = 0 ; w < nRoots ; ++w) { + for ( int w = 0 ; w < nRoots ; ++w) { double dU = 0, dV = 0 ; if ( vdRoots[w] > 0 - EPS_ZERO && vdRoots[w] < 1 + EPS_ZERO) { dU = vdRoots[w] ; // verifico che non sia una soluzione con molteplicità > 1 bool bAlreadyFound = false ; - for ( int k = w - 1 ; k >= 0 && ! bAlreadyFound ; --k) - bAlreadyFound = abs( dU - vdRoots[k]) < EPS_PARAM ; - if( ! bAlreadyFound) { + for ( int k = w - 1 ; k >= 0 && ! bAlreadyFound ; --k) + bAlreadyFound = ( abs( dU - vdRoots[k]) < EPS_PARAM) ; + if ( ! bAlreadyFound) { Vector3d vAlpha = a3 * pow(dU, 3) + a2 * pow( dU, 2) + a1 * dU + a0 ; Vector3d vBeta = b3 * pow(dU, 3) + b2 * pow( dU, 2) + b1 * dU + b0 ; double dDen = ( vAlpha.x * q.z - vAlpha.z * q.x) ; @@ -1587,8 +1593,8 @@ IntersLineBezierSurfSet( const Point3d& ptLineStart, const Vector3d& vtLineDir, vSurfInters.push_back( s) ; vbAlreadyCalc[s] = true ; - // se ho trovato un'intersezione all'interno dell'intervallo, esistente sullo spillone e che si interseca con la box, allora devo ricontrollare - // anche le superfici la cui box non facevano intersezione con l'intervallo + // se ho trovato un'intersezione all'interno dell'intervallo, esistente sullo spillone e che si interseca con il box, allora devo ricontrollare + // anche le superfici i cui box non facevano intersezione con l'intervallo if ( nInterv > -1 && ! bNeedToRot && ! bCalcAll && vInterv[nInterv].first < ptBez.z && ptBez.z < vInterv[nInterv].second) { bCalcAll = true ; goto Reiterate ; @@ -1607,14 +1613,14 @@ bool 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, int n5AxisType) { - // tolgo il volume spazzato dal tool durante il movimento - // Verifica sull'interferenza con lo Zmap + // tolgo il volume spazzato dal tool durante il movimento + // Verifica sull'interferenza con lo Zmap int nStartI, nStartJ, nEndI, nEndJ ; if ( ! TestCompoBBox( nGrid, ptS[0], ptE.back(), vtLs[0], vtLe.back(), dMaxRad, dMinRad, dHeight, nStartI, nStartJ, nEndI, nEndJ) ) return true ; int nStepCnt = int( ptS.size()) ; - // vettori di riferimento per trovare i punti ausiliari + // vettori di riferimento per trovare i punti ausiliari int nDegU = 3 ; int nDegV = 1 ; int nSpanU = 1 ; int nSpanV = 1 ; @@ -1624,16 +1630,16 @@ VolZmap::Comp_5AxisMilling( int nGrid, const PNTVECTOR& ptS, const PNTVECTOR& pt PNTVECTOR d ; Vector3d q = Z_AX ; - int nTotSurf = 4; - if ( n5AxisType == VolZmap::Move5Axis::NO_BASE_INTERS) + int nTotSurf = 4 ; + if ( n5AxisType == Move5Axis::NO_BASE_INTERS) nTotSurf = 2 * nStepCnt + nSub * 2 * nStepCnt + nSub * 2 + 8 ; // sup laterali, sup superiori e inferiori, superfici verticali di inizio e fine, superfici di base dei tool - else if( n5AxisType == VolZmap::Move5Axis::ACROSS) + else if( n5AxisType == Move5Axis::ACROSS) nTotSurf = 2 * nStepCnt + nSub * 4 * nStepCnt + nSub * 2 + 16 ; // come sopra int nSurfInd = 0 ; vector vSurfBez( nTotSurf) ; double dSide = 0 ; - // punti per le bilineari, sulle posizioni del tool alle estremità del movimento + // punti per le bilineari, sulle posizioni del tool alle estremità del movimento PNTVECTOR vPntTipStartExF ; PNTVECTOR vPntTipEndExF ; PNTVECTOR vPntTopStartExF ; @@ -1645,7 +1651,7 @@ VolZmap::Comp_5AxisMilling( int nGrid, const PNTVECTOR& ptS, const PNTVECTOR& pt Point3d ptP1TEx, ptP2TEx ; for ( int s = 0 ; s < nStepCnt ; ++s) { - // punti di riferimento sul tool + // punti di riferimento sul tool Point3d ptTop1s ; Point3d ptTop1e ; Point3d ptTop2s ; @@ -1654,17 +1660,17 @@ VolZmap::Comp_5AxisMilling( int nGrid, const PNTVECTOR& ptS, const PNTVECTOR& pt Point3d ptBottom1e ; Point3d ptBottom2s ; Point3d ptBottom2e ; - // tip del tool + // tip del tool Point3d ptP1T ; Point3d ptP2T ; - // determino la posizione della punta del tool nella posizione iniziale e in quella finale + // determino la posizione della punta del tool nella posizione iniziale e in quella finale ptP1T = ptS[s] - dHeight * vtLs[s] ; ptP2T = ptE[s] - dHeight * vtLe[s] ; - // determino la direzione di movimento del top del tool e della punta del tool + // determino la direzione di movimento del top del tool e della punta del tool Vector3d vtDirTop = ptE[s] - ptS[s] ; Vector3d vtDirTip = ptP2T - ptP1T ; - // determino i punti laterali del top e del bottom(tip), nella posizione di partenza + // determino i punti laterali del top e del bottom(tip), nella posizione di partenza Vector3d vtAuxTopS = vtLs[s] ^ vtDirTop ; vtAuxTopS.Normalize() ; vtAuxTopS *= dMaxRad ; @@ -1677,7 +1683,7 @@ VolZmap::Comp_5AxisMilling( int nGrid, const PNTVECTOR& ptS, const PNTVECTOR& pt ptBottom1s = ptP1T + vtAuxBottomS ; ptBottom2s = ptP1T - vtAuxBottomS ; - // determino i punti laterali del top e del bottom(tip), nella posizione di arrivo + // determino i punti laterali del top e del bottom(tip), nella posizione di arrivo Vector3d vtAuxTopE = vtLe[s] ^ vtDirTop ; vtAuxTopE.Normalize() ; vtAuxTopE *= dMaxRad ; @@ -1690,18 +1696,18 @@ VolZmap::Comp_5AxisMilling( int nGrid, const PNTVECTOR& ptS, const PNTVECTOR& pt ptBottom1e = ptP2T + vtAuxBottomE ; ptBottom2e = ptP2T - vtAuxBottomE ; - // punti sul top e tip del tool che servono per costruire le bilineare di congiunzione tra step + // punti sul top e tip del tool che servono per costruire le bilineare di congiunzione tra step PNTVECTOR vPntTipStartFront ; PNTVECTOR vPntTipEndFront ; PNTVECTOR vPntTopStartFront ; PNTVECTOR vPntTopEndFront ; - // punti addizionali che servono nei casi che rischiedono più superfici bilineari ( tutti tranne NO_BASE_INTERS) + // punti addizionali che servono nei casi che rischiedono più superfici bilineari ( tutti tranne NO_BASE_INTERS) PNTVECTOR vPntTipStartBack ; PNTVECTOR vPntTipEndBack ; PNTVECTOR vPntTopStartBack ; PNTVECTOR vPntTopEndBack ; if ( nSub > 1) { - // determino in che modo collegare il cilindro iniziale con quello finale + // determino in che modo collegare il cilindro iniziale con quello finale Vector3d vtTopBaseEnd = vtDirTop - ( (vtDirTop * vtLe[s]) * vtLe[s]) ; vtTopBaseEnd.Normalize() ; vtTopBaseEnd *= dMaxRad ; @@ -1712,14 +1718,14 @@ VolZmap::Comp_5AxisMilling( int nGrid, const PNTVECTOR& ptS, const PNTVECTOR& pt Point3d ptRefStart = ptS[s] + vtTopBaseStart ; dSide = (ptRefEnd - ptRefStart) * vtLs[s] ; - // calcolo anche i vettori per le basi inferiori + // calcolo anche i vettori per le basi inferiori Vector3d vtTipBaseStart = - (vtLs[s] ^ vtDirTip) ; vtTipBaseStart.Normalize() ; vtTipBaseStart *= dMinRad ; Vector3d vtTipBaseEnd = - (vtLe[s] ^ vtDirTip) ; vtTipBaseEnd.Normalize() ; vtTipBaseEnd *= dMinRad ; - // aggiungo il primo punto per ognuno dei gruppi + // aggiungo il primo punto per ognuno dei gruppi vtTopBaseStart.Rotate( vtLs[s], 90) ; vtTopBaseEnd.Rotate( vtLe[s], 90) ; vPntTopStartFront.emplace_back( ptS[s] - vtTopBaseStart) ; @@ -1727,31 +1733,31 @@ VolZmap::Comp_5AxisMilling( int nGrid, const PNTVECTOR& ptS, const PNTVECTOR& pt vPntTipStartFront.emplace_back( ptP1T + vtTipBaseStart) ; vPntTipEndFront.emplace_back( ptP2T + vtTipBaseEnd) ; - // punti addizionali per superfici bilineari + // punti addizionali per superfici bilineari vPntTopStartBack.emplace_back( ptS[s] + vtTopBaseStart) ; vPntTopEndBack.emplace_back( ptE[s] + vtTopBaseEnd) ; vPntTipStartBack.emplace_back( ptP1T - vtTipBaseStart) ; vPntTipEndBack.emplace_back( ptP2T - vtTipBaseEnd) ; double dSubAng = 90 ; - // girano tutti in verso CCW rispetto alla normale del tool + // girano tutti in verso CCW rispetto alla normale del tool for ( int i = 0 ; i < 2 ; ++i) { - // punti sulla base superiore dei cilindri - // start - //// frontale + // punti sulla base superiore dei cilindri + // start + // frontale vPntTopStartFront.emplace_back( vPntTopStartFront.back()) ; vPntTopStartFront.back().Rotate(ptS[s], vtLs[s], dSubAng) ; - //// posteriore + // posteriore vPntTopStartBack.emplace_back( vPntTopStartBack.back()) ; vPntTopStartBack.back().Rotate(ptS[s], vtLs[s], dSubAng) ; - // end - //// frontale + // end + // frontale vPntTopEndFront.emplace_back( vPntTopEndFront.back()) ; vPntTopEndFront.back().Rotate(ptE[s], vtLe[s], dSubAng) ; - //// posteriore + // posteriore vPntTopEndBack.emplace_back( vPntTopEndBack.back()) ; vPntTopEndBack.back().Rotate(ptE[s], vtLe[s], dSubAng) ; - // punti sulla base inferiore dei cilindri + // punti sulla base inferiore dei cilindri vPntTipStartFront.emplace_back( vPntTipStartFront.back()) ; vPntTipStartFront.back().Rotate(ptP1T, vtLs[s], dSubAng) ; vPntTipStartBack.emplace_back( vPntTipStartBack.back()) ; @@ -1763,7 +1769,7 @@ VolZmap::Comp_5AxisMilling( int nGrid, const PNTVECTOR& ptS, const PNTVECTOR& pt vPntTipEndBack.back().Rotate(ptP2T, vtLe[s], dSubAng) ; } } - // mi salvo i punti ausiliari per la posizione iniziale e finale del tool + // mi salvo i punti ausiliari per la posizione iniziale e finale del tool if ( s == 0) { vPntTipStartExF = vPntTipStartFront ; vPntTopStartExF = vPntTopStartFront ; @@ -1780,7 +1786,7 @@ VolZmap::Comp_5AxisMilling( int nGrid, const PNTVECTOR& ptS, const PNTVECTOR& pt } vector vvPtCtrl ; - // superficie laterale sinistra + // superficie laterale sinistra CurveLine cLineLeftStart ; cLineLeftStart.Set( ptBottom1s, ptTop1s) ; PtrOwner cBezLeftStart( GetBasicCurveBezier( LineToBezierCurve( &cLineLeftStart, nDegU, bRat))) ; CurveLine cLineLeftEnd ; cLineLeftEnd.Set( ptBottom1e, ptTop1e) ; @@ -1788,7 +1794,7 @@ VolZmap::Comp_5AxisMilling( int nGrid, const PNTVECTOR& ptS, const PNTVECTOR& pt vvPtCtrl.emplace_back( cBezLeftStart->GetAllControlPoints()) ; PNTVECTOR vPntLeft = cBezLeftEnd->GetAllControlPoints() ; vvPtCtrl.back().insert( vvPtCtrl.back().end(), vPntLeft.begin(), vPntLeft.end()) ; - // superficie laterale destra + // superficie laterale destra CurveLine cLineRightStart ; cLineRightStart.Set( ptTop2s, ptBottom2s) ; PtrOwner cBezRightStart( GetBasicCurveBezier( LineToBezierCurve( &cLineRightStart, nDegU, bRat))) ; CurveLine cLineRightEnd ; cLineRightEnd.Set( ptTop2e, ptBottom2e) ; @@ -1797,14 +1803,14 @@ VolZmap::Comp_5AxisMilling( int nGrid, const PNTVECTOR& ptS, const PNTVECTOR& pt PNTVECTOR vPntRight = cBezRightEnd->GetAllControlPoints() ; vvPtCtrl.back().insert( vvPtCtrl.back().end(), vPntRight.begin(), vPntRight.end()) ; if ( nSub == 1) { - // superficie inferiore + // superficie inferiore vvPtCtrl.emplace_back( PNTVECTOR({ ptBottom2s, ptBottom1s, ptBottom2e, ptBottom1e})) ; - // superficie superiore + // superficie superiore vvPtCtrl.emplace_back( PNTVECTOR({ ptTop1s, ptTop2s, ptTop1e, ptTop2e})) ; } else { - if( n5AxisType == VolZmap::Move5Axis::NO_BASE_INTERS || n5AxisType == VolZmap::Move5Axis::ACROSS){ - // inferiori + if ( n5AxisType == Move5Axis::NO_BASE_INTERS || n5AxisType == Move5Axis::ACROSS) { + // inferiori CurveArc cArcTipStart1, cArcTipEnd1, cArcTipStart2,cArcTipEnd2 ; if ( dSide > 0) { cArcTipStart1.SetC2PN( ptP1T, vPntTipStartFront[0], vPntTipStartFront[1], vtLs[s]) ; @@ -1818,19 +1824,19 @@ VolZmap::Comp_5AxisMilling( int nGrid, const PNTVECTOR& ptS, const PNTVECTOR& pt cArcTipStart2.SetC2PN( ptP1T, vPntTipStartBack[2], vPntTipStartBack[1], vtLs[s]) ; cArcTipEnd2.SetC2PN( ptP2T, vPntTipEndBack[2], vPntTipEndBack[1], vtLe[s]) ; } - // superfici inferiori 1 + // superfici inferiori 1 PtrOwner cBezTipStart1( GetBasicCurveBezier(ArcToBezierCurve( &cArcTipStart1, nDegU, bRat))) ; PtrOwner cBezTipEnd1( GetBasicCurveBezier(ArcToBezierCurve( &cArcTipEnd1, nDegU, bRat))) ; vvPtCtrl.emplace_back( cBezTipStart1->GetAllControlPoints()) ; PNTVECTOR vPntTipEnd1 = cBezTipEnd1->GetAllControlPoints() ; vvPtCtrl.back().insert( vvPtCtrl.back().end(), vPntTipEnd1.begin(), vPntTipEnd1.end()) ; - // superfici inferiori 2 + // superfici inferiori 2 PtrOwner cBezTipStart2( GetBasicCurveBezier(ArcToBezierCurve( &cArcTipStart2, nDegU, bRat))) ; PtrOwner cBezTipEnd2( GetBasicCurveBezier(ArcToBezierCurve( &cArcTipEnd2, nDegU, bRat))) ; vvPtCtrl.emplace_back( cBezTipStart2->GetAllControlPoints()) ; PNTVECTOR vPntTipEnd2 = cBezTipEnd2->GetAllControlPoints() ; vvPtCtrl.back().insert( vvPtCtrl.back().end(), vPntTipEnd2.begin(), vPntTipEnd2.end()) ; - // superiori + // superiori CurveArc cArcTopStart1, cArcTopEnd1, cArcTopStart2, cArcTopEnd2 ; if ( dSide > 0) { cArcTopStart1.SetC2PN( ptS[s], vPntTopStartBack[0], vPntTopStartBack[1], vtLs[s]) ; @@ -1844,21 +1850,21 @@ VolZmap::Comp_5AxisMilling( int nGrid, const PNTVECTOR& ptS, const PNTVECTOR& pt cArcTopStart2.SetC2PN( ptS[s], vPntTopStartFront[2], vPntTopStartFront[1], vtLs[s]) ; cArcTopEnd2.SetC2PN( ptE[s], vPntTopEndFront[2], vPntTopEndFront[1], vtLe[s]) ; } - // superfici superiori 1 + // superfici superiori 1 PtrOwner cBezTopStart1( GetBasicCurveBezier(ArcToBezierCurve( &cArcTopStart1, nDegU, bRat))) ; PtrOwner cBezTopEnd1( GetBasicCurveBezier(ArcToBezierCurve( &cArcTopEnd1, nDegU, bRat))) ; vvPtCtrl.emplace_back( cBezTopStart1->GetAllControlPoints()) ; PNTVECTOR vPntTopEnd1 = cBezTopEnd1->GetAllControlPoints() ; vvPtCtrl.back().insert( vvPtCtrl.back().end(), vPntTopEnd1.begin(), vPntTopEnd1.end()) ; - // superfici superiori 2 + // superfici superiori 2 PtrOwner cBezTopStart2( GetBasicCurveBezier(ArcToBezierCurve( &cArcTopStart2, nDegU, bRat))) ; PtrOwner cBezTopEnd2( GetBasicCurveBezier(ArcToBezierCurve( &cArcTopEnd2, nDegU, bRat))) ; vvPtCtrl.emplace_back( cBezTopStart2->GetAllControlPoints()) ; PNTVECTOR vPntTopEnd2 = cBezTopEnd2->GetAllControlPoints() ; vvPtCtrl.back().insert( vvPtCtrl.back().end(), vPntTopEnd2.begin(), vPntTopEnd2.end()) ; - // aggiungo le superfici bilineari anche nell'altro verso sia per il top che per il tip - if( n5AxisType == VolZmap::Move5Axis::ACROSS) { - // inferiori + // aggiungo le superfici bilineari anche nell'altro verso sia per il top che per il tip + if ( n5AxisType == Move5Axis::ACROSS) { + // inferiori CurveArc cArcTipStart1, cArcTipEnd1, cArcTipStart2, cArcTipEnd2 ; if ( dSide > 0) { cArcTipStart1.SetC2PN( ptP1T, vPntTipStartBack[1], vPntTipStartBack[0], vtLs[s]) ; @@ -1872,19 +1878,19 @@ VolZmap::Comp_5AxisMilling( int nGrid, const PNTVECTOR& ptS, const PNTVECTOR& pt cArcTipStart2.SetC2PN( ptP1T, vPntTipStartFront[1], vPntTipStartFront[2], vtLs[s]) ; cArcTipEnd2.SetC2PN( ptP2T, vPntTipEndFront[1], vPntTipEndFront[2], vtLe[s]) ; } - // inferiori 1 + // inferiori 1 PtrOwner cBezTipStart1( GetBasicCurveBezier(ArcToBezierCurve( &cArcTipStart1, nDegU, bRat))) ; PtrOwner cBezTipEnd1( GetBasicCurveBezier(ArcToBezierCurve( &cArcTipEnd1, nDegU, bRat))) ; vvPtCtrl.emplace_back( cBezTipStart1->GetAllControlPoints()) ; PNTVECTOR vPntTip1 = cBezTipEnd1->GetAllControlPoints() ; vvPtCtrl.back().insert( vvPtCtrl.back().end(), vPntTip1.begin(), vPntTip1.end()) ; - // inferiori 2 + // inferiori 2 PtrOwner cBezTipStart2( GetBasicCurveBezier(ArcToBezierCurve( &cArcTipStart2, nDegU, bRat))) ; PtrOwner cBezTipEnd2( GetBasicCurveBezier(ArcToBezierCurve( &cArcTipEnd2, nDegU, bRat))) ; vvPtCtrl.emplace_back( cBezTipStart2->GetAllControlPoints()) ; PNTVECTOR vPntTip2 = cBezTipEnd2->GetAllControlPoints() ; vvPtCtrl.back().insert( vvPtCtrl.back().end(), vPntTip2.begin(), vPntTip2.end()) ; - // superiori + // superiori CurveArc cArcTopStart1, cArcTopEnd1, cArcTopStart2, cArcTopEnd2 ; if ( dSide > 0) { cArcTopStart1.SetC2PN( ptS[s], vPntTopStartFront[1], vPntTopStartFront[0], vtLs[s]) ; @@ -1898,13 +1904,13 @@ VolZmap::Comp_5AxisMilling( int nGrid, const PNTVECTOR& ptS, const PNTVECTOR& pt cArcTopStart2.SetC2PN( ptS[s], vPntTopStartBack[1], vPntTopStartBack[2], vtLs[s]) ; cArcTopEnd2.SetC2PN( ptE[s], vPntTopEndBack[1], vPntTopEndBack[2], vtLe[s]) ; } - // superfici superiori 1 + // superfici superiori 1 PtrOwner cBezTopStart1( GetBasicCurveBezier(ArcToBezierCurve( &cArcTopStart1, nDegU, bRat))) ; PtrOwner cBezTopEnd1( GetBasicCurveBezier(ArcToBezierCurve( &cArcTopEnd1, nDegU, bRat))) ; vvPtCtrl.emplace_back( cBezTopStart1->GetAllControlPoints()) ; PNTVECTOR vPntTop1 = cBezTopEnd1->GetAllControlPoints() ; vvPtCtrl.back().insert( vvPtCtrl.back().end(), vPntTop1.begin(), vPntTop1.end()) ; - // superfici superiori 2 + // superfici superiori 2 PtrOwner cBezTopStart2( GetBasicCurveBezier(ArcToBezierCurve( &cArcTopStart2, nDegU, bRat))) ; PtrOwner cBezTopEnd2( GetBasicCurveBezier(ArcToBezierCurve( &cArcTopEnd2, nDegU, bRat))) ; vvPtCtrl.emplace_back( cBezTopStart2->GetAllControlPoints()) ; @@ -1913,9 +1919,9 @@ VolZmap::Comp_5AxisMilling( int nGrid, const PNTVECTOR& ptS, const PNTVECTOR& pt } } - // all'ultimo step chiudo il volume con le superfici verticali e le basi dei tool + // all'ultimo step chiudo il volume con le superfici verticali e le basi dei tool if ( s == nStepCnt - 1) { - // chiudo il volume con le superici verticali end 1 + // chiudo il volume con le superici verticali end 1 CurveArc cArcTipEnd1, cArcTopEnd1, cArcTipEnd2, cArcTopEnd2 ; cArcTipEnd1.SetC2PN( ptP2TEx, vPntTipEndExF[0], vPntTipEndExF[1], vtLe.back()) ; cArcTopEnd1.SetC2PN( ptE.back(), vPntTopEndExF[0], vPntTopEndExF[1], vtLe.back()) ; @@ -1926,14 +1932,14 @@ VolZmap::Comp_5AxisMilling( int nGrid, const PNTVECTOR& ptS, const PNTVECTOR& pt vvPtCtrl.emplace_back( cBezTipEnd1->GetAllControlPoints()) ; PNTVECTOR vPntEnd1 = cBezTopEnd1->GetAllControlPoints() ; vvPtCtrl.back().insert( vvPtCtrl.back().end(), vPntEnd1.begin(), vPntEnd1.end()) ; - // chiudo il volume con le superici verticali end 2 + // chiudo il volume con le superici verticali end 2 PtrOwner cBezTipEnd2( GetBasicCurveBezier(ArcToBezierCurve( &cArcTipEnd2, nDegU, bRat))) ; PtrOwner cBezTopEnd2( GetBasicCurveBezier(ArcToBezierCurve( &cArcTopEnd2, nDegU, bRat))) ; vvPtCtrl.emplace_back( cBezTipEnd2->GetAllControlPoints()) ; PNTVECTOR vPntEnd2 = cBezTopEnd2->GetAllControlPoints() ; vvPtCtrl.back().insert( vvPtCtrl.back().end(), vPntEnd2.begin(), vPntEnd2.end()) ; - // chiudo il volume con le superici verticali start 1 + // chiudo il volume con le superici verticali start 1 CurveArc cArcTipStart1, cArcTopStart1, cArcTipStart2, cArcTopStart2 ; cArcTipStart1.SetC2PN( ptP1TEx, vPntTipStartExB[0], vPntTipStartExB[1], vtLs.front()) ; cArcTopStart1.SetC2PN( ptS.front(), vPntTopStartExB[0], vPntTopStartExB[1], vtLs.front()) ; @@ -1944,16 +1950,16 @@ VolZmap::Comp_5AxisMilling( int nGrid, const PNTVECTOR& ptS, const PNTVECTOR& pt vvPtCtrl.emplace_back( cBezTipStart1->GetAllControlPoints()) ; PNTVECTOR vPntStart1 = cBezTopStart1->GetAllControlPoints() ; vvPtCtrl.back().insert( vvPtCtrl.back().end(), vPntStart1.begin(), vPntStart1.end()) ; - // chiudo il volume con le superfici verticali start 2 + // chiudo il volume con le superfici verticali start 2 PtrOwner cBezTipStart2( GetBasicCurveBezier(ArcToBezierCurve( &cArcTipStart2, nDegU, bRat))) ; PtrOwner cBezTopStart2( GetBasicCurveBezier(ArcToBezierCurve( &cArcTopStart2, nDegU, bRat))) ; vvPtCtrl.emplace_back( cBezTipStart2->GetAllControlPoints()) ; PNTVECTOR vPntStart2 = cBezTopStart2->GetAllControlPoints() ; vvPtCtrl.back().insert( vvPtCtrl.back().end(), vPntStart2.begin(), vPntStart2.end()) ; - // superfici di base dei tool - if ( ! ( n5AxisType == VolZmap::Move5Axis::NO_BASE_INTERS && dSide < 0)) { - // start back tip + // superfici di base dei tool + if ( ! ( n5AxisType == Move5Axis::NO_BASE_INTERS && dSide < 0)) { + // start back tip CurveArc cArcTipStartBack1, cArcTipStartBack2 ; cArcTipStartBack1.SetC2PN( ptP1TEx, vPntTipStartExB[0], vPntTipStartExB[1], vtLs.front()) ; cArcTipStartBack2.SetC2PN( ptP1TEx, vPntTipStartExB[1], vPntTipStartExB[2], vtLs.front()) ; @@ -1965,7 +1971,7 @@ VolZmap::Comp_5AxisMilling( int nGrid, const PNTVECTOR& ptS, const PNTVECTOR& pt vvPtCtrl.emplace_back( PNTVECTOR{ ptP1TEx, ptP1TEx, ptP1TEx, ptP1TEx}) ; PNTVECTOR vPntTipStartBack2 = cBezTipStartBack2->GetAllControlPoints() ; vvPtCtrl.back().insert( vvPtCtrl.back().end(), vPntTipStartBack2.begin(), vPntTipStartBack2.end()) ; - // start front tip + // start front tip CurveArc cArcTipStartFront1, cArcTipStartFront2 ; cArcTipStartFront1.SetC2PN( ptP1TEx, vPntTipStartExF[0], vPntTipStartExF[1], vtLs.front()) ; cArcTipStartFront2.SetC2PN( ptP1TEx, vPntTipStartExF[1], vPntTipStartExF[2], vtLs.front()) ; @@ -1978,8 +1984,8 @@ VolZmap::Comp_5AxisMilling( int nGrid, const PNTVECTOR& ptS, const PNTVECTOR& pt PNTVECTOR vPntTipStartFront2 = cBezTipStartFront2->GetAllControlPoints() ; vvPtCtrl.back().insert( vvPtCtrl.back().end(), vPntTipStartFront2.begin(), vPntTipStartFront2.end()) ; } - if ( ! ( n5AxisType == VolZmap::Move5Axis::NO_BASE_INTERS && dSide > 0)) { - // end front tip + if ( ! ( n5AxisType == Move5Axis::NO_BASE_INTERS && dSide > 0)) { + // end front tip CurveArc cArcTipEndFront1, cArcTipEndFront2 ; cArcTipEndFront1.SetC2PN( ptP2TEx, vPntTipEndExF[0], vPntTipEndExF[1], vtLe.back()) ; cArcTipEndFront2.SetC2PN( ptP2TEx, vPntTipEndExF[1], vPntTipEndExF[2], vtLe.back()) ; @@ -1991,7 +1997,7 @@ VolZmap::Comp_5AxisMilling( int nGrid, const PNTVECTOR& ptS, const PNTVECTOR& pt vvPtCtrl.emplace_back( PNTVECTOR{ ptP2TEx, ptP2TEx, ptP2TEx, ptP2TEx}) ; PNTVECTOR vPntTipEndFront2 = cBezTipEndFront2->GetAllControlPoints() ; vvPtCtrl.back().insert( vvPtCtrl.back().end(), vPntTipEndFront2.begin(), vPntTipEndFront2.end()) ; - // end back tip + // end back tip CurveArc cArcTipEndBack1, cArcTipEndBack2 ; cArcTipEndBack1.SetC2PN( ptP2TEx, vPntTipEndExB[0], vPntTipEndExB[1], vtLe.back()) ; cArcTipEndBack2.SetC2PN( ptP2TEx, vPntTipEndExB[1], vPntTipEndExB[2], vtLe.back()) ; @@ -2005,8 +2011,8 @@ VolZmap::Comp_5AxisMilling( int nGrid, const PNTVECTOR& ptS, const PNTVECTOR& pt vvPtCtrl.back().insert( vvPtCtrl.back().end(), vPntTipEndBack2.begin(), vPntTipEndBack2.end()) ; } - if ( ! ( n5AxisType == VolZmap::Move5Axis::NO_BASE_INTERS && dSide > 0)) { - // start back top + if ( ! ( n5AxisType == Move5Axis::NO_BASE_INTERS && dSide > 0)) { + // start back top CurveArc cArcTopStartBack1, cArcTopStartBack2 ; cArcTopStartBack1.SetC2PN( ptS.front(), vPntTopStartExB[1], vPntTopStartExB[0], vtLs.front()) ; cArcTopStartBack2.SetC2PN( ptS.front(), vPntTopStartExB[2], vPntTopStartExB[1], vtLs.front()) ; @@ -2018,7 +2024,7 @@ VolZmap::Comp_5AxisMilling( int nGrid, const PNTVECTOR& ptS, const PNTVECTOR& pt vvPtCtrl.emplace_back( PNTVECTOR{ ptS[0], ptS[0], ptS[0], ptS[0]}) ; PNTVECTOR vPntTopStartBack2 = cBezTopStartBack2->GetAllControlPoints() ; vvPtCtrl.back().insert( vvPtCtrl.back().end(), vPntTopStartBack2.begin(), vPntTopStartBack2.end()) ; - // start front top + // start front top CurveArc cArcTopStartFront1, cArcTopStartFront2 ; cArcTopStartFront1.SetC2PN( ptS.front(), vPntTopStartExF[1], vPntTopStartExF[0], vtLs.front()) ; cArcTopStartFront2.SetC2PN( ptS.front(), vPntTopStartExF[2], vPntTopStartExF[1], vtLs.front()) ; @@ -2031,8 +2037,8 @@ VolZmap::Comp_5AxisMilling( int nGrid, const PNTVECTOR& ptS, const PNTVECTOR& pt PNTVECTOR vPntTopStartFront2 = cBezTopStartFront2->GetAllControlPoints() ; vvPtCtrl.back().insert( vvPtCtrl.back().end(), vPntTopStartFront2.begin(), vPntTopStartFront2.end()) ; } - if ( ! ( n5AxisType == VolZmap::Move5Axis::NO_BASE_INTERS && dSide < 0)) { - // end front top + if ( ! ( n5AxisType == Move5Axis::NO_BASE_INTERS && dSide < 0)) { + // end front top CurveArc cArcTopEndFront1, cArcTopEndFront2 ; cArcTopEndFront1.SetC2PN( ptE.back(), vPntTopEndExF[1], vPntTopEndExF[0], vtLe.back()) ; cArcTopEndFront2.SetC2PN( ptE.back(), vPntTopEndExF[2], vPntTopEndExF[1], vtLe.back()) ; @@ -2044,7 +2050,7 @@ VolZmap::Comp_5AxisMilling( int nGrid, const PNTVECTOR& ptS, const PNTVECTOR& pt vvPtCtrl.emplace_back( PNTVECTOR{ ptE[s], ptE[s], ptE[s], ptE[s]}) ; PNTVECTOR vPntTopEndFront2 = cBezTopEndFront2->GetAllControlPoints() ; vvPtCtrl.back().insert( vvPtCtrl.back().end(), vPntTopEndFront2.begin(), vPntTopEndFront2.end()) ; - // end back top + // end back top CurveArc cArcTopEndBack1, cArcTopEndBack2 ; cArcTopEndBack1.SetC2PN( ptE.back(), vPntTopEndExB[1], vPntTopEndExB[0], vtLe.back()) ; cArcTopEndBack2.SetC2PN( ptE.back(), vPntTopEndExB[2], vPntTopEndExB[1], vtLe.back()) ; @@ -2060,8 +2066,8 @@ VolZmap::Comp_5AxisMilling( int nGrid, const PNTVECTOR& ptS, const PNTVECTOR& pt } } - // inizializzo le superfici bilineari e i parametri per le intersezioni - for( int z = 0 ; z < int( vvPtCtrl.size()) ; ++z) { + // 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) ; vSurfBez[nSurfInd].sBez.SetControlPoint( 0, vvPtCtrl[z][0]) ; vSurfBez[nSurfInd].sBez.SetControlPoint( 1, vvPtCtrl[z][1]) ; @@ -2094,34 +2100,34 @@ VolZmap::Comp_5AxisMilling( int nGrid, const PNTVECTOR& ptS, const PNTVECTOR& pt Vector3d vtDirX ; Vector3d vtDir0 = vvPtCtrl[z][4] - vvPtCtrl[z][0] ; Vector3d vtDir1 = vvPtCtrl[z][3] - vvPtCtrl[z][0] ; - if( vtDir0.Len() > vtDir1.Len()) + if ( vtDir0.Len() > vtDir1.Len()) vtDirX = vtDir0 ; else vtDirX = vtDir1 ; - // calcolo il box in un riferimento che usi come asse x la direzione P01 - P00 ( proiettata sul piano perperndicolare a Z) - if( vSurfBez[nSurfInd].frZMainDim.Set( ORIG, Z_AX, vtDirX)) { - // porto tutti i punti in quel riferimento e calcolo il box + // calcolo il box in un riferimento che usi come asse x la direzione P01 - P00 ( proiettata sul piano perperndicolare a Z) + if ( vSurfBez[nSurfInd].frZMainDim.Set( ORIG, Z_AX, vtDirX)) { + // porto tutti i punti in quel riferimento e calcolo il box PNTVECTOR vPtCtrlLoc = vvPtCtrl[z] ; - for( int p = 0 ; p < int( vPtCtrlLoc.size()) ; ++p) + for ( int p = 0 ; p < int( vPtCtrlLoc.size()) ; ++p) vPtCtrlLoc[p].ToLoc( vSurfBez[nSurfInd].frZMainDim) ; vSurfBez[nSurfInd].bbSurfZ.Add( vPtCtrlLoc) ; } else { - // in ogni caso definisco la box rispetto al rifemento di nGrid + // in ogni caso definisco la box rispetto al rifemento di nGrid vSurfBez[nSurfInd].bbSurfZ.Add( vvPtCtrl[z]) ; } - if( vSurfBez[nSurfInd].frXMainDim.Set( ORIG, X_AX, vtDirX)) { + if ( vSurfBez[nSurfInd].frXMainDim.Set( ORIG, X_AX, vtDirX)) { PNTVECTOR vPtCtrlLoc = vvPtCtrl[z] ; - // porto tutti i punti in quel riferimento e calcolo il box - for( int p = 0 ; p < int( vPtCtrlLoc.size()) ; ++p) + // porto tutti i punti in quel riferimento e calcolo il box + for ( int p = 0 ; p < int( vPtCtrlLoc.size()) ; ++p) vPtCtrlLoc[p].ToLoc( vSurfBez[nSurfInd].frXMainDim) ; vSurfBez[nSurfInd].bbSurfX.Add( vPtCtrlLoc) ; } - if( vSurfBez[nSurfInd].frYMainDim.Set( ORIG, Y_AX, vtDirX)) { + if ( vSurfBez[nSurfInd].frYMainDim.Set( ORIG, Y_AX, vtDirX)) { PNTVECTOR vPtCtrlLoc = vvPtCtrl[z] ; - // porto tutti i punti in quel riferimento e calcolo il box - for( int p = 0 ; p < int( vPtCtrlLoc.size()) ; ++p) + // porto tutti i punti in quel riferimento e calcolo il box + for ( int p = 0 ; p < int( vPtCtrlLoc.size()) ; ++p) vPtCtrlLoc[p].ToLoc( vSurfBez[nSurfInd].frYMainDim) ; vSurfBez[nSurfInd].bbSurfY.Add( vPtCtrlLoc) ; } @@ -2132,6 +2138,10 @@ VolZmap::Comp_5AxisMilling( int nGrid, const PNTVECTOR& ptS, const PNTVECTOR& pt // scorro tutti gli spilloni interessati int j = 0 ; int nLastForwardJ = -1 ; + bool bUseOnlyExtremes = false ; + bool bFirstAmbiguousCaseType = false ; + bool bForward = true ; + bool bAllSameType = false ; struct IntervalsToSubtract { int i = 0 ; int j = 0 ; @@ -2140,10 +2150,6 @@ VolZmap::Comp_5AxisMilling( int nGrid, const PNTVECTOR& ptS, const PNTVECTOR& pt INTINTVECTOR vStartEnds ; IntervalsToSubtract( int nI, int nJ, PNTVEC3DVECTOR& vPntInt, INTINTVECTOR& vSE, bool bUseExtremes) : i( nI), j( nJ), bUseOnlyExtremes( bUseExtremes), vInters( vPntInt), vStartEnds( vSE) {} } ; - bool bUseOnlyExtremes = false ; - bool bFirstAmbiguousCaseType = false ; - bool bForward = true ; - bool bAllSameType = false ; vector vIntervalsToSubtr ; for ( int i = nStartI ; i <= nEndI ; ++ i) { @@ -2162,7 +2168,7 @@ VolZmap::Comp_5AxisMilling( int nGrid, const PNTVECTOR& ptS, const PNTVECTOR& pt INTVECTOR vSurfInters ; int nPos = j * m_nNx[nGrid] + i ; vector& vDexel = m_Values[nGrid][nPos] ; - vector vInterv, vEmpty ; + DBLDBLVECTOR vInterv, vEmpty ; for ( int k = 0 ; k < int(vDexel.size()) ; ++k ) vInterv.emplace_back( vDexel[k].dMin, vDexel[k].dMax) ; @@ -2179,7 +2185,7 @@ VolZmap::Comp_5AxisMilling( int nGrid, const PNTVECTOR& ptS, const PNTVECTOR& pt if ( ! bForward && vStartEnds.size() > 1) { // salvo la prima intersezione dubbia e comincio a scorrere al contrario per trovare l'ultima e capire se è dello stesso tipo della prima - if( ! bAllSameType) { + if ( ! bAllSameType) { bUseOnlyExtremes = false ; // calcolo le intersezioni anche sugli altri due spilloni passanti per un punto a metà tra due dei vari intervalli @@ -2191,11 +2197,12 @@ VolZmap::Comp_5AxisMilling( int nGrid, const PNTVECTOR& ptS, const PNTVECTOR& pt INTINTVECTOR vStartEndsX ; bool bXInclude = false ; IntersLineBezierSurfSet( ptLineStart, vtLineStart, vSurfBez, vIntersX, vSurfX, V_NULL, vEmpty) ; - if( vIntersX.size() > 1) { + if ( vIntersX.size() > 1) { SortGroupInters( vIntersX, vStartEndsX, X_AX) ; - if( vStartEndsX.size() != 0) + if ( vStartEndsX.size() != 0) // se ho più di una intersezione e il punto di studio è compreso tra questi punti allora le info lungo questa direzione mi dicono che sono interno al volume spazzato - bXInclude = vIntersX[vStartEndsX.front().first].first.x < ptLineStart.x && vIntersX[vStartEndsX.back().second].first.x > ptLineStart.x ; + bXInclude = ( vIntersX[vStartEndsX.front().first].first.x < ptLineStart.x && + vIntersX[vStartEndsX.back().second].first.x > ptLineStart.x) ; } vtLineStart = Y_AX ; @@ -2206,18 +2213,19 @@ VolZmap::Comp_5AxisMilling( int nGrid, const PNTVECTOR& ptS, const PNTVECTOR& pt IntersLineBezierSurfSet( ptLineStart, vtLineStart, vSurfBez, vIntersY, vSurfY, V_NULL, vEmpty) ; if ( vIntersY.size() > 1) { SortGroupInters( vIntersY, vStartEndsY, Y_AX) ; - if( vStartEndsY.size() != 0) + if ( vStartEndsY.size() != 0) // se ho più di una intersezione e il punto di studio è compreso tra questi punti allora le info lungo questa direzione mi dicono che sono interno al volume spazzato - bYInclude = vIntersY[vStartEndsY.front().first].first.y < ptLineStart.y && vIntersY[vStartEndsY.back().second].first.y > ptLineStart.y ; + bYInclude = ( vIntersY[vStartEndsY.front().first].first.y < ptLineStart.y && + vIntersY[vStartEndsY.back().second].first.y > ptLineStart.y) ; } // se anche gli spilloni nelle altre due direzioni fanno intersezione sia a destra che a sinistra rispetto al punto a metà tra gli intervalli, allora sono all'interno del volume - if( bXInclude && bYInclude) + if ( bXInclude && bYInclude) bUseOnlyExtremes = true ; } int nJToSave = j ; - if( j == nEndJ + 1) { + if ( j == nEndJ + 1) { nJToSave = nLastForwardJ ; bFirstAmbiguousCaseType = bUseOnlyExtremes ; } @@ -2228,26 +2236,30 @@ VolZmap::Comp_5AxisMilling( int nGrid, const PNTVECTOR& ptS, const PNTVECTOR& pt bAllSameType = true ; } - if( ! bAllSameType) + if ( ! bAllSameType) vIntervalsToSubtr.emplace_back( i, nJToSave, vInters, vStartEnds, bUseOnlyExtremes) ; else { bUseOnlyExtremes = bFirstAmbiguousCaseType ; if ( bUseOnlyExtremes) - SubtractIntervals( nGrid, i, j, vInters.front().first.z, vInters.back().first.z, vInters.front().second, vInters.back().second, nToolNum) ; + SubtractIntervals( nGrid, i, j, vInters.front().first.z, vInters.back().first.z, + vInters.front().second, vInters.back().second, nToolNum) ; else { - for( auto p : vStartEnds) - SubtractIntervals(nGrid, i, j, vInters[p.first].first.z, vInters[p.second].first.z, vInters[p.first].second, vInters[p.second].second, nToolNum) ; + for ( auto p : vStartEnds) + SubtractIntervals( nGrid, i, j, vInters[p.first].first.z, vInters[p.second].first.z, + vInters[p.first].second, vInters[p.second].second, nToolNum) ; } } } else { - for( auto p : vStartEnds) - SubtractIntervals(nGrid, i, j, vInters[p.first].first.z, vInters[p.second].first.z, vInters[p.first].second, vInters[p.second].second, nToolNum) ; + for ( auto p : vStartEnds) + SubtractIntervals( nGrid, i, j, vInters[p.first].first.z, vInters[p.second].first.z, + vInters[p.first].second, vInters[p.second].second, nToolNum) ; } } - else if ( vInters.size() == 2){ + else if ( vInters.size() == 2) { vStartEnds.push_back(INTINT(0, 1)) ; - SubtractIntervals( nGrid, i, j, vInters.front().first.z, vInters.back().first.z, vInters.front().second, vInters.back().second, nToolNum) ; + SubtractIntervals( nGrid, i, j, vInters.front().first.z, vInters.back().first.z, + vInters.front().second, vInters.back().second, nToolNum) ; } else if ( vInters.size() == 1) { // se trovo solo un'intersezione è una tangenza tra spillone e una superficie @@ -2263,13 +2275,15 @@ VolZmap::Comp_5AxisMilling( int nGrid, const PNTVECTOR& ptS, const PNTVECTOR& pt for ( IntervalsToSubtract& intToSub : vIntervalsToSubtr) { if ( intToSub.bUseOnlyExtremes) - SubtractIntervals( nGrid, intToSub.i, intToSub.j, intToSub.vInters.front().first.z, intToSub.vInters.back().first.z, intToSub.vInters.front().second, intToSub.vInters.back().second, nToolNum) ; + SubtractIntervals( nGrid, intToSub.i, intToSub.j, intToSub.vInters.front().first.z, intToSub.vInters.back().first.z, + intToSub.vInters.front().second, intToSub.vInters.back().second, nToolNum) ; else { - // scorro le intersezione su questo spillone togliendo gli intervalli usando vStartEnds + // scorro le intersezione su questo spillone togliendo gli intervalli usando vStartEnds for ( int z = 0 ; z < int( intToSub.vStartEnds.size()) ; ++z) { int nStart = intToSub.vStartEnds[z].first ; int nEnd = intToSub.vStartEnds[z].second ; - SubtractIntervals( nGrid, intToSub.i, intToSub.j, intToSub.vInters[nStart].first.z, intToSub.vInters[nEnd].first.z, intToSub.vInters[nStart].second, intToSub.vInters[nEnd].second, nToolNum) ; + SubtractIntervals( nGrid, intToSub.i, intToSub.j, intToSub.vInters[nStart].first.z, intToSub.vInters[nEnd].first.z, + intToSub.vInters[nStart].second, intToSub.vInters[nEnd].second, nToolNum) ; } } } @@ -2282,24 +2296,20 @@ bool VolZmap::CompCyl_5AxisMilling( int nGrid, const PNTVECTOR& ptS, const PNTVECTOR& ptE, const VCT3DVECTOR& vtLs, const VCT3DVECTOR& vtLe, double dHeight, double dRadius, int nToolNum, int n5AxisType) { - bool bOk = true ; - - // tolgo il valume spazzato dal tool durante il movimento - bOk = bOk && Comp_5AxisMilling( nGrid, ptS, ptE, vtLs, vtLe, dHeight, dRadius, dRadius, nToolNum, n5AxisType) ; - - return bOk ; + // tolgo il volume spazzato dal tool durante il movimento + return Comp_5AxisMilling( nGrid, ptS, ptE, vtLs, vtLe, dHeight, dRadius, dRadius, nToolNum, n5AxisType) ; } //---------------------------------------------------------------------------- bool VolZmap::Cyl_5AxisMilling( int nGrid, const PNTVECTOR& ptS, const PNTVECTOR& ptE, const VCT3DVECTOR& vtLs, const VCT3DVECTOR& vtLe, int nToolNum, double dHeightCorr, int n5AxisType) { - // tolgo il volume dei cilindri all'inizio e alla fine del tratto e poi uso delle bilineari per approssimare il volume spazzato + // tolgo il volume dei cilindri all'inizio e alla fine del tratto e poi uso delle bilineari per approssimare il volume spazzato - // Controllo utensile + // Controllo utensile if ( m_nCurrTool < 0 || m_nCurrTool >= int( m_vTool.size())) return false ; - // recupero le info del tool + // recupero le info del tool Tool& CurrTool = m_vTool[m_nCurrTool] ; double dHeight = CurrTool.GetHeigth() - dHeightCorr ; double dRadius = CurrTool.GetRadius() ; @@ -2311,7 +2321,7 @@ VolZmap::Cyl_5AxisMilling( int nGrid, const PNTVECTOR& ptS, const PNTVECTOR& ptE bool VolZmap::CylBall_5AxisMilling( int nGrid, const PNTVECTOR& ptS, const PNTVECTOR& ptE, const VCT3DVECTOR& vtLs, const VCT3DVECTOR& vtLe, int nToolNum, int n5AxisType) { - // Controllo utensile + // Controllo utensile if ( m_nCurrTool < 0 || m_nCurrTool >= int( m_vTool.size())) return false ; Tool& CurrTool = m_vTool[m_nCurrTool] ; @@ -2319,7 +2329,7 @@ VolZmap::CylBall_5AxisMilling( int nGrid, const PNTVECTOR& ptS, const PNTVECTOR& double dRadius = CurrTool.GetRadius() ; CompCyl_5AxisMilling( nGrid, ptS, ptE, vtLs, vtLe, dHeight, dRadius, nToolNum, n5AxisType) ; - // devo poi togliere la sfera tip iniziale, la sfera tip finale e il cilindro del volume spazzato + // devo poi togliere la sfera tip iniziale, la sfera tip finale e il cilindro del volume spazzato Point3d ptTipS = ptS.front() - vtLs.front() * ( CurrTool.GetHeigth() ) ; Point3d ptTipE = ptE.back() - vtLe.back() * ( CurrTool.GetHeigth() ) ; CompBall_Milling( nGrid, ptTipS, ptTipE, CurrTool.GetRadius(), CurrTool.GetToolNum()) ; @@ -2331,16 +2341,16 @@ bool VolZmap::CompConus_5AxisMilling( int nGrid, const PNTVECTOR& ptS, const PNTVECTOR& ptE, const VCT3DVECTOR& vtLs, const VCT3DVECTOR& vtLe, double dHei, double dMaxRad, double dMinRad, bool bTapB, bool bTapT, const Vector3d& vtArcNormMaxR, const Vector3d& vtArcNormMinR, int nToolNum, int n5AxisType) { - // come per le altre funzioni che lavorano con i coni, se il cono è inverso ( che va allargandosi andando verso il fondo del tool), allora i vtL passati sono invertiti rispetto a quelli - // reali del tool e i punti ptS e ptE sono invertiti( così come dMaxRad e dMinRad) + // come per le altre funzioni che lavorano con i coni, se il cono è inverso ( che va allargandosi andando verso il fondo del tool), allora i vtL passati sono invertiti rispetto a quelli + // reali del tool e i punti ptS e ptE sono invertiti( così come dMaxRad e dMinRad) - // al momento i bool bTapB e bTapT vengono ignorati e di default si crea un volume chiuso con anche le superfici superiore e inferiore. + // al momento i bool bTapB e bTapT vengono ignorati e di default si crea un volume chiuso con anche le superfici superiore e inferiore. - // Controllo utensile + // Controllo utensile if ( m_nCurrTool < 0 || m_nCurrTool >= int( m_vTool.size())) return false ; - // tolgo il valume spazzato dal tool durante il movimento + // tolgo il valume spazzato dal tool durante il movimento return Comp_5AxisMilling( nGrid, ptS, ptE, vtLs, vtLe, dHei, dMaxRad, dMinRad, nToolNum, n5AxisType) ; } @@ -2348,10 +2358,10 @@ VolZmap::CompConus_5AxisMilling( int nGrid, const PNTVECTOR& ptS, const PNTVECTO bool VolZmap::Conus_5AxisMilling( int nGrid, const PNTVECTOR& ptS, const PNTVECTOR& ptE, const VCT3DVECTOR& vtLs, const VCT3DVECTOR& vtLe, int nToolNum, int n5AxisType) { - // Controllo utensile + // Controllo utensile if ( m_nCurrTool < 0 || m_nCurrTool >= int( m_vTool.size())) return false ; - // recupero le info del tool + // recupero le info del tool Tool& CurrTool = m_vTool[m_nCurrTool] ; double dHeight = CurrTool.GetHeigth() ; double dRadius = CurrTool.GetRadius() ; @@ -2359,10 +2369,10 @@ VolZmap::Conus_5AxisMilling( int nGrid, const PNTVECTOR& ptS, const PNTVECTOR& p double dStemHeigth = dHeight - CurrTool.GetTipHeigth() ; - // elimino la parte del volume spazzato dalla parte cilindrica del tool + // elimino la parte del volume spazzato dalla parte cilindrica del tool Cyl_5AxisMilling( nGrid, ptS, ptE, vtLs, vtLe, nToolNum, CurrTool.GetTipHeigth(), n5AxisType) ; - // elimino la parte spazzata dalla punta conica del tool + // elimino la parte spazzata dalla punta conica del tool if ( CurrTool.GetTipRadius() < dRadius) { // Trapano PNTVECTOR ptSConus( ptS.size()) ; @@ -2397,7 +2407,7 @@ VolZmap::Conus_5AxisMilling( int nGrid, const PNTVECTOR& ptS, const PNTVECTOR& p bool VolZmap::SelectGeneralMotion( int nGrid, const PNTVECTOR& ptPs, const PNTVECTOR& ptPe, const VCT3DVECTOR& vtLs, const VCT3DVECTOR& vtLe, int n5AxisType) { - // Controllo utensile + // Controllo utensile if ( m_nCurrTool < 0 || m_nCurrTool >= int( m_vTool.size())) return false ; Tool& CurrTool = m_vTool[m_nCurrTool] ; @@ -2425,38 +2435,78 @@ bool VolZmap::MillingGeneralMotionStep( const Point3d& ptPs, const Vector3d& vtDs, const Vector3d& vtAs, const Point3d& ptPe, const Vector3d& vtDe, const Vector3d& vtAe) { -#if false - #define OLD_LINEAR -#endif + // Flag per impostare vecchia (approssimativa) o nuova modalità di calcolo + constexpr bool OLD_LINEAR = true ; // Deve essere definito l'utensile corrente if ( m_nCurrTool < 0 || m_nCurrTool >= int( m_vTool.size())) return false ; + + // Angoli di rotazione longitudinale e trasversale massimi per singolo step + const double ANG_ALONG_STEP = 1.0 ; + const double ANG_ACROSS_STEP = ( OLD_LINEAR ? 0.04 : 1.0) ; + // Calcolo angoli di rotazione utensile longitudinale e trasversale rispetto al movimento per eventuale suddivisione double dAlongAngDeg, dAcrossAngDeg ; GetAlongAcrossRotation( vtDs, vtDe, ptPe - ptPs, dAlongAngDeg, dAcrossAngDeg) ; - // Divido il movimento in tratti con direzione utensile costante - // -#ifdef OLD_LINEAR - const double ANG_ACROSS_STEP = 0.04 ; -#else - const double ANG_ACROSS_STEP = 1 ; -#endif - const double ANG_ALONG_STEP = 1.0 ; + // Calcolo numero degli step di movimento int nStepCnt = int( max( { abs( dAlongAngDeg) / ANG_ALONG_STEP, abs( dAcrossAngDeg) / ANG_ACROSS_STEP, 1.})) ; + bool bOk = true ; + + // Divido il movimento in tratti lineari con direzione utensile costante (approssimazione a scaletta) + if ( OLD_LINEAR) { + // Calcolo coefficiente di riduzione movimenti con direzione costante per evitare extra tagli + double dToolLen = m_vTool[m_nCurrTool].GetHeigth() ; + double dToolCrad = m_vTool[m_nCurrTool].GetCornRadius() ; + Vector3d vtBase = ptPe - ptPs ; + double dBaseLen = vtBase.Len() ; + Vector3d vtTip = ptPe - dToolLen * vtDe - ( ptPs - dToolLen * vtDs) ; + double dTipLen = vtTip.Len() ; + double dK = ( vtBase * vtTip > EPS_SMALL ? dTipLen / dBaseLen : 0) ; + if ( dTipLen / nStepCnt < 0.1 * dToolCrad) + dK = 0 ; + for ( int i = 0 ; i <= nStepCnt && bOk ; ++ i) { + double dStCoeff, dEnCoeff, dDirCoeff ; + if ( i == 0) { + dStCoeff = 0 ; + dEnCoeff = dK / nStepCnt ; + dDirCoeff = 0 ; + } + else if ( i < nStepCnt) { + dStCoeff = ( i - dK) / nStepCnt ; + dEnCoeff = ( i + dK) / nStepCnt ; + dDirCoeff = double( i) / nStepCnt ; + } + else { + dStCoeff = ( nStepCnt - dK) / nStepCnt ; + dEnCoeff = 1 ; + dDirCoeff = 1 ; + } + Point3d ptSt = Media( ptPs, ptPe, dStCoeff) ; + Point3d ptEn = Media( ptPs, ptPe, dEnCoeff) ; + Vector3d vtD = Media( vtDs, vtDe, dDirCoeff) ; vtD.Normalize() ; + Vector3d vtA = Media( vtAs, vtAe, dDirCoeff) ; vtA.Normalize() ; + bOk = bOk && MillingTranslationStep( ptSt, ptEn, vtD, vtA) ; + } + // esco + return bOk ; + } + + // Divido il movimento in tratti lineari con direzione utensile variabile linearmente (approssimazione lineare) + + // Determino il tipo di movimento 5 assi Vector3d vtDir = ptPe - ptPs ; double dH = vtDir * vtDs ; double dHStep = abs( dH / nStepCnt) ; Tool& CurrTool = m_vTool[m_nCurrTool] ; double dRad = CurrTool.GetRadius() ; - bool bAcross = abs( dAcrossAngDeg) > EPS_SMALL ; + bool bAcross = ( abs( dAcrossAngDeg) > EPS_SMALL) ; bool bAcrossInters = false ; - - if( vtDe * vtDir < vtDs * vtDir) + if ( vtDe * vtDir < vtDs * vtDir) dAlongAngDeg *= -1 ; - bool bAlong = abs( dAlongAngDeg) > EPS_SMALL ; + bool bAlong = ( abs( dAlongAngDeg) > EPS_SMALL) ; bool bAlongInters = false ; if ( bAcross && bAlong) { Vector3d vtInters = vtDs ^ vtDe ; @@ -2470,152 +2520,97 @@ VolZmap::MillingGeneralMotionStep( const Point3d& ptPs, const Vector3d& vtDs, co } } else if ( bAcross) - bAcrossInters = dRad * sin( dAcrossAngDeg * DEGTORAD) > dHStep ; + bAcrossInters = ( dRad * sin( dAcrossAngDeg * DEGTORAD) > dHStep) ; else if ( bAlong) - bAlongInters = dRad * sin( abs( dAlongAngDeg) * DEGTORAD) > dHStep ; + bAlongInters = ( dRad * sin( abs( dAlongAngDeg) * DEGTORAD) > dHStep) ; - int n5AxisType = VolZmap::Move5Axis::NO_BASE_INTERS ; + int n5AxisType = Move5Axis::NO_BASE_INTERS ; if ( bAcross && bAlong && ( bAcrossInters || bAlongInters)) - n5AxisType = VolZmap::Move5Axis::ACROSS ; + n5AxisType = Move5Axis::ACROSS ; else if ( bAcross) { if ( bAcrossInters) - n5AxisType = VolZmap::Move5Axis::ACROSS ; + n5AxisType = Move5Axis::ACROSS ; else - n5AxisType = VolZmap::Move5Axis::NO_BASE_INTERS ; + n5AxisType = Move5Axis::NO_BASE_INTERS ; } else if ( bAlong) - n5AxisType = VolZmap::Move5Axis::NO_BASE_INTERS ; - - bool bOk = true ; - - //Divido il movimento in tratti con direzione utensile costante - - ////// debug - vecchia modalità -#ifdef OLD_LINEAR - // Calcolo coefficiente di riduzione movimenti con direzione costante per evitare extra tagli - //!!! In attesa dell'algoritmo esatto !!! - double dToolLen = m_vTool[m_nCurrTool].GetHeigth() ; - double dToolCrad = m_vTool[m_nCurrTool].GetCornRadius() ; - Vector3d vtBase = ptPe - ptPs ; - double dBaseLen = vtBase.Len() ; - Vector3d vtTip = ptPe - dToolLen * vtDe - ( ptPs - dToolLen * vtDs) ; - double dTipLen = vtTip.Len() ; - double dK = ( vtBase * vtTip > EPS_SMALL ? dTipLen / dBaseLen : 0) ; - if ( dTipLen / nStepCnt < 0.1 * dToolCrad) - dK = 0 ; - for ( int i = 0 ; i <= nStepCnt && bOk ; ++ i) { - double dStCoeff, dEnCoeff, dDirCoeff ; - if ( i == 0) { - dStCoeff = 0 ; - dEnCoeff = dK / nStepCnt ; - dDirCoeff = 0 ; - } - else if ( i < nStepCnt) { - dStCoeff = ( i - dK) / nStepCnt ; - dEnCoeff = ( i + dK) / nStepCnt ; - dDirCoeff = double( i) / nStepCnt ; - } - else { - dStCoeff = ( nStepCnt - dK) / nStepCnt ; - dEnCoeff = 1 ; - dDirCoeff = 1 ; - } - Point3d ptSt = Media( ptPs, ptPe, dStCoeff) ; - Point3d ptEn = Media( ptPs, ptPe, dEnCoeff) ; - Vector3d vtD = Media( vtDs, vtDe, dDirCoeff) ; vtD.Normalize() ; - Vector3d vtA = Media( vtAs, vtAe, dDirCoeff) ; vtA.Normalize() ; - bOk = bOk && MillingTranslationStep( ptSt, ptEn, vtD, vtA) ; - // aggiorno prossimo inizio - ptSt = ptEn ; - } - - return bOk ; -#endif - ////// 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. ; // annullo la sovrapposizione // debug - //BIPNTVECTOR vPntStep( nStepCnt) ; - //vector> vDirStep( nStepCnt) ; + n5AxisType = Move5Axis::NO_BASE_INTERS ; vector ptLs( nStepCnt) ; vector ptLe( nStepCnt) ; vector vtLs( nStepCnt) ; vector vtLe( nStepCnt) ; + // calcolo gli step (anticipo un poco gli inizi intermedi) for ( int i = 0 ; i < nStepCnt ; ++ 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) ; - dDirCoeffS = double( i) / (nStepCnt) ; - dPosCoeffE = double( i + 1) / (nStepCnt) ; - dDirCoeffE = double( i + 1) / (nStepCnt) ; - if ( i != 0) { - ptSti = Media( ptPs, ptPe, dPosCoeffS - dCorr) ; - vtDSi = Media( vtDs, vtDe, dDirCoeffS - dCorr) ; vtDSi.Normalize() ; - } - Point3d ptEni = Media( ptPs, ptPe, i != nStepCnt ? dPosCoeffE : (dPosCoeffE + dCorr)) ; - Vector3d vtDEi = Media( vtDs, vtDe, i != nStepCnt ? dDirCoeffE : (dPosCoeffE + dCorr)) ; vtDEi.Normalize() ; + double dCoeffS = max( ( i - 0.05) / nStepCnt, 0.) ; + double dCoeffE = min( ( i + 1.) / nStepCnt, 1.) ; + Point3d ptSti = Media( ptPs, ptPe, dCoeffS) ; + Vector3d vtDSi = Media( vtDs, vtDe, dCoeffS) ; vtDSi.Normalize() ; + Point3d ptEni = Media( ptPs, ptPe, dCoeffE) ; + Vector3d vtDEi = Media( vtDs, vtDe, dCoeffE) ; vtDEi.Normalize() ; InitializePointsAndVectors( ptSti, ptEni, vtDSi, vtDEi, ptLs[i], ptLe[i], vtLs[i], vtLe[i]) ; } -#ifdef _DEBUG - ///// decommentare solo per debug // versione a singolo thread - for( int j = 0 ; j < N_MAPS; ++j) { + // Standarda è multithread + constexpr bool MULTITHREAD = false ; + if ( MULTITHREAD) { + + // Ciclo sulle mappe + vector< future> vRes( m_nMapNum) ; + + vector ptLs_j( m_nMapNum) ; + vector ptLe_j( m_nMapNum) ; + vector vtLs_j( m_nMapNum) ; + vector vtLe_j( m_nMapNum) ; + for ( int j = 0 ; j < m_nMapNum ; ++j) { + ptLs_j[j].resize( nStepCnt) ; + ptLe_j[j].resize( nStepCnt) ; + vtLs_j[j].resize( nStepCnt) ; + vtLe_j[j].resize( nStepCnt) ; + for ( int k = 0 ; k < nStepCnt ; ++k) { + ptLs_j[j][k] = ptLs[k][j] ; + ptLe_j[j][k] = ptLe[k][j] ; + vtLs_j[j][k] = vtLs[k][j] ; + vtLe_j[j][k] = vtLe[k][j] ; + } + } + + for ( int j = 0 ; j < m_nMapNum ; ++ j) { + vRes[j] = async( launch::async, &VolZmap::SelectGeneralMotion, this, j, cref( ptLs_j[j]), cref( ptLe_j[j]), + cref( vtLs_j[j]), cref( vtLe_j[j]), n5AxisType) ; + } + + 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 ; + } + } + } + } + + // !!!! NON MULTITHREAD : SOLO PER DEBUG !!!! + else { + // Ciclo sulle mappe + for ( int j = 0 ; j < m_nMapNum ; ++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] ; + for ( int k = 0 ; k < nStepCnt ; ++k) { + ptLs_j[k] = ptLs[k][j] ; + ptLe_j[k] = ptLe[k][j] ; + vtLs_j[k] = vtLs[k][j] ; + vtLe_j[k] = vtLe[k][j] ; } - SelectGeneralMotion( j, ptLs_j, ptLe_j, vtLs_j,vtLe_j, n5AxisType) ; - } - ///// decommentare solo per debug -#else - - // Ciclo sulle mappe - vector< future> vRes ; - vRes.resize( m_nMapNum) ; - - vector ptLs_j( m_nMapNum) ; - vector ptLe_j( m_nMapNum) ; - vector vtLs_j( m_nMapNum) ; - vector vtLe_j( m_nMapNum) ; - for( int p = 0 ; p < m_nMapNum ; ++p) { - ptLs_j[p].resize(nStepCnt) ; - ptLe_j[p].resize(nStepCnt) ; - vtLs_j[p].resize(nStepCnt) ; - vtLe_j[p].resize(nStepCnt) ; - for ( int z = 0 ; z < nStepCnt ; ++z) { - ptLs_j[p][z] = ptLs[z][p] ; - ptLe_j[p][z] = ptLe[z][p] ; - vtLs_j[p][z] = vtLs[z][p] ; - vtLe_j[p][z] = vtLe[z][p] ; + bOk = SelectGeneralMotion( j, ptLs_j, ptLe_j, vtLs_j,vtLe_j, n5AxisType) && bOk ; } } - for ( int j = 0 ; j < m_nMapNum ; ++ j) { - vRes[j] = async( launch::async, &VolZmap::SelectGeneralMotion, this, j, cref( ptLs_j[j]), cref( ptLe_j[j]), cref( vtLs_j[j]), cref( vtLe_j[j]), n5AxisType) ; - } - 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 ; - } - } - } -#endif - return bOk ; } @@ -2623,37 +2618,44 @@ VolZmap::MillingGeneralMotionStep( const Point3d& ptPs, const Vector3d& vtDs, co bool VolZmap::MillingTranslationStep( const Point3d& ptPs, const Point3d& ptPe, const Vector3d& vtD, const Vector3d& vtA) { + // Assegno i dati per le diverse mappe di spilloni presenti Point3d ptLs[N_MAPS] ; Point3d ptLe[N_MAPS] ; Vector3d vtLs[N_MAPS] ; Vector3d vtALs[N_MAPS] ; InitializePointsAndVectors( ptPs, ptPe, vtD, vtA, ptLs, ptLe, vtLs, vtALs) ; - //// Ciclo sulle mappe (scommentare solo per DEBUG) - // { - // bool bOk = true ; - // for ( int i = 0 ; i < m_nMapNum ; ++ i) { - // bOk = SelectMotion( i, ptLs[i], ptLe[i], vtLs[i], vtALs[i]) && bOk ; - // } - // return true ; - // } - - // Ciclo sulle mappe - vector< future> vRes ; - vRes.resize( m_nMapNum) ; - for ( int i = 0 ; i < m_nMapNum ; ++ i) { - vRes[i] = async( launch::async, &VolZmap::SelectMotion, this, i, cref( ptLs[i]), cref( ptLe[i]), cref( vtLs[i]), cref( vtALs[i])) ; - } - bool bOk = true ; - int nTerminated = 0 ; - while ( nTerminated < m_nMapNum) { + + // Standarda è multithread + constexpr bool MULTITHREAD = true ; + if ( MULTITHREAD) { + // Ciclo sulle mappe + vector< future> vRes( m_nMapNum) ; for ( int i = 0 ; i < m_nMapNum ; ++ i) { - if ( vRes[i].valid() && vRes[i].wait_for( chrono::nanoseconds{ 1}) == future_status::ready) { - bOk = vRes[i].get() && bOk ; - ++ nTerminated ; + vRes[i] = async( launch::async, &VolZmap::SelectMotion, this, i, cref( ptLs[i]), cref( ptLe[i]), + cref( vtLs[i]), cref( vtALs[i])) ; + } + bool bOk = true ; + int nTerminated = 0 ; + while ( nTerminated < m_nMapNum) { + for ( int i = 0 ; i < m_nMapNum ; ++ i) { + if ( vRes[i].valid() && vRes[i].wait_for( chrono::nanoseconds{ 1}) == future_status::ready) { + bOk = vRes[i].get() && bOk ; + ++ nTerminated ; + } } } + return bOk ; + } + + // !!!! NON MULTITHREAD : SOLO PER DEBUG !!!! + else { + // Ciclo sulle mappe + bool bOk = true ; + for ( int i = 0 ; i < m_nMapNum ; ++ i) { + bOk = SelectMotion( i, ptLs[i], ptLe[i], vtLs[i], vtALs[i]) && bOk ; + } + return bOk ; } - return bOk ; } //---------------------------------------------------------------------------- @@ -2873,7 +2875,6 @@ VolZmap::SelectMotion( int nGrid, const Point3d& ptLs, const Point3d& ptLe, cons // ---------- VERSORE UTENSILE DIRETTO COME Z -------------------------------- - // ---------- Cilindro e sfera ----------------------------------------------- //---------------------------------------------------------------------------- bool