Esempio n. 1
0
        private static void Reduce_RecursiveComponent(Point3d[] p, bool[] vertexMap, double tolerance, int a, int b)
        {
            // Abort if there is nothing left to collapse.
            if (b <= (a + 1))
            {
                return;
            }

            // Create basis segment.E
            Line segment = new Line(p[a], p[b]);

            double maxDeviation = 0.0;
            int    maxIndex     = a;

            // Iterate over remaining points in subset and find furthest point.
            for (int i = a + 1; i < b; i++)
            {
                double localDeviation = segment.MinimumDistanceTo(p[i]);
                if (localDeviation > maxDeviation)
                {
                    maxDeviation = localDeviation;
                    maxIndex     = i;
                }
            }

            if (maxDeviation > tolerance)
            {
                vertexMap[maxIndex] = true;
                Reduce_RecursiveComponent(p, vertexMap, tolerance, a, maxIndex);
                Reduce_RecursiveComponent(p, vertexMap, tolerance, maxIndex, b);
            }
        }
        private static void Reduce_RecursiveComponent(Point3d[] P, bool[] vertex_map, double tolerance, int A, int B)
        {
            //Abort if there is nothing left to collapse.
            if (B <= (A + 1))
            {
                return;
            }

            // Create basis segment.E
            Line segment = new Line(P[A], P[B]);

            double max_d = 0.0;
            int    max_i = A;

            // Iterate over remaining points in subset and find furthest point.
            for (int i = A + 1; i < B; i++)
            {
                double loc_d = segment.MinimumDistanceTo(P[i]);
                if (loc_d > max_d)
                {
                    max_d = loc_d;
                    max_i = i;
                }
            }

            if (max_d > tolerance)
            {
                vertex_map[max_i] = true;

                Reduce_RecursiveComponent(P, vertex_map, tolerance, A, max_i);
                Reduce_RecursiveComponent(P, vertex_map, tolerance, max_i, B);
            }
        }