Пример #1
0
        private static List <List <Curve> > BuildInsetFilling(List <List <Curve> > plist, LaserGRBL.GrblFile.L2LConf cnf)
        {
            double spacing             = cnf.res / cnf.fres;
            List <List <Curve> > flist = new List <List <Curve> >();
            ClipperOffset        c     = new ClipperOffset();

            AddOffsetSubject(plist, c);

            for (int i = 1;  ; i++)
            {
                List <List <IntPoint> > solution = new List <List <IntPoint> >();
                c.Execute(ref solution, -spacing * i * resolution);

                if (solution.Count > 0)
                {
                    flist.AddRange(ToPotraceList(solution, true));
                }
                else
                {
                    break;
                }
            }

            return(flist);
        }
Пример #2
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);
        }
Пример #3
0
        private static List <List <Curve> > BuildGridFilling(List <List <Curve> > plist, double w, double h, LaserGRBL.GrblFile.L2LConf cnf)
        {
            Clipper c = new Clipper();

            AddGridSubject(c, w, h, cnf);
            AddGridClip(plist, c);

            PolyTree solution  = new PolyTree();
            bool     succeeded = c.Execute(ClipType.ctIntersection, solution, PolyFillType.pftEvenOdd, PolyFillType.pftEvenOdd);

            if (!succeeded)
            {
                return(null);
            }

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

            return(ToPotraceList(ll, false));
        }
Пример #4
0
 internal static List <List <Curve> > BuildFilling(List <List <Curve> > plist, double w, double h, LaserGRBL.GrblFile.L2LConf c)
 {
     if (c.dir == LaserGRBL.RasterConverter.ImageProcessor.Direction.NewInsetFilling)
     {
         return(BuildInsetFilling(plist, c));
     }
     else
     {
         return(BuildGridFilling(plist, w, h, c));
     }
 }