public DirectoryInfo DirectoryForTile(TileId id) { string path = Path.Combine(directory.FullName, Municipalities.map[id].ToString()); return(new DirectoryInfo(path)); }
public Municipality Find(TileId tile) { var tilePolygon = tile.Polygon; return(municipalities.Values .OrderByDescending(m => Intersection(tilePolygon, m)) .First()); }
private void MapView_TileClicked(TileId tileId) { if (jobRunner.jobs != null) { lstJobs.ItemsSource = jobRunner.jobs.Where(j => j.Tile.Id.Equals(tileId)); } selectedTile = tileId; }
internal Tile GenerateTile(TileId id) { var dir = DirectoryForTile(id); if (!dir.Exists) { Directory.CreateDirectory(dir.FullName); } return(new Tile(id, dir)); }
public override bool Equals(object obj) { if (obj.GetType() != typeof(TileId)) { return(false); } TileId t = (TileId)obj; return(t.X == X && t.Y == Y); }
public Municipality FindNearest(TileId tile) { int x = (tile.Left + tile.Right) / 2; int y = (tile.Bottom + tile.Top) / 2; var mun = municipalities.Values.OrderBy(m => { return(Math.Pow(x - m.X, 2) + Math.Pow(y - m.Y, 2)); } ).First(); return(mun); }
private void MapView_TileSelected(TileId tileId) { if (selectedTile == null) { var stage = ""; if (repository.Tiles.ContainsKey(tileId)) { stage = Enum.GetName(typeof(Stages), repository.Tiles[tileId].Stage); } var municipality = repository.Municipalities.municipalities?[repository.Municipalities.map[tileId]]; lblTile.Content = tileId.X + " " + tileId.Y + " " + municipality?.Name + " (" + municipality?.Id + ") " + stage; } }
public void Load(DirectoryInfo directory, Action <double> d) { logFile?.Flush(); logFile?.Close(); this.directory = directory; string logFileName = directory.FullName + "/pipeline.log"; if (!File.Exists(logFileName)) { File.Create(logFileName); } logFile = new FileStream(logFileName, FileMode.Append); logFile.Write(new byte[] { 0x31, 0x32, 0x33 }, 0, 3); logFile.Flush(); ResetMap(); var municipalityDirs = directory.GetDirectories(); int i = 0; foreach (var municipalityDir in municipalityDirs) { d?.Invoke((double)(++i) / municipalityDirs.Length); foreach (var file in municipalityDir.GetFiles()) { if (file.FullName.EndsWith(".laz")) { try { var s = (Stages)Convert.ToInt32(file.Name.Split('-')[0]); TileId id = new TileId(file.Name); if (Tiles.ContainsKey(id)) { Tiles[id].AddFile(file); } else { Tiles[id] = new Tile(file); } FillBlock(id.X, id.Y, Tiles[id].TileColor); } catch { } } } } UpdateMap(); }
public void BuildMap(int xmin, int ymin, int xmax, int ymax) { map = new Dictionary <TileId, int>(); for (int x = xmin; x <= xmax; x++) { for (int y = ymin; y <= ymax; y++) { TileId id = new TileId(x, y); var m = Find(id); if (Intersection(id.Polygon, m) == 0) { m = FindNearest(id); } map[id] = m.Id; } } }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { if (reader.TokenType == JsonToken.Null) { return(null); } var intermediateDictionary = new Dictionary <string, int>(); serializer.Populate(reader, intermediateDictionary); Dictionary <TileId, int> finalDictionary = new Dictionary <TileId, int>(); foreach (var pair in intermediateDictionary) { var s = pair.Key.Split(' '); var key = new TileId(Convert.ToInt32(s[0]), Convert.ToInt32(s[1])); finalDictionary[key] = pair.Value; } return(finalDictionary); }
public async Task RunArea(int x1, int y1, int x2, int y2, Municipality m) { cancellationSource = new CancellationTokenSource(); jobs = new ObservableCollection <Job>(); Dictionary <TileId, Tile> tiles = new Dictionary <TileId, Tile>(); for (int x = x1; x <= x2; x++) { for (int y = y1; y <= y2; y++) { TileId id = new TileId(x, y); if (repository.Municipalities.map[id] != m.Id) { continue; } if (repository.Tiles.ContainsKey(id)) { tiles[id] = repository.Tiles[id]; } else { var tile = repository.GenerateTile(id); tiles[id] = repository.Tiles[id] = tile; } repository.UpdateTile(tiles[id]); } } waitingQueue = new BufferBlock <Tile>(new DataflowBlockOptions() { EnsureOrdered = true }); workerBlock = new TransformBlock <Tile, Tile>(async t => { t.Rescan(repository.DirectoryForTile(t.Id)); var job = Job.NextJob(t); if (job == null) { return(t); } JobStarted.Invoke(this, job); await job.Run(cancellationSource.Token, Cleanup); t.Rescan(repository.DirectoryForTile(t.Id)); JobFinished.Invoke(this, job); byte[] csvLine = job.CsvBytes; repository.logFile.Write(csvLine, 0, csvLine.Length); repository.logFile.Flush(); return(t); }, new ExecutionDataflowBlockOptions() { CancellationToken = cancellationSource.Token, MaxDegreeOfParallelism = workers, }); //ActionBlock<Tile> mapUpdater = new ActionBlock<Tile>(t => repository.UpdateTile(t)); TaskCompletionSource <int> finishTask = new TaskCompletionSource <int>(); int finishedCounter = tiles.Count; ActionBlock <Tile> tileFinished = new ActionBlock <Tile>(t => { finishedCounter--; if (finishedCounter == 0) { finishTask.SetResult(finishedCounter); } }); waitingQueue.LinkTo(workerBlock); link = workerBlock.LinkTo(waitingQueue, t => Job.NextJob(t) != null); workerBlock.LinkTo(tileFinished, t => Job.NextJob(t) == null); //workerBlock.LinkTo(mapUpdater); foreach (var pair in tiles) { await waitingQueue.SendAsync(pair.Value); } await finishTask.Task; }
public Tile(TileId id, DirectoryInfo path) { this.Id = id; Files[Stages.Unknown] = new FileInfo(Path.Combine(path.FullName, id.GetFilename(Stages.Unknown))); Files[Stages.Unknown].Create(); }
/*public Polygon2d Polygon => new Polygon2d(new Vector2d[] { * new Vector2d(id.Left, id.Bottom), * new Vector2d(id.Right, id.Bottom), * new Vector2d(id.Right, id.Top), * new Vector2d(id.Left, id.Top) * });*/ public Tile(FileInfo file) { string[] parts = file.Name.Replace(".laz", "").Split('-'); Id = new TileId(Convert.ToInt32(parts[1]), Convert.ToInt32(parts[2])); Files[(Stages)Convert.ToInt32(parts[0])] = file; }