From 67e4b81e993942b93a2aacd92f313ae9f529358a Mon Sep 17 00:00:00 2001 From: LorenzoM Date: Fri, 15 Oct 2021 17:45:04 +0200 Subject: [PATCH] Correzione errori e migliorie a virtual milling --- Tool.cpp | 98 +++- Tool.h | 4 +- VolZmap.h | 11 +- VolZmapGraphics.cpp | 12 +- VolZmapVolume.cpp | 1207 ++++++++++++++++++++++++++++++------------- 5 files changed, 933 insertions(+), 399 deletions(-) diff --git a/Tool.cpp b/Tool.cpp index 1130d28..f5f9bd8 100644 --- a/Tool.cpp +++ b/Tool.cpp @@ -29,8 +29,8 @@ using namespace std ; Tool::Tool( bool bApproxWithLines) : m_bApproxWithLines( bApproxWithLines), m_dLinTol( LIN_TOL_STD), m_dAngTolDeg( ANG_TOL_APPROX_DEG), m_nType( UNDEF), m_nCurrentNum( 0), m_dHeight( 0), m_dTipHeight( 0), m_dRadius( 0), m_dRCorner( 0), - m_dTipRadius( 0), m_dRefRadius( 0), m_dCutterHeight( 0), m_dMrtChsWidth( 0), m_dMrtChsThickness( 0), - m_bAllPartCut( true) + m_dTipRadius( 0), m_dRefRadius( 0), m_dCutterHeight( 0), m_dMrtChsWidth( 0), m_dMrtChsThickness( 0)/*, + m_bAllPartCut( true)*/ { } @@ -101,9 +101,13 @@ Tool::SetStdTool( const string& sToolName, double dH, double dR, double dCornR, Point3d pt3( m_dRadius, - m_dHeight, 0) ; Point3d pt4( 0, - m_dHeight, 0) ; m_Outline.AddPoint( pt0) ; - m_Outline.AddLine( pt1); + m_Outline.AddLine( pt1) ; + m_Outline.SetCurveTempProp( 0, 1, 1) ; m_Outline.AddLine( pt3) ; + m_Outline.SetCurveTempProp( 1, 1, 1) ; m_Outline.AddLine( pt4) ; + m_Outline.SetCurveTempProp( 2, 1, 1) ; + m_Outline.SetTempProp( 1, 1) ; } // utensile naso di toro else if ( dCornR < dR - EPS_SMALL) { @@ -121,10 +125,15 @@ Tool::SetStdTool( const string& sToolName, double dH, double dR, double dCornR, Point3d pt3( m_dTipRadius, - m_dHeight, 0) ; Point3d pt4( 0, - m_dHeight, 0) ; m_Outline.AddPoint( pt0) ; - m_Outline.AddLine( pt1); - m_Outline.AddLine( pt2); + m_Outline.AddLine( pt1) ; + m_Outline.SetCurveTempProp( 0, 1, 1) ; + m_Outline.AddLine( pt2) ; + m_Outline.SetCurveTempProp( 1, 1, 1) ; m_Outline.AddArcTg( pt3) ; + m_Outline.SetCurveTempProp( 2, 1, 1) ; m_Outline.AddLine( pt4) ; + m_Outline.SetCurveTempProp( 3, 1, 1) ; + m_Outline.SetTempProp( 1, 1) ; // se da approosimare if ( m_bApproxWithLines) return SetGenTool( sToolName, &m_Outline, nToolNum) ; @@ -144,9 +153,13 @@ Tool::SetStdTool( const string& sToolName, double dH, double dR, double dCornR, Point3d pt2( m_dRadius, - m_dHeight + m_dTipHeight, 0) ; Point3d pt4( 0, - m_dHeight, 0) ; m_Outline.AddPoint( pt0) ; - m_Outline.AddLine( pt1); - m_Outline.AddLine( pt2); + m_Outline.AddLine( pt1) ; + m_Outline.SetCurveTempProp( 0, 1, 1) ; + m_Outline.AddLine( pt2) ; + m_Outline.SetCurveTempProp( 1, 1, 1) ; m_Outline.AddArcTg( pt4) ; + m_Outline.SetCurveTempProp( 2, 1, 1) ; + m_Outline.SetTempProp( 1, 1) ; } // impossibile else @@ -202,9 +215,14 @@ Tool::SetAdvTool( const string& sToolName, double dH, double dR, // profilo m_Outline.AddPoint( pt0) ; m_Outline.AddLine( pt1) ; + m_Outline.SetCurveTempProp( 0, 1, 1) ; m_Outline.AddLine( pt2) ; + m_Outline.SetCurveTempProp( 1, 1, 1) ; m_Outline.AddLine( Point3d( m_dTipRadius, - m_dHeight, 0)) ; + m_Outline.SetCurveTempProp( 2, 1, 1) ; m_Outline.AddLine( pt5) ; + m_Outline.SetCurveTempProp( 3, 1, 1) ; + m_Outline.SetTempProp( 1, 1) ; // eventuali sistemazioni per altezza tagliente if ( ModifyForCutterHeight()) return SetGenTool( sToolName, &m_Outline, nToolNum) ; @@ -243,10 +261,16 @@ Tool::SetAdvTool( const string& sToolName, double dH, double dR, // creazione curva composita m_Outline.AddPoint( pt0) ; m_Outline.AddLine( pt1) ; + m_Outline.SetCurveTempProp( 0, 1, 1) ; m_Outline.AddLine( pt2) ; + m_Outline.SetCurveTempProp( 1, 1, 1) ; m_Outline.AddLine( pt3) ; + m_Outline.SetCurveTempProp( 2, 1, 1) ; m_Outline.AddCurve( cvArc) ; + m_Outline.SetCurveTempProp( 3, 1, 1) ; m_Outline.AddLine( pt5) ; + m_Outline.SetCurveTempProp( 4, 1, 1) ; + m_Outline.SetTempProp( 1, 1) ; } // altrimenti punta a naso di toro else { @@ -272,10 +296,16 @@ Tool::SetAdvTool( const string& sToolName, double dH, double dR, // creazione curva composita m_Outline.AddPoint( pt0) ; m_Outline.AddLine( pt1) ; + m_Outline.SetCurveTempProp( 0, 1, 1) ; m_Outline.AddLine( pt2) ; + m_Outline.SetCurveTempProp( 1, 1, 1) ; m_Outline.AddLine( pt3) ; + m_Outline.SetCurveTempProp( 2, 1, 1) ; m_Outline.AddCurve( Release( pArc)) ; + m_Outline.SetCurveTempProp( 3, 1, 1) ; m_Outline.AddLine( pt5) ; + m_Outline.SetCurveTempProp( 4, 1, 1) ; + m_Outline.SetTempProp( 1, 1) ; } } @@ -306,10 +336,16 @@ Tool::SetAdvTool( const string& sToolName, double dH, double dR, // creazione curva composita m_Outline.AddPoint( pt0) ; m_Outline.AddLine( pt1) ; + m_Outline.SetCurveTempProp( 0, 1, 1) ; m_Outline.AddLine( pt2) ; + m_Outline.SetCurveTempProp( 1, 1, 1) ; m_Outline.AddLine( pt3) ; + m_Outline.SetCurveTempProp( 2, 1, 1) ; m_Outline.AddCurve( cvArc) ; + m_Outline.SetCurveTempProp( 3, 1, 1) ; m_Outline.AddLine( pt5) ; + m_Outline.SetCurveTempProp( 4, 1, 1) ; + m_Outline.SetTempProp( 1, 1) ; } // eventuali sistemazioni per altezza tagliente @@ -341,6 +377,8 @@ Tool::ModifyForCutterHeight( void) m_Outline.TrimStartAtParam( dU) ; m_Outline.AddLine( Point3d( 0, dYtrim, 0), false) ; m_Outline.AddLine( ORIG, false) ; + m_Outline.SetCurveTempProp( 0, 1, 1) ; + m_Outline.SetCurveTempProp( 1, 1, 1) ; return true ; } return false ; @@ -376,22 +414,36 @@ Tool::SetSawTool( const string& sToolName, double dH, double dR, // creazione profilo m_Outline.AddPoint( pt0) ; m_Outline.AddLine( pt1) ; + m_Outline.SetCurveTempProp( 0, 1, 1) ; m_Outline.AddLine( pt2) ; + m_Outline.SetCurveTempProp( 1, 1, 1) ; m_Outline.AddLine( pt3) ; + m_Outline.SetCurveTempProp( 2, 1, 1) ; m_Outline.AddLine( pt4) ; + m_Outline.SetCurveTempProp( 3, 1, 1) ; m_Outline.AddLine( pt5) ; + m_Outline.SetCurveTempProp( 4, 1, 1) ; + m_Outline.SetTempProp( 1, 1) ; } // altrimenti con raggio corner else { // creazione profilo m_Outline.AddPoint( pt0) ; m_Outline.AddLine( pt1) ; + m_Outline.SetCurveTempProp( 0, 1, 1) ; m_Outline.AddLine( pt2) ; + m_Outline.SetCurveTempProp( 1, 1, 1) ; m_Outline.AddLine( pt3 - X_AX * dCornR) ; + m_Outline.SetCurveTempProp( 0, 1, 1) ; m_Outline.AddArcTg( pt3 - Y_AX * dCornR) ; + m_Outline.SetCurveTempProp( 2, 1, 1) ; m_Outline.AddLine( pt4 + Y_AX * dCornR) ; + m_Outline.SetCurveTempProp( 3, 1, 1) ; m_Outline.AddArcTg( pt4 - X_AX * dCornR) ; + m_Outline.SetCurveTempProp( 4, 1, 1) ; m_Outline.AddLine( pt5) ; + m_Outline.SetCurveTempProp( 5, 1, 1) ; + m_Outline.SetTempProp( 1, 1) ; } } // altrimenti senza gambo @@ -406,18 +458,28 @@ Tool::SetSawTool( const string& sToolName, double dH, double dR, // creazione profilo m_Outline.AddPoint( pt0) ; m_Outline.AddLine( pt3) ; + m_Outline.SetCurveTempProp( 0, 1, 1) ; m_Outline.AddLine( pt4) ; + m_Outline.SetCurveTempProp( 0, 1, 1) ; m_Outline.AddLine( pt5) ; + m_Outline.SetCurveTempProp( 0, 1, 1) ; + m_Outline.SetTempProp( 1, 1) ; } // altrimenti con raggio corner else { // creazione profilo m_Outline.AddPoint( pt0) ; m_Outline.AddLine( pt3 - X_AX * dCornR) ; + m_Outline.SetCurveTempProp( 0, 1, 1) ; m_Outline.AddArcTg( pt3 - Y_AX * dCornR) ; + m_Outline.SetCurveTempProp( 0, 1, 1) ; m_Outline.AddLine( pt4 + Y_AX * dCornR) ; + m_Outline.SetCurveTempProp( 0, 1, 1) ; m_Outline.AddArcTg( pt4 - X_AX * dCornR) ; + m_Outline.SetCurveTempProp( 0, 1, 1) ; m_Outline.AddLine( pt5) ; + m_Outline.SetCurveTempProp( 0, 1, 1) ; + m_Outline.SetTempProp( 1, 1) ; } } // Assegno il raggio di riferimento @@ -437,20 +499,30 @@ Tool::SetGenTool( const string& sToolName, const ICurveComposite* pToolOutline, if ( pToolOutline != &m_Outline) m_Outline.Clear() ; m_ArcLineApprox.Clear() ; - + // Copio il profilo e garantisco sia di soli archi e rette (converto eventuali curve di Bezier) if ( ! m_Outline.CopyFrom( pToolOutline) || ! m_Outline.ArcsBezierCurvesToArcsPerpExtr( m_dLinTol, m_dAngTolDeg)) return false ; - // Ciclo sulle curve componenti + // Valuto se tutte le curve tagliano + //bool bAllPartCut = true ; + m_ArcLineApprox.SetTempProp( 1, 1) ; const ICurve* pCurve = m_Outline.GetFirstCurve() ; + while ( pCurve != nullptr && m_ArcLineApprox.GetTempProp( 1) == 1) { + int nCutTempProp = pCurve->GetTempProp( 1) ; + if ( nCutTempProp == 0) { + //bAllPartCut = false ; + m_ArcLineApprox.SetTempProp( 0, 1) ; + } + pCurve = m_Outline.GetNextCurve() ; + } + + // Ciclo sulle curve componenti + /*const ICurve**/ pCurve = m_Outline.GetFirstCurve() ; while ( pCurve != nullptr) { int nCutTempProp = pCurve->GetTempProp( 1) ; - if ( nCutTempProp == 0) { - m_bAllPartCut = false ; - } // Se la curva � un arco ed � richiesto la verifica per l'approssimazione, // verifico se approssimarlo @@ -464,7 +536,7 @@ Tool::SetGenTool( const string& sToolName, const ICurveComposite* pToolOutline, bool bCurrApprox = ( abs( ptO.x) > EPS_SMALL) ; // Se una delle altre curve dista dal centro meno del raggio, devo approssimare - for ( int nI = 0 ; ! bCurrApprox && nI < m_Outline.GetCurveCount() ; ++ nI) { + for ( int nI = 0 ; ! bCurrApprox && nI < m_Outline.GetCurveCount() && m_ArcLineApprox.GetTempProp( 1) == 1 ; ++ nI) { const ICurve* pOtherCrv = m_Outline.GetCurve( nI) ; if ( pOtherCrv != pCurve) { DistPointCurve CalcDist( ptO, *pOtherCrv) ; diff --git a/Tool.h b/Tool.h index 501bc1b..786ac4b 100644 --- a/Tool.h +++ b/Tool.h @@ -62,7 +62,7 @@ class Tool const VCT3DVECTOR& GetArcNormalVec( void) const { return m_vArcNormals ; } bool GetCuttingFlag() const - { return m_bAllPartCut ; } + { /*return m_bAllPartCut ;*/ return ( m_nType == GEN ? m_ArcLineApprox.GetTempProp( 1) == 1 : true ) ; } public : enum ToolType { UNDEF = 0, // Utensile indefinito @@ -79,7 +79,7 @@ class Tool private : bool m_bApproxWithLines ; - bool m_bAllPartCut ; + //bool m_bAllPartCut ; double m_dLinTol ; double m_dAngTolDeg ; std::string m_sName ; diff --git a/VolZmap.h b/VolZmap.h index ec73c68..5f14cdc 100644 --- a/VolZmap.h +++ b/VolZmap.h @@ -362,9 +362,8 @@ class VolZmap : public IVolZmap, public IGeoObjRW const Frame3d& frTruncPyramFrame, double dSegMin, double dSegMax, double dHeight, Point3d& ptInt1, Vector3d& vtN1, Point3d& ptInt2, Vector3d& vtN2) const ; bool TestIntersPlaneZmapBBox( const Plane3d& plPlane) const ; - // Intersezioni 2 - ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - /*public:*/ + + // Intersezioni per asportazioni avanzate int IntersLineCircCrown( const Point3d& ptLineP, const Vector3d& vtLineDir, const Point3d& ptCen, const Vector3d& vtAx, double dMaxRad, double dMinRad, Point3d& ptInt, Vector3d& vtN) const ; @@ -387,8 +386,10 @@ class VolZmap : public IVolZmap, public IGeoObjRW const Point3d& ptCen, double dRad, bool bInOut, const std::vector& vPlanesVec, Point3d& ptInt1, Vector3d& vtN1, Point3d& ptInt2, Vector3d& vtN2) const ; - /*private:*/ - ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + int IntersLineCatTongue( const Point3d& ptLineP, const Vector3d& vtLineD, + const Point3d& ptCenSt, const Point3d& ptCenEn, const Vector3d& vtNorm, double dRad, + Point3d& ptInt, Vector3d& vtN) const ; + // Voxel: esistenza e passaggio da N a ijk per i voxel bool IsValidVoxel( int nN) const ; bool IsValidVoxel( int nI, int nJ, int nK) const ; diff --git a/VolZmapGraphics.cpp b/VolZmapGraphics.cpp index 90c85fb..f9ee92b 100644 --- a/VolZmapGraphics.cpp +++ b/VolZmapGraphics.cpp @@ -844,7 +844,7 @@ VolZmap::UpdateTripleMapGraphics( void) const VecTriHold.resize( m_nNumBlock) ; // Ciclo sui blocchi per eliminare le slice fra blocchi da aggiornare - for ( int t = 0 ; t < m_nNumBlock ; ++ t) { + for ( int t = 0 ; t < m_nNumBlock ; ++ t) { for ( auto it = m_SliceXY[t].begin() ; it != m_SliceXY[t].end() ;) { int nSlIJK[3] ; if ( GetVoxIJKFromN( it->first, nSlIJK[0], nSlIJK[1], nSlIJK[2])) { @@ -1083,7 +1083,7 @@ VolZmap::ExtMarchingCubes( int nBlock, VoxelContainer& vVox) const // Flag di regolarità dei campi scalare e vettoriale bool bReg = true ; - + // Ciclo sui segmenti for ( int EdgeIndex = 0 ; EdgeIndex < 12 ; ++ EdgeIndex) { // Se il segmento non attraversa la superficie passo al successivo @@ -3984,13 +3984,13 @@ VolZmap::IsAVoxelOnBoundary( const int nLimits[], const int nIJK[], int nDeltaIn -- nDeltaIndex[0] ; else if ( nIJK[0] == nLimits[1] - 1) ++ nDeltaIndex[0] ; - if ( nIJK[0] == nLimits[0]) + if ( nIJK[1] == nLimits[2]) -- nDeltaIndex[1]; - else if ( nIJK[0] == nLimits[1] - 1) + else if ( nIJK[1] == nLimits[3] - 1) ++ nDeltaIndex[1]; - if ( nIJK[0] == nLimits[0]) + if ( nIJK[2] == nLimits[4]) -- nDeltaIndex[2]; - else if ( nIJK[0] == nLimits[1] - 1) + else if ( nIJK[2] == nLimits[5] - 1) ++ nDeltaIndex[2]; return ( nDeltaIndex[0] != 0 || nDeltaIndex[1] != 0 || nDeltaIndex[2] != 0) ; } diff --git a/VolZmapVolume.cpp b/VolZmapVolume.cpp index fd6dd50..fb199b3 100644 --- a/VolZmapVolume.cpp +++ b/VolZmapVolume.cpp @@ -111,10 +111,10 @@ VolZmap::SubtractIntervals( int nGrid, int nI, int nJ, -- i ; } } - // se è tutto minore dell'intervallo corrente, ho finito + // se � tutto minore dell'intervallo corrente, ho finito else if ( dMax <= vDexel[i].dMin + EPS_ZERO) break ; - // altrimenti è tutto maggiore dell'intervallo corrente, passo al successivo + // altrimenti � tutto maggiore dell'intervallo corrente, passo al successivo else // dMin >= vDexel[i].dMax - EPS_ZERO ; } @@ -323,7 +323,7 @@ VolZmap::AddIntervals( int nGrid, int nI, int nJ, // if ( i < m_Values[nGrid][nPos].size() - 1) { // if ( m_Values[nGrid][nPos][i].dMax > m_Values[nGrid][nPos][i + 1].dMin - EPS_SMALL) { // -// // Se l'intervallo corrente non è contenuto totalmente si esegue l'istruzione successiva +// // Se l'intervallo corrente non � contenuto totalmente si esegue l'istruzione successiva // if ( m_Values[nGrid][nPos][i].dMin < m_Values[nGrid][nPos][i + 1].dMin + EPS_SMALL) { // // m_Values[nGrid][nPos][i].dMax = m_Values[nGrid][nPos][i + 1].dMax ; @@ -391,7 +391,7 @@ VolZmap::AddIntervals( int nGrid, int nI, int nJ, // } // // else { -// // Se l'intervallo corrente è tutto contenuto nell'intervallo da aggungere modifico gli estremi +// // Se l'intervallo corrente � tutto contenuto nell'intervallo da aggungere modifico gli estremi // if ( m_Values[nGrid][nPos][i].dZVal > dMin + EPS_SMALL) { // // bModified = true ; @@ -496,7 +496,7 @@ bool VolZmap::MillingStep( const Point3d& ptPs, const Vector3d& vtDs, const Vector3d& vtAs, const Point3d& ptPe, const Vector3d& vtDe, const Vector3d& vtAe) { - // Se non è definito l'utensile, non devo fare alcunchè + // Se non � definito l'utensile, non devo fare alcunch� if ( m_Tool.GetType() == Tool::UNDEF) return true ; // Controllo definizione vettori direzione @@ -595,7 +595,7 @@ VolZmap::MillingTranslationStep( const Point3d& ptPs, const Point3d& ptPe, const Vector3d vtLs[N_MAPS] ; Vector3d vtALs[N_MAPS] ; InitializePointsAndVectors( ptPs, ptPe, vtD, vtA, ptLs, ptLe, vtLs, vtALs) ; - // Ciclo sulle mappe + // Ciclo sulle mappe vector< future> vRes ; vRes.resize( m_nMapNum) ; for ( int i = 0 ; i < m_nMapNum ; ++ i) { @@ -761,7 +761,7 @@ VolZmap::SelectMotion( int nGrid, const Point3d& ptLs, const Point3d& ptLe, cons CylBall_XYPerp( nGrid, ptLs, ptLe, vtL) ; break ; case Tool::CONEMILL : - // Usiamo la generica per via dell'intsabilità di Conus_XYPerp + // Usiamo la generica per via dell'intsabilit� di Conus_XYPerp //Conus_XYPerp( i, ptLs[i], ptLe[i], vtLs[i]) ; Conus_Milling( nGrid, ptLs, ptLe, vtL) ; break ; @@ -940,7 +940,7 @@ VolZmap::CylBall_ZPerp( int nGrid, const Point3d& ptS, const Point3d& ptE, const // Definizione di un sistema di riferimento ad hoc Point3d ptSxy( ptS.x, ptS.y, 0) ; Vector3d vtV1 = vtMove ; - vtV1.Normalize() ; // se |vtMove| < EPS è un buco con dz = 0 + vtV1.Normalize() ; // se |vtMove| < EPS � un buco con dz = 0 Vector3d vtV2 = vtV1 ; vtV2.Rotate( Z_AX, 0, 1) ; @@ -1077,7 +1077,7 @@ VolZmap::CylBall_ZMilling( int nGrid, const Point3d & ptS, const Point3d & ptE, // Definizione di un sistema di riferimento ad hoc Vector3d vtV1, vtV2 ; - // Se la lunghezza è troppo piccola lo allungo + // Se la lunghezza � troppo piccola lo allungo if ( dLenXY < EPS_SMALL) vtV1 = ( 1 / dLenXY) * vtMoveXY ; else @@ -1633,7 +1633,7 @@ VolZmap::Mrt_ZDrilling( int nGrid, const Point3d& ptS, const Point3d& ptE, const CompPar_ZDrilling( nGrid, dLenX, dLenY, dLenZ, ptS, ptEOnP, vtToolDir, vtAux) ; - // Se la punta è di tipo bull-nose + // Se la punta � di tipo bull-nose if ( abs( m_Tool.GetMrtChsWidth() - 2 * m_Tool.GetCornRadius()) > EPS_SMALL) { // Parallelepipedo di punta @@ -1657,7 +1657,7 @@ VolZmap::Mrt_ZDrilling( int nGrid, const Point3d& ptS, const Point3d& ptE, const CompCyl_Milling( nGrid, ptSplus, ptEplus, vtAux, dLenY, m_Tool.GetCornRadius(), false, false) ; } - // se la punta è di tipo sfera + // se la punta � di tipo sfera else { // Cilindro Point3d ptCylS = ptS - dLenZ * vtToolDir + 0.5 * dLenY * vtAux ; @@ -1707,7 +1707,7 @@ VolZmap::GenTool_ZDrilling( int nGrid, const Point3d& ptS, const Point3d& ptE, c Vector3d vtMove = ptE - ptS ; // Vettore delle normali agli archi const VCT3DVECTOR& vArcNorm = m_Tool.GetArcNormalVec() ; - // Poinché l'asse utensile è parallelo all'asse Z, definisco un sistema di + // 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. Frame3d frNormFrame ; frNormFrame.Set( ORIG, X_AX, - Z_AX, Y_AX) ; @@ -1739,23 +1739,23 @@ VolZmap::GenTool_ZDrilling( int nGrid, const Point3d& ptS, const Point3d& ptE, c dHeight = abs( dSignedHeight) ; // Cilindro o cono if ( dHeight > EPS_SMALL) { - // 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 && m_Tool.GetCuttingFlag()) CompCyl_ZDrilling( nGrid, ptI, ptF, vtToolDir, dHeight, dRadius) ; } - // Se X crescente, è un cono con vettore equiverso a quello dell'utensile + // Se X crescente, � un cono con vettore equiverso a quello dell'utensile else if ( ptStart.x > ptEnd.x) { double dMaxRad = ptStart.x ; double dMinRad = ptEnd.x ; if ( m_Tool.GetCuttingFlag()) CompConus_ZDrilling( nGrid, ptI, ptF, vtToolDir, dHeight, dMaxRad, dMinRad, vtNormSt, vtNormEn) ; - else if ( pCurve->GetTempProp(1) == 1) { - if ( ptI.y > ptF.y) + else if ( pCurve->GetTempProp( 1) == 1) { + if ( ptStart.y > ptEnd.y) SurfConus_ZDrilling( nGrid, ptI, ptF, vtToolDir, dHeight, dMaxRad, dMinRad, true, vtNormSt, vtNormEn) ; else { - Point3d ptIn = ptI - vtToolDir * dHeight ; + Point3d ptIn = ptI ; Point3d ptFn = ptIn + vtMove ; /*vtNormEn.z *= -1 ; vtNormSt.z *= -1 ;*/ @@ -1763,18 +1763,18 @@ VolZmap::GenTool_ZDrilling( int nGrid, const Point3d& ptS, const Point3d& ptE, c } } } - // Se X decrescente, è un cono con vettore opposto a quello dell'utensile + // Se X decrescente, � un cono con vettore opposto a quello dell'utensile else if ( ptStart.x < ptEnd.x) { double dMaxRad = ptEnd.x ; double dMinRad = ptStart.x ; - Point3d ptIn = ptI - vtToolDir * dHeight ; + Point3d ptIn = ptI - vtToolDir * dSignedHeight ; Point3d ptFn = ptIn + vtMove ; vtNormEn.z *= -1 ; vtNormSt.z *= -1 ; if ( m_Tool.GetCuttingFlag()) CompConus_ZDrilling( nGrid, ptIn, ptFn, - vtToolDir, dHeight, dMaxRad, dMinRad, vtNormEn, vtNormSt) ; else if ( pCurve->GetTempProp( 1) == 1) { - if ( ptI.y > ptF.y) + if ( ptStart.y > ptEnd.y) SurfConus_ZDrilling( nGrid, ptIn, ptFn, - vtToolDir, dHeight, dMaxRad, dMinRad, true, vtNormEn, vtNormSt) ; else { vtNormEn.z *= -1 ; @@ -1785,7 +1785,7 @@ VolZmap::GenTool_ZDrilling( int nGrid, const Point3d& ptS, const Point3d& ptE, c } } // Corona circolare - else if ( m_Tool.GetCuttingFlag() && pCurve->GetTempProp( 1) == 1) { + else if ( ! m_Tool.GetCuttingFlag() && pCurve->GetTempProp( 1) == 1) { if ( ptStart.x < ptEnd.x) { SurfCircCrown_ZDrilling( nGrid, ptI, ptF, vtToolDir, ptEnd.x, ptStart.x) ; } @@ -1819,10 +1819,10 @@ VolZmap::GenTool_ZDrilling( int nGrid, const Point3d& ptS, const Point3d& ptE, c } else if ( dStH > 0) { SurfSphericalShellPart_Milling( nGrid, ptCenS, ptCenE, - vtToolDir, dRadius, 0, dStH, true) ; - SurfSphericalShellPart_Milling( nGrid, ptCenS, ptCenE, vtToolDir, dRadius, 0, dEnH, true) ; + SurfSphericalShellPart_Milling( nGrid, ptCenS, ptCenE, vtToolDir, dRadius, 0, - dEnH, true) ; } else { - SurfSphericalShellPart_Milling( nGrid, ptCenS, ptCenE, vtToolDir, dRadius, dEnH, dStH, true) ; + SurfSphericalShellPart_Milling( nGrid, ptCenS, ptCenE, vtToolDir, dRadius, - dEnH, - dStH, true) ; } } // Tagliente interno @@ -1835,9 +1835,10 @@ VolZmap::GenTool_ZDrilling( int nGrid, const Point3d& ptS, const Point3d& ptE, c SurfSphericalShellPart_Milling( nGrid, ptCenS, ptCenE, - vtToolDir, dRadius, 0, abs( dEnH), false) ; } else { - SurfSphericalShellPart_Milling( nGrid, ptCenS, ptCenE, - vtToolDir, dRadius, abs( dStH), abs( dEnH), false) ; + SurfSphericalShellPart_Milling( nGrid, ptCenS, ptCenE, - vtToolDir, dRadius, abs( dEnH), abs( dStH), false) ; } - } + } + dSignedHeight = ptStart.y - ptEnd.y ; } // aggiorno l'altezza //dHeight = abs( ptStart.y - ptEnd.y) ; @@ -1864,7 +1865,7 @@ VolZmap::GenTool_ZMilling( int nGrid, const Point3d& ptS, const Point3d& ptE, co Vector3d vtMove = ptE - ptS ; // Vettore delle normali agli archi const VCT3DVECTOR& vArcNorm = m_Tool.GetArcNormalVec() ; - // Poinché l'asse utensile è parallelo all'asse Z, definisco un sistema di + // 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. Frame3d frNormFrame; frNormFrame.Set( ORIG, X_AX, -Z_AX, Y_AX) ; @@ -1895,32 +1896,32 @@ VolZmap::GenTool_ZMilling( int nGrid, const Point3d& ptS, const Point3d& ptE, co dSignedHeight = ptStart.y - ptEnd.y ; dHeight = abs( dSignedHeight) ; if ( dHeight > EPS_SMALL) { - // 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) { if ( m_Tool.GetCuttingFlag()) CompCyl_ZMilling( nGrid, ptI, ptF, vtToolDir, dHeight, dRadius) ; else if ( pCurve->GetTempProp( 1) == 1) { - if ( ptI.y > ptF.y) - SurfCyl_ZMilling( nGrid, ptS, ptE, vtToolDir, dHeight, dRadius, true) ; + if ( ptStart.y > ptEnd.y) + SurfCyl_ZMilling( nGrid, ptI, ptF, vtToolDir, dHeight, dRadius, true) ; else { - SurfCyl_ZMilling( nGrid, ptS, ptE, - vtToolDir, dHeight, dRadius, false) ; + SurfCyl_ZMilling( nGrid, ptI, ptF, - vtToolDir, dHeight, dRadius, false) ; } } } } - // Se X crescente, è un cono con vettore equiverso a quello dell'utensile + // Se X crescente, � un cono con vettore equiverso a quello dell'utensile else if ( ptStart.x > ptEnd.x) { double dMaxRad = ptStart.x ; double dMinRad = ptEnd.x ; if ( m_Tool.GetCuttingFlag()) CompConus_ZMilling( nGrid, ptI, ptF, vtToolDir, dHeight, dMaxRad, dMinRad, vtNormSt, vtNormEn) ; else if ( pCurve->GetTempProp( 1) == 1) { - if ( ptI.y > ptF.y) + if ( ptStart.y > ptEnd.y) SurfConus_ZMilling( nGrid, ptI, ptF, vtToolDir, dHeight, dMaxRad, dMinRad, true, vtNormSt, vtNormEn) ; else { - Point3d ptIn = ptI - vtToolDir * dHeight ; + Point3d ptIn = ptI ; Point3d ptFn = ptIn + vtMove ; /*vtNormEn.z *= -1 ; vtNormSt.z *= -1 ;*/ @@ -1928,18 +1929,18 @@ VolZmap::GenTool_ZMilling( int nGrid, const Point3d& ptS, const Point3d& ptE, co } } } - // Se X decrescente, è un cono con vettore opposto a quello dell'utensile + // Se X decrescente, � un cono con vettore opposto a quello dell'utensile else if ( ptStart.x < ptEnd.x) { double dMaxRad = ptEnd.x ; double dMinRad = ptStart.x ; - Point3d ptIn = ptI - vtToolDir * dHeight ; + Point3d ptIn = ptI - vtToolDir * dSignedHeight ; Point3d ptFn = ptIn + vtMove ; vtNormEn.z *= -1 ; vtNormSt.z *= -1 ; if ( m_Tool.GetCuttingFlag()) CompConus_ZMilling( nGrid, ptIn, ptFn, - vtToolDir, dHeight, dMaxRad, dMinRad, vtNormEn, vtNormSt) ; else if ( pCurve->GetTempProp( 1) == 1) { - if ( ptI.y > ptF.y) + if ( ptStart.y > ptEnd.y) SurfConus_ZMilling( nGrid, ptIn, ptFn, - vtToolDir, dHeight, dMaxRad, dMinRad, true, vtNormEn, vtNormSt) ; else { /*vtNormEn.z *= -1 ; @@ -1949,7 +1950,7 @@ VolZmap::GenTool_ZMilling( int nGrid, const Point3d& ptS, const Point3d& ptE, co } } } - else if ( m_Tool.GetCuttingFlag() && pCurve->GetTempProp( 1) == 1) { + else if ( ! m_Tool.GetCuttingFlag() && pCurve->GetTempProp( 1) == 1) { if ( ptStart.x < ptEnd.x) { SurfCircCrown_ZMilling( nGrid, ptI, ptF, vtToolDir, ptEnd.x, ptStart.x) ; } @@ -1983,10 +1984,10 @@ VolZmap::GenTool_ZMilling( int nGrid, const Point3d& ptS, const Point3d& ptE, co } else if ( dStH > 0) { SurfSphericalShellPart_Milling( nGrid, ptCenS, ptCenE, - vtToolDir, dRadius, 0, dStH, true) ; - SurfSphericalShellPart_Milling( nGrid, ptCenS, ptCenE, vtToolDir, dRadius, 0, dEnH, true) ; + SurfSphericalShellPart_Milling( nGrid, ptCenS, ptCenE, vtToolDir, dRadius, 0, - dEnH, true) ; } else { - SurfSphericalShellPart_Milling( nGrid, ptCenS, ptCenE, vtToolDir, dRadius, dEnH, dStH, true) ; + SurfSphericalShellPart_Milling( nGrid, ptCenS, ptCenE, vtToolDir, dRadius, - dEnH, - dStH, true) ; } } // Tagliente interno @@ -1999,9 +2000,10 @@ VolZmap::GenTool_ZMilling( int nGrid, const Point3d& ptS, const Point3d& ptE, co SurfSphericalShellPart_Milling( nGrid, ptCenS, ptCenE, - vtToolDir, dRadius, 0, abs( dEnH), false) ; } else { - SurfSphericalShellPart_Milling( nGrid, ptCenS, ptCenE, - vtToolDir, dRadius, abs( dStH), abs( dEnH), false) ; + SurfSphericalShellPart_Milling( nGrid, ptCenS, ptCenE, - vtToolDir, dRadius, abs( dEnH), abs( dStH), false) ; } - } + } + dSignedHeight = ptStart.y - ptEnd.y ; } // aggiorno l'altezza //dHeight = abs( ptStart.y - ptEnd.y) ; @@ -2082,9 +2084,9 @@ VolZmap::CylBall_XYDrilling( int nGrid, const Point3d& ptS, const Point3d& ptE, SubtractIntervals( nGrid, i, j, dMin, dMax, vtMin, vtMax) ; } - // Se l'utensile è sferico sottraggo anche la punta + // Se l'utensile � sferico sottraggo anche la punta if ( m_Tool.GetType() == Tool::BALLMILL) - if ( dSqLen < dSqRad) { // LA SOLUZIONE MOMENTANEA è CREARE UTENSILE GENERICO SE LO STELO è PIù CORTO DEL RAGGIO + if ( dSqLen < dSqRad) { // LA SOLUZIONE MOMENTANEA � CREARE UTENSILE GENERICO SE LO STELO � PI� CORTO DEL RAGGIO double dH = sqrt( dSqRad - dSqLen) ; double dMin = dZ - dH ; @@ -2120,7 +2122,7 @@ VolZmap::CylBall_XYPerp( int nGrid, const Point3d& ptS, const Point3d& ptE, cons // Studio simmetrie del problema Point3d ptI = ( ptS.z <= ptE.z ? ptS : ptE) ; Point3d ptF = ( ptS.z <= ptE.z ? ptE : ptS) ; - // elimino eventuale piccolo errore di perpendicolarità del movimento rispetto all'utensile + // elimino eventuale piccolo errore di perpendicolarit� del movimento rispetto all'utensile Vector3d vtErr = 0.5 * ( ( ptF - ptI) * vtToolDir) * vtToolDir ; ptI += vtErr ; ptF -= vtErr ; @@ -2298,7 +2300,7 @@ VolZmap::CylBall_XYPerp( int nGrid, const Point3d& ptS, const Point3d& ptE, cons } } - // Se l'utensile è ball-end sottraggo la punta + // Se l'utensile � ball-end sottraggo la punta if ( m_Tool.GetType() == Tool::BALLMILL) { if ( ( ( dP1 - dStemHeigth) * ( dP1 - dStemHeigth) + dP2 * dP2 < dSqRad || @@ -2532,7 +2534,7 @@ VolZmap::Conus_XYPerp( int nGrid, const Point3d& ptS, const Point3d& ptE, const // Studio delle simmetrie del moto Point3d ptI = ( ptS.z < ptE.z ? ptS : ptE) ; Point3d ptF = ( ptS.z < ptE.z ? ptE : ptS) ; - // elimino eventuale piccolo errore di perpendicolarità del movimento rispetto all'utensile + // elimino eventuale piccolo errore di perpendicolarit� del movimento rispetto all'utensile Vector3d vtErr = 0.5 * ( ( ptF - ptI) * vtToolDir) * vtToolDir ; ptI += vtErr ; ptF -= vtErr ; @@ -2845,7 +2847,7 @@ VolZmap::CylBall_Drilling( int nGrid, const Point3d& ptS, const Point3d& ptE, co double dStemHeigth = m_Tool.GetHeigth() - m_Tool.GetTipHeigth() ; // Sottraggo cilindro CompCyl_Drilling( nGrid, ptS, ptE, vtToolDir, dStemHeigth, m_Tool.GetRadius(), false, false) ; - // Se è sfera la sottraggo + // Se � sfera la sottraggo if ( m_Tool.GetType() == Tool::BALLMILL) { Point3d ptSBall = ptS - dStemHeigth * vtToolDir ; Point3d ptEBall = ptE - dStemHeigth * vtToolDir ; @@ -2862,7 +2864,7 @@ VolZmap::CylBall_Milling( int nGrid, const Point3d& ptS, const Point3d& ptE, con double dStemHeigth = m_Tool.GetHeigth() - m_Tool.GetTipHeigth() ; // Sottraggo cilindro CompCyl_Milling( nGrid, ptS, ptE, vtToolDir, dStemHeigth, m_Tool.GetRadius(), false, false) ; - // Se è sfera la sottraggo + // Se � sfera la sottraggo if ( m_Tool.GetType() == Tool::BALLMILL) { Point3d ptSBall = ptS - dStemHeigth * vtToolDir ; Point3d ptEBall = ptE - dStemHeigth * vtToolDir ; @@ -2938,7 +2940,7 @@ VolZmap::Mrt_Drilling( int nGrid, const Point3d& ptS, const Point3d& ptE, const double dLenZ = m_Tool.GetHeigth() - m_Tool.GetCornRadius() ; CompPar_Drilling( nGrid, dLenX, dLenY, dLenZ, ptS, ptEOnP, vtToolDir, vtAux) ; - // Se la punta è di tipo bull-nose + // Se la punta � di tipo bull-nose if ( abs( m_Tool.GetMrtChsWidth() - 2 * m_Tool.GetCornRadius()) > EPS_SMALL) { // Parallelepipedo di punta @@ -2962,7 +2964,7 @@ VolZmap::Mrt_Drilling( int nGrid, const Point3d& ptS, const Point3d& ptE, const CompCyl_Milling( nGrid, ptSplus, ptEplus, vtAux, dLenY, m_Tool.GetCornRadius(), false, false) ; } - // se la punta è di tipo sfera + // se la punta � di tipo sfera else { // Cilindro Point3d ptCylS = ptS - dLenZ * vtToolDir + 0.5 * dLenY * vtAux ; @@ -2988,7 +2990,7 @@ VolZmap::Mrt_Milling( int nGrid, const Point3d& ptS, const Point3d& ptE, const V Point3d ptBasePE = ptE - 0.5 * dLenZ * vtToolDir + 0.5 * dLenY * vtAux ; CompPar_Milling( nGrid, dLenX, dLenZ, dLenY, ptBasePS, ptBasePE, vtAux, vtToolDir) ; - // Se la punta è di tipo bull-nose + // Se la punta � di tipo bull-nose if ( abs( m_Tool.GetMrtChsWidth() - 2 * m_Tool.GetCornRadius()) > EPS_SMALL) { // Parallelepipedo di punta @@ -3015,7 +3017,7 @@ VolZmap::Mrt_Milling( int nGrid, const Point3d& ptS, const Point3d& ptE, const V CompCyl_Milling( nGrid, ptSplus, ptEplus, vtAux, dLenY, m_Tool.GetCornRadius(), false, false) ; } - // se la punta è di tipo sfera + // se la punta � di tipo sfera else { // Cilindro Point3d ptCylS = ptBasePS - 0.5 * dLenZ * vtToolDir ; @@ -3031,7 +3033,7 @@ VolZmap::Mrt_Milling( int nGrid, const Point3d& ptS, const Point3d& ptE, const V bool VolZmap::Chs_Drilling( int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtToolDir, const Vector3d& vtAux) { - // Proiezione della traiettoria sulla varietà del movimento + // Proiezione della traiettoria sulla variet� del movimento Point3d ptProjE = ptS + ( ptE - ptS) * vtToolDir * vtToolDir ; CompPar_Drilling( nGrid, m_Tool.GetMrtChsWidth(), m_Tool.GetMrtChsThickness(), m_Tool.GetHeigth(), ptS, ptProjE, vtToolDir, vtAux) ; @@ -3063,7 +3065,7 @@ VolZmap::Chs_Milling( int nGrid, const Point3d& ptS, const Point3d& ptE, const V // Vector3d vtMove = ptE - ptS ; // // Vettore delle normali agli archi // const VCT3DVECTOR& vArcNorm = m_Tool.GetArcNormalVec() ; -// // Poinché l'asse utensile è parallelo all'asse Z, definisco un sistema di +// // 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. // Frame3d frNormFrame ; // frNormFrame.Set( ORIG, X_AX, -Z_AX, Y_AX) ; @@ -3112,19 +3114,19 @@ VolZmap::Chs_Milling( int nGrid, const Point3d& ptS, const Point3d& ptE, const V // if ( abs( ptOthStart.y - ptOthEnd.y) < EPS_SMALL && ptOthStart.x > ptOthEnd.x) // bTapB = true ; // } -// // 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_Drilling( nGrid, ptI, ptF, vtToolDir, dHeight, dRadius, bTapB, bTapT) ; // } -// // Se X crescente, è un cono con vettore equiverso a quello dell'utensile +// // Se X crescente, � un cono con vettore equiverso a quello dell'utensile // else if ( ptStart.x > ptEnd.x) { // double dMaxRad = ptStart.x ; // double dMinRad = ptEnd.x ; // CompConus_Drilling( nGrid, ptI, ptF, vtToolDir, dHeight, dMaxRad, dMinRad, bTapB, bTapT, vtNormSt, vtNormEn) ; // } -// // Se X decrescente, è un cono con vettore opposto a quello dell'utensile +// // Se X decrescente, � un cono con vettore opposto a quello dell'utensile // else if ( ptStart.x < ptEnd.x) { // double dMaxRad = ptEnd.x ; // double dMinRad = ptStart.x ; @@ -3181,7 +3183,7 @@ VolZmap::GenTool_Drilling( int nGrid, const Point3d& ptS, const Point3d& ptE, co Vector3d vtMove = ptE - ptS ; // Vettore delle normali agli archi const VCT3DVECTOR& vArcNorm = m_Tool.GetArcNormalVec() ; - // Poinché l'asse utensile è parallelo all'asse Z, definisco un sistema di + // 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. Frame3d frNormFrame ; frNormFrame.Set( ORIG, X_AX, -Z_AX, Y_AX) ; @@ -3224,7 +3226,8 @@ VolZmap::GenTool_Drilling( int nGrid, const Point3d& ptS, const Point3d& ptE, co } // Verifiche curva successiva per eventuale tappo sotto bool bTapB = false ; - const ICurve* pNextCurve = ToolProfile.GetCurve( ++ i) ; + int j = i ; + const ICurve* pNextCurve = ToolProfile.GetCurve( ++ j) ; if ( pNextCurve != nullptr && pNextCurve->GetType() == CRV_LINE) { const ICurveLine* pOthLine = GetCurveLine( pNextCurve) ; Point3d ptOthStart = pOthLine->GetStart() ; @@ -3232,23 +3235,23 @@ VolZmap::GenTool_Drilling( int nGrid, const Point3d& ptS, const Point3d& ptE, co if ( abs( ptOthStart.y - ptOthEnd.y) < EPS_SMALL && ptOthStart.x > ptOthEnd.x) bTapB = true ; } - // 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 && m_Tool.GetCuttingFlag()) CompCyl_Drilling( nGrid, ptI, ptF, vtToolDir, dHeight, dRadius, bTapB, bTapT) ; } - // Se X crescente, è un cono con vettore equiverso a quello dell'utensile + // Se X crescente, � un cono con vettore equiverso a quello dell'utensile else if ( ptStart.x > ptEnd.x) { double dMaxRad = ptStart.x ; double dMinRad = ptEnd.x ; if ( m_Tool.GetCuttingFlag()) CompConus_Drilling( nGrid, ptI, ptF, vtToolDir, dHeight, dMaxRad, dMinRad, bTapB, bTapT, vtNormSt, vtNormEn) ; else if ( pCurve->GetTempProp( 1) == 1) { - if ( ptI.y > ptF.y) + if ( ptStart.y > ptEnd.y) SurfConus_Drilling( nGrid, ptI, ptF, vtToolDir, dHeight, dMaxRad, dMinRad, true, bTapB, bTapT, vtNormSt, vtNormEn) ; else { - Point3d ptIn = ptI - vtToolDir * dHeight ; + Point3d ptIn = ptI /*- vtToolDir * dSignedHeight*/ ; Point3d ptFn = ptIn + vtMove ; /*vtNormEn.z *= -1 ; vtNormSt.z *= -1 ;*/ @@ -3256,18 +3259,18 @@ VolZmap::GenTool_Drilling( int nGrid, const Point3d& ptS, const Point3d& ptE, co } } } - // Se X decrescente, è un cono con vettore opposto a quello dell'utensile + // Se X decrescente, � un cono con vettore opposto a quello dell'utensile else if ( ptStart.x < ptEnd.x) { double dMaxRad = ptEnd.x ; double dMinRad = ptStart.x ; - Point3d ptIn = ptI - vtToolDir * dHeight ; + Point3d ptIn = ptI - vtToolDir * dSignedHeight ; Point3d ptFn = ptIn + vtMove ; vtNormEn.z *= -1 ; vtNormSt.z *= -1 ; if ( m_Tool.GetCuttingFlag()) CompConus_Drilling( nGrid, ptIn, ptFn, - vtToolDir, dHeight, dMaxRad, dMinRad, bTapT, bTapB, vtNormEn, vtNormSt) ; else if ( pCurve->GetTempProp( 1) == 1) { - if ( ptI.y > ptF.y) + if ( ptStart.y > ptEnd.y) SurfConus_Drilling( nGrid, ptIn, ptFn, - vtToolDir, dHeight, dMaxRad, dMinRad, true, bTapT, bTapB, vtNormEn, vtNormSt) ; else { /*vtNormEn.z *= -1 ; @@ -3278,7 +3281,7 @@ VolZmap::GenTool_Drilling( int nGrid, const Point3d& ptS, const Point3d& ptE, co } } - else if ( m_Tool.GetCuttingFlag() && pCurve->GetTempProp( 1) == 1) { + else if ( ! m_Tool.GetCuttingFlag() && pCurve->GetTempProp( 1) == 1) { if ( ptStart.x < ptEnd.x) { SurfCircCrown_Drilling( nGrid, ptI, ptF, vtToolDir, ptEnd.x, ptStart.x) ; } @@ -3312,10 +3315,10 @@ VolZmap::GenTool_Drilling( int nGrid, const Point3d& ptS, const Point3d& ptE, co } else if ( dStH > 0) { SurfSphericalShellPart_Milling( nGrid, ptCenS, ptCenE, - vtToolDir, dRadius, 0, dStH, true) ; - SurfSphericalShellPart_Milling( nGrid, ptCenS, ptCenE, vtToolDir, dRadius, 0, dEnH, true) ; + SurfSphericalShellPart_Milling( nGrid, ptCenS, ptCenE, vtToolDir, dRadius, 0, - dEnH, true) ; } else { - SurfSphericalShellPart_Milling( nGrid, ptCenS, ptCenE, vtToolDir, dRadius, dEnH, dStH, true) ; + SurfSphericalShellPart_Milling( nGrid, ptCenS, ptCenE, vtToolDir, dRadius, - dEnH, - dStH, true) ; } } // Tagliente interno @@ -3328,9 +3331,10 @@ VolZmap::GenTool_Drilling( int nGrid, const Point3d& ptS, const Point3d& ptE, co SurfSphericalShellPart_Milling( nGrid, ptCenS, ptCenE, - vtToolDir, dRadius, 0, abs( dEnH), false) ; } else { - SurfSphericalShellPart_Milling( nGrid, ptCenS, ptCenE, - vtToolDir, dRadius, abs( dStH), abs( dEnH), false) ; + SurfSphericalShellPart_Milling( nGrid, ptCenS, ptCenE, - vtToolDir, dRadius, abs( dEnH), abs( dStH), false) ; } - } + } + dSignedHeight = ptStart.y - ptEnd.y ; } // aggiorno l'altezza //dHeight = abs( ptStart.y - ptEnd.y) ; @@ -3358,7 +3362,7 @@ VolZmap::GenTool_Milling( int nGrid, const Point3d& ptS, const Point3d& ptE, con Vector3d vtMove = ptE - ptS ; // Vettore delle normali agli archi const VCT3DVECTOR& vArcNorm = m_Tool.GetArcNormalVec() ; - // Poinché l'asse utensile è parallelo all'asse Z, definisco un sistema di + // 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. Frame3d frNormFrame ; frNormFrame.Set( ORIG, X_AX, -Z_AX, Y_AX) ; @@ -3400,7 +3404,8 @@ VolZmap::GenTool_Milling( int nGrid, const Point3d& ptS, const Point3d& ptE, con } // verifiche curva successiva per eventuale tappo sotto bool bTapB = false ; - const ICurve* pNextCurve = ToolProfile.GetCurve( ++ i) ; + int j = i ; + const ICurve* pNextCurve = ToolProfile.GetCurve( ++ j) ; if ( pNextCurve != nullptr && pNextCurve->GetType() == CRV_LINE) { const ICurveLine* pOthLine = GetCurveLine( pNextCurve) ; Point3d ptOthStart = pOthLine->GetStart() ; @@ -3408,31 +3413,31 @@ VolZmap::GenTool_Milling( int nGrid, const Point3d& ptS, const Point3d& ptE, con 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) { if ( m_Tool.GetCuttingFlag()) CompCyl_Milling( nGrid, ptI, ptF, vtToolDir, dHeight, dRadius, bTapB, bTapT) ; else if ( pCurve->GetTempProp( 1) == 1) { - if ( ptI.y > ptF.y) + if ( ptStart.y > ptEnd.y) SurfCyl_Milling( nGrid, ptI, ptF, vtToolDir, dHeight, dRadius, true, bTapB, bTapT) ; else SurfCyl_Milling( nGrid, ptI, ptF, - vtToolDir, dHeight, dRadius, false, bTapB, bTapT) ; } } } - // Se X crescente, è un cono con vettore equiverso a quello dell'utensile + // Se X crescente, � un cono con vettore equiverso a quello dell'utensile else if ( ptStart.x > ptEnd.x) { double dMaxRad = ptStart.x ; double dMinRad = ptEnd.x ; if ( m_Tool.GetCuttingFlag()) CompConus_Milling( nGrid, ptI, ptF, vtToolDir, dHeight, dMaxRad, dMinRad, bTapB, bTapT, vtNormSt, vtNormEn) ; else if ( pCurve->GetTempProp( 1) == 1) { - if ( ptI.y > ptF.y) + if ( ptStart.y > ptEnd.y) SurfConus_Milling( nGrid, ptI, ptF, vtToolDir, dHeight, dMaxRad, dMinRad, true, bTapB, bTapT, vtNormSt, vtNormEn) ; else { - Point3d ptIn = ptI - vtToolDir * dHeight ; + Point3d ptIn = ptI /*- vtToolDir * dSignedHeight*/ ; Point3d ptFn = ptIn + vtMove ; /*vtNormEn.z *= -1 ; vtNormSt.z *= -1 ;*/ @@ -3440,18 +3445,18 @@ VolZmap::GenTool_Milling( int nGrid, const Point3d& ptS, const Point3d& ptE, con } } } - // Se X decrescente, è un cono con vettore opposto a quello dell'utensile + // Se X decrescente, � un cono con vettore opposto a quello dell'utensile else if ( ptStart.x < ptEnd.x) { double dMaxRad = ptEnd.x ; double dMinRad = ptStart.x ; - Point3d ptIn = ptI - vtToolDir * dHeight ; + Point3d ptIn = ptI - vtToolDir * dSignedHeight ; Point3d ptFn = ptIn + vtMove ; vtNormEn.z *= -1 ; vtNormSt.z *= -1 ; if ( m_Tool.GetCuttingFlag()) CompConus_Milling( nGrid, ptIn, ptFn, - vtToolDir, dHeight, dMaxRad, dMinRad, bTapT, bTapB, vtNormEn, vtNormSt) ; else if ( pCurve->GetTempProp( 1) == 1) { - if ( ptI.y > ptF.y) + if ( ptStart.y > ptEnd.y) SurfConus_Milling( nGrid, ptIn, ptFn, - vtToolDir, dHeight, dMaxRad, dMinRad, true, bTapT, bTapB, vtNormEn, vtNormSt) ; else { /*vtNormEn.z *= -1 ; @@ -3461,7 +3466,7 @@ VolZmap::GenTool_Milling( int nGrid, const Point3d& ptS, const Point3d& ptE, con } } } - else if ( m_Tool.GetCuttingFlag() && pCurve->GetTempProp( 1) == 1) { + else if ( ! m_Tool.GetCuttingFlag() && pCurve->GetTempProp( 1) == 1) { if ( ptStart.x < ptEnd.x) { SurfCircCrown_Milling( nGrid, ptI, ptF, vtToolDir, ptEnd.x, ptStart.x) ; } @@ -3495,10 +3500,10 @@ VolZmap::GenTool_Milling( int nGrid, const Point3d& ptS, const Point3d& ptE, con } else if ( dStH > 0) { SurfSphericalShellPart_Milling( nGrid, ptCenS, ptCenE, - vtToolDir, dRadius, 0, dStH, true) ; - SurfSphericalShellPart_Milling( nGrid, ptCenS, ptCenE, vtToolDir, dRadius, 0, dEnH, true) ; + SurfSphericalShellPart_Milling( nGrid, ptCenS, ptCenE, vtToolDir, dRadius, 0, - dEnH, true) ; } else { - SurfSphericalShellPart_Milling( nGrid, ptCenS, ptCenE, vtToolDir, dRadius, dEnH, dStH, true) ; + SurfSphericalShellPart_Milling( nGrid, ptCenS, ptCenE, vtToolDir, dRadius, - dEnH, - dStH, true) ; } } // Tagliente interno @@ -3511,9 +3516,10 @@ VolZmap::GenTool_Milling( int nGrid, const Point3d& ptS, const Point3d& ptE, con SurfSphericalShellPart_Milling( nGrid, ptCenS, ptCenE, - vtToolDir, dRadius, 0, abs( dEnH), false) ; } else { - SurfSphericalShellPart_Milling( nGrid, ptCenS, ptCenE, - vtToolDir, dRadius, abs( dStH), abs( dEnH), false) ; + SurfSphericalShellPart_Milling( nGrid, ptCenS, ptCenE, - vtToolDir, dRadius, abs( dEnH), abs( dStH), false) ; } - } + } + dSignedHeight = ptStart.y - ptEnd.y ; } // aggiorno l'altezza //dHeight = abs( ptStart.y - ptEnd.y) ; @@ -3593,9 +3599,9 @@ VolZmap::CompConus_ZDrilling( int nGrid, const Point3d& ptS, const Point3d& ptE, double dAngC = dHei / ( dMaxRad - dMinRad) ; double dSqMinRad = dMinRad * dMinRad ; double dSqMaxRad = dMaxRad * dMaxRad ; - double dSafeSqMaxRad = dSqMaxRad - 2 * dMaxRad * EPS_SMALL ; // Questa variabile è sperimentale: serve per evitare il taglio di un dexel dalla parte cilindrica del volume spazzato dalla traslazione del cono. - double dDeltaR = dMaxRad - dMinRad ; // Per tornare alla versione precedente basta sostituire dSafeSqMaxRad con dSqMaxRad. Per risolvere il problema in modo forse più sicuro, ma - // computazionalmente più pesante è sottrarre prima il cilindro con dSafeSqMaxRad e dopo il cono con dSqMaxRad. + double dSafeSqMaxRad = dSqMaxRad - 2 * dMaxRad * EPS_SMALL ; // Questa variabile � sperimentale: serve per evitare il taglio di un dexel dalla parte cilindrica del volume spazzato dalla traslazione del cono. + double dDeltaR = dMaxRad - dMinRad ; // Per tornare alla versione precedente basta sostituire dSafeSqMaxRad con dSqMaxRad. Per risolvere il problema in modo forse pi� sicuro, ma + // computazionalmente pi� pesante � sottrarre prima il cilindro con dSafeSqMaxRad e dopo il cono con dSqMaxRad. // Studio delle simmetrie if ( vtToolDir.z > 0) { dZMin = ( ptS.z < ptE.z ? ptS.z - dHei : ptE.z - dHei) ; @@ -3628,7 +3634,7 @@ VolZmap::CompConus_ZDrilling( int nGrid, const Point3d& ptS, const Point3d& ptE, SubtractIntervals( nGrid, i, j, dZMin, dZMax, Z_AX, -Z_AX) ; } - else if ( dSqDist < dSafeSqMaxRad) { // dSafeSqMaxRad è sperimentale + else if ( dSqDist < dSafeSqMaxRad) { // dSafeSqMaxRad � sperimentale double dr = sqrt( dSqDist) ; @@ -3777,7 +3783,7 @@ VolZmap::CompCyl_ZMilling( int nGrid, const Point3d& ptS, const Point3d& ptE, co // Definizione di un sistema di riferimento ad hoc Vector3d vtV1, vtV2 ; - // Se la lunghezza è troppo piccola lo allungo + // Se la lunghezza � troppo piccola lo allungo if ( dLenXY < EPS_SMALL) vtV1 = ( 1 / dLenXY) * vtMoveXY ; else @@ -4185,7 +4191,7 @@ VolZmap::CompConus_ZMilling( int nGrid, const Point3d& ptS, const Point3d& ptE, } //---------------------------------------------------------------------------- -bool // E' in realtà MillingPerp +bool // E' in realt� MillingPerp VolZmap::CompPar_ZMilling( int nGrid, double dLenX, double dLenY, double dLenZ, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtToolDir, const Vector3d& vtAux) @@ -4322,7 +4328,7 @@ VolZmap::CompConus_Drilling( int nGrid, const Point3d& ptS, const Point3d& ptE, Frame3d ConusFrame ; ConusFrame.Set( ptVertex, vtToolDir) ; Frame3d CylFrame = ConusFrame ; CylFrame.Translate( vtToolDir * dConeMaxH) ; - // L'altezza del cilindro è il movimento + // L'altezza del cilindro � il movimento double dH = ( ptE - ptS).Len() ; for ( int i = nStartI ; i <= nEndI ; ++ i) { @@ -4464,7 +4470,7 @@ VolZmap::CompCyl_Milling( int nGrid, const Point3d& ptS, const Point3d& ptE, SubtractIntervals( nGrid, i, j, ptInt1.z, ptInt2.z, vtN1, vtN2) ; } - // Cilindro finale:L'unica differenza rispetto a prima è l'origine + // Cilindro finale:L'unica differenza rispetto a prima � l'origine // del sistema di riferimento, quindi usiamo lo stesso sistema sommando a ptC // il vettore che congiunge le due origini. CylFrame.ChangeOrig( ptITip + vtMove) ; @@ -4487,7 +4493,7 @@ VolZmap::CompCyl_Milling( int nGrid, const Point3d& ptS, const Point3d& ptE, SubtractIntervals( nGrid, i, j, ptInt1.z, ptInt2.z, vtN1, vtN2) ; } - // Cilindro ellittico di base: L'unica differenza rispetto a prima è l'origine + // Cilindro ellittico di base: L'unica differenza rispetto a prima � l'origine // del sistema di riferimento, quindi usiamo lo stesso sistema sommando a ptC // il vettore che congiunge le due origini. CylFrame.ChangeOrig( ptITip + dHei * vtV1) ; @@ -4798,7 +4804,7 @@ VolZmap::CompConus_Milling( int nGrid, const Point3d& ptS, const Point3d& ptE, c } } } - // Se il poliedro è attraversato taglio + // Se il poliedro � attraversato taglio if ( nIntNum == 2) { // Riporto le intersezioni nel sistema griglia @@ -5030,7 +5036,7 @@ VolZmap::CompBall_Milling( int nGrid, const Point3d& ptLs, const Point3d& ptLe, // vtLineDir, e la superficie definita da una corona circolare nello spazio, descritta dal centro delle // circonferenze di frontiera, dal versore del loro asse di simmetria rotazionale e dai loro raggi. // Il versore normale alla superficie coincide con quello dell'asse di simmetria e quello vtN -// dell'intersezione è opposto ad'esso. +// dell'intersezione � opposto ad'esso. int VolZmap::IntersLineCircCrown( const Point3d& ptLineP, const Vector3d& vtLineDir, const Point3d& ptCen, const Vector3d& vtAx, double dMaxRad, double dMinRad, @@ -5056,7 +5062,7 @@ VolZmap::IntersLineCircCrown( const Point3d& ptLineP, const Vector3d& vtLineDir, if ( nIntType == ILPT_YES /* || nIntType == ILPT_START || nIntType == ILPT_END*/) { // Se il punto d'intersezione sta nella corona double dSqIntCenDist = ( ptInt - ptCen) * ( ptInt - ptCen) ; - if ( dSqIntCenDist > dSqMinRad && dSqIntCenDist > dSqMaxRad) { + if ( dSqIntCenDist > dSqMinRad && dSqIntCenDist < dSqMaxRad) { vtN = - vtAx ; return 1 ; } @@ -5069,7 +5075,7 @@ VolZmap::IntersLineCircCrown( const Point3d& ptLineP, const Vector3d& vtLineDir, // Calcola l'intersezione di una retta, descritta da punto iniziale ptLineP e versore della // direzione vtLineDir, e la superficie definita da un parallelogramma nello spazio, descritto da un punto // ptParOrig e i vettori che da esso spiccano. -// Se bExtNorm è true la normale alla superficie ha lo stesso verso di vtSeg2 ^ vtSeg1, altrimenti +// Se bExtNorm � true la normale alla superficie ha lo stesso verso di vtSeg2 ^ vtSeg1, altrimenti // quello opposto. int VolZmap::IntersLineParallelogram( const Point3d& ptLineP, const Vector3d& vtLineDir, @@ -5096,14 +5102,20 @@ VolZmap::IntersLineParallelogram( const Point3d& ptLineP, const Vector3d& vtLine Vector3d vtIntV = ptInt - ptParOrig ; double dIntPerp = vtIntV * vtPerpToUnit2 ; double dIntLong = vtIntV * vtUnit2 ; - if ( dIntPerp > 0 && dIntPerp < dSegProjPerpLen1 && - dIntLong * dSegProjPerpLen1 > dIntPerp * dSegProjLongLen1 && - ( dIntLong - dLen2) * dSegProjPerpLen1 < dIntPerp * dSegProjLongLen1) { - vtN = bExtNorm ? - vtPlaneN : vtPlaneN ; + if ( dIntPerp > 0 - EPS_SMALL && dIntPerp < dSegProjPerpLen1 + EPS_SMALL && + ( dIntLong + EPS_SMALL) * dSegProjPerpLen1 > dIntPerp * dSegProjLongLen1 && + ( dIntLong - dLen2 - EPS_SMALL) * dSegProjPerpLen1 < dIntPerp * dSegProjLongLen1) { + vtN = bExtNorm ? vtPlaneN : - vtPlaneN ; return 1 ; } - // Oppure crei poliline e chiami la funzione per testare se - // un punto è interno o meno a una polyline chiusa e piana. + /*if ( dIntPerp >= 0 && dIntPerp <= dSegProjPerpLen1 && + ( dIntLong) * dSegProjPerpLen1 >= dIntPerp * dSegProjLongLen1 && + ( dIntLong - dLen2) * dSegProjPerpLen1 <= dIntPerp * dSegProjLongLen1) { + vtN = bExtNorm ? vtPlaneN : - vtPlaneN ; + return 1 ; + }*/ + // Oppure crei polyline e chiami la funzione per testare se + // un punto � interno o meno a una polyline chiusa e piana. } return 0 ; @@ -5113,7 +5125,7 @@ VolZmap::IntersLineParallelogram( const Point3d& ptLineP, const Vector3d& vtLine // Calcola le intersezioni di una retta con la superficie ottenuta dal taglio di un cilindro, inteso come la sola superficie // laterale, con un numero arbitrario di piani. // Nel taglio del cilindro si esclude la parte che sta nel semispazio verso cui punta la normale al piano. -// Il cilindro è descritto dal centro della base ptBaseCen, dal versore vtAx del suo asse di simmetria, dal raggio dRad, +// Il cilindro � descritto dal centro della base ptBaseCen, dal versore vtAx del suo asse di simmetria, dal raggio dRad, // dall'altezza dH e da un flag bInOut che indica se il campo delle normali al cilindro volge verso l'asse di simmetria o meno. // I piani devono essere espressi nello stesso sistema di riferimento in cui sono espressi i punti e i vettori che descrivono // retta e cilindro. @@ -5126,16 +5138,16 @@ VolZmap::IntersLineCylinderCuttedByPlanes( const Point3d& ptLineP, const Vector3 const vector& vPlanesVec, Point3d& ptInt1, Vector3d& vtN1, Point3d& ptInt2, Vector3d& vtN2) const { - // Se il raggio non è sufficientemente grande, non devo fare alcunché. + // Se il raggio non � sufficientemente grande, non devo fare alcunch�. if ( dRad < EPS_SMALL) return 0 ; - // Definisco il sistema di riferimento S; se non è possibile, c'è un errore. + // Definisco il sistema di riferimento S; se non � possibile, c'� un errore. Frame3d frFrameS ; if ( ! frFrameS.Set( ptBaseCen, vtAx)) return 0 ; - // Se l'altezza è negativa, cambio sistema di riferimento. + // Se l'altezza � negativa, cambio sistema di riferimento. if ( dH < 0) { frFrameS.Translate( dH * frFrameS.VersZ()) ; dH *= - 1 ; @@ -5145,7 +5157,7 @@ VolZmap::IntersLineCylinderCuttedByPlanes( const Point3d& ptLineP, const Vector3 Point3d ptP = ptLineP ; ptP.ToLoc( frFrameS) ; Vector3d vtV = vtLineDir ; vtV.ToLoc( frFrameS) ; - // Se la retta è parallela all'asse, non ci sono intersezioni. + // Se la retta � parallela all'asse, non ci sono intersezioni. if ( vtV.SqLenXY() < EPS_ZERO * EPS_ZERO) return 0 ; @@ -5184,7 +5196,7 @@ VolZmap::IntersLineCylinderCuttedByPlanes( const Point3d& ptLineP, const Vector3 -- nRoot ; } - // Esprimo punti e vettori nel sistema in cui è immerso S. + // Esprimo punti e vettori nel sistema in cui � immerso S. if ( nRoot > 0) { ptInt1.ToGlob( frFrameS) ; vtN1.ToGlob( frFrameS) ; @@ -5195,14 +5207,17 @@ VolZmap::IntersLineCylinderCuttedByPlanes( const Point3d& ptLineP, const Vector3 } // Elimino le intersezioni sul cono che non fanno parte della superficie. + bool bSecIntToTest = nRoot > 1 ; for ( int n = 0 ; n < int( vPlanesVec.size()) && nRoot > 0 ; ++ n) { - if ( DistPointPlane( ptInt1, vPlanesVec[n]) > 0) { + if ( /*DistPointPlane( ptInt1, vPlanesVec[n]) > 0*/ DistPointPlane( ptInt1, vPlanesVec[n]) >= 0) { ptInt1 = ptInt2 ; vtN1 = vtN2 ; -- nRoot ; } - if ( nRoot > 0 && DistPointPlane( ptInt2, vPlanesVec[n]) > 0) + if ( /*bSecIntToTest && nRoot > 0 && DistPointPlane( ptInt2, vPlanesVec[n]) > 0*/bSecIntToTest && nRoot > 0 && DistPointPlane( ptInt2, vPlanesVec[n]) >= 0) { + bSecIntToTest = false ; -- nRoot ; + } } return nRoot ; @@ -5212,7 +5227,7 @@ VolZmap::IntersLineCylinderCuttedByPlanes( const Point3d& ptLineP, const Vector3 // Calcola le intersezioni di una retta con una superficie di traslazione di una circonferenza di un vettore vtSweptVec // tagliata da un numero arbitrario di piani. // Nel taglio della superficie di traslazione si esclude la parte che sta nel semispazio verso cui punta la normale al piano. -// La circonferenza è descritta dal centro ptCen, dal versore vtAx del suo asse di simmetria rotazionale e dal raggio dRad. +// La circonferenza � descritta dal centro ptCen, dal versore vtAx del suo asse di simmetria rotazionale e dal raggio dRad. // Il flag bInOut indica se la proiezione sul piano della circonferenza del campo delle normail alla superficie volge verso il // centro di quest'ultima o meno. // I piani devono essere espressi nello stesso sistema di riferimento in cui sono espressi i punti e i vettori che descrivono @@ -5226,7 +5241,7 @@ VolZmap::IntersLineCircSweptSurfCuttedByPlanes( const Point3d& ptLineP, const Ve const vector& vPlanesVec, Point3d& ptInt1, Vector3d& vtN1, Point3d& ptInt2, Vector3d& vtN2) const { - // Se il raggio non è sufficientemente grande, non devo fare alcunché. + // Se il raggio non � sufficientemente grande, non devo fare alcunch�. if ( dRad < EPS_SMALL) return 0 ; @@ -5243,14 +5258,18 @@ VolZmap::IntersLineCircSweptSurfCuttedByPlanes( const Point3d& ptLineP, const Ve double dLongVecLen = vtMySweptVec * vtAx ; double dOrtVecLen = sqrt( max( vtMySweptVec.SqLen() - dLongVecLen * dLongVecLen, 0.)) ; - // Definisco il sistema di riferimento S; se non è possibile, c'è un errore. + // Definisco il sistema di riferimento S; se non � possibile, c'� un errore. Vector3d vtV1 = vtMySweptVec - dLongVecLen * vtAx ; Frame3d frFrameS ; - if ( ! frFrameS.Set( ptMyCen, vtV1, vtAx ^ vtV1, vtAx)) + if ( ! vtV1.Normalize()) { + if ( ! frFrameS.Set( ptMyCen, vtAx)) + return 0 ; + } + else if ( ! frFrameS.Set( ptMyCen, vtV1, vtAx ^ vtV1, vtAx)) return 0 ; // Se la suerficie degenera in un piano, non bisogna tagliare - if ( abs( dLongVecLen) < EPS_SMALL) + if ( abs( dLongVecLen) < /*EPS_SMALL*/EPS_ZERO) return 0 ; // Porto la linea nel riferimento S @@ -5268,38 +5287,36 @@ VolZmap::IntersLineCircSweptSurfCuttedByPlanes( const Point3d& ptLineP, const Ve // Quadrato del raggio, coefficiente angolare della retta di movimento nel // piano ZX del sistema di riferimento del movimento e suo quadrato double dSqRad = dRad * dRad ; - double dObCoef = dLongVecLen / dOrtVecLen ; - double dSqCoef = dObCoef * dObCoef ; + double dSqLongLen = dLongVecLen * dLongVecLen ; + double dSqOrtLen = dOrtVecLen * dOrtVecLen ; // Setto i coeficienti dell'equazione d'intersezione della // retta con la superficie di traslazione della circonferenza. DBLVECTOR vdCoef(3) ; - vdCoef[0] = dSqCoef * ( ptP.x * ptP.x + ptP.y * ptP.y) + ptP.z * ptP.z - - 2 * dObCoef * ptP.x * ptP.z - dSqCoef * dSqRad ; - vdCoef[1] = 2 * dSqCoef * ( ptP.x * vtV.x + ptP.y * vtV.y) + 2 * ptP.z * vtV.z - 2 * dObCoef * ( ptP.x * vtV.z + ptP.z * vtV.x) ; - vdCoef[2] = dSqCoef * ( vtV.x * vtV.x + vtV.y * vtV.y) + vtV.z * vtV.z - 2 * dObCoef * vtV.x * vtV.z ; + vdCoef[0] = dSqLongLen * ( ptP.x * ptP.x + ptP.y * ptP.y) + dSqOrtLen * ptP.z * ptP.z + - 2 * dLongVecLen * dOrtVecLen * ptP.x * ptP.z - dSqLongLen * dSqRad ; + vdCoef[1] = 2 * dSqLongLen * ( ptP.x * vtV.x + ptP.y * vtV.y) + 2 * dSqOrtLen * ptP.z * vtV.z + - 2 * dLongVecLen * dOrtVecLen * ( ptP.x * vtV.z + ptP.z * vtV.x) ; + vdCoef[2] = dSqLongLen * ( vtV.x * vtV.x + vtV.y * vtV.y) + dSqOrtLen * vtV.z * vtV.z + - 2 * dLongVecLen * dOrtVecLen * vtV.x * vtV.z ; // Numero di soluzioni DBLVECTOR vdRoots ; int nRoot = PolynomialRoots( 2, vdCoef, vdRoots) ; - - dObCoef = dLongVecLen / dOrtVecLen ; - dSqCoef = dObCoef * dObCoef ; - // L'equazione ammette o due soluzioni (eventualmente // coincidenti) oppure nessuna o infinite se la la retta // appartiene alla superficie - // Se numero di soluzioni diverso da due le eventuali intersezioni sono già state trovate + // Se numero di soluzioni diverso da due le eventuali intersezioni sono gi� state trovate if ( nRoot != 2) return 0 ; // Punti di intersezione e versori alla superficie in corrispondenza di essi ptInt1 = ptP + vdRoots[0] * vtV ; ptInt2 = ptP + vdRoots[1] * vtV ; - vtN1.Set( dSqCoef * ptInt1.x - dObCoef * ptInt1.z, dSqCoef * ptInt1.y, ptInt1.z - dObCoef * ptInt1.x) ; - vtN1.Normalize() ; - vtN2.Set( dSqCoef * ptInt2.x - dObCoef * ptInt2.z, dSqCoef * ptInt2.y, ptInt2.z - dObCoef * ptInt2.x) ; - vtN2.Normalize() ; + vtN1.Set( dSqLongLen * ptInt1.x - dLongVecLen * dOrtVecLen * ptInt1.z, dSqLongLen * ptInt1.y, dSqOrtLen * ptInt1.z - dLongVecLen * dOrtVecLen * ptInt1.x) ; + vtN1.Normalize( EPS_ZERO) ; + vtN2.Set( dSqLongLen * ptInt2.x - dLongVecLen * dOrtVecLen * ptInt2.z, dSqLongLen * ptInt2.y, dSqOrtLen * ptInt2.z - dLongVecLen * dOrtVecLen * ptInt2.x) ; + vtN2.Normalize( EPS_ZERO) ; if ( ! bInOut) { vtN1 *= - 1 ; vtN2 *= - 1 ; @@ -5315,7 +5332,7 @@ VolZmap::IntersLineCircSweptSurfCuttedByPlanes( const Point3d& ptLineP, const Ve -- nRoot ; } - // Esprimo punti e vettori nel sistema in cui è immerso S. + // Esprimo punti e vettori nel sistema in cui � immerso S. if ( nRoot > 0) { ptInt1.ToGlob( frFrameS) ; vtN1.ToGlob( frFrameS) ; @@ -5326,14 +5343,19 @@ VolZmap::IntersLineCircSweptSurfCuttedByPlanes( const Point3d& ptLineP, const Ve } // Escludo le soluzioni che non stanno dalla parte ammissibile rispetto al piano. + bool bSecIntToTest = nRoot > 1 ; for ( int n = 0 ; n < int( vPlanesVec.size()) && nRoot > 0 ; ++ n) { - if ( DistPointPlane( ptInt1, vPlanesVec[n]) > 0) { + double dDist1 = DistPointPlane(ptInt1, vPlanesVec[n]); + if ( DistPointPlane( ptInt1, vPlanesVec[n]) > 0 + EPS_SMALL/*DistPointPlane( ptInt1, vPlanesVec[n]) >= 0*/) { ptInt1 = ptInt2 ; vtN1 = vtN2 ; -- nRoot ; } - if ( nRoot > 0 && DistPointPlane( ptInt2, vPlanesVec[n]) > 0) + double dDist2 = DistPointPlane(ptInt2, vPlanesVec[n]); + if ( bSecIntToTest && nRoot > 0 && DistPointPlane( ptInt2, vPlanesVec[n]) > 0 + EPS_SMALL/*bSecIntToTest && nRoot > 0 && DistPointPlane( ptInt2, vPlanesVec[n]) >= 0*/) { + bSecIntToTest = false ; -- nRoot ; + } } return nRoot ; @@ -5343,7 +5365,7 @@ VolZmap::IntersLineCircSweptSurfCuttedByPlanes( const Point3d& ptLineP, const Ve // Calcola le intersezioni di una retta con la superficie ottenuta dal taglio di un cono, inteso come la sola superficie // laterale, con un numero arbitrario di piani. // Nel taglio del cono si esclude la parte che sta nel semispazio verso cui punta la normale al piano. -// Il cono è descritto dal vertice ptVert, dal versore vtAx del suo asse di simmetria, dal raggio dRad, dall'altezza dH +// Il cono � descritto dal vertice ptVert, dal versore vtAx del suo asse di simmetria, dal raggio dRad, dall'altezza dH // e da un flag bInOut che indica se il campo delle normali al cono volge verso l'asse di simmetria o meno. // I piani devono essere espressi nello stesso sistema di riferimento in cui sono espressi i punti e i vettori che descrivono // retta e cono. @@ -5356,7 +5378,7 @@ VolZmap::IntersLineConeCuttedByPlanes( const Point3d& ptLineP, const Vector3d& v const vector& vPlanesVec, Point3d& ptInt1, Vector3d& vtN1, Point3d& ptInt2, Vector3d& vtN2) const { - // Definisco il sistema di riferimento S; se non è possibile, c'è un errore. + // Definisco il sistema di riferimento S; se non � possibile, c'� un errore. Frame3d frFrameS ; if ( ! frFrameS.Set( ptVert, vtAx)) return 0 ; @@ -5377,9 +5399,9 @@ VolZmap::IntersLineConeCuttedByPlanes( const Point3d& ptLineP, const Vector3d& v DBLVECTOR vdRoots ; int nRoot = PolynomialRoots( 2, vdCoef, vdRoots) ; - // Se non ho trovato soluzioni, ho terminato. - if ( nRoot == 0) - return nRoot ; + // Se non ho trovato soluzioni, ovvero si � stata trovata una soluzione di tangenza, ho terminato. + if ( nRoot == 0 || ( nRoot == 1 && abs( vtV.z) < EPS_ZERO)) + return 0 ; // Intersezioni ptInt1 = ptP + vdRoots[0] * vtV ; @@ -5404,7 +5426,7 @@ VolZmap::IntersLineConeCuttedByPlanes( const Point3d& ptLineP, const Vector3d& v if ( nRoot > 0 && ( ptInt2.z < 0 || ptInt2.z > dH)) -- nRoot ; - // Esprimo punti e vettori nel sistema in cui è immerso S. + // Esprimo punti e vettori nel sistema in cui � immerso S. if ( nRoot > 0) { ptInt1.ToGlob( frFrameS) ; vtN1.ToGlob( frFrameS) ; @@ -5415,14 +5437,17 @@ VolZmap::IntersLineConeCuttedByPlanes( const Point3d& ptLineP, const Vector3d& v } // Elimino le intersezioni sul cono che non fanno parte della superficie. + bool bSecIntToTest = nRoot > 1 ; for ( int n = 0 ; n < int( vPlanesVec.size()) && nRoot > 0 ; ++ n) { - if ( DistPointPlane( ptInt1, vPlanesVec[n]) > 0) { + if ( /*DistPointPlane( ptInt1, vPlanesVec[n]) > 0*/DistPointPlane( ptInt1, vPlanesVec[n]) >= 0) { ptInt1 = ptInt2 ; vtN1 = vtN2 ; -- nRoot ; } - if ( nRoot > 0 && DistPointPlane( ptInt2, vPlanesVec[n]) > 0) + if ( /*bSecIntToTest && nRoot > 0 && DistPointPlane( ptInt2, vPlanesVec[n]) > 0*/bSecIntToTest && nRoot > 0 && DistPointPlane( ptInt2, vPlanesVec[n]) >= 0) { + bSecIntToTest = false ; -- nRoot ; + } } return nRoot ; @@ -5431,7 +5456,7 @@ VolZmap::IntersLineConeCuttedByPlanes( const Point3d& ptLineP, const Vector3d& v //---------------------------------------------------------------------------- // Calcola le intersezioni di una retta con una superficie sferica tagliata da un numero arbitrario di piani. // Nel taglio della sfera si esclude la parte che sta nel semispazio verso cui punta la normale al piano. -// Il cono è descritto dal vertice ptVert, dal versore vtAx del suo asse di simmetria, dal raggio dRad, dall'altezza dH +// Il cono � descritto dal vertice ptVert, dal versore vtAx del suo asse di simmetria, dal raggio dRad, dall'altezza dH // e da un flag bInOut che indica se il campo delle normali volge verso l'interno della sfera o meno. // I piani devono essere espressi nello stesso sistema di riferimento in cui sono espressi i punti e i vettori che descrivono // retta e cono. @@ -5461,19 +5486,58 @@ VolZmap::IntersLineSphereCuttedByPlanes( const Point3d& ptLineP, const Vector3d& // Escludo le soluzioni fuori dalla parte ammissibile. + bool bSecIntToTest = nSol > 1 ; for ( int n = 0 ; n < int( vPlanesVec.size()) && nSol != 0 ; ++ n) { - if ( DistPointPlane( ptInt1, vPlanesVec[n]) > 0) { + if ( /*DistPointPlane( ptInt1, vPlanesVec[n]) > 0*/DistPointPlane( ptInt1, vPlanesVec[n]) >= 0) { ptInt1 = ptInt2 ; vtN1 = vtN2 ; -- nSol ; } - if ( nSol > 0 && DistPointPlane( ptInt2, vPlanesVec[n]) > 0) + if ( /*bSecIntToTest && nSol > 0 && DistPointPlane( ptInt2, vPlanesVec[n]) > 0*/bSecIntToTest && nSol > 0 && DistPointPlane( ptInt2, vPlanesVec[n]) >= 0) { + bSecIntToTest = false ; -- nSol ; + } } return nSol ; } +//---------------------------------------------------------------------------- +// Il vettore normale alla superficie deve essere passato gi� normalizzato. +int +VolZmap::IntersLineCatTongue( const Point3d& ptLineP, const Vector3d& vtLineD, + const Point3d& ptCenSt, const Point3d& ptCenEn, const Vector3d& vtNorm, double dRad, + Point3d& ptInt, Vector3d& vtN) const +{ + // Definisco il piano. + Plane3d plPlane ; + if ( ! plPlane.Set( ptCenSt, vtNorm)) + return 0 ; + + // Intersezione retta piano + int nIntType = IntersLinePlane( ptLineP, vtLineD, 1000, plPlane, ptInt, false) ; + if ( nIntType == ILPT_YES /* || nIntType == ILPT_START || nIntType == ILPT_END*/) { + // Creo un sistema di riferimento per stabilire se l'intersezione avviene in un + // punto del piano interno alla superficie o meno. + Vector3d vtLong = ptCenEn - ptCenSt ; + double dLongLen = vtLong.Len() ; + vtLong /= dLongLen ; + Vector3d vtTrasv = vtNorm ^ vtLong ; + // Determino se l'intersezione � sulla superficie + Vector3d vtIntV = ptInt - ptCenSt ; + double dIntLong = vtIntV * vtLong ; + double dIntTrasv = vtIntV * vtTrasv ; + double dInfLongLim = sqrt( max( dRad * dRad - dIntTrasv * dIntTrasv, 0.)) ; + double dSupLongLim = dLongLen + dInfLongLim ; + if ( abs( dIntTrasv) < dRad && dIntLong > dInfLongLim && dIntLong < dSupLongLim) { + vtN = - vtNorm ; + return 1 ; + } + } + + return 0 ; +} + // Filtro per le intersezioni typedef vector> DexelSurfIntersVector ; @@ -5490,13 +5554,13 @@ IntersectionsFilter( const Vector3d& vtDexDir, const DexelSurfIntersVector& vOri DexelSurfIntersVector vEntrancesVec, vExitsVec, vIndefVec ; for ( int n = 0 ; n < int( vOrigineIntersVec.size()) ; ++ n) { if ( vOrigineIntersVec[n].second * vtDexDir < - dDotEps) { - vEntrancesVec.emplace_back( vOrigineIntersVec[n]) ; + vExitsVec.emplace_back( vOrigineIntersVec[n]) ; } else if ( vOrigineIntersVec[n].second * vtDexDir > dDotEps) { - vExitsVec.emplace_back( vOrigineIntersVec[n]) ; + vEntrancesVec.emplace_back( vOrigineIntersVec[n]) ; } else { - vIndefVec.emplace_back( vOrigineIntersVec[n]) ; + vIndefVec.emplace_back( vOrigineIntersVec[n]) ; } } @@ -5506,6 +5570,12 @@ IntersectionsFilter( const Vector3d& vtDexDir, const DexelSurfIntersVector& vOri sort( vExitsVec.begin(), vExitsVec.end(), [] ( pair Int1, pair Int2) { return Int1.first < Int2.first ; }) ; + if ( int( vEntrancesVec.size()) == 2 && + int( vExitsVec.size()) == 2 && + abs( vEntrancesVec[0].first - vExitsVec[0].first) < dLenEps && + abs( vEntrancesVec[1].first - vExitsVec[1].first) < dLenEps) + return true ; + // Modo 1 for ( int n = 0 ; n < int( vEntrancesVec.size()) ; ++ n) { for ( int m = 0 ; m < int( vExitsVec.size()) ; ++ m) { @@ -5521,114 +5591,119 @@ IntersectionsFilter( const Vector3d& vtDexDir, const DexelSurfIntersVector& vOri // Modo 2 - // Media delle entrate - double dEntrancesAvarage = 0 ; - for ( int n = 0 ; n < int( vEntrancesVec.size()) ; ++ n) { - dEntrancesAvarage += vEntrancesVec[n].first ; - } - dEntrancesAvarage /= int( vEntrancesVec.size()) ; - // Deviazione standard delle entrate - double dEntrancesStdDev = 0 ; - for ( int n = 0 ; n < int( vEntrancesVec.size()) ; ++ n) { - dEntrancesStdDev += ( vEntrancesVec[n].first - dEntrancesAvarage) * ( vEntrancesVec[n].first - dEntrancesAvarage) ; - } - dEntrancesStdDev = sqrt( dEntrancesStdDev / int( vEntrancesVec.size())) ; - - // Media delle uscite - double dExitsAvarage = 0 ; - for ( int n = 0 ; n < int( vExitsVec.size()) ; ++ n) { - dExitsAvarage += vExitsVec[n].first ; - } - dExitsAvarage /= int( vExitsVec.size()) ; - // Deviazione standard delle uscite - double dExitsStdDev = 0 ; - for ( int n = 0 ; n < int( vExitsVec.size()) ; ++ n) { - dExitsStdDev += ( vExitsVec[n].first - dExitsAvarage) * ( vExitsVec[n].first - dExitsAvarage) ; - } - dExitsStdDev = sqrt( dExitsStdDev / int( vExitsVec.size())) ; + // Media e deviazione standard delle entrate + //double dEntrancesAvarage = 0 ; + //double dEntrancesStdDev = 0 ; + //if ( int( vEntrancesVec.size()) != 0) { + // for ( int n = 0 ; n < int( vEntrancesVec.size()) ; ++ n) { + // dEntrancesAvarage += vEntrancesVec[n].first ; + // } + // dEntrancesAvarage /= int( vEntrancesVec.size()) ; + // for ( int n = 0 ; n < int( vEntrancesVec.size()) ; ++ n) { + // dEntrancesStdDev += ( vEntrancesVec[n].first - dEntrancesAvarage) * ( vEntrancesVec[n].first - dEntrancesAvarage) ; + // } + // dEntrancesStdDev = sqrt( dEntrancesStdDev / int( vEntrancesVec.size())) ; + //} + // + //// Media e deviazione standard delle uscite + //double dExitsAvarage = 0 ; + //double dExitsStdDev = 0 ; + //if ( int( vExitsVec.size()) != 0) { + // for ( int n = 0 ; n < int( vExitsVec.size()) ; ++ n) { + // dExitsAvarage += vExitsVec[n].first ; + // } + // dExitsAvarage /= int( vExitsVec.size()) ; + // for ( int n = 0 ; n < int( vExitsVec.size()) ; ++ n) { + // dExitsStdDev += ( vExitsVec[n].first - dExitsAvarage) * ( vExitsVec[n].first - dExitsAvarage) ; + // } + // dExitsStdDev = sqrt( dExitsStdDev / int( vExitsVec.size())) ; + //} + // + //// Deve esserci almeno un entrata e un uscita + //if ( int( vEntrancesVec.size()) != 0 && int( vExitsVec.size()) != 0) { + // // Caso di un solo gruppo per le entrate + // if ( dEntrancesStdDev < dLenEps) { + // // Caso di un solo gruppo per le uscite + // if ( dExitsStdDev < dLenEps) { + // if ( vExitsVec.back().first > vEntrancesVec[0].first) { + // vFilteredIntersVec.emplace_back( vEntrancesVec[0]) ; + // vFilteredIntersVec.emplace_back( vExitsVec.back()) ; + // } + // } + // // Caso di due gruppi per le uscite + // else { + // // Cerco ultima uscita del primo gruppo + // int n ; + // for ( n = int( vExitsVec.size()) - 1 ; n >= 0 ; -- n) { + // if ( vExitsVec[n].first < dExitsAvarage) + // break ; + // } + // // Aggiungo ingressi e uscite filtrati. + // if ( vExitsVec[n].first > vEntrancesVec[0].first) { + // vFilteredIntersVec.emplace_back( vEntrancesVec[0]) ; + // vFilteredIntersVec.emplace_back( vExitsVec[n]) ; + // } + // else if ( vExitsVec.back().first > vEntrancesVec[0].first) { + // vFilteredIntersVec.emplace_back( vEntrancesVec[0]) ; + // vFilteredIntersVec.emplace_back( vExitsVec.back()) ; + // } + // } + // } + // // Caso di due gruppi per le entrate + // else { + // // Cerco prima entrata del secondo gruppo + // int n ; + // for ( n = 0 ; n < int( vEntrancesVec.size()) ; ++ n) { + // if ( vEntrancesVec[n].first > dEntrancesAvarage) + // break ; + // } + // // Caso di un solo gruppo per le uscite + // if ( dExitsStdDev < dLenEps) { + // // Aggiungo ingressi e uscite filtrati. + // if ( vExitsVec.back().first > vEntrancesVec[n].first) { + // vFilteredIntersVec.emplace_back( vEntrancesVec[n]) ; + // vFilteredIntersVec.emplace_back( vExitsVec.back()) ; + // } + // else if ( vExitsVec.back().first > vEntrancesVec[0].first) { + // vFilteredIntersVec.emplace_back( vEntrancesVec[0]) ; + // vFilteredIntersVec.emplace_back( vExitsVec.back()) ; + // } + // } + // // Caso di due gruppi per le uscite + // else { + // // Cerco ultima uscita del primo gruppo + // int m ; + // for ( m = int( vExitsVec.size()) - 1 ; m >= 0 ; -- m) { + // if ( vExitsVec[m].first < dExitsAvarage) + // break ; + // } + // // Aggiungo ingressi e uscite ai filtri. + // if ( vExitsVec[m].first > vEntrancesVec[0].first) { + // if ( vExitsVec[m].first > vEntrancesVec[n].first) { + // vFilteredIntersVec.emplace_back( vEntrancesVec[0]) ; + // vFilteredIntersVec.emplace_back( vExitsVec.back()) ; + // } + // else if ( vExitsVec.back().first > vEntrancesVec[n].first) { + // vFilteredIntersVec.emplace_back( vEntrancesVec[0]) ; + // vFilteredIntersVec.emplace_back( vExitsVec[m]) ; + // vFilteredIntersVec.emplace_back( vEntrancesVec[n]) ; + // vFilteredIntersVec.emplace_back( vExitsVec.back()) ; + // } + // else { + // vFilteredIntersVec.emplace_back( vEntrancesVec[0]) ; + // vFilteredIntersVec.emplace_back( vExitsVec[m]) ; + // } + // } + // else { + // if ( vExitsVec.back().first > vEntrancesVec[n].first) { + // vFilteredIntersVec.emplace_back( vEntrancesVec[n]) ; + // vFilteredIntersVec.emplace_back( vExitsVec.back()) ; + // } + // } + // } + // } + //} - // Caso di un solo gruppo per le entrate - if ( dEntrancesStdDev < dLenEps) { - // Caso di un solo gruppo per le uscite - if ( dExitsStdDev < dLenEps) { - if ( vExitsVec.back().first > vEntrancesVec[0].first) { - vFilteredIntersVec.emplace_back( vEntrancesVec[0]) ; - vFilteredIntersVec.emplace_back( vExitsVec.back()) ; - } - } - // Caso di due gruppi per le uscite - else { - // Cerco ultima uscita del primo gruppo - int n ; - for ( n = int( vExitsVec.size()) - 1 ; n >= 0 ; -- n) { - if ( vExitsVec[n].first < dExitsAvarage) - break ; - } - // Aggiungo ingressi e uscite filtrati. - if ( vExitsVec[n].first > vEntrancesVec[0].first) { - vFilteredIntersVec.emplace_back( vEntrancesVec[0]) ; - vFilteredIntersVec.emplace_back( vExitsVec[n]) ; - } - else if ( vExitsVec.back().first > vEntrancesVec[0].first) { - vFilteredIntersVec.emplace_back( vEntrancesVec[0]) ; - vFilteredIntersVec.emplace_back( vExitsVec.back()) ; - } - } - } - // Caso di due gruppi per le entrate - else { - // Cerco prima entrata del secondo gruppo - int n ; - for ( n = 0 ; n < int( vEntrancesVec.size()) ; ++ n) { - if ( vEntrancesVec[n].first > dEntrancesAvarage) - break ; - } - // Caso di un solo gruppo per le uscite - if ( dExitsStdDev < dLenEps) { - // Aggiungo ingressi e uscite filtrati. - if ( vExitsVec.back().first > vEntrancesVec[n].first) { - vFilteredIntersVec.emplace_back( vEntrancesVec[n]) ; - vFilteredIntersVec.emplace_back( vExitsVec.back()) ; - } - else if ( vExitsVec.back().first > vEntrancesVec[0].first) { - vFilteredIntersVec.emplace_back( vEntrancesVec[0]) ; - vFilteredIntersVec.emplace_back( vExitsVec.back()) ; - } - } - // Caso di due gruppi per le uscite - else { - // Cerco ultima uscita del primo gruppo - int m ; - for ( m = int( vExitsVec.size()) - 1 ; m >= 0 ; -- m) { - if ( vExitsVec[m].first < dExitsAvarage) - break ; - } - // Aggiungo ingressi e uscite ai filtri. - if ( vExitsVec[m].first > vEntrancesVec[0].first) { - if ( vExitsVec[m].first > vEntrancesVec[n].first) { - vFilteredIntersVec.emplace_back( vEntrancesVec[0]) ; - vFilteredIntersVec.emplace_back( vExitsVec.back()) ; - } - else if ( vExitsVec.back().first > vEntrancesVec[n].first) { - vFilteredIntersVec.emplace_back( vEntrancesVec[0]) ; - vFilteredIntersVec.emplace_back( vExitsVec[m]) ; - vFilteredIntersVec.emplace_back( vEntrancesVec[n]) ; - vFilteredIntersVec.emplace_back( vExitsVec.back()) ; - } - else { - vFilteredIntersVec.emplace_back( vEntrancesVec[0]) ; - vFilteredIntersVec.emplace_back( vExitsVec[m]) ; - } - } - else { - if ( vExitsVec.back().first > vEntrancesVec[n].first) { - vFilteredIntersVec.emplace_back( vEntrancesVec[n]) ; - vFilteredIntersVec.emplace_back( vExitsVec.back()) ; - } - } - } - } - return true ; } @@ -5642,7 +5717,7 @@ VolZmap::SurfCircCrown_ZDrilling( int nGrid, const Point3d& ptS, const Point3d& if ( ! TestCompoBBox( nGrid, ptS, ptE, vtAx, dMaxRad, dMaxRad, 1, nStartI, nStartJ, nEndI, nEndJ)) return true ; - // Se il movimento è in direzione opposta a quella ove la corona può tagliare, non devo fare nulla. + // Se il movimento � in direzione opposta a quella ove la corona pu� tagliare, non devo fare nulla. if ( vtAx.z * ( ptE - ptS).z < EPS_ZERO) return true ; @@ -5669,10 +5744,10 @@ VolZmap::SurfCircCrown_ZDrilling( int nGrid, const Point3d& ptS, const Point3d& Vector3d vtMinN, vtMaxN ; if ( ptE.z < ptS.z) { vtMinN.z = 1 ; - vtMaxN.z = 1 ; + vtMaxN.z = -1 ; } else { - vtMinN.z = - 1 ; + vtMinN.z = 1 ; vtMaxN.z = - 1 ; } SubtractIntervals( nGrid, i, j, dMinZ, dMaxZ, vtMinN, vtMaxN) ; @@ -5692,7 +5767,7 @@ VolZmap::SurfCircCrown_Drilling( int nGrid, const Point3d& ptS, const Point3d& p if ( ! TestCompoBBox( nGrid, ptS, ptE, vtAx, dMaxRad, dMinRad, 1, nStartI, nStartJ, nEndI, nEndJ)) return true ; - // Se il movimento è in direzione opposta a quella ove la corona può tagliare, non devo fare nulla. + // Se il movimento � in direzione opposta a quella ove la corona pu� tagliare, non devo fare nulla. double dMotProjOnAx = vtAx * ( ptE - ptS) ; if ( dMotProjOnAx < EPS_ZERO) return true ; @@ -5703,7 +5778,7 @@ VolZmap::SurfCircCrown_Drilling( int nGrid, const Point3d& ptS, const Point3d& p // Ciclo sui dexel. 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) ; DexelSurfIntersVector vParAndNormIntersVec ; @@ -5757,7 +5832,7 @@ VolZmap::SurfCircCrown_Drilling( int nGrid, const Point3d& ptS, const Point3d& p // Filtro le intersezioni trovate. DexelSurfIntersVector vFilteredIntersVec ; - IntersectionsFilter( Z_AX, vParAndNormIntersVec, vFilteredIntersVec) ; + IntersectionsFilter( Z_AX, vParAndNormIntersVec, vFilteredIntersVec) ; // Sottraggo gli intervalli. for ( int n = 0 ; n < int( vFilteredIntersVec.size()) ; n += 2) { @@ -5780,13 +5855,13 @@ VolZmap::SurfCircCrown_ZMilling( int nGrid, const Point3d& ptS, const Point3d& p //---------------------------------------------------------------------------- bool VolZmap::SurfCircCrown_Milling( int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtAx, double dMaxRad, double dMinRad) -{ +{ // Verifica sull'interferenza utensile Zmap int nStartI, nStartJ, nEndI, nEndJ ; if ( ! TestCompoBBox( nGrid, ptS, ptE, vtAx, dMaxRad, dMaxRad, 1, nStartI, nStartJ, nEndI, nEndJ)) return true ; - // Se il movimento è in direzione opposta a quella ove la corona può tagliare, non devo fare nulla. + // Se il movimento � in direzione opposta a quella ove la corona pu� tagliare, non devo fare nulla. Vector3d vtDisp = ( ptE - ptS) ; double dMotProjOnAx = vtAx * vtDisp ; if ( dMotProjOnAx < EPS_ZERO) @@ -5798,7 +5873,7 @@ VolZmap::SurfCircCrown_Milling( int nGrid, const Point3d& ptS, const Point3d& pt // Ciclo sui dexel. 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) ; DexelSurfIntersVector vParAndNormIntersVec ; @@ -5836,7 +5911,7 @@ VolZmap::SurfCircCrown_Milling( int nGrid, const Point3d& ptS, const Point3d& pt } // Intersezione con corona in posizione inziale - nIntNum = IntersLineCircCrown( ptC, Z_AX, ptS, vtAx, dMaxRad, dMinRad, ptInt1, vtN1) ; + nIntNum = IntersLineCircCrown( ptC, Z_AX, ptS, - vtAx, dMaxRad, dMinRad, ptInt1, vtN1) ; if ( nIntNum == 1) { vParAndNormIntersVec.emplace_back() ; vParAndNormIntersVec.back().first = ptInt1.z ; @@ -5908,6 +5983,31 @@ VolZmap::SurfCyl_ZMilling( int nGrid, const Point3d& ptS, const Point3d& ptE, co Vector3d vtV2 = vtV3 ^ vtV1 ; Point3d ptSxy( ptS.x, ptS.y, 0) ; + // Caso moto perpendicolare + if ( abs( dDispZ) < EPS_SMALL) { + + // Ciclo sui dexel. + 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) ; + double dProj1 = ( ptC - ptSxy) * vtV1 ; + double dProj2 = ( ptC - ptSxy) * vtV2 ; + double dCirc1 = ( bOuterCutter ? 1 : - 1) * sqrt( max( dRad * dRad - dProj2 * dProj2, 0.)) ; + if ( abs( dProj2) < dRad && dProj1 > dCirc1 && dProj1 < dDispXY + dCirc1) { + // Quote minima e massima rispetto al sistema griglia e versori normali associati + double dMin = vtAx.z > 0 ? dStartBotZ : dStartTopZ ; + double dMax = vtAx.z > 0 ? dStartTopZ : dStartBotZ ; + Vector3d vtMin = Z_AX ; + Vector3d vtMax = - Z_AX ; + // Taglio dei dexel + SubtractIntervals( nGrid, i, j, dMin, dMax, vtMin, vtMax) ; + } + } + } + + return true ; + } + // Ciclo sui dexel. for ( int i = nStartI ; i <= nEndI ; ++ i) { for ( int j = nStartJ ; j <= nEndJ ; ++ j) { @@ -5917,8 +6017,8 @@ VolZmap::SurfCyl_ZMilling( int nGrid, const Point3d& ptS, const Point3d& ptE, co double dCirc1 = ( bOuterCutter ? 1 : - 1) * sqrt( max( dRad * dRad - dProj2 * dProj2, 0.)) ; if ( abs( dProj2) < dRad && dProj1 > dCirc1 && dProj1 < dDispXY + dCirc1) { // Quote inferiore e superiore rispetto alla direzione del versore utensile - double dInfZ = dStartBotZ + ( dProj1 - dCirc1) * dDispZ / dDispXY ; - double dSupZ = dStartTopZ + ( dProj1 - dCirc1) * dDispZ / dDispXY ; + double dInfZ = dStartBotZ + ( dProj1 - dCirc1) * dDispZ * vtAx.z / dDispXY ; + double dSupZ = dStartTopZ + ( dProj1 - dCirc1) * dDispZ * vtAx.z / dDispXY ; // Calcolo dei versori normali associati Vector3d vtRad = dCirc1 * vtV1 + dProj2 * vtV2 ; Vector3d vtTan( - vtRad.y, vtRad.x, 0) ; @@ -5947,20 +6047,130 @@ VolZmap::SurfCyl_Milling( int nGrid, const Point3d& ptS, const Point3d& ptE, int nStartI, nStartJ, nEndI, nEndJ ; if ( ! TestCompoBBox( nGrid, ptS, ptE, vtAx, dRad, dRad, dHei, nStartI, nStartJ, nEndI, nEndJ)) return true ; - + // Vettore spostamento Vector3d vtDisp = ptE - ptS ; // Versore della componente del moto ortogonale all'asse dell'utensile double dDispZ = vtDisp * vtAx ; Vector3d vtOrtDisp = vtDisp - dDispZ * vtAx ; - vtOrtDisp.Normalize() ; + double dOrtDispLen = vtOrtDisp.Len() ; + vtOrtDisp /= dOrtDispLen ; // Versore direzione del moto Vector3d vtDispDir = vtDisp ; vtDispDir.Normalize() ; // Versore laterale Vector3d vtLat = vtAx ^ vtOrtDisp ; + // Deduzione dei punti per la definizione dei piani laterali + Point3d ptPlanePlus = ptS - dHei * vtAx + dRad * vtLat ; + Point3d ptPlaneMinus = ptS - dHei * vtAx - dRad * vtLat ; + + // Moto ortogonale all'asse del cilindro + double dObCoef = dDispZ / dOrtDispLen ; + double dMyLength = dObCoef * dRad / sqrt( 1 + dObCoef * dObCoef) ; + if ( abs( dDispZ) < 2 * EPS_SMALL && dMyLength < 2 * EPS_SMALL) { + + Point3d ptMyE = ptS + dOrtDispLen * vtOrtDisp ; + + // Definisco i piani utilizzati per tagliare le superfici elementari. + // Piano per cilindro in posizione iniziale + vector vCutCylPlaneVecSt ; + vCutCylPlaneVecSt.emplace_back() ; + vCutCylPlaneVecSt.back().Set( ptS, ( bOuterCutter ? - 1 : 1) * vtOrtDisp) ; + // Piano per cilindro in posizione finale + vector vCutCylPlaneVecEn ; + vCutCylPlaneVecEn.emplace_back() ; + vCutCylPlaneVecEn.back().Set( ptMyE, ( bOuterCutter ? - 1 : 1) * vtOrtDisp) ; + + 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.) ; + + DexelSurfIntersVector vParAndNormIntersVec ; + Point3d ptInt1, ptInt2 ; + Vector3d vtN1, vtN2 ; + + // Intersezione con cilindro in posizione iniziale + int nIntNum = IntersLineCylinderCuttedByPlanes( ptC, Z_AX, ptS, vtAx, dRad, - dHei, bOuterCutter, vCutCylPlaneVecSt, + ptInt1, vtN1, ptInt2, vtN2) ; + if ( nIntNum >= 1) { + vParAndNormIntersVec.emplace_back() ; + vParAndNormIntersVec.back().first = ptInt1.z ; + vParAndNormIntersVec.back().second = vtN1 ; + if ( nIntNum == 2) { + vParAndNormIntersVec.emplace_back() ; + vParAndNormIntersVec.back().first = ptInt2.z ; + vParAndNormIntersVec.back().second = vtN2 ; + } + } + + // Intersezione con cilindro in posizione finale + nIntNum = IntersLineCylinderCuttedByPlanes( ptC, Z_AX, ptE, vtAx, dRad, - dHei, ! bOuterCutter, vCutCylPlaneVecEn, + ptInt1, vtN1, ptInt2, vtN2) ; + if ( nIntNum >= 1) { + vParAndNormIntersVec.emplace_back() ; + vParAndNormIntersVec.back().first = ptInt1.z ; + vParAndNormIntersVec.back().second = vtN1 ; + if ( nIntNum == 2) { + vParAndNormIntersVec.emplace_back() ; + vParAndNormIntersVec.back().first = ptInt2.z ; + vParAndNormIntersVec.back().second = vtN2 ; + } + } + + // Intersezione con lingua di gatto superiore + nIntNum = IntersLineCatTongue( ptC, Z_AX, bOuterCutter ? ptS : ptMyE, bOuterCutter ? ptMyE : ptS, + vtAx, dRad, ptInt1, vtN1) ; + if ( nIntNum == 1) { + vParAndNormIntersVec.emplace_back() ; + vParAndNormIntersVec.back().first = ptInt1.z ; + vParAndNormIntersVec.back().second = vtN1 ; + } + + // Intersezione con lingua di gatto inferiore + nIntNum = IntersLineCatTongue( ptC, Z_AX, ( bOuterCutter ? ptS : ptMyE) - dHei * vtAx, ( bOuterCutter ? ptMyE : ptS) - dHei * vtAx, + - vtAx, dRad, ptInt1, vtN1) ; + if ( nIntNum == 1) { + vParAndNormIntersVec.emplace_back() ; + vParAndNormIntersVec.back().first = ptInt1.z ; + vParAndNormIntersVec.back().second = vtN1 ; + } + + // Piano + (con normale + vtLat) + nIntNum = IntersLineParallelogram( ptC, Z_AX, ptPlanePlus, dHei * vtAx, vtDisp, + true, ptInt1, vtN1) ; + if ( nIntNum == 1) { + vParAndNormIntersVec.emplace_back() ; + vParAndNormIntersVec.back().first = ptInt1.z ; + vParAndNormIntersVec.back().second = vtN1 ; + } + + // Piano - (con normale - vtLat) + nIntNum = IntersLineParallelogram( ptC, Z_AX, ptPlaneMinus, dHei * vtAx, vtDisp, + false, ptInt1, vtN1) ; + if ( nIntNum == 1) { + vParAndNormIntersVec.emplace_back() ; + vParAndNormIntersVec.back().first = ptInt1.z ; + vParAndNormIntersVec.back().second = vtN1 ; + } + + // Filtro le intersezioni trovate. + DexelSurfIntersVector vFilteredIntersVec ; + IntersectionsFilter( Z_AX, vParAndNormIntersVec, vFilteredIntersVec) ; + + // Sottraggo gli intervalli. + for ( int n = 0 ; n < int( vFilteredIntersVec.size()) ; n += 2) { + SubtractIntervals( nGrid, i, j, vFilteredIntersVec[n].first, vFilteredIntersVec[n+1].first, + vFilteredIntersVec[n].second, vFilteredIntersVec[n+1].second) ; + } + } + } + + return true ; + } + // Definisco i piani utilizzati per tagliare le superfici elementari. // Piano per cilindro in posizione iniziale vector vCutCylPlaneVecSt ; @@ -5991,13 +6201,9 @@ VolZmap::SurfCyl_Milling( int nGrid, const Point3d& ptS, const Point3d& ptE, vCutEllipCylPlaneVecDw.back().Set( ptS - dHei * vtAx, ( bOuterCutter ? - 1 : 1) * vtDispDir ^ vtLat) ; } - // Deduzione dei punti per la definizione dei piani laterali - Point3d ptPlanePlus = ptS - dHei * vtAx + dRad * vtLat ; - Point3d ptPlaneMinus = ptS - dHei * vtAx - dRad * vtLat ; - 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.) ; DexelSurfIntersVector vParAndNormIntersVec ; @@ -6005,7 +6211,7 @@ VolZmap::SurfCyl_Milling( int nGrid, const Point3d& ptS, const Point3d& ptE, Vector3d vtN1, vtN2 ; // Intersezione con cilindro in posizione iniziale - int nIntNum = IntersLineCylinderCuttedByPlanes( ptC, Z_AX, ptS, vtAx, dRad, - dHei, ! bOuterCutter, vCutCylPlaneVecSt, + int nIntNum = IntersLineCylinderCuttedByPlanes( ptC, Z_AX, ptS, vtAx, dRad, - dHei, bOuterCutter, vCutCylPlaneVecSt, ptInt1, vtN1, ptInt2, vtN2) ; if ( nIntNum >= 1) { vParAndNormIntersVec.emplace_back() ; @@ -6043,6 +6249,17 @@ VolZmap::SurfCyl_Milling( int nGrid, const Point3d& ptS, const Point3d& ptE, vParAndNormIntersVec.emplace_back() ; vParAndNormIntersVec.back().first = ptInt2.z ; vParAndNormIntersVec.back().second = vtN2 ; + if ( vCutEllipCylPlaneVecUp.size() == 1) { + if ( SqDist( ptInt1, ptInt2) < EPS_SMALL) { + int bazinga1 = 0 ; + double dLL1 = (ptInt1 - vCutEllipCylPlaneVecUp[0].GetPoint()) * vCutEllipCylPlaneVecUp[0].GetVersN(); + double dLL2 = (ptInt2 - vCutEllipCylPlaneVecUp[0].GetPoint()) * vCutEllipCylPlaneVecUp[0].GetVersN(); + if ( ( ptInt1 - vCutEllipCylPlaneVecUp[0].GetPoint()) * vCutEllipCylPlaneVecUp[0].GetVersN() > 0.) + vParAndNormIntersVec.erase( vParAndNormIntersVec.begin() + int( vParAndNormIntersVec.size()) - 2) ; + else if ( ( ptInt2 - vCutEllipCylPlaneVecUp[0].GetPoint()) * vCutEllipCylPlaneVecUp[0].GetVersN() > 0.) + vParAndNormIntersVec.erase( vParAndNormIntersVec.begin() + int( vParAndNormIntersVec.size()) - 1) ; + } + } } } @@ -6057,6 +6274,17 @@ VolZmap::SurfCyl_Milling( int nGrid, const Point3d& ptS, const Point3d& ptE, vParAndNormIntersVec.emplace_back() ; vParAndNormIntersVec.back().first = ptInt2.z ; vParAndNormIntersVec.back().second = vtN2 ; + if ( vCutEllipCylPlaneVecDw.size() == 1) { + if ( SqDist( ptInt1, ptInt2) < EPS_SMALL) { + int bazinga2 = 0 ; + double dLL1 = (ptInt1 - vCutEllipCylPlaneVecDw[0].GetPoint()) * vCutEllipCylPlaneVecDw[0].GetVersN(); + double dLL2 = (ptInt2 - vCutEllipCylPlaneVecDw[0].GetPoint()) * vCutEllipCylPlaneVecDw[0].GetVersN(); + if ( ( ptInt1 - vCutEllipCylPlaneVecDw[0].GetPoint()) * vCutEllipCylPlaneVecDw[0].GetVersN() > 0.) + vParAndNormIntersVec.erase( vParAndNormIntersVec.begin() + int( vParAndNormIntersVec.size()) - 2) ; + else if ( ( ptInt2 - vCutEllipCylPlaneVecDw[0].GetPoint()) * vCutEllipCylPlaneVecDw[0].GetVersN() > 0.) + vParAndNormIntersVec.erase( vParAndNormIntersVec.begin() + int( vParAndNormIntersVec.size()) - 1) ; + } + } } } @@ -6108,23 +6336,23 @@ VolZmap::SurfConus_ZDrilling( int nGrid, const Point3d& ptS, const Point3d& ptE, double dSqSafeMinRad = dMinRad * dMinRad + 2 * dMinRad * EPS_SMALL ; double dSqSafeMaxRad = dMaxRad * dMaxRad - 2 * dMaxRad * EPS_SMALL ; - // Se il movimento è nella direzione ove il cono non taglia, ho finito. + // Se il movimento � nella direzione ove il cono non taglia, ho finito. if ( vtAx.z * ( ptE.z - ptS.z) > 0 == bOuterCutter) return true ; // Ciclo sui punti for ( int i = nStartI ; i <= nEndI ; ++ i) { for ( int j = nStartJ ; j <= nEndJ ; ++ j) { + + double dX = ( i + 0.5) * m_dStep ; + double dY = ( j + 0.5) * m_dStep ; + double dSqR = ( dX - ptS.x) * ( dX - ptS.x) + ( dY - ptS.y) * ( dY - ptS.y) ; - double dX = ( i + 0.5) * m_dStep - ptS.x ; - double dY = ( j + 0.5) * m_dStep - ptS.y ; - double dR = dX * dX + dY * dY ; - - if ( dR < dSqSafeMinRad || dR > dSqSafeMaxRad) + if ( dSqR < dSqSafeMinRad || dSqR > dSqSafeMaxRad) continue ; if ( vtAx.z > 0) { - double dr = sqrt( dR) ; + double dr = sqrt( dSqR) ; // Quote Z double dMinZ = min( ptS.z, ptE.z) - dHei + ( dr - dMinRad) * dHei / ( dMaxRad - dMinRad) ; double dMaxZ = max( ptS.z, ptE.z) - dHei + ( dr - dMinRad) * dHei / ( dMaxRad - dMinRad) ; @@ -6141,7 +6369,8 @@ VolZmap::SurfConus_ZDrilling( int nGrid, const Point3d& ptS, const Point3d& ptE, double dCompOrt = vtIntMinOrtV.Len() ; vtIntMinOrtV /= dCompOrt ; vtMinN = - dCompLong * vtIntMinOrtV + dCompOrt * vtAx ; - vtMaxN = vtMinN ; + vtMinN.Normalize() ; + vtMaxN = - vtMinN ; } else { double dDeltaH = dMinRad * dHei / ( dMaxRad - dMinRad) ; @@ -6153,12 +6382,15 @@ VolZmap::SurfConus_ZDrilling( int nGrid, const Point3d& ptS, const Point3d& ptE, Vector3d vtIntMaxOrtV = vtIntMaxV - vtIntMaxLongV ; double dCompOrt = vtIntMaxOrtV.Len() ; vtIntMaxOrtV /= dCompOrt ; - vtMaxN = - dCompLong * vtIntMaxOrtV + dCompOrt * vtAx ; - vtMinN = vtMaxN ; + vtMaxN = dCompLong * vtIntMaxOrtV - dCompOrt * vtAx ; + vtMaxN.Normalize() ; + vtMinN = - vtMaxN ; } + // Taglio dei dexel + SubtractIntervals( nGrid, i, j, dMinZ, dMaxZ, vtMinN, vtMaxN) ; } else { - double dr = sqrt( dR) ; + double dr = sqrt( dSqR) ; // Quote Z double dMinZ = min( ptS.z, ptE.z) + dHei - ( dr - dMinRad) * dHei / ( dMaxRad - dMinRad) ; double dMaxZ = max( ptS.z, ptE.z) + dHei - ( dr - dMinRad) * dHei / ( dMaxRad - dMinRad) ; @@ -6175,7 +6407,8 @@ VolZmap::SurfConus_ZDrilling( int nGrid, const Point3d& ptS, const Point3d& ptE, double dCompOrt = vtIntMaxOrtV.Len() ; vtIntMaxOrtV /= dCompOrt ; vtMaxN = - dCompLong * vtIntMaxOrtV + dCompOrt * vtAx ; - vtMinN = vtMaxN ; + vtMaxN.Normalize() ; + vtMinN = - vtMaxN ; } else { double dDeltaH = dMinRad * dHei / ( dMaxRad - dMinRad) ; @@ -6187,9 +6420,12 @@ VolZmap::SurfConus_ZDrilling( int nGrid, const Point3d& ptS, const Point3d& ptE, Vector3d vtIntMinOrtV = vtIntMinV - vtIntMinLongV ; double dCompOrt = vtIntMinOrtV.Len() ; vtIntMinOrtV /= dCompOrt ; - vtMinN = - dCompLong * vtIntMinOrtV + dCompOrt * vtAx ; - vtMaxN = vtMinN ; + vtMinN = dCompLong * vtIntMinOrtV - dCompOrt * vtAx ; + vtMinN.Normalize() ; + vtMaxN = - vtMinN ; } + // Taglio dei dexel + SubtractIntervals( nGrid, i, j, dMinZ, dMaxZ, vtMinN, vtMaxN) ; } } } @@ -6211,7 +6447,7 @@ VolZmap::SurfConus_Drilling( int nGrid, const Point3d& ptS, const Point3d& ptE, Vector3d vtDisp = ptE - ptS ; double dDispLong = vtAx * vtDisp ; - // Se lo spostamento è in direzione opposta a quella ove il cono taglia, ho finito. + // Se lo spostamento � in direzione opposta a quella ove il cono taglia, ho finito. bool bToolVecAndDispAreOpposite = dDispLong < 0 ; if ( bToolVecAndDispAreOpposite != bOuterCutter) return true ; @@ -6229,9 +6465,9 @@ VolZmap::SurfConus_Drilling( int nGrid, const Point3d& ptS, const Point3d& ptE, vector vEmptyPlaneVec ; // Ciclo sui punti - for ( int i = nStartI ; i < nEndI ; ++ i) { - for ( int j = nStartJ ; j < nEndJ ; ++ j) { - + 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) ; DexelSurfIntersVector vParAndNormIntersVec ; @@ -6239,7 +6475,7 @@ VolZmap::SurfConus_Drilling( int nGrid, const Point3d& ptS, const Point3d& ptE, Vector3d vtN1, vtN2 ; // Intersezione con il cono in posizione iniziale - int nIntNum = IntersLineConeCuttedByPlanes( ptC, Z_AX, ptVs, vtAx, dMaxRad, dHei + dDeltaHei, ! bToolVecAndDispAreOpposite, + int nIntNum = IntersLineConeCuttedByPlanes( ptC, Z_AX, ptVs, vtAx, dMaxRad, dHei + dDeltaHei, /*!*/ bToolVecAndDispAreOpposite, vCutConePlaneVecSt, ptInt1, vtN1, ptInt2, vtN2) ; if ( nIntNum >= 1) { vParAndNormIntersVec.emplace_back() ; @@ -6281,7 +6517,7 @@ VolZmap::SurfConus_Drilling( int nGrid, const Point3d& ptS, const Point3d& ptE, } // Intersezione con il cilindro interno - nIntNum = IntersLineCylinderCuttedByPlanes( ptC, Z_AX, ptS, vtAx, dMinRad, dDispLong, true, + nIntNum = IntersLineCylinderCuttedByPlanes( ptC, Z_AX, ptS - dHei * vtAx, vtAx, dMinRad, dDispLong, true, vEmptyPlaneVec, ptInt1, vtN1, ptInt2, vtN2) ; if ( nIntNum >= 1) { vParAndNormIntersVec.emplace_back() ; @@ -6342,12 +6578,12 @@ VolZmap::SurfConus_Milling( int nGrid, const Point3d& ptS, const Point3d& ptE, c // Parametri geometrici descriventi il cono e il moto double dDeltaHei = dMinRad * dHei / ( dMaxRad - dMinRad) ; double dTanAlpha = dMaxRad / ( dHei + dDeltaHei) ; - double dCosTheta = ( dTanAlpha * vtDisp * vtV3) / ( vtDisp * vtV1) ; + double dCosTheta = Clamp( ( dTanAlpha * vtDisp * vtV3) / ( vtDisp * vtV1), -1., 1.) ; double dSinTheta = sqrt( max( 1 - dCosTheta * dCosTheta, 0.)) ; - bool bLimPassed = abs( dCosTheta) > 1 ; + double dLim = abs( dCosTheta) ; - // Se il movimento non è compatibile con il verso delle normali, ho finito. - if ( bLimPassed && ( bOuterCutter == dDispProjOnAxDir > 0)) + // Se il movimento non � compatibile con il verso delle normali, ho finito. + if ( dLim > 1 - EPS_ZERO && ( bOuterCutter == dDispProjOnAxDir > 0)) return true ; // Vertici del cono nelle posizioni iniziale e finale @@ -6373,12 +6609,12 @@ VolZmap::SurfConus_Milling( int nGrid, const Point3d& ptS, const Point3d& ptE, c vector vCutEllipCylPlaneVecDw ; // Caso di limete oltrepassato - if ( bLimPassed) { + if ( dLim > 1 - EPS_ZERO) { // Ciclo sui punti 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) ; DexelSurfIntersVector vParAndNormIntersVec ; @@ -6386,7 +6622,7 @@ VolZmap::SurfConus_Milling( int nGrid, const Point3d& ptS, const Point3d& ptE, c Vector3d vtN1, vtN2 ; // Intersezione con il cono in posizione iniziale - int nIntNum = IntersLineConeCuttedByPlanes( ptC, Z_AX, ptVertSt, vtAx, dMaxRad, dHei + dDeltaHei, ! bOuterCutter, + int nIntNum = IntersLineConeCuttedByPlanes( ptC, Z_AX, ptVertSt, vtAx, dMaxRad, dHei + dDeltaHei, bOuterCutter, vCutConePlaneVecSt, ptInt1, vtN1, ptInt2, vtN2) ; if ( nIntNum >= 1) { vParAndNormIntersVec.emplace_back() ; @@ -6466,22 +6702,121 @@ VolZmap::SurfConus_Milling( int nGrid, const Point3d& ptS, const Point3d& ptE, c vCutConePlaneVecEn.emplace_back() ; vCutConePlaneVecEn.back().Set( ptVertEn, vtConePlaneNorm) ; - // Aggiorno il vettore dei piani per tagliare il cilindro ellittico superiore. - Vector3d vtEllipCylPlaneNormUp = vtDisp ^ vtV2 ; vtEllipCylPlaneNormUp.Normalize() ; - if ( bOuterCutter == dDispProjOnAxDir > 0) - vtEllipCylPlaneNormUp *= - 1 ; - vCutEllipCylPlaneVecUp.emplace_back() ; - vCutEllipCylPlaneVecUp.back().Set( ptS + dMaxRad * dCosTheta * vtV1, vtEllipCylPlaneNormUp) ; - // Aggiorno il vettore dei piani per tagliare il cilindro ellittico inferiore. - Vector3d vtEllipCylPlaneNormDw = - vtEllipCylPlaneNormUp ; - vCutEllipCylPlaneVecDw.emplace_back() ; - vCutEllipCylPlaneVecDw.back().Set( ptS - dHei * vtAx + dMinRad * dCosTheta * vtV1, vtEllipCylPlaneNormDw) ; - // Punti e normali dei piani laterali Point3d ptPlanePlusP = ptS - dHei * vtAx + dMinRad * vtRadPlus ; Point3d ptPlaneMinusP = ptS - dHei * vtAx + dMinRad * vtRadMinus ; Vector3d vtPlanePlusN = ptS + dMaxRad * vtRadPlus - ptPlanePlusP ; - Vector3d vtPlaneMinusN = ptS + dMaxRad * vtRadPlus - ptPlaneMinusP ; + Vector3d vtPlaneMinusN = ptS + dMaxRad * vtRadMinus - ptPlaneMinusP ; + + // Moto ortogonale all'asse del cono + double dObCoef = dDispProjOnAxDir / vtDispOrt.Len() ; + double dMyLengthMax = dObCoef * dMaxRad / sqrt( 1 + dObCoef * dObCoef) ; + double dMyLengthMin = dObCoef * dMinRad / sqrt( 1 + dObCoef * dObCoef) ; + if ( abs( dDispProjOnAxDir) < 2 * EPS_SMALL && min( dMyLengthMax, dMyLengthMin) < 2 * EPS_SMALL) { + + Point3d ptMyE = ptS + vtDispOrt ; + + // Ciclo sui punti + 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) ; + + DexelSurfIntersVector vParAndNormIntersVec ; + Point3d ptInt1, ptInt2 ; + Vector3d vtN1, vtN2 ; + + // Intersezione con il cono in posizione iniziale + int nIntNum = IntersLineConeCuttedByPlanes( ptC, Z_AX, ptVertSt, vtAx, dMaxRad, dHei + dDeltaHei, bOuterCutter, + vCutConePlaneVecSt, ptInt1, vtN1, ptInt2, vtN2) ; + if ( nIntNum >= 1) { + vParAndNormIntersVec.emplace_back() ; + vParAndNormIntersVec.back().first = ptInt1.z ; + vParAndNormIntersVec.back().second = vtN1 ; + if ( nIntNum == 2) { + vParAndNormIntersVec.emplace_back() ; + vParAndNormIntersVec.back().first = ptInt2.z ; + vParAndNormIntersVec.back().second = vtN2 ; + } + } + + // Intersezione con il cono in posizione finale + nIntNum = IntersLineConeCuttedByPlanes( ptC, Z_AX, ptVertEn, vtAx, dMaxRad, dHei + dDeltaHei, ! bOuterCutter, + vCutConePlaneVecEn, ptInt1, vtN1, ptInt2, vtN2) ; + if ( nIntNum >= 1) { + vParAndNormIntersVec.emplace_back() ; + vParAndNormIntersVec.back().first = ptInt1.z ; + vParAndNormIntersVec.back().second = vtN1 ; + if ( nIntNum == 2) { + vParAndNormIntersVec.emplace_back() ; + vParAndNormIntersVec.back().first = ptInt2.z ; + vParAndNormIntersVec.back().second = vtN2 ; + } + } + + + + // Intersezione con lingua di gatto superiore + nIntNum = IntersLineCatTongue( ptC, Z_AX, bOuterCutter ? ptS : ptMyE, bOuterCutter ? ptMyE : ptS, + vtAx, dMaxRad, ptInt1, vtN1) ; + if ( nIntNum == 1) { + vParAndNormIntersVec.emplace_back() ; + vParAndNormIntersVec.back().first = ptInt1.z ; + vParAndNormIntersVec.back().second = vtN1 ; + } + + // Intersezione con lingua di gatto inferiore + nIntNum = IntersLineCatTongue( ptC, Z_AX, ( bOuterCutter ? ptS : ptMyE) - dHei * vtAx, ( bOuterCutter ? ptMyE : ptS) - dHei * vtAx, + - vtAx, dMinRad, ptInt1, vtN1) ; + if ( nIntNum == 1) { + vParAndNormIntersVec.emplace_back() ; + vParAndNormIntersVec.back().first = ptInt1.z ; + vParAndNormIntersVec.back().second = vtN1 ; + } + + // Piano + (con normale + vtAx ^ vtOrtDisp) + nIntNum = IntersLineParallelogram( ptC, Z_AX, ptPlanePlusP, vtPlanePlusN, vtDisp, + true, ptInt1, vtN1) ; + if ( nIntNum == 1) { + vParAndNormIntersVec.emplace_back() ; + vParAndNormIntersVec.back().first = ptInt1.z ; + vParAndNormIntersVec.back().second = vtN1 ; + } + + // Piano - (con normale - vtAx ^ vtOrtDisp) + nIntNum = IntersLineParallelogram( ptC, Z_AX, ptPlaneMinusP, vtPlaneMinusN, vtDisp, + false, ptInt1, vtN1) ; + if ( nIntNum == 1) { + vParAndNormIntersVec.emplace_back() ; + vParAndNormIntersVec.back().first = ptInt1.z ; + vParAndNormIntersVec.back().second = vtN1 ; + } + + // Filtro le intersezioni trovate. + DexelSurfIntersVector vFilteredIntersVec ; + IntersectionsFilter( Z_AX, vParAndNormIntersVec, vFilteredIntersVec) ; + + // Sottraggo gli intervalli. + for ( int n = 0 ; n < int( vFilteredIntersVec.size()) ; n += 2) { + SubtractIntervals( nGrid, i, j, vFilteredIntersVec[n].first, vFilteredIntersVec[n+1].first, + vFilteredIntersVec[n].second, vFilteredIntersVec[n+1].second) ; + } + } + } + + return true ; + } + + // Aggiorno il vettore dei piani per tagliare il cilindro ellittico superiore. + Vector3d vtEllipCylPlaneNormUp = vtDisp ^ vtV2 ; vtEllipCylPlaneNormUp.Normalize() ; + if ( bOuterCutter != dDispProjOnAxDir > 0) + vtEllipCylPlaneNormUp *= - 1 ; + vCutEllipCylPlaneVecUp.emplace_back() ; + vCutEllipCylPlaneVecUp.back().Set( ptS + dMaxRad * dCosTheta * vtV1, vtEllipCylPlaneNormUp) ; + // Aggiorno il vettore dei piani per tagliare il cilindro ellittico inferiore. + Vector3d vtEllipCylPlaneNormDw = vtEllipCylPlaneNormUp ; + vCutEllipCylPlaneVecDw.emplace_back() ; + vCutEllipCylPlaneVecDw.back().Set( ptS - dHei * vtAx + dMinRad * dCosTheta * vtV1, vtEllipCylPlaneNormDw) ; // Ciclo sui punti for ( int i = nStartI ; i <= nEndI ; ++ i) { @@ -6489,12 +6824,13 @@ VolZmap::SurfConus_Milling( int nGrid, const Point3d& ptS, const Point3d& ptE, c Point3d ptC( ( i + 0.5) * m_dStep, ( j + 0.5) * m_dStep, 0) ; - DexelSurfIntersVector vParAndNormIntersVec ; + DexelSurfIntersVector vParAndNormIntersVec; + DexelSurfIntersVector vIntersConusStart, vIntersConusEnd, vIntersEllipSup, vIntersEllipInf, vIntersPlanePlus, vIntersPlaneMinus; Point3d ptInt1, ptInt2 ; Vector3d vtN1, vtN2 ; // Intersezione con il cono in posizione iniziale - int nIntNum = IntersLineConeCuttedByPlanes( ptC, Z_AX, ptVertSt, vtAx, dMaxRad, dHei + dDeltaHei, ! bOuterCutter, + int nIntNum = IntersLineConeCuttedByPlanes( ptC, Z_AX, ptVertSt, vtAx, dMaxRad, dHei + dDeltaHei, bOuterCutter, vCutConePlaneVecSt, ptInt1, vtN1, ptInt2, vtN2) ; if ( nIntNum >= 1) { vParAndNormIntersVec.emplace_back() ; @@ -6522,7 +6858,7 @@ VolZmap::SurfConus_Milling( int nGrid, const Point3d& ptS, const Point3d& ptE, c } // Intersezione con cilindro ellittico superiore - nIntNum = IntersLineCircSweptSurfCuttedByPlanes( ptC, Z_AX, ptS, vtAx, dMaxRad, vtDisp, bOuterCutter, vCutEllipCylPlaneVecUp, + nIntNum = IntersLineCircSweptSurfCuttedByPlanes( ptC, Z_AX, ptS, vtAx, dMaxRad, vtDisp, bOuterCutter == dDispProjOnAxDir > 0, vCutEllipCylPlaneVecUp, ptInt1, vtN1, ptInt2, vtN2) ; if ( nIntNum >= 1) { vParAndNormIntersVec.emplace_back() ; @@ -6532,11 +6868,22 @@ VolZmap::SurfConus_Milling( int nGrid, const Point3d& ptS, const Point3d& ptE, c vParAndNormIntersVec.emplace_back() ; vParAndNormIntersVec.back().first = ptInt2.z ; vParAndNormIntersVec.back().second = vtN2 ; + if ( vCutEllipCylPlaneVecUp.size() == 1) { + if ( SqDist( ptInt1, ptInt2) < EPS_SMALL) { + int bazinga1 = 0 ; + double dLL1 = (ptInt1 - vCutEllipCylPlaneVecUp[0].GetPoint()) * vCutEllipCylPlaneVecUp[0].GetVersN(); + double dLL2 = (ptInt2 - vCutEllipCylPlaneVecUp[0].GetPoint()) * vCutEllipCylPlaneVecUp[0].GetVersN(); + if ( ( ptInt1 - vCutEllipCylPlaneVecUp[0].GetPoint()) * vCutEllipCylPlaneVecUp[0].GetVersN() > 0.) + vParAndNormIntersVec.erase( vParAndNormIntersVec.begin() + int( vParAndNormIntersVec.size()) - 2) ; + else if ( ( ptInt2 - vCutEllipCylPlaneVecUp[0].GetPoint()) * vCutEllipCylPlaneVecUp[0].GetVersN() > 0.) + vParAndNormIntersVec.erase( vParAndNormIntersVec.begin() + int( vParAndNormIntersVec.size()) - 1) ; + } + } } } // Intersezione con cilindro ellittico inferiore - nIntNum = IntersLineCircSweptSurfCuttedByPlanes( ptC, Z_AX, ptS - dHei * vtAx, vtAx, dMinRad, vtDisp, ! bOuterCutter, vCutEllipCylPlaneVecUp, + nIntNum = IntersLineCircSweptSurfCuttedByPlanes( ptC, Z_AX, ptS - dHei * vtAx, vtAx, dMinRad, vtDisp, bOuterCutter != dDispProjOnAxDir > 0, vCutEllipCylPlaneVecDw, ptInt1, vtN1, ptInt2, vtN2) ; if ( nIntNum >= 1) { vParAndNormIntersVec.emplace_back() ; @@ -6546,6 +6893,17 @@ VolZmap::SurfConus_Milling( int nGrid, const Point3d& ptS, const Point3d& ptE, c vParAndNormIntersVec.emplace_back() ; vParAndNormIntersVec.back().first = ptInt2.z ; vParAndNormIntersVec.back().second = vtN2 ; + if ( vCutEllipCylPlaneVecDw.size() == 1) { + if ( SqDist( ptInt1, ptInt2) < EPS_SMALL) { + int bazinga2 = 0 ; + double dLL1 = (ptInt1 - vCutEllipCylPlaneVecDw[0].GetPoint()) * vCutEllipCylPlaneVecDw[0].GetVersN(); + double dLL2 = (ptInt2 - vCutEllipCylPlaneVecDw[0].GetPoint()) * vCutEllipCylPlaneVecDw[0].GetVersN(); + if ( ( ptInt1 - vCutEllipCylPlaneVecDw[0].GetPoint()) * vCutEllipCylPlaneVecDw[0].GetVersN() > 0.) + vParAndNormIntersVec.erase( vParAndNormIntersVec.begin() + int( vParAndNormIntersVec.size()) - 2) ; + else if ( ( ptInt2 - vCutEllipCylPlaneVecDw[0].GetPoint()) * vCutEllipCylPlaneVecDw[0].GetVersN() > 0.) + vParAndNormIntersVec.erase( vParAndNormIntersVec.begin() + int( vParAndNormIntersVec.size()) - 1) ; + } + } } } @@ -6570,7 +6928,7 @@ VolZmap::SurfConus_Milling( int nGrid, const Point3d& ptS, const Point3d& ptE, c // Filtro le intersezioni trovate. DexelSurfIntersVector vFilteredIntersVec ; IntersectionsFilter( Z_AX, vParAndNormIntersVec, vFilteredIntersVec) ; - + // Sottraggo gli intervalli. for ( int n = 0 ; n < int( vFilteredIntersVec.size()) ; n += 2) { SubtractIntervals( nGrid, i, j, vFilteredIntersVec[n].first, vFilteredIntersVec[n+1].first, @@ -6589,13 +6947,13 @@ bool VolZmap::SurfSphericalShellPart_Milling( int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtAx, double dRad, double dInfH, double dSupH, bool bOuterCutter) { - // Se la superficie è una calotta sferica, chiamo la routine apposita. + // Se la superficie � una calotta sferica, chiamo la routine apposita. if ( dInfH > dRad - EPS_SMALL) return SurfSphericalShell_Milling( nGrid, ptS, ptE, vtAx, dRad, dSupH, bOuterCutter) ; // Verifico interferisca int nStartI, nStartJ, nEndI, nEndJ ; - if ( ! TestCompoBBox( nGrid, ptS, ptS, V_NULL, dRad, 0, 0, nStartI, nStartJ, nEndI, nEndJ)) + if ( ! TestCompoBBox( nGrid, ptS, ptE, V_NULL, dRad, 0, 0, nStartI, nStartJ, nEndI, nEndJ)) return true ; // Vettore spostamento @@ -6640,7 +6998,7 @@ VolZmap::SurfSphericalShellPart_Milling( int nGrid, const Point3d& ptS, const Po // Ciclo sui punti 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) ; DexelSurfIntersVector vParAndNormIntersVec ; @@ -6648,7 +7006,7 @@ VolZmap::SurfSphericalShellPart_Milling( int nGrid, const Point3d& ptS, const Po Vector3d vtN1, vtN2 ; // Intersezione con sfera in posizione iniziale - int nIntNum = IntersLineSphereCuttedByPlanes( ptC, Z_AX, ptS, dRad, ! bOuterCutter, vSphereCutPlanesVecSt, + int nIntNum = IntersLineSphereCuttedByPlanes( ptC, Z_AX, ptS, dRad, bOuterCutter, vSphereCutPlanesVecSt, ptInt1, vtN1, ptInt2, vtN2) ; if ( nIntNum >= 1) { vParAndNormIntersVec.emplace_back() ; @@ -6725,12 +7083,13 @@ VolZmap::SurfSphericalShellPart_Milling( int nGrid, const Point3d& ptS, const Po vSphereCutPlanesVecEn.back().Set( ptE, bOuterCutter ? - vtDispVers : vtDispVers) ; // Versore della componente del moto perpendicolare all'asse - Vector3d vtOrtDispVers = vtDisp - dAxDispDot * vtAx ; + Vector3d vtOrtDispVers = vtDisp - dDispLen * dAxDispDot * vtAx ; double dOrtDispLen = vtOrtDispVers.Len() ; vtOrtDispVers /= dOrtDispLen ; // Vettore dei piani di taglio del cilindro ellittico superiore - Vector3d vtPlaneN = - dAxDispDot * vtOrtDispVers + dOrtDispLen * vtAx ; + Vector3d vtPlaneN = - dDispLen * dAxDispDot * vtOrtDispVers + dOrtDispLen * vtAx ; + vtPlaneN.Normalize() ; if ( bOuterCutter != dAxDispDot > 0) vtPlaneN *= - 1 ; double dC = vtDispVers * vtAx ; @@ -6759,7 +7118,7 @@ VolZmap::SurfSphericalShellPart_Milling( int nGrid, const Point3d& ptS, const Po Vector3d vtN1, vtN2 ; // Intersezione con sfera in posizione iniziale - int nIntNum = IntersLineSphereCuttedByPlanes( ptC, Z_AX, ptS, dRad, ! bOuterCutter, vSphereCutPlanesVecSt, + int nIntNum = IntersLineSphereCuttedByPlanes( ptC, Z_AX, ptS, dRad, bOuterCutter, vSphereCutPlanesVecSt, ptInt1, vtN1, ptInt2, vtN2) ; if ( nIntNum >= 1) { vParAndNormIntersVec.emplace_back() ; @@ -6852,12 +7211,13 @@ VolZmap::SurfSphericalShellPart_Milling( int nGrid, const Point3d& ptS, const Po vSphereCutPlanesVecEn.back().Set( ptE, bOuterCutter ? - vtDispVers : vtDispVers) ; // Versore della componente del moto perpendicolare all'asse - Vector3d vtOrtDispVers = vtDisp - dAxDispDot * vtAx ; + Vector3d vtOrtDispVers = vtDisp - dDispLen * dAxDispDot * vtAx ; double dOrtDispLen = vtOrtDispVers.Len() ; vtOrtDispVers /= dOrtDispLen ; // Determinazione dei piani di taglio dei cilindri ellittici - Vector3d vtPlaneN = - dAxDispDot * vtOrtDispVers + dOrtDispLen * vtAx ; + Vector3d vtPlaneN = - dDispLen * dAxDispDot * vtOrtDispVers + dOrtDispLen * vtAx ; + vtPlaneN.Normalize() ; if ( bOuterCutter != dAxDispDot > 0) vtPlaneN *= - 1 ; double dC = vtDispVers * vtAx ; @@ -6883,7 +7243,7 @@ VolZmap::SurfSphericalShellPart_Milling( int nGrid, const Point3d& ptS, const Po // Ciclo sui punti 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) ; DexelSurfIntersVector vParAndNormIntersVec ; @@ -6891,7 +7251,7 @@ VolZmap::SurfSphericalShellPart_Milling( int nGrid, const Point3d& ptS, const Po Vector3d vtN1, vtN2 ; // Intersezione con sfera in posizione iniziale - int nIntNum = IntersLineSphereCuttedByPlanes( ptC, Z_AX, ptS, dRad, ! bOuterCutter, vSphereCutPlanesVecSt, + int nIntNum = IntersLineSphereCuttedByPlanes( ptC, Z_AX, ptS, dRad, bOuterCutter, vSphereCutPlanesVecSt, ptInt1, vtN1, ptInt2, vtN2) ; if ( nIntNum >= 1) { vParAndNormIntersVec.emplace_back() ; @@ -6918,33 +7278,117 @@ VolZmap::SurfSphericalShellPart_Milling( int nGrid, const Point3d& ptS, const Po } } - // Intersezione con cilindro ellittico superiore - nIntNum = IntersLineCircSweptSurfCuttedByPlanes( ptC, Z_AX, ptS - dSupH * vtAx, vtAx, dSupRad, vtDisp, bOuterCutter == dAxDispDot > 0, - vEllipCylCutPlanesVecSup, ptInt1, vtN1, ptInt2, vtN2) ; - if ( nIntNum >= 1) { - vParAndNormIntersVec.emplace_back() ; - vParAndNormIntersVec.back().first = ptInt1.z ; - vParAndNormIntersVec.back().second = vtN1 ; - if ( nIntNum == 2) { + //// Se il movimento non � ortogonale all'asse interseco con i cilindri ellittici. + //double dObCoef = dDispLen * dAxDispDot / dOrtDispLen ; + //double dMyLengthSup = dObCoef * dSupRad / sqrt( 1 + dObCoef * dObCoef) ; + //double dMyLengthInf = dObCoef * dInfRad / sqrt( 1 + dObCoef * dObCoef) ; + //if ( abs( dDispLen * dAxDispDot) > EPS_SMALL && min( dMyLengthSup, dMyLengthInf) > 2 * EPS_SMALL) { + // // Intersezione con cilindro ellittico superiore + // nIntNum = IntersLineCircSweptSurfCuttedByPlanes( ptC, Z_AX, ptS - dSupH * vtAx, vtAx, dSupRad, vtDisp, bOuterCutter == dAxDispDot > 0, + // vEllipCylCutPlanesVecSup, ptInt1, vtN1, ptInt2, vtN2) ; + // if ( nIntNum >= 1) { + // vParAndNormIntersVec.emplace_back() ; + // vParAndNormIntersVec.back().first = ptInt1.z ; + // vParAndNormIntersVec.back().second = vtN1 ; + // if ( nIntNum == 2) { + // vParAndNormIntersVec.emplace_back() ; + // vParAndNormIntersVec.back().first = ptInt2.z ; + // vParAndNormIntersVec.back().second = vtN2 ; + // } + // } + // + // // Intersezione con cilindro ellittico inferiore + // nIntNum = IntersLineCircSweptSurfCuttedByPlanes( ptC, Z_AX, ptS - dInfH * vtAx, vtAx, dInfRad, vtDisp, bOuterCutter != dAxDispDot > 0, + // vEllipCylCutPlanesVecInf, ptInt1, vtN1, ptInt2, vtN2) ; + // if ( nIntNum >= 1) { + // vParAndNormIntersVec.emplace_back() ; + // vParAndNormIntersVec.back().first = ptInt1.z ; + // vParAndNormIntersVec.back().second = vtN1 ; + // if ( nIntNum == 2) { + // vParAndNormIntersVec.emplace_back() ; + // vParAndNormIntersVec.back().first = ptInt2.z ; + // vParAndNormIntersVec.back().second = vtN2 ; + // } + // } + //} + //// Altrimenti interseco con le lingue di gatto. + //else { + // Point3d ptMyE = ptS + dOrtDispLen * vtOrtDispVers ; + // // Intersezione con lingua la gatto superiore + // nIntNum = IntersLineCatTongue( ptC, Z_AX, ( bOuterCutter ? ptS : ptMyE) - dSupH * vtAx, ( bOuterCutter ? ptMyE : ptS) - dSupH * vtAx, + // vtAx, dSupRad, ptInt1, vtN1) ; + + // if ( nIntNum == 1) { + // vParAndNormIntersVec.emplace_back() ; + // vParAndNormIntersVec.back().first = ptInt1.z ; + // vParAndNormIntersVec.back().second = vtN1 ; + // } + + // // Intersezione con la lingua di gatto inferiore + // nIntNum = IntersLineCatTongue( ptC, Z_AX, ( bOuterCutter ? ptS : ptMyE) - dInfH * vtAx, ( bOuterCutter ? ptMyE : ptS) - dInfH * vtAx, + // - vtAx, dInfRad, ptInt1, vtN1) ; + + // if ( nIntNum == 1) { + // vParAndNormIntersVec.emplace_back() ; + // vParAndNormIntersVec.back().first = ptInt1.z ; + // vParAndNormIntersVec.back().second = vtN1 ; + // } + //} + + // Se il movimento � ortogonale all'asse interseco con le lingue di gatto. + double dObCoef = dDispLen * dAxDispDot / dOrtDispLen ; + double dMyLengthSup = dObCoef * dSupRad / sqrt( 1 + dObCoef * dObCoef) ; + double dMyLengthInf = dObCoef * dInfRad / sqrt( 1 + dObCoef * dObCoef) ; + if ( abs( dDispLen * dAxDispDot) < 2 * EPS_SMALL && min( dMyLengthSup, dMyLengthInf) < 2 * EPS_SMALL) { + Point3d ptMyE = ptS + dOrtDispLen * vtOrtDispVers ; + // Intersezione con lingua la gatto superiore + nIntNum = IntersLineCatTongue( ptC, Z_AX, ( bOuterCutter ? ptS : ptMyE) - dSupH * vtAx, ( bOuterCutter ? ptMyE : ptS) - dSupH * vtAx, + vtAx, dSupRad, ptInt1, vtN1) ; + if ( nIntNum == 1) { vParAndNormIntersVec.emplace_back() ; - vParAndNormIntersVec.back().first = ptInt2.z ; - vParAndNormIntersVec.back().second = vtN2 ; + vParAndNormIntersVec.back().first = ptInt1.z ; + vParAndNormIntersVec.back().second = vtN1 ; } + + // Intersezione con la lingua di gatto inferiore + nIntNum = IntersLineCatTongue( ptC, Z_AX, ( bOuterCutter ? ptS : ptMyE) - dInfH * vtAx, ( bOuterCutter ? ptMyE : ptS) - dInfH * vtAx, + - vtAx, dInfRad, ptInt1, vtN1) ; + if ( nIntNum == 1) { + vParAndNormIntersVec.emplace_back() ; + vParAndNormIntersVec.back().first = ptInt1.z ; + vParAndNormIntersVec.back().second = vtN1 ; + } } - - // Intersezione con cilindro ellittico inferiore - nIntNum = IntersLineCircSweptSurfCuttedByPlanes( ptC, Z_AX, ptS - dInfH * vtAx, vtAx, dInfRad, vtDisp, bOuterCutter != dAxDispDot > 0, - vEllipCylCutPlanesVecInf, ptInt1, vtN1, ptInt2, vtN2) ; - if ( nIntNum >= 1) { - vParAndNormIntersVec.emplace_back() ; - vParAndNormIntersVec.back().first = ptInt1.z ; - vParAndNormIntersVec.back().second = vtN1 ; - if ( nIntNum == 2) { + // Altrimenti interseco con i cilindri ellittici. + else { + // Intersezione con cilindro ellittico superiore + nIntNum = IntersLineCircSweptSurfCuttedByPlanes( ptC, Z_AX, ptS - dSupH * vtAx, vtAx, dSupRad, vtDisp, bOuterCutter == dAxDispDot > 0, + vEllipCylCutPlanesVecSup, ptInt1, vtN1, ptInt2, vtN2) ; + if ( nIntNum >= 1) { vParAndNormIntersVec.emplace_back() ; - vParAndNormIntersVec.back().first = ptInt2.z ; - vParAndNormIntersVec.back().second = vtN2 ; + vParAndNormIntersVec.back().first = ptInt1.z ; + vParAndNormIntersVec.back().second = vtN1 ; + if ( nIntNum == 2) { + vParAndNormIntersVec.emplace_back() ; + vParAndNormIntersVec.back().first = ptInt2.z ; + vParAndNormIntersVec.back().second = vtN2 ; + } } - } + + // Intersezione con cilindro ellittico inferiore + nIntNum = IntersLineCircSweptSurfCuttedByPlanes( ptC, Z_AX, ptS - dInfH * vtAx, vtAx, dInfRad, vtDisp, bOuterCutter != dAxDispDot > 0, + vEllipCylCutPlanesVecInf, ptInt1, vtN1, ptInt2, vtN2) ; + if ( nIntNum >= 1) { + vParAndNormIntersVec.emplace_back() ; + vParAndNormIntersVec.back().first = ptInt1.z ; + vParAndNormIntersVec.back().second = vtN1 ; + if ( nIntNum == 2) { + vParAndNormIntersVec.emplace_back() ; + vParAndNormIntersVec.back().first = ptInt2.z ; + vParAndNormIntersVec.back().second = vtN2 ; + } + } + } // Intersezione con cilindro esterno nIntNum = IntersLineCylinderCuttedByPlanes( ptC, Z_AX, ptE, - vtDispVers, dRad, dDispLen, false, @@ -6984,7 +7428,7 @@ VolZmap::SurfSphericalShell_Milling( int nGrid, const Point3d& ptS, const Point3 { // Verifico interferisca int nStartI, nStartJ, nEndI, nEndJ ; - if ( ! TestCompoBBox( nGrid, ptS, ptS, V_NULL, dRad, 0, 0, nStartI, nStartJ, nEndI, nEndJ)) + if ( ! TestCompoBBox( nGrid, ptS, ptE, V_NULL, dRad, 0, 0, nStartI, nStartJ, nEndI, nEndJ)) return true ; // Vettore spostamento @@ -7022,7 +7466,7 @@ VolZmap::SurfSphericalShell_Milling( int nGrid, const Point3d& ptS, const Point3 // Ciclo sui punti 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) ; DexelSurfIntersVector vParAndNormIntersVec ; @@ -7030,7 +7474,7 @@ VolZmap::SurfSphericalShell_Milling( int nGrid, const Point3d& ptS, const Point3 Vector3d vtN1, vtN2 ; // Intersezione con sfera in posizione iniziale - int nIntNum = IntersLineSphereCuttedByPlanes( ptC, Z_AX, ptS, dRad, ! bOuterCutter, vSphereCutPlanesVecSt, + int nIntNum = IntersLineSphereCuttedByPlanes( ptC, Z_AX, ptS, dRad, bOuterCutter, vSphereCutPlanesVecSt, ptInt1, vtN1, ptInt2, vtN2) ; if ( nIntNum >= 1) { vParAndNormIntersVec.emplace_back() ; @@ -7093,16 +7537,18 @@ VolZmap::SurfSphericalShell_Milling( int nGrid, const Point3d& ptS, const Point3 vSphereCutPlanesVecEn.back().Set( ptE, bOuterCutter ? - vtDispVers : vtDispVers) ; // Versore della componente del moto perpendicolare all'asse - Vector3d vtOrtDispVers = vtDisp - dAxDispDot * vtAx ; + Vector3d vtOrtDispVers = vtDisp - dDispLen * dAxDispDot * vtAx ; double dOrtDispLen = vtOrtDispVers.Len() ; vtOrtDispVers /= dOrtDispLen ; // Vettore dei piani di taglio del cilindro ellittico superiore - Vector3d vtPlaneN = - dAxDispDot * vtOrtDispVers + dOrtDispLen * vtAx ; + Vector3d vtPlaneN = - dDispLen * dAxDispDot * vtOrtDispVers + dOrtDispLen * vtAx ; + vtPlaneN.Normalize() ; if ( bOuterCutter != dAxDispDot > 0) vtPlaneN *= - 1 ; double dC = vtDispVers * vtAx ; double dS = sqrt( max( 1 - dC * dC, 0.)) ; + double dTempTest = (dC * dHei / dS); Point3d ptPlaneP = ptS - dHei * vtAx + ( dC * dHei / dS) * vtOrtDispVers ; vector vEllipCylCutPlanesVec ; vEllipCylCutPlanesVec.emplace_back() ; @@ -7116,7 +7562,7 @@ VolZmap::SurfSphericalShell_Milling( int nGrid, const Point3d& ptS, const Point3 // Ciclo sui punti 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) ; DexelSurfIntersVector vParAndNormIntersVec ; @@ -7124,7 +7570,7 @@ VolZmap::SurfSphericalShell_Milling( int nGrid, const Point3d& ptS, const Point3 Vector3d vtN1, vtN2 ; // Intersezione con sfera in posizione iniziale - int nIntNum = IntersLineSphereCuttedByPlanes( ptC, Z_AX, ptS, dRad, ! bOuterCutter, vSphereCutPlanesVecSt, + int nIntNum = IntersLineSphereCuttedByPlanes( ptC, Z_AX, ptS, dRad, bOuterCutter, vSphereCutPlanesVecSt, ptInt1, vtN1, ptInt2, vtN2) ; if ( nIntNum >= 1) { vParAndNormIntersVec.emplace_back() ; @@ -7151,17 +7597,32 @@ VolZmap::SurfSphericalShell_Milling( int nGrid, const Point3d& ptS, const Point3 } } - // Intersezione con cilindro ellittico - nIntNum = IntersLineCircSweptSurfCuttedByPlanes( ptC, Z_AX, ptS - dHei * vtAx, vtAx, dBaseRad, vtDisp, bOuterCutter == dAxDispDot > 0, - vEllipCylCutPlanesVec, ptInt1, vtN1, ptInt2, vtN2) ; - if ( nIntNum >= 1) { - vParAndNormIntersVec.emplace_back() ; - vParAndNormIntersVec.back().first = ptInt1.z ; - vParAndNormIntersVec.back().second = vtN1 ; - if ( nIntNum == 2) { + // Intersezione con lingua di gatto se il movimento � perpendicolare all'asse di simmetria + double dObCoef = dDispLen * dAxDispDot / dOrtDispLen ; + double dMyLength = dObCoef * dRad / sqrt( 1 + dObCoef * dObCoef) ; + if ( abs( dDispLen * dAxDispDot) < 2 * EPS_SMALL && dMyLength < 2 * EPS_SMALL) { + Point3d ptMyE = ptS + dOrtDispLen * vtOrtDispVers ; + nIntNum = IntersLineCatTongue( ptC, Z_AX, ( bOuterCutter ? ptS : ptMyE) - dHei * vtAx, ( bOuterCutter ? ptMyE : ptS) - dHei * vtAx, + vtAx, dBaseRad, ptInt1, vtN1) ; + if ( nIntNum == 1) { vParAndNormIntersVec.emplace_back() ; - vParAndNormIntersVec.back().first = ptInt2.z ; - vParAndNormIntersVec.back().second = vtN2 ; + vParAndNormIntersVec.back().first = ptInt1.z ; + vParAndNormIntersVec.back().second = vtN1 ; + } + } + // Intersezione con cilindro ellittico se il movimento � generico + else { + nIntNum = IntersLineCircSweptSurfCuttedByPlanes( ptC, Z_AX, ptS - dHei * vtAx, vtAx, dBaseRad, vtDisp, bOuterCutter == dAxDispDot > 0, + vEllipCylCutPlanesVec, ptInt1, vtN1, ptInt2, vtN2) ; + if ( nIntNum >= 1) { + vParAndNormIntersVec.emplace_back() ; + vParAndNormIntersVec.back().first = ptInt1.z ; + vParAndNormIntersVec.back().second = vtN1 ; + if ( nIntNum == 2) { + vParAndNormIntersVec.emplace_back() ; + vParAndNormIntersVec.back().first = ptInt2.z ; + vParAndNormIntersVec.back().second = vtN2 ; + } } } @@ -7258,7 +7719,7 @@ VolZmap::TestCompoBBox( int nGrid, const Point3d& ptP1, const Point3d& ptP2, con { // 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 ; @@ -7297,7 +7758,7 @@ VolZmap::TestParaBBox( int nGrid, const Point3d& ptS, const Point3d& ptE, const 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 ;