Exemple #1
0
        /// <summary>
        /// Optimizes edge target.
        /// </summary>
        /// <param name="v1">The source edge vertex.</param>
        /// <param name="v2">The target edge vertex.</param>
        /// <param name="edge">The edge additional params.</param>
        /// <param name="policy">The used policy.</param>
        private void OptimizeEdgeTarget(ref Vertex v1, ref Vertex v2, ref Triangle.Edge edge, WeightPolicy policy)
        {
            ErrorMetric Q = (ErrorMetric)edge.Tag;

            double  min_cost = double.MaxValue;
            Vector3 best;

            if (policy.HasFlag(WeightPolicy.Optmized) && Q.Optimize(out best))
            {
                Q.ProposedPoint = best;
                min_cost        = Q.VertexError(best);
            }
            else
            {
                double min1 = Q.VertexError(v1.Position);
                double min2 = Q.VertexError(v2.Position);

                if (min1 < min2)
                {
                    min_cost = min1;
                    best     = v1.Position;
                }
                else
                {
                    min_cost = min2;
                    best     = v2.Position;
                }

                if (policy.HasFlag(WeightPolicy.MiddlePoint))
                {
                    Vector3 middle      = Vector3Extension.Mean(v1.Position, v2.Position);
                    double  cost_middle = Q.VertexError(middle);

                    if (cost_middle < min_cost)
                    {
                        min_cost = cost_middle;
                        best     = middle;
                    }
                }
            }

            if (policy.HasFlag(WeightPolicy.AverageTriangleArea))
            {
                min_cost /= Q.Area;
            }

            edge.Cost       = -min_cost;
            Q.ProposedPoint = best;
            edge.Tag        = (object)Q;
        }
        /// <summary>
        /// Optimizes edge target.
        /// </summary>
        /// <param name="v1">The source edge vertex.</param>
        /// <param name="v2">The target edge vertex.</param>
        /// <param name="edge">The edge additional params.</param>
        /// <param name="policy">The used policy.</param>
        private void OptimizeEdgeTarget(ref Vertex v1, ref Vertex v2, ref Triangle.Edge edge, WeightPolicy policy)
        {
            ErrorMetric Q = (ErrorMetric)edge.Tag;
         
            double min_cost = 0.0;
            Vector3 best;

            if (policy.HasFlag(WeightPolicy.Optmized) && Q.Optimize(out best))
            {
                best = Q.ProposedPoint;
                min_cost = Q.Evaluate(best);
            }
            else
            {
                double min1 = Q.Evaluate(v1.Position);
                double min2 = Q.Evaluate(v2.Position);

                if (min1 < min2)
                {
                    min_cost = min1;
                    best = v1.Position;
                }
                else
                {
                    min_cost = min2;
                    best = v2.Position;
                }

                if (policy.HasFlag(WeightPolicy.MiddlePoint))
                {
                    Vector3 middle = Vector3Extension.Mean(v1.Position, v2.Position);
                    double cost_middle = Q.Evaluate(middle);

                    if (cost_middle < min_cost)
                    {
                        min_cost = cost_middle;
                        best = middle;
                    }
                }
            }

            if (policy.HasFlag(WeightPolicy.AverageTriangleArea))
            {
                min_cost /= Q.Area;
            }

            edge.Cost = 1.0/min_cost;
            Q.ProposedPoint = best;
            edge.Tag = (object)Q;
        }