public static ErrorMetric operator -(ErrorMetric e1, ErrorMetric e2) { ErrorMetric result = new ErrorMetric(); result.m_Matrix = e1.m_Matrix - e2.m_Matrix; return(result); }
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); }
public static ErrorMetric operator + (ErrorMetric e1, ErrorMetric e2) { ErrorMetric result = new ErrorMetric(); result.m_Matrix = e1.m_Matrix + e2.m_Matrix; return result; }
private void ComputeInitialQuadrics() { for (int i = 0; i < m_Vertices.Count; ++i) { m_Quadrics.Add(i + 1, ErrorMetric.Empty); } for (int i = 0; i < m_Faces.Count; ++i) { for (int j = 0; j < 3; ++j) { var face = m_Faces.ElementAt(i); var index = face[j]; #if DEBUG if (!m_Quadrics.ContainsKey(index)) { System.Diagnostics.Debug.WriteLine("Failed {0}", index); } #endif m_Quadrics[index] += new ErrorMetric(face.Plane); } } }