Esempio n. 1
0
        public static IEnumerable <Geometry> ToGeometryBlock(this netDxf.Entities.LwPolyline lwpolyline,
                                                             double tolLen)
        {
            var geoms = new List <Geometry>();

            var els = lwpolyline.Explode();

            foreach (var el in els)
            {
                if (el.Type == netDxf.Entities.EntityType.Arc)
                {
                    yield return((el as netDxf.Entities.Arc).ToArc3D(tolLen));
                }
                else if (el.Type == netDxf.Entities.EntityType.Line)
                {
                    var line = (el as netDxf.Entities.Line);
                    if (((Vector3D)line.StartPoint).EqualsTol(tolLen, line.EndPoint))
                    {
                        continue;
                    }

                    yield return(line.ToLine3D());
                }
            }
        }
Esempio n. 2
0
        public override void ToDxf(DxfDocument dxf)
        {
            //= new DxfDocument();
            // Bound
            List <netDxf.Entities.LwPolylineVertex> polyVertexes = new List <netDxf.Entities.LwPolylineVertex>();

            foreach (IFigure p in this.CulvertBound.Dependencies)
            {
                if (p is IPoint)
                {
                    var point = p as IPoint;
                    polyVertexes.Add(new netDxf.Entities.LwPolylineVertex(point.Coordinates.X, point.Coordinates.Y));
                }
            }

            // Cells
            // Số cells trên mặt cắt ngang
            int cellsNumber = NumberOfCellsToInt(this.NumberOfCells);

            for (int i = 0; i < cellsNumber; i++)
            {
                List <netDxf.Entities.LwPolylineVertex> cellVertexes = new List <netDxf.Entities.LwPolylineVertex>();
                foreach (IPoint p in GetCellDependencies(i))
                {
                    cellVertexes.Add(new netDxf.Entities.LwPolylineVertex(p.Coordinates.X, p.Coordinates.Y));
                }
                netDxf.Entities.LwPolyline cellPolyline = new netDxf.Entities.LwPolyline(cellVertexes, true);
                cellPolyline.Layer             = new netDxf.Tables.Layer("polyline2d");
                cellPolyline.Layer.Color.Index = ColorHelper.ColorToAutoCADColor(this.LineStyle.Color);
                //polyline2d.Normal = new Vector3(1, 1, 1);
                //polyline2d.Elevation = 0.0f;
                dxf.AddEntity(cellPolyline);
            }
            netDxf.Entities.LwPolyline polyline2d = new netDxf.Entities.LwPolyline(polyVertexes, true);
            polyline2d.Layer             = new netDxf.Tables.Layer("polyline2d");
            polyline2d.Layer.Color.Index = ColorHelper.ColorToAutoCADColor(this.LineStyle.Color);
            //polyline2d.Normal = new Vector3(1, 1, 1);
            //polyline2d.Elevation = 0.0f;
            dxf.AddEntity(polyline2d);
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2000;
            //dxf.Save(fileName);

            foreach (IFigure f in Children)
            {
                var child = f as FigureBase;
                child.ToDxf(dxf);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// build 2d dxf polyline.
        /// note: use RepeatFirstAtEnd extension to build a closed polyline
        /// </summary>
        public static netDxf.Entities.LwPolyline ToLwPolyline(this IEnumerable <Geometry> _geom, double tolLen, bool closed = true)
        {
            var geom = _geom.ToList();

            var N = Vector3D.ZAxis;

            var cs = new CoordinateSystem3D(Vector3D.Zero, N, CoordinateSystem3DAutoEnum.AAA);

            var pvtx = new List <netDxf.Entities.LwPolylineVertex>();

            Vector3D lastPt = null;

            for (int i = 0; i < geom.Count; ++i)
            {
                Vector3D from = null;
                Vector3D to   = null;

                switch (geom[i].Type)
                {
                case GeometryType.Vector3D:
                {
                    to = geom[i] as Vector3D;
                    var lwpv = new netDxf.Entities.LwPolylineVertex(to.ToVector2());
                    pvtx.Add(lwpv);
                    lastPt = to;
                }
                break;

                case GeometryType.Line3D:
                {
                    var seg = geom[i] as Line3D;
                    from = seg.From;
                    to   = seg.To;

                    if (lastPt == null || lastPt.EqualsTol(tolLen, from))
                    {
                        var lwpv = new netDxf.Entities.LwPolylineVertex(from.ToUCS(cs).ToVector2());
                        pvtx.Add(lwpv);
                        lastPt = to;
                    }
                    else
                    {
                        var lwpv = new netDxf.Entities.LwPolylineVertex(to.ToUCS(cs).ToVector2());
                        pvtx.Add(lwpv);
                        lastPt = from;
                    }
                }
                break;

                case GeometryType.Arc3D:
                {
                    var arc = geom[i] as Arc3D;
                    from = arc.From;
                    to   = arc.To;
                    var bulge = arc.Bulge(tolLen, arc.From, arc.To, N);

                    if (lastPt == null)
                    {
                        if (i < geom.Count - 1)
                        {
                            if (geom[i + 1].GeomFrom.EqualsTol(tolLen, to))
                            {
                                var lwpv = new netDxf.Entities.LwPolylineVertex(from.ToUCS(cs).ToVector2())
                                {
                                    Bulge = bulge
                                };
                                pvtx.Add(lwpv);
                                lastPt = to;
                            }
                            else
                            {
                                var lwpv = new netDxf.Entities.LwPolylineVertex(to.ToUCS(cs).ToVector2())
                                {
                                    Bulge = -bulge
                                };
                                pvtx.Add(lwpv);
                                lastPt = from;
                            }
                        }
                        else
                        {
                            var lwpv = new netDxf.Entities.LwPolylineVertex(from.ToUCS(cs).ToVector2())
                            {
                                Bulge = bulge
                            };
                            pvtx.Add(lwpv);
                            lastPt = to;
                        }
                    }
                    else
                    {
                        if (lastPt.EqualsTol(tolLen, from))
                        {
                            var lwpv = new netDxf.Entities.LwPolylineVertex(from.ToUCS(cs).ToVector2())
                            {
                                Bulge = bulge
                            };
                            pvtx.Add(lwpv);
                            lastPt = to;
                        }
                        else
                        {
                            var lwpv = new netDxf.Entities.LwPolylineVertex(to.ToUCS(cs).ToVector2())
                            {
                                Bulge = -bulge
                            };
                            pvtx.Add(lwpv);
                            lastPt = from;
                        }
                    }
                }
                break;
                }
            }

            if (!closed)
            {
                var lwpv = new netDxf.Entities.LwPolylineVertex(lastPt.ToUCS(cs).ToVector2());
                pvtx.Add(lwpv);
            }

            var lwpoly = new netDxf.Entities.LwPolyline(pvtx, isClosed: closed);

            lwpoly.Normal = N.Normalized();

            return(lwpoly);
        }
Esempio n. 4
0
        public static void RegisterGraphArea(CmdlineParser parser)
        {
            var cmdReplaceToken = parser.AddCommand("graph-area", "compute area under graph XY", (parserGraphArea) =>
            {
                var _decimalDelimiter = parserGraphArea.AddShort("d", "decimal separator (default=.)", "VAL");
                var _fieldDelimiter   = parserGraphArea.AddShort("f", "field separator (default=,)", "VAL");
                var _genDxf           = parserGraphArea.AddShort("x", "generate dxf lwpolyline output");
                var _filename         = parserGraphArea.AddMandatoryParameter("filename", "simple XY column file");

                parserGraphArea.OnCmdlineMatch(() =>
                {
                    var genDxf = (bool)_genDxf;

                    var pathfilename = (string)_filename;
                    if (!File.Exists(pathfilename))
                    {
                        System.Console.WriteLine($"can't find file [{pathfilename}]");
                        return;
                    }

                    string dxfPathfilename = null;
                    netDxf.DxfDocument dxf = null;
                    if (genDxf)
                    {
                        dxfPathfilename = Path.Combine(
                            Path.GetDirectoryName(pathfilename), Path.GetFileNameWithoutExtension(pathfilename) + ".dxf");
                        dxf = new netDxf.DxfDocument();
                    }

                    var decDelim   = (string)_decimalDelimiter;
                    var fieldDelim = (string)_fieldDelimiter;

                    if (decDelim == null)
                    {
                        decDelim = ".";
                    }
                    if (fieldDelim == null)
                    {
                        fieldDelim = ",";
                    }

                    var ni = (NumberFormatInfo)CultureInfo.InvariantCulture.NumberFormat.Clone();
                    ni.NumberDecimalSeparator = decDelim;

                    var area = 0d;

                    var pts = new List <XYPt>();

                    using (var sr = new StreamReader(pathfilename))
                    {
                        while (!sr.EndOfStream)
                        {
                            var line = sr.ReadLine().Trim();
                            if (line.Length != 0)
                            {
                                var ss = line.Split(fieldDelim);
                                var x  = double.Parse(ss[0], ni);
                                var y  = double.Parse(ss[1], ni);
                                pts.Add(new XYPt()
                                {
                                    x = x, y = y
                                });
                            }
                        }
                    }

                    pts = pts.OrderBy(w => w.x).ToList();

                    var MINY = pts.Min(w => w.y);

                    var prevx = 0d;
                    var prevy = 0d;
                    int cnt   = 0;

                    netDxf.Entities.LwPolyline lw = null;
                    if (dxf != null)
                    {
                        lw = new netDxf.Entities.LwPolyline();
                    }

                    foreach (var pt in pts)
                    {
                        if (dxf != null)
                        {
                            lw.Vertexes.Add(new netDxf.Entities.LwPolylineVertex(pt.x, pt.y));
                        }
                        if (cnt > 0)
                        {
                            var maxy = Max(prevy, pt.y);
                            var miny = Min(prevy, pt.y);
                            var b    = (pt.x - prevx);
                            area    += b * (miny - MINY) + b * (maxy - miny) / 2;
                        }

                        prevx = pt.x;
                        prevy = pt.y;

                        ++cnt;
                    }

                    System.Console.WriteLine(Invariant($"area: {area}"));

                    if (dxf != null)
                    {
                        dxf.AddEntity(lw);
                        dxf.Save(dxfPathfilename, true);
                        System.Console.WriteLine($"[{dxfPathfilename}] written.");
                    }
                });
            });
        }
Esempio n. 5
0
        //Method to parse DXF line by line when LoadDXF fails
        public static DxfDocument LineByLineLoader(string filename)
        {
            vector_list.Clear();

            DxfDocument dxfdata = new DxfDocument();
            List<string> list_of_strings = new List<string>();
            //reset logic function
            reset_logic();

            entity_count =0;
            double intermediate =0.0d;  //used for nullable exchange
            int int_intermediate =0;

            bool in_block = false;
            bool in_entities =false;
            int LineCount  =0;
            string coder_string ="";
            string a_string ="";
            string layer_string ="";

            Vector2 start_point = new Vector2(0,0);
            Vector2 end_point = new Vector2(0,0);

            try
            {
                string line = null;
                bool found_file_end =false;
                System.IO.TextReader readFile = new StreamReader(filename);
                while (found_file_end==false)
                {
                    line = readFile.ReadLine();
                    if (line != null)
                    {
                        list_of_strings.Add(line);
                    }
                    else
                    {
                        found_file_end=true;
                    }
                }
                readFile.Close();
                readFile = null;
            }
               	    catch(Exception e)
            {
                error_string=e.ToString();
                return dxfdata;
            }

               	    for(int i=0;i<list_of_strings.Count; i+=2)   //read strings in pairs - first is code - second is value
               	    {
                LineCount = LineCount+1;
                coder_string = list_of_strings[i].Trim();
                try
                {
                    a_string = list_of_strings[i+1].Trim();
                }
                catch
                {
                    a_string="";
                }

                //check location in structure - only read from entities section
                if (coder_string =="0" && a_string=="BLOCK")
                {
                    in_block=true;
                }
                if(coder_string =="2" && a_string=="ENTITIES")
                {
                    in_entities=true;
                }
                if(coder_string =="0" && a_string=="ENDBLK")
                {
                    in_block=false;
                }
                if(coder_string =="0" && a_string=="ENDSEC")
                {
                    in_entities=false;
                }

                //read in layer info
                if(coder_string=="8" && in_block==false &&  in_entities==true && (ReadingLine==true || ReadingPolyline == true ||ReadingArc==true || ReadingCircle == true))
                {
                   layer_string = a_string;
                   FoundNewLayer=true;
                    //could populate a layer list here if needed

                }
                //read data
                if(coder_string=="10")
                {
                    double.TryParse(a_string, out intermediate);
                    X1=(double?)intermediate;
                }

                if (coder_string=="11")
                {
                    double.TryParse(a_string, out intermediate);
                    X2=(double?)intermediate;
                }

                if(coder_string=="20")
                {
                    double.TryParse(a_string, out intermediate);
                    Y1=(double?)intermediate;
                }

                if(coder_string=="21")
                {
                    double.TryParse(a_string, out intermediate);
                    Y2=(double?)intermediate;
                }

                if(coder_string=="40")
                {
                    double.TryParse(a_string, out intermediate);
                    radius=(double?)intermediate;
                }

                if(coder_string=="50")
                {
                    double.TryParse(a_string, out intermediate);
                    start_angle=(double?)intermediate;
                }

                if(coder_string=="51")
                {
                    double.TryParse(a_string, out intermediate);
                    end_angle=(double?)intermediate;
                }

                if(coder_string=="70")
                {
                    if(ReadingPolyline==true)
                    {
                        if(a_string=="1")
                        {
                            polyline_closed=true;
                        }
                        else
                        {
                            polyline_closed=false;
                        }
                    }
                }
                if(coder_string=="90")
                {
                    if(ReadingPolyline==true)
                    {
                        int.TryParse(a_string, out int_intermediate);
                        PointCount = (int?)int_intermediate;
                    }

                }

               	//flag start of a line
               	if(coder_string =="0" && a_string=="LINE" && in_block==false && in_entities==true)
               	{
               		if(ReadingLine==false)
               		{
                        reset_logic();
                        ReadingLine = true;
               		}
                    else
                    {
                        reset_logic();
                    }
               	}
                //add line if data complete
                if(ReadingLine==true && X1!=null && Y1 !=null && X2 !=null && Y2 != null)
                {
                    start_point = new Vector2((double)X1,(double)Y1);
                    end_point = new Vector2((double)X2,(double)Y2);

                    netDxf.Entities.Line aLine = new netDxf.Entities.Line(start_point,end_point);

                    aLine.Layer = new netDxf.Tables.Layer(layer_string);

                    dxfdata.AddEntity(aLine);
                    reset_logic();

                    entity_count++;
                }

                //flag start of a LWPOLYLINE
                if(coder_string =="0" && a_string=="LWPOLYLINE" && in_block==false && in_entities==true)
                {
                    if(ReadingPolyline == false)
                    {
                        reset_logic();
                        ReadingPolyline = true;
                    }
                    else
                    {
                        reset_logic();
                    }
                }

                //add point to polyline
                if(ReadingPolyline==true && X1 !=null && Y1!=null)
                {
                    netDxf.Entities.LwPolylineVertex aVertex = new netDxf.Entities.LwPolylineVertex(new Vector2((double)X1,(double)Y1),0.0d);

                    points.Add(aVertex);
                    X1 = null;
                    Y1 = null;
                }

                //add polyline if have enough points

                if(ReadingPolyline==true && points.Count==PointCount && PointCount !=null)
                {
                    netDxf.Entities.LwPolyline aPolyline = new netDxf.Entities.LwPolyline(points,polyline_closed);
                    aPolyline.Layer= new netDxf.Tables.Layer(layer_string);
                    dxfdata.AddEntity(aPolyline);
                    reset_logic();
                    entity_count++;

                }

                //flag star of a ARC
                if(coder_string =="0" && a_string=="ARC" && in_block == false)
                {
                    if(ReadingArc==false)
                    {
                        reset_logic();
                        ReadingArc = true;
                    }
                    else
                    {
                        reset_logic();
                    }
                }

                //add arc if data complete
                if(ReadingArc==true && X1 != null && Y1 !=null && radius !=null && start_angle != null && end_angle !=null)
                {
                    Vector2 center = new Vector2((double)X1,(double)Y1);
                    netDxf.Entities.Arc aArc = new netDxf.Entities.Arc(center,(double)radius,(double)start_angle,(double)end_angle);
                    aArc.Layer= new netDxf.Tables.Layer(layer_string);
                    dxfdata.AddEntity(aArc);
                    reset_logic();
                    entity_count++;
                }

                //flag star of a CIRCLE
                if (coder_string =="0" && a_string=="CIRCLE" && in_block ==false)
                {
                    if (ReadingArc==false)
                    {
                        reset_logic();
                        ReadingCircle =true;
                    }
                    else
                    {
                        reset_logic();
                    }
                }

                //add circle if data complete
                if(ReadingCircle==true && X1 !=null && Y1 !=null && radius != null)
                {
               			Vector2 center = new Vector2((double)X1,(double)Y1);
               			netDxf.Entities.Circle aCircle = new netDxf.Entities.Circle(center,(double)radius);
                    aCircle.Layer= new netDxf.Tables.Layer(layer_string);
                    dxfdata.AddEntity(aCircle);
                    reset_logic();
                    entity_count++;
                }

               	    }

            return dxfdata;
        }
Esempio n. 6
0
        private void decompose_DXF(string dxfpath, string txtpath, int prec)
        {
            DxfDocument dxf;

            try
            {
                dxf = DxfDocument.Load(dxfpath);
            }
            catch (Exception ex)
            {
                MessageBox.Show("dxf load fail.\r\n" + ex.Message);
                return;
            }
            if (dxf == null)
            {
                MessageBox.Show("dxf load fail.");
                return;
            }
            //Save the coordinates of each segment into a list
            List <List <List <double> > > doublelist = new List <List <List <double> > >();

            //LwPolylines
            if (dxf.LwPolylines.Count != 0)
            {
                foreach (netDxf.Entities.LwPolyline i in dxf.LwPolylines)
                {
                    List <netDxf.Entities.EntityObject> polymember = new List <netDxf.Entities.EntityObject>();
                    polymember = i.Explode();
                    dxf.AddEntity(polymember);
                }
            }
            //Splines
            if (dxf.Splines.Count != 0)
            {
                foreach (netDxf.Entities.Spline i in dxf.Splines)
                {
                    List <List <double> >    element = new List <List <double> >();
                    netDxf.Entities.Polyline k       = i.ToPolyline(20);
                    foreach (netDxf.Entities.PolylineVertex j in k.Vertexes)
                    {
                        List <double> coor = new List <double>();
                        coor.Add(j.Location.X);
                        coor.Add(j.Location.Y);
                        element.Add(coor);
                    }
                    doublelist.Add(element);
                }
            }
            //Arcs
            if (dxf.Arcs.Count != 0)
            {
                foreach (netDxf.Entities.Arc i in dxf.Arcs)
                {
                    List <List <double> > element = new List <List <double> >();
                    //int sampling_point=(int)(Math.Round(Math.Abs(i.EndAngle - i.StartAngle) / prec)+0.5);
                    //netDxf.Entities.LwPolyline k = i.ToPolyline(sampling_point);
                    int number_of_sampling = (int)Math.Round(2 * Math.PI * i.Radius * Math.Min(Math.Abs(i.StartAngle - i.EndAngle), Math.Abs(i.StartAngle - i.EndAngle - 360)) / 360 * (1 / prec));
                    if (number_of_sampling < 2)
                    {
                        number_of_sampling = 2;
                    }
                    netDxf.Entities.LwPolyline k = i.ToPolyline(number_of_sampling);
                    foreach (netDxf.Entities.LwPolylineVertex j in k.Vertexes)
                    {
                        List <double> coor = new List <double>();
                        coor.Add(j.Location.X);
                        coor.Add(j.Location.Y);
                        element.Add(coor);
                    }
                    doublelist.Add(element);
                }
            }
            //Circles
            if (dxf.Circles.Count != 0)
            {
                foreach (netDxf.Entities.Circle i in dxf.Circles)
                {
                    List <List <double> > element = new List <List <double> >();
                    int number_of_sampling        = (int)Math.Round(2 * Math.PI * i.Radius * (1 / prec));
                    netDxf.Entities.LwPolyline k  = i.ToPolyline(number_of_sampling);
                    foreach (netDxf.Entities.LwPolylineVertex j in k.Vertexes)
                    {
                        List <double> coor = new List <double>();
                        coor.Add(j.Location.X);
                        coor.Add(j.Location.Y);
                        element.Add(coor);
                    }
                    doublelist.Add(element);
                }
            }
            //Lines
            if (dxf.Lines.Count != 0)
            {
                foreach (netDxf.Entities.Line i in dxf.Lines)
                {
                    /*List<List<double>> element = new List<List<double>>();
                     * List<double> coor1 = new List<double>();
                     * coor1.Add(i.StartPoint.X);
                     * coor1.Add(i.StartPoint.Y);
                     * element.Add(coor1);
                     * List<double> coor2 = new List<double>();
                     * coor2.Add(i.EndPoint.X);
                     * coor2.Add(i.EndPoint.Y);
                     * element.Add(coor2);
                     * doublelist.Add(element);*/
                    List <List <double> > element = new List <List <double> >();
                    double m = i.StartPoint.X;
                    double n = i.StartPoint.Y;
                    double s = i.EndPoint.X;
                    double t = i.EndPoint.Y;
                    double x = s - m;
                    double y = t - n;
                    //Normalize
                    double n_x = x / Math.Sqrt(x * x + y * y) * prec;
                    double n_y = y / Math.Sqrt(x * x + y * y) * prec;
                    int    number_of_sampling = (int)(Math.Floor(Math.Sqrt(x * x + y * y) / prec));
                    for (int j = 0; j <= number_of_sampling; j++)
                    {
                        List <double> coor1 = new List <double>();
                        coor1.Add(m + n_x * j);
                        coor1.Add(n + n_y * j);
                        element.Add(coor1);
                    }
                    List <double> coor2 = new List <double>();
                    coor2.Add(i.EndPoint.X);
                    coor2.Add(i.EndPoint.Y);
                    element.Add(coor2);
                    doublelist.Add(element);
                }
            }
            //Sorting
            List <List <List <double> > > result = new List <List <List <double> > >();

            while (doublelist.Count != 0)
            {
                List <List <double> > currentoutline = new List <List <double> >();
                currentoutline = doublelist[0];
                List <double> currentend = new List <double>();
                currentend = currentoutline[currentoutline.Count - 1];
                doublelist.RemoveAt(0);

                int size = doublelist.Count;
                for (int j = 0; j < size; j++)
                {
                    for (int i = 0; i < doublelist.Count; i++)
                    {
                        List <double> newhead = new List <double>();
                        newhead = doublelist[i][0];

                        List <double> newend = new List <double>();
                        newend = (doublelist[i][doublelist[i].Count - 1]);
                        if (Math.Abs(currentend[0] - newhead[0]) < 0.05 && Math.Abs(currentend[1] - newhead[1]) < 0.05)
                        {
                            int tail = currentoutline.Count - 1;
                            currentoutline.AddRange(doublelist[i]);
                            currentoutline.RemoveAt(tail);
                            currentend.RemoveAt(0);
                            currentend = currentoutline[currentoutline.Count - 1];
                            doublelist.RemoveAt(i);
                            break;
                        }
                        else if (Math.Abs(currentend[0] - newend[0]) < 0.05 && Math.Abs(currentend[1] - newend[1]) < 0.05)
                        {
                            int tail = currentoutline.Count - 1;
                            doublelist[i].Reverse();
                            currentoutline.AddRange(doublelist[i]);
                            currentoutline.RemoveAt(tail);
                            currentend.RemoveAt(0);
                            currentend = currentoutline[currentoutline.Count - 1];
                            doublelist.RemoveAt(i);
                            break;
                        }
                    }
                }
                //currentoutline.Add(currentoutline[0]);
                //currentoutline.Add(currentoutline[1]);
                result.Add(currentoutline);
            }
            List <List <double> >         outline      = new List <List <double> >();
            List <List <List <double> > > inneroutline = new List <List <List <double> > >();

            outline = result[0];
            double        maxarea             = 0;
            List <double> center_and_boundary = new List <double>();

            for (int i = 0; i < result.Count; i++)
            {
                double right  = result[i][0][0];
                double left   = result[i][0][0];
                double top    = result[i][0][1];
                double bottom = result[i][0][1];
                for (int j = 0; j < result[i].Count; j++)
                {
                    if (result[i][j][0] > right)
                    {
                        right = result[i][j][0];
                    }
                    if (result[i][j][0] < left)
                    {
                        left = result[i][j][0];
                    }
                    if (result[i][j][1] > top)
                    {
                        top = result[i][j][1];
                    }
                    if (result[i][j][1] < bottom)
                    {
                        bottom = result[i][j][1];
                    }
                }
                double currentarea = (top - bottom) * (right - left);
                if (i == 0)
                {
                    maxarea = currentarea;
                    outline = result[i];
                    center_and_boundary.Add((right + left) / 2);
                    center_and_boundary.Add((top + bottom) / 2);
                    center_and_boundary.Add(left);
                    center_and_boundary.Add(top);
                    center_and_boundary.Add(right);
                    center_and_boundary.Add(bottom);
                }
                else if (currentarea > maxarea && i > 0)
                {
                    maxarea = currentarea;
                    inneroutline.Add(outline);
                    outline = result[i];
                    center_and_boundary[0] = ((right + left) / 2);
                    center_and_boundary[1] = ((top + bottom) / 2);
                    center_and_boundary[2] = left;
                    center_and_boundary[3] = top;
                    center_and_boundary[4] = right;
                    center_and_boundary[5] = bottom;
                }
                else
                {
                    inneroutline.Add(result[i]);
                }
            }
            StreamWriter str = new StreamWriter(txtpath);

            foreach (double j in center_and_boundary)
            {
                str.WriteLine(j.ToString());
            }
            str.WriteLine("");
            foreach (List <double> j in outline)
            {
                foreach (double k in j)
                {
                    str.WriteLine(k.ToString());
                }
            }
            str.WriteLine("");
            foreach (List <List <double> > i in inneroutline)
            {
                foreach (List <double> j in i)
                {
                    foreach (double k in j)
                    {
                        str.WriteLine(k.ToString());
                    }
                }
                str.WriteLine("");
            }
            str.Close();
        }