Exemple #1
0
        public static List <itemWellLayerVoi> calVoi()
        {
            Voronoi voroObject = new Voronoi(0.1);
            int     iExtentDis = 200; //外边距
            List <itemWellLayerVoi> listLayerVoronoi = new List <itemWellLayerVoi>();
            // 读入小层数据字典
            List <ItemDicLayerDataStatic> listData = cIODicLayerDataStatic.readDicLayerData2struct();

            //   按小层顺序筛选,并计算voronoi,通过voronic 求取每个井层的面积

            foreach (string xcm in cProjectData.ltStrProjectXCM)
            {
                //写到每个小层文件夹内
                string       filePath = Path.Combine(cProjectManager.dirPathLayerDir, xcm, cProjectManager.fileNameGE);
                StreamWriter swGe     = new StreamWriter(filePath, false, Encoding.UTF8);
                List <ItemDicLayerDataStatic> listCurrentLayerData = listData.FindAll(p => p.sXCM == xcm);

                //如果没填得检查一遍
                //内部会排序并有对应的ID
                //尽量让排序后的sizes和Voronoi内部的size是同一个顺序,这块需要校验=Y的情况

                List <PointD> sites = new List <PointD>();

                foreach (ItemDicLayerDataStatic well in listCurrentLayerData)
                {
                    sites.Add(new PointD(well.dbX, well.dbY));
                }

                double[] xVal = new double[sites.Count];
                double[] yVal = new double[sites.Count];
                for (int i = 0; i < sites.Count; i++)
                {
                    xVal[i] = sites[i].X;
                    yVal[i] = sites[i].Y;
                    string sLine = i + " " + xVal[i] + " " + yVal[i];
                    swGe.WriteLine(sLine);
                }
                double           minX    = cProjectData.ltProjectWell.Min(p => p.dbX) - iExtentDis;
                double           maxX    = cProjectData.ltProjectWell.Max(p => p.dbX) + iExtentDis;
                double           minY    = cProjectData.ltProjectWell.Min(p => p.dbY) - iExtentDis;
                double           maxY    = cProjectData.ltProjectWell.Max(p => p.dbY) + iExtentDis;
                List <GraphEdge> list_ge = voroObject.generateVoronoi(xVal, yVal, minX, maxX, minY, maxY);

                for (int i = 0; i < list_ge.Count; i++)
                {
                    Point  p1    = new Point((int)list_ge[i].x1, (int)list_ge[i].y1);
                    Point  p2    = new Point((int)list_ge[i].x2, (int)list_ge[i].y2);
                    string sLine = " size1: " + list_ge[i].site1 + " " + list_ge[i].x1.ToString("0.0") + " " + list_ge[i].y1.ToString("0.0") + " size2: " + list_ge[i].site2 + " " + list_ge[i].x2.ToString("0.0") + " " + list_ge[i].y2.ToString("0.0");
                    swGe.WriteLine(sLine);
                }
                swGe.Close();

                //定义一个数据结构 就是返回 顶点序列,边的顺或者逆时针方向的结构列表
                //注意 这里安装sites的个数找 但是 ge里egde存的是
                List <List <PointD> > list_ClockPoints = new List <List <PointD> >();
                for (int i = 0; i < sites.Count; i++)
                {
                    List <PointD>    points      = new List <PointD>();
                    List <GraphEdge> ListEdgeCur = new List <GraphEdge>();
                    foreach (GraphEdge ge in list_ge)
                    {
                        if ((ge.site2 == i || ge.site1 == i) && (!(ge.x1 == ge.x2 && ge.y1 == ge.y2)))
                        {
                            ListEdgeCur.Add(ge);                                                                     //收集环绕顶点的所有边
                        }
                    }
                    foreach (GraphEdge ge in ListEdgeCur)
                    {
                        PointD p1 = new PointD(ge.x1, ge.y1);
                        PointD p2 = new PointD(ge.x2, ge.y2);

                        if (points.FindIndex(p => p.X == p1.X && p.Y == p1.Y) < 0)
                        {
                            points.Add(p1);
                        }
                        if (points.FindIndex(p => p.X == p2.X && p.Y == p2.Y) < 0)
                        {
                            points.Add(p2);                                            //获得顶点
                        }
                    }
                    List <PointD> PointDistinct = points.Distinct().ToList();
                    //按序号找到所有的顶点,按顺时针或者逆时针排序后输出
                    list_ClockPoints.Add(cSortPoints.sortPoints(PointDistinct, sites[i]));
                }

                //有了 listCurrentLayerData和对应的list_ClockPoints,加上对应的密度,体积系数就能按容积法求出面积,然后输出了
                for (int i = 0; i < listCurrentLayerData.Count; i++)
                {
                    itemWellLayerVoi item = new itemWellLayerVoi();
                    item.sJH        = listCurrentLayerData[i].sJH;
                    item.sXCM       = listCurrentLayerData[i].sXCM;
                    item.dbX        = listCurrentLayerData[i].dbX;
                    item.dbY        = listCurrentLayerData[i].dbY;
                    item.ltdpVertex = list_ClockPoints[i];//顶点
                    listLayerVoronoi.Add(item);
                }
            }//end of layerXCM foreach

            return(listLayerVoronoi);
        }//end of calRes
