Пример #1
0
        private float ComputeLeastSquares(Vec4 alphax_sum, Vec4 betax_sum, Vec4 alphabeta_sum, out Vec4 a, out Vec4 b)
        {
            Vec4 alpha2_sum = alphax_sum.SplatW();
            Vec4 beta2_sum  = betax_sum.SplatW();

            // compute the least-squares optimal points
            Vec4 factor = alphabeta_sum.NegativeMultiplySubtract(alphabeta_sum, alpha2_sum * beta2_sum).Reciprocal();

            a = betax_sum.NegativeMultiplySubtract(alphabeta_sum, alphax_sum * beta2_sum) * factor;
            b = alphax_sum.NegativeMultiplySubtract(alphabeta_sum, betax_sum * alpha2_sum) * factor;

            // clamp to the grid
            a = a.Clamp(Vec4.Zero, Vec4.One);
            b = b.Clamp(Vec4.Zero, Vec4.One);
            a = GRID.MultiplyAdd(a, HALF).Truncate() * GRIDRCP;
            b = GRID.MultiplyAdd(b, HALF).Truncate() * GRIDRCP;

            // compute the error (we skip the constant xxsum)
            Vec4 e1 = (a * a * alpha2_sum) + (b * b * beta2_sum);
            Vec4 e2 = a.NegativeMultiplySubtract(alphax_sum, a * b * alphabeta_sum);
            Vec4 e3 = b.NegativeMultiplySubtract(betax_sum, e2);
            Vec4 e4 = e3 * 2 + e1;

            // apply the metric to the error term
            Vec4 e5 = e4 * m_metric;

            return(e5.X + e5.Y + e5.Z);
        }