Example #1
0
        static void AddGridSubject(Clipper c, double step, double w, double h, LaserGRBL.RasterConverter.ImageProcessor.Direction dir)
        {
            long t1 = Tools.HiResTimer.TotalMilliseconds;

            double dstep  = step * Math.Sqrt(2);            //step for diagonal (1.414)
            double rdstep = step * (1 / Math.Sqrt(2));      //step for diagonal (1.414)
            List <List <IntPoint> > paths = new List <List <IntPoint> >();

            if (dir == LaserGRBL.RasterConverter.ImageProcessor.Direction.NewVertical || dir == LaserGRBL.RasterConverter.ImageProcessor.Direction.NewGrid)
            {
                bool pari = true;
                for (double x = 0; x < w + step; x += step, pari = !pari)
                {
                    AddPathPoint(paths, x, 0, x, h, pari);
                }
            }
            if (dir == LaserGRBL.RasterConverter.ImageProcessor.Direction.NewHorizontal || dir == LaserGRBL.RasterConverter.ImageProcessor.Direction.NewGrid)
            {
                bool pari = true;
                for (double y = 0; y < h + step; y += step, pari = !pari)
                {
                    AddPathPoint(paths, 0, y, w, y, pari);
                }
            }

            if (dir == LaserGRBL.RasterConverter.ImageProcessor.Direction.NewDiagonal || dir == LaserGRBL.RasterConverter.ImageProcessor.Direction.NewDiagonalGrid)
            {
                bool pari = true;
                for (double i = 0; i < (2 * Math.Max(w, h)) + dstep; i += dstep, pari = !pari)
                {
                    AddPathPoint(paths, 0, i, i, 0, pari);
                }
            }
            if (dir == LaserGRBL.RasterConverter.ImageProcessor.Direction.NewReverseDiagonal || dir == LaserGRBL.RasterConverter.ImageProcessor.Direction.NewDiagonalGrid)
            {
                bool pari = true;
                for (double i = 0; i < (2 * Math.Max(w, h)) + dstep; i += dstep, pari = !pari)
                {
                    AddPathPoint(paths, 0, (h - i), i, h, pari);
                }
            }

            if (dir == LaserGRBL.RasterConverter.ImageProcessor.Direction.NewCross)
            {
                double cl = step / 3;                 //cross len

                //stanghette orizzontali
                bool pari = true;
                for (double y = 0; y < h + step; y += step, pari = !pari)
                {
                    for (double x = 0; x < w + step; x += step)
                    {
                        AddPathPoint(paths, x - cl, y, x + cl, y, pari);
                    }
                }

                //stanghette verticali
                pari = true;
                for (double x = 0; x < w + step; x += step, pari = !pari)
                {
                    for (double y = 0; y < h + step; y += step)
                    {
                        AddPathPoint(paths, x, y - cl, x, y + cl, pari);
                    }
                }
            }

            if (dir == LaserGRBL.RasterConverter.ImageProcessor.Direction.NewDiagonalCross)
            {
                double cl = rdstep / 3;                 //cross len

                //stanghette alto-basso
                for (double y = 0; y < h + step; y += step)
                {
                    for (double x = 0; x < w + step; x += step)
                    {
                        AddPathPoint(paths, x - cl, y - cl, x + cl, y + cl);
                    }
                }

                //stanghette basso-alto
                for (double x = 0; x < w + step; x += step)
                {
                    for (double y = 0; y < h + step; y += step)
                    {
                        AddPathPoint(paths, x - cl, y + cl, x + cl, y - cl);
                    }
                }
            }

            if (dir == LaserGRBL.RasterConverter.ImageProcessor.Direction.NewSquares)
            {
                double crosslen = step / 3 * resolution;
                double x        = 0;
                while (x <= w + step)
                {
                    double xPres = x * resolution;

                    double y = 0;
                    while (y <= h + step)
                    {
                        double yPres = y * resolution;

                        paths.Add(new List <IntPoint>()
                        {
                            new IntPoint(xPres - crosslen, yPres),
                            new IntPoint(xPres, yPres + crosslen),
                        });

                        paths.Add(new List <IntPoint>()
                        {
                            new IntPoint(xPres, yPres + crosslen),
                            new IntPoint(xPres + crosslen, yPres),
                        });

                        paths.Add(new List <IntPoint>()
                        {
                            new IntPoint(xPres + crosslen, yPres),
                            new IntPoint(xPres, yPres - crosslen),
                        });

                        paths.Add(new List <IntPoint>()
                        {
                            new IntPoint(xPres, yPres - crosslen),
                            new IntPoint(xPres - crosslen, yPres)
                        });

                        y += step;
                    }
                    x += step;
                }
            }

            long t2 = Tools.HiResTimer.TotalMilliseconds;

            System.Diagnostics.Debug.WriteLine($"GeneratePath: {t2 - t1}ms");

            c.AddPaths(paths, PolyType.ptSubject, false);

            long t3 = Tools.HiResTimer.TotalMilliseconds;

            System.Diagnostics.Debug.WriteLine($"AddPath: {t3 - t2}ms");
        }