Exemple #2
0
        void spreadPoints(PaintEventArgs e)
        {
            Graphics dc = e.Graphics;

            List <PointF> sites = new List <PointF>();

            foreach (ItemWell well in cProjectData.ltProjectWell)
            {
                PointF headView = cCordinationTransform.transRealPointF2ViewPoint(
                    well.dbX, well.dbY, cProjectData.dfMapXrealRefer, cProjectData.dfMapYrealRefer, cProjectData.dfMapScale);
                // sites.Add(headView);
                sites.Add(new PointF(Convert.ToSingle(well.dbX), Convert.ToSingle(well.dbY)));
                Pen wellPen = new Pen(Color.Black, 2);
                if (well.iWellType == 3)
                {
                    wellPen = new Pen(Color.Red, 2);
                }
                else if (well.iWellType == 5)
                {
                    wellPen = new Pen(Color.Green, 2);
                }
                else if (well.iWellType == 15)
                {
                    wellPen = new Pen(Color.Blue, 2);
                }

                Pen blackPen = new Pen(Color.Black, 1);
                dc.DrawEllipse(wellPen, headView.X - 1.5f, headView.Y - 1.5f, 3, 3);
                Brush blackBrush = Brushes.Black;
                Font  font       = new Font("黑体", 8);
                dc.DrawString(well.sJH, font, blackBrush,
                              headView.X + 3, headView.Y + 3);
            }
            int iExtentDis = 200;

            double[] xVal = new double[sites.Count];
            double[] yVal = new double[sites.Count];
            for (int i = 0; i < sites.Count; i++)
            {
                xVal[i] = sites[i].X;
                yVal[i] = sites[i].Y;
            }
            double           minX    = cProjectData.ltProjectWell.Min(p => p.dbX) - iExtentDis;
            double           maxX    = cProjectData.ltProjectWell.Max(p => p.dbX) + iExtentDis;
            double           minY    = cProjectData.ltProjectWell.Min(p => p.dbY) - iExtentDis;
            double           maxY    = cProjectData.ltProjectWell.Max(p => p.dbY) + iExtentDis;
            List <GraphEdge> list_ge = voroObject.generateVoronoi(xVal, yVal, minX, maxX, minY, maxY);

            //定义一个数据结构 就是返回 顶点序列,边的顺或者逆时针方向的结构列表
            //注意 这里安装sites的个数找 但是 ge里egde存的是
            List <List <PointD> > list_ClockPoints = new List <List <PointD> >();

            for (int i = 0; i < sites.Count; i++)
            {
                List <PointD>    points      = new List <PointD>();
                List <GraphEdge> ListEdgeCur = new List <GraphEdge>();
                foreach (GraphEdge ge in list_ge)
                {
                    if (ge.site2 == i || ge.site1 == i)
                    {
                        ListEdgeCur.Add(ge);                                //收集环绕顶点的所有边
                    }
                }

                foreach (GraphEdge ge in ListEdgeCur)
                {
                    PointF p1 = cCordinationTransform.transRealPointF2ViewPoint(
                        ge.x1, ge.y1, cProjectData.dfMapXrealRefer, cProjectData.dfMapYrealRefer, cProjectData.dfMapScale);
                    PointF p2 = cCordinationTransform.transRealPointF2ViewPoint(
                        ge.x2, ge.y2, cProjectData.dfMapXrealRefer, cProjectData.dfMapYrealRefer, cProjectData.dfMapScale);
                    dc.DrawLine(Pens.Black, p1.X, p1.Y, p2.X, p2.Y);
                    //points.Add(new PointF(Convert.ToSingle(ge.x2), Convert.ToSingle(ge.y2)));
                    //points.Add(new PointF(Convert.ToSingle(ge.x1), Convert.ToSingle(ge.y1))); //获得顶点
                }
                //按序号找到所有的顶点,按顺时针或者逆时针排序后输出
                //list_ClockPoints.Add(cSortPoints.sortPoints(points.Distinct().OrderBy(p => p.Y).ToList(), sites[i]));
            }

            //List<GraphEdge> ge;
            //ge = MakeVoronoiGraph(sites, panelResCal.Width , panelResCal.Height);
            //StreamWriter swNew = new StreamWriter(cProjectManager.filePathRunInfor, true, Encoding.UTF8);
            //// رسم أضلاع فورونوي
            //for (int i = 0; i < ge.Count; i++)
            //{

            //        Point p1 = new Point((int)ge[i].x1, (int)ge[i].y1);
            //        Point p2 = new Point((int)ge[i].x2, (int)ge[i].y2);
            //        dc.DrawLine(Pens.Black, p1.X, p1.Y, p2.X, p2.Y);

            //        string sLine = "P" + i + " size1: " + ge[i].site1 + " " + ge[i].x1.ToString("0.0") + " " + ge[i].y1.ToString("0.0") + " size2: " + ge[i].site2 + "  " + ge[i].x2.ToString("0.0") + " " + ge[i].y2.ToString("0.0");

            //       swNew.WriteLine(sLine);
            //}
            //swNew.Close();
            base.OnPaint(e);
        }