public void RouteEdges_SplineRoutingRegressionBug20110127()
 {
     double tightPadding = 1;
     double loosePadding = 20;
     double coneAngle = Math.PI / 6;
     GeometryGraph graph = LoadGraph("RoutingRegressionBug20110127.msagl.geom");
     SplineRouter splineRouter = new SplineRouter(graph, tightPadding, loosePadding, coneAngle, null);
     splineRouter.Run();
     //DisplayGeometryGraph.ShowGraph(graph);
     CheckEdgesForOverlapWithNodes(tightPadding, graph);
 }
Exemplo n.º 2
0
        static void DemoEdgeRouterHelper(GeometryGraph graph)
        {
            DemoRoutingFromPortToPort(graph);

            var router = new SplineRouter(graph, 3, 3, Math.PI / 6, null);

            router.Run();
            #if TEST
            LayoutAlgorithmSettings.ShowGraph(graph);
            #endif

            var rectRouter = new RectilinearEdgeRouter(graph, 3,3, true);
            rectRouter.Run();
            #if TEST
            LayoutAlgorithmSettings.ShowGraph(graph);
            #endif
        }
        internal static void RouteEdges(GeometryGraph component, LayoutAlgorithmSettings settings, CancelToken cancelToken)
        {
            EdgeRoutingMode mode = settings.EdgeRoutingSettings.EdgeRoutingMode;

            // Use straight line routing on very large graphs otherwise it is too slow 
            if (component.Nodes.Count >= 2000)
            {
                mode = EdgeRoutingMode.StraightLine;
            }

            switch (mode)
            {
                case EdgeRoutingMode.Spline:
                    var splineRouter = new SplineRouter(
                        component,
                        settings.EdgeRoutingSettings.Padding,
                        settings.NodeSeparation, settings.EdgeRoutingSettings.ConeAngle, null);
                    splineRouter.Run(cancelToken);
                    break;
                case EdgeRoutingMode.SplineBundling:
                    splineRouter = new SplineRouter(
                        component,
                        settings.EdgeRoutingSettings.Padding,
                        settings.NodeSeparation / 20, settings.EdgeRoutingSettings.ConeAngle,
                      new BundlingSettings());
                    splineRouter.Run(cancelToken);
                    break;
                case EdgeRoutingMode.Rectilinear:
                    double edgePadding = settings.EdgeRoutingSettings.Padding;
                    double cornerRadius = settings.EdgeRoutingSettings.CornerRadius;
                    var rectilinearEdgeRouter = new RectilinearEdgeRouter(component, edgePadding, cornerRadius,
                                                                          true);
                    rectilinearEdgeRouter.Run(cancelToken);
                    break;
                case EdgeRoutingMode.StraightLine:
                    var router = new StraightLineEdges(component.Edges,
                                                       settings.EdgeRoutingSettings.Padding);
                    router.Run(cancelToken);
                    break;
            }
        }
        public void RouteEdges_CallsProgress()
        {
            //DisplayGeometryGraph.SetShowFunctions();
            GeometryGraph graph = GraphGenerator.GenerateTree(10);
            double ratioComplete = 0;
            EventHandler<ProgressChangedEventArgs> handler = (s, e) => ratioComplete = e.RatioComplete;
            SplineRouter splineRouter = null;
            try
            {
                splineRouter = new SplineRouter(graph, 10, 1, Math.PI / 6, null);
                splineRouter.ProgressChanged += handler;
                splineRouter.Run();
             //   DisplayGeometryGraph.ShowGraph(graph);
            }
            finally
            {
                splineRouter.ProgressChanged -= handler;
            }

            Assert.AreEqual(1, ratioComplete, "RouteEdges did not complete");
        }
        public void RoutingWithThreeGroups()
        {
            var graph = LoadGraph("abstract.msagl.geom");
            var root = graph.RootCluster;
            var a = new Cluster { UserData = "a" };
            foreach (string id in new[] { "17", "39", "13", "19", "28", "12" })
                a.AddChild(graph.FindNodeByUserData(id));

            var b = new Cluster { UserData = "b" };
            b.AddChild(a);
            b.AddChild(graph.FindNodeByUserData("18"));
            root.AddChild(b);

            var c = new Cluster { UserData = "c" };
            foreach (string id in new[] { "30", "5", "6", "7", "8" })
                c.AddChild(graph.FindNodeByUserData(id));
            root.AddChild(c);

            var clusterNodes = new Set<Node>(root.AllClustersDepthFirst().SelectMany(cl => cl.Nodes));
            foreach (var node in graph.Nodes.Where(n => clusterNodes.Contains(n) == false))
                root.AddChild(node);

            FixClusterBoundariesWithNoRectBoundaries(root, 5);
            var defaultSettings = new FastIncrementalLayoutSettings();
            var rootSettings = new FastIncrementalLayoutSettings() { AvoidOverlaps = true };

            var initialLayout = new InitialLayoutByCluster(graph, new[] { graph.RootCluster }, cl => cl == root ? rootSettings : defaultSettings);
            initialLayout.Run();
            
            const double Padding = 5;

            SplineRouter splineRouter = new SplineRouter(graph, Padding/3, Padding, Math.PI / 6);
            splineRouter.Run();
#if TEST_MSAGL
            if (!DontShowTheDebugViewer())
            {
                graph.UpdateBoundingBox();
                DisplayGeometryGraph.ShowGraph(graph);                
            }
#endif
            
        }
 public void BundlingWithGroups() {
     var graph = GeometryGraphReader.CreateFromFile(GetGeomGraphFileName("graphWithGroups.msagl.geom"));
     var settings = new BundlingSettings();
     var router = new SplineRouter(graph, 3, 1, Math.PI / 6, settings);
     router.Run();
 }
