Пример #1
0
        private static void DrawEdge(XGraphics g, Edge e, LayoutProvider layout, NetworkColorizer colorizer)
        {
            Vector3 p1 = layout.GetPositionOfNode(e.Source);
            Vector3 p2 = layout.GetPositionOfNode(e.Target);

            g.DrawLine(new Pen(colorizer[e], 0.05f), p1.X, p1.Y, p2.X, p2.Y);
        }
Пример #2
0
        internal NetworkVisualizer(Network network, LayoutProvider layout, NetworkColorizer colorizer, int width, int height)
            : base(width, height, OpenTK.Graphics.GraphicsMode.Default, "NETGen Display")
        {
            Keyboard.KeyDown += new EventHandler<KeyboardKeyEventArgs>(Keyboard_KeyDown);
            Mouse.ButtonDown += new EventHandler<MouseButtonEventArgs>(Mouse_ButtonDown);
            Mouse.ButtonUp += new EventHandler<MouseButtonEventArgs>(Mouse_ButtonUp);
            Mouse.Move += new EventHandler<MouseMoveEventArgs>(Mouse_Move);
            Mouse.WheelChanged += new EventHandler<MouseWheelEventArgs>(Mouse_WheelChanged);

            ComputeNodeSize = new Func<Vertex, float>(v => {
                return 2f;
            });

            ComputeEdgeWidth = new Func<Edge, float>( e => {
                return 0.05f;
            });
            _network = network;

            _layout = layout;
            _layout.Init(Width, Height, network);

            if (colorizer == null)
                _colorizer = new NetworkColorizer();
            else
                _colorizer = colorizer;
        }
Пример #3
0
        internal NetworkVisualizer(Network network, LayoutProvider layout, NetworkColorizer colorizer, int width, int height) : base(width, height, OpenTK.Graphics.GraphicsMode.Default, "NETGen Display")
        {
            Keyboard.KeyDown   += new EventHandler <KeyboardKeyEventArgs>(Keyboard_KeyDown);
            Mouse.ButtonDown   += new EventHandler <MouseButtonEventArgs>(Mouse_ButtonDown);
            Mouse.ButtonUp     += new EventHandler <MouseButtonEventArgs>(Mouse_ButtonUp);
            Mouse.Move         += new EventHandler <MouseMoveEventArgs>(Mouse_Move);
            Mouse.WheelChanged += new EventHandler <MouseWheelEventArgs>(Mouse_WheelChanged);

            ComputeNodeSize = new Func <Vertex, float>(v => {
                return(2f);
            });

            ComputeEdgeWidth = new Func <Edge, float>(e => {
                return(0.05f);
            });
            _network = network;

            _layout = layout;
            _layout.Init(Width, Height, network);

            if (colorizer == null)
            {
                _colorizer = new NetworkColorizer();
            }
            else
            {
                _colorizer = colorizer;
            }
        }
Пример #4
0
        private static void DrawEdge(XGraphics g, Edge e, LayoutProvider layout, NetworkColorizer colorizer)
        {
            Vector3 p1 = layout.GetPositionOfNode(e.Source);
            Vector3 p2 = layout.GetPositionOfNode(e.Target);

            float width = ComputeEdgeWidth(e);

            g.DrawLine(new Pen(colorizer[e], width), p1.X, p1.Y, p2.X, p2.Y);
        }
Пример #5
0
        private static void DrawVertex(XGraphics g, Vertex v, LayoutProvider layout, NetworkColorizer colorizer)
        {
            Vector3 p = layout.GetPositionOfNode(v);

            double size = Math.Min(2f, Math.Max(0.05d, Math.Log10(v.Degree)));

            if (!double.IsNaN(p.X) &&
               !double.IsNaN(p.Y) &&
               !double.IsNaN(p.Z))
                g.DrawEllipse(new SolidBrush(colorizer[v]), p.X - size/2d, p.Y - size/2d, size, size);
        }
Пример #6
0
        private static void DrawVertex(XGraphics g, Vertex v, LayoutProvider layout, NetworkColorizer colorizer)
        {
            Vector3 p = layout.GetPositionOfNode(v);

            double size = ComputeNodeSize(v);

            if (!double.IsNaN(p.X) &&
                !double.IsNaN(p.Y) &&
                !double.IsNaN(p.Z))
            {
                g.DrawEllipse(new SolidBrush(colorizer[v]), p.X - size / 2d, p.Y - size / 2d, size, size);
            }
        }
