예제 #1
0
        public static IPoint[] AdditiveSimplifyByAreaPlus(IPoint[] points, double threshold)
        {
            if (points == null || points.Length == 0)
            {
                return(null);
            }
            else if (points.Length == 2)
            {
                return(points);
            }

            List <int> filtered = new List <int>();

            filtered.Add(0);

            int firstIndex = 0, secondIndex = 1, thirdIndex = 2;

            var totalAreaCoef = SpatialUtility.IsClockwise(points) ? 1 : -1;

            double tempArea = 0;

            while (thirdIndex < points.Length)
            {
                var area = SpatialUtility.CalculateTriangleSignedArea(points[firstIndex], points[secondIndex], points[thirdIndex]);

                var areaCheck2 = SpatialUtility.CalculateTriangleArea(points[firstIndex], points[(int)((firstIndex + thirdIndex) / 2.0)], points[thirdIndex]);

                tempArea += area;

                if (Math.Abs(tempArea) > threshold || areaCheck2 > threshold || (area * totalAreaCoef > 0))
                {
                    tempArea = 0;

                    filtered.Add(secondIndex);

                    firstIndex = secondIndex;
                }

                secondIndex = thirdIndex;

                thirdIndex = thirdIndex + 1;
            }

            if (filtered.Count == 1)
            {
                filtered.Add(points.Count() / 2);
            }

            filtered.Add(points.Length - 1);

            var output1 = filtered.Select(i => points[i]).ToArray();

            //if (!output1[0].Equals(output1[output1.Length - 1]))
            //{

            //}
            return(output1);
        }
예제 #2
0
        public static IPoint[] AdditiveSimplifyByArea(IPoint[] points, double threshold)
        {
            if (points == null || points.Length == 0)
            {
                return(null);
            }
            else if (points.Length == 2)
            {
                return(points);
            }

            List <int> filtered = new List <int>();

            filtered.Add(0);

            int firstIndex = 0, secondIndex = 1, thirdIndex = 2;

            double tempArea = 0;

            while (thirdIndex < points.Length)
            {
                var area = SpatialUtility.CalculateTriangleSignedArea(points[firstIndex], points[secondIndex], points[thirdIndex]);

                tempArea += area;

                if (Math.Abs(tempArea) > threshold)
                {
                    tempArea = 0;

                    filtered.Add(secondIndex);

                    firstIndex = secondIndex;
                }

                secondIndex = thirdIndex;

                thirdIndex = thirdIndex + 1;
            }

            if (filtered.Count == 1)
            {
                filtered.Add(points.Count() / 2);
            }

            filtered.Add(points.Length - 1);

            var output1 = filtered.Select(i => points[i]).ToArray();

            return(output1);
        }