Exemplo n.º 7
0
        static void TestRouting() {
            LayoutAlgorithmSettings settings;
            GeometryGraph graph = GeometryGraphReader.CreateFromFile("../../../graphs/ch0.msagl.geom", out settings);
            foreach (Edge e in graph.Edges) {
                if (e.SourcePort == null)
                    e.SourcePort = new FloatingPort(e.Source.BoundaryCurve, e.Source.Center);
                if (e.TargetPort == null)
                    e.TargetPort = new FloatingPort(e.Target.BoundaryCurve, e.Target.Center);
            }
            var t = new Microsoft.Msagl.DebugHelpers.Timer();
            t.Start();

            EdgeRoutingSettings routingSettings = settings.EdgeRoutingSettings;
            for (int i = 0; i < 20; i++)
                if (routingSettings.EdgeRoutingMode == EdgeRoutingMode.Spline) {
                    var router = new SplineRouter(graph, 2, 3, 0.349065850398866, null);
                    router.Run();
                }
            t.Stop();
            Console.WriteLine(t.Duration);
            //#if DEBUG

            //            LayoutAlgorithmSettings.Show(a, b, c, eg.Curve, eg0.Curve, eg1.Curve);
            //#endif
        }
        static void LabelParentEdgesAndMaybeRerouteThemNicely(GeometryGraph graph, List<Edge> inParentEdges,
            List<Edge> outParentEdges, EdgeRoutingSettings edgeRoutingSettings) {
            if (AllowedToRoute(inParentEdges, outParentEdges, edgeRoutingSettings)) {
                var shapeGroupRouter = new SplineRouter(graph, edgeRoutingSettings.Padding,
                    edgeRoutingSettings.PolylinePadding,
                    edgeRoutingSettings.RoutingToParentConeAngle, inParentEdges, outParentEdges);
                shapeGroupRouter.Run();
            }

            var labeledEdges = outParentEdges.Concat(inParentEdges).Where(e => e.Labels.Any());
            if (labeledEdges.Any()) {
                var elb = new EdgeLabelPlacement(graph.Nodes, labeledEdges);
                    //consider adding more nodes here: some sibling clusters maybe
                elb.Run();
            }

            /*//*************debug code start
            var parentEdges = inParentEdges.Concat(outParentEdges);
            var ll = new List<DebugCurve>();
            var marked = new Microsoft.Msagl.Core.DataStructures.Set<Node>();
            foreach (var e in parentEdges) {
                marked.Insert(e.Source);
                marked.Insert(e.Target);
                ll.Add(new DebugCurve(100, 1, "blue", e.Curve));
            }
            foreach (var c in graph.RootCluster.AllClustersDepthFirst()) {
                var color = marked.Contains(c) ? "red" : "green";
                ll.Add(new DebugCurve(100, 1, color, c.BoundaryCurve));
            }
            foreach (var c in graph.Nodes) {
                var color = marked.Contains(c) ? "red" : "green";
                ll.Add(new DebugCurve(100, 1, color, c.BoundaryCurve));
            }

            LayoutAlgorithmSettings.ShowDebugCurvesEnumeration(ll);
            */
            //*************debug code end
        }
 /// <summary>
 /// </summary>
 /// <param name="geometryGraph"></param>
 /// <param name="layoutSettings"></param>
 /// <param name="edgesToRoute"></param>
 public static void RouteAndLabelEdges(GeometryGraph geometryGraph, LayoutAlgorithmSettings layoutSettings, IEnumerable<Edge> edgesToRoute) {
     //todo: what about parent edges!!!!
     var filteredEdgesToRoute =
         edgesToRoute.Where(e => ! e.UnderCollapsedCluster()).ToArray();
     var ers = layoutSettings.EdgeRoutingSettings;
     if (ers.EdgeRoutingMode == EdgeRoutingMode.Rectilinear ||
         ers.EdgeRoutingMode == EdgeRoutingMode.RectilinearToCenter) {
         RectilinearInteractiveEditor.CreatePortsAndRouteEdges(
             layoutSettings.NodeSeparation/3,
             layoutSettings.NodeSeparation/3,
             geometryGraph.Nodes,
             edgesToRoute,
             ers.EdgeRoutingMode,
             true,
             ers.UseObstacleRectangles,
             ers.BendPenalty);
     } else if (ers.EdgeRoutingMode == EdgeRoutingMode.Spline || ers.EdgeRoutingMode==EdgeRoutingMode.SugiyamaSplines) {
         new SplineRouter(geometryGraph, filteredEdgesToRoute, ers.Padding, ers.PolylinePadding, ers.ConeAngle, null)
         {
             ContinueOnOverlaps = true, KeepOriginalSpline = ers.KeepOriginalSpline
         }.Run();
     } else if (ers.EdgeRoutingMode == EdgeRoutingMode.SplineBundling) {
         var edgeBundlingSettings = ers.BundlingSettings ?? new BundlingSettings();
         var bundleRouter = new SplineRouter(geometryGraph, filteredEdgesToRoute, ers.Padding, ers.PolylinePadding, ers.ConeAngle,
                                             edgeBundlingSettings) {
                                                 KeepOriginalSpline = ers.KeepOriginalSpline
                                             };
         bundleRouter.Run();
         if (bundleRouter.OverlapsDetected)
         {
             new SplineRouter(geometryGraph, filteredEdgesToRoute, ers.Padding, ers.PolylinePadding, ers.ConeAngle, null)
             {
                 ContinueOnOverlaps = true,
                 KeepOriginalSpline = ers.KeepOriginalSpline
             }.Run();
         }                
     } else if (ers.EdgeRoutingMode == EdgeRoutingMode.StraightLine) {
         var router = new StraightLineEdges(filteredEdgesToRoute, ers.Padding);
         router.Run();
     }
     var elb = new EdgeLabelPlacement(geometryGraph.Nodes, filteredEdgesToRoute);
     elb.Run();
     geometryGraph.UpdateBoundingBox();
 }
