diff --git a/VolZmap.h b/VolZmap.h index bd4689b..ac68212 100644 --- a/VolZmap.h +++ b/VolZmap.h @@ -343,6 +343,7 @@ class VolZmap : public IVolZmap, public IGeoObjRW bool AddingTruncatedCone( int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtAx, double dMaxRad, double dMinRad, double dHei, const Vector3d& vtArcNormMaxR, const Vector3d& vtArcNormMinR) ; + bool AddingSphere( int nGrid, const Point3d& ptS, const Point3d& ptE, double dRad) ; bool AddingGeneral( int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtAx) ; @@ -357,7 +358,7 @@ class VolZmap : public IVolZmap, public IGeoObjRW bool GetDepthWithVoxel( const Point3d& ptP, const Vector3d& vtDir, double& dInLength, double& dOutLength) const ; bool IntersLineCylinder( const Point3d& ptLineSt, const Vector3d& vtLineDir, const Frame3d& CylFrame, double dH, double dRad, bool bTapLow, bool bTapUp, - Point3d& ptInt1, Vector3d& vtN1, Point3d& ptInt2, Vector3d& vtN2) const ; + Point3d& ptInt1, Vector3d& vtN1, Point3d& ptInt2, Vector3d& vtN2, bool bSubtracting = true) const ; bool IntersLineEllipticalCylinder( const Point3d& ptLineSt, const Vector3d& vtLineDir, const Frame3d& CircFrame, double dRad, double dLongMvLen, double dOrtMvLen, bool bTapLow, bool bTapUp, diff --git a/VolZmapCalculus.cpp b/VolZmapCalculus.cpp index c494902..961b9c4 100644 --- a/VolZmapCalculus.cpp +++ b/VolZmapCalculus.cpp @@ -2281,7 +2281,7 @@ VolZmap::AvoidSurfTm( const ISurfTriMesh& tmSurf, double dSafeDist, bool bPrecis bool VolZmap::IntersLineCylinder( const Point3d& ptLineSt, const Vector3d& vtLineDir, const Frame3d& CylFrame, double dH, double dRad, bool bTapLow, bool bTapUp, - Point3d& ptInt1, Vector3d& vtN1, Point3d& ptInt2, Vector3d& vtN2) const + Point3d& ptInt1, Vector3d& vtN1, Point3d& ptInt2, Vector3d& vtN2, bool bSubtracting) const { // Porto la linea nel riferimento del cilindro Point3d ptP = ptLineSt ; ptP.ToLoc( CylFrame) ; @@ -2291,14 +2291,14 @@ VolZmap::IntersLineCylinder( const Point3d& ptLineSt, const Vector3d& vtLineDir, int nBasInt = 0 ; if ( abs( vtV.z) > EPS_ZERO) { // le linee tangenti al cilindro non sono considerate intersecanti - double EpsRad = ( vtV.IsZeroXY() ? - EPS_SMALL : EPS_SMALL) ; + double dEpsRad = ( bSubtracting ? ( vtV.IsZeroXY() ? - EPS_SMALL : EPS_SMALL) : EPS_SMALL) ; ptInt1 = ptP + ( ( 0 - ptP.z) / vtV.z) * vtV ; - if ( ptInt1.x * ptInt1.x + ptInt1.y * ptInt1.y < dRad * dRad + 2 * dRad * EpsRad) { + if ( ptInt1.x * ptInt1.x + ptInt1.y * ptInt1.y < dRad * dRad + 2 * dRad * dEpsRad) { nBasInt += 1 ; vtN1 = Z_AX ; } ptInt2 = ptP + ( ( dH - ptP.z) / vtV.z) * vtV ; - if ( ptInt2.x * ptInt2.x + ptInt2.y * ptInt2.y < dRad * dRad + 2 * dRad * EpsRad) { + if ( ptInt2.x * ptInt2.x + ptInt2.y * ptInt2.y < dRad * dRad + 2 * dRad * dEpsRad) { nBasInt += 2 ; vtN2 = - Z_AX ; } diff --git a/VolZmapVolume.cpp b/VolZmapVolume.cpp index f3e262c..8f1952a 100644 --- a/VolZmapVolume.cpp +++ b/VolZmapVolume.cpp @@ -726,11 +726,11 @@ 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) ; - for ( int i = 0 ; i < m_nMapNum ; ++ i) { + /*for ( int i = 0 ; i < m_nMapNum ; ++ i) { SelectMotion( i, ptLs[i], ptLe[i], vtLs[i], vtALs[i]) ; - } + }*/ // Ciclo sulle mappe - /*vector< future> vRes ; + vector< future> vRes ; vRes.resize( m_nMapNum) ; for ( int i = 0 ; i < m_nMapNum ; ++ i) { vRes[i] = async( launch::async, &VolZmap::SelectMotion, this, i, cref( ptLs[i]), cref( ptLe[i]), cref( vtLs[i]), cref( vtALs[i])) ; @@ -744,7 +744,7 @@ VolZmap::MillingTranslationStep( const Point3d& ptPs, const Point3d& ptPe, const ++ nTerminated ; } } - }*/ + } return true ; } @@ -7808,7 +7808,7 @@ VolZmap::AddingMotion( int nGrid, const Point3d& ptS, const Point3d& ptE, const } // Utensile sferico else if ( dRad - dCornerRad < EPS_SMALL) { - ; + AddingSphere( nGrid, ptS - dRad * vtAx, ptE - dRad * vtAx, dRad) ; } // Utensile cilindro else if ( dCornerRad < EPS_SMALL) { @@ -8354,6 +8354,68 @@ VolZmap::AddingTruncatedCone( int nGrid, const Point3d& ptS, const Point3d& ptE, } } +//---------------------------------------------------------------------------- +bool +VolZmap::AddingSphere( int nGrid, const Point3d& ptS, const Point3d& ptE, double dRad) +{ + // Verifico interferisca + int nStartI, nStartJ, nEndI, nEndJ ; + if ( ! TestCompoBBox( nGrid, ptS, ptE, V_NULL, dRad, 0, 0, nStartI, nStartJ, nEndI, nEndJ)) + return true ; + // Vettore modivemnto + Vector3d vtV = ptE - ptS ; + double dLengthPath = vtV.Len() ; + if ( dLengthPath > EPS_ZERO) + vtV /= dLengthPath ; + // Riferimento per cilindro inviluppo della sfera lungo il movimento + Frame3d CylFrame ; + CylFrame.Set( ptS, vtV) ; + + double dSqRad = dRad * dRad ; + + 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 ; + Point3d ptC( dX, dY, 0) ; + + // Sfera in posizione start + double dStSqDXY = SqDistXY( ptC, ptS) ; + if ( dStSqDXY < dSqRad) { + double dMin = ptS.z - sqrt( dSqRad - dStSqDXY) ; + Vector3d vtNmin = Point3d( dX, dY, dMin) - ptS ; + vtNmin.Normalize() ; + double dMax = ptS.z + sqrt( dSqRad - dStSqDXY) ; + Vector3d vtNmax = Point3d( dX, dY, dMax) - ptS ; + vtNmax.Normalize() ; + AddIntervals( nGrid, i, j, dMin, dMax, vtNmin, vtNmax) ; + } + + // Sfera in posizione end + double dEnSqDXY = SqDistXY( ptC, ptE) ; + if ( dEnSqDXY < dSqRad) { + double dMin = ptE.z - sqrt( dSqRad - dEnSqDXY) ; + Vector3d vtNmin = Point3d( dX, dY, dMin) - ptE ; + vtNmin.Normalize() ; + double dMax = ptE.z + sqrt( dSqRad - dEnSqDXY) ; + Vector3d vtNmax = Point3d( dX, dY, dMax) - ptE ; + vtNmax.Normalize() ; + AddIntervals( nGrid, i, j, dMin, dMax, vtNmin, vtNmax) ; + } + + // Cilindro inviluppo della sfera + Point3d ptInt1, ptInt2 ; + Vector3d vtN1, vtN2 ; + if ( IntersLineCylinder( ptC, Z_AX, CylFrame, dLengthPath, dRad, false, false, ptInt1, vtN1, ptInt2, vtN2, false)) { + AddIntervals( nGrid, i, j, ptInt1.z, ptInt2.z, - vtN1, - vtN2) ; + } + } + } + + return true ; +} + // ------------------------- BOUNDING BOX -------------------------------------------------------------------------------------- //----------------------------------------------------------------------------