Example #2
0
        internal static List <List <Curve> > BuildFilling(List <List <Curve> > plist, double spacing, double w, double h, LaserGRBL.RasterConverter.ImageProcessor.Direction dir)
        {
            if (dir == LaserGRBL.RasterConverter.ImageProcessor.Direction.NewInsetFilling)
            {
                return(BuildInsetFilling(plist, spacing));
            }

            List <List <Curve> > flist = new List <List <Curve> >();

            Clipper c = new Clipper();

            AddGridSubject(c, spacing, w, h, dir);
            AddGridClip(plist, c);

            long     t1        = Tools.HiResTimer.TotalMilliseconds;
            PolyTree solution  = new PolyTree();
            bool     succeeded = c.Execute(ClipType.ctIntersection, solution, PolyFillType.pftEvenOdd, PolyFillType.pftEvenOdd);

            long t2 = Tools.HiResTimer.TotalMilliseconds;

            System.Diagnostics.Debug.WriteLine($"ClipperExecute: {t2 - t1}ms");

            //GraphicsPath result = new GraphicsPath();

            List <List <IntPoint> > ll = Clipper.OpenPathsFromPolyTree(solution);

            foreach (List <IntPoint> pg in ll)
            {
                PointF[] pts = PolygonToPointFArray(pg, resolution);
                if (pts.Count() > 2)
                {
                    ;                    // result.AddPolygon(pts);
                }
                else
                {
                    dPoint a = new dPoint(pts[0].X, pts[0].Y);
                    dPoint b = new dPoint(pts[1].X, pts[1].Y);
                    flist.Add(new List <Curve>()
                    {
                        new Curve(CurveKind.Line, a, a, b, b)
                    });
                }
                //result.AddLine(pts[0], pts[1]);
            }

            flist.Reverse();
            return(flist);
        }