Exemplo n.º 10
0
        static void RouteBundledEdges(GeometryGraph geometryGraph, ArgsParser.ArgsParser argsParser) {
            double loosePadding;
            double tightPadding = GetPaddings(argsParser, out loosePadding);

            var br = new SplineRouter(geometryGraph, tightPadding, loosePadding, Math.PI/6, new BundlingSettings());
            br.Run();
        }
Exemplo n.º 11
0
        static void LoadDrawingGraph(string fileName, EdgeRoutingSettings edgeRoutingSettings, double bendPenalty) {
            var graph = Graph.Read(fileName);
            if (edgeRoutingSettings.EdgeRoutingMode == EdgeRoutingMode.Rectilinear || edgeRoutingSettings.EdgeRoutingMode == EdgeRoutingMode.RectilinearToCenter) {
                var sugiyamaSettings=new SugiyamaLayoutSettings();
                RouteRectEdgesOfGeomGraph(edgeRoutingSettings.EdgeRoutingMode, true ,
                                        edgeRoutingSettings.UseObstacleRectangles, bendPenalty, graph.GeometryGraph, sugiyamaSettings);
            } else {
                const double angle = 30 * Math.PI / 180;
                var router = new SplineRouter(graph.GeometryGraph, edgeRoutingSettings.Padding, edgeRoutingSettings.PolylinePadding, angle, edgeRoutingSettings.BundlingSettings);
                router.Run();

                TestPadding(graph.GeometryGraph);
#if DEBUG
                var gv = new GViewer();
                var f = new Form {
                    StartPosition = FormStartPosition.CenterScreen,
                    //     f.layerSeparationMult.Value = (decimal)(gwgraph.GraphAttr.LayerSep / gwgraph.GraphAttr.MinLayerSep);

                    Size = new Size(Screen.PrimaryScreen.WorkingArea.Width,
                                      Screen.PrimaryScreen.WorkingArea.Height)
                };
                f.SuspendLayout();
                f.Controls.Add(gv);
                gv.Dock = DockStyle.Fill;
                gv.NeedToCalculateLayout = false;
                gv.Graph = graph;
                f.ResumeLayout();

                f.ShowDialog();
#endif
            }
        }
        public void RouteEdges_SplineRouting1138Bus()
        {
            var g = LoadGraph("GeometryGraph_1138bus.msagl.geom");
            var sw = new Stopwatch();
            sw.Start();
            var loosePadding = SplineRouter.ComputeLooseSplinePadding(10, 2);
            SplineRouter splineRouter = new SplineRouter(g, 2, loosePadding, Math.PI / 6, null);
            splineRouter.Run();

            sw.Stop();
            System.Console.WriteLine("Edge routing took: {0} seconds.", sw.ElapsedMilliseconds / 1000.0);
        }
Exemplo n.º 13
0
        static void BundleRouterTest() {
            var graph = CreateGraphForGroupRouting();

            var router = new SplineRouter(graph, 1, 1, Math.PI / 180 * 30, new BundlingSettings());
            router.Run();
#if DEBUG

            //int j = 1;
            List<DebugCurve> edges =
                graph.Edges.Select(edgeGeometry => new DebugCurve(200, 0.5, "black" /*Nudger.Colors[j++]*/, edgeGeometry.Curve))
                    .ToList();
            var boundaries = graph.RootCluster.AllClustersDepthFirst().Select(
                    s => new DebugCurve(s.BoundaryCurve, s.UserData)).Concat(graph.RootCluster.AllClustersDepthFirst().SelectMany(c=>c.Nodes.Select(n=>new DebugCurve(n.BoundaryCurve))));
            LayoutAlgorithmSettings.ShowDebugCurvesEnumeration(
                boundaries.Concat(edges));
#endif

        }
