Exemplo n.º 1
0
 static private PixelPosition_T[,] CalOne(PixelPosition_T[,] pixelArrange)//第一次计算
 {
     for (int i = 0; i < pixelArrange.GetLength(0); i++)
     {
         for (int j = 0; j < pixelArrange.GetLength(1); j++)
         {
             if (pixelArrange[i, j] != null)
             {
                 if (pixelArrange[i, j - 1] == null)
                 {
                     pixelArrange[i, j - 1] = new PixelPosition_T();
                 }
                 if (pixelArrange[i - 1, j] == null)
                 {
                     pixelArrange[i - 1, j] = new PixelPosition_T();
                 }
                 if (pixelArrange[i, j - 1].Code < pixelArrange[i - 1, j].Code)
                 {
                     pixelArrange[i, j].Code = pixelArrange[i, j - 1].Code + 1;
                 }
                 else
                 {
                     pixelArrange[i, j].Code = pixelArrange[i - 1, j].Code + 1;
                 }
             }
         }
     }
     return(pixelArrange);
 }
Exemplo n.º 2
0
        static private PixelPosition_T RasterationPoint(IPoint pt, Raster_T ras)
        {
            int             row = (int)((pt.Y - ras.Originpt.Y) / ras.Pixelsize);
            int             col = (int)((pt.X - ras.Originpt.X) / ras.Pixelsize);
            PixelPosition_T pp  = new PixelPosition_T(row, col);

            return(pp);
        }
Exemplo n.º 3
0
        static private List <PixelPosition_T> RasterationPolygon(IFeature polyFea, Raster_T ras, double xmin, double xMax)
        {
            List <PixelPosition_T>      pypixel    = new List <PixelPosition_T>();
            IPointCollection            pygonPtCol = polyFea.Shape as IPointCollection;
            Dictionary <IPoint, double> ptDic      = new Dictionary <IPoint, double>();

            for (int i = 0; i < pygonPtCol.PointCount; i++)
            {
                //IPoint ppt = GetGeo( axMapControl1.ActiveView,pygonPtCol.get_Point(i).X, pygonPtCol.get_Point(i).Y);
                IPoint ppt = pygonPtCol.get_Point(i);
                ptDic.Add(ppt, ppt.Y);
            }

            Dictionary <IPoint, double> dicYValue = SortByXYvalue(ptDic);
            PixelPosition_T             ppmax     = RasterationPoint(dicYValue.Keys.ElementAt(dicYValue.Count - 1), ras);
            PixelPosition_T             ppmin     = RasterationPoint(dicYValue.Keys.ElementAt(0), ras);

            for (int i = 0; i <= (ppmax.Row - ppmin.Row); i++)
            {
                double y   = (ppmin.Row + i + 0.5) * ras.Pixelsize + ras.Originpt.Y;
                IPoint pt1 = new PointClass();
                pt1.X = xmin;// ras.Originpt.X;
                pt1.Y = y;
                pt1.Z = 100;
                IPoint pt2 = new PointClass();
                pt2.X = xMax;//  ras.Originpt.X + ras.Cols * ras.Pixelsize;
                pt2.Y = y;
                pt2.Z = 100;
                IPolyline plyLine = new PolylineClass();
                plyLine.FromPoint = pt1;
                plyLine.ToPoint   = pt2;
                ITopologicalOperator        topoLyr  = plyLine as ITopologicalOperator;
                Dictionary <IPoint, double> interpts = new Dictionary <IPoint, double>();
                for (int j = 0; j < pygonPtCol.PointCount - 1; j++)
                {
                    IPolyline partLy = new PolylineClass();
                    partLy.FromPoint = pygonPtCol.get_Point(j);
                    partLy.ToPoint   = pygonPtCol.get_Point(j + 1);
                    IGeometry pgeo = topoLyr.Intersect(partLy as IGeometry, esriGeometryDimension.esriGeometry0Dimension);
                    if (pgeo.IsEmpty == false)
                    {
                        IPointCollection ptC = pgeo as IPointCollection;
                        interpts.Add(ptC.get_Point(0), ptC.get_Point(0).X);
                    }
                }
                Dictionary <IPoint, double> newPts = SortByXYvalue(interpts);
                for (int j = 0; j < newPts.Count - 1; j = j + 2)
                {
                    IPolyline pline = new PolylineClass();
                    pline.FromPoint = newPts.Keys.ElementAt(j);
                    pline.ToPoint   = newPts.Keys.ElementAt(j + 1);
                    List <PixelPosition_T> cpixel = RasterationHonLine(pline, ras);
                    pypixel.AddRange(cpixel);
                }
            }
            return(pypixel);
        }
