diff --git a/VolZmapVolume.cpp b/VolZmapVolume.cpp index 79411f9..1930c68 100644 --- a/VolZmapVolume.cpp +++ b/VolZmapVolume.cpp @@ -1765,6 +1765,7 @@ VolZmap::Comp_5AxisMilling( int nGrid, const Point3d& ptS, const Point3d& ptE, c Vector3d vtDirTip = ptP2T - ptP1T ; bool bTopIsPivot = vtDirTop.IsSmall() ; bool bTipIsPivot = vtDirTip.IsSmall() ; + bool bSmallMovement = vtDirTop.Len() < 10 * EPS_SMALL && vtDirTip.Len() < 10 * EPS_SMALL ; bool bInverse = ! (bTopIsPivot || bTipIsPivot) && vtDirTop * vtDirTip < 0 ; if ( bInverse) @@ -1857,26 +1858,44 @@ VolZmap::Comp_5AxisMilling( int nGrid, const Point3d& ptS, const Point3d& ptE, c } vector vvPtCtrl ; - // superficie laterale sinistra - CurveLine cLineLeftBottom ; cLineLeftBottom.Set( vPntTipEndFront.back(), vPntTipStartFront.back()) ; - if ( bInverse) - cLineLeftBottom.Invert() ; - PtrOwner cBezLeftBottom( GetBasicCurveBezier( LineToBezierCurve( &cLineLeftBottom, nDegU, bRat))) ; - CurveLine cLineLeftTop ; cLineLeftTop.Set( vPntTopEndFront.back(), vPntTopStartFront.back()) ; - PtrOwner cBezLeftTop( GetBasicCurveBezier( LineToBezierCurve( &cLineLeftTop, nDegU, bRat))) ; - vvPtCtrl.emplace_back( cBezLeftBottom->GetAllControlPoints()) ; - PNTVECTOR vPntLeft = cBezLeftTop->GetAllControlPoints() ; - vvPtCtrl.back().insert( vvPtCtrl.back().end(), vPntLeft.begin(), vPntLeft.end()) ; - // superficie laterale destra - CurveLine cLineRightBottom ; cLineRightBottom.Set( vPntTipStartFront.front(), vPntTipEndFront.front()) ; - if ( bInverse) - cLineRightBottom.Invert() ; - PtrOwner cBezRightBottom( GetBasicCurveBezier( LineToBezierCurve( &cLineRightBottom, nDegU, bRat))) ; - CurveLine cLineRightTop ; cLineRightTop.Set( vPntTopStartFront.front(), vPntTopEndFront.front()) ; - PtrOwner cBezRightTop( GetBasicCurveBezier( LineToBezierCurve( &cLineRightTop, nDegU, bRat))) ; - vvPtCtrl.emplace_back( cBezRightBottom->GetAllControlPoints()) ; - PNTVECTOR vPntRight = cBezRightTop->GetAllControlPoints() ; - vvPtCtrl.back().insert( vvPtCtrl.back().end(), vPntRight.begin(), vPntRight.end()) ; + if ( ! bSmallMovement) { + // superficie laterale sinistra + CurveLine cLineLeftBottom ; cLineLeftBottom.Set( vPntTipEndFront.back(), vPntTipStartFront.back()) ; + if ( ! cLineLeftBottom.IsValid()) + return false ; + if ( bInverse) + cLineLeftBottom.Invert() ; + PtrOwner cBezLeftBottom( GetBasicCurveBezier( LineToBezierCurve( &cLineLeftBottom, nDegU, bRat))) ; + if ( IsNull( cBezLeftBottom)) + return false ; + CurveLine cLineLeftTop ; cLineLeftTop.Set( vPntTopEndFront.back(), vPntTopStartFront.back()) ; + if ( ! cLineLeftTop.IsValid()) + return false ; + PtrOwner cBezLeftTop( GetBasicCurveBezier( LineToBezierCurve( &cLineLeftTop, nDegU, bRat))) ; + if ( IsNull( cBezLeftTop)) + return false ; + vvPtCtrl.emplace_back( cBezLeftBottom->GetAllControlPoints()) ; + PNTVECTOR vPntLeft = cBezLeftTop->GetAllControlPoints() ; + vvPtCtrl.back().insert( vvPtCtrl.back().end(), vPntLeft.begin(), vPntLeft.end()) ; + // superficie laterale destra + CurveLine cLineRightBottom ; cLineRightBottom.Set( vPntTipStartFront.front(), vPntTipEndFront.front()) ; + if ( ! cLineRightBottom.IsValid()) + return false ; + if ( bInverse) + cLineRightBottom.Invert() ; + PtrOwner cBezRightBottom( GetBasicCurveBezier( LineToBezierCurve( &cLineRightBottom, nDegU, bRat))) ; + if ( IsNull( cBezRightBottom)) + return false ; + CurveLine cLineRightTop ; cLineRightTop.Set( vPntTopStartFront.front(), vPntTopEndFront.front()) ; + if ( ! cLineRightTop.IsValid()) + return false ; + PtrOwner cBezRightTop( GetBasicCurveBezier( LineToBezierCurve( &cLineRightTop, nDegU, bRat))) ; + if ( IsNull( cBezRightTop)) + return false ; + vvPtCtrl.emplace_back( cBezRightBottom->GetAllControlPoints()) ; + PNTVECTOR vPntRight = cBezRightTop->GetAllControlPoints() ; + vvPtCtrl.back().insert( vvPtCtrl.back().end(), vPntRight.begin(), vPntRight.end()) ; + } if ( nSub == 1) { // superficie inferiore vvPtCtrl.emplace_back( PNTVECTOR( { vPntTipStartFront.front(), vPntTipStartFront.back(), vPntTipEndFront.front(), vPntTipEndFront.back() })) ; @@ -2116,7 +2135,7 @@ VolZmap::Comp_5AxisMilling( int nGrid, const Point3d& ptS, const Point3d& ptE, c vvPtCtrl.emplace_back( cBezTipEndF2->GetAllControlPoints()) ; PNTVECTOR vPntEndF2 = cBezTopEndF2->GetAllControlPoints() ; vvPtCtrl.back().insert( vvPtCtrl.back().end(), vPntEndF2.begin(), vPntEndF2.end()) ; - if ( bInverse) { + if ( bInverse || bSmallMovement) { // chiudo il volume con le superici verticali end back 1 vvPtCtrl.emplace_back( cBezTipEndB1->GetAllControlPoints()) ; PNTVECTOR vPntEndB1 = cBezTopEndB1->GetAllControlPoints() ; @@ -2135,7 +2154,7 @@ VolZmap::Comp_5AxisMilling( int nGrid, const Point3d& ptS, const Point3d& ptE, c vvPtCtrl.emplace_back( cBezTipStartB2->GetAllControlPoints()) ; PNTVECTOR vPntStartB2 = cBezTopStartB2->GetAllControlPoints() ; vvPtCtrl.back().insert( vvPtCtrl.back().end(), vPntStartB2.begin(), vPntStartB2.end()) ; - if ( bInverse) { + if ( bInverse || bSmallMovement) { // chiudo il volume con le superici verticali start front 1 vvPtCtrl.emplace_back( cBezTipStartF1->GetAllControlPoints()) ; PNTVECTOR vPntStartF1 = cBezTopStartF1->GetAllControlPoints() ; @@ -2215,7 +2234,7 @@ VolZmap::Comp_5AxisMilling( int nGrid, const Point3d& ptS, const Point3d& ptE, c } // inizializzo le superfici bilineari e i parametri per le intersezioni - for ( int z = 0 ; z < int( vvPtCtrl.size()) ; ++z) { + for ( int z = 0 ; z < ssize( vvPtCtrl) ; ++z) { vSurfBez[nSurfInd].sBez.Init( nDegU, nDegV, nSpanU, nSpanV, bRat) ; vSurfBez[nSurfInd].sBez.SetControlPoint( 0, vvPtCtrl[z][0]) ; vSurfBez[nSurfInd].sBez.SetControlPoint( 1, vvPtCtrl[z][1]) ;