Beispiel #1
0
        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);
        }
Beispiel #2
0
 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);
 }
Beispiel #3
0
 protected override MyColor ReadPixel(BlobHelper.DeletableFileStream stream, byte[] buffer)
 {
     return(new MyColor(
                (byte)stream.ReadByte(),
                (byte)stream.ReadByte(),
                (byte)stream.ReadByte()));
 }
Beispiel #4
0
        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);
        }
Beispiel #5
0
 private float ReadFloat(BlobHelper.DeletableFileStream stream, byte[] buffer)
 {
     stream.Read(buffer, 0, 4);
     return(BitConverter.ToSingle(buffer, 0));
 }