private byte[] ReadChunk(BlobHelper.DeletableFileStream stream, StandardChunkMetadata template) { byte[] imageData = new byte[stream.Stream.Length]; stream.Seek(0, SeekOrigin.Begin); stream.Read(imageData, 0, imageData.Length); return(imageData); }
public static async Task Test1(string outputFolder, TraceListener log) { var homeLat = Angle.FromDecimalDegrees(47.6867797); var homeLon = Angle.FromDecimalDegrees(-122.2907541); var scm = StandardChunkMetadata.GetRangeContaingPoint(homeLat, homeLon, 4); var xxx = await Images.Current.GetData(scm, log); Utils.WriteImageFile(xxx, Path.Combine(outputFolder, "xxx.jpg"), a => a, OutputType.JPEG); var yyy = await Heights.Current.GetData(scm, log); Utils.WriteImageFile(yyy, Path.Combine(outputFolder, "yyy.jpg"), a => Utils.GetColorForHeight(a), OutputType.JPEG); //var newONe = AdfReaderWorker.GetChunk(@"C:\Users\jrcoo\Desktop\Map\n48w123\grdn48w123_13"); //// Utils.WriteImageFile(newONe, Path.Combine(outputFolder, "newONe.png"), a => Utils.GetColorForHeight(a)); //ChunkHolder<float> ddd = newONe.RenderSubChunk(homeLat, homeLon, // Angle.FromMinutes(2), Angle.FromMinutes(2), // Angle.FromThirds(20), Angle.FromThirds(20), // Utils.WeightedFloatAverage); //Utils.WriteImageFile(ddd, Path.Combine(outputFolder, "ddd.png"), a => Utils.GetColorForHeight(a)); //var tttt = ImageWorker.GetColors(homeLat, homeLon, 13).Result; ////ChunkHolder<MyColor> ddd2 = tttt.RenderSubChunk(homeLat, homeLon, //// Angle.FromMinutes(2), Angle.FromMinutes(2), //// Angle.FromThirds(20), Angle.FromThirds(20), //// Utils.WeightedColorAverage); //Utils.WriteImageFile(tttt, Path.Combine(outputFolder, "tttt.png"), a => a); ////Utils.WriteImageFile(ddd2, Path.Combine(outputFolder, "ddd2.png"), a => a); }
private async Task <Tuple <string, FriendlyMesh> > GetComputedChunk(StandardChunkMetadata template, TraceListener log) { string filename = GetShortFilename(template); Tuple <string, FriendlyMesh> ret = new Tuple <string, FriendlyMesh>(GetFullFileName(template, filename), null); try { using (BlobHelper.DeletableFileStream ms = await BlobHelper.TryGetStreamAsync(cachedFileContainer, ret.Item1, log)) { if (ms != null) { ret = new Tuple <string, FriendlyMesh>(ret.Item1, ReadChunk(ms, template)); } } } catch (StorageException stex) { if (stex.RequestInformation.HttpStatusCode == 404) { log?.WriteLine("Blob not found;"); } else { throw; } } return(ret); }
public async Task <NearestInterpolatingChunk <T> > GetLazySimpleInterpolator(StandardChunkMetadata template, TraceListener log) { if (template == null) { return(null); } string filename = GetShortFilename(template); string fullFileName = GetFullFileName(template, filename); while ( !(await BlobHelper.BlobExists(cachedFileContainer, fullFileName, log)) && template.ZoomLevel > SourceDataZoom) { template = template.GetParentChunk(); return(await GetLazySimpleInterpolator(template, log)); } byte[] buffer = new byte[Math.Max(4, pixelDataSize)]; return(new NearestInterpolatingChunk <T>( template.LatLo.DecimalDegree, template.LonLo.DecimalDegree, template.LatHi.DecimalDegree, template.LonHi.DecimalDegree, template.LatSteps, template.LonSteps, cachedFileContainer, fullFileName, (ms, i, j) => { ms.Seek(8 + pixelDataSize * (i * template.LatSteps + j), SeekOrigin.Begin); return ReadPixel(ms, buffer); })); }
//public static async Task<FriendlyMesh> GetMesh(TraceListener log, double latD, double lonD, int zoomLevel = 5) //{ // // 5 is most zoomed in. // BlobHelper.SetConnectionString(ConfigurationManager.AppSettings["ConnectionString"]); // var lat = Angle.FromDecimalDegrees(latD); // var lon = Angle.FromDecimalDegrees(lonD); // log?.WriteLine(lat.ToLatString() + "," + lon.ToLonString()); // var template = StandardChunkMetadata.GetRangeContaingPoint(lat, lon, zoomLevel); // log?.WriteLine(template); // var m = await Meshes.Current.GetData(template, log); // if (m != null) // { // m.ImageData = await JpegImages.Current.GetData(template, log); // } // return m; //} //public static async Task ImagesForTopChunks(string outputFolder, TraceListener log) //{ // var x = await BlobHelper.GetFiles("mapv8", "", log); // var top = new Regex(@"\d\d\dDn\d\d\dDw03[.]v8.*"); // var t = x.Where(p => top.IsMatch(p)).ToArray(); // foreach (var f in t) // { // var parts = f.Split('D', 'n'); // var lat = Angle.FromDecimalDegrees(+int.Parse(parts[0]) + 0.5); // var lon = Angle.FromDecimalDegrees(-int.Parse(parts[2]) + 0.5); // var scm = StandardChunkMetadata.GetRangeContaingPoint(lat, lon, 3); // if (f.EndsWith(".idata")) // { // var xxx = await Images.Current.GetData(scm, log); // Utils.WriteImageFile(xxx, Path.Combine(outputFolder, f + ".jpg"), a => a, OutputType.JPEG); // } // else // { // var yyy = await Heights.Current.GetData(scm, log); // Utils.WriteImageFile(yyy, Path.Combine(outputFolder, f + ".jpg"), a => Utils.GetColorForHeight(a), OutputType.JPEG); // } // } //} public static async Task ProcessRawData(Angle lat, Angle lon, TraceListener log) { // Generate for a 1 degree square region. StandardChunkMetadata template = StandardChunkMetadata.GetRangeContaingPoint(lat, lon, 3); await ProcessRawData(template, log); }
public static async Task Test3(string outputFolder, Angle lat, Angle lon, TraceListener log) { for (int zoomLevel = 5; zoomLevel >= 3; zoomLevel--) { StandardChunkMetadata template = StandardChunkMetadata.GetRangeContaingPoint(lat, lon, zoomLevel); 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); } var pixels = await Images.Current.GetData(template, log); if (pixels != null) { Utils.WriteImageFile(pixels, Path.Combine(outputFolder, "AChunkC" + zoomLevel + ".png"), a => a, OutputType.JPEG); } //var pixels3 = await Features.Current.GetData(template, log); //if (pixels3 != null) //{ // Utils.WriteImageFile(pixels3, // Path.Combine(outputFolder, "AChunkF" + zoomLevel + ".jpg"), // a => a, // OutputType.JPEG);// new MyColor((byte)((a - short.MinValue) / 256), (byte)((a - short.MinValue) % 256), 0)); //} } }
protected override async Task <ChunkHolder <float> > GenerateData(StandardChunkMetadata template, TraceListener log) { var ret = new ChunkHolder <float>( template.LatSteps, template.LonSteps, template.LatLo, template.LonLo, template.LatHi, template.LonHi, null, toDouble, fromDouble); int latMin = (int)(Math.Min(template.LatLo.DecimalDegree, template.LatHi.DecimalDegree) + 1.0e-5); int latMax = (int)(Math.Max(template.LatLo.DecimalDegree, template.LatHi.DecimalDegree) - 1.0e-5); int lonMin = (int)(Math.Min(template.LonLo.DecimalDegree, template.LonHi.DecimalDegree) + 1.0e-5); int lonMax = (int)(Math.Max(template.LonLo.DecimalDegree, template.LonHi.DecimalDegree) - 1.0e-5); var chunks = new List <ChunkHolder <float> >(); for (int latInt = latMin; latInt <= latMax; latInt++) { for (int lonInt = lonMin; lonInt <= lonMax; lonInt++) { chunks.Add(await UsgsRawChunks.GetRawHeightsInMeters(latInt, lonInt, log)); } } ret.RenderChunksInto(chunks, aggregate, log); return(ret); }
private static string GetBaseFileName(StandardChunkMetadata template) { return(string.Format("{0}{1}{2:D2}", template.LatLo.ToLatString(), template.LonLo.ToLonString(), template.ZoomLevel)); }
public static async Task ProcessRawData(StandardChunkMetadata template, TraceListener log) { bool doMore = false; if (template.ZoomLevel <= Heights.Current.SourceDataZoom) { var ok = await Heights.Current.ExistsComputedChunk(template, log); log?.Write(ok ? "." : ("Heights:" + Heights.Current.GetShortFilename(template) + ":" + "missing")); doMore = true; } if (template.ZoomLevel <= Images.Current.SourceDataZoom) { var ok = await Images.Current.ExistsComputedChunk(template, log); log?.Write(ok ? "." : ("Images:" + Images.Current.GetShortFilename(template) + ":" + "missing")); doMore = true; } if (!doMore) { return; } foreach (var c in template.GetChildChunks()) { await ProcessRawData(c, log); } }
private FriendlyMesh ReadChunk(BlobHelper.DeletableFileStream stream, StandardChunkMetadata template) { byte[] buffer = new byte[Math.Max(4, pixelDataSize)]; stream.Read(buffer, 0, 4); int vertexCount = BitConverter.ToInt32(buffer, 0); stream.Read(buffer, 0, 4); int triangleIndexCount = BitConverter.ToInt32(buffer, 0); stream.Read(buffer, 0, 4); int edgeIndicesCount = BitConverter.ToInt32(buffer, 0); var ret = new FriendlyMesh( template.LatLo, template.LonLo, template.LatHi, template.LonHi, vertexCount, triangleIndexCount, edgeIndicesCount); for (int i = 0; i < vertexCount; i++) { ret.Vertices[i].X = ReadFloat(stream, buffer); ret.Vertices[i].Y = ReadFloat(stream, buffer); ret.Vertices[i].Z = ReadFloat(stream, buffer); } for (int i = 0; i < triangleIndexCount; i++) { stream.Read(buffer, 0, 4); ret.TriangleIndices[i] = BitConverter.ToInt32(buffer, 0); } for (int i = 0; i < edgeIndicesCount; i++) { stream.Read(buffer, 0, 4); ret.EdgeIndices[i] = BitConverter.ToInt32(buffer, 0); } for (int i = 0; i < vertexCount; i++) { ret.VertexNormals[i].X = ReadFloat(stream, buffer); ret.VertexNormals[i].Y = ReadFloat(stream, buffer); ret.VertexNormals[i].Z = ReadFloat(stream, buffer); } for (int i = 0; i < vertexCount; i++) { ret.VertexToImage[i].X = ReadFloat(stream, buffer); ret.VertexToImage[i].Y = ReadFloat(stream, buffer); } for (int i = 0; i < 4; i++) { ret.Corners[i].X = ReadFloat(stream, buffer); ret.Corners[i].Y = ReadFloat(stream, buffer); ret.Corners[i].Z = ReadFloat(stream, buffer); } return(ret); }
private string GetShortFilename(StandardChunkMetadata template) { if (!filenameCache.TryGetValue(template.Key, out string filename)) { filename = GetBaseFileName(template); filenameCache.AddOrUpdate(template.Key, filename, (a, b) => b); } return(filename); }
public async Task <ChunkHolder <T> > ProcessRawData(StandardChunkMetadata template, TraceListener log) { var computedChunk = await GetComputedChunk(template, log); string fileName = computedChunk.Item1; ChunkHolder <T> ret = computedChunk.Item2; if (computedChunk.Item2 != null) { log?.WriteLine("Cached " + description + " chunk file exists: " + fileName); return(computedChunk.Item2); } log?.WriteLine("Cached " + description + " chunk file does not exist: " + fileName); if (template.ZoomLevel > this.SourceDataZoom) { // Nothing to do for processing return(null); } else if (template.ZoomLevel == this.SourceDataZoom) { log?.WriteLine("Starting generation..."); ret = await GenerateData(template, log); await WriteChunk(ret, fileName, log); log?.WriteLine("Finished generation of " + description + " cached chunk file: " + fileName); return(ret); } log?.WriteLine("Need to aggregate up from higher zoom data"); var children = template.GetChildChunks(); List <ChunkHolder <T> > chunks = new List <ChunkHolder <T> >(); foreach (var child in children) { log?.WriteLine(child); chunks.Add(await ProcessRawData(child, log)); } ret = new ChunkHolder <T>( template.LatSteps, template.LonSteps, template.LatLo, template.LonLo, template.LatHi, template.LonHi, null, toDouble, fromDouble); ret.RenderChunksInto(chunks, aggregate, log); await WriteChunk(ret, fileName, log); log?.WriteLine("Finished generation of " + description + " cached chunk file: " + fileName); return(ret); }
private async Task <Tuple <string, ChunkHolder <T> > > GetComputedChunk(StandardChunkMetadata template, TraceListener log) { string filename = GetShortFilename(template); Tuple <string, ChunkHolder <T> > ret = new Tuple <string, ChunkHolder <T> >(GetFullFileName(template, filename), null); using (var ms = await BlobHelper.TryGetStreamAsync(cachedFileContainer, ret.Item1, log)) { if (ms != null) { ret = new Tuple <string, ChunkHolder <T> >(ret.Item1, ReadChunk(ms, template)); } } return(ret); }
public async Task <byte[]> GetData(StandardChunkMetadata template, TraceListener log) { var computedChunk = await GetComputedChunk(template, log); string fileName = computedChunk.Item1; byte[] imageData = computedChunk.Item2; if (computedChunk.Item2 != null) { log?.WriteLine("Cached " + description + " chunk (" + template.ToString() + ") file exists: " + fileName); return(computedChunk.Item2); } log?.WriteLine("Cached " + description + " chunk (" + template.ToString() + ") file does not exist: " + fileName + ", so starting generation..."); MemoryStream ms = null; try { var pixels = await Images.Current.GetData(template, log); if (pixels != null) { ms = Utils.GetBitmap(pixels, a => a, OutputType.JPEG); } } catch { } if (ms == null) { throw new MountainViewException("Source image not found for chunk " + template.ToString()); } imageData = new byte[ms.Length]; ms.Seek(0, SeekOrigin.Begin); ms.Read(imageData, 0, imageData.Length); await WriteChunk(imageData, fileName, log); log?.WriteLine("Finished generation of " + description + " cached chunk (" + template.ToString() + ") file: " + fileName); return(imageData); }
public async Task <FriendlyMesh> GetData(StandardChunkMetadata template, TraceListener log) { var computedChunk = await GetComputedChunk(template, log); string fileName = computedChunk.Item1; FriendlyMesh ret = computedChunk.Item2; if (computedChunk.Item2 != null) { log?.WriteLine("Cached " + description + " chunk (" + template.ToString() + ") file exists: " + fileName); return(computedChunk.Item2); } log?.WriteLine("Cached " + description + " chunk (" + template.ToString() + ") file does not exist: " + fileName + ", so starting generation..."); ChunkHolder <float> pixels2 = null; try { pixels2 = await Heights.Current.GetData(template, log); } catch { } if (pixels2 == null) { // throw new InvalidOperationException("Source heights not found for chunk " + template.ToString()); return(null); } ret = new FriendlyMesh( template.LatSteps, template.LonSteps, template.LatLo, template.LonLo, template.LatHi, template.LonHi, pixels2.Data, log); await WriteChunk(ret, fileName, log); log?.WriteLine("Finished generation of " + description + " cached chunk (" + template.ToString() + ") file: " + fileName); return(ret); }
public async Task <ChunkHolder <T> > GetData(StandardChunkMetadata template, TraceListener log) { var computedChunk = await GetComputedChunk(template, log); string fileName = computedChunk.Item1; ChunkHolder <T> ret = computedChunk.Item2; if (computedChunk.Item2 != null) { log?.WriteLine("Cached " + description + " chunk file exists: " + fileName); return(computedChunk.Item2); } log?.WriteLine("Cached " + description + " chunk file does not exist: " + fileName); if (template.ZoomLevel <= this.SourceDataZoom) { throw new MountainViewException("Source data is missing for chunk " + template.ToString()); //log?.WriteLine("Starting generation..."); //ret = await GenerateData(template, log); //await WriteChunk(ret, fileName, log); //log?.WriteLine("Finished generation of " + description + " cached chunk file: " + fileName); //return ret; } log?.WriteLine("Need to interpolate from lower zoom data"); var parent = template.GetParentChunk(); var chunks = new ChunkHolder <T>[] { await GetData(parent, log) }; ret = new ChunkHolder <T>( template.LatSteps, template.LonSteps, template.LatLo, template.LonLo, template.LatHi, template.LonHi, null, toDouble, fromDouble); ret.RenderChunksInto(chunks, aggregate, log); await WriteChunk(ret, fileName, log); log?.WriteLine("Finished generation of " + description + " cached chunk file: " + fileName); return(ret); }
protected override async Task <ChunkHolder <MyColor> > GenerateData(StandardChunkMetadata template, TraceListener log) { var ret = new ChunkHolder <MyColor>( template.LatSteps, template.LonSteps, template.LatLo, template.LonLo, template.LatHi, template.LonHi, null, toDouble, fromDouble); var targetChunks = (await UsgsRawImageChunks.GetChunkMetadata(log)) .Select(p => new { p, Chunk = new ChunkMetadata(0, 0, Angle.FromDecimalDegrees(p.Points.Min(q => q.Item1)), Angle.FromDecimalDegrees(p.Points.Min(q => q.Item2)), Angle.FromDecimalDegrees(p.Points.Max(q => q.Item1)), Angle.FromDecimalDegrees(p.Points.Max(q => q.Item2))) }) .Where(p => !ret.Disjoint(p.Chunk)) .ToArray(); var chunks = new List <ChunkHolder <MyColor> >(); foreach (var tmp in targetChunks) { log?.WriteLine(tmp.Chunk); var col = await UsgsRawImageChunks.GetRawColors( Angle.Add(tmp.Chunk.LatLo, Angle.Divide(tmp.Chunk.LatDelta, 2)), Angle.Add(tmp.Chunk.LonLo, Angle.Divide(tmp.Chunk.LonDelta, 2)), log); if (col != null) { chunks.Add(col); } } ret.RenderChunksInto(chunks, aggregate, log); return(ret); }
private static long[] GetVisibleChunks(Config config, int zoom, double R, TraceListener log) { int numR = 1000; List <long> orderedChunkKeys = new List <long>(); for (int iR = 1; iR <= numR; iR++) { for (double iTheta = config.MinAngleDec; iTheta <= config.MaxAngleDec; iTheta += (config.MaxAngleDec - config.MinAngleDec) / numR) { var dest = Utils.GetDestFromBearing(config.HomePoint, Angle.FromDecimalDegrees(iTheta), R * iR / numR); var curr = StandardChunkMetadata.GetKey(dest.Lat.Fourths, dest.Lon.Fourths, zoom); if (!orderedChunkKeys.Contains(curr)) { orderedChunkKeys.Add(curr); } } } orderedChunkKeys.Reverse(); return(orderedChunkKeys.ToArray()); }
private ChunkHolder <T> ReadChunk(DeletableFileStream stream, StandardChunkMetadata template) { byte[] buffer = new byte[Math.Max(4, pixelDataSize)]; stream.Read(buffer, 0, 4); int width = BitConverter.ToInt32(buffer, 0); stream.Read(buffer, 0, 4); int height = BitConverter.ToInt32(buffer, 0); var ret = new ChunkHolder <T>(width, height, template.LatLo, template.LonLo, template.LatHi, template.LonHi, null, toDouble, fromDouble); for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { ret.Data[i][j] = ReadPixel(stream, buffer); } } return(ret); }
protected abstract Task <ChunkHolder <T> > GenerateData(StandardChunkMetadata template, TraceListener log);
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); } } } }
private static async Task NewMethod(TraceListener log, Action <Stream> drawToScreen) { var x = await BlobHelper.GetFileNames("mapv8", null, log); var y = x .Select(p => new { Name = p, P = p.Split('.') }) .Select(p => new { p.Name, Base = StandardChunkMetadata.ParseBase(p.P[0]), V = p.P[1], Ext = p.P[2] }) .GroupBy(p => new { p.Ext, p.V, p.Base.ZoomLevel }) .Select(p => new { p.Key.Ext, p.Key.V, p.Key.ZoomLevel, Data = p.Select(q => new { q.Name, q.Base }).ToArray() }) .OrderBy(p => p.ZoomLevel) .ThenBy(p => p.Ext) .ThenBy(p => p.V) .ToArray(); var baseBmp = new DirectBitmap(1000, 1000); baseBmp.SetAllPixels(new MyColor(255, 255, 255)); foreach (var dfgdfg in y.Where(p => p.Ext == "jpeg" && p.ZoomLevel == 6)) { var lats = dfgdfg.Data.Select(p => p.Base.LatLo.Abs).Distinct().OrderBy(p => p).ToArray(); var lons = dfgdfg.Data.Select(p => p.Base.LonLo.Abs).Distinct().OrderBy(p => p).ToArray(); if (dfgdfg.Ext == "jpeg") { for (int i = 0; i < lats.Length; i++) { for (int j = 0; j < lons.Length; j++) { var t = dfgdfg.Data.FirstOrDefault(p => p.Base.LatLo.Abs == lats[i] && p.Base.LonLo.Abs == lons[j])?.Base; if (t != null) { var tmpImg = await JpegImages.Current.GetData(t, log); var gggg = new DirectBitmap(tmpImg); //device.RenderInto(chunkBmp); baseBmp.DrawAt(gggg, j, i, lons.Length, lats.Length); drawToScreen?.Invoke(baseBmp.GetStream(OutputType.PNG)); } } } } else if (dfgdfg.Ext == "hdata") { } else if (dfgdfg.Ext == "idata") { } else if (dfgdfg.Ext == "mdata") { } else { } log?.WriteLine(dfgdfg.Ext + "\t" + dfgdfg.ZoomLevel + "\t" + dfgdfg.V); for (int i = 0; i < lats.Length; i++) { for (int j = 0; j < lons.Length; j++) { log?.Write(dfgdfg.Data.Any(p => p.Base.LatLo.Abs == lats[i] && p.Base.LonLo.Abs == lons[j]) ? "X" : " "); } log?.WriteLine(""); } } }
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 async Task <bool> ExistsComputedChunk(StandardChunkMetadata template, TraceListener log) { string filename = GetShortFilename(template); return(await BlobHelper.BlobExists(cachedFileContainer, GetFullFileName(template, filename), log)); }
public string GetFileName(StandardChunkMetadata template) { string baseFileName = GetBaseFileName(template); return(GetFullFileName(template, baseFileName)); }
private string GetFullFileName(StandardChunkMetadata template, string filename) { return(string.Format(cachedFileTemplate, filename, fileExt)); }