Пример #1
0
        public void Remesh(ref Mesh mesh, IProgressListener progress = null)
        {
            var triangles = mesh.Triangles;
            var vertices = mesh.Vertices;

            // Compute K matrices for initial triangles.
            foreach (var t in triangles)
            {
                t.UpdateGeometricData();
                t.Tag = new ErrorMetric(t);
            }

            // Compute Q for intiial vertices.
            foreach (var v in vertices)
            {
                ComputeErrorMetricForVertex(v);
            }

            // Compute initial edge QEM-s
            foreach (var t in triangles)
            {
                ComputeErrorMetricForEdges(t);
            }

            foreach (var t in triangles)
            {
                ComputeEdgeCost(t);
            }

            // Compute number of triangles after we stop
            int toRemove = (int)((m_Removed) * triangles.Count);
            int triangleLimit = triangles.Count - toRemove;

#if TRACE_NANS
            int nansCount = 0;
#endif
            int index = 0;
            while (triangleLimit < triangles.Count)
            {
                Vertex v1, v2;
                Triangle.Edge edge;
                if (SearchBestCandidate(ref mesh, out v1, out v2, out edge))
                {
                    if (edge != null)
                    {

                        ErrorMetric em = (ErrorMetric)edge.Tag;
                        Vector3 v = em.ProposedPoint;
#if false
                        if (v.IsNaN())
                        {
#if TRACE_NANS
                            ++nansCount;
#endif
                            v = Vector3Extension.Mean(v1.Position, v2.Position);
                        }
#endif
                        if (mesh.JoinVertices(v1, v2, v))
                        {
                            // V1, since v2 is removed from now.
                            UpdateVertexNeighbors(v1);
                        }

                        progress.OnProgress(index, toRemove);
                        index += 2;
                    }
                    else
                    {
                        Trace.WriteLine("If you see this message more than once per second, I can't find any matching edge");
                    }
                }

            }

#if TRACE_NANS
            Trace.WriteLine(string.Format("NaNs count: {0}", nansCount));
#endif

        }
Пример #2
0
        public void Remesh(ref Mesh mesh, IProgressListener progress = null)
        {
            var triangles = mesh.Triangles;
            var vertices  = mesh.Vertices;

            // Compute K matrices for initial triangles.
            foreach (var t in triangles)
            {
                t.UpdateGeometricData();
                t.Tag = new ErrorMetric(t);
            }

            // Compute Q for intiial vertices.
            foreach (var v in vertices)
            {
                ComputeErrorMetricForVertex(v);
            }

            // Compute initial edge QEM-s
            foreach (var t in triangles)
            {
                ComputeErrorMetricForEdges(t);
            }

            foreach (var t in triangles)
            {
                ComputeEdgeCost(t);
            }

            foreach (var v in vertices)
            {
                v.Cost = 0.0;
                foreach (var t in v.Triangles)
                {
                    v.Cost += Math.Max(Math.Max(t.Edge12.Cost, t.Edge23.Cost), t.Edge31.Cost);
                }
            }

            // Compute number of triangles after we stop
            int toRemove      = (int)((m_Removed) * triangles.Count);
            int triangleLimit = triangles.Count - toRemove;

#if TRACE_NANS
            int nansCount = 0;
#endif
            int index = 0;
            for (int i = 0; (i < m_Removed) && (2 * m_Removed < triangles.Count); i += 2)
            {
                Vertex        v1, v2;
                Triangle.Edge edge;
                if (SearchBestCandidate(ref mesh, out v1, out v2, out edge))
                {
                    if (edge != null)
                    {
                        ErrorMetric em = (ErrorMetric)edge.Tag;
                        Vector3     v  = em.ProposedPoint;
#if false
                        if (v.IsNaN())
                        {
#if TRACE_NANS
                            ++nansCount;
#endif
                            v = Vector3Extension.Mean(v1.Position, v2.Position);
                        }
#endif
                        if (mesh.JoinVertices(v1, v2, v))
                        {
                            // V1, since v2 is removed from now.
                            UpdateVertexNeighbors(v1);
                        }

                        progress.OnProgress(index, toRemove);
                        index += 2;
                    }
                    else
                    {
                        Trace.WriteLine("If you see this message more than once per second, I can't find any matching edge");
                    }
                }
            }

#if TRACE_NANS
            Trace.WriteLine(string.Format("NaNs count: {0}", nansCount));
#endif
        }