Exemplo n.º 1
0
 public static void printImage(LogicalImage image, ImageConstraints constraints)
 {
     foreach (var connection in image.Connections)
     {
         Console.WriteLine(connection);
     }
 }
Exemplo n.º 2
0
        public static void build_image(String directory, LogicalImage image, ImageConstraints constraints, int index)
        {
            Graph graph = new Graph("graph");
            GetNodeBoundaryDelegate boundry = new GetNodeBoundaryDelegate(GetNodeBoundary);
            double thickness = s_random.Next(20, 60) / 10.0;

            var settings = new SugiyamaLayoutSettings
            {
                EdgeRoutingSettings = { CornerRadius = 0.0, EdgeRoutingMode = EdgeRoutingMode.Rectilinear, Padding = 1, BendPenalty = 99 },
                AspectRatio         = 1
            };

            graph.LayoutAlgorithmSettings = settings;
            foreach (var connection in image.Connections)
            {
                ImageLayout.Shape src   = connection.Source;
                ImageLayout.Shape dst   = connection.Destination;
                String            label = "";
                var edge = graph.AddEdge(src.ToString(), label, dst.ToString());
                edge.Attr.LineWidth = thickness;
            }

            foreach (var shape in image.Shapes)
            {
                Microsoft.Msagl.Drawing.Node node = graph.FindNode(shape.ToString());
                node.Attr.Shape           = Microsoft.Msagl.Drawing.Shape.DrawFromGeometry;
                node.NodeBoundaryDelegate = new DelegateToSetNodeBoundary(boundry);
                node.LabelText            = "";
                node.Attr.LineWidth       = thickness;
                //node.Attr.FillColor = new Microsoft.Msagl.Drawing.Color((byte)s_random.Next(255), (byte)s_random.Next(255), (byte)s_random.Next(255));
            }

            var renderer = new GraphRenderer(graph);

            renderer.CalculateLayout();
            Point topleft = graph.GeometryGraph.BoundingBox.LeftTop;

            graph.GeometryGraph.Transform(new PlaneTransformation(1, 0, 0 - topleft.X, 0, 1, 0 - topleft.Y)); //fix bounding box

            Bitmap bitmap = new Bitmap((int)graph.Width, (int)graph.Height, PixelFormat.Format32bppPArgb);    //PixelFormat.Format32bppPArgb);

            renderer.Render(bitmap);
            bitmap.Save(System.IO.Path.Combine(directory, index + ".jpg"));
            create_json(directory, graph, index);
        }
Exemplo n.º 3
0
        public static void build_image_sd(String directory, LogicalImage image, ImageConstraints constraints, int index)
        {
            //draw all line
            System.Drawing.Image    img         = new Bitmap(constraints.Width, constraints.Height, PixelFormat.Format32bppPArgb);
            System.Drawing.Graphics graphicsObj = System.Drawing.Graphics.FromImage(img);//myform.CreateGraphics();

            System.Drawing.Pen myPen   = new System.Drawing.Pen(System.Drawing.Color.Black, s_random.Next(200, 230) / 100.0f);
            System.Drawing.Pen dashPen = new System.Drawing.Pen(System.Drawing.Color.Black, 2);
            dashPen.DashPattern = new float[] { 4, 2 };

            int b = s_random.Next(constraints.Width / 10, constraints.Width / 7);          //buffer
            int s = (int)((float)(constraints.Width - b) / (float)(image.Shapes.Count())); //stride;

            foreach (var shape in image.Shapes)
            {
                //Draw object
                int x = b + shape.Id * s;
                graphicsObj.DrawRectangle(myPen, new System.Drawing.Rectangle(x - (int)(s * 0.4f), b, (int)(s * 0.4f), b / 2));
                graphicsObj.DrawLine(dashPen, x, b * 2, x, constraints.Height - 0.8f * b);
            }

            //pick connections in random order and draw
            myPen.EndCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor;
            int sv = (constraints.Height - 3 * b) / image.Connections.Count(); //vertical stride
            int i  = 1;

            foreach (var connection in image.Connections)
            {
                ImageLayout.Shape src = connection.Source;
                ImageLayout.Shape dst = connection.Destination;
                int x1 = b + src.Id * s;
                int x2 = b + dst.Id * s;
                int y  = 2 * b + sv * i++;
                graphicsObj.DrawLine(myPen, x1, y, x2, y);
            }

            img.Save(directory + @"\images\" + index + ".jpg");
        }