Revise.Files.HIM.HeightmapFile.Load C# (CSharp) Method

Load() public method

Loads the file from the specified stream.
public Load ( Stream stream ) : void
stream System.IO.Stream The stream to read from.
return void
        public override void Load(Stream stream)
        {
            BinaryReader reader = new BinaryReader(stream, Encoding.GetEncoding("EUC-KR"));

            int width = reader.ReadInt32();
            int height = reader.ReadInt32();
            heights = new float[height, width];
            /*int patchGridCount = */reader.ReadInt32();
            /*float patchSize = */reader.ReadSingle();

            for (int h = 0; h < height; h++) {
                for (int w = 0; w < width; w++) {
                    heights[h, w] = reader.ReadSingle();
                }
            }

            /*string name = */reader.ReadString();
            /*int patchCount = */reader.ReadInt32();

            for (int h = 0; h < 16; h++) {
                for (int w = 0; w < 16; w++) {
                    patches[h, w].Maximum = reader.ReadSingle();
                    patches[h, w].Minimum = reader.ReadSingle();
                }
            }

            int quadPatchCount = reader.ReadInt32();

            for (int i = 0; i < quadPatchCount; i++) {
                quadPatches[i].Maximum = reader.ReadSingle();
                quadPatches[i].Minimum = reader.ReadSingle();
            }
        }

Usage Example

Example #1
0
        public void TestSaveMethod()
        {
            HeightmapFile heightmapFile = new HeightmapFile();
            heightmapFile.Load(TEST_FILE);

            MemoryStream savedStream = new MemoryStream();
            heightmapFile.Save(savedStream);
            heightmapFile.Load(TEST_FILE);

            savedStream.Seek(0, SeekOrigin.Begin);

            HeightmapFile savedHeightmapFile = new HeightmapFile();
            savedHeightmapFile.Load(savedStream);

            savedStream.Close();

            for (int x = 0; x < heightmapFile.Height; x++) {
                for (int y = 0; y < heightmapFile.Width; y++) {
                    Assert.AreEqual(heightmapFile[x, y], savedHeightmapFile[x, y], "Height values do not match");
                }
            }

            for (int x = 0; x < heightmapFile.Patches.GetLength(0); x++) {
                for (int y = 0; y < heightmapFile.Patches.GetLength(1); y++) {
                    Assert.AreEqual(heightmapFile.Patches[x, y].Minimum, savedHeightmapFile.Patches[x, y].Minimum, "Minimum patch values do not match");
                    Assert.AreEqual(heightmapFile.Patches[x, y].Maximum, savedHeightmapFile.Patches[x, y].Maximum, "Maximum patch values do not match");
                }
            }

            for (int i = 0; i < heightmapFile.QuadPatches.Length; i++) {
                Assert.AreEqual(heightmapFile.QuadPatches[i].Minimum, savedHeightmapFile.QuadPatches[i].Minimum, "Minimum quad patch values do not match");
                Assert.AreEqual(heightmapFile.QuadPatches[i].Maximum, savedHeightmapFile.QuadPatches[i].Maximum, "Maximum quad patch values do not match");
            }
        }
All Usage Examples Of Revise.Files.HIM.HeightmapFile::Load