Exemplo n.º 14
0
        static void TestGroupRouting() {
            GeometryGraph graph = GeometryGraphReader.CreateFromFile("c:/tmp/bug.msagl.geom");
            var router = new SplineRouter(graph, 10, 5, Math.PI/6);
            router.Run();
#if DEBUG
            DisplayGeometryGraph.ShowGraph(graph);
#endif
        }
Exemplo n.º 15
0
        static void GroupRoutingTestSpline() {
            LayoutAlgorithmSettings settings;
            var graph = GetTestGraphWithClusters(out settings);
#if DEBUG
            //DisplayGeometryGraph.ShowGraph(graph);
#endif
            var router = new SplineRouter(graph, 2, 9, Math.PI / 6, new BundlingSettings());
            router.Run();
#if DEBUG
            DisplayGeometryGraph.ShowGraph(graph);
#endif
        }
Exemplo n.º 16
0
        static void BundleWithWidths() {
            bool msaglFile;
            int line;
            int column;
            var graph = Form2.CreateDrawingGraphFromFile("c:\\dev\\graphlayout\\graphs\\tail.dot", out line, out column, out msaglFile);
            var graph1 = Form2.CreateDrawingGraphFromFile("c:\\dev\\graphlayout\\graphs\\tail.dot", out line, out column, out msaglFile);

            double w = 0.3;
            foreach (var edge in graph.Edges) {
                edge.Attr.LineWidth = w;
                if (w == 0.3)
                    w = 0.4;
                else if (w == 0.4)
                    w = .5;
                else w = 0.3;
            }

            var gv = new GViewer();
            gv.Graph = graph1;
            graph.CreateGeometryGraph();
            var gg = graph.GeometryGraph;
            var gg1 = graph1.GeometryGraph;

            for (int i = 0; i < gg.Nodes.Count; i++)
                gg.Nodes[i].BoundaryCurve = gg1.Nodes[i].BoundaryCurve;

            var ss = new SugiyamaLayoutSettings();
            var ll = new LayeredLayout(graph.GeometryGraph, ss);
            ll.Run();

            var bundler = new SplineRouter(graph.GeometryGraph, ss.NodeSeparation * 2, ss.NodeSeparation / 3, Math.PI / 6, ss.EdgeRoutingSettings.BundlingSettings);

            bundler.Run();
            
            var f = new Form();
            f.SuspendLayout();
            f.Controls.Add(gv);
            gv.Dock = DockStyle.Fill;
            gv.NeedToCalculateLayout = false;
            gv.Graph = graph;
            f.ResumeLayout();

            f.ShowDialog();


        }
Exemplo n.º 17
0
        static void TestDeb11() {
            GeometryGraph graph = GeometryGraphReader.CreateFromFile("c:\\tmp\\DebugGraph11.msagl.geom");

            var allEdges = new List<Edge>(graph.Edges);
            int start = 64;
            int end = 64;
            for (int i = 0; i < allEdges.Count; i++)
                if (i < start || i > end)
                    graph.Edges.Remove(allEdges[i]);

            var splineRouter = new SplineRouter(graph, 1, 20, Math.PI / 6, null);
            splineRouter.Run();
#if TEST_MSAGL
            LayoutAlgorithmSettings.ShowGraph(graph);
#endif
        }
