diff --git a/EgtGeomKernel.rc b/EgtGeomKernel.rc index 2fa2c3e..6037d28 100644 Binary files a/EgtGeomKernel.rc and b/EgtGeomKernel.rc differ diff --git a/VolTriZmapCreation.cpp b/VolTriZmapCreation.cpp index 12596b6..f646076 100644 --- a/VolTriZmapCreation.cpp +++ b/VolTriZmapCreation.cpp @@ -493,12 +493,15 @@ VolZmap::CreateFromTriMesh( const ISurfTriMesh& Surf, double dPrec, bool bTriDex // Determino il bounding box della TriMesh BBox3d SurfBBox ; Surf.GetLocalBBox( SurfBBox) ; - SurfBBox.Expand( 100 * EPS_SMALL, 100 * EPS_SMALL, 100 * EPS_SMALL) ; - + // Determino i punti estremi del bounding box Point3d ptMapOrig, ptMapEnd ; SurfBBox.GetMinMax( ptMapOrig, ptMapEnd) ; + // Il dexel se parte da un triangolo della trimesh può non trovare l'intersezione, + // quindi espandiamo il bounding box per ovviare al problema. + SurfBBox.Expand( 100 * EPS_SMALL, 100 * EPS_SMALL, 100 * EPS_SMALL) ; + // Sistema di riferimento mappa m_MapFrame[0].Set( ptMapOrig, Frame3d::TOP) ; diff --git a/VolTriZmapVolume.cpp b/VolTriZmapVolume.cpp index ce7c9c4..059f16e 100644 --- a/VolTriZmapVolume.cpp +++ b/VolTriZmapVolume.cpp @@ -632,6 +632,13 @@ VolZmap::AddIntervals( unsigned int nGrid, const Point3d & ptP, //---------------------------------------------------------------------------- bool VolZmap::MillingStep( const Point3d& ptPs, const Vector3d& vtDs, const Point3d& ptPe, const Vector3d& vtDe) +{ + return MillingStep( ptPs, vtDs, Vector3d(), ptPe, vtDe, Vector3d()) ; +} + +//---------------------------------------------------------------------------- +bool +VolZmap::MillingStep( const Point3d& ptPs, const Vector3d& vtDs, const Vector3d& vtAs, const Point3d& ptPe, const Vector3d& vtDe, const Vector3d& vtAe) { // Controllo sull'effettiva esisenza del movimento if ( AreSamePointApprox( ptPs, ptPe) && AreSameVectorApprox( vtDs, vtDe)) @@ -648,15 +655,14 @@ VolZmap::MillingStep( const Point3d& ptPs, const Vector3d& vtDs, const Point3d& ptLe[0].ToLoc( m_MapFrame[0]) ; if ( m_nMapNum > 1) { - ptLs[1].x = ptLs[0].y ; ptLs[1].y = ptLs[0].z ; ptLs[1].z = ptLs[0].x ; ptLs[2].x = ptLs[0].z ; ptLs[2].y = ptLs[0].x ; ptLs[2].z = ptLs[0].y ; ptLe[1].x = ptLe[0].y ; ptLe[1].y = ptLe[0].z ; ptLe[1].z = ptLe[0].x ; ptLe[2].x = ptLe[0].z ; ptLe[2].y = ptLe[0].x ; ptLe[2].z = ptLe[0].y ; } - else { + else { ptLs[1].x = 0 ; ptLs[1].y = 0 ; ptLs[1].z = 0 ; ptLs[2].x = 0 ; ptLs[2].y = 0 ; ptLs[2].z = 0 ; @@ -666,39 +672,47 @@ VolZmap::MillingStep( const Point3d& ptPs, const Vector3d& vtDs, const Point3d& // Vettori nei sistemi di riferimento intrinseci dello Zmap - Vector3d vtLs [3] ; - Vector3d vtLe [3] ; + Vector3d vtLs[3] ; + Vector3d vtLe[3] ; vtLs[0] = vtDs ; vtLs[0].ToLoc( m_MapFrame[0]) ; + vtLs[0].Normalize() ; vtLe[0] = vtDe ; vtLe[0].ToLoc( m_MapFrame[0]) ; + vtLe[0].Normalize() ; if ( m_nMapNum > 1) { - vtLs[1].x = vtLs[0].y ; vtLs[1].y = vtLs[0].z ; vtLs[1].z = vtLs[0].x ; vtLs[2].x = vtLs[0].z ; vtLs[2].y = vtLs[0].x ; vtLs[2].z = vtLs[0].y ; vtLe[1].x = vtLe[0].y ; vtLe[1].y = vtLe[0].z ; vtLe[1].z = vtLe[0].x ; vtLe[2].x = vtLe[0].z ; vtLe[2].y = vtLe[0].x ; vtLe[2].z = vtLe[0].y ; } - else { - vtLs[1].x = 0 ; vtLs[1].y = 0 ; vtLs[1].z = 0 ; - vtLs[2].x = 0 ; vtLs[2].y = 0 ; vtLs[2].z = 0 ; + // Vettori ausiliari nei sistemi di riferimento intrinseci dello Zmap + Vector3d vtALs[3] ; + Vector3d vtALe[3] ; - vtLe[1].x = 0 ; vtLe[1].y = 0 ; vtLe[1].z = 0 ; - vtLe[2].x = 0 ; vtLe[2].y = 0 ; vtLe[2].z = 0 ; + vtALs[0] = vtAs ; + vtALs[0].ToLoc( m_MapFrame[0]) ; + vtALs[0].Normalize() ; + + vtALe[0] = vtAe ; + vtALe[0].ToLoc( m_MapFrame[0]) ; + vtALe[0].Normalize() ; + + if ( m_nMapNum > 1) { + vtALs[1].x = vtALs[0].y ; vtALs[1].y = vtALs[0].z ; vtALs[1].z = vtALs[0].x ; + vtALs[2].x = vtALs[0].z ; vtALs[2].y = vtALs[0].x ; vtALs[2].z = vtALs[0].y ; + + vtALe[1].x = vtALe[0].y ; vtALe[1].y = vtALe[0].z ; vtALe[1].z = vtALe[0].x ; + vtALe[2].x = vtALe[0].z ; vtALe[2].y = vtALe[0].x ; vtALe[2].z = vtALe[0].y ; } - // Ciclo sulle mappe for ( unsigned int i = 0 ; i < m_nMapNum ; ++ i) { - // Normalizzo i vettori - vtLs[i].Normalize() ; - vtLe[i].Normalize() ; - // Direzione utensile costante: pura traslazione if ( AreSameVectorApprox( vtLs[i], vtLe[i])) { @@ -712,39 +726,59 @@ VolZmap::MillingStep( const Point3d& ptPs, const Vector3d& vtDs, const Point3d& // Foratura if ( vtMove.SqLenXY() < EPS_SMALL) { - // Utensile generico - if ( m_nToolType == 0) + switch ( m_nToolType) { + case GENTOOL : GenTool_ZDrilling( i, ptLs[i], ptLe[i], vtLs[i]) ; - // Fresa cilindrica o sferica - else if ( m_nToolType == 1 || m_nToolType == 2) - CylBall_ZDrilling( i, ptLs[i], ptLe[i], vtLs[i]) ; - // Fresa conica - else if ( m_nToolType == 4) - Conus_ZDrilling( i, ptLs[i], ptLe[i], vtLs[i]) ; + break ; + case CYLMILL : + case BALLMILL : + CylBall_ZDrilling( i, ptLs[i], ptLe[i], vtLs[i]) ; + break ; + case CONUSMILL : + Conus_ZDrilling( i, ptLs[i], ptLe[i], vtLs[i]) ; + break ; + case MORTISER : + Mrt_ZDrilling( i, ptLs[i], ptLe[i], vtLs[i], vtALs[i]) ; + break ; + case CHISEL : + Chs_ZDrilling( i, ptLs[i], ptLe[i], vtLs[i], vtALs[i]) ; + break ; + } } // Fresatura con vettore movimento perpendicolare all'utensile else if ( abs( vtMove.z) < EPS_SMALL) { - // Utensile generico - if ( m_nToolType == 0) + switch ( m_nToolType) { + case GENTOOL : GenTool_ZMilling( i, ptLs[i], ptLe[i], vtLs[i]) ; - // Fresa cilindrica o sferica - else if ( m_nToolType == 1 || m_nToolType == 2) + break ; + case CYLMILL : + case BALLMILL : CylBall_ZPerp( i, ptLs[i], ptLe[i], vtLs[i]) ; - // Fresa conica - else if ( m_nToolType == 4) - Conus_ZPerp( i, ptLs[i], ptLe[i], vtLs[i]) ; + break ; + case CONUSMILL : + Conus_ZPerp( i, ptLs[i], ptLe[i], vtLs[i]) ; + break ; + case MORTISER : + Mrt_ZMilling( i, ptLs[i], ptLe[i], vtLs[i], vtALs[i]) ; + break ; + case CHISEL : + Chs_ZMilling( i, ptLs[i], ptLe[i], vtLs[i], vtALs[i]) ; + break ; + } } // Fresatura con vettore movimento generico rispetto all'utensile else { - // Utensile generico - if ( m_nToolType == 0) + switch ( m_nToolType) { + case GENTOOL : GenTool_ZMilling( i, ptLs[i], ptLe[i], vtLs[i]) ; - // Fresa cilindrica o sferica - else if ( m_nToolType == 1 || m_nToolType == 2) + break ; + case CYLMILL : + case BALLMILL : CylBall_ZMilling( i, ptLs[i], ptLe[i], vtLs[i]) ; - // Fresa conica - else + break ; + case CONUSMILL : Conus_ZMilling( i, ptLs[i], ptLe[i], vtLs[i]) ; + } } } // Versore utensile nel piano @@ -758,44 +792,65 @@ VolZmap::MillingStep( const Point3d& ptPs, const Vector3d& vtDs, const Point3d& // Foratura if ( dSqLOrt < EPS_SMALL * EPS_SMALL) { - // Utensile generico - if ( m_nToolType == 0) + switch ( m_nToolType) { + case GENTOOL : GenTool_Drilling( i, ptLs[i], ptLe[i], vtLs[i]) ; - // Fresa cilindrica o sferica - else if ( m_nToolType == 1 || m_nToolType == 2) + break ; + case CYLMILL : + case BALLMILL : CylBall_XYDrilling( i, ptLs[i], ptLe[i], vtLs[i]) ; - // Fresa conica - else - Conus_XYDrilling( i, ptLs[i], ptLe[i], vtLs[i]) ; + break ; + case CONUSMILL : + Conus_XYDrilling( i, ptLs[i], ptLe[i], vtLs[i]) ; + break ; + case MORTISER : + Mrt_Drilling( i, ptLs[i], ptLe[i], vtLs[i], vtALs[i]) ; + break ; + case CHISEL : + Chs_Drilling( i, ptLs[i], ptLe[i], vtLs[i], vtALs[i]) ; + break ; + } } // Fresatura con vettore movimento perpendicolare all'utensile else if ( 1 - dSqLOrt < EPS_SMALL * EPS_SMALL) { - // Utensile generico - if ( m_nToolType == 0) + switch ( m_nToolType) { + case GENTOOL : GenTool_Milling( i, ptLs[i], ptLe[i], vtLs[i]) ; - // Fresa cilindrica o sferica - else if ( m_nToolType == 1 || m_nToolType == 2) + break ; + case CYLMILL : + case BALLMILL : CylBall_XYPerp( i, ptLs[i], ptLe[i], vtLs[i]) ; - // Fresa conica - else if ( m_nToolType == 4) - Conus_XYPerp( i, ptLs[i], ptLe[i], vtLs[i]) ; + break ; + case CONUSMILL : + Conus_XYPerp( i, ptLs[i], ptLe[i], vtLs[i]) ; + break ; + case MORTISER : + Mrt_Milling( i, ptLs[i], ptLe[i], vtLs[i], vtALs[i]) ; + break ; + case CHISEL : + Chs_Milling( i, ptLs[i], ptLe[i], vtLs[i], vtALs[i]) ; + break ; + } } // Fresatura con vettore movimento generico rispetto all'utensile else { - // Utensile generico - if ( m_nToolType == 0) + switch ( m_nToolType) { + case GENTOOL : GenTool_Milling( i, ptLs[i], ptLe[i], vtLs[i]) ; - // Fresa cilindrica o sferica - else if ( m_nToolType == 1 || m_nToolType == 2) + break ; + case CYLMILL : + case BALLMILL : CylBall_XYMilling( i, ptLs[i], ptLe[i], vtLs[i]) ; - // Altri utensili - else if ( m_nToolType == 4) + break ; + case CONUSMILL : Conus_XYMilling( i, ptLs[i], ptLe[i], vtLs[i]) ; + break ; + } } } + // Versore utensile con direzione generica else { - Vector3d vtMove = ptLe[i] - ptLs[i] ; vtMove.Normalize() ; Vector3d vtMLong = ( vtMove * vtLs[i]) * vtLs[i] ; Vector3d vtMOrt = vtMove - vtMLong ; @@ -804,24 +859,45 @@ VolZmap::MillingStep( const Point3d& ptPs, const Vector3d& vtDs, const Point3d& // Foratura if ( dSqLOrt < EPS_SMALL * EPS_SMALL) { - // Utensile generico - if ( m_nToolType == 0) + switch ( m_nToolType) { + case GENTOOL : GenTool_Drilling( i, ptLs[i], ptLe[i], vtLs[i]) ; - // Fresa cilindrica e sferica - else if ( m_nToolType == 1 || m_nToolType == 2) - CylBall_Drilling( i, ptLs[i], ptLe[i], vtLs[i]) ; - else if ( m_nToolType == 4) + break ; + case CYLMILL : + case BALLMILL : + CylBall_Drilling( i, ptLs[i], ptLe[i], vtLs[i]) ; + break ; + case CONUSMILL : Conus_Drilling( i, ptLs[i], ptLe[i], vtLs[i]) ; + break ; + case MORTISER : + Mrt_Drilling( i, ptLs[i], ptLe[i], vtLs[i], vtALs[i]) ; + break ; + case CHISEL : + Chs_Drilling( i, ptLs[i], ptLe[i], vtLs[i], vtALs[i]) ; + break ; + } } + else { - // Utensile generico - if ( m_nToolType == 0) + switch ( m_nToolType) { + case GENTOOL : GenTool_Milling( i, ptLs[i], ptLe[i], vtLs[i]) ; - // Fresa cilindrica e sferica - else if ( m_nToolType == 1 || m_nToolType == 2) - CylBall_Milling( i, ptLs[i], ptLe[i], vtLs[i]) ; - else if ( m_nToolType == 4) - Conus_Milling( i, ptLs[i], ptLe[i], vtLs[i]) ; + break ; + case CYLMILL : + case BALLMILL : + CylBall_Milling( i, ptLs[i], ptLe[i], vtLs[i]) ; + break ; + case CONUSMILL : + Conus_Milling( i, ptLs[i], ptLe[i], vtLs[i]) ; + break ; + case MORTISER : + Mrt_Milling( i, ptLs[i], ptLe[i], vtLs[i], vtALs[i]) ; + break ; + case CHISEL : + Chs_Milling( i, ptLs[i], ptLe[i], vtLs[i], vtALs[i]) ; + break ; + } } } } @@ -843,7 +919,7 @@ VolZmap::CylBall_ZDrilling( unsigned int nGrid, const Point3d & ptS, const Point unsigned int nStartI, nStartJ, nEndI, nEndJ ; // Verifica sull'interferenza utensile Zmap - bool bTest = BoundingBox( nGrid, ptS, ptE, vtToolDir, vtToolDir, nStartI, nStartJ, nEndI, nEndJ) ; + bool bTest = BoundingBox( nGrid, ptS, ptE, vtToolDir, nStartI, nStartJ, nEndI, nEndJ) ; if ( ! bTest) return true ; @@ -875,10 +951,10 @@ VolZmap::CylBall_ZDrilling( unsigned int nGrid, const Point3d & ptS, const Point // Se il punto si trova dentro il cerchio taglio if ( dSqLen < dSqRad - 2 * m_dRadius * EPS_SMALL) // utensile cilindrico - if ( m_nToolType == CylindricalMill) + if ( m_nToolType == CYLMILL) SubtractIntervals( nGrid, i, j, dMinStemZ, dMaxStemZ, Z_AX, - Z_AX) ; // utensile sferico - else if ( m_nToolType == BallEndMill) { + else if ( m_nToolType == BALLMILL) { double dH = sqrt( dSqRad - dSqLen) ; @@ -907,7 +983,7 @@ VolZmap::CylBall_ZPerp( unsigned int nGrid, const Point3d& ptS, const Point3d& p unsigned int nStartI, nStartJ, nEndI, nEndJ ; // Verifica sull'interferenza utensile Zmap - bool bTest = BoundingBox( nGrid, ptS, ptE, vtToolDir, vtToolDir, nStartI, nStartJ, nEndI, nEndJ) ; + bool bTest = BoundingBox( nGrid, ptS, ptE, vtToolDir, nStartI, nStartJ, nEndI, nEndJ) ; if ( ! bTest) return true ; @@ -947,7 +1023,7 @@ VolZmap::CylBall_ZPerp( unsigned int nGrid, const Point3d& ptS, const Point3d& p double dP1 = vtC * vtV1 ; double dP2 = vtC * vtV2 ; // Utensile cilindrico - if ( m_nToolType == CylindricalMill) { + if ( m_nToolType == CYLMILL) { // Se il punto cade nella zona di interesse taglio if ( ( dP1 * dP1 + dP2 * dP2 < dSafeSqRad) || ( ( dP1 - dLen) * ( dP1 - dLen) + dP2 * dP2) < dSafeSqRad || @@ -956,7 +1032,7 @@ VolZmap::CylBall_ZPerp( unsigned int nGrid, const Point3d& ptS, const Point3d& p SubtractIntervals( nGrid, i, j, dMinStemZ, dMaxStemZ, Z_AX, - Z_AX) ; } // Utensile sferico - else if ( m_nToolType == BallEndMill) { + else if ( m_nToolType == BALLMILL) { if ( abs( dP2) < dSafeRad) { @@ -1038,7 +1114,7 @@ VolZmap::CylBall_ZMilling( unsigned int nGrid, const Point3d & ptS, const Point3 unsigned int nStartI, nStartJ, nEndI, nEndJ ; // Verifica sull'interferenza utensile Zmap - bool bTest = BoundingBox( nGrid, ptS, ptE, vtToolDir, vtToolDir, nStartI, nStartJ, nEndI, nEndJ) ; + bool bTest = BoundingBox( nGrid, ptS, ptE, vtToolDir, nStartI, nStartJ, nEndI, nEndJ) ; if ( ! bTest) return true ; @@ -1181,7 +1257,7 @@ VolZmap::Conus_ZDrilling( unsigned int nGrid, const Point3d & ptS, const Point3d unsigned int nStartI, nStartJ, nEndI, nEndJ ; // Verifica sull'interferenza utensile Zmap - bool bTest = BoundingBox( nGrid, ptS, ptE, vtToolDir, vtToolDir, nStartI, nStartJ, nEndI, nEndJ) ; + bool bTest = BoundingBox( nGrid, ptS, ptE, vtToolDir, nStartI, nStartJ, nEndI, nEndJ) ; if ( ! bTest) return true ; @@ -1323,7 +1399,7 @@ VolZmap::Conus_ZPerp( unsigned int nGrid, const Point3d & ptS, const Point3d & p unsigned int nStartI, nStartJ, nEndI, nEndJ ; // Verifica sull'interferenza utensile Zmap - bool bTest = BoundingBox( nGrid, ptS, ptE, vtToolDir, vtToolDir, nStartI, nStartJ, nEndI, nEndJ) ; + bool bTest = BoundingBox( nGrid, ptS, ptE, vtToolDir, nStartI, nStartJ, nEndI, nEndJ) ; if ( ! bTest) return true ; @@ -1710,6 +1786,142 @@ VolZmap::Conus_ZMilling( unsigned int nGrid, const Point3d & ptS, const Point3d return true ; } +// --------- Mortasatrice ----------------------------------------------------- + +// ---------------------------------------------------------------------------- +bool +VolZmap::Mrt_ZDrilling( unsigned int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtToolDir, const Vector3d& vtAux) +{ + // Proiezione della traiettoria sul piano dei movimenti possibili + Vector3d vtMoveOnP = ( ptE - ptS) * vtToolDir * vtToolDir ; + Point3d ptEOnP = ptS + vtMoveOnP ; + + // Scompongo la mortasatrice in solidi semplici + + // Parallelepipedo di base + double dLenX = m_dMrtChsWidth ; + double dLenY = m_dMrtChsThickness ; + double dLenZ = m_dHeight - m_dRCorner ; + + CompPar_ZDrilling( nGrid, dLenX, dLenY, dLenZ, ptS, ptEOnP, vtToolDir, vtAux) ; + + // Se la punta è di tipo bull-nose + if ( abs( m_dMrtChsWidth - 2 * m_dRCorner) > EPS_SMALL) { + + // Parallelepipedo di punta + Point3d ptTipS = ptS - dLenZ * vtToolDir ; + Point3d ptTipE = ptEOnP - dLenZ * vtToolDir ; + + dLenX = abs( m_dMrtChsWidth - 2 * m_dRCorner) ; + dLenZ = m_dRCorner ; + + CompPar_ZDrilling( nGrid, dLenX, dLenY, dLenZ, ptTipS, ptTipE, vtToolDir, vtAux) ; + + Vector3d vtVOnP = vtToolDir ^ vtAux ; + + // Cilindri + Point3d ptSminus = ptTipS - ( 0.5 * dLenX) * vtVOnP + 0.5 * dLenY * vtAux ; + Point3d ptEminus = ptTipE - ( 0.5 * dLenX) * vtVOnP + 0.5 * dLenY * vtAux ; + Point3d ptSplus = ptTipS + ( 0.5 * dLenX) * vtVOnP + 0.5 * dLenY * vtAux ; + Point3d ptEplus = ptTipE + ( 0.5 * dLenX) * vtVOnP + 0.5 * dLenY * vtAux ; + + CompCyl_Milling( nGrid, ptSminus, ptEminus, vtAux, dLenY, m_dRCorner, false, false) ; + CompCyl_Milling( nGrid, ptSplus, ptEplus, vtAux, dLenY, m_dRCorner, false, false) ; + } + // se la punta è di tipo sfera + else { + + // Cilindro + Point3d ptCylS = ptS - dLenZ * vtToolDir + 0.5 * dLenY * vtAux ; + Point3d ptCylE = ptEOnP - dLenZ * vtToolDir + 0.5 * dLenY * vtAux ; + + CompCyl_ZMilling( nGrid, ptCylS, ptCylE, vtAux, dLenY, m_dRCorner) ; + } + + return true ; +} + +//---------------------------------------------------------------------------- +bool +VolZmap::Mrt_ZMilling( unsigned int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtToolDir, const Vector3d& vtAux) +{ + // Proiezione della traiettoria sul piano di movimento + Vector3d vtPlV = vtToolDir ^ vtAux ; + + if ( vtPlV * ( ptE - ptS) < 0) + vtPlV *= - 1 ; + + Point3d ptPlS = ptS ; + Point3d ptPlE = ptS + ( ptE - ptS) * vtPlV * vtPlV ; + + // Scompongo la mortasatrice in solidi semplici + + // Parallelepipedo di base + double dLenX = m_dMrtChsWidth ; + double dLenY = m_dMrtChsThickness ; + double dLenZ = m_dHeight - m_dRCorner ; + + CompPar_ZMilling( nGrid, dLenX, dLenY, dLenZ, ptPlS, ptPlE, vtToolDir, vtAux) ; + + // Se la punta è di tipo bull-nose + if ( abs( m_dMrtChsWidth - 2 * m_dRCorner) > EPS_SMALL) { + + // Parallelepipedo di punta + Point3d ptTipS = ptPlS - dLenZ * vtToolDir ; + Point3d ptTipE = ptPlE - dLenZ * vtToolDir ; + + dLenX = abs( m_dMrtChsWidth - 2 * m_dRCorner) ; + dLenZ = m_dRCorner ; + + //CompPar_ZMilling( nGrid, dLenX, dLenY, dLenZ, ptTipS, ptTipE, vtToolDir, vtAux) ; + + // Cilindro ( il moto dei due cilindri si sovrappone, quindi è inutile + // eseguire due volte il conto + Point3d ptSminus = ptTipS - ( 0.5 * dLenX) * vtPlV + 0.5 * dLenY * vtAux ; + /*Point3d ptEminus = ptTipE - ( 0.5 * dLenX) * vtPlV + 0.5 * dLenY * vtAux ; + Point3d ptSplus = ptTipS + ( 0.5 * dLenX) * vtPlV + 0.5 * dLenY * vtAux ;*/ + Point3d ptEplus = ptTipE + ( 0.5 * dLenX) * vtPlV + 0.5 * dLenY * vtAux ; + + CompCyl_Milling( nGrid, ptSminus, ptEplus, vtAux, dLenY, m_dRCorner, false, false) ; + } + // se la punta è di tipo sfera + else { + + // Cilindro + Point3d ptCylS = ptPlS - dLenZ * vtToolDir + 0.5 * dLenY * vtAux ; + Point3d ptCylE = ptPlE - dLenZ * vtToolDir + 0.5 * dLenY * vtAux ; + + CompCyl_ZMilling( nGrid, ptCylS, ptCylE, vtAux, dLenY, m_dRCorner) ; + } + + return true ; +} + +// --------- Chisel ---------------------------------------------------------- + +//---------------------------------------------------------------------------- +bool +VolZmap::Chs_ZDrilling( unsigned int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtToolDir, const Vector3d& vtAux) +{ + CompPar_ZDrilling( nGrid, m_dMrtChsWidth, m_dMrtChsThickness, m_dHeight, + ptS, ptE, vtToolDir, vtAux) ; + return true ; +} + +//---------------------------------------------------------------------------- +bool +VolZmap::Chs_ZMilling( unsigned int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtToolDir, const Vector3d& vtAux) +{ + // Proiezione della traiettoria sul piano dei moti possibili + Point3d ptSp = ptS ; + Vector3d vtMoveOnP = ( ptE - ptS) - ( ptE - ptS) * vtToolDir * vtToolDir ; + Point3d ptEp = ptS + vtMoveOnP ; + + CompPar_ZMilling( nGrid, m_dMrtChsWidth, m_dMrtChsThickness, m_dHeight, + ptSp, ptEp, vtToolDir, vtAux) ; + return true ; +} + // --------- Utensile generico ------------------------------------------------ //---------------------------------------------------------------------------- @@ -1890,6 +2102,7 @@ VolZmap::GenTool_ZMilling( unsigned int nGrid, const Point3d & ptS, const Point3 else dHeight = 0 ; } + // Caso arco else if ( nCurveType == CRV_ARC) { @@ -1925,23 +2138,18 @@ VolZmap::GenTool_ZMilling( unsigned int nGrid, const Point3d & ptS, const Point3 pCurve = pToolProfile->GetNextCurve() ; } return true ; - } - // ---------- VERSORE UTENSILE NEL PIANO XY ---------------------------------- // --------- Cilindro e sfera ------------------------------------------------ //---------------------------------------------------------------------------- bool -VolZmap::CylBall_XYDrilling( unsigned int nGrid, const Point3d & ptS, const Point3d & ptE, const Vector3d & vtToolDir) +VolZmap::CylBall_XYDrilling( unsigned int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtToolDir) { - - unsigned int nStartI, nStartJ, nEndI, nEndJ ; - // Verifica sull'interferenza utensile Zmap - bool bTest = BoundingBox( nGrid, ptS, ptE, vtToolDir, vtToolDir, nStartI, nStartJ, nEndI, nEndJ) ; - + unsigned int nStartI, nStartJ, nEndI, nEndJ ; + bool bTest = BoundingBox( nGrid, ptS, ptE, vtToolDir, nStartI, nStartJ, nEndI, nEndJ) ; if ( ! bTest) return true ; @@ -1962,7 +2170,7 @@ VolZmap::CylBall_XYDrilling( unsigned int nGrid, const Point3d & ptS, const Poin Vector3d vtV1( - vtToolDir.x, - vtToolDir.y, 0) ; vtV1.Normalize() ; Vector3d vtV2 = vtV1 ; vtV2.Rotate( Z_AX, 90) ; - for( unsigned int i = nStartI ; i <= nEndI ; ++ i) { + for ( unsigned int i = nStartI ; i <= nEndI ; ++ i) { for ( unsigned int j = nStartJ ; j <= nEndJ ; ++ j) { double dX = ( i + 0.5) * m_dStep ; double dY = ( j + 0.5) * m_dStep ; @@ -1996,7 +2204,7 @@ VolZmap::CylBall_XYDrilling( unsigned int nGrid, const Point3d & ptS, const Poin } // Se l'utensile è sferico sottraggo anche la punta - if ( m_nToolType == BallEndMill) + if ( m_nToolType == BALLMILL) if ( dSqLen < dSqRad) { // LA SOLUZIONE MOMENTANEA è CREARE UTENSILE GENERICO SE LO STELO è PIù CORTO DEL RAGGIO double dH = sqrt( dSqRad - dSqLen) ; @@ -2020,11 +2228,9 @@ VolZmap::CylBall_XYDrilling( unsigned int nGrid, const Point3d & ptS, const Poin bool VolZmap::CylBall_XYPerp( unsigned int nGrid, const Point3d & ptS, const Point3d & ptE, const Vector3d & vtToolDir) { - unsigned int nStartI, nStartJ, nEndI, nEndJ ; - // Verifica sull'interferenza utensile Zmap - bool bTest = BoundingBox( nGrid, ptS, ptE, vtToolDir, vtToolDir, nStartI, nStartJ, nEndI, nEndJ) ; - + unsigned int nStartI, nStartJ, nEndI, nEndJ ; + bool bTest = BoundingBox( nGrid, ptS, ptE, vtToolDir, nStartI, nStartJ, nEndI, nEndJ) ; if ( ! bTest) return true ; @@ -2115,7 +2321,7 @@ VolZmap::CylBall_XYPerp( unsigned int nGrid, const Point3d & ptS, const Point3d SubtractIntervals( nGrid, i, j, dInfZ, dSupZ, vtNmin, vtNmax) ; } - if ( m_nToolType == BallEndMill) { + if ( m_nToolType == BALLMILL) { if ( dP1 > dStemHeigth - 2 * EPS_SMALL && ( dP1 - dStemHeigth) * ( dP1 - dStemHeigth) + dP2 * dP2 < dSafeSqRad) { @@ -2137,8 +2343,8 @@ VolZmap::CylBall_XYPerp( unsigned int nGrid, const Point3d & ptS, const Point3d } } } + else { - for( unsigned int i = nStartI ; i <= nEndI ; ++ i) { for( unsigned int j = nStartJ ; j <= nEndJ ; ++ j) { @@ -2221,7 +2427,7 @@ VolZmap::CylBall_XYPerp( unsigned int nGrid, const Point3d & ptS, const Point3d } } // Se l'utensile è ball-end sottraggo la punta - if ( m_nToolType == BallEndMill) { + if ( m_nToolType == BALLMILL) { if ( ( ( dP1 - dStemHeigth) * ( dP1 - dStemHeigth) + dP2 * dP2 < dSqRad || ( dP1 - dStemHeigth) * ( dP1 - dStemHeigth) + ( dP2 - dLenXY) * ( dP2 - dLenXY) < dSqRad || @@ -2245,8 +2451,8 @@ VolZmap::CylBall_XYPerp( unsigned int nGrid, const Point3d & ptS, const Point3d vtNmax = ptIStemT - ptInt ; vtNmax.Normalize() ; } - else if ( dP2 < dLenXY - dP2_0) { + else if ( dP2 < dLenXY - dP2_0) { dMax = dZI + dH0 + dDeltaZ * ( dP2 + dP2_0) / dLenXY ; Point3d ptInt( dX, dY, dMax) ; @@ -2254,8 +2460,8 @@ VolZmap::CylBall_XYPerp( unsigned int nGrid, const Point3d & ptS, const Point3d vtNmax = - ( ptInt - ptIStemT) + ( ptInt - ptIStemT) * vtMove * vtMove ; vtNmax.Normalize() ; } - else { + else { dMax = dZF + sqrt( dSqRad - ( dP1 - dStemHeigth) * ( dP1 - dStemHeigth) - ( dP2 - dLenXY) * ( dP2 - dLenXY)) ; Point3d ptInt( dX, dY, dMax) ; @@ -2274,8 +2480,8 @@ VolZmap::CylBall_XYPerp( unsigned int nGrid, const Point3d & ptS, const Point3d vtNmin = ptIStemT - ptInt ; vtNmin.Normalize() ; } - else if ( dP2 < dLenXY + dP2_0) { + else if ( dP2 < dLenXY + dP2_0) { dMin = dZI - dH0 + dDeltaZ * ( dP2 - dP2_0) / dLenXY ; Point3d ptInt( dX, dY, dMin) ; @@ -2283,8 +2489,8 @@ VolZmap::CylBall_XYPerp( unsigned int nGrid, const Point3d & ptS, const Point3d vtNmin = - ( ptInt - ptIStemT) + ( ptInt - ptIStemT) * vtMove * vtMove ; vtNmin.Normalize() ; } - else { + else { dMin = dZF - sqrt( dSqRad - ( dP1 - dStemHeigth) * ( dP1 - dStemHeigth) - ( dP2 - dLenXY) * ( dP2 - dLenXY)) ; Point3d ptInt( dX, dY, dMin) ; @@ -2293,7 +2499,6 @@ VolZmap::CylBall_XYPerp( unsigned int nGrid, const Point3d & ptS, const Point3d vtNmin.Normalize() ; } - SubtractIntervals( nGrid, i, j, dMin, dMax, vtNmin, vtNmax) ; } } @@ -2307,11 +2512,11 @@ VolZmap::CylBall_XYPerp( unsigned int nGrid, const Point3d & ptS, const Point3d bool VolZmap::CylBall_XYMilling( unsigned int nGrid, const Point3d & ptS, const Point3d & ptE, const Vector3d & vtToolDir) { - if ( m_nToolType == CylindricalMill) + if ( m_nToolType == CYLMILL) return CompCyl_Milling( nGrid, ptS, ptE, vtToolDir, m_dHeight, m_dRadius, false, false) ; - else if ( m_nToolType == BallEndMill) { + else if ( m_nToolType == BALLMILL) { double dHei = m_dHeight - m_dTipHeight ; @@ -2334,7 +2539,7 @@ VolZmap::Conus_XYDrilling( unsigned int nGrid, const Point3d & ptS, const Point3 unsigned int nStartI, nStartJ, nEndI, nEndJ ; // Verifica sull'interferenza utensile Zmap - bool bTest = BoundingBox( nGrid, ptS, ptE, vtToolDir, vtToolDir, nStartI, nStartJ, nEndI, nEndJ) ; + bool bTest = BoundingBox( nGrid, ptS, ptE, vtToolDir, nStartI, nStartJ, nEndI, nEndJ) ; if ( ! bTest) return true ; @@ -2472,7 +2677,7 @@ VolZmap::Conus_XYPerp( unsigned int nGrid, const Point3d& ptS, const Point3d& pt unsigned int nStartI, nStartJ, nEndI, nEndJ ; // Verifica sull'interferenza utensile Zmap - bool bTest = BoundingBox( nGrid, ptS, ptE, vtToolDir, vtToolDir, nStartI, nStartJ, nEndI, nEndJ) ; + bool bTest = BoundingBox( nGrid, ptS, ptE, vtToolDir, nStartI, nStartJ, nEndI, nEndJ) ; if ( ! bTest) return true ; @@ -2808,8 +3013,8 @@ VolZmap::Conus_XYPerp( unsigned int nGrid, const Point3d& ptS, const Point3d& pt //---------------------------------------------------------------------------- bool -VolZmap::Conus_XYMilling( unsigned int nGrid, const Point3d & ptS, const Point3d & ptE, const Vector3d & vtToolDir) { - +VolZmap::Conus_XYMilling( unsigned int nGrid, const Point3d & ptS, const Point3d & ptE, const Vector3d & vtToolDir) +{ double dStemHeigth = m_dHeight - m_dTipHeight ; CompCyl_Milling( nGrid, ptS, ptE, vtToolDir, dStemHeigth, m_dRadius, false, true) ; @@ -2837,8 +3042,8 @@ VolZmap::Conus_XYMilling( unsigned int nGrid, const Point3d & ptS, const Point3d // ---------- Cilindro e sfera ----------------------------------------------- //---------------------------------------------------------------------------- bool -VolZmap::CylBall_Drilling( unsigned int nGrid, const Point3d & ptS, const Point3d & ptE, const Vector3d & vtToolDir) { - +VolZmap::CylBall_Drilling( unsigned int nGrid, const Point3d & ptS, const Point3d & ptE, const Vector3d & vtToolDir) +{ double dStemHeigth = m_dHeight - m_dRadius ; CompCyl_Drilling( nGrid, ptS, ptE, vtToolDir, dStemHeigth, m_dRadius, false, false) ; @@ -2855,8 +3060,8 @@ VolZmap::CylBall_Drilling( unsigned int nGrid, const Point3d & ptS, const Point3 } //---------------------------------------------------------------------------- bool -VolZmap::CylBall_Milling( unsigned int nGrid, const Point3d & ptS, const Point3d & ptE, const Vector3d & vtToolDir) { - +VolZmap::CylBall_Milling( unsigned int nGrid, const Point3d & ptS, const Point3d & ptE, const Vector3d & vtToolDir) +{ double dStemHeigth = m_dHeight - m_dTipHeight ; CompCyl_Milling( nGrid, ptS, ptE, vtToolDir, dStemHeigth, m_dRadius, false, false) ; @@ -2875,8 +3080,8 @@ VolZmap::CylBall_Milling( unsigned int nGrid, const Point3d & ptS, const Point3d // ---------- Coni ----------------------------------------------------------- //---------------------------------------------------------------------------- bool -VolZmap::Conus_Drilling( unsigned int nGrid, const Point3d & ptS, const Point3d & ptE, const Vector3d & vtToolDir) { - +VolZmap::Conus_Drilling( unsigned int nGrid, const Point3d & ptS, const Point3d & ptE, const Vector3d & vtToolDir) +{ double dStemHeigth = m_dHeight - m_dTipHeight ; CompCyl_Drilling( nGrid, ptS, ptE, vtToolDir, dStemHeigth, m_dRadius, false, true) ; @@ -2901,8 +3106,8 @@ VolZmap::Conus_Drilling( unsigned int nGrid, const Point3d & ptS, const Point3d //---------------------------------------------------------------------------- bool -VolZmap::Conus_Milling( unsigned int nGrid, const Point3d & ptS, const Point3d & ptE, const Vector3d & vtToolDir) { - +VolZmap::Conus_Milling( unsigned int nGrid, const Point3d & ptS, const Point3d & ptE, const Vector3d & vtToolDir) +{ double dStemHeigth = m_dHeight - m_dTipHeight ; CompCyl_Milling( nGrid, ptS, ptE, vtToolDir, dStemHeigth, m_dRadius, false, true) ; @@ -2925,6 +3130,136 @@ VolZmap::Conus_Milling( unsigned int nGrid, const Point3d & ptS, const Point3d & return true ; } + +// ---------- Mortasatrice --------------------------------------------------- + +//---------------------------------------------------------------------------- +bool +VolZmap::Mrt_Drilling( unsigned int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtToolDir, const Vector3d& vtAux) +{ + // Proiezione della traiettoria sul piano dei movimenti possibili + //Vector3d vtMoveOnP = ( ptE - ptS) * vtVOnP * vtVOnP ; + Point3d ptEOnP = ptS + ( ptE - ptS) * vtToolDir * vtToolDir ; + + // Scompongo la mortasatrice in solidi semplici + + // Parallelepipedo di base + double dLenX = m_dMrtChsWidth ; + double dLenY = m_dMrtChsThickness ; + double dLenZ = m_dHeight - m_dRCorner ; + + CompPar_Drilling( nGrid, dLenX, dLenY, dLenZ, ptS, ptEOnP, vtToolDir, vtAux) ; + + // Se la punta è di tipo bull-nose + if ( abs( m_dMrtChsWidth - 2 * m_dRCorner) > EPS_SMALL) { + + // Parallelepipedo di punta + Point3d ptTipS = ptS - dLenZ * vtToolDir ; + Point3d ptTipE = ptEOnP - dLenZ * vtToolDir ; + + dLenX = abs( m_dMrtChsWidth - 2 * m_dRCorner) ; + dLenZ = m_dRCorner ; + + CompPar_Drilling( nGrid, dLenX, dLenY, dLenZ, ptTipS, ptTipE, vtToolDir, vtAux) ; + + Vector3d vtVOnP = vtToolDir ^ vtAux ; + + // Cilindri + Point3d ptSminus = ptTipS - ( 0.5 * dLenX) * vtVOnP + 0.5 * dLenY * vtAux ; + Point3d ptEminus = ptTipE - ( 0.5 * dLenX) * vtVOnP + 0.5 * dLenY * vtAux ; + Point3d ptSplus = ptTipS + ( 0.5 * dLenX) * vtVOnP + 0.5 * dLenY * vtAux ; + Point3d ptEplus = ptTipE + ( 0.5 * dLenX) * vtVOnP + 0.5 * dLenY * vtAux ; + + CompCyl_Milling( nGrid, ptSminus, ptEminus, vtAux, dLenY, m_dRCorner, false, false) ; + CompCyl_Milling( nGrid, ptSplus, ptEplus, vtAux, dLenY, m_dRCorner, false, false) ; + } + // se la punta è di tipo sfera + else { + + // Cilindro + Point3d ptCylS = ptS - dLenZ * vtToolDir + 0.5 * dLenY * vtAux ; + Point3d ptCylE = ptEOnP - dLenZ * vtToolDir + 0.5 * dLenY * vtAux ; + + CompCyl_Milling( nGrid, ptCylS, ptCylE, vtAux, dLenY, m_dRCorner, false, false) ; + } + + return true ; +} + +//---------------------------------------------------------------------------- +bool +VolZmap::Mrt_Milling( unsigned int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtToolDir, const Vector3d& vtAux) +{ + // Proiezione della traiettoria sul piano dei movimenti possibili + Point3d ptSp = ptS ; + Vector3d vtMoveDir = vtToolDir ^ vtAux ; + Point3d ptEp = ptS + ( ptE - ptS) * vtMoveDir * vtMoveDir ; + + // Scompongo la mortasatrice in solidi semplici + + // Parallelepipedo di base + double dLenX = m_dMrtChsWidth ; + double dLenY = m_dMrtChsThickness ; + double dLenZ = m_dHeight - m_dRCorner ; + + CompPar_Milling( nGrid, dLenX, dLenY, dLenZ, ptS, ptEp, vtToolDir, vtAux) ; + + // Se la punta è di tipo bull-nose + if ( abs( m_dMrtChsWidth - 2 * m_dRCorner) > EPS_SMALL) { + + // Parallelepipedo di punta + Point3d ptTipS = ptS - dLenZ * vtToolDir ; + Point3d ptTipE = ptEp - dLenZ * vtToolDir ; + + dLenX = abs( m_dMrtChsWidth - 2 * m_dRCorner) ; + dLenZ = m_dRCorner ; + + Vector3d vtVOnP = vtToolDir ^ vtAux ; + + // Cilindri + Point3d ptSminus = ptTipS - ( 0.5 * dLenX) * vtVOnP + 0.5 * dLenY * vtAux ; + Point3d ptEminus = ptTipE - ( 0.5 * dLenX) * vtVOnP + 0.5 * dLenY * vtAux ; + Point3d ptSplus = ptTipS + ( 0.5 * dLenX) * vtVOnP + 0.5 * dLenY * vtAux ; + Point3d ptEplus = ptTipE + ( 0.5 * dLenX) * vtVOnP + 0.5 * dLenY * vtAux ; + CompCyl_Milling( nGrid, ptSminus, ptEplus, vtAux, dLenY, m_dRCorner, false, false) ; + } + + // se la punta è di tipo sfera + else { + // Cilindro + Point3d ptCylS = ptS - dLenZ * vtToolDir + 0.5 * dLenY * vtAux ; + Point3d ptCylE = ptEp - dLenZ * vtToolDir + 0.5 * dLenY * vtAux ; + CompCyl_Milling( nGrid, ptCylS, ptCylE, vtAux, dLenY, m_dRCorner, false, false) ; + } + + return true ; +} + + +// ---------- Chisel --------------------------------------------------------- + +//---------------------------------------------------------------------------- +bool +VolZmap::Chs_Drilling( unsigned int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtToolDir, const Vector3d& vtAux) +{ + + return true ; +} + +//---------------------------------------------------------------------------- +bool +VolZmap::Chs_Milling( unsigned int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtToolDir, const Vector3d& vtAux) +{ + + // Proiezione della traiettoria sul piano dei movimenti possibili + Point3d ptSp = ptS ; + Vector3d vtMoveOnP = ( ptE - ptS) - ( ptE - ptS) * vtToolDir * vtToolDir ; + Point3d pEp = ptS + vtMoveOnP ; + + return true ; +} + + // ---------- Utensile generico ---------------------------------------------- //---------------------------------------------------------------------------- @@ -3261,7 +3596,7 @@ VolZmap::CompCyl_ZDrilling( unsigned int nGrid, const Point3d & ptS, const Point unsigned int nStartI, nStartJ, nEndI, nEndJ ; // Verifica sull'interferenza con lo Zmap - bool bTest = BBoxComponent( nGrid, ptS, ptE, vtToolDir, vtToolDir, nStartI, nStartJ, nEndI, nEndJ, + bool bTest = BBoxComponent( nGrid, ptS, ptE, vtToolDir, nStartI, nStartJ, nEndI, nEndJ, dRad, dRad, dHei) ; if ( ! bTest) @@ -3307,7 +3642,7 @@ VolZmap::CompConus_ZDrilling( unsigned int nGrid, const Point3d & ptS, const Poi unsigned int nStartI, nStartJ, nEndI, nEndJ ; // Verifica sull'interferenza con lo Zmap - bool Control = BBoxComponent( nGrid, ptS, ptE, vtToolDir, vtToolDir, nStartI, nStartJ, nEndI, nEndJ, dMaxRad, dMinRad, dHei) ; + bool Control = BBoxComponent( nGrid, ptS, ptE, vtToolDir, nStartI, nStartJ, nEndI, nEndJ, dMaxRad, dMinRad, dHei) ; if ( ! Control) return true ; @@ -3403,6 +3738,50 @@ VolZmap::CompConus_ZDrilling( unsigned int nGrid, const Point3d & ptS, const Poi return true ; } +//---------------------------------------------------------------------------- +bool +VolZmap::CompPar_ZDrilling( unsigned int nGrid, double dLenX, double dLenY, double dLenZ, + const Point3d& ptS, const Point3d& ptE, + const Vector3d& vtToolDir, const Vector3d& vtAux) +{ + unsigned int nStartI, nStartJ, nEndI, nEndJ ; + + // Controllo sull'interferenza utensile-solido + bool bInterf = BBoxParaComp( nGrid, dLenX, dLenY, dLenZ, ptS, ptE, vtToolDir, vtAux, nStartI, nStartJ, nEndI, nEndJ) ; + if ( ! bInterf) + return true ; + + // Costruisco un sistema di riferimento nel piano + Point3d ptOXY( ptS.x, ptS.y, 0) ; + Vector3d vtV1 = vtToolDir ^ vtAux ; + Vector3d vtV2 = vtAux ; + + // Quote estreme del volume asportato + double dMinZ = min( min( ptS.z, ptS.z - vtToolDir.z * dLenZ), min( ptE.z, ptE.z - vtToolDir.z * dLenZ)) ; + double dMaxZ = max( max( ptS.z, ptS.z - vtToolDir.z * dLenZ), max( ptE.z, ptE.z - vtToolDir.z * dLenZ)) ; + + for ( unsigned int i = nStartI ; i <= nEndI ; ++ i) { + for ( unsigned 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) ; + Vector3d vtR = ptC - ptOXY ; + + double dR1 = vtR * vtV1 ; + double dR2 = vtR * vtV2 ; + + if ( abs( dR1) < 0.5 * dLenX - EPS_SMALL && + abs( dR2) < 0.5 * dLenY - EPS_SMALL) + + SubtractIntervals( nGrid, i, j, dMinZ, dMaxZ, Z_AX, - Z_AX) ; + } + } + + return true ; +} + // Asse di simmetria diretto come l'asse Z: FRESATURA //---------------------------------------------------------------------------- @@ -3412,7 +3791,7 @@ VolZmap::CompCyl_ZMilling( unsigned int nGrid, const Point3d & ptS, const Point3 unsigned int nStartI, nStartJ, nEndI, nEndJ ; // Verifica sull'interferenza con lo Zmap - bool bTest = BBoxComponent( nGrid, ptS, ptE, vtToolDir, vtToolDir, nStartI, nStartJ, nEndI, nEndJ, dRad, dRad, dHei) ; + bool bTest = BBoxComponent( nGrid, ptS, ptE, vtToolDir, nStartI, nStartJ, nEndI, nEndJ, dRad, dRad, dHei) ; if ( ! bTest) return true ; @@ -3554,7 +3933,7 @@ VolZmap::CompConus_ZMilling( unsigned int nGrid, const Point3d & ptS, const Poin { unsigned int nStartI, nStartJ, nEndI, nEndJ ; - bool Control = BBoxComponent( nGrid, ptS, ptE, vtToolDir, vtToolDir, nStartI, nStartJ, nEndI, nEndJ, dMaxRad, dMinRad, dHei) ; + bool Control = BBoxComponent( nGrid, ptS, ptE, vtToolDir, nStartI, nStartJ, nEndI, nEndJ, dMaxRad, dMinRad, dHei) ; if ( ! Control) return true ; @@ -3881,6 +4260,121 @@ VolZmap::CompConus_ZMilling( unsigned int nGrid, const Point3d & ptS, const Poin return true ; } +//---------------------------------------------------------------------------- +bool // E' in realtà MillingPerp +VolZmap::CompPar_ZMilling( unsigned int nGrid, double dLenX, double dLenY, double dLenZ, + const Point3d& ptS, const Point3d& ptE, + const Vector3d& vtToolDir, const Vector3d& vtAux) { + + unsigned int nStartI, nStartJ, nEndI, nEndJ ; + + // Controllo sull'interferenza utensile-solido + bool bInterf = BBoxParaComp( nGrid, dLenX, dLenY, dLenZ, ptS, ptE, vtToolDir, vtAux, nStartI, nStartJ, nEndI, nEndJ) ; + if ( ! bInterf) + return true ; + + // Materiale asportato nelle posizioni iniziale e finale + + // Costruisco un sistema di riferimento nel piano + Point3d ptSXY( ptS.x, ptS.y, 0) ; + Point3d ptEXY( ptE.x, ptE.y, 0) ; + Vector3d vtV1 = vtToolDir ^ vtAux ; + Vector3d vtV2 = vtAux ; + + if ( vtV1 * ( ptE - ptS) < 0) + vtV1 *= - 1 ; + + double dLenMove = ( ( ( ptE - ptS) * vtV1) * vtV1).Len() ; + + // Quote estreme del volume asportato + double dMinZ = min( min( ptS.z, ptS.z - vtToolDir.z * dLenZ), min( ptE.z, ptE.z - vtToolDir.z * dLenZ)) ; + double dMaxZ = max( max( ptS.z, ptS.z - vtToolDir.z * dLenZ), max( ptE.z, ptE.z - vtToolDir.z * dLenZ)) ; + + // Studio del volume asportato durante il moto + + // Studio delle simmetrieto + + Point3d ptLs = ( ( ptE - ptS) * vtAux > 0 ? ptS : ptE) ; + Point3d ptLe = ( ( ptE - ptS) * vtAux > 0 ? ptE : ptS) ; + + Vector3d vtMove = ptLe - ptLs ; + + Vector3d vtW3 = vtAux ; + Vector3d vtAnsatz = ( vtW3 ^ vtToolDir) ; + + + bool bSymmetry = vtMove * ( vtW3 ^ vtToolDir) > 0 ; + + Vector3d vtW2 = ( bSymmetry ? vtAnsatz : - vtAnsatz) ; + Vector3d vtW1 = ( bSymmetry ? vtToolDir : - vtToolDir) ; + + /* Point3d ptBase = bSymmetry ? ptLs - ( 0.5 * dLenZ) * vtW1 : ptLs ; */ // mi sa che +è sbagliato: va fatto sempre non se bSymmetry è true + + + Frame3d MotionFrame ; + + Point3d ptDiagMin = ptLs - vtW2 * ( 0.5 * dLenX) + vtW3 * ( 0.5 * dLenY) ; + Point3d ptDiagMax = ptLs + vtW2 * ( 0.5 * dLenX) - vtW3 * ( 0.5 * dLenY) ; + + Vector3d vtU1 = ptDiagMax - ptDiagMin ; vtU1.Normalize() ; + Vector3d vtU2 = ( vtU1 * vtMove > 0 ? vtMove - vtMove * vtU1 * vtU1 : + vtMove * vtU1 * vtU1 - vtMove) ; + vtU2.Normalize() ; + Vector3d vtU3 = vtU1 ^ vtU2 ; + + Point3d ptOMot = ( vtMove * vtU1 > 0 ? ptDiagMin : ptDiagMin + vtMove) ; + + Point3d ptOMotXY( ptOMot.x, ptOMot.y, 0) ; + + + double dLen1 = vtMove * vtU1 ; + double dLen2 = vtMove * vtU2 ; + double dHx = ( ptDiagMax - ptDiagMin).Len() ; + + for ( unsigned int i = nStartI ; i <= nEndI ; ++ i) { + for ( unsigned 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) ; + Vector3d vtRS = ptC - ptSXY ; + Vector3d vtRE = ptC - ptEXY ; + + double dRS1 = vtRS * vtV1 ; + double dRS2 = vtRS * vtV2 ; + + double dRE1 = vtRE * vtV1 ; + double dRE2 = vtRE * vtV2 ; + + // Asportazione materiale nella posizione iniziale + if ( abs( dRS1) < 0.5 * dLenX - EPS_SMALL && + abs( dRS2) < 0.5 * dLenY - EPS_SMALL) + + SubtractIntervals( nGrid, i, j, dMinZ, dMaxZ, Z_AX, - Z_AX) ; + + // Asportazione materiale nella posizione finale + if ( abs( dRE1) < 0.5 * dLenX - EPS_SMALL && + abs( dRE2) < 0.5 * dLenY - EPS_SMALL) + + SubtractIntervals( nGrid, i, j, dMinZ, dMaxZ, Z_AX, - Z_AX) ; + + // Asportazione materiale nel moto + Vector3d vtR = ptC - ptOMotXY ; + + double dR1 = vtR * vtU1 ; + double dR2 = vtR * vtU2 ; + + if ( dR2 > EPS_SMALL && dR2 < dLen2 - EPS_SMALL && + dR1 * dLen2 > dLen1 * dR2 + EPS_SMALL && + dR1 * dLen2 < dHx * dLen2 + dLen1 * dR2 - EPS_SMALL) + + SubtractIntervals( nGrid, i, j, dMinZ, dMaxZ, Z_AX, - Z_AX) ; + } + } + return true ; +} + // Asse di simmetria con orientazione generica: FORATURA @@ -3891,7 +4385,7 @@ VolZmap::CompCyl_Drilling( unsigned int nGrid, const Point3d & ptS, const Point3 { unsigned int nStartI, nEndI, nStartJ, nEndJ ; - bool Control = BBoxComponent( nGrid, ptS, ptE, vtToolDir, vtToolDir, nStartI, nStartJ, nEndI, nEndJ, + bool Control = BBoxComponent( nGrid, ptS, ptE, vtToolDir, nStartI, nStartJ, nEndI, nEndJ, dRad, dRad, dHei) ; if ( ! Control) @@ -3968,7 +4462,7 @@ VolZmap::CompConus_Drilling( unsigned int nGrid, const Point3d & ptS, const Poin { unsigned int nStartI, nStartJ, nEndI, nEndJ ; - bool Control = BBoxComponent( nGrid, ptS, ptE, vtToolDir, vtToolDir, nStartI, nStartJ, nEndI, nEndJ, + bool Control = BBoxComponent( nGrid, ptS, ptE, vtToolDir, nStartI, nStartJ, nEndI, nEndJ, dMaxRad, dMinRad, dHei) ; if ( ! Control) @@ -4068,8 +4562,70 @@ VolZmap::CompConus_Drilling( unsigned int nGrid, const Point3d & ptS, const Poin return true ; } -// Asse di simmetria con orientazione generica: FRESATURA +//---------------------------------------------------------------------------- +bool +VolZmap::CompPar_Drilling( unsigned int nGrid, double dLenX, double dLenY, double dLenZ, + const Point3d& ptS, const Point3d& ptE, + const Vector3d& vtToolDir, const Vector3d& vtAux) +{ + unsigned int nStartI, nStartJ, nEndI, nEndJ ; + + // Controllo sull'interferenza utensile-solido + bool bInterf = BBoxParaComp( nGrid, dLenX, dLenY, dLenZ, ptS, ptE, vtToolDir, vtAux, nStartI, nStartJ, nEndI, nEndJ) ; + if ( ! bInterf) + return true ; + // Costruzione di un sistema di riferimento per il volume + // asportato dal solido nelle psoizioni iniziale e finale. + Vector3d vtV1 = vtToolDir ; + Vector3d vtV2 = vtAux ^ vtV1 ; + Vector3d vtV3 = vtAux ; + + double dLenMove = ( ptE - ptS).Len() ; + Point3d ptO = ptS - ( ( ptE - ptS) * vtV1 > 0 ? dLenZ : dLenZ + dLenMove) * vtV1 - ( 0.5 * dLenX) * vtV2 ; + Frame3d ParaFrame ; ParaFrame.Set( ptO, vtV1, vtV2, vtV3) ; + + for ( unsigned int i = nStartI ; i <= nEndI ; ++ i) { + for ( unsigned 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) ; + + Point3d ptInt1, ptInt2 ; + Vector3d vtN1, vtN2 ; + + if ( IntersLineMyPolyhedron( ptC, Z_AX, ParaFrame, dLenZ + dLenMove, dLenX, dLenY, 0, ptInt1, ptInt2, vtN1, vtN2)) { + + double dMin, dMax ; + Vector3d vtNmin, vtNmax ; + + if ( ptInt1.z < ptInt2.z) { + + dMin = ptInt1.z ; + dMax = ptInt2.z ; + vtNmin = vtN1 ; + vtNmax = vtN2 ; + } + else { + + dMin = ptInt2.z ; + dMax = ptInt1.z ; + vtNmin = vtN2 ; + vtNmax = vtN1 ; + } + + SubtractIntervals( nGrid, i, j, dMin, dMax, vtNmin, vtNmax) ; + } + } + } + + return true ; +} + +// Asse di simmetria con orientazione generica: FRESATURA + //---------------------------------------------------------------------------- bool VolZmap::CompCyl_Milling( unsigned int nGrid, const Point3d& ptS, const Point3d& ptE, @@ -4078,7 +4634,7 @@ VolZmap::CompCyl_Milling( unsigned int nGrid, const Point3d& ptS, const Point3d& unsigned int nStartI, nStartJ, nEndI, nEndJ ; // Verifica sull'interferenza utensile Zmap - bool Control = BBoxComponent( nGrid, ptS, ptE, vtToolDir, vtToolDir, + bool Control = BBoxComponent( nGrid, ptS, ptE, vtToolDir, nStartI, nStartJ, nEndI, nEndJ, dRad, dRad, dHei) ; if ( ! Control) return true ; @@ -4257,7 +4813,7 @@ VolZmap::CompConus_Milling( unsigned int nGrid, const Point3d & ptS, const Point { unsigned int nStartI, nStartJ, nEndI, nEndJ ; - bool Control = BBoxComponent( nGrid, ptS, ptE, vtToolDir, vtToolDir, nStartI, nStartJ, nEndI, nEndJ, + bool Control = BBoxComponent( nGrid, ptS, ptE, vtToolDir, nStartI, nStartJ, nEndI, nEndJ, dMaxRad, dMinRad, dHei) ; if ( ! Control) @@ -4693,7 +5249,166 @@ VolZmap::CompConus_Milling( unsigned int nGrid, const Point3d & ptS, const Point } return true ; } -} +} + +//---------------------------------------------------------------------------- +bool +VolZmap::CompPar_Milling( unsigned int nGrid, double dLenX, double dLenY, double dLenZ, + const Point3d& ptS, const Point3d& ptE, + const Vector3d& vtToolDir, const Vector3d& vtAux) +{ + unsigned int nStartI, nStartJ, nEndI, nEndJ ; + + // Controllo sull'interferenza utensile-solido + bool bInterf = BBoxParaComp( nGrid, dLenX, dLenY, dLenZ, ptS, ptE, vtToolDir, vtAux, nStartI, nStartJ, nEndI, nEndJ) ; + if ( ! bInterf) + return true ; + + // Vettore di movimento + Vector3d vtMove = ptE - ptS ; + + // Sistema di riferimento del solido + // nelle posizioni iniziale e finale. + Vector3d vtV1 = vtToolDir ; + Vector3d vtV2 = ( vtMove * ( vtV1 ^ vtAux) > 0 ? ( vtV1 ^ vtAux) : ( vtAux ^ vtV1)) ; + Vector3d vtV3 = vtV1 ^ vtV2 ; + Point3d ptO = ptS - dLenZ * vtV1 - vtV2 * ( 0.5 * dLenX) ; + Frame3d ParaFrame ; ParaFrame.Set( ptO, vtV1, vtV2, vtV3) ; + + // Lunghezza della traiettoria + double dLenMove = vtMove * vtV2 ; + + // Studio del volume asportato durante il moto + Point3d ptLs = ( vtMove * vtAux >= 0 ? ptS : ptE) ; + Point3d ptLe = ( vtMove * vtAux >= 0 ? ptE : ptS) ; + + Vector3d vtW3 = vtAux ; + Vector3d vtAnsatz = ( vtW3 ^ vtToolDir) ; + + Vector3d vtMv = ptLe - ptLs ; + + bool bSymmetry = vtMv * ( vtW3 ^ vtToolDir) > 0 ; + + Vector3d vtW2 = ( bSymmetry ? vtAnsatz : - vtAnsatz) ; + Vector3d vtW1 = ( bSymmetry ? vtToolDir : - vtToolDir) ; + + Point3d ptBase = bSymmetry ? ptLs - dLenZ * vtW1 : ptLs ; + + /*Point3d ptOMotion = ptBase - vtW2 * ( 0.5 * dLenX) - vtW3 * ( 0.5 * dLenY) ; + + Vector3d vtU1 = vtW2 ; + Vector3d vtU2 = vtW3 ; + Vector3d vtU3 = vtW1 ; */ + + Frame3d MotionFrame ; /*MotionFrame.Set( ptOMotion, vtU1, vtU2, vtU3) ;*/ + + Point3d ptDiagMin = ptBase - vtW2 * ( 0.5 * dLenX) + vtW3 * ( 0.5 * dLenY) ; + Point3d ptDiagMax = ptBase + vtW2 * ( 0.5 * dLenX) - vtW3 * ( 0.5 * dLenY) ; + + Vector3d vtU1 = ptDiagMax - ptDiagMin ; + double dDimX = ( ptDiagMax - ptDiagMin).Len() ; + vtU1.Normalize() ; + bool bSymmetry2 = vtU1 * vtMv > 0 ; + Vector3d vtU2 = ( bSymmetry2 ? vtMv - vtMv * vtU1 * vtU1 : + vtMv * vtU1 * vtU1 - vtMv) ; + vtU2.Normalize() ; + Vector3d vtU3 = vtU1 ^ vtU2 ; + + Point3d ptOMotion = ( vtMv * vtU1 > 0 ? ptDiagMin : ptDiagMin + vtMv) + vtU3 * ( 0.5 * dLenZ) ; + + MotionFrame.Set( ptOMotion, vtU1, vtU2, vtU3) ; + + double dLen1 = abs( vtMv * vtU1) ; + double dLen2 = abs( vtMv * vtU2) ; + + + for ( unsigned int i = nStartI ; i <= nEndI ; ++ i) { + for ( unsigned 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) ; + + Point3d ptInt1, ptInt2 ; + Vector3d vtN1, vtN2 ; + + // Solido nella posizione iniziale + if ( IntersLineMyPolyhedron( ptC, Z_AX, ParaFrame, dLenZ, dLenX, dLenY, 0, ptInt1, ptInt2, vtN1, vtN2)) { + + double dMin, dMax ; + Vector3d vtNmin, vtNmax ; + + if ( ptInt1.z < ptInt2.z) { + + dMin = ptInt1.z ; + dMax = ptInt2.z ; + vtNmin = vtN1 ; + vtNmax = vtN2 ; + } + else { + + dMin = ptInt2.z ; + dMax = ptInt1.z ; + vtNmin = vtN2 ; + vtNmax = vtN1 ; + } + + SubtractIntervals( nGrid, i, j, dMin, dMax, vtNmin, vtNmax) ; + } + + // Solido nella posizione finale + if ( IntersLineMyPolyhedron( ptC - vtMove, Z_AX, ParaFrame, dLenZ, dLenX, dLenY, 0, ptInt1, ptInt2, vtN1, vtN2)) { + + double dMin, dMax ; + Vector3d vtNmin, vtNmax ; + + if ( ptInt1.z < ptInt2.z) { + + dMin = ptInt1.z + vtMove.z ; + dMax = ptInt2.z + vtMove.z ; + vtNmin = vtN1 ; + vtNmax = vtN2 ; + } + else { + + dMin = ptInt2.z + vtMove.z ; + dMax = ptInt1.z + vtMove.z ; + vtNmin = vtN2 ; + vtNmax = vtN1 ; + } + + SubtractIntervals( nGrid, i, j, dMin, dMax, vtNmin, vtNmax) ; + } + + // Volume spazzato nel moto + if ( IntersLineMyPolyhedron( ptC, Z_AX, MotionFrame, dDimX, dLen2, dLenZ, dLen1, ptInt1, ptInt2, vtN1, vtN2)) { + + double dMin, dMax ; + Vector3d vtNmin, vtNmax ; + + if ( ptInt1.z < ptInt2.z) { + + dMin = ptInt1.z ; + dMax = ptInt2.z ; + vtNmin = vtN1 ; + vtNmax = vtN2 ; + } + else { + + dMin = ptInt2.z ; + dMax = ptInt1.z ; + vtNmin = vtN2 ; + vtNmax = vtN1 ; + } + + SubtractIntervals( nGrid, i, j, dMin, dMax, vtNmin, vtNmax) ; + } + } + } + + return true ; +} // ---------- SFERA ---------------------------------------------------------- @@ -4703,7 +5418,7 @@ VolZmap::CompBall_Milling( unsigned int nGrid, const Point3d & ptLs, const Point { unsigned int nStartI, nStartJ, nEndI, nEndJ ; - bool Control = BBoxComponent( nGrid, ptLs, ptLe, V_NULL, V_NULL, nStartI, nStartJ, nEndI, nEndJ, dRad, 0, 0) ; + bool Control = BBoxComponent( nGrid, ptLs, ptLe, V_NULL, nStartI, nStartJ, nEndI, nEndJ, dRad, 0, 0) ; if ( ! Control) return true ; @@ -4820,11 +5535,11 @@ VolZmap::CompBall_Milling( unsigned int nGrid, const Point3d & ptLs, const Point //---------------------------------------------------------------------------- inline bool -VolZmap::BoundingBox( unsigned int nGrid, const Point3d & ptP1, const Point3d & ptP2, const Vector3d & vtV1, const Vector3d & vtV2, +VolZmap::BoundingBox( unsigned int nGrid, const Point3d & ptP1, const Point3d & ptP2, const Vector3d & vtV, unsigned int & nStI, unsigned int & nStJ, unsigned int & nEnI, unsigned int & nEnJ) { - // NB: E' vitale che vengano passati i punti e i vettori nel sistema di riferimento - // di riferimento opportuno. + // NB: E' vitale che vengano passati i punti e i vettori + // nel sistema di riferimento opportuno. // Controllo sull'ammissibilità del numero di griglia if ( nGrid < 0 || nGrid > 2) @@ -4846,8 +5561,8 @@ VolZmap::BoundingBox( unsigned int nGrid, const Point3d & ptP1, const Point3d & double dMaxRad = max( m_dRadius, m_dTipRadius) ; // Determinazione delle posizioni della punta dell'utensile nelle posizioni iniziale e finale - Point3d ptP1T = ptP1 - m_dHeight * vtV1 ; - Point3d ptP2T = ptP2 - m_dHeight * vtV2 ; + Point3d ptP1T = ptP1 - m_dHeight * vtV ; + Point3d ptP2T = ptP2 - m_dHeight * vtV ; // Determinazione dei limiti del più piccolo parallelepipedo contenente il movimento double dMinX = min( min( ptP1.x, ptP1T.x), min( ptP2.x, ptP2T.x)) - dMaxRad ; @@ -4876,12 +5591,12 @@ VolZmap::BoundingBox( unsigned int nGrid, const Point3d & ptP1, const Point3d & //---------------------------------------------------------------------------- inline bool -VolZmap::BBoxComponent( unsigned int nGrid, const Point3d & ptP1, const Point3d & ptP2, const Vector3d & vtV1, const Vector3d & vtV2, +VolZmap::BBoxComponent( unsigned int nGrid, const Point3d & ptP1, const Point3d & ptP2, const Vector3d & vtV, unsigned int & nStI, unsigned int & nStJ, unsigned int & nEnI, unsigned int & nEnJ, double dRad, double dTipRad, double dHei) { - // NB: E' vitale che vengano passati i punti e i vettori nel sistema di riferimento - // di riferimento opportuno. + // NB: E' vitale che vengano passati i punti e i vettori + // nel sistema di riferimento opportuno. // Controllo sull'ammissibilità del numero di griglia if ( nGrid < 0 || nGrid > 2) @@ -4902,16 +5617,16 @@ VolZmap::BBoxComponent( unsigned int nGrid, const Point3d & ptP1, const Point3d double dMaxRad = max( dRad, dTipRad) ; // Determinazione delle posizioni della punta del componente nelle posizioni iniziale e finale - Point3d ptP1T = ptP1 - dHei * vtV1 ; - Point3d ptP2T = ptP2 - dHei * vtV2 ; + Point3d ptP1T = ptP1 - dHei * vtV ; + Point3d ptP2T = ptP2 - dHei * vtV ; // Determinazione dei limiti del più piccolo parallelepipedo contenente il movimento - double dMinX = min( min( ptP1.x, ptP1T.x), min( ptP2.x, ptP2T.x)) - dMaxRad; - double dMinY = min( min( ptP1.y, ptP1T.y), min( ptP2.y, ptP2T.y)) - dMaxRad; - double dMinZ = min( min( ptP1.z, ptP1T.z), min( ptP2.z, ptP2T.z)) - dMaxRad; - double dMaxX = max( max( ptP1.x, ptP1T.x), max( ptP2.x, ptP2T.x)) + dMaxRad; - double dMaxY = max( max( ptP1.y, ptP1T.y), max( ptP2.y, ptP2T.y)) + dMaxRad; - double dMaxZ = max( max( ptP1.z, ptP1T.z), max( ptP2.z, ptP2T.z)) + dMaxRad; + double dMinX = min( min( ptP1.x, ptP1T.x), min( ptP2.x, ptP2T.x)) - dMaxRad ; + double dMinY = min( min( ptP1.y, ptP1T.y), min( ptP2.y, ptP2T.y)) - dMaxRad ; + double dMinZ = min( min( ptP1.z, ptP1T.z), min( ptP2.z, ptP2T.z)) - dMaxRad ; + double dMaxX = max( max( ptP1.x, ptP1T.x), max( ptP2.x, ptP2T.x)) + dMaxRad ; + double dMaxY = max( max( ptP1.y, ptP1T.y), max( ptP2.y, ptP2T.y)) + dMaxRad ; + double dMaxZ = max( max( ptP1.z, ptP1T.z), max( ptP2.z, ptP2T.z)) + dMaxRad ; // Verifica dell'interferenza dell'utensile con lo Zmap if ( dMaxX < EPS_SMALL || dMinX > dMaxXValue - EPS_SMALL) @@ -4929,3 +5644,56 @@ VolZmap::BBoxComponent( unsigned int nGrid, const Point3d & ptP1, const Point3d return true ; } + +//---------------------------------------------------------------------------- +inline bool +VolZmap::BBoxParaComp( unsigned int nGrid, double dLenX, double dLenY, double dLenZ, + const Point3d& ptS, const Point3d& ptE, const Vector3d& vtD, const Vector3d& vtA, + unsigned int& nStI, unsigned int& nStJ, unsigned int& nEnI, unsigned int& nEnJ) +{ + // NB: E' vitale che vengano passati i punti e i vettori + // nel sistema di riferimento opportuno. + + // Determino le posizioni iniziale e + // finale della punta dell'utensile. + Point3d ptSTip = ptS - vtD * dLenZ ; + Point3d ptETip = ptE - vtD * dLenZ ; + + double dMaxDim = max( dLenX, dLenY) ; + + // Determinazione dei limiti del più piccolo parallelepipedo contenente il movimento + double dMinX = min( min( ptS.x, ptSTip.x), min( ptE.x, ptETip.x)) - dMaxDim ; + double dMinY = min( min( ptS.y, ptSTip.y), min( ptE.y, ptETip.y)) - dMaxDim ; + double dMinZ = min( min( ptS.z, ptSTip.z), min( ptE.z, ptETip.z)) - dMaxDim ; + double dMaxX = max( max( ptS.x, ptSTip.x), max( ptE.x, ptETip.x)) + dMaxDim ; + double dMaxY = max( max( ptS.y, ptSTip.y), max( ptE.y, ptETip.y)) + dMaxDim ; + double dMaxZ = max( max( ptS.z, ptSTip.z), max( ptE.z, ptETip.z)) + dMaxDim ; + + unsigned int nMaxNx, nMaxNy ; + + double dMaxXValue, dMaxYValue ; + double dMinZValue, dMaxZValue ; + + nMaxNx = m_nNx[nGrid] ; nMaxNy = m_nNy[nGrid] ; + + dMaxXValue = nMaxNx * m_dStep ; dMaxYValue = nMaxNy * m_dStep ; + + dMinZValue = m_dMinZ[nGrid] ; dMaxZValue = m_dMaxZ[nGrid] ; + + // Verifica dell'interferenza dell'utensile con lo Zmap + if ( dMaxX < EPS_SMALL || dMinX > dMaxXValue - EPS_SMALL) + return false ; + if ( dMaxY < EPS_SMALL || dMinY > dMaxYValue - EPS_SMALL) + return false ; + if ( dMaxZ < dMinZValue + EPS_SMALL || dMinZ > dMaxZValue - EPS_SMALL) + return false ; + + // Limiti su indici + nStI = ( dMinX < EPS_SMALL ? 0 : static_cast ( dMinX / m_dStep)) ; + nEnI = ( dMaxX > dMaxXValue - EPS_SMALL ? nMaxNx - 1 : static_cast ( dMaxX / m_dStep)) ; + nStJ = ( dMinY < EPS_SMALL ? 0 : static_cast ( dMinY / m_dStep)) ; + nEnJ = ( dMaxY > dMaxYValue - EPS_SMALL ? nMaxNy - 1 : static_cast ( dMaxY / m_dStep)) ; + + return true ; +} + diff --git a/VolZmap.h b/VolZmap.h index ed94337..23d229e 100644 --- a/VolZmap.h +++ b/VolZmap.h @@ -84,11 +84,14 @@ class VolZmap : public IVolZmap, public IGeoObjRW bool GetTriangles( bool bAllBlocks, INTVECTOR& nModifiedBlocks, TRIA3DLISTVECTOR& vLstTria) const override ; bool GetDexelLines( int nDir, int nPos1, int nPos2, POLYLINELIST& lstPL) const override ; bool SetTolerances( double dLinTol, double dAngTolDeg = 90) override ; - bool SetStdTool( const std::string& pToolName, double dH, double dR, double dCornR) override ; - bool SetAdvTool( const std::string& pToolName, - double dH, double dR, double dTipH, double dTipR, double dCornR) override ; - bool SetGenTool( const std::string& pToolName, const ICurveComposite* pToolOutline) override ; + bool SetStdTool( const std::string& sToolName, double dH, double dR, double dCornR) override ; + bool SetAdvTool( const std::string& sToolName, + double dH, double dR, double dTipH, double dTipR, double dCornR) override ; + bool SetGenTool( const std::string& sToolName, const ICurveComposite* pToolOutline) override ; + bool SetMortiserTool( const std::string& sToolName, double dH, double dW, double dTh, double dRc) override ; + bool SetChiselTool( const std::string& sToolName, double dH, double dW, double dTh) override ; bool MillingStep( const Point3d& ptPs, const Vector3d& vtDs, const Point3d& ptPe, const Vector3d& vtDe) override ; + bool MillingStep( const Point3d& ptPs, const Vector3d& vtDs, const Vector3d& vtAs, const Point3d& ptPe, const Vector3d& vtDe, const Vector3d& vtAe) override ; bool GetDepth( const Point3d& ptP, const Vector3d& vtDir, double& dInLength, double& dOutLength) override ; bool AvoidBox( const Frame3d& frBox, const Vector3d& vtDiag) override ; @@ -108,11 +111,13 @@ class VolZmap : public IVolZmap, public IGeoObjRW return *this ; } private : - enum ToolType { GenericTool = 0, // generico da profilo -> usare SetTool - CylindricalMill = 1, // cilindrica - BallEndMill = 2, // sferica - BullNoseMill = 3, // naso di toro - ConusMill = 4} ; // con parte terminale conica + enum ToolType { GENTOOL = 0, // generico da profilo -> usare SetTool + CYLMILL = 1, // cilindrica + BALLMILL = 2, // sferica + BULLNOSEMILL = 3, // naso di toro + CONUSMILL = 4, // con parte terminale conica + MORTISER = 5, // mortasatrice + CHISEL = 6} ; // scalpello private : bool CopyFrom( const VolZmap& clSrc) ; @@ -133,7 +138,7 @@ class VolZmap : public IVolZmap, public IGeoObjRW bool IsPointInsideVoxel( int nI, int nJ, int nK, const Point3d& ptP) const ; bool IsPointInsideVoxelApprox( int nI, int nJ, int nK, const Point3d& ptP, double dPrec = EPS_SMALL) const ; bool GetPointVoxel( const Point3d& ptP, int& nVoxI, int& nVoxJ, int& nVoxK) const ; - + // OPERAZIONI SU INTERVALLI bool SubtractIntervals( unsigned int nGrid, unsigned int nI, unsigned int nJ, double dMin, double dMax, const Vector3d& vtNMin, const Vector3d& vtNMax) ; @@ -147,17 +152,26 @@ class VolZmap : public IVolZmap, public IGeoObjRW // SOTTRAZIONI // UTENSILI // Asse di simmetria parallelo a Z + + // Cilindro Sfera bool CylBall_ZDrilling( unsigned int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtToolDir) ; bool CylBall_ZPerp( unsigned int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtToolDir) ; bool CylBall_ZMilling( unsigned int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtToolDir) ; - + + // Coni bool Conus_ZDrilling( unsigned int nGrid, const Point3d & ptS, const Point3d& ptE, const Vector3d& vtToolDir) ; bool Conus_ZPerp( unsigned int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtToolDir) ; bool Conus_ZMilling( unsigned int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtToolDir) ; - bool Dr_ZMilling( unsigned int nGrid, const Point3d& ptLs, const Point3d& ptLe, const Vector3d & vtToolDir) ; - bool Sw_ZMilling( unsigned int nGrid, const Point3d& ptLs, const Point3d& ptLe, const Vector3d & vtToolDir) ; + // Mortasatrice + bool Mrt_ZDrilling( unsigned int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtToolDir, const Vector3d& vtAux) ; + bool Mrt_ZMilling( unsigned int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtToolDir, const Vector3d& vtAux) ; + // Chisel + bool Chs_ZDrilling( unsigned int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtToolDir, const Vector3d& vtAux) ; + bool Chs_ZMilling( unsigned int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtToolDir, const Vector3d& vtAux) ; + + // Utensile generico bool GenTool_ZDrilling( unsigned int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtToolDir) ; bool GenTool_ZMilling( unsigned int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtToolDir) ; @@ -171,12 +185,23 @@ class VolZmap : public IVolZmap, public IGeoObjRW bool Conus_XYMilling( unsigned int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtToolDir) ; // Asse di simmetria con orientazione generica + // Cilindro e sfera bool CylBall_Drilling( unsigned int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtToolDir) ; bool CylBall_Milling( unsigned int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtToolDir) ; + // Coni bool Conus_Drilling( unsigned int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtToolDir) ; bool Conus_Milling( unsigned int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtToolDir) ; + // Mortasatrice + bool Mrt_Drilling( unsigned int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtToolDir, const Vector3d& vtAux) ; + bool Mrt_Milling( unsigned int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtToolDir, const Vector3d& vtAux) ; // E' in realtà un Perp + + // Chisel + bool Chs_Drilling( unsigned int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtToolDir, const Vector3d& vtAux) ; + bool Chs_Milling( unsigned int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtToolDir, const Vector3d& vtAux) ; // E' in realtà un Perp + + // Utensile generico bool GenTool_Drilling( unsigned int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtToolDir) ; bool GenTool_Milling( unsigned int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtToolDir) ; @@ -188,12 +213,19 @@ class VolZmap : public IVolZmap, public IGeoObjRW double dHei, double dRad) ; bool CompConus_ZDrilling( unsigned int nGrid, const Point3d& ptLs, const Point3d& ptLe, const Vector3d& vtToolDir, double dHei, double dMaxRad, double dMinRad) ; + bool CompPar_ZDrilling( unsigned int nGrid, double dLenX, double dLenY, double dLenZ, + const Point3d& ptS, const Point3d& ptE, + const Vector3d& vtToolDir, const Vector3d& vtAux) ; // Milling bool CompCyl_ZMilling( unsigned int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtToolDir, double dHei, double dRad) ; bool CompConus_ZMilling( unsigned int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtToolDir, double dHei, double dMaxRad, double dMinRad) ; + bool CompPar_ZMilling( unsigned int nGrid, double dLenX, double dLenY, double dLenZ, + const Point3d& ptS, const Point3d& ptE, + const Vector3d& vtToolDir, const Vector3d& vtAux) ; // E' in realtà MillingPerp + // Asse di simmetria con orientazione generica @@ -202,22 +234,32 @@ class VolZmap : public IVolZmap, public IGeoObjRW double dHei, double dRad, bool bTapB, bool bTapT) ; bool CompConus_Drilling( unsigned int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtToolDir, double dHei, double dMaxRad, double dMinRad, bool bTapB, bool bTapT) ; + bool CompPar_Drilling( unsigned int nGrid, double dLenX, double dLenY, double dLenZ, + const Point3d& ptS, const Point3d& ptE, + const Vector3d& vtToolDir, const Vector3d& vtAux) ; // Milling bool CompCyl_Milling( unsigned int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtToolDir, double dHei, double dRad, bool bTapB, bool bTapT) ; bool CompConus_Milling( unsigned int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtToolDir, double dHei, double dMaxRad, double dMinRad, bool bTapB, bool bTapT) ; + bool CompPar_Milling( unsigned int nGrid, double dLenX, double dLenY, double dLenZ, + const Point3d& ptS, const Point3d& ptE, + const Vector3d& vtToolDir, const Vector3d& vtAux) ; // E' in realtà MillingPerp // Generica traslazione sfera bool CompBall_Milling( unsigned int nGrid, const Point3d& ptS, const Point3d& ptE, double dRad) ; - // BBox per utensili e solidi semplici - inline bool BoundingBox( unsigned int nGrid, const Point3d& ptP1, const Point3d& ptP2, const Vector3d& vtV1, const Vector3d& vtV2, + // BBox per utensili e solidi semplici in movimenti di traslazione pura; in futuro si dovrà implementare le routine che prevedono rotazioni + inline bool BoundingBox( unsigned int nGrid, const Point3d& ptP1, const Point3d& ptP2, const Vector3d& vtV, unsigned int& nStI, unsigned int& nStJ, unsigned int& nEnI, unsigned int& nEnJ) ; - inline bool BBoxComponent( unsigned int nGrid, const Point3d& ptP1, const Point3d& ptP2, const Vector3d& vtV1, const Vector3d& vtV2, + inline bool BBoxComponent( unsigned int nGrid, const Point3d& ptP1, const Point3d& ptP2, const Vector3d& vtV, unsigned int& nStI, unsigned int& nStJ, unsigned int& nEnI, unsigned int& nEnJ, double dRad, double dTipRad, double dHei) ; + inline bool BBoxParaComp( unsigned int nGrid, double dLenX, double dLenY, double dLenZ, + const Point3d& ptS, const Point3d& ptE, const Vector3d& vtD, const Vector3d& vtA, + unsigned int& nStI, unsigned int& nStJ, unsigned int& nEnI, unsigned int& nEnJ) ; + // Intersezioni bool IntersLineBox( const Point3d& ptP, const Vector3d& vtV, const Point3d& ptMin, const Point3d& ptMax, @@ -315,6 +357,9 @@ class VolZmap : public IVolZmap, public IGeoObjRW double m_dRadius ; double m_dRCorner ; double m_dTipRadius ; + double m_dMrtChsWidth ; + double m_dMrtChsThickness ; + mutable TriaMatrix m_InterBlockTria ; } ; diff --git a/VolZmapTool.cpp b/VolZmapTool.cpp index 426dbd4..9dfcbf8 100644 --- a/VolZmapTool.cpp +++ b/VolZmapTool.cpp @@ -44,7 +44,7 @@ VolZmap::SetStdTool( const string& sToolName, double dH, double dR, double dCorn return false ; // utensile cilindrico if ( dCornR < EPS_SMALL) { - m_nToolType = CylindricalMill ; + m_nToolType = CYLMILL ; m_dHeight = dH ; m_dRadius = dR ; m_dTipHeight = 0 ; @@ -53,14 +53,14 @@ VolZmap::SetStdTool( const string& sToolName, double dH, double dR, double dCorn } // utensile naso di toro else if ( dCornR < dR - EPS_SMALL) { - m_nToolType = BullNoseMill ; + m_nToolType = BULLNOSEMILL ; m_dHeight = dH ; m_dRadius = dR ; m_dTipHeight = dCornR ; m_dTipRadius = dR - dCornR ; m_dRCorner = dCornR ; // come profilo - m_nToolType = GenericTool ; + m_nToolType = GENTOOL ; Point3d pt0( 0, 0, 0) ; Point3d pt1( m_dRadius, 0, 0) ; Point3d pt2( m_dRadius, - m_dHeight + m_dTipHeight, 0) ; @@ -77,7 +77,7 @@ VolZmap::SetStdTool( const string& sToolName, double dH, double dR, double dCorn } // utensile sferico else if ( dCornR < dR + EPS_SMALL) { - m_nToolType = BallEndMill ; + m_nToolType = BALLMILL ; m_dHeight = dH ; m_dRadius = dR ; m_dTipHeight = m_dRadius ; @@ -118,7 +118,7 @@ VolZmap::SetAdvTool( const string& sToolName, double dH, double dR, // Se raggio corner nullo, allora utensile conico if ( dCornR < EPS_SMALL) { - m_nToolType = ConusMill ; + m_nToolType = CONUSMILL ; m_dRCorner = 0 ; // assegno nome e identificativo m_sToolName = sToolName ; @@ -127,7 +127,7 @@ VolZmap::SetAdvTool( const string& sToolName, double dH, double dR, } // Altrimenti utensile generico. - m_nToolType = GenericTool ; + m_nToolType = GENTOOL ; m_dRCorner = dCornR ; m_ToolOutline.Clear() ; @@ -219,7 +219,7 @@ VolZmap::SetGenTool( const string& sToolName, const ICurveComposite* pToolOutlin { // Assegno nome, tipo e id dell'utensile m_sToolName = sToolName ; - m_nToolType = GenericTool ; + m_nToolType = GENTOOL ; m_nCurrentToolNum = 0 ; // Copio il profilo e garantisco sia di soli archi e rette (converto eventuali curve di Bezier) @@ -291,3 +291,47 @@ VolZmap::SetGenTool( const string& sToolName, const ICurveComposite* pToolOutlin return true ; } + +//---------------------------------------------------------------------------- +bool +VolZmap::SetMortiserTool( const std::string& sToolName, double dH, double dW, double dTh, double dRc) +{ + // Reset nome + m_sToolName.clear() ; + + if ( dH < EPS_SMALL || dW < EPS_SMALL || + dTh < EPS_SMALL || dRc < 0 || dW - 2 * dRc < 0) + return false ; + + m_dHeight = dH ; + m_dRCorner = dRc ; + m_dMrtChsWidth = dW ; + m_dMrtChsThickness = dTh ; + + m_sToolName = sToolName ; + m_nToolType = MORTISER ; + m_nCurrentToolNum = 0 ; + + return true ; +} + +//---------------------------------------------------------------------------- +bool +VolZmap::SetChiselTool( const std::string& sToolName, double dH, double dW, double dTh) { + + // Reset nome + m_sToolName.clear() ; + + if ( dH < EPS_SMALL || dW < EPS_SMALL || dTh < 0) + return false ; + + m_dHeight = dH ; + m_dMrtChsWidth = dW ; + m_dMrtChsThickness = dTh ; + + m_sToolName = sToolName ; + m_nToolType = CHISEL ; + m_nCurrentToolNum = 0 ; + + return true ; +} \ No newline at end of file