internal int TryInsertingNodesAndRoutes(int numNodesToInsert, Dictionary <SymmetricTuple <LgNodeInfo>, List <Point> > trajectories, List <SymmetricSegment> oldSegments, int zoomLevel, int numNodesOnPreviousLevel, GridTraversal grid, LgPathRouter pathRouter) { MarkAllNodesNotProcessed(); _segmentTileTable = new Dictionary <Tuple <int, int>, int>(); _nodeTileTable = new Dictionary <Tuple <int, int>, int>(); var canAddOldSegments = TryAddingOldSegments(oldSegments, grid); if (!canAddOldSegments) { return(0); } AddOldNodes(numNodesOnPreviousLevel, grid); int i; for (i = numNodesOnPreviousLevel; i < numNodesToInsert; i++) { var ni = SortedLgNodeInfos[i]; var nodeTile = grid.PointToTuple(ni.Center); if (!_nodeTileTable.ContainsKey(nodeTile)) { _nodeTileTable[nodeTile] = 0; } if (_nodeTileTable[nodeTile] >= MaxNodesPerTile(zoomLevel)) //test MaxAmountNodesPerTile { ShowDebugInsertedSegments(grid, zoomLevel, ni, null, null); break; } Set <VisibilityEdge> edges = GetSegmentsOnPathsToInsertedNeighborsNotOnOldTrajectories(ni, trajectories, pathRouter); Set <SymmetricSegment> segments = new Set <SymmetricSegment>( edges.Select(e => new SymmetricSegment(e.SourcePoint, e.TargetPoint))); var newToAdd = segments.Where(seg => !IsSegmentAlreadyAdded(seg)).ToList(); Set <SymmetricSegment> insertedSegments; bool canInsertPaths = TryAddingSegmentsUpdateTiles(newToAdd, grid, out insertedSegments); if (canInsertPaths) { AddSegmentsToRtree(newToAdd); ni.Processed = true; _nodeTileTable[nodeTile]++; _insertedNodes.Add(ni); continue; } //debug output //AddSegmentsToRtree(newToAdd); //remove // ShowDebugInsertedSegments(grid, zoomLevel, ni, newToAdd, segments); break; } var nextNode = numNodesToInsert < SortedLgNodeInfos.Count ? SortedLgNodeInfos[numNodesToInsert] : null; // ShowDebugInsertedSegments(grid, zoomLevel, nextNode, null, null); return(i); }
internal int TryInsertingNodesAndRoutes(int numNodesToInsert, Dictionary<SymmetricTuple<LgNodeInfo>, List<Point>> trajectories, List<SymmetricSegment> oldSegments, int zoomLevel, int numNodesOnPreviousLevel, GridTraversal grid, LgPathRouter pathRouter) { MarkAllNodesNotProcessed(); _segmentTileTable = new Dictionary<Tuple<int, int>, int>(); _nodeTileTable = new Dictionary<Tuple<int, int>, int>(); var canAddOldSegments = TryAddingOldSegments(oldSegments, grid); if (!canAddOldSegments) { return 0; } AddOldNodes(numNodesOnPreviousLevel, grid); int i; for (i = numNodesOnPreviousLevel; i < numNodesToInsert; i++) { var ni = SortedLgNodeInfos[i]; var nodeTile = grid.PointToTuple(ni.Center); if (!_nodeTileTable.ContainsKey(nodeTile)) _nodeTileTable[nodeTile] = 0; if (_nodeTileTable[nodeTile] >= MaxNodesPerTile(zoomLevel)) //test MaxAmountNodesPerTile { ShowDebugInsertedSegments(grid, zoomLevel, ni, null, null); break; } Set<VisibilityEdge> edges = GetSegmentsOnPathsToInsertedNeighborsNotOnOldTrajectories(ni, trajectories, pathRouter); Set<SymmetricSegment> segments = new Set<SymmetricSegment>( edges.Select(e => new SymmetricSegment(e.SourcePoint, e.TargetPoint))); var newToAdd = segments.Where(seg => !IsSegmentAlreadyAdded(seg)).ToList(); Set<SymmetricSegment> insertedSegments; bool canInsertPaths = TryAddingSegmentsUpdateTiles(newToAdd, grid, out insertedSegments); if (canInsertPaths) { AddSegmentsToRtree(newToAdd); ni.Processed = true; _nodeTileTable[nodeTile]++; _insertedNodes.Add(ni); continue; } //debug output //AddSegmentsToRtree(newToAdd); //remove // ShowDebugInsertedSegments(grid, zoomLevel, ni, newToAdd, segments); break; } var nextNode = numNodesToInsert < SortedLgNodeInfos.Count ? SortedLgNodeInfos[numNodesToInsert] : null; // ShowDebugInsertedSegments(grid, zoomLevel, nextNode, null, null); return i; }
private Set <VisibilityEdge> GetSegmentsOnPathsToInsertedNeighborsNotOnOldTrajectories(LgNodeInfo ni, Dictionary <SymmetricTuple <LgNodeInfo>, List <Point> > trajectories, LgPathRouter pathRouter) { var edges = new Set <VisibilityEdge>(); var neighbors = GetAdjacentProcessed(ni); foreach (var neighb in neighbors) { var t1 = new SymmetricTuple <LgNodeInfo>(ni, neighb); List <Point> trajectory; if (trajectories.ContainsKey(t1)) { trajectory = trajectories[t1]; } else { continue; } for (int i = 0; i < trajectory.Count - 1; i++) { var p0 = trajectory[i]; var p1 = trajectory[i + 1]; var e = pathRouter.FindEdge(p0, p1); Debug.Assert(e != null, "VisibilityEdge on trajectory not found!"); if (!pathRouter.IsOnOldTrajectory(e)) { edges.Insert(e); } } } return(edges); }
private Set<VisibilityEdge> GetSegmentsOnPathsToInsertedNeighborsNotOnOldTrajectories(LgNodeInfo ni, Dictionary<SymmetricTuple<LgNodeInfo>, List<Point>> trajectories, LgPathRouter pathRouter) { var edges = new Set<VisibilityEdge>(); var neighbors = GetAdjacentProcessed(ni); foreach (var neighb in neighbors) { var t1 = new SymmetricTuple<LgNodeInfo>(ni, neighb); List<Point> trajectory; if (trajectories.ContainsKey(t1)) trajectory = trajectories[t1]; else continue; for (int i = 0; i < trajectory.Count - 1; i++) { var p0 = trajectory[i]; var p1 = trajectory[i + 1]; var e = pathRouter.FindEdge(p0, p1); Debug.Assert(e!=null, "VisibilityEdge on trajectory not found!"); if (!pathRouter.IsOnOldTrajectory(e)) { edges.Insert(e); } } } return edges; }