Exemplo n.º 18
0
        static void Main(string[] args) {
#if DEBUG
            DisplayGeometryGraph.SetShowFunctions();
#endif
            ArgsParser.ArgsParser argsParser = SetArgsParser(args);

            if (argsParser.OptionIsUsed(PolygonDistanceTestOption))
                TestPolygonDistance();
            else if (argsParser.OptionIsUsed(TestCdtThreaderOption))
                TestCdtThreader();
            else if (argsParser.OptionIsUsed(RandomBundlingTest))
                RandomBundlingTests.RsmContent();


            bundling = argsParser.OptionIsUsed(BundlingOption);

            var gviewer = new GViewer();
            gviewer.MouseMove += Draw.GviewerMouseMove;
            if(argsParser.OptionIsUsed(FdOption)) {
                TestFD();
                gviewer.CurrentLayoutMethod = LayoutMethod.IcrementalLayout;
            }
            Form form = CreateForm(null, gviewer);
            if (argsParser.OptionIsUsed(AsyncLayoutOption))
                gviewer.AsyncLayout = true;

            string listOfFilesFile = argsParser.GetValueOfOptionWithAfterString(ListOfFilesOption);
            if (listOfFilesFile != null) {
                ProcessListOfFiles(listOfFilesFile, argsParser);
                return;
            }
            string fileName = argsParser.GetValueOfOptionWithAfterString(FileOption);
            string ext = Path.GetExtension(fileName);
            if (ext != null) {
                ext = ext.ToLower();
                if (ext == ".dot") {
                    ProcessDotFile(gviewer, argsParser, fileName);
                }
                else {
                    if (ext == ".geom") {
                        GeometryGraph geometryGraph = GeometryGraphReader.CreateFromFile(fileName);
                        geometryGraph.Margins = 10;

                        FixHookPorts(geometryGraph);
                        // if (argsParser.OptionIsUsed(BundlingOption)) {
                        for (int i = 0; i < 1; i++) {
#if DEBUG
                            /*DisplayGeometryGraph.ShowGraph(geometryGraph);
                                var l = new List<DebugCurve>(); l.AddRange(geometryGraph.Nodes.Select(n=>new DebugCurve(100,1,"black",n.BoundaryCurve)));
                                l.AddRange(geometryGraph.Edges.Select(e=>new DebugCurve(100,1,"black", new LineSegment(e.Source.Center,e.Target.Center))));
                                foreach (var cl in geometryGraph.RootCluster.AllClustersDepthFirst()) {
                                    l.Add(new DebugCurve(100,2,"blue",cl.BoundaryCurve));
                                    foreach (var node in cl.Nodes)
                                        l.Add(new DebugCurve(100, 2, "brown", node.BoundaryCurve));
                                  
                                    foreach (var e in cl.Edges)
                                        l.Add(new DebugCurve(100, 2, "pink", new LineSegment(e.Source.Center, e.Target.Center)));
                                  
                                }

                                DisplayGeometryGraph.ShowDebugCurves(l.ToArray());*/

#endif
                            BundlingSettings bs = GetBundlingSettings(argsParser);

                            double loosePadding;
                            double tightPadding = GetPaddings(argsParser, out loosePadding);
                            if (argsParser.OptionIsUsed(MdsOption)) {
                                var mdsLayoutSettings = new MdsLayoutSettings
                                                        {RemoveOverlaps = true, NodeSeparation = loosePadding*3};
                                var mdsLayout = new MdsGraphLayout(mdsLayoutSettings, geometryGraph);
                                mdsLayout.Run();
                            }
                            else {
                                if (argsParser.OptionIsUsed(FdOption)) {
                                    var settings = new FastIncrementalLayoutSettings {AvoidOverlaps = true};
                                    (new InitialLayout(geometryGraph, settings)).Run();
                                }
                            }
                            var splineRouter = new SplineRouter(geometryGraph, geometryGraph.Edges, tightPadding,
                                                                loosePadding,
                                                                Math.PI/6, bs);
                            splineRouter.Run();
                        }
#if DEBUG
                        DisplayGeometryGraph.ShowGraph(geometryGraph);
#endif
                        return;
                    }
                    else {
                        if (ext == ".msagl") {
                            Graph graph = Graph.Read(fileName);
                            //           DisplayGeometryGraph.ShowGraph(graph.GeometryGraph);
                            if (graph != null) {
                                if (argsParser.OptionIsUsed(BundlingOption)) {
                                    BundlingSettings bs = GetBundlingSettings(argsParser);

                                    double loosePadding;
                                    double tightPadding = GetPaddings(argsParser, out loosePadding);
                                    var br = new SplineRouter(graph.GeometryGraph, tightPadding, loosePadding, Math.PI/6,
                                                              bs);
                                    br.Run();
                                    //                 DisplayGeometryGraph.ShowGraph(graph.GeometryGraph);
                                }
                            }
                            gviewer.NeedToCalculateLayout = false;
                            gviewer.Graph = graph;
                            gviewer.NeedToCalculateLayout = true;
                        }
                    }
                }
            }
            else if (argsParser.OptionIsUsed(TestCdtOption)) {
                Triangulation(argsParser.OptionIsUsed(ReverseXOption));
                Environment.Exit(0);
            }
            else if (argsParser.OptionIsUsed(TestCdtOption0)) {
                TestTriangulationOnSmallGraph(argsParser);
                Environment.Exit(0);
            }
            else if (argsParser.OptionIsUsed(TestCdtOption2)) {
                TestTriangulationOnPolys();
                Environment.Exit(0);
            }
            else if (argsParser.OptionIsUsed(TestCdtOption1)) {
                ThreadThroughCdt();
                Environment.Exit(0);
            }
            else if (argsParser.OptionIsUsed(ConstraintsTestOption))
                TestGraphWithConstraints();
            
            Application.Run(form);
            
        }
