diff --git a/Frame3d.cpp b/Frame3d.cpp index 0216924..9024d15 100644 --- a/Frame3d.cpp +++ b/Frame3d.cpp @@ -37,6 +37,23 @@ Frame3d::Set( const Point3d& ptOrig, const Vector3d& vtDirX, ! m_vtVersZ.Normalize()) return false ; + // se ci sono errori molto piccoli di ortogonalità, li correggo + double dOrtXZ = m_vtVersX * m_vtVersZ ; + if ( dOrtXZ > EPS_ZERO && dOrtXZ < 10 * EPS_ZERO) { + m_vtVersX = OrthoCompo( m_vtVersX, m_vtVersZ) ; + m_vtVersX.Normalize() ; + } + double dOrtYX = m_vtVersY * m_vtVersX ; + if ( dOrtYX > EPS_ZERO && dOrtYX < 10 * EPS_ZERO) { + m_vtVersY = OrthoCompo( m_vtVersY, m_vtVersX) ; + m_vtVersY.Normalize() ; + } + double dOrtYZ = m_vtVersY * m_vtVersZ ; + if ( dOrtYZ > EPS_ZERO && dOrtYZ < 10 * EPS_ZERO) { + m_vtVersY = OrthoCompo( m_vtVersY, m_vtVersZ) ; + m_vtVersY.Normalize() ; + } + // verifica della ortogonalità dei versori e del senso destrorso if ( ! Verify()) return false ; diff --git a/Tool.cpp b/Tool.cpp index 0c4fd11..9ab58cf 100644 --- a/Tool.cpp +++ b/Tool.cpp @@ -583,34 +583,78 @@ Tool::SetChiselTool( const string& sToolName, double dH, double dW, double dTh, //---------------------------------------------------------------------------- bool -Tool::SetAdditiveTool( const std::string& sToolName, double dH, double dR, double dRC, int nToolNum) +Tool::SetAdditiveTool( const std::string& sToolName, double dH, double dR, double dRc, int nToolNum) { - // Impostazioni generali + // Impostazioni generali m_sName = sToolName ; m_nCurrentNum = nToolNum ; m_nType = UNDEF ; m_Outline.Clear() ; m_ArcLineApprox.Clear() ; - // verifica sulle minime dimensioni globali - if ( dH < EPS_SMALL || dR < EPS_SMALL || dRC < - EPS_SMALL) + // Verifica sulle dimensioni + if ( dH < 10 * EPS_SMALL || dR < 10 * EPS_SMALL || dRc < - EPS_SMALL || dR < dRc - EPS_SMALL) return false ; + // Assegnazione dati geometrici principali m_dHeight = dH ; m_dRadius = dR ; - m_dRCorner = dRC ; + m_dRCorner = min( dRc, dR) ; + if ( m_dRCorner < 10 * EPS_SMALL) + m_dRCorner = 0 ; m_dTipHeight = 0 ; m_dTipRadius = 0 ; m_dRefRadius = 0 ; m_dCutterHeight = dH ; - bool bToolDefined = true ; - - double dSquareCornerRadProj = m_dRCorner * m_dRCorner - 0.25 * m_dHeight * m_dHeight ; - // Utensile sfiancato - if ( dSquareCornerRadProj > 0) { + // Utensile cilindrico con eventuale raggio corner (al limite sferico) + if ( m_dRCorner <= m_dHeight / 2) { + // Se Cilindrico + if ( m_dRCorner < EPS_SMALL) { + // inizio + m_Outline.AddPoint( Point3d( 0, 0, 0)) ; + // segmento orizzontale in alto + m_Outline.AddLine( Point3d( m_dRadius, 0, 0)) ; + m_Outline.SetCurveTempProp( 0, 1, 1) ; + // segmento verticale + m_Outline.AddLine( Point3d( m_dRadius, -m_dHeight, 0)) ; + m_Outline.SetCurveTempProp( 1, 1, 1) ; + // segmento orizzontale in basso + m_Outline.AddLine( Point3d( 0, -m_dHeight, 0)) ; + m_Outline.SetCurveTempProp( 2, 1, 1) ; + } + // Generico + else { + // inizio + m_Outline.AddPoint( Point3d( 0, 0, 0)) ; + int nInd = -1 ; + // eventuale segmento orizzontale in alto + if ( m_Outline.AddLine( Point3d( m_dRadius - m_dRCorner, 0, 0))) + m_Outline.SetCurveTempProp( ++ nInd, 1, 1) ; + // raggio corner in alto + CurveArc cvArc ; + cvArc.SetC2P( Point3d( m_dRadius - m_dRCorner, -m_dRCorner, 0), Point3d( m_dRadius - m_dRCorner, 0, 0), Point3d( m_dRadius, -m_dRCorner, 0)) ; + m_Outline.AddCurve( cvArc, true, 2 * EPS_SMALL) ; + m_Outline.SetCurveTempProp( ++ nInd, 1, 1) ; + // eventuale segmento verticale + if ( m_Outline.AddLine( Point3d( m_dRadius, -m_dHeight + m_dRCorner, 0))) + m_Outline.SetCurveTempProp( ++ nInd, 1, 1) ; + // raggio corner in basso + cvArc.SetC2P( Point3d( m_dRadius - m_dRCorner, -m_dHeight + m_dRCorner, 0), Point3d( m_dRadius, -m_dHeight + m_dRCorner, 0), Point3d( m_dRadius - m_dRCorner, -m_dHeight, 0)) ; + m_Outline.AddCurve( cvArc, true, 2 * EPS_SMALL) ; + m_Outline.SetCurveTempProp( ++ nInd, 1, 1) ; + // eventuale segmento orizzontale in basso + if ( m_Outline.AddLine( Point3d( 0, -m_dHeight, 0))) + m_Outline.SetCurveTempProp( ++ nInd, 1, 1) ; + } + m_Outline.SetTempProp( 1, 1) ; + if ( ! SetGenTool( sToolName, &m_Outline, nToolNum)) + return false ; + } + // Utensile sfiancato + else { double dCenX = m_dRadius - m_dRCorner ; - double dCylRad = dCenX + sqrt( dSquareCornerRadProj) ; + double dCylRad = dCenX + sqrt( m_dRCorner * m_dRCorner - m_dHeight * m_dHeight / 4) ; // Utensile mal definito if ( dCylRad < EPS_SMALL) return false ; @@ -625,41 +669,10 @@ Tool::SetAdditiveTool( const std::string& sToolName, double dH, double dR, doubl m_Outline.AddLine( Point3d( 0, - m_dHeight, 0)) ; m_Outline.SetCurveTempProp( 2, 1, 1) ; m_Outline.SetTempProp( 1, 1) ; - bToolDefined = SetGenTool( sToolName, &m_Outline, nToolNum) ; - } - // Utensile cilindrico con eventuale raggio corner - else { - // Utensile mal definito - if ( m_dRadius - m_dRCorner < 0) + if ( ! SetGenTool( sToolName, &m_Outline, nToolNum)) return false ; - // Utensile sferico - else if ( m_dRadius - m_dRCorner < EPS_SMALL) - ; - // Raggio corner nullo: cilindro - else if ( m_dRCorner < EPS_SMALL) { - ; - } - else { - // Profilo - m_Outline.AddPoint( Point3d( 0, 0, 0)) ; - m_Outline.AddLine( Point3d( m_dRadius - m_dRCorner, 0, 0)) ; - m_Outline.SetCurveTempProp( 0, 1, 1) ; - CurveArc cvArc ; - cvArc.SetC2P( Point3d( m_dRadius - m_dRCorner, - m_dRCorner, 0), Point3d( m_dRadius - m_dRCorner, 0, 0), Point3d( m_dRadius, - m_dRCorner, 0)) ; - m_Outline.AddCurve( cvArc) ; - m_Outline.SetCurveTempProp( 1, 1, 1) ; - m_Outline.AddLine( Point3d( m_dRadius, - m_dHeight + m_dRCorner, 0)) ; - m_Outline.SetCurveTempProp( 2, 1, 1) ; - cvArc.SetC2P( Point3d( m_dRadius - m_dRCorner, - m_dHeight + m_dRCorner, 0), Point3d( m_dRadius, - m_dHeight + m_dRCorner, 0), Point3d( m_dRadius - m_dRCorner, - m_dHeight, 0)) ; - m_Outline.AddCurve( cvArc) ; - m_Outline.SetCurveTempProp( 3, 1, 1) ; - m_Outline.AddLine( Point3d( 0, - m_dHeight, 0)) ; - m_Outline.SetCurveTempProp( 4, 1, 1) ; - m_Outline.SetTempProp( 1, 1) ; - bToolDefined = SetGenTool( sToolName, &m_Outline, nToolNum) ; - } - } + } m_nType = ADDITIVE ; - return bToolDefined ; -} \ No newline at end of file + return true ; +} diff --git a/Tool.h b/Tool.h index 5180e4b..6b0e43e 100644 --- a/Tool.h +++ b/Tool.h @@ -33,7 +33,7 @@ class Tool bool SetGenTool( const std::string& sToolName, const ICurveComposite* pToolOutline, int nToolNum) ; bool SetMortiserTool( const std::string& sToolName, double dH, double dW, double dTh, double dRc, int nToolNum) ; bool SetChiselTool( const std::string& sToolName, double dH, double dW, double dTh, int nToolNum) ; - bool SetAdditiveTool( const std::string& sToolName, double dH, double dR, double dRC, int nToolNum) ; + bool SetAdditiveTool( const std::string& sToolName, double dH, double dR, double dRc, int nToolNum) ; bool SetToolNum( int nToolNum) { m_nCurrentNum = nToolNum ; return true ; } int GetType() const diff --git a/VolZmap.cpp b/VolZmap.cpp index bb0dd5e..cb1b028 100644 --- a/VolZmap.cpp +++ b/VolZmap.cpp @@ -49,7 +49,6 @@ VolZmap::VolZmap(void) m_nFracLin[i] = 0 ; } m_vTool.resize( 1) ; - m_nCurrTool = 0 ; } //---------------------------------------------------------------------------- @@ -2175,7 +2174,7 @@ VolZmap::SetChiselTool( const string& sToolName, double dH, double dW, double dT //---------------------------------------------------------------------------- bool VolZmap::SetAdditiveTool( const std::string& sToolName, - double dH, double dR, double dRC, int nFlag, bool bFirst) + double dH, double dR, double dRc, int nFlag, bool bFirst) { if ( bFirst) { m_vTool.resize( 1) ; @@ -2187,10 +2186,9 @@ VolZmap::SetAdditiveTool( const std::string& sToolName, if ( m_nCurrTool < 0) return false ; m_vTool[m_nCurrTool].SetTolerances( m_dToolLinTol, m_dToolAngTolDeg) ; - return m_vTool[m_nCurrTool].SetAdditiveTool( sToolName, dH, dR, dRC, nFlag) ; + return m_vTool[m_nCurrTool].SetAdditiveTool( sToolName, dH, dR, dRc, nFlag) ; } - //---------------------------------------------------------------------------- int VolZmap::GetToolCount( void) const diff --git a/VolZmap.h b/VolZmap.h index b1c6619..85034ef 100644 --- a/VolZmap.h +++ b/VolZmap.h @@ -1,7 +1,7 @@ //---------------------------------------------------------------------------- -// EgalTech 2015-2023 +// EgalTech 2015-2024 //---------------------------------------------------------------------------- -// File : VolZmap.h Data : 12.09.23 Versione : 2.5i1 +// File : VolZmap.h Data : 22.04.24 Versione : 2.6d4 // Contenuto : Dichiarazione della classe Volume Zmap. // // @@ -78,7 +78,7 @@ class VolZmap : public IVolZmap, public IGeoObjRW bool CopyFrom( const IGeoObj* pGObjSrc) override ; bool Clear( void) override ; bool Create( const Point3d& ptO, double dDimX, double dDimY, double dDimZ, double dStep, bool bTriDex) override ; - bool CreateEmptyMap( const Point3d& ptO, double dLengthX, double dLengthY, double dLengthZ, double dStep, bool bTriDex) override ; + bool CreateEmpty( const Point3d& ptO, double dDimX, double dDimY, double dDimZ, double dStep, bool bTriDex) override ; bool CreateFromFlatRegion( const ISurfFlatRegion& Surf, double dDimZ, double dStep, bool bTriDex) override ; bool CreateFromTriMesh( const ISurfTriMesh& Surf, double dStep, bool bTriDex) override ; int GetBlockCount( void) const override ; @@ -111,7 +111,7 @@ class VolZmap : public IVolZmap, public IGeoObjRW bool SetChiselTool( const std::string& sToolName, double dH, double dW, double dTh, int nFlag, bool bFirst) override ; bool SetAdditiveTool( const std::string& sToolName, - double dH, double dR, double dRC, int nFlag, bool bFirst) override ; + double dH, double dR, double dRc, int nFlag, bool bFirst) override ; int GetToolCount( void) const override ; bool SetCurrTool( int nCurrTool) override ; bool ResetTools( void) override ; diff --git a/VolZmapCreation.cpp b/VolZmapCreation.cpp index 4158804..a6a9d6a 100644 --- a/VolZmapCreation.cpp +++ b/VolZmapCreation.cpp @@ -1,4 +1,4 @@ -//---------------------------------------------------------------------------- +//---------------------------------------------------------------------------- // EgalTech 2015-2016 //---------------------------------------------------------------------------- // File : VolZmap.cpp Data : 22.01.15 Versione : 1.6a4 @@ -27,10 +27,10 @@ using namespace std ; //---------------------------------------------------------------------------- bool -VolZmap::Create( const Point3d& ptO, double dLengthX, double dLengthY, double dLengthZ, double dStep, bool bTriDex) +VolZmap::Create( const Point3d& ptO, double dDimX, double dDimY, double dDimZ, double dStep, bool bTriDex) { // Controlli sull'ammissibilità delle dimensioni lineari del grezzo e del passo - if ( dStep < EPS_SMALL || dLengthX < EPS_SMALL || dLengthY < EPS_SMALL || dLengthZ < EPS_SMALL) + if ( dStep < EPS_SMALL || dDimX < EPS_SMALL || dDimY < EPS_SMALL || dDimZ < EPS_SMALL) return false ; // Il passo di discretizzazione non può essere inferiore a 100 * EPS_SMALL @@ -47,8 +47,8 @@ VolZmap::Create( const Point3d& ptO, double dLengthX, double dLengthY, double dL m_MapFrame.Set( ptO, X_AX, Y_AX, Z_AX) ; // Definisco i vettori dei limiti su indici - m_nNx[0] = max( int( ( dLengthX + EPS_SMALL) / m_dStep + 0.5), 1) ; - m_nNy[0] = max( int( ( dLengthY + EPS_SMALL) / m_dStep + 0.5), 1) ; + m_nNx[0] = max( int( ( dDimX + EPS_SMALL) / m_dStep + 0.5), 1) ; + m_nNy[0] = max( int( ( dDimY + EPS_SMALL) / m_dStep + 0.5), 1) ; // Numero di componenti connesse m_nConnectedCompoCount = 1 ; @@ -56,7 +56,7 @@ VolZmap::Create( const Point3d& ptO, double dLengthX, double dLengthY, double dL // Se tridexel if ( bTriDex) { m_nNx[1] = m_nNy[0] ; - m_nNy[1] = max( int( ( dLengthZ + EPS_SMALL) / m_dStep + 0.5), 1) ; + m_nNy[1] = max( int( ( dDimZ + EPS_SMALL) / m_dStep + 0.5), 1) ; m_nNx[2] = m_nNy[1] ; m_nNy[2] = m_nNx[0] ; } @@ -97,19 +97,19 @@ VolZmap::Create( const Point3d& ptO, double dLengthX, double dLengthY, double dL switch ( i) { case 0 : m_Values[i][j][0].vtMinN = - Z_AX ; - m_Values[i][j][0].dMax = dLengthZ ; + m_Values[i][j][0].dMax = dDimZ ; m_Values[i][j][0].vtMaxN = Z_AX ; m_Values[i][j][0].nToolMax = 0 ; break ; case 1 : m_Values[i][j][0].vtMinN = - X_AX ; - m_Values[i][j][0].dMax = dLengthX ; + m_Values[i][j][0].dMax = dDimX ; m_Values[i][j][0].vtMaxN = X_AX ; m_Values[i][j][0].nToolMax = 0 ; break ; case 2 : m_Values[i][j][0].vtMinN = - Y_AX ; - m_Values[i][j][0].dMax = dLengthY ; + m_Values[i][j][0].dMax = dDimY ; m_Values[i][j][0].vtMaxN = Y_AX ; m_Values[i][j][0].nToolMax = 0 ; break ; @@ -118,11 +118,11 @@ VolZmap::Create( const Point3d& ptO, double dLengthX, double dLengthY, double dL // Definizione delle limitazioni iniziali in Z per ogni mappa m_dMinZ[0] = 0 ; - m_dMaxZ[0] = dLengthZ ; + m_dMaxZ[0] = dDimZ ; m_dMinZ[1] = 0 ; - m_dMaxZ[1] = ( bTriDex ? dLengthX : 0) ; + m_dMaxZ[1] = ( bTriDex ? dDimX : 0) ; m_dMinZ[2] = 0 ; - m_dMaxZ[2] = ( bTriDex ? dLengthY : 0) ; + m_dMaxZ[2] = ( bTriDex ? dDimY : 0) ; // Tipologia m_nShape = BOX ; @@ -135,13 +135,13 @@ VolZmap::Create( const Point3d& ptO, double dLengthX, double dLengthY, double dL //---------------------------------------------------------------------------- bool -VolZmap::CreateEmptyMap( const Point3d& ptO, double dLengthX, double dLengthY, double dLengthZ, double dStep, bool bTriDex) +VolZmap::CreateEmpty( const Point3d& ptO, double dDimX, double dDimY, double dDimZ, double dStep, bool bTriDex) { - // Controlli sull'ammissibilit� delle dimensioni lineari del grezzo e del passo - if ( dStep < EPS_SMALL || dLengthX < EPS_SMALL || dLengthY < EPS_SMALL || dLengthZ < EPS_SMALL) + // Controlli sull'ammissibilità delle dimensioni lineari del grezzo e del passo + if ( dStep < EPS_SMALL || dDimX < EPS_SMALL || dDimY < EPS_SMALL || dDimZ < EPS_SMALL) return false ; - // Il passo di discretizzazione non pu� essere inferiore a 100 * EPS_SMALL + // Il passo di discretizzazione non può essere inferiore a 100 * EPS_SMALL m_dStep = max( dStep, 100 * EPS_SMALL) ; // Aggiorno la dimensione della mappa 1 o 3 @@ -155,8 +155,8 @@ VolZmap::CreateEmptyMap( const Point3d& ptO, double dLengthX, double dLengthY, d m_MapFrame.Set( ptO, X_AX, Y_AX, Z_AX) ; // Definisco i vettori dei limiti su indici - m_nNx[0] = max( int( ( dLengthX + EPS_SMALL) / m_dStep + 0.5), 1) ; - m_nNy[0] = max( int( ( dLengthY + EPS_SMALL) / m_dStep + 0.5), 1) ; + m_nNx[0] = max( int( ( dDimX + EPS_SMALL) / m_dStep + 0.5), 1) ; + m_nNy[0] = max( int( ( dDimY + EPS_SMALL) / m_dStep + 0.5), 1) ; // Numero di componenti connesse m_nConnectedCompoCount = 1 ; @@ -164,7 +164,7 @@ VolZmap::CreateEmptyMap( const Point3d& ptO, double dLengthX, double dLengthY, d // Se tridexel if ( bTriDex) { m_nNx[1] = m_nNy[0] ; - m_nNy[1] = max( int( ( dLengthZ + EPS_SMALL) / m_dStep + 0.5), 1) ; + m_nNy[1] = max( int( ( dDimZ + EPS_SMALL) / m_dStep + 0.5), 1) ; m_nNx[2] = m_nNy[1] ; m_nNy[2] = m_nNx[0] ; } @@ -192,11 +192,11 @@ VolZmap::CreateEmptyMap( const Point3d& ptO, double dLengthX, double dLengthY, d // Definizione delle limitazioni iniziali in Z per ogni mappa m_dMinZ[0] = 0 ; - m_dMaxZ[0] = dLengthZ ; + m_dMaxZ[0] = dDimZ ; m_dMinZ[1] = 0 ; - m_dMaxZ[1] = ( bTriDex ? dLengthX : 0) ; + m_dMaxZ[1] = ( bTriDex ? dDimX : 0) ; m_dMinZ[2] = 0 ; - m_dMaxZ[2] = ( bTriDex ? dLengthY : 0) ; + m_dMaxZ[2] = ( bTriDex ? dDimY : 0) ; // Tipologia m_nShape = GENERIC ; diff --git a/VolZmapVolume.cpp b/VolZmapVolume.cpp index b5726c0..03f5561 100644 --- a/VolZmapVolume.cpp +++ b/VolZmapVolume.cpp @@ -253,12 +253,12 @@ VolZmap::AddIntervals( int nGrid, int nI, int nJ, double dMin, double dMax, const Vector3d& vtNMin, const Vector3d& vtNMax, int nToolNum) { // Controllo che il numero di griglia sia entro i limiti - if ( nGrid < 0 || nGrid > 2) + if ( nGrid < 0 || nGrid > 2) return false ; - // Controllo che indici nI, nJ siano entro i limiti - if ( nI < 0 && nI >= m_nNx[nGrid] && - nJ < 0 && nJ >= m_nNy[nGrid]) + // Controllo che indici nI, nJ siano entro i limiti + if ( nI < 0 && nI >= m_nNx[nGrid] && + nJ < 0 && nJ >= m_nNy[nGrid]) return false ; // Controllo che dMin < dMax @@ -287,7 +287,7 @@ VolZmap::AddIntervals( int nGrid, int nI, int nJ, vtNma = Z_AX ; } - // Controllo che dMin e dMax non siano quasi coincidenti + // Controllo che dMin e dMax non siano quasi coincidenti if ( abs( dMax - dMin) < EPS_SMALL) return true ; @@ -306,13 +306,13 @@ VolZmap::AddIntervals( int nGrid, int nI, int nJ, } // Calcolo nPos - unsigned int nPos = nJ * m_nNx[nGrid] + nI ; + int nPos = nJ * m_nNx[nGrid] + nI ; vector& vDexel = m_Values[nGrid][nPos] ; bool bModified = false ; - // Non esistono segmenti - if ( int( vDexel.size()) == 0) { + // Non esistono segmenti + if ( vDexel.empty()) { vDexel.emplace_back() ; vDexel.back().dMin = dMin ; @@ -326,10 +326,10 @@ VolZmap::AddIntervals( int nGrid, int nI, int nJ, bModified = true ; } - // Esiste almeno un segmento + // Esiste almeno un segmento else { - // Cerco l'ultimo intervallo a sinistra e l'ultimo intervallo a destra - // di quello da aggiungere, che non interferiscono con quest'ultimo. + // Cerco l'ultimo intervallo a sinistra e l'ultimo intervallo a destra + // di quello da aggiungere, che non interferiscono con quest'ultimo. auto itLastLeft = vDexel.end() ; auto itFirstRight = vDexel.end() ; for ( auto it = vDexel.begin() ; it != vDexel.end() ; ++ it) { @@ -338,12 +338,12 @@ VolZmap::AddIntervals( int nGrid, int nI, int nJ, if ( dMax < it->dMin - EPS_SMALL && itFirstRight == vDexel.end()) itFirstRight = it ; } - // Esistono intervalli a sinistra. + // Esistono intervalli a sinistra. if ( itLastLeft != vDexel.end()) { - // Intervallo successivo all'ultimo a sinistra + // Intervallo successivo all'ultimo a sinistra auto itNextToLastLeft = itLastLeft ; ++ itNextToLastLeft ; - // Il successivo non esiste. + // Il successivo non esiste. if ( itNextToLastLeft == vDexel.end()) { // Aggiungo il nuovo semgento vDexel.emplace_back() ; @@ -356,11 +356,11 @@ VolZmap::AddIntervals( int nGrid, int nI, int nJ, //m_Values[nGrid][nPos].back().nCompo = ; bModified = true ; } - // Il successivo esiste. + // Il successivo esiste. else { - // Il successivo è il primo a destra. + // Il successivo è il primo a destra. if ( itNextToLastLeft == itFirstRight) { - // Inserisco nuovo segmento- + // Inserisco nuovo segmento- Data NewSegment ; NewSegment.dMin = dMin ; NewSegment.dMax = dMax ; @@ -373,18 +373,18 @@ VolZmap::AddIntervals( int nGrid, int nI, int nJ, bModified = true ; } else { - // Il successivo non esce a sinistra da quello da aggiungere. + // Il successivo non esce a sinistra da quello da aggiungere. if ( itNextToLastLeft->dMin > dMin + EPS_SMALL) { itNextToLastLeft->dMin = dMin ; itNextToLastLeft->vtMinN = vtNmi ; itNextToLastLeft->nToolMin = nToolNum ; } - // Cerco l'ultimo segmento che interferisce con quello da aggiungere. + // Cerco l'ultimo segmento che interferisce con quello da aggiungere. auto itPrevToFirstRight = vDexel.end() ; for ( auto it = itNextToLastLeft ; it != itFirstRight ; ++ it) { itPrevToFirstRight = it ; } - // L'ultimo che interferisce non esce a destra da quello da aggiungere. + // L'ultimo che interferisce non esce a destra da quello da aggiungere. if ( itPrevToFirstRight->dMax < dMax - EPS_SMALL) { itNextToLastLeft->dMax = dMax ; itNextToLastLeft->vtMaxN = vtNma ; @@ -403,18 +403,18 @@ VolZmap::AddIntervals( int nGrid, int nI, int nJ, } } } - // Non esistono neanche a destra. + // Non esistono neanche a destra. else if ( itFirstRight == m_Values[nGrid][nPos].end()) { - // Il primo intervallo non sporge a sinistra + // Il primo intervallo non sporge a sinistra if ( vDexel.begin()->dMin > dMin + EPS_SMALL) { vDexel.begin()->dMin = dMin ; vDexel.begin()->vtMinN = vtNmi ; vDexel.begin()->nToolMin = nToolNum ; bModified = true ; } - // L'ultimo intervallo sporge a destra. + // L'ultimo intervallo sporge a destra. if ( m_Values[nGrid][nPos].back().dMax > dMax + EPS_SMALL) { - // Ci sono più segmenti, inglobo tutti nel primo. + // Ci sono più segmenti, inglobo tutti nel primo. if ( vDexel.back().dMax > vDexel.begin()->dMax + EPS_SMALL) { vDexel.begin()->dMax = vDexel.back().dMax ; vDexel.begin()->vtMaxN = vDexel.back().vtMaxN ; @@ -422,7 +422,7 @@ VolZmap::AddIntervals( int nGrid, int nI, int nJ, bModified = true ; } } - // L'ultimo intervallo non sporge a destra. + // L'ultimo intervallo non sporge a destra. else { vDexel.begin()->dMax = dMax ; vDexel.begin()->vtMaxN = vtNma ; @@ -431,11 +431,11 @@ VolZmap::AddIntervals( int nGrid, int nI, int nJ, } vDexel.erase( vDexel.begin() + 1, vDexel.end()) ; } - // A destra esistono. + // A destra esistono. else { - // Tutti i segmenti sono a destra di qullo da aggiungere. + // Tutti i segmenti sono a destra di qullo da aggiungere. if ( itFirstRight == vDexel.begin()) { - // Inserisco nuovo segmento- + // Inserisco nuovo segmento- Data NewSegment ; NewSegment.dMin = dMin ; NewSegment.dMax = dMax ; @@ -447,19 +447,19 @@ VolZmap::AddIntervals( int nGrid, int nI, int nJ, bModified = true ; } else { - // Se il primo segmento non esce a sinistra da quello da aggiungere, cambio l'inizio. + // Se il primo segmento non esce a sinistra da quello da aggiungere, cambio l'inizio. if ( vDexel.begin()->dMin > dMin + EPS_SMALL) { vDexel.begin()->dMin = dMin ; vDexel.begin()->vtMinN = vtNmi ; vDexel.begin()->nToolMin = nToolNum ; bModified = true ; } - // Cerco l'ultimo segmento che interferisce con quello da aggiungere. + // Cerco l'ultimo segmento che interferisce con quello da aggiungere. auto itPrevToFirstRight = vDexel.begin() ; for ( auto it = m_Values[nGrid][nPos].begin() ; it != itFirstRight ; ++ it) { itPrevToFirstRight = it ; } - // L'ultimo che interferisce non esce a destra da quello da aggiungere. + // L'ultimo che interferisce non esce a destra da quello da aggiungere. if ( itPrevToFirstRight->dMax < dMax - EPS_SMALL) { vDexel.begin()->dMax = dMax ; vDexel.begin()->vtMaxN = vtNma ; @@ -479,24 +479,24 @@ VolZmap::AddIntervals( int nGrid, int nI, int nJ, } } - // Se nessuna modifica, esco + // Se nessuna modifica, esco if ( ! bModified) return true ; - // Imposto ricalcolo della grafica + // Imposto ricalcolo della grafica m_OGrMgr.Reset() ; - // Imposto forma generica + // Imposto forma generica m_nShape = GENERIC ; - // Imposto ricalcolo numero di componenti connesse + // Imposto ricalcolo numero di componenti connesse m_nConnectedCompoCount = - 1 ; - // Passo da indici di dexel a indici di voxel + // Passo da indici di dexel a indici di voxel nI /= m_nDexVoxRatio ; nJ /= m_nDexVoxRatio ; - // Determino quali blocchi sono stati modificati + // Determino quali blocchi sono stati modificati if ( nGrid == 0) { - // Voxel lungo X + // Voxel lungo X int nXStop = 1 ; int nXBlock[2] ; nXBlock[0] = min( nI / m_nVoxNumPerBlock, m_nFracLin[0] - 1) ; @@ -504,7 +504,7 @@ VolZmap::AddIntervals( int nGrid, int nI, int nJ, nXBlock[1] = nXBlock[0] - 1 ; ++ nXStop ; } - // Voxel lungo Y + // Voxel lungo Y int nYStop = 1 ; int nYBlock[2] ; nYBlock[0] = min( nJ / m_nVoxNumPerBlock, m_nFracLin[1] - 1) ; @@ -512,13 +512,13 @@ VolZmap::AddIntervals( int nGrid, int nI, int nJ, nYBlock[1] = nYBlock[0] - 1 ; ++ nYStop ; } - // Voxel lungo Z + // Voxel lungo Z int nVoxNumZ = int( m_nNy[1] / m_nDexVoxRatio + ( m_nNy[1] % m_nDexVoxRatio == 0 ? 1 : 2)) ; int nMinK = Clamp( int( floor( ( ( dMin - 0.5 * m_dStep) / ( m_nDexVoxRatio * m_dStep) - EPS_SMALL))), 0, nVoxNumZ - 2) ; int nMaxK = Clamp( int( floor( ( ( dMax + 0.5 * m_dStep) / ( m_nDexVoxRatio * m_dStep) + EPS_SMALL))), 0, nVoxNumZ - 2) ; int nMinZBlock = ( m_nMapNum == 1 ? 0 : Clamp( nMinK / int( m_nVoxNumPerBlock), 0, int( m_nFracLin[2] - 1))) ; int nMaxZBlock = min( int( m_nFracLin[2] - 1), nMaxK / int( m_nVoxNumPerBlock)) ; - // Assegno flag ai voxel + // Assegno flag ai voxel for ( int tI = 0 ; tI < nXStop ; ++ tI) { for ( int tJ = 0 ; tJ < nYStop ; ++ tJ) { for ( int k = nMinZBlock ; k <= nMaxZBlock ; ++ k) { @@ -530,7 +530,7 @@ VolZmap::AddIntervals( int nGrid, int nI, int nJ, } else if ( nGrid == 1) { - // Voxel lungo Y + // Voxel lungo Y int nYStop = 1 ; int nYBlock[2] ; nYBlock[0] = min( nI / m_nVoxNumPerBlock, m_nFracLin[1] - 1) ; @@ -538,7 +538,7 @@ VolZmap::AddIntervals( int nGrid, int nI, int nJ, nYBlock[1] = nYBlock[0] - 1 ; ++ nYStop ; } - // Voxel lungo Z + // Voxel lungo Z int nZStop = 1 ; int nZBlock[2] ; nZBlock[0] = min( nJ / m_nVoxNumPerBlock, m_nFracLin[2] - 1) ; @@ -546,13 +546,13 @@ VolZmap::AddIntervals( int nGrid, int nI, int nJ, nZBlock[1] = nZBlock[0] - 1 ; ++ nZStop ; } - // Voxel lungo X + // Voxel lungo X int nVoxNumX = int( m_nNx[0] / m_nDexVoxRatio + ( m_nNx[0] % m_nDexVoxRatio == 0 ? 1 : 2)) ; int nMinI = Clamp( int( floor( ( ( dMin - 0.5 * m_dStep) / ( m_nDexVoxRatio * m_dStep) - EPS_SMALL))), 0, nVoxNumX - 2) ; int nMaxI = Clamp( int( floor( ( ( dMax + 0.5 * m_dStep) / ( m_nDexVoxRatio * m_dStep) + EPS_SMALL))), 0, nVoxNumX - 2) ; int nMinXBlock = Clamp( nMinI / int( m_nVoxNumPerBlock), 0, int( m_nFracLin[0] - 1)) ; int nMaxXBlock = min( int( m_nFracLin[0] - 1), nMaxI / int( m_nVoxNumPerBlock)) ; - // Assegno flag ai voxel + // Assegno flag ai voxel for ( int tI = 0 ; tI < nYStop ; ++ tI) { for ( int tJ = 0 ; tJ < nZStop ; ++ tJ) { for ( int k = nMinXBlock ; k <= nMaxXBlock ; ++ k) { @@ -564,7 +564,7 @@ VolZmap::AddIntervals( int nGrid, int nI, int nJ, } else if ( nGrid == 2) { - // Voxel lungo X + // Voxel lungo X int nXStop = 1 ; int nXBlock[2] ; nXBlock[0] = min( nJ / m_nVoxNumPerBlock, m_nFracLin[0] - 1) ; @@ -572,7 +572,7 @@ VolZmap::AddIntervals( int nGrid, int nI, int nJ, nXBlock[1] = nXBlock[0] - 1 ; ++ nXStop ; } - // Voxel lungo Z + // Voxel lungo Z int nZStop = 1 ; int nZBlock[2] ; nZBlock[0] = min( nI / m_nVoxNumPerBlock, m_nFracLin[2] - 1) ; @@ -580,13 +580,13 @@ VolZmap::AddIntervals( int nGrid, int nI, int nJ, nZBlock[1] = nZBlock[0] - 1 ; ++ nZStop ; } - // Voxel lungo Y + // Voxel lungo Y int nVoxNumY = int( m_nNy[0] / m_nDexVoxRatio + ( m_nNy[0] % m_nDexVoxRatio == 0 ? 1 : 2)) ; int nMinJ = Clamp( int( floor( ( ( dMin - 0.5 * m_dStep) / ( m_nDexVoxRatio * m_dStep) - EPS_SMALL))), 0, nVoxNumY - 2) ; int nMaxJ = Clamp( int( floor( ( ( dMax + 0.5 * m_dStep) / ( m_nDexVoxRatio * m_dStep) + EPS_SMALL))), 0, nVoxNumY - 2) ; int nMinYBlock = Clamp( nMinJ / int( m_nVoxNumPerBlock), 0, int( m_nFracLin[1] - 1)) ; int nMaxYBlock = min( int( m_nFracLin[1] - 1), nMaxJ / int( m_nVoxNumPerBlock)) ; - // Assegno flag ai voxel + // Assegno flag ai voxel for ( int tI = 0 ; tI < nZStop ; ++ tI) { for ( int tJ = 0 ; tJ < nXStop ; ++ tJ) { for ( int k = nMinYBlock ; k <= nMaxYBlock ; ++ k) { @@ -638,9 +638,6 @@ VolZmap::MillingStep( int nCurrTool, return false ; } - // Reset numero di parti - m_nConnectedCompoCount = - 1 ; - // Punti e vettori descriventi il moto nel sistema intrinseco dello Zmap Point3d ptPLs = GetToLoc( ptPs, m_MapFrame) ; Point3d ptPLe = GetToLoc( ptPe, m_MapFrame) ; @@ -837,6 +834,8 @@ VolZmap::SelectMotion( int nGrid, const Point3d& ptLs, const Point3d& ptLe, cons return Conus_ZMilling( nGrid, ptLs, ptLe, vtL) ; case Tool::MORTISER : return Mrt_Milling( nGrid, ptLs, ptLe, vtL, vtAL) ; + case Tool::ADDITIVE : + return AddingMotion( nGrid, ptLs, ptLe, vtL) ; } } } @@ -899,6 +898,8 @@ VolZmap::SelectMotion( int nGrid, const Point3d& ptLs, const Point3d& ptLe, cons return Conus_XYMilling( nGrid, ptLs, ptLe, vtL) ; case Tool::MORTISER : return Mrt_Milling( nGrid, ptLs, ptLe, vtL, vtAL) ; + case Tool::ADDITIVE : + return AddingMotion( nGrid, ptLs, ptLe, vtL) ; } } } @@ -945,6 +946,8 @@ VolZmap::SelectMotion( int nGrid, const Point3d& ptLs, const Point3d& ptLe, cons if ( dSqLLong < EPS_SMALL * EPS_SMALL) return Chs_Milling( nGrid, ptLs, ptLe, vtL, vtAL) ; break ; + case Tool::ADDITIVE : + return AddingMotion( nGrid, ptLs, ptLe, vtL) ; } } } @@ -4942,29 +4945,27 @@ VolZmap::CompBall_Milling( int nGrid, const Point3d& ptLs, const Point3d& ptLe, bool VolZmap::AddingMotion( int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtAx) { - // Dimensioni lineari dell'utensile + // Dimensioni lineari dell'utensile double dHei = m_vTool[m_nCurrTool].GetHeigth() ; double dRad = m_vTool[m_nCurrTool].GetRadius() ; double dCornerRad = m_vTool[m_nCurrTool].GetCornRadius() ; - // Utensile sfiancato + // Utensile sfiancato if ( dCornerRad * dCornerRad - 0.25 * dHei * dHei > 0) { - AddingGeneral( nGrid, ptS, ptE, vtAx) ; + return AddingGeneral( nGrid, ptS, ptE, vtAx) ; } - // Utensile sferico + // Utensile sferico else if ( dRad - dCornerRad < EPS_SMALL) { - AddingSphere( nGrid, ptS - dRad * vtAx, ptE - dRad * vtAx, dRad) ; + return AddingSphere( nGrid, ptS - dRad * vtAx, ptE - dRad * vtAx, dRad) ; } - // Utensile cilindro + // Utensile cilindro else if ( dCornerRad < EPS_SMALL) { - AddingCylinder( nGrid, ptS, ptE, vtAx, dHei, dRad) ; + return AddingCylinder( nGrid, ptS, ptE, vtAx, dHei, dRad) ; } - // Utensile naso di toro + // Utensile naso di toro else { - AddingGeneral( nGrid, ptS, ptE, vtAx) ; + return AddingGeneral( nGrid, ptS, ptE, vtAx) ; } - - return true ; } //---------------------------------------------------------------------------- @@ -5064,57 +5065,37 @@ VolZmap::AddingCylinder( int nGrid, const Point3d& ptS, const Point3d& ptE, cons double dLen1 = vtV1.Len() ; vtV1 /= dLen1 ; - if ( nGrid == 0) { + double dMyTol = 0 ; + Frame3d CylFrame, PolyFrame ; + if ( ! CylFrame.Set( ptS - dHei * vtAx, vtAx)) + return false ; + if ( ! PolyFrame.Set( ptS - ( dHei + dMyTol) * vtAx, vtAx, vtV1)) + return false ; + for ( int i = nStartI ; i <= nEndI ; ++ i) { + for ( int j = nStartJ ; j <= nEndJ ; ++ j) { + + Point3d ptC( ( i + 0.5) * m_dStep, ( j + 0.5) * m_dStep, 0) ; + + Point3d ptInt1, ptInt2 ; + Vector3d vtN1, vtN2 ; - Vector3d vtV2 = Z_AX ^ vtV1 ; + if ( IntersLineCylinder( ptC, Z_AX, CylFrame, dHei, dRad, true, true, + ptInt1, vtN1, ptInt2, vtN2)) { + AddIntervals( nGrid, i, j, ptInt1.z, ptInt2.z, - vtN1, - vtN2, CurrTool.GetToolNum()) ; + } - for ( int i = nStartI ; i <= nEndI ; ++ i) { - for ( int j = nStartJ ; j <= nEndJ ; ++ j) { + if ( IntersLineCylinder( ptC - dLen1 * vtV1, Z_AX, CylFrame, dHei, dRad, true, true, + ptInt1, vtN1, ptInt2, vtN2)) { + AddIntervals( nGrid, i, j, ptInt1.z + dLen1 * vtV1.z, ptInt2.z + dLen1 * vtV1.z, - vtN1, - vtN2, CurrTool.GetToolNum()) ; + } - Vector3d vtStC( ( i + 0.5) * m_dStep - ptS.x, ( j + 0.5) * m_dStep - ptS.y, 0) ; - Vector3d vtEnC = vtStC - dLen1 * vtV1 ; - - double dX1 = vtStC * vtV1 ; - double dX2 = vtStC * vtV2 ; - - if ( ( dX1 > 0 && dX1 < dLen1 && abs( dX2) < dRad + EPS_SMALL) || - vtStC.SqLen() < dRad * dRad + 2 * dRad * EPS_SMALL || - vtEnC.SqLen() < dRad * dRad + 2 * dRad * EPS_SMALL) { - AddIntervals( nGrid, i, j, ptS.z - dHei, ptS.z, - Z_AX, Z_AX, CurrTool.GetToolNum()) ; - } + if ( IntersLineMyPolyhedron( ptC, Z_AX, PolyFrame, dLen1, 2 * ( dRad + dMyTol), dHei + 2 * dMyTol, 0, + ptInt1, vtN1, ptInt2, vtN2)) { + AddIntervals( nGrid, i, j, ptInt1.z, ptInt2.z, - vtN1, - vtN2, CurrTool.GetToolNum()) ; } } } - else { - double dMyTol = 0 ; - Frame3d CylFrame, PolyFrame ; - CylFrame.Set( ptS - dHei * vtAx, vtAx) ; - PolyFrame.Set( ptS - ( dHei + dMyTol) * vtAx, vtV1, vtAx ^ vtV1, vtAx) ; - for ( int i = nStartI ; i <= nEndI ; ++ i) { - for ( int j = nStartJ ; j <= nEndJ ; ++ j) { - - Point3d ptC( ( i + 0.5) * m_dStep, ( j + 0.5) * m_dStep, 0) ; - - Point3d ptInt1, ptInt2 ; - Vector3d vtN1, vtN2 ; - if ( IntersLineCylinder( ptC, Z_AX, CylFrame, dHei, dRad, true, true, - ptInt1, vtN1, ptInt2, vtN2)) { - AddIntervals( nGrid, i, j, ptInt1.z, ptInt2.z, - vtN1, - vtN2, CurrTool.GetToolNum()) ; - } - - if ( IntersLineCylinder( ptC - dLen1 * vtV1, Z_AX, CylFrame, dHei, dRad, true, true, - ptInt1, vtN1, ptInt2, vtN2)) { - AddIntervals( nGrid, i, j, ptInt1.z + dLen1 * vtV1.z, ptInt2.z + dLen1 * vtV1.z, - vtN1, - vtN2, CurrTool.GetToolNum()) ; - } - - if ( IntersLineMyPolyhedron( ptC, Z_AX, PolyFrame, dLen1, 2 * ( dRad + dMyTol), dHei + 2 * dMyTol, 0, - ptInt1, vtN1, ptInt2, vtN2)) { - AddIntervals( nGrid, i, j, ptInt1.z, ptInt2.z, - vtN1, - vtN2, CurrTool.GetToolNum()) ; - } - } - } - } return true ; } @@ -5158,7 +5139,9 @@ VolZmap::AddingTruncatedCone( int nGrid, const Point3d& ptS, const Point3d& ptE, Vector3d vtV3 = vtV1 ^ vtV2 ; // Sistema di riferimento intrinseco del movimento - Frame3d ConusFrame ; ConusFrame.Set( ptV, vtV2, vtV3, vtV1) ; + Frame3d ConusFrame ; + if ( ! ConusFrame.Set( ptV, vtV1, vtV2, vtV3)) + return false ; // Dimensioni lineari movimento double dLongLen = 0 ; @@ -5183,7 +5166,8 @@ VolZmap::AddingTruncatedCone( int nGrid, const Point3d& ptS, const Point3d& ptE, // Sistema di riferimento poliedro Point3d ptO = ptV + vtV1 * dl + vtV2 * ( dCos * dMinRad) ; Frame3d PolyFrame ; - PolyFrame.Set( ptO, vtV1, vtV2, vtV3) ; + if ( ! PolyFrame.Set( ptO, vtV1, vtV2, vtV3)) + return false ; // Versori piani nel riferimento poliedro ( riferiti al sistema di riferimento) : // Sx, Dx @@ -5423,7 +5407,7 @@ VolZmap::AddingTruncatedCone( int nGrid, const Point3d& ptS, const Point3d& ptE, } } } - // Se il poliedro � attraversato, aggiungo + // Se il poliedro è attraversato, aggiungo if ( nIntNum == 2) { // Riporto le intersezioni nel sistema griglia @@ -5459,7 +5443,8 @@ VolZmap::AddingSphere( int nGrid, const Point3d& ptS, const Point3d& ptE, double vtV /= dLengthPath ; // Riferimento per cilindro inviluppo della sfera lungo il movimento Frame3d CylFrame ; - CylFrame.Set( ptS, vtV) ; + if ( ! CylFrame.Set( ptS, vtV)) + return false ; double dSqRad = dRad * dRad ;