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