示例#1
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;
            }
        }
        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 SimpleClusterGraphRectilinear()
 {
     var g = new GeometryGraph();
     var node0 = new Node(CurveFactory.CreateRectangle(10, 10, new Point()), 0);
     var node1 = new Node(CurveFactory.CreateRectangle(10, 10, new Point()), 1);
     var cluster = new Cluster(new[] { node1 });
     cluster.UserData = 2; 
     cluster.BoundaryCurve = CurveFactory.CreateRectangle(10, 10, new Point());
     var edge = new Edge(node0, node1) { Length = 100 };
     g.Nodes.Add(node0);
     g.Nodes.Add(node1);
     g.Edges.Add(edge);
     var cluster2 = new Cluster(new[] { node0 }, new[] { cluster });
     cluster2.UserData = 3;
     cluster2.BoundaryCurve = CurveFactory.CreateRectangle(10, 10, new Point());
     g.RootCluster = cluster2;
     InitialLayout initialLayout = new InitialLayout(g, new FastIncrementalLayoutSettings() { AvoidOverlaps = true });
     initialLayout.Run();
     
     RectilinearEdgeRouter router = new RectilinearEdgeRouter(g, 1, 1, false);
     router.Run();
     EnableDebugViewer();
     ShowGraphInDebugViewer(g);
     var bb0 = node0.BoundingBox;
     bb0.Pad(1);
     Assert.IsTrue(bb0.Contains(edge.EdgeGeometry.Curve.Start));
     var bb1 = node1.BoundingBox;
     bb1.Pad(1);
     Assert.IsTrue(bb1.Contains(edge.EdgeGeometry.Curve.End));
 }
示例#5
0
        static void GroupRoutingTestRect() {
            LayoutAlgorithmSettings settings;
            GeometryGraph graph = GetTestGraphWithClusters(out settings);
            var sugiyamaSettings = (SugiyamaLayoutSettings) settings;
            var router = new RectilinearEdgeRouter(graph, sugiyamaSettings.NodeSeparation/6,
                                                   sugiyamaSettings.NodeSeparation/6,
                                                   true,
                                                   sugiyamaSettings.EdgeRoutingSettings.UseObstacleRectangles)
                                                   {
                                                       BendPenaltyAsAPercentageOfDistance = sugiyamaSettings.EdgeRoutingSettings.BendPenalty
                                                   };
            router.Run();
#if DEBUG
            DisplayGeometryGraph.ShowGraph(graph);
#endif
        }
示例#6
0
        static void RectilinearTestOnGeomGraph(EdgeRoutingMode edgeRoutingMode, bool useSparseVisibilityGraph, bool useObstacleRectangles,
                                               double bendPenalty, int reps, Random random, GeometryGraph geomGraph, Point delta) {
            Console.WriteLine("shifting nodes and calling RectilinearEdgeRouter {0} times", reps);
            for (int i = 0; i < reps; i++) {
                Console.WriteLine(i + 1);
                ShiftNodes(random, geomGraph, delta);
                //                    if(i<=567)
                //                        continue;
                if (i == -1) {
                    GeometryGraphWriter.Write(geomGraph, "c:/tmp/ch0");
#if TEST_MSAGL
                    LayoutAlgorithmSettings.ShowDebugCurvesEnumeration(DebugCurvesFromGraph(geomGraph));
#endif
                }
                var nodeShapeMap = new Dictionary<Node, Shape>();
                foreach (Node node in geomGraph.Nodes) {
                    Shape shape = RectilinearInteractiveEditor.CreateShapeWithRelativeNodeAtCenter(node);
                    nodeShapeMap[node] = shape;
                }

                var router = new RectilinearEdgeRouter(nodeShapeMap.Values, RectilinearEdgeRouter.DefaultPadding,
                                                       RectilinearEdgeRouter.DefaultCornerFitRadius, useSparseVisibilityGraph, useObstacleRectangles) {
                    RouteToCenterOfObstacles = edgeRoutingMode == EdgeRoutingMode.RectilinearToCenter,
                    BendPenaltyAsAPercentageOfDistance =  bendPenalty
                };

                foreach (Edge edge in geomGraph.Edges) {
                    EdgeGeometry edgeGeom = edge.EdgeGeometry;
                    edgeGeom.SourcePort = nodeShapeMap[edge.Source].Ports.First();
                    edgeGeom.TargetPort = nodeShapeMap[edge.Target].Ports.First();
                    router.AddEdgeGeometryToRoute(edgeGeom);
                }

                router.UpdateObstacles(geomGraph.Nodes.Select(n => nodeShapeMap[n]));
                router.Run();
            }
        }
示例#7
0
        static void RouteRectEdgesOfGeomGraph(EdgeRoutingMode edgeRoutingMode, bool useSparseVisibilityGraph, bool useObstacleRectangles,
                                            double bendPenalty, GeometryGraph geomGraph, SugiyamaLayoutSettings settings) {
            var nodeShapeMap = new Dictionary<Node, Shape>();
            foreach (Node node in geomGraph.Nodes) {
                Shape shape = RectilinearInteractiveEditor.CreateShapeWithRelativeNodeAtCenter(node);
                nodeShapeMap[node] = shape;
            }

            var padding = (settings == null) ? 3 : settings.NodeSeparation / 3;
            var router = new RectilinearEdgeRouter(nodeShapeMap.Values, padding, 3, useSparseVisibilityGraph, useObstacleRectangles)
            {
                RouteToCenterOfObstacles = edgeRoutingMode == EdgeRoutingMode.RectilinearToCenter,
                BendPenaltyAsAPercentageOfDistance = bendPenalty
            };

            foreach (Edge edge in geomGraph.Edges) {
                EdgeGeometry edgeGeom = edge.EdgeGeometry;
                edgeGeom.SourcePort = nodeShapeMap[edge.Source].Ports.First();
                edgeGeom.TargetPort = nodeShapeMap[edge.Target].Ports.First();

                // Remove any path results retrieved from the geom file.
                edgeGeom.Curve = null;
                if (edgeGeom.SourceArrowhead != null)
                {
                    edgeGeom.SourceArrowhead.TipPosition = new Point();
                }
                if (edgeGeom.TargetArrowhead != null)
                {
                    edgeGeom.TargetArrowhead.TipPosition = new Point();
                }

                router.AddEdgeGeometryToRoute(edgeGeom);
            }
            router.Run();
        }