Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
        }