Example #3
0
        static void AddGridSubject(Clipper c, double step, double w, double h, LaserGRBL.RasterConverter.ImageProcessor.Direction dir)
        {
            long t1 = Tools.HiResTimer.TotalMilliseconds;

            double dstep = step * Math.Sqrt(2);             //step for diagonal (1.414)
            List <List <IntPoint> > paths = new List <List <IntPoint> >();

            if (dir == LaserGRBL.RasterConverter.ImageProcessor.Direction.NewVertical || dir == LaserGRBL.RasterConverter.ImageProcessor.Direction.NewGrid)
            {
                double x     = 0;
                double hPres = h * resolution;
                while (x <= w + step)
                {
                    double xPres = x * resolution;
                    paths.Add(new List <IntPoint>()
                    {
                        new IntPoint(xPres, 0),
                        new IntPoint(xPres, hPres)
                    });
                    x += step;
                }
            }
            if (dir == LaserGRBL.RasterConverter.ImageProcessor.Direction.NewHorizontal || dir == LaserGRBL.RasterConverter.ImageProcessor.Direction.NewGrid)
            {
                double y     = 0;
                double wPres = w * resolution;
                while (y <= h + step)
                {
                    double yPres = y * resolution;
                    paths.Add(new List <IntPoint>()
                    {
                        new IntPoint(0, yPres),
                        new IntPoint(wPres, yPres)
                    });

                    y += step;
                }
            }

            if (dir == LaserGRBL.RasterConverter.ImageProcessor.Direction.NewDiagonal || dir == LaserGRBL.RasterConverter.ImageProcessor.Direction.NewDiagonalGrid)
            {
                double i = 0;
                while (i <= (2 * w) + step || i <= (2 * h) + step)
                {
                    double iPres = i * resolution;
                    paths.Add(new List <IntPoint>()
                    {
                        new IntPoint(0, iPres),
                        new IntPoint(iPres, 0)
                    });

                    i += dstep;
                }
            }
            if (dir == LaserGRBL.RasterConverter.ImageProcessor.Direction.NewReverseDiagonal || dir == LaserGRBL.RasterConverter.ImageProcessor.Direction.NewDiagonalGrid)
            {
                double i = 0;
                while (i <= (2 * w) + step || i <= (2 * h) + step)
                {
                    paths.Add(new List <IntPoint>()
                    {
                        new IntPoint(0, (h - i) * resolution),
                        new IntPoint(i * resolution, h * resolution)
                    });

                    i += dstep;
                }
            }

            if (dir == LaserGRBL.RasterConverter.ImageProcessor.Direction.NewCross)
            {
                double crosslen = step / 3 * resolution;
                double x        = 0;
                while (x <= w + step)
                {
                    double y = 0;
                    while (y <= h + step)
                    {
                        paths.Add(new List <IntPoint>()
                        {
                            new IntPoint(x * resolution, y * resolution - crosslen),
                            new IntPoint(x * resolution, y * resolution + crosslen)
                        });

                        paths.Add(new List <IntPoint>()
                        {
                            new IntPoint(x * resolution - crosslen, y * resolution),
                            new IntPoint(x * resolution + crosslen, y * resolution)
                        });

                        y += step;
                    }
                    x += step;
                }
            }

            if (dir == LaserGRBL.RasterConverter.ImageProcessor.Direction.NewDiagonalCross)
            {
                double crosslen = step / 3 * resolution;
                double x        = 0;
                while (x <= w + step)
                {
                    double xPres = x * resolution;

                    double y = 0;
                    while (y <= h + step)
                    {
                        double yPres = y * resolution;

                        paths.Add(new List <IntPoint>()
                        {
                            new IntPoint(xPres - crosslen, yPres - crosslen),
                            new IntPoint(xPres + crosslen, yPres + crosslen)
                        });

                        paths.Add(new List <IntPoint>()
                        {
                            new IntPoint(xPres - crosslen, yPres + crosslen),
                            new IntPoint(xPres + crosslen, yPres - crosslen)
                        });

                        y += step;
                    }
                    x += step;
                }
            }

            if (dir == LaserGRBL.RasterConverter.ImageProcessor.Direction.NewSquares)
            {
                double crosslen = step / 3 * resolution;
                double x        = 0;
                while (x <= w + step)
                {
                    double xPres = x * resolution;

                    double y = 0;
                    while (y <= h + step)
                    {
                        double yPres = y * resolution;

                        paths.Add(new List <IntPoint>()
                        {
                            new IntPoint(xPres - crosslen, yPres),
                            new IntPoint(xPres, yPres + crosslen),
                        });

                        paths.Add(new List <IntPoint>()
                        {
                            new IntPoint(xPres, yPres + crosslen),
                            new IntPoint(xPres + crosslen, yPres),
                        });

                        paths.Add(new List <IntPoint>()
                        {
                            new IntPoint(xPres + crosslen, yPres),
                            new IntPoint(xPres, yPres - crosslen),
                        });

                        paths.Add(new List <IntPoint>()
                        {
                            new IntPoint(xPres, yPres - crosslen),
                            new IntPoint(xPres - crosslen, yPres)
                        });

                        y += step;
                    }
                    x += step;
                }
            }

            long t2 = Tools.HiResTimer.TotalMilliseconds;

            System.Diagnostics.Debug.WriteLine($"GeneratePath: {t2 - t1}ms");

            c.AddPaths(paths, PolyType.ptSubject, false);

            long t3 = Tools.HiResTimer.TotalMilliseconds;

            System.Diagnostics.Debug.WriteLine($"AddPath: {t3 - t2}ms");
        }