Exemplo n.º 4
0
 static private PixelPosition_T[,] OneDemiConvertToTwo(int rs, int col)
 {
     PixelPosition_T[,] pixelArrange = new PixelPosition_T[rs, col];
     for (int i = 0; i < newPiexlList.Count; i++)
     {
         PixelPosition_T pix_T = newPiexlList[i];
         pixelArrange[pix_T.Row, pix_T.Col]      = new PixelPosition_T();
         pixelArrange[pix_T.Row, pix_T.Col].Row  = pix_T.Row;
         pixelArrange[pix_T.Row, pix_T.Col].Col  = pix_T.Col;
         pixelArrange[pix_T.Row, pix_T.Col].Code = pix_T.Code;
     }
     return(pixelArrange);
 }
Exemplo n.º 5
0
        static private List <PixelPosition_T> RasterationHonLine(IPolyline line, Raster_T ras)
        {
            List <PixelPosition_T> pixels = new List <PixelPosition_T>();

            PixelPosition_T ppmax = RasterationPoint(line.ToPoint, ras);

            PixelPosition_T ppmin = RasterationPoint(line.FromPoint, ras);

            pixels.Add(ppmin);
            for (int i = 1; i < ppmax.Col - ppmin.Col; i++)//
            {
                PixelPosition_T cpp = new PixelPosition_T(ppmin.Row, ppmin.Col + i);
                pixels.Add(cpp);
            }
            pixels.Add(ppmax);
            return(pixels);
        }
Exemplo n.º 6
0
        static private List <PixelPosition_T> ArrangePixel(List <PixelPosition_T> newPiexl)
        {
            List <PixelPosition_T> piexlList = new List <PixelPosition_T>();

            for (int i = 0; i < newPiexl.Count - 1; i++)
            {
                PixelPosition_T pixel = new PixelPosition_T();
                for (int j = 0; j < newPiexl.Count - 1; j++)
                {
                    if (newPiexl[j + 1].Row == newPiexl[j].Row && newPiexl[j].Col > newPiexl[j + 1].Col)
                    {
                        pixel           = newPiexl[j + 1];
                        newPiexl[j + 1] = newPiexl[j];
                        newPiexl[j]     = pixel;
                    }
                }
            }
            return(piexlList = newPiexl);
        }
