From 70837364bd9d3cd185dea97b3ffd4572a568ad26 Mon Sep 17 00:00:00 2001 From: kreso-t Date: Sat, 8 Sep 2018 00:20:48 +0200 Subject: [PATCH] Path: Adaptive - fixes --- src/Mod/Path/libarea/Adaptive.cpp | 83 +++++++++++++++++-------------- src/Mod/Path/libarea/Adaptive.hpp | 2 +- 2 files changed, 47 insertions(+), 38 deletions(-) diff --git a/src/Mod/Path/libarea/Adaptive.cpp b/src/Mod/Path/libarea/Adaptive.cpp index 67613b39b8..11575d2b93 100644 --- a/src/Mod/Path/libarea/Adaptive.cpp +++ b/src/Mod/Path/libarea/Adaptive.cpp @@ -660,7 +660,8 @@ namespace AdaptivePath { } }; EngagePoint(const Paths & p_toolBoundPaths) { - toolBoundPaths = p_toolBoundPaths; + SetPaths(p_toolBoundPaths); + state.currentPathIndex=0; state.currentSegmentIndex=0; state.segmentPos =0; @@ -668,6 +669,16 @@ namespace AdaptivePath { calculateCurrentPathLength(); } + void SetPaths(const Paths & paths) { + toolBoundPaths = paths; + state.currentPathIndex=0; + state.currentSegmentIndex=0; + state.segmentPos =0; + state.totalDistance=0; + state.passes =0; + calculateCurrentPathLength(); + } + EngageState GetState() { return state; } @@ -720,7 +731,7 @@ namespace AdaptivePath { calculateCurrentPathLength(); ResetPasses(); } - bool nextEngagePoint(Adaptive2d*parent, const Paths & cleared, double step, double minCutArea, double maxCutArea) { + bool nextEngagePoint(Adaptive2d*parent, const Paths & cleared, double step, double minCutArea, double maxCutArea, int maxPases=2) { //cout << "nextEngagePoint called step: " << step << endl; Perf_NextEngagePoint.Start(); double prevArea = 0; // we want to make sure that we catch the point where the area is on raising slope @@ -730,7 +741,7 @@ namespace AdaptivePath { if(!moveForward(step)) { if(!nextPath()) { state.passes++; - if(state.passes>1) { + if(state.passes>=maxPases) { Perf_NextEngagePoint.Stop(); return false; // nothin more to cut } @@ -1093,7 +1104,7 @@ namespace AdaptivePath { if(helixRampDiameterRESOLUTION_FACTOR ) { // first point outside boundary - its not clear to cut @@ -1430,7 +1441,7 @@ namespace AdaptivePath { if(area>areaFactor*stepSize*optimalCutAreaPD) return false; //if tool is outside boundary -> its not clear to cut - if(!IsPointWithinCutRegion(toolBoundPaths,toolPos2) + if(!skipBoundsCheck && !IsPointWithinCutRegion(toolBoundPaths,toolPos2) && sqrt(DistancePointToPathsSqrd(toolBoundPaths,toolPos2,clp,clpPathIndex,clpSegmentIndex,clpParameter))>RESOLUTION_FACTOR ) { return false; @@ -2033,7 +2044,7 @@ namespace AdaptivePath { AppendToolPath(progressPaths, output,cleaned,clearedBeforePass,toolBoundPaths); CheckReportProgress(progressPaths); bad_engage_count=0; - engage.ResetPasses(); + //engage.ResetPasses(); //firstEngagePoint=true; } else { bad_engage_count++; @@ -2045,7 +2056,11 @@ namespace AdaptivePath { } else { // check which is better to find next cut from closest point or to continue from current double moveDistance = ENGAGE_SCAN_DISTANCE_FACTOR * RESOLUTION_FACTOR * 8; - if(!engage.nextEngagePoint(this, cleared,moveDistance,ENGAGE_AREA_THR_FACTOR*optimalCutAreaPD*RESOLUTION_FACTOR,4*referenceCutArea*stepOverFactor)) break; + if(!engage.nextEngagePoint(this, cleared,moveDistance, + ENGAGE_AREA_THR_FACTOR*optimalCutAreaPD*RESOLUTION_FACTOR, + 4*referenceCutArea*stepOverFactor)) { + break; + } } toolPos = engage.getCurrentPoint(); toolDir = engage.getCurrentDir(); @@ -2083,38 +2098,31 @@ namespace AdaptivePath { if(!finShiftedPath.empty()) finShiftedPath << finShiftedPath.front(); // make sure its closed + //safety check for finishing paths - check the area of finishing cut + for(size_t i=1;i3) cutOK=false; - } - } - if(cutOK) { - AppendToolPath(progressPaths,output,finCleaned,clearedBeforePass,toolBoundPaths); - //expand cleared for finishing path - clipof.Clear(); - clipof.AddPath(finCleaned,JoinType::jtRound,EndType::etOpenRound); - Paths toolCoverPoly; - clipof.Execute(toolCoverPoly,toolRadiusScaled+1); - clip.Clear(); - clip.AddPaths(cleared,PolyType::ptSubject,true); - clip.AddPaths(toolCoverPoly,PolyType::ptClip,true); - clip.Execute(ClipType::ctUnion,cleared); - CleanPolygons(cleared); - if(!finCleaned.empty()) { - lastPoint.X = finCleaned.back().X; - lastPoint.Y = finCleaned.back().Y; - } - } + AppendToolPath(progressPaths,output,finCleaned,clearedBeforePass,toolBoundPaths); + //expand cleared for finishing path + clipof.Clear(); + clipof.AddPath(finCleaned,JoinType::jtRound,EndType::etOpenRound); + Paths toolCoverPoly; + clipof.Execute(toolCoverPoly,toolRadiusScaled+1); + + clip.Clear(); + clip.AddPaths(cleared,PolyType::ptSubject,true); + clip.AddPaths(toolCoverPoly,PolyType::ptClip,true); + clip.Execute(ClipType::ctUnion,cleared); + CleanPolygons(cleared); + if(!finCleaned.empty()) { + lastPoint.X = finCleaned.back().X; + lastPoint.Y = finCleaned.back().Y; + } } Path returnPath; @@ -2148,6 +2156,7 @@ namespace AdaptivePath { // make sure invalid paths are not used if(!allCutsAllowed) { cerr << "INVALID CUTS DETECTED! Please try to modify accuracy and/or step-over." << endl; + output.AdaptivePaths.clear(); } results.push_back(output); diff --git a/src/Mod/Path/libarea/Adaptive.hpp b/src/Mod/Path/libarea/Adaptive.hpp index 0c3c91e439..133cb6b719 100644 --- a/src/Mod/Path/libarea/Adaptive.hpp +++ b/src/Mod/Path/libarea/Adaptive.hpp @@ -102,7 +102,7 @@ namespace AdaptivePath { double CalcCutArea(Clipper & clip,const IntPoint &toolPos, const IntPoint &newToolPos, const Paths &cleared_paths, bool preventConvetionalMode=true); void AppendToolPath(TPaths &progressPaths,AdaptiveOutput & output,const Path & passToolPath,const Paths & cleared,const Paths & toolBoundPaths); bool IsClearPath(const Path & path,const Paths & cleared, double safetyDistanceScaled=0); - bool IsAllowedToCutTrough(const IntPoint &p1,const IntPoint &p2,const Paths & cleared,const Paths & toolBoundPaths, double areaFactor=1.5); + bool IsAllowedToCutTrough(const IntPoint &p1,const IntPoint &p2,const Paths & cleared,const Paths & toolBoundPaths, double areaFactor=1.5, bool skipBoundsCheck=false); friend class EngagePoint; // for CalcCutArea