From 092b358df5e1b233d59dfed01267b3abcbfd0d94 Mon Sep 17 00:00:00 2001 From: kreso-t Date: Tue, 28 Aug 2018 22:01:02 +0200 Subject: [PATCH] Path: Adaptive - linking moves optimization --- src/Mod/Path/libarea/Adaptive.cpp | 46 +++++++++++++++++++++++++------ src/Mod/Path/libarea/Adaptive.hpp | 4 +-- 2 files changed, 40 insertions(+), 10 deletions(-) diff --git a/src/Mod/Path/libarea/Adaptive.cpp b/src/Mod/Path/libarea/Adaptive.cpp index 3ac7790d7c..48864a9abd 100644 --- a/src/Mod/Path/libarea/Adaptive.cpp +++ b/src/Mod/Path/libarea/Adaptive.cpp @@ -681,9 +681,9 @@ namespace AdaptivePath { if(PointSideOfLine(fpc2,lpc2,midPoint)>0) { area = __DBL_MAX__; Perf_CalcCutArea.Stop(); - #ifdef DEV_MODE - cout << "Break: @(" << double(c2.X)/scaleFactor << "," << double(c2.Y)/scaleFactor << ") conventional mode" << endl; - #endif + // #ifdef DEV_MODE + // cout << "Break: @(" << double(c2.X)/scaleFactor << "," << double(c2.Y)/scaleFactor << ") conventional mode" << endl; + // #endif return area; } } @@ -1029,7 +1029,7 @@ namespace AdaptivePath { return collisionArea <= NTOL; } - void Adaptive2d::AppendToolPath(AdaptiveOutput & output,const Path & passToolPath,const Paths & cleared, bool close) { + void Adaptive2d::AppendToolPath(AdaptiveOutput & output,const Path & passToolPath,const Paths & cleared, const Paths & toolBoundPaths, bool close) { if(passToolPath.size()<1) return; IntPoint nextPoint(passToolPath[0]); @@ -1037,10 +1037,38 @@ namespace AdaptivePath { auto & lastTPath = output.AdaptivePaths.back(); auto & lastTPoint = lastTPath.second.back(); IntPoint lastPoint(long(lastTPoint.first*scaleFactor),long(lastTPoint.second*scaleFactor)); - bool clear = CheckCollision(lastPoint,nextPoint,cleared); + MotionType mt = CheckCollision(lastPoint,nextPoint,cleared) ? MotionType::mtLinkClear : MotionType::mtLinkNotClear; + if(mt==MotionType::mtLinkNotClear) { // if link not clear and distance smaller than toolDiameter check if we can make acutall cut move, optimalCutAreaPD + double linkDistance = sqrt(DistanceSqrd(lastPoint,nextPoint)); + //cout<<"linking distance:" << linkDistance << " toolDia:" << toolRadiusScaled*2 << endl; + if(linkDistance<4*toolRadiusScaled) { + double stepSize=2*RESOLUTION_FACTOR; + Clipper clip; + mt=MotionType::mtCutting; // asume we can cut trough + IntPoint inters; // to hold intersection point + if(IntersectionPoint(toolBoundPaths,lastPoint, nextPoint,inters)) { + // if intersect with boundary - its not clear to cut + mt=MotionType::mtLinkNotClear; + // cout<<"linking - touches boundary" << endl; + } else for(double d=stepSize;doptimalCutAreaPD) { // if we are cutting above optimal -> not clear link + mt=MotionType::mtLinkNotClear; + // cout<<"linking - overcut" << endl; + break; + } + } + //if(mt==MotionType::mtCutting) cout<<"cutting link"<0) { lastPoint.X = pth[pth.size()-1].X; lastPoint.Y = pth[pth.size()-1].Y; @@ -1437,6 +1466,7 @@ namespace AdaptivePath { << " total_iterations:" << total_iterations << " iter_per_point:" << (double(total_iterations)/((double(total_points)+0.001))) << " total_exceeded:" << total_exceeded << " (" << 100 * double(total_exceeded)/double(total_points) << "%)" + << " linking moves:" << unclearLinkingMoveCount << endl; #endif results.push_back(output); diff --git a/src/Mod/Path/libarea/Adaptive.hpp b/src/Mod/Path/libarea/Adaptive.hpp index 3780bd1733..266edb07ac 100644 --- a/src/Mod/Path/libarea/Adaptive.hpp +++ b/src/Mod/Path/libarea/Adaptive.hpp @@ -84,7 +84,7 @@ namespace AdaptivePath { double optimalCutAreaPD=0; double minCutAreaPD=0; bool stopProcessing=false; - + long unclearLinkingMoveCount = 0; time_t lastProgressTime = 0; std::function * progressCallback=NULL; @@ -93,7 +93,7 @@ namespace AdaptivePath { void ProcessPolyNode(Paths & boundPaths, Paths & toolBoundPaths); bool FindEntryPoint(const Paths & toolBoundPaths,const Paths &bound, Paths &cleared /*output*/, IntPoint &entryPoint /*output*/); double CalcCutArea(Clipper & clip,const IntPoint &toolPos, const IntPoint &newToolPos, const Paths &cleared_paths); - void AppendToolPath(AdaptiveOutput & output,const Path & passToolPath,const Paths & cleared, bool close=false); + void AppendToolPath(AdaptiveOutput & output,const Path & passToolPath,const Paths & cleared,const Paths & toolBoundPaths, bool close=false); bool CheckCollision(const IntPoint &lastPoint,const IntPoint &nextPoint,const Paths & cleared); friend class EngagePoint; // for CalcCutArea