Exemplo n.º 1
0
        // Update triangle connections and edge error after a edge is collapsed

        void update_triangles(int i0, MSVertex v, List <int> deleted, ref int deleted_triangles)
        {
            Vector3 p = Vector3.Zero;

            for (int k = 0; k < v.tcount; k++)
            {
                var r = refs[v.tstart + k];
                var t = triangles[r.tid];
                if (t.deleted)
                {
                    continue;
                }
                if (k < deleted.Count && deleted[k] > 0)
                {
                    t.deleted = true;
                    deleted_triangles++;
                    continue;
                }
                t.v[r.tvertex] = i0;
                t.dirty        = true;
                t.err[0]       = calculate_error(t.v[0], t.v[1], ref p);
                t.err[1]       = calculate_error(t.v[1], t.v[2], ref p);
                t.err[2]       = calculate_error(t.v[2], t.v[0], ref p);
                t.err[3]       = Math.Min(t.err[0], Math.Min(t.err[1], t.err[2]));
                refs.Add(r);
            }
        }
Exemplo n.º 2
0
        // Check if a triangle flips when this edge is removed

        bool flipped(Vector3 p, int i0, int i1, MSVertex v0, MSVertex v1, List <int> deleted)
        {
            int bordercount = 0;

            for (int k = 0; k < v0.tcount; k++)
            {
                var t = triangles[refs[v0.tstart + k].tid];
                if (t.deleted)
                {
                    continue;
                }

                int s   = refs[v0.tstart + k].tvertex;
                int id1 = t.v[(s + 1) % 3];
                int id2 = t.v[(s + 2) % 3];

                if (id1 == i1 || id2 == i1) // delete ?
                {
                    bordercount++;
                    deleted[k] = 1;
                    continue;
                }
                Vector3 d1 = vertices[id1].p - p; d1.Normalize();
                Vector3 d2 = vertices[id2].p - p; d2.Normalize();
                if (Math.Abs(Vector3.Dot(d1, d2)) > 0.999)
                {
                    return(true);
                }
                Vector3 n;
                n = Vector3.Cross(d1, d2);
                n.Normalize();
                deleted[k] = 0;
                if (Vector3.Dot(n, t.n) < 0.2)
                {
                    return(true);
                }
            }
            return(false);
        }