Exemplo n.º 19
0
        static void GroupRoutingTest() {
            const int count = 1;
            var sw = new Stopwatch();
            sw.Start();
            //RouteGroupGraph(count);
            RouteCustomEdges(count);
            sw.Stop();
            Console.WriteLine((double) sw.ElapsedMilliseconds/1000);
            return;
#if false // turns off "unreachable code" warning due to the foregoing "return;".

            RouteBus1138(count);

            GeometryGraph graph = GeometryGraphReader.CreateFromFile("c:\\tmp\\graph0.msagl.geom");
            for (int i = 0; i < count; i++)
            {
                var box = graph.BoundingBox;
                box.Pad(box.Diagonal/4);
                graph.BoundingBox = box;
                var router = new SplineRouter(graph, 10, 1, Math.PI/6);
                router.Run();
            }
#if DEBUG
            LayoutAlgorithmSettings.ShowGraph(graph);
#endif
            graph = GeometryGraphReader.CreateFromFile("c:\\tmp\\graph1.msagl.geom");
            var splineRouter = new SplineRouter(graph, 10, 1, Math.PI / 6);
            splineRouter.Run();
#if DEBUG
            LayoutAlgorithmSettings.ShowGraph(graph);
#endif
            //RoutingTest0();
            for (int i = 0; i < count; i++)
            {
                graph = GeometryGraphReader.CreateFromFile("c:\\tmp\\graph2.msagl.geom");
                var router = new SplineRouter(graph, 10, 1, Math.PI / 6);
                router.Run();
                var box = graph.BoundingBox;
                box.Pad(box.Diagonal/4);
                graph.BoundingBox = box;
            }
#if DEBUG
            LayoutAlgorithmSettings.ShowGraph(graph);
#endif
#endif
        }
Exemplo n.º 20
0
        static void ProcessFile(string fileName, int fileReps, bool show, bool mds, EdgeRoutingMode edgeRoutingMode, double bendPenalty,
                                ref int nOfBugs, bool bundling, int randomShifts, bool useSparseVisibilityGraph, bool useObstacleRectangles) {
            Console.WriteLine(fileName);
            var random = new Random(1);
            for (int rep = 0; rep < fileReps; ++rep) {
                try {
                    int line, column;
                    bool msaglFile;
                    Graph gwgraph = Form2.CreateDrawingGraphFromFile(fileName, out line, out column, out msaglFile);
                    if (msaglFile) {
                        using (var f = new Form2(false) {
                                    EdgeRoutingMode = edgeRoutingMode,
                                    UseObstacleRectangles = useObstacleRectangles}) {
                            f.GViewer.NeedToCalculateLayout=false;
                            if (edgeRoutingMode == EdgeRoutingMode.SplineBundling) {
                                var nodeSeparation = gwgraph.LayoutAlgorithmSettings.NodeSeparation;
                                GeometryGraph originalGraph=gwgraph.GeometryGraph;
                                var coneAngle = gwgraph.LayoutAlgorithmSettings.EdgeRoutingSettings.ConeAngle;
                                var padding = nodeSeparation / 3;
                                var loosePadding = SplineRouter.ComputeLooseSplinePadding(nodeSeparation, padding) * 2;
                                var br = new SplineRouter(originalGraph, padding, loosePadding, coneAngle,
                                                                            gwgraph.LayoutAlgorithmSettings.EdgeRoutingSettings.BundlingSettings);
                                br.Run();
                            }

                            if (show)
                            {
                                f.StartPosition = FormStartPosition.CenterScreen;
                                //     f.layerSeparationMult.Value = (decimal)(gwgraph.GraphAttr.LayerSep / gwgraph.GraphAttr.MinLayerSep);
                               
                                f.Size = new Size(Screen.PrimaryScreen.WorkingArea.Width,
                                                  Screen.PrimaryScreen.WorkingArea.Height);
                                f.GViewer.Graph = gwgraph;
                                f.ShowDialog();
                            }
                            
                        }
                    }
                    else 
                    if (gwgraph != null) {
                        gwgraph.LayoutAlgorithmSettings.EdgeRoutingSettings.EdgeRoutingMode = edgeRoutingMode;
                        gwgraph.LayoutAlgorithmSettings.EdgeRoutingSettings.UseObstacleRectangles = useObstacleRectangles;
                        gwgraph.LayoutAlgorithmSettings.EdgeRoutingSettings.BendPenalty = bendPenalty;
                        using (var f = new Form2(false) {
                                    EdgeRoutingMode = edgeRoutingMode,
                                    UseObstacleRectangles = useObstacleRectangles,
                                    BendPenalty = bendPenalty
                                }) {
                            if (mds) {
                                foreach (Microsoft.Msagl.Drawing.Node n in gwgraph.Nodes)
                                    n.Attr.FillColor = Color.WhiteSmoke;

                                gwgraph.LayoutAlgorithmSettings = new MdsLayoutSettings {
                                    EdgeRoutingSettings = { 
                                        EdgeRoutingMode = edgeRoutingMode,
                                        BundlingSettings = bundling ? new BundlingSettings() : null
                                    } 
                                };
                            }

                            object ret = f.GViewer.CalculateLayout(gwgraph);

                            if (randomShifts > 0) {
                                var del = new Point(2, 2);
                                GeometryGraph geomGraph = f.GViewer.Graph.GeometryGraph;
                                for (int i = 0; i < randomShifts; i++) {
                                    ShiftNodes(random, geomGraph, del);
                                    if (edgeRoutingMode == EdgeRoutingMode.Rectilinear ||
                                        edgeRoutingMode == EdgeRoutingMode.RectilinearToCenter)
                                        RouteRectEdgesOfGeomGraph(edgeRoutingMode, useSparseVisibilityGraph, useObstacleRectangles, bendPenalty,
                                                                  geomGraph, (SugiyamaLayoutSettings)gwgraph.LayoutAlgorithmSettings);
                                }
                            }

                            if (show) {
                                f.Text = Process.GetCurrentProcess().MainModule.FileName;
                                f.StartPosition = FormStartPosition.CenterScreen;
                                //     f.layerSeparationMult.Value = (decimal)(gwgraph.GraphAttr.LayerSep / gwgraph.GraphAttr.MinLayerSep);
                                f.GViewer.SetCalculatedLayout(ret);

                                f.Size = new Size(Screen.PrimaryScreen.WorkingArea.Width,
                                                  Screen.PrimaryScreen.WorkingArea.Height);
                                f.ShowDialog();
                            }
                        }
                    } else
                        Console.WriteLine(" skipping - cannot parse");
                }
                catch (Exception e) {
                    nOfBugs++;
                    Console.WriteLine("bug " + nOfBugs);
                    if (fileReps > 1) {
                        Console.WriteLine("  (iteration: {0})", rep);
                    }
                    Console.WriteLine(e.ToString());
                    return;
                }
                if ((rep > 1) && (0 == (rep%100))) {
                    Console.WriteLine("  {0} reps", rep);
                }
            }
        }
