コード例 #1
0
ファイル: PathPlanner.cs プロジェクト: zhangzheng1205/PathCAM
            /// <summary>
            /// Generate a set of tool paths which will completely remove the material specified in
            /// the polygons, plus an offset equal to the radius of the tool used.
            /// </summary>
            /// <param name="polygons"></param>
            /// <param name="maxShrink">maximum distance between disjoint paths</param>
            /// <returns></returns>
            public static List <LineStrip> ObliterateSlice(Slice polygons, float maxShrink, bool reverse = false)
            {
                List <LineStrip> lines = new List <LineStrip>();

                foreach (Slice slice in polygons.IndividualPolygons())
                {
                    PathTree tree   = new PathTree(reverse);
                    Slice    inside = new Slice(slice.GetLines(Slice.LineType.Hole), slice.Plane);
                    Slice    shrink = new Slice(slice);
                    while (shrink.Area() > 0)
                    {
                        shrink = new Slice(shrink.GetLines(Slice.LineType.Outside), shrink.Plane);
                        foreach (var a in shrink.IndividualPolygons())
                        {
                            if (!tree.AddPolygon(a))
                            {
                                // The new polygon didn't fit into the path tree...  shouldn't get here.
                            }
                        }

                        shrink.Offset(-maxShrink);
                        shrink.Subtract(inside);
                    }

                    LineStrip toolPath = new LineStrip();
                    tree.GenerateToolPath(toolPath, tree.CreatePath(), maxShrink * 2.0f);
                    lines.Add(toolPath);
                }
                return(lines);
            }