Example #4
0
        static void AddGridSubject(Clipper c, double w, double h, LaserGRBL.GrblFile.L2LConf cnf)
        {
            LaserGRBL.RasterConverter.ImageProcessor.Direction dir = cnf.dir;

            double step   = cnf.res / cnf.fres;
            double dstep  = step * Math.Sqrt(2);            //step for diagonal (1.414)
            double rdstep = step * (1 / Math.Sqrt(2));      //step for diagonal (1.414)

            List <List <IntPoint> > paths = new List <List <IntPoint> >();

            //se si vuole sfasare per via dell'offset è necessario applicare questa correzione a x e y
            //ma i risultati possono essere brutti rispetto a ciò che ci si aspetta
            //double stepmm = 1 / cnf.fres;
            //double cX = (stepmm - cnf.oX % stepmm) * cnf.res;
            //double cY = (stepmm - cnf.oY % stepmm) * cnf.res;

            if (dir == LaserGRBL.RasterConverter.ImageProcessor.Direction.NewHorizontal || dir == LaserGRBL.RasterConverter.ImageProcessor.Direction.NewGrid)
            {
                for (int y = 1; y < (h / step); y++)
                {
                    AddSegment(paths, 0, y * step, w, y * step, y % 2 == 1);
                }
            }
            if (dir == LaserGRBL.RasterConverter.ImageProcessor.Direction.NewVertical || dir == LaserGRBL.RasterConverter.ImageProcessor.Direction.NewGrid)
            {
                for (int x = 1; x < (w / step); x++)
                {
                    AddSegment(paths, x * step, 0, x * step, h, x % 2 == 0);
                }
            }
            if (dir == LaserGRBL.RasterConverter.ImageProcessor.Direction.NewDiagonal || dir == LaserGRBL.RasterConverter.ImageProcessor.Direction.NewDiagonalGrid)
            {
                for (int i = 0; i < (w + h) / dstep; i++)
                {
                    AddSegment(paths, 0, i * dstep, i * dstep, 0, i % 2 == 0);
                }
            }
            if (dir == LaserGRBL.RasterConverter.ImageProcessor.Direction.NewReverseDiagonal || dir == LaserGRBL.RasterConverter.ImageProcessor.Direction.NewDiagonalGrid)
            {
                for (int i = 0; i < (w + h) / dstep; i++)
                {
                    AddSegment(paths, 0, h - (i * dstep), i * dstep, h, i % 2 == 1);
                }
            }

            if (dir == LaserGRBL.RasterConverter.ImageProcessor.Direction.NewCross)
            {
                double cl = step / 3;                 //cross len
                for (int y = 1; y < (h / step); y++)
                {
                    for (int x = 1; x < (w / step); x++)
                    {
                        AddSegment(paths, (x * step) - cl, y * step, (x * step) + cl, y * step, y % 2 == 1);                            //stanghette orizzontali
                        AddSegment(paths, x * step, (y * step) - cl, x * step, (y * step) + cl, x % 2 == 0);                            //stanghette verticali
                    }
                }
            }

            if (dir == LaserGRBL.RasterConverter.ImageProcessor.Direction.NewDiagonalCross)
            {
                double cl = rdstep / 3;
                for (int y = 0; y < (h / step) + 1; y++)
                {
                    for (int x = 0; x < (w / step) + 1; x++)
                    {
                        AddSegment(paths, (x * step) - cl, (y * step) - cl, (x * step) + cl, (y * step) + cl, x % 2 == 1);                              //stanghetta verso l'alto
                        AddSegment(paths, (x * step) + cl, (y * step) - cl, (x * step) - cl, (y * step) + cl, x % 2 == 1);                              //stanghetta verso il basso
                    }
                }
            }
            if (dir == LaserGRBL.RasterConverter.ImageProcessor.Direction.NewSquares)
            {
                double cl = step / 3;
                for (int y = 0; y < (h / step) + 1; y++)
                {
                    for (int x = 0; x < (w / step) + 1; x++)
                    {
                        List <IntPoint> list = new List <IntPoint>();
                        AddPathPoint(list, (x * step) - cl, y * step);
                        AddPathPoint(list, x * step, (y * step) + cl);
                        AddPathPoint(list, (x * step) + cl, y * step);
                        AddPathPoint(list, x * step, (y * step) - cl);
                        AddPathPoint(list, (x * step) - cl, y * step);
                        AddPathPoints(paths, list);
                    }
                }
            }
            if (dir == LaserGRBL.RasterConverter.ImageProcessor.Direction.NewZigZag)
            {
                double hs = dstep / 2;                  //halfstep

                for (int i = 1; i < (w + h) / dstep; i++)
                {
                    List <IntPoint> list = new List <IntPoint>();

                    if (i % 2 == 1)
                    {
                        double my = 0;
                        double mx = (i * dstep) - hs;

                        AddPathPoint(list, mx, my);
                        while (mx > 0)
                        {
                            AddPathPoint(list, mx, my += hs);
                            AddPathPoint(list, mx     -= hs, my);
                        }
                    }
                    else
                    {
                        double mx = 0;
                        double my = (i * dstep) - hs;

                        AddPathPoint(list, mx - 1, my + 1);                     //non togliere questo +/-1, sembra che freghi l'algoritmo clipper obbligandolo a mantenere la mia direzione
                        AddPathPoint(list, mx, my);
                        while (my > 0)
                        {
                            AddPathPoint(list, mx     += hs, my);
                            AddPathPoint(list, mx, my -= hs);
                        }
                    }

                    AddPathPoints(paths, list);
                }
            }
            if (dir == LaserGRBL.RasterConverter.ImageProcessor.Direction.NewHilbert)
            {
                int   n  = 6;
                float ts = (float)(Math.Pow(2, n) * step);
                //genera un elemento da n ricorsioni su step
                //la sua dimensione sarà 2^n * step
                List <PointF> texel = Hilbert.Execute(n, (float)(step));

                for (int y = 0; y < (h / ts); y++)
                {
                    for (int x = 0; x < (w / ts); x++)
                    {
                        List <IntPoint> list = new List <IntPoint>();
                        for (int i = 0; i < texel.Count; i++)
                        {
                            AddPathPoint(list, texel[i].X + (x * ts), texel[i].Y + (y * ts));
                        }
                        AddPathPoints(paths, list);
                    }
                }
            }
            c.AddPaths(paths, PolyType.ptSubject, false);
        }