Exemplo n.º 21
0
        static void RouteEdges(GeometryGraph graph, FastIncrementalLayoutSettings settings) {
            if (graph.Edges.Count < 1000) {
                var router = new SplineRouter(graph, settings.EdgeRoutingSettings.Padding,
                                              settings.EdgeRoutingSettings.PolylinePadding,
                                              settings.EdgeRoutingSettings.ConeAngle,
                                              settings.EdgeRoutingSettings.BundlingSettings);

                router.Run();
            } else {
                var sr = new StraightLineEdges(graph.Edges, 1);
                sr.Run();
            }

        }
Exemplo n.º 22
0
        static void RouteCustomEdges(int count) {
            for (int i = 0; i < count; i++) {
                var graph = CreateGraphForGroupRouting();
#if DEBUG
                LayoutAlgorithmSettings.ShowGraph(graph);
#endif
                var router = new SplineRouter(graph, 3, 3,Math.PI/180*30);
                router.Run();
#if DEBUG

                int j = 0;
                List<DebugCurve> edges =
                    graph.Edges.Select(edge => new DebugCurve(200, 2, DebugCurve.Colors[j++], edge.Curve))
                        .ToList();
                LayoutAlgorithmSettings.ShowDebugCurvesEnumeration(graph.RootCluster.AllClustersDepthFirst().Select(
                    s => new DebugCurve(s.BoundaryCurve, s.UserData)).
                                                                       Concat(edges));
#endif
            }
        }
Exemplo n.º 23
0
        static void EdgeSeparationTrackBarValueChanged(object sender, EventArgs e) {
            var edgeSeparationTruckBar = (TrackBar) sender;
            GViewer gviewer = GetGviewer(edgeSeparationTruckBar);

            Graph drawingGraph = gviewer.Graph;
            if (drawingGraph == null)
                return;


            EdgeRoutingSettings edgeRoutingSettings = drawingGraph.LayoutAlgorithmSettings.EdgeRoutingSettings;
            edgeRoutingSettings.EdgeRoutingMode = EdgeRoutingMode.SplineBundling;
            if (edgeRoutingSettings.BundlingSettings == null)
                edgeRoutingSettings.BundlingSettings = new BundlingSettings();
            edgeRoutingSettings.BundlingSettings.EdgeSeparation = GetEdgeSeparation(edgeSeparationTruckBar);
            var br = new SplineRouter(drawingGraph.GeometryGraph, 1, 1, Math.PI/6, edgeRoutingSettings.BundlingSettings);
            br.Run();

            IViewer iv = gviewer;
            foreach (IViewerObject edge in iv.Entities) {
                if (edge is IViewerEdge)
                    iv.Invalidate(edge);
            }
        }
 public void RouteEdges_Nodes50()
 {
     var g = LoadGraph("nodes50.msagl.geom");
     var sw = new Stopwatch();
     sw.Start();
     const double TightPadding = 2.0;
     var loosePadding = SplineRouter.ComputeLooseSplinePadding(10, TightPadding);
     SplineRouter splineRouter = new SplineRouter(g, TightPadding, loosePadding, Math.PI / 6, null);
     splineRouter.Run();
     sw.Stop();
     Console.WriteLine("Edge routing took: {0} seconds.", sw.ElapsedMilliseconds / 1000.0);
     CheckEdgesForOverlapWithNodes(TightPadding, g);
 }
 static void RouteEdges(GeometryGraph graph, double edgeSeparation)
 {
     var bs = new BundlingSettings();
     bs.EdgeSeparation = edgeSeparation;
     var br = new SplineRouter(graph, 0.25, 10, Math.PI / 6, bs);
     br.Run();
 }
 public void SplineRoutingSmallCompleteGraph()
 {
     //DisplayGeometryGraph.SetShowFunctions();
     var g = LoadGraph("K20.msagl.geom");
     var sw = new Stopwatch();
     sw.Start();
     var loosePadding = SplineRouter.ComputeLooseSplinePadding(10, 2);
     SplineRouter splineRouter = new SplineRouter(g, 2, loosePadding, Math.PI / 6, null); 
     splineRouter.Run();
     sw.Stop();
     TestContext.WriteLine("Edge routing took: {0} seconds.", sw.ElapsedMilliseconds / 1000.0);
 }