Exemplo n.º 7
0
        static private Dictionary <int, PixelPosition_T[, ]> CalTwo(PixelPosition_T[,] pixelArrange)//第二次计算
        {
            Dictionary <int, PixelPosition_T[, ]> dic = new Dictionary <int, PixelPosition_T[, ]>();
            int maxCode = 1;

            for (int i = pixelArrange.GetLength(0) - 1; i >= 0; i--)
            {
                for (int j = pixelArrange.GetLength(1) - 1; j >= 0; j--)
                {
                    if (pixelArrange[i, j] != null && pixelArrange[i, j].Code != 0)
                    {
                        if (pixelArrange[i, j + 1] == null)
                        {
                            pixelArrange[i, j + 1] = new PixelPosition_T();
                        }
                        if (pixelArrange[i + 1, j] == null)
                        {
                            pixelArrange[i + 1, j] = new PixelPosition_T();
                        }
                        if (pixelArrange[i, j].Code <= pixelArrange[i, j + 1].Code + 1 && pixelArrange[i, j].Code <= pixelArrange[i + 1, j].Code + 1)
                        {
                            pixelArrange[i, j].Code = pixelArrange[i, j].Code;
                        }
                        else if (pixelArrange[i, j + 1].Code + 1 <= pixelArrange[i, j].Code && pixelArrange[i, j + 1].Code + 1 <= pixelArrange[i + 1, j].Code + 1)
                        {
                            pixelArrange[i, j].Code = pixelArrange[i, j + 1].Code + 1;
                        }
                        else if (pixelArrange[i + 1, j].Code + 1 <= pixelArrange[i, j + 1].Code + 1 && pixelArrange[i + 1, j].Code + 1 <= pixelArrange[i, j].Code)
                        {
                            pixelArrange[i, j].Code = pixelArrange[i + 1, j].Code + 1;
                        }
                        if (pixelArrange[i, j].Code > maxCode)
                        {
                            maxCode = pixelArrange[i, j].Code;
                        }
                    }
                }
            }
            dic.Add(maxCode, pixelArrange);
            return(dic);
        }
Exemplo n.º 8
0
        static private List <PixelPosition_T> TestDistanceSkeletonThinning(Dictionary <int, PixelPosition_T[, ]> dic)
        {
            PixelPosition_T[,] pixelArrange = dic.Values.ElementAt(0);
            int maxCode = dic.Keys.ElementAt(0);
            List <PixelPosition_T> pixelList = new List <PixelPosition_T>();

            for (int i = 0; i < pixelArrange.GetLength(0); i++)
            {
                for (int j = 0; j < pixelArrange.GetLength(1); j++)
                {
                    if (pixelArrange[i, j] != null && pixelArrange[i, j].Code == maxCode)
                    {
                        PixelPosition_T p_T = new PixelPosition_T();
                        p_T.Code = maxCode;
                        p_T.Row  = pixelArrange[i, j].Row;
                        p_T.Col  = pixelArrange[i, j].Col;
                        pixelList.Add(p_T);
                    }
                }
            }
            List <PixelPosition_T> pList = new List <PixelPosition_T>();//总的栅格点存储

            if (pixelList.Count == 1)
            {
                pList.Add(pixelList[0]);
            }
            else
            {
                Dictionary <int, List <PixelPosition_T> > rowPP = new Dictionary <int, List <PixelPosition_T> >();
                List <PixelPosition_T> ppList = null;
                for (int i = 0; i < pixelList.Count; i++)
                {
                    ppList = new List <PixelPosition_T>();
                    PixelPosition_T p_T1 = pixelList[i];
                    ppList.Add(p_T1);
                    pixelList.Remove(p_T1);
                    for (int j = 0; j < pixelList.Count; j++)
                    {
                        PixelPosition_T p_T2 = pixelList[j];
                        if (p_T1.Row == p_T2.Row)
                        {
                            ppList.Add(p_T2); pixelList.Remove(p_T2); j = -1;
                        }
                    }
                    i = -1;
                    rowPP.Add(p_T1.Row, ppList);
                }
                if (rowPP.Count == 1)
                {
                    pList.Add(rowPP.Values.ElementAt(0)[(int)(rowPP.Values.ElementAt(0).Count / 2)]);
                }
                else
                {
                    bool isLinkRow = true;
                    for (int i = 0; i < rowPP.Count - 1; i++)
                    {
                        int row1 = rowPP.Keys.ElementAt(i);
                        List <PixelPosition_T> p_T1 = rowPP.Values.ElementAt(i);
                        List <PixelPosition_T> p_T2 = rowPP.Values.ElementAt(i + 1);
                        int row2 = rowPP.Keys.ElementAt(i + 1);
                        if (Math.Abs(row1 - row2) == 1)
                        {
                            if (isLinkRow == false)
                            {
                                pList.Clear();
                                for (int m = 0; m < p_T2.Count; m++)
                                {
                                    pList.Add(p_T2[m]);
                                }
                            }
                            if (isLinkRow == true)
                            {
                                if (i == 0)
                                {
                                    for (int m = 0; m < p_T1.Count; m++)
                                    {
                                        pList.Add(p_T1[m]);
                                    }
                                }
                                for (int m = 0; m < p_T2.Count; m++)
                                {
                                    pList.Add(p_T2[m]);
                                }
                            }
                            isLinkRow = true;
                        }
                        else
                        {
                            isLinkRow = false;
                        }
                    }
                    if (isLinkRow == false)
                    {
                        List <PixelPosition_T> p_T2 = rowPP.Values.ElementAt((int)(rowPP.Count / 2));
                        for (int m = 0; m < p_T2.Count; m++)
                        {
                            pList.Add(p_T2[m]);
                        }
                    }
                }
            }
            return(pList);
        }
