public static async Task Doit(Config config, TraceListener log, Action <Stream, FeatureInfo[][]> drawToScreen) { DateTime start = DateTime.Now; BlobHelper.SetConnectionString(ConfigurationManager.AppSettings["ConnectionString"]); int subpixel = 3; var compositeBmp = new DirectBitmap(subpixel * config.Width, subpixel * config.Height); Device.RenderState renderState = new Device.RenderState(compositeBmp) { Camera = new Camera() { MaxAngleRad = config.MaxAngleDec * Math.PI / 180, MinAngleRad = config.MinAngleDec * Math.PI / 180, HeightOffset = config.HeightOffset, }, }; var chunks = View.GetRelevantChunkKeys(config, log); StandardChunkMetadata mainChunk = StandardChunkMetadata.GetRangeFromKey(chunks.Last()); var mainMesh = await Meshes.Current.GetData(mainChunk, log); var norm = mainMesh.GetCenterAndScale( config.Lat.DecimalDegree, config.Lon.DecimalDegree, mainChunk.ZoomLevel, mainChunk.LatDelta.DecimalDegree, 10, log); int counter = 0; foreach (var chunkKey in chunks) { StandardChunkMetadata chunk = StandardChunkMetadata.GetRangeFromKey(chunkKey); if (chunk == null) { continue; } var mesh = await Meshes.Current.GetData(chunk, log); if (mesh == null) { continue; } mesh.Match(norm); try { mesh.ImageData = await JpegImages.Current.GetData(chunk, log); } catch { } if (mesh.ImageData == null) { DirectBitmap tmp = new DirectBitmap(10, 10); tmp.SetAllPixels(new MyColor(0, 0, 0, 255)); using (var mss = new MemoryStream()) { tmp.WriteFile(OutputType.PNG, mss); mss.Position = 0; mesh.ImageData = new byte[mss.Length]; mss.Read(mesh.ImageData, 0, mesh.ImageData.Length); } } using (var renderMesh = SoftEngine.Mesh.GetMesh(mesh)) { Device.RenderInto(renderState, renderMesh); renderState.UpdateLatLons(chunk.LatLo, chunk.LatDelta, chunk.LonLo, chunk.LonDelta); } counter++; log?.WriteLine(counter); } FeatureInfo[][] features = renderState.GetLatLons().Select(q => q.Select(p => !p.HasValue ? null : UsgsRawFeatures.GetData(p.Value)).ToArray()).ToArray(); string fileNameRoot = DateTime.Now.ToString("HHmmss"); //config.LocalTime = new DateTimeOffset(2019, 3, 5, 0, 0, 0, TimeSpan.FromHours(-8)); //while (config.LocalTime < new DateTimeOffset(2019, 3, 6, 0, 0, 0, TimeSpan.FromHours(-8))) { var skyColor = new Nishita(config.SunPos); using (DirectBitmap lighted = renderState.RenderLight(config.Light, config.DirectLight, config.AmbientLight, skyColor)) { drawToScreen?.Invoke(lighted.GetStream(OutputType.PNG), features); using (var fs = File.OpenWrite("final_" + config.LocalTime.ToString("HHmmss") + "_" + fileNameRoot + ".jpg")) { lighted.WriteFile(OutputType.JPEG, fs); } } //config.LocalTime = config.LocalTime.AddHours(1); } DateTime end = DateTime.Now; log?.WriteLine(start); log?.WriteLine(end); log?.WriteLine(end - start); }
public static async Task Test12(string outputFolder, TraceListener log, Action <MemoryStream> getBitmap = null) { var lat = Angle.FromDecimalDegrees(47.6867797); var lon = Angle.FromDecimalDegrees(-122.2907541); for (int i = 0; i <= StandardChunkMetadata.MaxZoomLevel; i++) { var k1 = StandardChunkMetadata.GetRangeContaingPoint(lat, lon, i); log?.WriteLine(i + ", 1: " + k1); } log?.WriteLine(lat.ToLatString() + "," + lon.ToLonString()); for (int zoomLevel = StandardChunkMetadata.MaxZoomLevel; zoomLevel >= 0; zoomLevel--) { var kay = StandardChunkMetadata.GetKey(lat.Fourths, lon.Fourths, zoomLevel); var xxx = StandardChunkMetadata.GetRangeFromKey(kay); var cc = StandardChunkMetadata.GetRangeContaingPoint(lat, lon, zoomLevel); if (cc == null) { log?.WriteLine("Chunk is null"); } else { log?.Write(zoomLevel + "\t" + cc.LatDelta); log?.WriteLine("\t" + cc.LatLo.ToLatString() + "," + cc.LonLo.ToLonString() + ", " + cc.LatHi.ToLatString() + "," + cc.LonHi.ToLonString()); var template = cc; try { var pixels2 = await Heights.Current.GetData(template, log); if (pixels2 != null) { Utils.WriteImageFile(pixels2, Path.Combine(outputFolder, "AChunkH" + zoomLevel + ".png"), a => Utils.GetColorForHeight(a), OutputType.JPEG); getBitmap?.Invoke(Utils.GetBitmap(pixels2, a => Utils.GetColorForHeight(a), OutputType.JPEG)); } } catch (Exception ex) { log?.WriteLine(ex.Message); } try { var pixels = await Images.Current.GetData(template, log); if (pixels != null) { Utils.WriteImageFile(pixels, Path.Combine(outputFolder, "AChunkC" + zoomLevel + ".png"), a => a, OutputType.JPEG); getBitmap?.Invoke(Utils.GetBitmap(pixels, a => a, OutputType.JPEG)); } } catch (Exception ex) { log?.WriteLine(ex.Message); } } } }