IEnumerable <DebugCurve> Hubs() { return(mgd.Stations.Select(station => new DebugCurve(100, 1, "blue", CurveFactory.CreateCircle(Math.Max(station.Radius, 1.0), station.Position)))); }
static ICurve Box(Point p) { // ReSharper restore UnusedMember.Local return(CurveFactory.CreateRectangle(2, 2, p)); }
IEnumerable <DebugCurve> BBoxes() { return(mgd.Stations.Where(n => n.IsRealNode).Select(n => new DebugCurve("red", CurveFactory.CreateCircle(n.BoundaryCurve.BoundingBox.Diagonal / 2, n.Position)))); }
static ICurve CreateCurveAt(double x, double y, double size) { return(CurveFactory.CreateRectangleWithRoundedCorners(size, size, size / 10, size / 10, new Point(x, y))); }
void ShowEdge(AxisEdge edge, Point point) { // ReSharper restore SuggestBaseTypeForParameter var dd = GetObstacleBoundaries("black"); var seg = new DebugCurve(1, "red", new LineSegment(edge.Source.Point, edge.Target.Point)); LayoutAlgorithmSettings.ShowDebugCurvesEnumeration(dd.Concat( new[] { seg, new DebugCurve("blue", CurveFactory.CreateEllipse(3, 3, point)) })); }
/// <summary> /// Example on how to use Stress Majorization with a small graph and Localized method. /// </summary> public static void RunStressMajorizationExample() { //create a star graph where three nodes are connected to the center GeometryGraph graph = new GeometryGraph(); graph.Nodes.Add(new Node()); graph.Nodes.Add(new Node()); graph.Nodes.Add(new Node()); graph.Nodes.Add(new Node()); //set initial positions, e.g., random graph.Nodes[0].BoundaryCurve = CurveFactory.CreateRectangle(20, 10, new Point(5, 5)); graph.Nodes[1].BoundaryCurve = CurveFactory.CreateRectangle(20, 10, new Point(7, 10)); graph.Nodes[2].BoundaryCurve = CurveFactory.CreateRectangle(20, 10, new Point(7, 2)); graph.Nodes[3].BoundaryCurve = CurveFactory.CreateRectangle(20, 10, new Point(35, 1)); graph.Edges.Add(new Edge(graph.Nodes[0], graph.Nodes[1])); graph.Edges.Add(new Edge(graph.Nodes[0], graph.Nodes[2])); graph.Edges.Add(new Edge(graph.Nodes[0], graph.Nodes[3])); //array with desired distances between the nodes for every edge double[] idealEdgeLength = new double[graph.Edges.Count]; for (int i = 0; i < graph.Edges.Count; i++) { idealEdgeLength[i] = 100; //all edges should have this euclidean length } //create stress majorization class and set the desired distances on the edges StressMajorization majorizer = new StressMajorization(); majorizer.Positions = new List <Point>(graph.Nodes.Select(v => v.Center)); majorizer.NodeVotings = new List <NodeVoting>(graph.Nodes.Count); // initialize for every node an empty block for (int i = 0; i < graph.Nodes.Count; i++) { var nodeVote = new NodeVoting(i); //by default there is already a block with weighting 1 //optional: add second block with different type of edges, e.g., with stronger weight //var secondBlock = new VoteBlock(new List<Vote>(), 100); //nodeVote.VotingBlocks.Add(secondBlock); //var block2=nodeVote.VotingBlocks[1]; //block could be accessed like this in a later stage majorizer.NodeVotings.Add(nodeVote); } // for every edge set the desired distances by setting votings among the two end nodes. Dictionary <Node, int> posDict = new Dictionary <Node, int>(); for (int i = 0; i < graph.Nodes.Count; i++) { posDict[graph.Nodes[i]] = i; } var edges = graph.Edges.ToArray(); for (int i = 0; i < graph.Edges.Count; i++) { var edge = edges[i]; int nodeId1 = posDict[edge.Source]; int nodeId2 = posDict[edge.Target]; double idealDistance = idealEdgeLength[i]; double weight = 1 / (idealDistance * idealDistance); var voteFromNode1 = new Vote(nodeId1, idealDistance, weight); // vote from node1 for node2 var voteFromNode2 = new Vote(nodeId2, idealDistance, weight); // vote from node2 for node1 // add vote of node1 to list of node2 (in first voting block) majorizer.NodeVotings[nodeId2].VotingBlocks[0].Votings.Add(voteFromNode1); // add vote of node2 to list of node1 (in first voting block) majorizer.NodeVotings[nodeId1].VotingBlocks[0].Votings.Add(voteFromNode2); } //used localized method to reduce stress majorizer.Settings = new StressMajorizationSettings(); majorizer.Settings.SolvingMethod = SolvingMethod.Localized; List <Point> result = majorizer.IterateAll(); for (int i = 0; i < result.Count; i++) { graph.Nodes[i].Center = result[i]; } #if DEBUG && !SILVERLIGHT && !SHARPKIT LayoutAlgorithmSettings.ShowGraph(graph); #endif }
static ICurve CreateEllipse() { return(CurveFactory.CreateEllipse(20, 10, new Point())); }
private static ICurve CreateRectangle() { return(CurveFactory.CreateRectangle(20, 10, new Point())); }
private static ICurve CreateDot() { return(CurveFactory.CreateRectangle(5, 5, new Point())); }
private void ShowDebugInsertedSegments(GridTraversal grid, int zoomLevel, LgNodeInfo nodeToAdd, IEnumerable <SymmetricSegment> newToAdd, IEnumerable <SymmetricSegment> allOnNewEdges) { #if DEBUG && !SILVERLIGHT && !SHARPKIT && PREPARE_DEMO var edges = _pathRouter.GetAllEdgesVisibilityEdges(); var ll = new List <DebugCurve>(); foreach (var ni in _insertedNodes) { ll.Add(new DebugCurve(5, "green", ni.BoundaryCurve)); } if (nodeToAdd != null) { var curve = _insertedNodes.Last().BoundaryCurve.Clone(); curve.Translate(nodeToAdd.Center - _insertedNodes.Last().Center); ll.Add(new DebugCurve(5, "red", curve)); } foreach (var e in edges) { ll.Add(new DebugCurve(new LineSegment(e.SourcePoint, e.TargetPoint))); } int n = zoomLevel; int maxNodes = MaxNodesPerTile(zoomLevel); for (int ix = 0; ix < n; ix++) { for (int iy = 0; iy < n; iy++) { var tile = new Tuple <int, int>(ix, iy); var r = grid.GetTileRect(ix, iy); if (_nodeTileTable.ContainsKey(tile) && _nodeTileTable[tile] >= maxNodes) { ll.Add(new DebugCurve(5, "yellow", CurveFactory.CreateRectangle(r))); } else if (_segmentTileTable.ContainsKey(tile) && _segmentTileTable[tile] >= MaxAmountRailsPerTile) { ll.Add(new DebugCurve(5, "orange", CurveFactory.CreateRectangle(r))); } else { ll.Add(new DebugCurve(5, "blue", CurveFactory.CreateRectangle(r))); } } } if (allOnNewEdges != null) { foreach (var seg in allOnNewEdges) { ll.Add(new DebugCurve(5, "yellow", new LineSegment(seg.A, seg.B))); } } if (newToAdd != null) { foreach (var seg in newToAdd) { ll.Add(new DebugCurve(5, "red", new LineSegment(seg.A, seg.B))); } } LayoutAlgorithmSettings.ShowDebugCurves(ll.ToArray()); PrintInsertedNodesLabels(); #endif }
static IEnumerable <DebugCurve> DebugCircles(MetroGraphData metroGraphData) { return (metroGraphData.Stations.Select( station => new DebugCurve(100, 0.1, "blue", CurveFactory.CreateCircle(station.Radius, station.Position)))); }
public static ICurve CreateCurve(double w, double h) { //return CurveFactory.CreateRectangle(w, h, new Point()); //return CurveFactory.CreateEllipse(w/2,h/2, new Point()); return(CurveFactory.CreateRectangleWithRoundedCorners(w, h, 10, 10, new Point())); }
internal void CreateClassGraph() { graph = new GeometryGraph(); var typeNodes = new Dictionary <string, Node>(); ProcessTypeDelegate processType = type => { //string typeNamespace = type.Namespace; //if (!string.IsNullOrEmpty(typeNamespace)) //{ // if (typeNamespace.StartsWith("Unity") // || typeNamespace.StartsWith("TMPro") // || typeNamespace.StartsWith("TMPro") // ) // return; //} char start = type.Name[0]; if (start == '<' || start == '$') { return; } //if(!type.Name.Contains("Singleton")) // return; TypeNodeInfo info = new TypeNodeInfo(type); var node = new Node(CurveFactory.CreateRectangle(info.baseSize.x, info.baseSize.y, new Point())) { UserData = info }; graph.Nodes.Add(node); Node doublonByNameToBeFixedOneDayIWillGiveAFuck; if (!typeNodes.TryGetValue(info.ToString(), out doublonByNameToBeFixedOneDayIWillGiveAFuck)) { typeNodes.Add(info.ToString(), node); } }; AssemblyScanner.Register(processType, AssemblyScanner.OnlyProject); AssemblyScanner.Scan(); foreach (var kvp in typeNodes) { Node node = kvp.Value; Type baseType = (node.UserData as TypeNodeInfo).type.BaseType; if (baseType == null) { continue; } string baseTypeName = GetTypeName(baseType); Node parentNode; if (typeNodes.TryGetValue(baseTypeName, out parentNode)) { graph.Edges.Add(new Edge(node, parentNode)); } } for (int i = graph.Nodes.Count; --i >= 0;) { if (graph.Nodes[i].Edges.Any()) { continue; } graph.Nodes.RemoveAt(i); } }
// double GetAverageOverlap(List<Tuple<int, int, double, double>> proximityEdgesWithDistance, // Point[] positions, Rectangle[] rectangles) { // double overlap = 0; // int counter = 0; // foreach (Tuple<int, int, double, double> tuple in proximityEdgesWithDistance) { // int nodeId1 = tuple.Item1; // int nodeId2 = tuple.Item2; // Point point1 = positions[nodeId1]; // Point point2 = positions[nodeId2]; // // if (nodeBoxes == null) throw new ArgumentNullException("nodeBoxes"); // if (nodeBoxes.Length <= nodeId1) return 0; // if (nodeBoxes.Length <= nodeId2) return 0; // double box1Width = nodeBoxes[nodeId1].Width; // double box1Height = nodeBoxes[nodeId1].Height; // double box2Width = nodeBoxes[nodeId2].Width; // double box2Height = nodeBoxes[nodeId2].Height; // // //Gansner et. al Scaling factor of distance // double tw = (box1Width/2 + box2Width/2)/Math.Abs(point1.X - point2.X); // double th = (box1Height/2 + box2Height/2)/Math.Abs(point1.Y - point2.Y); // double t = Math.Max(Math.Min(tw, th), 1); // // if (t == 1) continue; // no overlap between the bounding boxes // // double distance = (t - 1)*(point1 - point2).Length; // overlap += distance; // counter++; // } // // overlap /= counter; // return overlap; // } /// <summary> /// For debugging only /// </summary> /// <param name="currentIteration"></param> /// <param name="nodeSizes"></param> /// <param name="nodePositions"></param> /// <param name="newPositions"></param> /// <param name="proximityEdgesWithDistance"></param> /// <param name="finalGridVectors"></param> static void ShowCurrentMovementVectors(int currentIteration, Size[] nodeSizes, Point[] nodePositions, List <Point> newPositions, List <Tuple <int, int, double, double> > proximityEdgesWithDistance, Point[] finalGridVectors) { #if TEST_MSAGL && !SHARPKIT if (DebugMode && currentIteration % 1 == 0) { List <DebugCurve> curveList = new List <DebugCurve>(); var nodeBoxes = new Rectangle[nodeSizes.Length]; for (int i = 0; i < nodeBoxes.Length; i++) { nodeBoxes[i] = new Rectangle(nodeSizes[i], nodePositions[i]); } var nodeCurves = nodeBoxes.Select( v => new DebugCurve(220, 1, "black", Curve.PolylineAroundClosedCurve(CurveFactory.CreateRectangle(v)))); curveList.AddRange(nodeCurves); var vectors = nodePositions.Select( (p, i) => new DebugCurve(220, 2, "red", new Polyline(p, newPositions[i]))).ToList(); foreach (Tuple <int, int, double, double> tuple in proximityEdgesWithDistance) { if (tuple.Item3 > 0) { curveList.Add(new DebugCurve(220, 1, "gray", new Polyline(nodePositions[tuple.Item1], nodePositions[tuple.Item2]))); } } curveList.AddRange(vectors); if (finalGridVectors != null) { var gridFlowVectors = nodePositions.Select((p, i) => new DebugCurve(220, 2, "blue", new Polyline(p, p + finalGridVectors[i]))) .ToList(); curveList.AddRange(gridFlowVectors); } LayoutAlgorithmSettings.ShowDebugCurves(curveList.ToArray()); } #endif }