예제 #1
0
        public MeshResult RemoveEdge(int eID, bool bRemoveIsolatedVertices)
        {
            if (!edges_refcount.isValid(eID))
            {
                Util.gDevAssert(false);
                return(MeshResult.Failed_NotAnEdge);
            }

            int i  = 3 * eID;
            var ev = new Index2i(edges[i], edges[i + 1]);

            vertex_edges[ev.a].Remove(eID);
            vertex_edges[ev.b].Remove(eID);

            edges_refcount.decrement(eID);

            // Decrement vertex refcounts. If any hit 1 and we got remove-isolated flag,
            // we need to remove that vertex
            for (int j = 0; j < 2; ++j)
            {
                int vid = ev[j];
                vertices_refcount.decrement(vid);
                if (bRemoveIsolatedVertices && vertices_refcount.refCount(vid) == 1)
                {
                    vertices_refcount.decrement(vid);
                    Util.gDevAssert(vertices_refcount.isValid(vid) == false);
                    vertex_edges[vid] = null;
                }
            }

            updateTimeStamp(true);
            return(MeshResult.Ok);
        }
예제 #2
0
        /// <summary>
        // This function checks that the graph is well-formed, ie all internal data
        // structures are consistent
        /// </summary>
        public virtual bool CheckValidity(FailMode eFailMode = FailMode.Throw)
        {
            bool          is_ok        = true;
            Action <bool> CheckOrFailF = (b) =>
            {
                is_ok = is_ok && b;
            };

            if (eFailMode == FailMode.DebugAssert)
            {
                CheckOrFailF = (b) =>
                {
                    Debug.Assert(b);
                    is_ok = is_ok && b;
                };
            }
            else if (eFailMode == FailMode.gDevAssert)
            {
                CheckOrFailF = (b) =>
                {
                    Util.gDevAssert(b);
                    is_ok = is_ok && b;
                };
            }
            else if (eFailMode == FailMode.Throw)
            {
                CheckOrFailF = (b) =>
                {
                    if (b == false)
                    {
                        throw new Exception("DGraph3.CheckValidity: check failed");
                    }
                };
            }

            // edge verts/tris must exist
            foreach (int eID in EdgeIndices())
            {
                CheckOrFailF(IsEdge(eID));
                CheckOrFailF(edges_refcount.refCount(eID) == 1);
                Index2i ev = GetEdgeV(eID);
                CheckOrFailF(IsVertex(ev[0]));
                CheckOrFailF(IsVertex(ev[1]));
                CheckOrFailF(ev[0] < ev[1]);
            }

            // verify compact check
            bool is_compact = vertices_refcount.is_dense;

            if (is_compact)
            {
                for (int vid = 0; vid < VertexCount; ++vid)
                {
                    CheckOrFailF(vertices_refcount.isValid(vid));
                }
            }

            // vertex edges must exist and reference this vert
            foreach (int vID in VertexIndices())
            {
                CheckOrFailF(IsVertex(vID));

                //Vector3d v = GetVertex(vID);
                //CheckOrFailF(double.IsNaN(v.LengthSquared) == false);
                //CheckOrFailF(double.IsInfinity(v.LengthSquared) == false);

                List <int> l = vertex_edges[vID];
                foreach (int edgeid in l)
                {
                    CheckOrFailF(IsEdge(edgeid));
                    CheckOrFailF(edge_has_v(edgeid, vID));

                    int otherV = edge_other_v(edgeid, vID);
                    int e2     = FindEdge(vID, otherV);
                    CheckOrFailF(e2 != InvalidID);
                    CheckOrFailF(e2 == edgeid);
                    e2 = FindEdge(otherV, vID);
                    CheckOrFailF(e2 != InvalidID);
                    CheckOrFailF(e2 == edgeid);
                }

                CheckOrFailF(vertices_refcount.refCount(vID) == l.Count + 1);
            }

            subclass_validity_checks(CheckOrFailF);

            return(is_ok);
        }