Example #5
0
        static void AddGridSubject(Clipper c, double step, double w, double h, LaserGRBL.RasterConverter.ImageProcessor.Direction dir)
        {
            long t1 = Tools.HiResTimer.TotalMilliseconds;

            double dstep  = step * Math.Sqrt(2);            //step for diagonal (1.414)
            double rdstep = step * (1 / Math.Sqrt(2));      //step for diagonal (1.414)
            List <List <IntPoint> > paths = new List <List <IntPoint> >();

            if (dir == LaserGRBL.RasterConverter.ImageProcessor.Direction.NewVertical || dir == LaserGRBL.RasterConverter.ImageProcessor.Direction.NewGrid)
            {
                bool pari = true;
                for (double x = 0; x < w + step; x += step, pari = !pari)
                {
                    AddPathPoint(paths, x, 0, x, h, pari);
                }
            }
            if (dir == LaserGRBL.RasterConverter.ImageProcessor.Direction.NewHorizontal || dir == LaserGRBL.RasterConverter.ImageProcessor.Direction.NewGrid)
            {
                bool pari = true;
                for (double y = 0; y < h + step; y += step, pari = !pari)
                {
                    AddPathPoint(paths, 0, y, w, y, pari);
                }
            }

            if (dir == LaserGRBL.RasterConverter.ImageProcessor.Direction.NewDiagonal || dir == LaserGRBL.RasterConverter.ImageProcessor.Direction.NewDiagonalGrid)
            {
                bool pari = true;
                for (double i = 0; i < w + h + dstep; i += dstep, pari = !pari)
                {
                    AddPathPoint(paths, 0, i, i, 0, pari);
                }
            }
            if (dir == LaserGRBL.RasterConverter.ImageProcessor.Direction.NewReverseDiagonal || dir == LaserGRBL.RasterConverter.ImageProcessor.Direction.NewDiagonalGrid)
            {
                bool pari = true;
                for (double i = 0; i < w + h + dstep; i += dstep, pari = !pari)
                {
                    AddPathPoint(paths, 0, h - i, i, h, pari);
                }
            }

            if (dir == LaserGRBL.RasterConverter.ImageProcessor.Direction.NewCross)
            {
                double cl = step / 3;                 //cross len


                bool yp = true;
                for (double y = 0; y < h + step; y += step, yp = !yp)
                {
                    bool xp = true;
                    for (double x = 0; x < w + step; x += step, xp = !xp)
                    {
                        AddPathPoint(paths, x - cl, y, x + cl, y, yp);                          //stanghette orizzontali
                        AddPathPoint(paths, x, y - cl, x, y + cl, xp);                          //stanghette verticali
                    }
                }
            }

            if (dir == LaserGRBL.RasterConverter.ImageProcessor.Direction.NewDiagonalCross)
            {
                double cl = rdstep / 3;                 //cross len

                //stanghette basso-alto alto-basso
                //e riga successiva invertita
                int yp = 0;
                for (double y = 0; y < h + step; y += step)
                {
                    int xp = yp++ % 2;
                    for (double x = 0; x < w + step; x += step)
                    {
                        if (xp++ % 2 == 0)
                        {
                            AddPathPoint(paths, x - cl, y - cl, x + cl, y + cl);
                            AddPathPoint(paths, x - cl, y + cl, x + cl, y - cl);
                        }
                        else
                        {
                            AddPathPoint(paths, x - cl, y + cl, x + cl, y - cl);
                            AddPathPoint(paths, x - cl, y - cl, x + cl, y + cl);
                        }
                    }
                }
            }
            if (dir == LaserGRBL.RasterConverter.ImageProcessor.Direction.NewSquares)
            {
                double cl = step / 3;                 //cross len

                for (double y = 0; y < h + step; y += step)
                {
                    for (double x = 0; x < w + step; x += step)
                    {
                        AddPathPoint(paths, x - cl, y, x, y + cl);
                        AddPathPoint(paths, x, y + cl, x + cl, y);
                        AddPathPoint(paths, x + cl, y, x, y - cl);
                        AddPathPoint(paths, x, y - cl, x - cl, y);
                    }
                }
            }
            if (dir == LaserGRBL.RasterConverter.ImageProcessor.Direction.NewZigZag)
            {
                double hs = step / 2;                   //halfstep
                double ds = step * 2;                   //doublestep

                for (double y = step; y < w + h + step; y += 2 * step)
                {
                    double my = y - hs;
                    double mx = 0;

                    while (my > 0)
                    {
                        AddPathPoint(paths, mx, my, mx + hs, my);
                        AddPathPoint(paths, mx + hs, my, mx + hs, my - hs);
                        my -= hs;
                        mx += hs;
                    }
                }

                for (double x = 2 * step; x < w + h + step; x += 2 * step)
                {
                    double mx = x - hs;
                    double my = 0;

                    while (mx > 0)
                    {
                        AddPathPoint(paths, mx, my, mx, my + hs);
                        AddPathPoint(paths, mx, my + hs, mx - hs, my + hs);
                        my += hs;
                        mx -= hs;
                    }
                }
            }

            long t2 = Tools.HiResTimer.TotalMilliseconds;

            System.Diagnostics.Debug.WriteLine($"GeneratePath: {t2 - t1}ms");

            c.AddPaths(paths, PolyType.ptSubject, false);

            long t3 = Tools.HiResTimer.TotalMilliseconds;

            System.Diagnostics.Debug.WriteLine($"AddPath: {t3 - t2}ms");
        }