internal bool Run() { if (metroGraphData.Edges.Count() == 0) { return(false); } var splittingPoints = new Dictionary <PointPair, List <Point> >(); var treeOfVertices = new RTree <Point, Point>(); foreach (var vertex in Vertices()) { var r = new Rectangle(vertex.Point); r.Pad(ApproximateComparer.IntersectionEpsilon); treeOfVertices.Add(r, vertex.Point); } var treeOfEdges = RectangleNode <PointPair, Point> .CreateRectangleNodeOnData(Edges(), e => new Rectangle(e.First, e.Second)); RectangleNodeUtils.CrossRectangleNodes <PointPair, Point>(treeOfEdges, treeOfEdges, (a, b) => IntersectTwoEdges(a, b, splittingPoints, treeOfVertices)); SortInsertedPoints(splittingPoints); bool pointsInserted = InsertPointsIntoPolylines(splittingPoints); bool progress = FixPaths(); bool pointsRemoved = RemoveUnimportantCrossings(); return(progress || pointsInserted || pointsRemoved); }
private bool OverlapsExist() { if (this.Root == null) { return(false); } RectangleNodeUtils.CrossRectangleNodes <Obstacle, Point>(this.Root, this.Root, this.CheckForInitialOverlaps); return(this.hasOverlaps); }
static IEnumerable <IntPair> EnumeratePairsOfIntersectedPreGraphs(List <PreGraph> preGraphs) { var rn = RectangleNode <int> .CreateRectangleNodeOnData(Enumerable.Range(0, preGraphs.Count), i => preGraphs[i].boundingBox); var list = new List <IntPair>(); RectangleNodeUtils.CrossRectangleNodes <int>(rn, rn, (a, b) => list.Add(new IntPair(a, b))); return(list); }
void FillTheMapOfShapeToTightLooseCouples() { var childrenShapeHierarchy = RectangleNode <Shape> .CreateRectangleNodeOnEnumeration( MainShape.Children.Select(s => new RectangleNode <Shape>(s, s.BoundingBox))); RectangleNodeUtils.CrossRectangleNodes(childrenShapeHierarchy, coupleHierarchy, TryMapShapeToTightLooseCouple); }
private void AccumulateObstaclesForGroupOverlaps() { var groupObstacles = CalculateHierarchy(this.GetAllObstacles().Where(obs => obs.IsGroup)); var allPrimaryObstacles = CalculateHierarchy(this.GetAllObstacles().Where(obs => obs.IsPrimaryObstacle)); if ((groupObstacles == null) || (allPrimaryObstacles == null)) { return; } RectangleNodeUtils.CrossRectangleNodes <Obstacle, Point>(groupObstacles, allPrimaryObstacles, this.EvaluateOverlappedPairForGroup); }
private void AccumulateObstaclesForConvexHulls() { this.overlapPairs.Clear(); var allPrimaryNonGroupObstacles = CalculateHierarchy(this.GetAllObstacles().Where(obs => obs.IsPrimaryObstacle && !obs.IsGroup)); if (allPrimaryNonGroupObstacles == null) { return; } RectangleNodeUtils.CrossRectangleNodes <Obstacle, Point>(allPrimaryNonGroupObstacles, allPrimaryNonGroupObstacles, this.EvaluateOverlappedPairForConvexHull); }
private void AccumulateObstaclesForClumps() { this.overlapPairs.Clear(); var rectangularObstacles = CalculateHierarchy(this.GetAllObstacles().Where(obs => !obs.IsGroup && obs.IsRectangle)); if (rectangularObstacles == null) { return; } RectangleNodeUtils.CrossRectangleNodes <Obstacle, Point>(rectangularObstacles, rectangularObstacles, this.EvaluateOverlappedPairForClump); }
int CreateProximityEdgesWithRTree(List <Tuple <int, int, double, double> > proximityEdges) { var edgeSet = new HashSet <Tuple <int, int> >(); foreach (var proximityEdge in proximityEdges) { edgeSet.Add(Tuple.Create(proximityEdge.Item1, proximityEdge.Item2)); } RectangleNode <int> rootNode = RectangleNode <int> .CreateRectangleNodeOnEnumeration( nodeSizes.Select((size, index) => new RectangleNode <int>(index, new Rectangle(size, nodePositions[index])))); int numCrossings = 0; RectangleNodeUtils.CrossRectangleNodes <int, int>(rootNode, rootNode, (a, b) => { if (a == b) { return; } double t; double dist = GetOverlapFactorBetweenNodes ( a, b, nodePositions[a ], nodePositions[b ], nodeSizes, out t); int smallId = a; int bigId = b; if (smallId > bigId) { smallId = b; bigId = a; } if (!(t > 1) || edgeSet.Contains(new Tuple <int, int>(smallId, bigId))) { return; } proximityEdges.Add(Tuple.Create(smallId, bigId, dist, t)); edgeSet.Add(new Tuple <int, int>(smallId, bigId)); numCrossings++; }); return(numCrossings); }
internal static Set <Tuple <Polyline, Polyline> > GetOverlappedPairSet(RectangleNode <Polyline> rootOfObstacleHierarchy) { var overlappingPairSet = new Set <Tuple <Polyline, Polyline> >(); RectangleNodeUtils.CrossRectangleNodes <Polyline>(rootOfObstacleHierarchy, rootOfObstacleHierarchy, (a, b) => { if (PolylinesIntersect(a, b)) { overlappingPairSet.Insert( new Tuple <Polyline, Polyline>(a, b)); } }); return(overlappingPairSet); }
void SetVertexTriangles() { var triangleTree = RectangleNode <CdtTriangle, Point> .CreateRectangleNodeOnEnumeration( CdtProperty.GetTriangles().Select(t => new RectangleNode <CdtTriangle, Point>(t, t.BoundingBox()))); var vertexTree = RectangleNode <SdVertex, Point> .CreateRectangleNodeOnEnumeration( vertexArray.Select(v => new RectangleNode <SdVertex, Point>(v, new Rectangle(v.Point)))); RectangleNodeUtils.CrossRectangleNodes(triangleTree, vertexTree, TryToAssigenTriangleToVertex); // foreach (var v in vertexArray) { // Debug.Assert(v.Triangle != null); // } }
/// <summary> /// unite the nodes that are close to each other /// </summary> bool GlueConflictingNodes() { var circlesHierarchy = GetCirclesHierarchy(); if (circlesHierarchy == null) { return(false); } var gluingMap = new Dictionary <Station, Station>(); var gluedDomain = new Set <Station>(); RectangleNodeUtils.CrossRectangleNodes <Station>(circlesHierarchy, circlesHierarchy, (i, j) => TryToGlueNodes(i, j, gluingMap, gluedDomain)); if (gluingMap.Count == 0) { return(false); } for (int i = 0; i < metroGraphData.Edges.Length; i++) { RegenerateEdge(gluingMap, i); } //can it be more efficient? HashSet <Point> affectedPoints = new HashSet <Point>(); foreach (var s in gluedDomain) { affectedPoints.Add(s.Position); foreach (var neig in s.Neighbors) { if (!neig.IsRealNode) { affectedPoints.Add(neig.Position); } } } //TimeMeasurer.DebugOutput("gluing nodes"); metroGraphData.Initialize(false); SimulatedAnnealing.FixRouting(metroGraphData, bundlingSettings, affectedPoints); return(true); }
int CountCrossingsWithRTree(Size[] nodeSizes) { RectangleNode <int> rootNode = RectangleNode <int> .CreateRectangleNodeOnEnumeration( nodeSizes.Select((r, index) => new RectangleNode <int>(index, new Rectangle(r, nodePositions[index])))); int numCrossings = 0; RectangleNodeUtils.CrossRectangleNodes <int, int>(rootNode, rootNode, (a, b) => { if (a == b) { return; } numCrossings++; }); return(numCrossings); }