From cc0dbb58e574b0f1e8ee8392222c7ed91c84a845 Mon Sep 17 00:00:00 2001 From: kreso-t Date: Sat, 29 Sep 2018 19:01:48 +0200 Subject: [PATCH] Path: Adaptive - adjustments to path smoothing --- src/Mod/Path/libarea/Adaptive.cpp | 45 ++++++++++++++++--------------- src/Mod/Path/libarea/Adaptive.hpp | 2 +- 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/src/Mod/Path/libarea/Adaptive.cpp b/src/Mod/Path/libarea/Adaptive.cpp index 3b66f0f313..00db3a6df9 100644 --- a/src/Mod/Path/libarea/Adaptive.cpp +++ b/src/Mod/Path/libarea/Adaptive.cpp @@ -603,16 +603,16 @@ void SmoothPaths(Paths &paths, double stepSize, long pointCount, long iterations const double l = sqrt(DistanceSqrd(lastPt, pt)); - if (l < 0.5*stepScaled) + if (l < 0.5*stepScaled ) { - points.pop_back(); + if(points.size()>1) points.pop_back(); points.push_back(pair(i, pt)); continue; } size_t lastPathIndex = back.first; - const long steps = long(l / stepScaled)+1; // +1 is important! - const long left=pointCount*2; - const long right =steps-pointCount*2; + const long steps = max(long(l / stepScaled),1L); + const long left=pointCount*iterations*2; + const long right =steps-pointCount*iterations*2; for (long idx = 0; idx <= steps; idx++) { if(idx>left && idx1) points.pop_back(); if (p < 0.5) points.push_back(pair(lastPathIndex, ptx)); @@ -635,20 +635,18 @@ void SmoothPaths(Paths &paths, double stepSize, long pointCount, long iterations if (points.empty()) return; const long size=long(points.size()); - double rangeSqrd = stepScaled * 2 * pointCount; rangeSqrd*=rangeSqrd; for(long iter=0;iter= size-1) ptsToAverage = size-1-i; - for (long j = i-ptsToAverage; j <= i+ptsToAverage; j++) { if (j == i) continue; @@ -656,11 +654,9 @@ void SmoothPaths(Paths &paths, double stepSize, long pointCount, long iterations if(index<0) index=0; if(index>=size) index=size-1; IntPoint &p = points[index].second; - if(DistanceSqrd(cp,p) Adaptive2d::Execute(const DPaths &stockPaths, const DP if (scaleFactor > 250) scaleFactor = 250; - cout << "Tool Diam: " << toolDiameter << endl; - cout << "Accuracy: " << 1000.0/scaleFactor << " um" << endl; + scaleFactor = round(scaleFactor); + + current_region=0; + cout << "Tool Diameter: " << toolDiameter << endl; + cout << "Accuracy: " << round(10000.0/scaleFactor)/10 << " um" << endl; + cout << flush; toolRadiusScaled = long(toolDiameter * scaleFactor / 2); stepOverScaled = toolRadiusScaled * stepOverFactor; @@ -1705,7 +1704,6 @@ std::list Adaptive2d::Execute(const DPaths &stockPaths, const DP #ifdef DEV_MODE cout << "optimalCutAreaPD:" << optimalCutAreaPD << " scaleFactor:" << scaleFactor << " toolRadiusScaled:" << toolRadiusScaled << " helixRampRadiusScaled:" << helixRampRadiusScaled << endl; #endif - //****************************** // Convert input paths to clipper //****************************** @@ -2276,7 +2274,7 @@ bool Adaptive2d::MakeLeadPath(bool leadIn, const IntPoint &startPoint, const Dou double alfa = M_PI / 64; double pathLen = 0; checkPath.push_back(nextPoint); - for (int i = 0; i < 1000; i++) + for (int i = 0; i < 10000; i++) { if (IsAllowedToCutTrough(IntPoint(currentPoint.X + RESOLUTION_FACTOR * nextDir.X, currentPoint.Y + RESOLUTION_FACTOR * nextDir.Y), nextPoint, clearedArea, toolBoundPaths)) { @@ -2442,7 +2440,7 @@ void Adaptive2d::AppendToolPath(TPaths &progressPaths, AdaptiveOutput &output, if (linkType == MotionType::mtLinkClear) { - SmoothPaths(linkPaths, 0.05*stepOverScaled,4,2); + SmoothPaths(linkPaths, 0.1*stepOverScaled,1,4); } leadOutPath = linkPaths[0]; @@ -2571,6 +2569,9 @@ void Adaptive2d::AddPathToProgress(TPaths &progressPaths, const Path pth, Motion void Adaptive2d::ProcessPolyNode(Paths boundPaths, Paths toolBoundPaths) { Perf_ProcessPolyNode.Start(); + current_region++; + cout << "** Processing region: " << current_region << endl; + // node paths are already constrained to tool boundary path for adaptive path before finishing pass Clipper clip; ClipperOffset clipof; diff --git a/src/Mod/Path/libarea/Adaptive.hpp b/src/Mod/Path/libarea/Adaptive.hpp index a61fab1747..060e8a858b 100644 --- a/src/Mod/Path/libarea/Adaptive.hpp +++ b/src/Mod/Path/libarea/Adaptive.hpp @@ -117,7 +117,7 @@ class Adaptive2d double referenceCutArea = 0; double optimalCutAreaPD = 0; bool stopProcessing = false; - + int current_region=0; clock_t lastProgressTime = 0; std::function *progressCallback = NULL;