Esempio n. 1
0
        public void saveFile(string fileName, HffFile file)
        {
            Stream fs = null;
            EndianBinaryWriter writer = null;
            try
            {
                debugLine("file name: " + fileName);
                fs = Util.openStream(fileName, FileFormat.UNCOMPRESSED, FileMode.Create);
                writer = Util.createEndianBinaryWriterForStream(fs);

                writeHffHeader(writer, file);
                writeHffData(writer, file);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (writer != null)
                {
                    writer.Close();
                }
                setDebug(false, null);
            }
        }
 public HffHeightMap(string filename)
 {
     L3dtFileManager.L3dtFileManager hfzManager = new L3dtFileManager.L3dtFileManager();
     if (filename.EndsWith(".hff"))
     {
         this.file = hfzManager.loadHffFile(filename);
     }
     else
     {
         throw new Exception("Not a Hff map file");
     }
 }
Esempio n. 3
0
        public HffFile loadFile(string fileName)
        {
            HffFile file = new HffFile();

            Stream fs = null;
            EndianBinaryReader reader = null;
            try
            {
                debugLine("file name: " + fileName);
                //create a file stream to work with during load
                fs = Util.openStream(fileName, FileFormat.UNCOMPRESSED, FileMode.Open);
                reader = Util.createEndianBinaryReaderForStream(fs);

                HffHeader header = readHffHeader(reader);
                file.header = header;
                if (header.tileSize <= 1)
                {
                    readConventionalData(reader, header, file);
                }
                else
                {
                    readTiledData(reader, header, file);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                reader.Close();
                if (debug)
                {
                    writeLog.Close();
                }
                setDebug(false, null);
            }

            return file;
        }
 public void saveHffFile(string fileName, HffFile file)
 {
     hffManager.saveFile(fileName, file);
 }
 public override void Dispose()
 {
     this.file = null;
 }
Esempio n. 6
0
 private void writeHffHeader(EndianBinaryWriter writer, HffFile file)
 {
     HffHeader header = file.header;
     writer.Write(Util.StringToByteArray("L3DT", 4));
     ushort fileType = 300;
     writer.Write(fileType);
     writer.Write(Util.StringToByteArray("HFF_v1.0", 8));
     writer.Write(header.dataOffset);
     writer.Write(header.width);
     writer.Write(header.height);
     writer.Write(header.dataSize);
     writer.Write(header.floatingPointFlag == true ? (byte)1 : (byte)0);
     writer.Write(header.verticalScale);
     writer.Write(header.verticalOffset);
     writer.Write(header.horizontalScale);
     writer.Write(header.tileSize);
     writer.Write(header.wrapFlag == true ? (byte)1 : (byte)0);
     writer.Write(header.reserved);
 }
Esempio n. 7
0
 private void writeHffData(EndianBinaryWriter writer, HffFile file)
 {
     float minalt = findMinAltitude(file.pixels);
     debugLine("minalt: " + minalt);
     float maxalt = findMaxAltitude(file.pixels);
     debugLine("maxalt: " + maxalt);
     float vertScale, formulaResult;
     foreach (HffPixelInfo pixel in file.pixels)
     {
         if (file.header.floatingPointFlag)
         {
             formulaResult = ((pixel.data - 0) / 1);
             debugLine("v: " + formulaResult);
             writer.Write(formulaResult);
         }
         else
         {
             switch (file.header.dataSize)
             {
                 case 1:
                     vertScale = (maxalt - minalt) / 255;
                     debugLine("vertScale: " + vertScale);
                     formulaResult = (pixel.data - minalt) / vertScale;
                     debugLine("v: " + formulaResult);
                     writer.Write(Convert.ToSByte(formulaResult));
                     break;
                 case 2:
                     vertScale = (maxalt - minalt) / 65535;
                     debugLine("vertScale: " + vertScale);
                     formulaResult = (pixel.data - minalt) / vertScale;
                     debugLine("v: " + formulaResult);
                     writer.Write(Convert.ToUInt16(formulaResult));
                     break;
                 default: throw new Exception("Wrong datasize for pixel at x: " + pixel.x + ", y: " + pixel.y);
             }
         }
     }
 }
Esempio n. 8
0
        private void readTiledData(EndianBinaryReader reader, HffHeader header, HffFile file)
        {
            validateTileSizeForDimensions(header);

            uint horizontalTiles = header.width / header.tileSize;
            uint verticalTiles = header.height / header.tileSize;

            for (int y = 0; y < verticalTiles; y++)
            {
                for (int x = 0; x < horizontalTiles; x++)
                {
                    readTile(x, y, header, reader, file);
                }
            }
        }
Esempio n. 9
0
 private void readTile(int x, int y, HffHeader header, EndianBinaryReader reader, HffFile file)
 {
     for (int j = 1; j <= header.tileSize; j++)
     {
         for (int i = 1; i <= header.tileSize; i++)
         {
             uint xLocation = (uint)((x * header.tileSize) + i);
             uint yLocation = (uint)((y * header.tileSize) + j);
             float value = readValueFromReader(reader, header, xLocation, yLocation);
             file.addPixel(new HffPixelInfo(xLocation, yLocation, value));
         }
     }
 }
Esempio n. 10
0
        private void readConventionalData(EndianBinaryReader reader, HffHeader header, HffFile file)
        {
            uint totalPixels = header.width * header.height;
            uint xLocation = 1;
            uint yLocation = 1;
            for (int i = 0; i < totalPixels; i++)
            {
                float value = readValueFromReader(reader, header, xLocation, yLocation);
                file.addPixel(new HffPixelInfo(xLocation, yLocation, value));

                xLocation++;
                if (xLocation > header.width)
                {
                    xLocation = 1;
                    yLocation++;
                }
            }

            debugLine("pixel count: " + file.pixels.Count());
        }