Пример #7
0
private static void Draw(XGraphics g, Network n, LayoutProvider layout, NetworkColorizer colorizer)
{
    lock (n)
            {
                if (g == null)
                    return;
                g.SmoothingMode = PdfSharp.Drawing.XSmoothingMode.HighQuality;
                g.Clear(Color.White);
                foreach (Edge e in n.Edges)
                        DrawEdge(g, e, layout, colorizer);
                foreach (Vertex v in n.Vertices)
                        DrawVertex(g, v, layout, colorizer);
            }
}
Пример #8
0
        /// <summary>
        /// Creates a new instance of a Networkvisualizer which renders the specified network in real-time
        /// </summary>
        /// <param name='n'>
        /// N.
        /// </param>
        /// <param name='layout'>
        /// Layout.
        /// </param>
        public static void Start(Network network, LayoutProvider layout, NetworkColorizer colorizer = null, int width = 800, int height = 600)
        {
            // The actual rendering needs to be done in a separate thread placed in the single thread appartment state
            _mainThread = new Thread(new ThreadStart(new Action(delegate() {
                Instance = new NetworkVisualizer(network, layout, colorizer, width, height);
                _initialized.Set();
                Instance.Run(80f);
            })));

            _mainThread.SetApartmentState(ApartmentState.STA);
            _mainThread.Name = "STA Thread for NETGen Visualizer";

            // Fire up the thread
            _mainThread.Start();
            _initialized.WaitOne();
        }
Пример #9
0
        public static void CreatePDF(string path, Network n, LayoutProvider layout, NetworkColorizer colorizer)
        {
            PdfSharp.Pdf.PdfDocument doc = new PdfDocument();
            doc.Info.Title = "Network";
            doc.Info.Subject = "Created by NETGen";

            PdfPage page = doc.AddPage();
            page.Size = PageSize.A4;
            page.Orientation = PageOrientation.Landscape;

            // Draw the network to the xgraphics object
            Draw(XGraphics.FromPdfPage(page), n, layout, colorizer);

            // Save the s_document...
            doc.Save(path);
        }
Пример #10
0
 private static void Draw(XGraphics g, Network n, LayoutProvider layout, NetworkColorizer colorizer)
 {
     lock (n)
     {
         if (g == null)
         {
             return;
         }
         g.SmoothingMode = PdfSharp.Drawing.XSmoothingMode.HighQuality;
         g.Clear(Color.White);
         foreach (Edge e in n.Edges)
         {
             DrawEdge(g, e, layout, colorizer);
         }
         foreach (Vertex v in n.Vertices)
         {
             DrawVertex(g, v, layout, colorizer);
         }
     }
 }
Пример #11
0
        public static void CreatePDF(string path, Network n, LayoutProvider layout, NetworkColorizer colorizer = null)
        {
            PdfSharp.Pdf.PdfDocument doc = new PdfDocument();
            doc.Info.Title   = "Network";
            doc.Info.Subject = "Created by NETGen";

            PdfPage page = doc.AddPage();

            page.Size        = PageSize.A4;
            page.Orientation = PageOrientation.Landscape;

            if (colorizer != null)
            {
                // Draw the network to the xgraphics object
                Draw(XGraphics.FromPdfPage(page), n, layout, colorizer);
            }
            else
            {
                Draw(XGraphics.FromPdfPage(page), n, layout, new NetworkColorizer());
            }

            // Save the s_document...
            doc.Save(path);
        }
Пример #12
0
        /// <summary>
        /// Creates a new instance of a Networkvisualizer which renders the specified network in real-time
        /// </summary>
        /// <param name='n'>
        /// N.
        /// </param>
        /// <param name='layout'>
        /// Layout.
        /// </param>
        public static void Start(Network network, LayoutProvider layout, NetworkColorizer colorizer = null, int width=800, int height=600)
        {
            // The actual rendering needs to be done in a separate thread placed in the single thread appartment state
            _mainThread = new Thread(new ThreadStart(new Action(delegate() {
                    Instance =  new NetworkVisualizer(network, layout, colorizer, width, height);
                    _initialized.Set();
                    Instance.Run(80f);
            })));

            _mainThread.SetApartmentState(ApartmentState.STA);
            _mainThread.Name = "STA Thread for NETGen Visualizer";

            // Fire up the thread
            _mainThread.Start();
            _initialized.WaitOne();
        }
Пример #13
0
private static void DrawVertex(XGraphics g, Vertex v, LayoutProvider layout, NetworkColorizer colorizer)
{
    Vector3 p = layout.GetPositionOfNode(v);

            double size = ComputeNodeSize(v);

            if (!double.IsNaN(p.X) &&
               !double.IsNaN(p.Y) &&
               !double.IsNaN(p.Z))
                g.DrawEllipse(new SolidBrush(colorizer[v]), p.X - size/2d, p.Y - size/2d, size, size);
}