public static void SaveBin(this MultiGridData multigrid, string filename) { using (var bw = new BinaryWriter(File.Open(filename, FileMode.Create))) { PatchDataIO.WriteBinVersion(bw); PatchDataIO.WriteBinBoundsHeader(bw, multigrid); // Write Metadata (if available) PatchDataIO.WriteBinMetadata(bw, multigrid.metadata); bw.Write((byte)multigrid.coloring); int categoriesCount = multigrid.categories == null ? 0 : multigrid.categories.Length; bw.Write(categoriesCount); if (multigrid.categories != null) { // Write categories (without values) foreach (var c in multigrid.categories) { bw.Write(c.name); } // Write Grids foreach (var c in multigrid.categories) { GridDataIO.WriteBinProperties(bw, c.grid); GridDataIO.WriteBinValues(bw, c.grid); } } } }
public static void WriteBinProperties(BinaryWriter bw, PointData pointData) { bw.Write(pointData.minValue); bw.Write(pointData.maxValue); bw.Write(pointData.count); bw.Write(pointData.units); bw.Write((byte)pointData.coloring); // Write Metadata (if available) PatchDataIO.WriteBinMetadata(bw, pointData.metadata); // Write Categories (if available) WriteBinCategories(bw, pointData.categories, pointData.coloring == PointData.Coloring.Custom); }
public static void WriteBinProperties(BinaryWriter bw, GridData grid) { bw.Write(grid.minValue); bw.Write(grid.maxValue); bw.Write(grid.countX); bw.Write(grid.countY); bw.Write(grid.units); bw.Write((byte)grid.coloring); // Write Metadata (if available) PatchDataIO.WriteBinMetadata(bw, grid.metadata); // Write Categories (if available) WriteBinCategories(bw, grid.categories, grid.coloring == GridData.Coloring.Custom); }
public static void SaveBin(this GridData grid, string filename) { using (var bw = new BinaryWriter(File.Open(filename, FileMode.Create))) { PatchDataIO.WriteBinBoundsHeader(bw, grid); // Write Categories count bw.Write(grid.categories == null ? 0 : grid.categories.Length); bw.Write(grid.minValue); bw.Write(grid.maxValue); bw.Write(grid.countX); bw.Write(grid.countY); bw.Write(grid.units); bw.Write((byte)grid.coloring); // Write Metadata (if available) PatchDataIO.WriteBinMetadata(bw, grid.metadata); // Write Categories (if available) WriteBinCategories(bw, grid.categories); // Write values byte[] byteArray = new byte[grid.values.Length * 4]; Buffer.BlockCopy(grid.values, 0, byteArray, 0, byteArray.Length); bw.Write(byteArray); // Write mask byteArray = new byte[grid.valuesMask.Length]; Buffer.BlockCopy(grid.valuesMask, 0, byteArray, 0, byteArray.Length); bw.Write(byteArray); // Write distribution values var distribution = grid.DistributionValues; bw.Write((byte)distribution.Length); byteArray = new byte[distribution.Length * 4]; Buffer.BlockCopy(distribution, 0, byteArray, 0, byteArray.Length); bw.Write(byteArray); // Write max distribution value bw.Write(grid.MaxDistributionValue); } }