Exemplo n.º 27
0
        public void RouteEdgeSetSpline(IEnumerable<DEdge> edges)
        {
            if (!edges.Any())
                return;

            GeometryGraph ggAux = new GeometryGraph();
            foreach (DEdge edge in edges)
            {
                if (!ggAux.Nodes.Contains(edge.Source.GeometryNode))
                    ggAux.Nodes.Add(edge.Source.GeometryNode);
                if (!ggAux.Nodes.Contains(edge.Target.GeometryNode))
                    ggAux.Nodes.Add(edge.Target.GeometryNode);
                if (!ggAux.Edges.Contains(edge.GeometryEdge))
                    ggAux.Edges.Add(edge.GeometryEdge);
            }

            var router = new SplineRouter(ggAux, 3.0, 2.0, Math.PI / 6.0);
            router.Run();
            VerifyPolylines();
        }
        public void BundlingBug1GeomGraph() {
#if DEBUG && TEST_MSAGL
            DisplayGeometryGraph.SetShowFunctions();
#endif
            var graph = GeometryGraphReader.CreateFromFile(GetGeomGraphFileName("bug1.msagl.geom"));
            var settings = new BundlingSettings();
            var router = new SplineRouter(graph, 0.1, 0.75, Math.PI / 6, settings);
            router.Run();
        }
        void RunPostLayering() {
#if REPORTING
            Timer t = null;
            if (sugiyamaSettings.Reporting) {
                Report("Calculating edge splines... ");
                t = new Timer();
                t.Start();
            }
#endif
            EdgeRoutingSettings routingSettings = sugiyamaSettings.EdgeRoutingSettings;
            var mode = routingSettings.EdgeRoutingMode;
            if (constrainedOrdering != null) //we switch to splines when there are constraints, since the ordering of virtual nodes sometimes does not do a good job
                mode = EdgeRoutingMode.Spline;
            switch (mode) {
                case EdgeRoutingMode.SugiyamaSplines:
                    CalculateEdgeSplines();
                    break;
                case EdgeRoutingMode.StraightLine:
                    StraightLineEdges.SetStraightLineEdgesWithUnderlyingPolylines(originalGraph);
                    SetLabels();
                    break;
                case EdgeRoutingMode.Spline:
                    double padding = sugiyamaSettings.NodeSeparation/4;
                    double loosePadding = SplineRouter.ComputeLooseSplinePadding(sugiyamaSettings.NodeSeparation,
                                                                                 padding);
                    var router = new SplineRouter(originalGraph, padding, loosePadding, (Math.PI / 6), null);
                    router.Run();
                    SetLabels();
                    break;
                case EdgeRoutingMode.SplineBundling:
                    double coneAngle = routingSettings.ConeAngle;
                    padding = sugiyamaSettings.NodeSeparation/20;
                    loosePadding = SplineRouter.ComputeLooseSplinePadding(sugiyamaSettings.NodeSeparation, padding)*2;
                    if (sugiyamaSettings.EdgeRoutingSettings.BundlingSettings == null)
                        sugiyamaSettings.EdgeRoutingSettings.BundlingSettings = new BundlingSettings();
                    var br = new SplineRouter(originalGraph, padding, loosePadding, coneAngle,
                                              sugiyamaSettings.EdgeRoutingSettings.BundlingSettings);
                    br.Run();
                    SetLabels();
                    break;
                case EdgeRoutingMode.Rectilinear:
                case EdgeRoutingMode.RectilinearToCenter:
                    //todo: are these good values?
                    var rer = new RectilinearEdgeRouter(originalGraph, sugiyamaSettings.NodeSeparation/3,
                                                        sugiyamaSettings.NodeSeparation/4,
                                                        true,
                                                        sugiyamaSettings.EdgeRoutingSettings.UseObstacleRectangles);
                    rer.RouteToCenterOfObstacles = routingSettings.EdgeRoutingMode ==
                                                   EdgeRoutingMode.RectilinearToCenter;
                    rer.BendPenaltyAsAPercentageOfDistance = routingSettings.BendPenalty;
                    rer.Run();
                    SetLabels();
                    break;
            }
            originalGraph.BoundingBox = originalGraph.PumpTheBoxToTheGraphWithMargins();

#if REPORTING
            if (sugiyamaSettings.Reporting) {
                t.Stop();
                Report(String.Format(CultureInfo.InvariantCulture, "splines done for {0}", t.Duration));
            }
#endif
        }
 public void ComplexGeomGraph() {
     var graph = GeometryGraphReader.CreateFromFile(GetGeomGraphFileName("complex.msagl.geom"));
     var settings = new BundlingSettings();
     var br = new SplineRouter(graph, 1, 1.5, Math.PI / 6, settings);
     br.Run();
 }