private void CountEdgeCrossings(GraphLink edge) { int crossings = 0; GraphNode v1 = edge.Origin; GraphNode v2 = edge.Destination; SpringVertexData v1D = (SpringVertexData)v1.GetData(_SpringVertex); SpringVertexData v2D = (SpringVertexData)v2.GetData(_SpringVertex); PointF pt = new PointF(0, 0), pt11, pt12, pt21, pt22; pt11 = v1.Center; pt12 = v2.Center; foreach (GraphLink test in _graph.Links) { if (edge == test) { continue; } pt21 = test.Origin.Center; pt22 = test.Destination.Center; if (pt11 != pt21 && pt11 != pt22 && pt12 != pt21 && pt12 != pt22) { if (new Line(pt11, pt12).IntersectSegment(pt21, pt22).X != float.PositiveInfinity) { crossings++; v1D.Crossings++; v2D.Crossings++; } } } SpringEdgeData data = (SpringEdgeData)edge.GetData(_SpringEdge); data.Crossings = crossings; }
private void SetGraphElements() { _nodes = new GraphNode[_tempGraph.Nodes.Count]; _links = new GraphLink[_tempGraph.Links.Count]; for (int i = 0; i < _tempGraph.Nodes.Count; i++) { _nodes[i] = _tempGraph.Nodes[i] as GraphNode; } for (int i = 0; i < _tempGraph.Links.Count; i++) { _links[i] = _tempGraph.Links[i] as GraphLink; } _sharedNode = new bool[_links.Length, _links.Length]; for (int i = 0; i < _links.Length; i++) { for (int j = 0; j < _links.Length; j++) { _sharedNode[i, j] = (i == j) || _links[i].Origin == _links[j].Origin || _links[i].Origin == _links[j].Destination || _links[i].Destination == _links[j].Destination || _links[i].Destination == _links[j].Origin; } } _nodeLink = new bool[_nodes.Length, _links.Length]; for (int i = 0; i < _nodes.Length; i++) { for (int j = 0; j < _links.Length; j++) { _nodeLink[i, j] = _nodes[i].InLinks.Contains(_links[j]) || _nodes[i].OutLinks.Contains(_links[j]); } } }
private float lengthFix(GraphLink link) { return(lengthFix(link.Origin, link.Destination)); }
private int countCrossings(GraphLink link) { float k1, k2, cpx, cpy; PointF crossingPoint; int crossingCount = 0; PointF o1 = link.Origin.Center; PointF d1 = link.Destination.Center; for (int i = 0; i < _links.GetLength(0); i++) { if (link.Origin == _links[i].Origin) { continue; } if (link.Origin == _links[i].Destination) { continue; } if (link.Destination == _links[i].Origin) { continue; } if (link.Destination == _links[i].Destination) { continue; } PointF o2 = _links[i].Origin.Center; PointF d2 = _links[i].Destination.Center; if ((o1.X == d1.X) && (o2.X == d2.X)) { continue; } if ((o1.Y == d1.Y) && (o2.Y == d2.Y)) { continue; } if (o1.X == d1.X) { cpx = d1.X; k2 = (o2.Y - d2.Y) / (o2.X - d2.X); cpy = o2.Y - k2 * (o2.X - cpx); } else if (o2.X == d2.X) { cpx = o2.X; k1 = (o1.Y - d1.Y) / (o1.X - d1.X); cpy = o1.Y - k1 * (o1.X - cpx); } else { k1 = (o1.Y - d1.Y) / (o1.X - d1.X); k2 = (o2.Y - d2.Y) / (o2.X - d2.X); if (k1 == k2) { continue; } cpx = (o2.Y + k1 * o1.X - o1.Y - k2 * o2.X) / (k1 - k2); cpy = -k2 * (o2.X - cpx) + o2.Y; } crossingPoint = new PointF(cpx, cpy); if (Math.Abs(LinkLength(link) - (DistanceBetweenPoints(crossingPoint, o1) + DistanceBetweenPoints(crossingPoint, d1))) <= .00001 && Math.Abs(LinkLength(_links[i]) - (DistanceBetweenPoints(crossingPoint, o2) + DistanceBetweenPoints(crossingPoint, d2))) <= .00001) { crossingCount++; } } return(crossingCount); }
private float LinkLength(GraphLink link) { return(DistanceBetweenPoints(link.Origin.Center, link.Destination.Center)); }
private void Dummify() { ArrayList links = new ArrayList(_graph.Links); foreach (GraphLink link in links) { GraphNode o = link.Origin; GraphNode d = link.Destination; int oLayer = (int)o.GetData(_Layer); int dLayer = (int)d.GetData(_Layer); double oPos = (double)o.GetData(_GridPosition); double dPos = (double)d.GetData(_GridPosition); double step = (dPos - oPos) / Math.Abs(dLayer - oLayer); GraphNode p = o; if (oLayer - dLayer > 1) { for (int i = oLayer - 1; i > dLayer; i--) { GraphNode newNode = new GraphNode(o.Bounds); ArrayList layer = _layers[i] as ArrayList; double pos = (i - dLayer) * step + oPos; if (pos > layer.Count) pos = layer.Count; // Check if origin and dest are both last if (oPos >= (_layers[oLayer] as ArrayList).Count - 1 && dPos >= (_layers[dLayer] as ArrayList).Count - 1) pos = layer.Count; // Check if origin and destination are both first else if (oPos == 0 && dPos == 0) pos = 0; newNode.SetData(_Layer, i); newNode.SetData(_UBaryCenter, 0.0); newNode.SetData(_DBaryCenter, 0.0); newNode.SetData(_ULinkCount, 0); newNode.SetData(_DLinkCount, 0); newNode.SetData(_GridPosition, pos); newNode.SetData(_Dummy, true); layer.Insert((int)pos, newNode); // Translate rightwards nodes' positions for (int r = (int)pos + 1; r < layer.Count; r++) { GraphNode node = layer[r] as GraphNode; node.SetData(_GridPosition, (double)node.GetData(_GridPosition) + 1); } GraphLink newLink = new GraphLink(p, newNode); newLink.SetData(_DummificationLevel, 0); p = newNode; // Add the new node and the new link to the graph _graph.Nodes.Add(newNode); _graph.Links.Add(newLink); } // Set the origin of the real arrow to the last dummy link.Origin = p; link.SetData(_DummificationLevel, oLayer - dLayer - 1); } if (oLayer - dLayer < -1) { for (int i = oLayer + 1; i < dLayer; i++) { GraphNode newNode = new GraphNode(o.Bounds); ArrayList layer = _layers[i] as ArrayList; double pos = (i - oLayer) * step + oPos; if (pos > layer.Count) pos = layer.Count; // Check if origin and dest are both last if (oPos >= (_layers[oLayer] as ArrayList).Count - 1 && dPos >= (_layers[dLayer] as ArrayList).Count - 1) pos = layer.Count; // Check if origin and destination are both first else if (oPos == 0 && dPos == 0) pos = 0; newNode.SetData(_Layer, i); newNode.SetData(_UBaryCenter, 0.0); newNode.SetData(_DBaryCenter, 0.0); newNode.SetData(_ULinkCount, 0); newNode.SetData(_DLinkCount, 0); newNode.SetData(_GridPosition, pos); newNode.SetData(_Dummy, true); layer.Insert((int)pos, newNode); // Translate rightwards nodes' positions for (int r = (int)pos + 1; r < layer.Count; r++) { GraphNode node = layer[r] as GraphNode; node.SetData(_GridPosition, (double)node.GetData(_GridPosition) + 1); } GraphLink newLink = new GraphLink(p, newNode); newLink.SetData(_DummificationLevel, 0); p = newNode; // Add the new node and the new link to the graph _graph.Nodes.Add(newNode); _graph.Links.Add(newLink); } // Set the origin of the real arrow to the last dummy link.Origin = p; link.SetData(_DummificationLevel, dLayer - oLayer - 1); } } }
private float lengthFix(GraphLink link) { return lengthFix(link.Origin, link.Destination); }
private int countCrossings(GraphLink link) { float k1, k2, cpx, cpy; PointF crossingPoint; int crossingCount = 0; PointF o1 = link.Origin.Center; PointF d1 = link.Destination.Center; for (int i = 0; i < _links.GetLength(0); i++) { if (link.Origin == _links[i].Origin) continue; if (link.Origin == _links[i].Destination) continue; if (link.Destination == _links[i].Origin) continue; if (link.Destination == _links[i].Destination) continue; PointF o2 = _links[i].Origin.Center; PointF d2 = _links[i].Destination.Center; if ((o1.X == d1.X) && (o2.X == d2.X)) continue; if ((o1.Y == d1.Y) && (o2.Y == d2.Y)) continue; if (o1.X == d1.X) { cpx = d1.X; k2 = (o2.Y - d2.Y) / (o2.X - d2.X); cpy = o2.Y - k2 * (o2.X - cpx); } else if (o2.X == d2.X) { cpx = o2.X; k1 = (o1.Y - d1.Y) / (o1.X - d1.X); cpy = o1.Y - k1 * (o1.X - cpx); } else { k1 = (o1.Y - d1.Y) / (o1.X - d1.X); k2 = (o2.Y - d2.Y) / (o2.X - d2.X); if (k1 == k2) continue; cpx = (o2.Y + k1 * o1.X - o1.Y - k2 * o2.X) / (k1 - k2); cpy = -k2 * (o2.X - cpx) + o2.Y; } crossingPoint = new PointF(cpx, cpy); if (Math.Abs(LinkLength(link) - (DistanceBetweenPoints(crossingPoint, o1) + DistanceBetweenPoints(crossingPoint, d1))) <= .00001 && Math.Abs(LinkLength(_links[i]) - (DistanceBetweenPoints(crossingPoint, o2) + DistanceBetweenPoints(crossingPoint, d2))) <= .00001) { crossingCount++; } } return crossingCount; }
private float LinkLength(GraphLink link) { return DistanceBetweenPoints(link.Origin.Center, link.Destination.Center); }
private void SetGraphElements() { _nodes = new GraphNode[_tempGraph.Nodes.Count]; _links = new GraphLink[_tempGraph.Links.Count]; for (int i = 0; i < _tempGraph.Nodes.Count; i++) _nodes[i] = _tempGraph.Nodes[i] as GraphNode; for (int i = 0; i < _tempGraph.Links.Count; i++) _links[i] = _tempGraph.Links[i] as GraphLink; _sharedNode = new bool[_links.Length, _links.Length]; for (int i = 0; i < _links.Length; i++) { for (int j = 0; j < _links.Length; j++) { _sharedNode[i, j] = (i == j) || _links[i].Origin == _links[j].Origin || _links[i].Origin == _links[j].Destination || _links[i].Destination == _links[j].Destination || _links[i].Destination == _links[j].Origin; } } _nodeLink = new bool[_nodes.Length, _links.Length]; for (int i = 0; i < _nodes.Length; i++) { for (int j = 0; j < _links.Length; j++) { _nodeLink[i,j] = _nodes[i].InLinks.Contains(_links[j]) || _nodes[i].OutLinks.Contains(_links[j]); } } }
private void CountEdgeCrossings(GraphLink edge) { int crossings = 0; GraphNode v1 = edge.Origin; GraphNode v2 = edge.Destination; SpringVertexData v1D = (SpringVertexData)v1.GetData(_SpringVertex); SpringVertexData v2D = (SpringVertexData)v2.GetData(_SpringVertex); PointF pt = new PointF(0, 0), pt11, pt12, pt21, pt22; pt11 = v1.Center; pt12 = v2.Center; foreach(GraphLink test in _graph.Links) { if(edge == test) continue; pt21 = test.Origin.Center; pt22 = test.Destination.Center; if(pt11 != pt21 && pt11 != pt22 && pt12 != pt21 && pt12 != pt22) { if (new Line(pt11, pt12).IntersectSegment(pt21, pt22).X != float.PositiveInfinity) { crossings++; v1D.Crossings++; v2D.Crossings++; } } } SpringEdgeData data = (SpringEdgeData)edge.GetData(_SpringEdge); data.Crossings = crossings; }