public static List <Point3d> GetBoundaryLine2d(List <Int16Triple> regionPoints, bool smoothing, int iteration)
        {
            Box3Int  box = GetBox3(regionPoints);
            int      stx = 0, sty = 0;
            BitMap2d bmp_1 = GetMappedBitmap(regionPoints, box, ref stx, ref sty);
            // bmp_1.OutputBitMap("1.bmp");
            BitMap2d bmp_2 = GetSingleRegionBitmap(bmp_1);

            // bmp_2.OutputBitMap("2.bmp");
            bmp_1 = null;
            SquarSurface mc2      = new SquarSurface(bmp_2);
            PolyLine     polyline = mc2.GenerateLine();

            if (smoothing && iteration >= 1)
            {
                for (int i = 0; i < iteration; i++)
                {
                    SmoothingLine(polyline);
                }
            }
            // PlyManager.Output2(polyline.Points,polyline.Edges,"3.ply");
            List <FloatDouble> points = polyline.GetDrawablePointList();
            List <Point3d>     ret    = new List <Point3d>(points.Count);

            for (int i = 0; i < points.Count; i++)
            {
                ret.Add(new Point3d(points[i].X + stx, points[i].Y + sty, 0));
            }
            return(ret);
        }
        private static BitMap2d GetSingleRegionBitmap(BitMap2d b)
        {
            BitMap2d            bmp   = new BitMap2d(b.width, b.height, BitMap2d.WHITE);
            Queue <Int16Double> queue = new Queue <Int16Double>();

            queue.Enqueue(new Int16Double(0, 0));
            bmp.SetPixel(0, 0, BitMap2d.BLACK);
            Int16Double[] adj = new Int16Double[4];
            while (queue.Count != 0)
            {
                Int16Double pix = queue.Dequeue();
                InitAdj4(adj, pix.X, pix.Y);
                for (int i = 0; i < 4; i++)
                {
                    Int16Double t = adj[i];
                    if (t.X >= 0 && t.X < bmp.width && t.Y >= 0 && t.Y < bmp.height &&
                        b.GetPixel(t.X, t.Y) == BitMap2d.BLACK && bmp.GetPixel(t.X, t.Y) == BitMap2d.WHITE)
                    {
                        bmp.SetPixel(t.X, t.Y, BitMap2d.BLACK);
                        queue.Enqueue(t);
                    }
                }
            }
            return(bmp);
        }
 public SquarSurface(BitMap2d bmp)
 {
     this.bmp = bmp;
     Width    = bmp.width;
     Height   = bmp.height;
     pb       = new PolyLine2dBuider(bmp.width, bmp.height);
 }
        private static BitMap2d GetMappedBitmap(List <Int16Triple> regionPoints, Box3Int box, ref int stx, ref int sty)
        {
            BitMap2d bmp = new BitMap2d(box.GetXLength() + 2, box.GetYLength() + 2, BitMap2d.BLACK);

            stx = box.Min3[0] - 1;
            sty = box.Min3[1] - 1;
            for (int i = 0; i < regionPoints.Count; i++)
            {
                bmp.SetPixel(regionPoints[i].X - stx, regionPoints[i].Y - sty, BitMap2d.WHITE);
            }
            return(bmp);
        }