コード例 #1
0
ファイル: QuadricErrorMetric.cs プロジェクト: gxmc/terremesh
        public static ErrorMetric operator -(ErrorMetric e1, ErrorMetric e2)
        {
            ErrorMetric result = new ErrorMetric();

            result.m_Matrix = e1.m_Matrix - e2.m_Matrix;
            return(result);
        }
コード例 #2
0
ファイル: QuadricErrorMetric.cs プロジェクト: gxmc/terremesh
        private double ComputeError(int id1, int id2, out Vector3 error)
        {
            ErrorMetric edge  = ErrorMetric.Empty;
            ErrorMetric delta = ErrorMetric.Empty;

            Vector3 vertex = new Vector3();

            edge = m_Quadrics[id1] + m_Quadrics[id2];

            delta = edge;
            Matrix m = delta.Matrix;

            {
                m.M41 = 0.0f;
                m.M42 = 0.0f;
                m.M43 = 0.0f;
                m.M44 = 1.0f;
            }
            delta.Matrix = m;

            double minError = 0.0;

            if (Math.Abs(delta.Matrix.Determinant()) <= 1e-5)
            {
                Vector3 v1 = m_Vertices[id1].Position;
                Vector3 v2 = m_Vertices[id2].Position;
                Vector3 v3 = Vector3Extension.Mean(v1, v2);

                double e1 = edge.Evaluate(v1);
                double e2 = edge.Evaluate(v2);
                double e3 = edge.Evaluate(v3);

                minError = Math.Min(Math.Min(e1, e2), e3);

                if (minError == e1)
                {
                    vertex = v1;
                }
                else if (minError == e2)
                {
                    vertex = v2;
                }
                else if (minError == e3)
                {
                    vertex = v3;
                }
            }
            else
            {
                double det = (double)delta.Matrix.IndexedDeterminant(0, 1, 2, 4, 5, 6, 8, 9, 10);
                vertex.X = (float)(-1.0 / det * (delta.Matrix.IndexedDeterminant(1, 2, 3, 5, 6, 7, 9, 10, 11)));
                vertex.Y = (float)(1.0 / det * (delta.Matrix.IndexedDeterminant(0, 2, 3, 4, 6, 7, 8, 10, 11)));
                vertex.Z = (float)(-1.0 / det * (delta.Matrix.IndexedDeterminant(0, 1, 3, 4, 5, 7, 8, 9, 11)));
            }

            error    = vertex;
            minError = edge.Evaluate(vertex);
            return(minError);
        }