Ejemplo n.º 1
0
 public void StartNest()
 {
     current = null;
     Nest    = new SvgNest();
     Background.cacheProcess = new Dictionary <string, NFP[]>();
     Background.window       = new windowUnk();
     Background.callCounter  = 0;
     Iterations = 0;
 }
Ejemplo n.º 2
0
        //解的迭代更新
        public void NestIterate()
        {
            List <NFP> lsheets = new List <NFP>();
            List <NFP> lpoly   = new List <NFP>();

            for (int i = 0; i < Polygons.Count; i++)
            {
                Polygons[i].id = i;
            }
            for (int i = 0; i < Sheets.Count; i++)
            {
                Sheets[i].id = i;
            }
            foreach (var item in Polygons)
            {
                NFP clone = new NFP();
                clone.id     = item.id;
                clone.source = item.source;
                clone.Points = item.Points.Select(z => new SvgPoint(z.x, z.y)
                {
                    exact = z.exact
                }).ToArray();
                if (item.children != null)
                {
                    clone.children = new List <NFP>();
                    foreach (var citem in item.children)
                    {
                        clone.children.Add(new NFP());
                        var l = clone.children.Last();
                        l.id     = citem.id;
                        l.source = citem.source;
                        l.Points = citem.Points.Select(z => new SvgPoint(z.x, z.y)
                        {
                            exact = z.exact
                        }).ToArray();
                    }
                }
                lpoly.Add(clone);
            }


            foreach (var item in Sheets)
            {
                NFP clone = new NFP();
                clone.id     = item.id;
                clone.source = item.source;
                clone.Points = item.Points.Select(z => new SvgPoint(z.x, z.y)
                {
                    exact = z.exact
                }).ToArray();
                if (item.children != null)
                {
                    clone.children = new List <NFP>();
                    foreach (var citem in item.children)
                    {
                        clone.children.Add(new NFP());
                        var l = clone.children.Last();
                        l.id     = citem.id;
                        l.source = citem.source;
                        l.Points = citem.Points.Select(z => new SvgPoint(z.x, z.y)
                        {
                            exact = z.exact
                        }).ToArray();
                    }
                }
                lsheets.Add(clone);
            }

            if (offsetTreePhase)
            {
                var grps = lpoly.GroupBy(z => z.source).ToArray();
                if (Background.UseParallel)
                {
                    Parallel.ForEach(grps, (item) =>
                    {
                        SvgNest.offsetTree(item.First(), 0.5 * SvgNest.Config.spacing, SvgNest.Config);
                        foreach (var zitem in item)
                        {
                            zitem.Points = item.First().Points.ToArray();
                        }
                    });
                }
                else
                {
                    foreach (var item in grps)
                    {
                        SvgNest.offsetTree(item.First(), 0.5 * SvgNest.Config.spacing, SvgNest.Config);
                        foreach (var zitem in item)
                        {
                            zitem.Points = item.First().Points.ToArray();
                        }
                    }
                }

                foreach (var item in lsheets)
                {
                    SvgNest.offsetTree(item, -0.5 * SvgNest.Config.spacing, SvgNest.Config, true);
                }
            }



            List <NestItem> partsLocal = new List <NestItem>();
            var             p1         = lpoly.GroupBy(z => z.source).Select(z => new NestItem()
            {
                Polygon = z.First(),
                IsSheet = false,
                Quanity = z.Count()
            });

            var p2 = lsheets.GroupBy(z => z.source).Select(z => new NestItem()
            {
                Polygon = z.First(),
                IsSheet = true,
                Quanity = z.Count()
            });


            partsLocal.AddRange(p1);
            partsLocal.AddRange(p2);
            int srcc = 0;

            foreach (var item in partsLocal)
            {
                item.Polygon.source = srcc++;
            }


            Nest.launchWorkers(partsLocal.ToArray());
            var plcpr = Nest.nests.First();

            if (current == null || plcpr.fitness < current.fitness)
            {
                AssignPlacement(plcpr);
            }
            Iterations++;
        }