Exemplo n.º 9
0
        static private Dictionary <IPoint, IFeature> RaterPtToVectorPt(IFeature pFeature)
        {
            Dictionary <IPoint, IFeature> feaAndCenterRaterPt = new Dictionary <IPoint, IFeature>();

            newPiexlList = new List <PixelPosition_T>();
            IPoint opt = new PointClass();

            opt.X = 0;
            opt.Y = 0;
            double    pixelsize = 1;
            IPolyline pFeaPly   = pFeature.Shape as IPolyline;
            IEnvelope envelop   = pFeaPly.Envelope;
            double    xMin      = envelop.XMin;
            double    xMax      = envelop.XMax;
            double    yMin      = envelop.YMin;
            double    yMax      = envelop.YMax;

            int      rs     = (int)((yMax - yMin) / pixelsize);
            int      cs     = (int)((xMax - xMin) / pixelsize);
            Raster_T mapras = new Raster_T(rs, cs, pixelsize, opt);

            mapras.Originpt.Y = yMax;
            mapras.Originpt.X = xMin;
            List <PixelPosition_T> pypixel  = RasterationPolygon(pFeature, mapras, xMin, xMax);
            PixelPosition_T        pp1      = pypixel[pypixel.Count - 1];
            List <PixelPosition_T> newPiexl = new List <PixelPosition_T>();

            Bitmap bmp = new Bitmap(mapras.Cols + 3, mapras.Rows + 2);

            foreach (PixelPosition_T pp in pypixel)
            {
                PixelPosition_T pix_T = new PixelPosition_T();
                pix_T.Code = 1;
                pix_T.Col  = Math.Abs(pp.Col) + 1;
                pix_T.Row  = Math.Abs(pp.Row) + 1;
                newPiexl.Add(pix_T);
            }
            newPiexl.Reverse();
            newPiexlList          = ArrangePixel(newPiexl);
            PixelPosition_T[,] p1 = OneDemiConvertToTwo(rs + 2, cs + 3);
            PixelPosition_T[,] p2 = CalOne(p1);
            Dictionary <int, PixelPosition_T[, ]> p3 = CalTwo(p2);
            List <PixelPosition_T> test = TestDistanceSkeletonThinning(p3);
            IPoint newPeakPt            = new PointClass();

            if (test.Count == 1)
            {
                newPeakPt.X = xMin + test[0].Col;
                newPeakPt.Y = yMax - test[0].Row;
                newPeakPt.Z = 100;
                feaAndCenterRaterPt.Add(newPeakPt, pFeature);
            }
            else
            {
                double X = 0; double Y = 0;
                for (int i = 0; i < test.Count; i++)
                {
                    X += xMin + test[i].Col;
                    Y += yMax - test[i].Row;
                }
                newPeakPt.X = X / test.Count;
                newPeakPt.Y = Y / test.Count;
                newPeakPt.Z = 100;
                feaAndCenterRaterPt.Add(newPeakPt, pFeature);
            }
            return(feaAndCenterRaterPt);
        }