Exemplo n.º 1
0
        public int AppendEdge(Index2i ev, int gid = -1)
        {
            if (IsVertex(ev[0]) == false || IsVertex(ev[1]) == false)
            {
                Util.gDevAssert(false);
                return(InvalidID);
            }
            if (ev[0] == ev[1])
            {
                Util.gDevAssert(false);
                return(InvalidID);
            }
            int e0 = FindEdge(ev[0], ev[1]);

            if (e0 != InvalidID)
            {
                return(DuplicateEdgeID);
            }

            // increment ref counts and update/create edges
            vertices_refcount.increment(ev[0]);
            vertices_refcount.increment(ev[1]);
            max_group_id = Math.Max(max_group_id, gid + 1);

            // now safe to insert edge
            int eid = add_edge(ev[0], ev[1], gid);

            updateTimeStamp(true);
            return(eid);
        }
Exemplo n.º 2
0
        public int AppendTriangle(Index3i tv, int gid = -1)
        {
            if (IsVertex(tv[0]) == false || IsVertex(tv[1]) == false || IsVertex(tv[2]) == false)
            {
                Util.gDevAssert(false);
                return(InvalidID);
            }
            if (tv[0] == tv[1] || tv[0] == tv[2] || tv[1] == tv[2])
            {
                Util.gDevAssert(false);
                return(InvalidID);
            }

            // look up edges. if any already have two triangles, this would
            // create non-manifold geometry and so we do not allow it
            int e0 = find_edge(tv[0], tv[1]);
            int e1 = find_edge(tv[1], tv[2]);
            int e2 = find_edge(tv[2], tv[0]);

            if ((e0 != InvalidID && edge_is_boundary(e0) == false) ||
                (e1 != InvalidID && edge_is_boundary(e1) == false) ||
                (e2 != InvalidID && edge_is_boundary(e2) == false))
            {
                return(NonManifoldID);
            }

            // now safe to insert triangle
            int tid = triangles_refcount.allocate();
            int i   = 3 * tid;

            triangles.insert(tv[2], i + 2);
            triangles.insert(tv[1], i + 1);
            triangles.insert(tv[0], i);
            if (triangle_groups != null)
            {
                triangle_groups.insert(gid, tid);
            }

            // increment ref counts and update/create edges
            vertices_refcount.increment(tv[0]);
            vertices_refcount.increment(tv[1]);
            vertices_refcount.increment(tv[2]);

            add_tri_edge(tid, tv[0], tv[1], 0, e0);
            add_tri_edge(tid, tv[1], tv[2], 1, e1);
            add_tri_edge(tid, tv[2], tv[0], 2, e2);

            updateTimeStamp();
            return(tid);
        }