| | |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | #include "clipper.hpp" |
| | #include <vector> |
| | #include <list> |
| | #include <time.h> |
| |
|
| | #ifndef ADAPTIVE_HPP |
| | # define ADAPTIVE_HPP |
| |
|
| | # ifndef __DBL_MAX__ |
| | # define __DBL_MAX__ 1.7976931348623158e+308 |
| | # endif |
| |
|
| | # ifndef __LONG_MAX__ |
| | # define __LONG_MAX__ 2147483647 |
| | # endif |
| |
|
| | |
| |
|
| | # define NTOL 1.0e-7 |
| |
|
| | namespace AdaptivePath |
| | { |
| | using namespace ClipperLib; |
| |
|
| | enum MotionType |
| | { |
| | mtCutting = 0, |
| | mtLinkClear = 1, |
| | mtLinkNotClear = 2, |
| | mtLinkClearAtPrevPass = 3 |
| | }; |
| |
|
| | enum OperationType |
| | { |
| | otClearingInside = 0, |
| | otClearingOutside = 1, |
| | otProfilingInside = 2, |
| | otProfilingOutside = 3 |
| | }; |
| |
|
| | typedef std::pair<double, double> DPoint; |
| | typedef std::vector<DPoint> DPath; |
| | typedef std::vector<DPath> DPaths; |
| | typedef std::pair<int, DPath> TPath; |
| | |
| |
|
| | class ClearedArea; |
| |
|
| | typedef std::vector<TPath> TPaths; |
| |
|
| | struct AdaptiveOutput |
| | { |
| | DPoint HelixCenterPoint; |
| | DPoint StartPoint; |
| | TPaths AdaptivePaths; |
| | int ReturnMotionType; |
| | }; |
| |
|
| | |
| |
|
| | class Adaptive2d |
| | { |
| | public: |
| | Adaptive2d(); |
| | double toolDiameter = 5; |
| | double helixRampTargetDiameter = 0; |
| | double helixRampMinDiameter = 0; |
| | double stepOverFactor = 0.2; |
| | double tolerance = 0.1; |
| | double stockToLeave = 0; |
| | bool forceInsideOut = true; |
| | bool finishingProfile = true; |
| | double keepToolDownDistRatio = 3.0; |
| | OperationType opType = OperationType::otClearingInside; |
| |
|
| | std::list<AdaptiveOutput> Execute( |
| | const DPaths& stockPaths, |
| | const DPaths& paths, |
| | std::function<bool(TPaths)> progressCallbackFn |
| | ); |
| |
|
| | # ifdef DEV_MODE |
| | |
| | std::function<void(double cx, double cy, double radius, int color)> DrawCircleFn; |
| | std::function<void(const DPath&, int color)> DrawPathFn; |
| | std::function<void()> ClearScreenFn; |
| | # endif |
| |
|
| | private: |
| | std::list<AdaptiveOutput> results; |
| | Paths inputPaths; |
| | Paths stockInputPaths; |
| | int polyTreeNestingLimit = 0; |
| | long scaleFactor = 100; |
| | double stepOverScaled = 1; |
| | long toolRadiusScaled = 10; |
| | long finishPassOffsetScaled = 0; |
| | long helixRampMaxRadiusScaled = 0; |
| | long helixRampMinRadiusScaled = 0; |
| | double referenceCutArea = 0; |
| | double optimalCutAreaPD = 0; |
| | bool stopProcessing = false; |
| | int current_region = 0; |
| | clock_t lastProgressTime = 0; |
| |
|
| | std::function<bool(TPaths)>* progressCallback = NULL; |
| | Path toolGeometry; |
| |
|
| | void ProcessPolyNode(Paths boundPaths, Paths toolBoundPaths); |
| | bool FindEntryPoint( |
| | TPaths& progressPaths, |
| | const Paths& toolBoundPaths, |
| | const Paths& bound, |
| | ClearedArea& cleared , |
| | IntPoint& entryPoint , |
| | IntPoint& toolPos, |
| | DoublePoint& toolDir, |
| | long& helixRadiusScaled |
| | ); |
| | bool FindEntryPointOutside( |
| | TPaths& progressPaths, |
| | const Paths& toolBoundPaths, |
| | const Paths& bound, |
| | ClearedArea& cleared , |
| | IntPoint& entryPoint , |
| | IntPoint& toolPos, |
| | DoublePoint& toolDir |
| | ); |
| | double CalcCutArea( |
| | Clipper& clip, |
| | const IntPoint& toolPos, |
| | const IntPoint& newToolPos, |
| | ClearedArea& clearedArea, |
| | bool preventConventionalMode = true |
| | ); |
| | void AppendToolPath( |
| | TPaths& progressPaths, |
| | AdaptiveOutput& output, |
| | const Path& passToolPath, |
| | ClearedArea& clearedAreaBefore, |
| | ClearedArea& clearedAreaAfter, |
| | const Paths& toolBoundPaths |
| | ); |
| | bool IsClearPath(const Path& path, ClearedArea& clearedArea, double safetyDistanceScaled = 0); |
| | bool IsAllowedToCutTrough( |
| | const IntPoint& p1, |
| | const IntPoint& p2, |
| | ClearedArea& clearedArea, |
| | const Paths& toolBoundPaths, |
| | double areaFactor = 1.5, |
| | bool skipBoundsCheck = false |
| | ); |
| | bool MakeLeadPath( |
| | bool leadIn, |
| | const IntPoint& startPoint, |
| | const DoublePoint& startDir, |
| | const IntPoint& beaconPoint, |
| | ClearedArea& clearedArea, |
| | const Paths& toolBoundPaths, |
| | Path& output |
| | ); |
| |
|
| | bool ResolveLinkPath( |
| | const IntPoint& startPoint, |
| | const IntPoint& endPoint, |
| | ClearedArea& clearedArea, |
| | Path& output |
| | ); |
| |
|
| | friend class EngagePoint; |
| |
|
| | void CheckReportProgress(TPaths& progressPaths, bool force = false); |
| | void AddPathsToProgress( |
| | TPaths& progressPaths, |
| | const Paths paths, |
| | MotionType mt = MotionType::mtCutting |
| | ); |
| | void AddPathToProgress(TPaths& progressPaths, const Path pth, MotionType mt = MotionType::mtCutting); |
| | void ApplyStockToLeave(Paths& inputPaths); |
| |
|
| | private: |
| | const double MIN_STEP_CLIPPER = 16.0; |
| | const int MAX_ITERATIONS = 10; |
| | const double AREA_ERROR_FACTOR = 0.05; |
| | |
| | const size_t ANGLE_HISTORY_POINTS = 3; |
| | const int DIRECTION_SMOOTHING_BUFLEN = 3; |
| |
|
| |
|
| | const double MIN_CUT_AREA_FACTOR = 0.1 |
| | * 16; |
| | const double ENGAGE_AREA_THR_FACTOR = 0.5 * 16; |
| | const double ENGAGE_SCAN_DISTANCE_FACTOR = 0.2; |
| |
|
| | const double CLEAN_PATH_TOLERANCE = 1.41; |
| | const double FINISHING_CLEAN_PATH_TOLERANCE = 1.41; |
| |
|
| | const long PASSES_LIMIT = __LONG_MAX__; |
| | const long POINTS_PER_PASS_LIMIT = __LONG_MAX__; |
| | const clock_t PROGRESS_TICKS = CLOCKS_PER_SEC / 10; |
| | }; |
| | } |
| | #endif |
| |
|