Exemple #1
0
        /// <summary>
        /// Marks all edges and nodes of this graph and returns the result as an array of Guids
        /// </summary>
        /// <returns>The resulting array of Guids</returns>
        public static Guid[] Mark(CurvesTopology top, Color verticesColor, Color edgesColor)
        {
            Guid[]           dots = new Guid[top.VertexLength + top.EdgeLength];
            ObjectAttributes oa   = RhinoDoc.ActiveDoc.CreateDefaultAttributes();

            oa.ColorSource = ObjectColorSource.ColorFromObject;

            //Graph vertices color
            oa.ObjectColor = verticesColor;
            for (int i = 0; i < top.VertexLength; i++)
            {
                dots[i] = RhinoDoc.ActiveDoc.Objects.AddTextDot(i.ToString(), top.VertexAt(i), oa);
                var sette = top.VertexAt(i);
            }

            //Graph edges
            oa.ObjectColor = edgesColor;
            for (int i = 0; i < top.EdgeLength; i++)
            {
                var p = top.CurveAt(i).PointAtNormalizedLength(0.5);
                dots[i + top.VertexLength] = RhinoDoc.ActiveDoc.Objects.AddTextDot(i.ToString(), p, oa);
            }

            RhinoDoc.ActiveDoc.Views.Redraw();
            return(dots);
        }
Exemple #2
0
        protected Curve ReconstructPath(int[] cameFrom, int currentNode, out int[] nodes, out int[] edges, out bool[] edgeDir, out double totLength)
        {
            List <int> resultNodes = new List <int>();

            for (; ;)
            {
                if (currentNode == -1)
                {
                    break;
                }
                resultNodes.Add(currentNode);
                currentNode = cameFrom[currentNode];
            }
            resultNodes.Reverse();
            nodes = resultNodes.ToArray();

            List <int>  resultEdges    = new List <int>();
            List <bool> resultEdgesRev = new List <bool>();

            currentNode = nodes[0];
            for (int i = 1; i < nodes.Length; i++)
            {
                int  nxt = nodes[i];
                bool rev;
                int  edgeIndex = FindEdge(currentNode, nxt, out rev);
                resultEdges.Add(edgeIndex);
                resultEdgesRev.Add(rev);
                currentNode = nxt;
            }
            edges   = resultEdges.ToArray();
            edgeDir = resultEdgesRev.ToArray();

            totLength = 0;
            PolyCurve pc = new PolyCurve();

            for (int i = 0; i < resultEdges.Count; i++)
            {
                int ei = resultEdges[i];
                var cv = m_top.CurveAt(ei).DuplicateCurve();
                if (!resultEdgesRev[i])
                {
                    cv.Reverse();
                }
                pc.Append(cv);
                totLength += m_dist[ei];
            }
            pc.RemoveNesting();

            return(pc);
        }