コード例 #1
0
 public Network INetwork()
 {
     PolarNetwork network = new PolarNetwork();
     network.Initialize( (int)numRings.Value,
                         (float)innerRadius.Value,
                         (float)ringWidth.Value,
                         (float)spokeWidth.Value,
                         (float)ringWeighting.Value,
                         (float)weavePercent.Value);
     return network;
 }
コード例 #2
0
        public Network INetwork()
        {
            PolarNetwork network = new PolarNetwork();

            network.Initialize((int)numRings.Value,
                               (float)innerRadius.Value,
                               (float)ringWidth.Value,
                               (float)spokeWidth.Value,
                               (float)ringWeighting.Value,
                               (float)weavePercent.Value);
            return(network);
        }
コード例 #3
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="network"></param>
        protected void RenderPolarNetwork(PolarNetwork network)
        {
            worldOffset.X = network.Radius;
            worldOffset.Y = network.Radius;

            bmp = new Bitmap(1 + ((int)(Math.Ceiling(network.Diameter * worldScale))),
                             1 + ((int)(Math.Ceiling(network.Diameter * worldScale))));

            Graphics g = Graphics.FromImage(bmp);
            g.Clear(colBackground);

            g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

            Pen penWall = new Pen(colWall, worldScale * (corridorWidth + wallWidth));
            Pen penCorridor = new Pen(colCorridor, worldScale * (corridorWidth));
            //SolidBrush br = new SolidBrush(Color.Red);

            List<NodeLink> renderedLinks = new List<NodeLink>();

            foreach (Node node in network.nodeDict.Keys)
            {
                PolarNode pn = (PolarNode)node;

                PointF ptA = pn.Point;
                LocalToWorld(ref ptA);
                DrawCircle(g, ptA, worldScale * (((Math.Max(pn.size, corridorWidth) + wallWidth) * 0.5f)), penWall.Color);
            }

            foreach (List<NodeLink> linkList in network.nodeDict.Values)
            {
                foreach (NodeLink link in linkList)
                {
                    if (!renderedLinks.Contains(link))
                    {
                        if (link.visited)
                        {
                            if (link.a != null && link.b != null)
                            {
                                PolarNode nodeA = (PolarNode)link.a;
                                PolarNode nodeB = (PolarNode)link.b;
                                PointF ptA = nodeA.Point;
                                PointF ptB = nodeB.Point;
                                LocalToWorld(ref ptA);
                                LocalToWorld(ref ptB);

                                float minNodeSize = Math.Min(nodeA.size, nodeB.size);

                                penWall.Width = worldScale * (corridorWidth + minNodeSize  + wallWidth);
                                penCorridor.Width = worldScale * (corridorWidth + minNodeSize);
                                g.DrawLine(penWall, ptA, ptB);
                                g.DrawLine(penCorridor, ptA, ptB);

                                renderedLinks.Add(link);
                            }
                        }

                    }
                }

            }

            // Clean up any path overlap
            foreach (NodeLink link in renderedLinks)
            {
                PolarNode nodeA = (PolarNode)link.a;
                PolarNode nodeB = (PolarNode)link.b;
                PointF ptA = nodeA.Point;
                PointF ptB = nodeB.Point;

                Vector2D vA = new Vector2D(ptA, ptB);
                vA = vA.Normalized();
                vA.Scale(((Math.Max(nodeA.size, corridorWidth)) * 0.5f) + wallWidth);

                Vector2D vB = new Vector2D(ptB, ptA);
                vB = vB.Normalized();
                vB.Scale(((Math.Max(nodeB.size, corridorWidth)) * 0.5f) + wallWidth);

                PointF ptA2 = nodeA.Point;
                ptA2.X += vA.b.X;
                ptA2.Y += vA.b.Y;

                PointF ptB2 = nodeB.Point;
                ptB2.X += vB.b.X;
                ptB2.Y += vB.b.Y;

                LocalToWorld(ref ptA);
                LocalToWorld(ref ptA2);
                LocalToWorld(ref ptB);
                LocalToWorld(ref ptB2);

                float minNodeSize = Math.Min(nodeA.size, nodeB.size);

                penCorridor.Width = worldScale * (corridorWidth + minNodeSize);
                g.DrawLine(penCorridor, ptA, ptA2);
                g.DrawLine(penCorridor, ptB, ptB2);
            }

            //penCorridor.Color = Color.Red; // for debug - Highlights all rendered nodes
            foreach (Node node in network.nodeDict.Keys)
            {
                PolarNode pn = (PolarNode)node;

                PointF ptA = pn.Point;
                LocalToWorld(ref ptA);
                DrawCircle(g, ptA, worldScale * (Math.Max(pn.size, corridorWidth) * 0.5f), penCorridor.Color);
            }
        }