コード例 #1
0
        /// <summary>
        /// 큰 diagridUnit에 pixel이 들어갈 수록 높은 점수를 받는다.
        /// </summary>
        /// <param name="grid"></param>
        /// <param name="intension"></param>
        public double EstimateInclusionScore(RectangleFrameDiagrid grid, IntensionLayer intension, GeometryParser parser)
        {
            var handler = new GeoHandler();
            List <List <(int, int)> > all = parser.ToPolygonPointList(grid);
            double       width            = all.SelectMany(n => n).Max(n => n.Item1);
            double       height           = all.SelectMany(n => n).Max(n => n.Item2);
            List <Pixel> pixels           = intension.GetPixels(width, height);

            var diagridUnits = grid.DiagridUnits;

            var inspections = diagridUnits
                              .Select(n => new { pointList = parser.ToPolygonPointList(n), mag = n.Magnification })
                              .Select(n => new { pts = n.pointList.Select(k => new Point(k.Item1, k.Item2)), mag = n.mag })
                              .Select(n => new { polygon = new Polygon(n.pts), mag = n.mag })
                              .ToList();


            double total = 0;

            foreach (var inspect in inspections)
            {
                var inclusions = pixels
                                 .Where(n => handler.PointInPolygon(new Point(n.PixelCenterX, n.PixelCenterY), inspect.polygon) == PointPositionWithPolygon.Inside)
                                 .ToList();

                double score = inclusions
                               .Select(n => (int)n.Val)
                               .Sum();

                double weightedScore = score * inspect.mag;
                total += weightedScore;
            }

            return(total);
        }
コード例 #2
0
        public void PointInPolygon_Test1()
        {
            var handler = new GeoHandler();

            var pts = new List <Point>()
            {
                new Point(0, 0),
                new Point(2, 3),
                new Point(-2, 7),
            };
            var poly = new Polygon(pts);
            var pt1  = new Point(1, 1);
            var pt2  = new Point(0, 1);
            var pt3  = new Point(1.50921, 2.2638);

            Assert.IsTrue(handler.PointInPolygon(pt1, poly) == PointPositionWithPolygon.Outside);
            Assert.IsTrue(handler.PointInPolygon(pt2, poly) == PointPositionWithPolygon.Inside);
            Assert.IsTrue(handler.PointInPolygon(pt3, poly) == PointPositionWithPolygon.OnBoundary);
        }