Пример #1
0
        /// <summary>
        /// construct EdgeSpan from a list of edges of mesh
        /// </summary>
        public static EdgeSpan FromEdges(DMesh3 mesh, IList <int> edges)
        {
            int[] Edges = new int[edges.Count];
            for (int i = 0; i < Edges.Length; ++i)
            {
                Edges[i] = edges[i];
            }
            int[]   Vertices = new int[Edges.Length + 1];
            Index2i start_ev = mesh.GetEdgeV(Edges[0]);
            Index2i prev_ev  = start_ev;

            if (Edges.Length > 1)
            {
                for (int i = 1; i < Edges.Length; ++i)
                {
                    Index2i next_ev = mesh.GetEdgeV(Edges[i]);
                    Vertices[i] = IndexUtil.find_shared_edge_v(ref prev_ev, ref next_ev);
                    prev_ev     = next_ev;
                }
                Vertices[0] = IndexUtil.find_edge_other_v(ref start_ev, Vertices[1]);
                Vertices[Vertices.Length - 1] = IndexUtil.find_edge_other_v(prev_ev, Vertices[Vertices.Length - 2]);
            }
            else
            {
                Vertices[0] = start_ev[0]; Vertices[1] = start_ev[1];
            }
            return(new EdgeSpan(mesh, Vertices, Edges, false));
        }
Пример #2
0
        /// <summary>
        /// construct EdgeLoop from a list of edges of mesh
        /// </summary>
        public static EdgeLoop FromEdges(DMesh3 mesh, IList <int> edges)
        {
            int[] Edges = new int[edges.Count];
            for (int i = 0; i < Edges.Length; ++i)
            {
                Edges[i] = edges[i];
            }

            int[]   Vertices = new int[Edges.Length];
            Index2i start_ev = mesh.GetEdgeV(Edges[0]);
            Index2i prev_ev  = start_ev;

            for (int i = 1; i < Edges.Length; ++i)
            {
                Index2i next_ev = mesh.GetEdgeV(Edges[i % Edges.Length]);
                Vertices[i] = IndexUtil.find_shared_edge_v(ref prev_ev, ref next_ev);
                prev_ev     = next_ev;
            }
            Vertices[0] = IndexUtil.find_edge_other_v(ref start_ev, Vertices[1]);
            return(new EdgeLoop(mesh, Vertices, Edges, false));
        }
        static List <int> walk_edge_span_forward(DMesh3 mesh, int start_edge, int start_pivot_v, HashSet <int> EdgeSet, out bool bClosedLoop)
        {
            bClosedLoop = false;

            List <int> edgeSpan = new List <int>();

            edgeSpan.Add(start_edge);

            // we update this as we step
            //int cur_edge = start_edge;
            int cur_pivot_v  = start_pivot_v;
            int stop_pivot_v = IndexUtil.find_edge_other_v(mesh.GetEdgeV(start_edge), start_pivot_v);

            Util.gDevAssert(stop_pivot_v != DMesh3.InvalidID);

            bool done = false;

            while (!done)
            {
                // find outgoing edge in set and connected to current pivot vtx
                int next_edge = -1;
                foreach (int nbr_edge in mesh.VtxEdgesItr(cur_pivot_v))
                {
                    if (EdgeSet.Contains(nbr_edge))
                    {
                        next_edge = nbr_edge;
                        break;
                    }
                }

                // could not find - must be done span
                if (next_edge == -1)
                {
                    done = true;
                    break;
                }

                // figure out next pivot vtx (is 'other' from current pivot on next edge)
                Index2i next_edge_v = mesh.GetEdgeV(next_edge);
                if (next_edge_v.a == cur_pivot_v)
                {
                    cur_pivot_v = next_edge_v.b;
                }
                else if (next_edge_v.b == cur_pivot_v)
                {
                    cur_pivot_v = next_edge_v.a;
                }
                else
                {
                    throw new Exception("walk_edge_span_forward: found valid next edge but not connected to previous vertex??");
                }

                edgeSpan.Add(next_edge);
                EdgeSet.Remove(next_edge);

                // if this happens, we closed a loop
                if (cur_pivot_v == stop_pivot_v)
                {
                    done        = true;
                    bClosedLoop = true;
                }
            }

            return(edgeSpan);
        }