void Convert() { for (int x = 1; x < 80; x += 2) { for (int y = 1; y < 36; y += 2) { string file1 = Path.Combine(srcDir, "tile_" + x.ToString("D2") + "_" + y.ToString("D2") + ".tdmp"); string file2 = Path.Combine(srcDir, "tile_" + (x + 1).ToString("D2") + "_" + y.ToString("D2") + ".tdmp"); string file3 = Path.Combine(srcDir, "tile_" + x.ToString("D2") + "_" + (y + 1).ToString("D2") + ".tdmp"); string file4 = Path.Combine(srcDir, "tile_" + (x + 1).ToString("D2") + "_" + (y + 1).ToString("D2") + ".tdmp"); bool ex1 = File.Exists(file1); bool ex2 = File.Exists(file2); bool ex3 = File.Exists(file3); bool ex4 = File.Exists(file4); if (ex1 || ex2 || ex3 || ex4) { int width = 0; int height = 0; float xSpan = 0; float ySpan = 0; float xllCorner = 0; float yllCorner = 0; int bits = 32; bool parsed = false; TDMPIO d1 = new TDMPIO(); if (ex1) { d1.Load(new DevFileLocation(file1)); if (!parsed) { width = d1.Width; height = d1.Height; xSpan = d1.XSpan; ySpan = d1.YSpan; xllCorner = d1.Xllcorner; yllCorner = d1.Yllcorner; bits = d1.Bits; } } TDMPIO d2 = new TDMPIO(); if (ex2) { d2.Load(new DevFileLocation(file2)); if (!parsed) { width = d2.Width; height = d2.Height; xSpan = d2.XSpan; ySpan = d2.YSpan; xllCorner = d2.Xllcorner - xSpan; yllCorner = d2.Yllcorner; bits = d2.Bits; } } TDMPIO d3 = new TDMPIO(); if (ex3) { d3.Load(new DevFileLocation(file3)); if (!parsed) { width = d3.Width; height = d3.Height; xSpan = d3.XSpan; ySpan = d3.YSpan; xllCorner = d3.Xllcorner; yllCorner = d3.Yllcorner - ySpan; bits = d3.Bits; } } TDMPIO d4 = new TDMPIO(); if (ex4) { d4.Load(new DevFileLocation(file4)); if (!parsed) { width = d4.Width; height = d4.Height; xSpan = d4.XSpan; ySpan = d4.YSpan; xllCorner = d4.Xllcorner - xSpan; yllCorner = d4.Yllcorner - ySpan; bits = d4.Bits; } } TDMPIO data = new TDMPIO(); data.Data = new float[width * height * 4]; data.Width = width * 2; data.Height = height * 2; data.Xllcorner = xllCorner; data.Yllcorner = yllCorner; data.XSpan = xSpan * 2; data.YSpan = ySpan * 2; data.Bits = bits; DataGetter dg = new DataGetter(d1.Data, d2.Data, d3.Data, d4.Data, width, height); for (int i = 0; i < data.Height; i++) { for (int j = 0; j < data.Width; j++) { data.Data[i * data.Width + j] = dg[i, j]; } } string outPath = Path.Combine(dstDir, "tile_" + x.ToString("D2") + "_" + y.ToString("D2") + ".tdmp"); FileStream fs = new FileStream(outPath, FileMode.OpenOrCreate, FileAccess.Write); data.Save(fs); } } } }
void Convert() { for (int x = 1; x < 80; x += 2) { for (int y = 1; y < 36; y += 2) { string file1 = Path.Combine(srcDir, "tile_" + x.ToString("D2") + "_" + y.ToString("D2") + ".tdmp"); string file2 = Path.Combine(srcDir, "tile_" + (x + 1).ToString("D2") + "_" + y.ToString("D2") + ".tdmp"); string file3 = Path.Combine(srcDir, "tile_" + x.ToString("D2") + "_" + (y + 1).ToString("D2") + ".tdmp"); string file4 = Path.Combine(srcDir, "tile_" + (x + 1).ToString("D2") + "_" + (y + 1).ToString("D2") + ".tdmp"); bool ex1 = File.Exists(file1); bool ex2 = File.Exists(file2); bool ex3 = File.Exists(file3); bool ex4 = File.Exists(file4); if (ex1 || ex2 || ex3 || ex4) { int width = 0; int height = 0; float xSpan = 0; float ySpan = 0; float xllCorner = 0; float yllCorner = 0; int bits = 32; bool parsed = false; TDMPIO d1 = new TDMPIO(); if (ex1) { d1.Load(new DevFileLocation(file1)); if (!parsed) { width = d1.Width; height = d1.Height; xSpan = d1.XSpan; ySpan = d1.YSpan; xllCorner = d1.Xllcorner; yllCorner = d1.Yllcorner; bits = d1.Bits; } } TDMPIO d2 = new TDMPIO(); if (ex2) { d2.Load(new DevFileLocation(file2)); if (!parsed) { width = d2.Width; height = d2.Height; xSpan = d2.XSpan; ySpan = d2.YSpan; xllCorner = d2.Xllcorner - xSpan; yllCorner = d2.Yllcorner; bits = d2.Bits; } } TDMPIO d3 = new TDMPIO(); if (ex3) { d3.Load(new DevFileLocation(file3)); if (!parsed) { width = d3.Width; height = d3.Height; xSpan = d3.XSpan; ySpan = d3.YSpan; xllCorner = d3.Xllcorner; yllCorner = d3.Yllcorner - ySpan; bits = d3.Bits; } } TDMPIO d4 = new TDMPIO(); if (ex4) { d4.Load(new DevFileLocation(file4)); if (!parsed) { width = d4.Width; height = d4.Height; xSpan = d4.XSpan; ySpan = d4.YSpan; xllCorner = d4.Xllcorner - xSpan; yllCorner = d4.Yllcorner - ySpan; bits = d4.Bits; } } TDMPIO data = new TDMPIO(); data.Data = new float[width * height * 4]; data.Width = width * 2; data.Height = height * 2; data.Xllcorner = xllCorner; data.Yllcorner = yllCorner; data.XSpan = xSpan * 2; data.YSpan = ySpan * 2; data.Bits = bits; DataGetter dg = new DataGetter(d1.Data, d2.Data, d3.Data, d4.Data, width, height); for (int i = 0; i < data.Height; i++) { for (int j = 0; j < data.Width; j++) { data.Data[i * data.Width + j] = dg[i, j]; } } string outPath = Path.Combine(dstDir, "tile_" + x.ToString("D2") + "_" + y.ToString("D2") + ".tdmp"); FileStream fs = new FileStream(outPath, FileMode.OpenOrCreate, FileAccess.Write); data.Save(fs); } } } }
static void Convert(string srcDir, string dstDir, string suffix) { for (int x = 1; x < 72; x += 2) { for (int y = 1; y < 36; y += 2) { int minX = x - 2; int maxX = x + 2; int minY = y - 2; int maxY = y + 2; if (minX < 0) minX = 71; if (maxX > 72) maxX = 1; //if (minY < 0) minY = 23; //if (maxY > 72) maxY = 1; string[] files = new string[9]; files[0] = Path.Combine(srcDir, "tile_" + minX.ToString("D2") + "_" + minY.ToString("D2") + suffix + ".tdmp"); files[1] = Path.Combine(srcDir, "tile_" + x.ToString("D2") + "_" + minY.ToString("D2") + suffix + ".tdmp"); files[2] = Path.Combine(srcDir, "tile_" + maxX.ToString("D2") + "_" + minY.ToString("D2") + suffix + ".tdmp"); files[3] = Path.Combine(srcDir, "tile_" + minX.ToString("D2") + "_" + y.ToString("D2") + suffix + ".tdmp"); files[4] = Path.Combine(srcDir, "tile_" + x.ToString("D2") + "_" + y.ToString("D2") + suffix + ".tdmp"); files[5] = Path.Combine(srcDir, "tile_" + maxX.ToString("D2") + "_" + y.ToString("D2") + suffix + ".tdmp"); files[6] = Path.Combine(srcDir, "tile_" + minX.ToString("D2") + "_" + maxY.ToString("D2") + suffix + ".tdmp"); files[7] = Path.Combine(srcDir, "tile_" + x.ToString("D2") + "_" + maxY.ToString("D2") + suffix + ".tdmp"); files[8] = Path.Combine(srcDir, "tile_" + maxX.ToString("D2") + "_" + maxY.ToString("D2") + suffix + ".tdmp"); bool[] exists = new bool[9]; bool passed = false; for (int i = 0; i < files.Length; i++) { exists[i] = File.Exists(files[i]); passed |= exists[i]; } passed &= exists[4]; if (passed) { int width = 0; int height = 0; int bits = 32; bool parsed = false; TDMPIO[] dataBlocks = new TDMPIO[9]; for (int i = 0; i < 9; i++) { if (exists[i]) { TDMPIO d1 = new TDMPIO(); d1.Load(new DevFileLocation(files[i])); if (!parsed) { width = d1.Width; height = d1.Height; bits = d1.Bits; parsed = true; } dataBlocks[i] = d1; } } float[] databy = new float[width * height]; DataGetter dg = new DataGetter( dataBlocks[0] == null ? null : dataBlocks[0].Data, dataBlocks[1] == null ? null : dataBlocks[1].Data, dataBlocks[2] == null ? null : dataBlocks[2].Data, dataBlocks[3] == null ? null : dataBlocks[3].Data, dataBlocks[4] == null ? null : dataBlocks[4].Data, dataBlocks[5] == null ? null : dataBlocks[5].Data, dataBlocks[6] == null ? null : dataBlocks[6].Data, dataBlocks[7] == null ? null : dataBlocks[7].Data, dataBlocks[8] == null ? null : dataBlocks[8].Data, width, height); string fileName = Path.Combine(dstDir, Path.GetFileName(files[4])); TDMPIO result = new TDMPIO(); result.Bits = 16; result.Height = height; result.Width = width; result.XSpan = dataBlocks[4].XSpan; result.YSpan = dataBlocks[4].YSpan; result.Xllcorner = dataBlocks[4].Xllcorner; result.Yllcorner = dataBlocks[4].Yllcorner; result.Data = new float[width * height]; int[] weightMap = new int[width * height]; for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { result.Data[i * width + j] = dg[i + height, j + width]; weightMap[i * width + j] = 1; } } for (int i = 0; i < height; i++) { if (dg.HasValue(i + height, width - 1)) { result.Data[i * width] += dg[i + height, width - 1]; weightMap[i * width]++; } if (dg.HasValue(i + height, 2 * width)) { result.Data[i * width + height - 1] += dg[i + height, 2 * width]; weightMap[i * width + height - 1]++; } } for (int j = 0; j < width; j++) { if (dg.HasValue(height - 1, j + width)) { result.Data[j] += dg[height - 1, j + width]; weightMap[j]++; } if (dg.HasValue(2 * height, j + width)) { result.Data[width * (height - 1) + j] += dg[2 * height, j + width]; weightMap[width * (height - 1) + j]++; } } //result.Data[0] += dg[width - 1, height - 1]; //weightMap[0]++; //result.Data[width - 1] += dg[2 * width, height - 1]; //weightMap[width - 1]++; //result.Data[width * (height - 1)] += dg[width - 1, 2 * height]; //weightMap[width * (height - 1) - 1]++; //result.Data[width * height - 1] += dg[2 * width, 2 * height]; //weightMap[width * height - 1]++; for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { int idx = i * width + j; result.Data[idx] /= (float)weightMap[idx]; } } result.Save(File.Open(fileName, FileMode.OpenOrCreate, FileAccess.Write)); Console.Write('#'); } } } }
void Convert() { for (int x = 1; x < 72; x += 2) { for (int y = 1; y < 36; y += 2) { int minX = x - 2; int maxX = x + 2; int minY = y - 2; int maxY = y + 2; if (minX < 0) minX = 71; if (maxX > 72) maxX = 1; //if (minY < 0) minY = 23; //if (maxY > 72) maxY = 1; string[] files = new string[9]; files[0] = Path.Combine(srcDir, "tile_" + minX.ToString("D2") + "_" + minY.ToString("D2") + ".tdmp"); files[1] = Path.Combine(srcDir, "tile_" + x.ToString("D2") + "_" + minY.ToString("D2") + ".tdmp"); files[2] = Path.Combine(srcDir, "tile_" + maxX.ToString("D2") + "_" + minY.ToString("D2") + ".tdmp"); files[3] = Path.Combine(srcDir, "tile_" + minX.ToString("D2") + "_" + y.ToString("D2") + ".tdmp"); files[4] = Path.Combine(srcDir, "tile_" + x.ToString("D2") + "_" + y.ToString("D2") + ".tdmp"); files[5] = Path.Combine(srcDir, "tile_" + maxX.ToString("D2") + "_" + y.ToString("D2") + ".tdmp"); files[6] = Path.Combine(srcDir, "tile_" + minX.ToString("D2") + "_" + maxY.ToString("D2") + ".tdmp"); files[7] = Path.Combine(srcDir, "tile_" + x.ToString("D2") + "_" + maxY.ToString("D2") + ".tdmp"); files[8] = Path.Combine(srcDir, "tile_" + maxX.ToString("D2") + "_" + maxY.ToString("D2") + ".tdmp"); bool[] exists = new bool[9]; bool passed = false; for (int i = 0; i < files.Length; i++) { exists[i] = File.Exists(files[i]); passed |= exists[i]; } passed &= exists[4]; if (passed) { int width = 0; int height = 0; int bits = 32; bool parsed = false; TDMPIO[] dataBlocks = new TDMPIO[9]; for (int i = 0; i < 9; i++) { if (exists[i]) { TDMPIO d1 = new TDMPIO(); d1.Load(new DevFileLocation(files[i])); if (!parsed) { width = d1.Width; height = d1.Height; bits = d1.Bits; parsed = true; } dataBlocks[i] = d1; } } float[] original = dataBlocks[4].Data; float[] sampleSrc1 = dataBlocks[0] == null ? null : BathymetrySlopSampleData(dataBlocks[0].Data); float[] sampleSrc2 = dataBlocks[1] == null ? null : BathymetrySlopSampleData(dataBlocks[1].Data); float[] sampleSrc3 = dataBlocks[2] == null ? null : BathymetrySlopSampleData(dataBlocks[2].Data); float[] sampleSrc4 = dataBlocks[3] == null ? null : BathymetrySlopSampleData(dataBlocks[3].Data); float[] sampleSrc5 = dataBlocks[4] == null ? null : BathymetrySlopSampleData(dataBlocks[4].Data); float[] sampleSrc6 = dataBlocks[5] == null ? null : BathymetrySlopSampleData(dataBlocks[5].Data); float[] sampleSrc7 = dataBlocks[6] == null ? null : BathymetrySlopSampleData(dataBlocks[6].Data); float[] sampleSrc8 = dataBlocks[7] == null ? null : BathymetrySlopSampleData(dataBlocks[7].Data); float[] sampleSrc9 = dataBlocks[8] == null ? null : BathymetrySlopSampleData(dataBlocks[8].Data); DataGetter dg = new DataGetter( dataBlocks[0] == null ? null : sampleSrc1, dataBlocks[1] == null ? null : sampleSrc2, dataBlocks[2] == null ? null : sampleSrc3, dataBlocks[3] == null ? null : sampleSrc4, dataBlocks[4] == null ? null : sampleSrc5, dataBlocks[5] == null ? null : sampleSrc6, dataBlocks[6] == null ? null : sampleSrc7, dataBlocks[7] == null ? null : sampleSrc8, dataBlocks[8] == null ? null : sampleSrc9, width, height); #region 高斯模糊 int brushSize = 65; float[] databy = new float[width * height]; float[] weights = MathEx.ComputeGuassFilter1D((float)Math.Sqrt(1 * brushSize), brushSize); #region Normalize float maxValue = 0; for (int i = 0; i < brushSize; i++) { maxValue += weights[i]; } if (maxValue != 0) { float scale = 1.0f / maxValue; for (int i = 0; i < brushSize; i++) { weights[i] *= scale; } } #endregion int mid = brushSize / 2; #region Y方向模糊 for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { int idx = i * width + j; if (original[idx] < 1600) { float val = 0; for (int ii = 0; ii < brushSize; ii++) { val += weights[ii] * dg[i + ii - mid + width, j + height]; } databy[idx] = MathEx.Clamp(0, 1600, val); } else databy[idx] = original[idx]; } } #endregion float[] databx = new float[width * height]; dg.MainData = databy; #region X方向模糊 for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { int idx = i * width + j; if (original[idx] < 1600) { float val = 0; for (int ii = 0; ii < brushSize; ii++) { val += weights[ii] * dg[i + width, j + ii - mid + height]; } databx[idx] = MathEx.Clamp(0, 1600, val); } else databx[idx] = original[idx]; } } #endregion #endregion string fileName = Path.Combine(dstDir, Path.GetFileName(files[4]) ); string fileNameImg = Path.Combine(dstDir, Path.GetFileName(files[4]) + "s.png"); string fileNameImg2 = Path.Combine(dstDir, Path.GetFileName(files[4]) + "d.png"); TDMPIO result = new TDMPIO(); result.Data = databx; result.Bits = 16; result.Height = height; result.Width = width; result.XSpan = dataBlocks[4].XSpan; result.YSpan = dataBlocks[4].YSpan; result.Xllcorner = dataBlocks[4].Xllcorner; result.Yllcorner = dataBlocks[4].Yllcorner; result.Save(File.Open(fileName, FileMode.OpenOrCreate, FileAccess.Write)); #region 预览图 for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { int idx = i * width + j; original[idx] /= 7000; databx[idx] /= 7000; } } OutPng(databx, width, height, fileNameImg); OutPng(original, width, height, fileNameImg2); #endregion } } } }
void Convert() { for (int x = 1; x < 72; x += 2) { for (int y = 1; y < 36; y += 2) { int minX = x - 2; int maxX = x + 2; int minY = y - 2; int maxY = y + 2; if (minX < 0) { minX = 71; } if (maxX > 72) { maxX = 1; } //if (minY < 0) minY = 23; //if (maxY > 72) maxY = 1; string[] files = new string[9]; files[0] = Path.Combine(srcDir, "tile_" + minX.ToString("D2") + "_" + minY.ToString("D2") + ".tdmp"); files[1] = Path.Combine(srcDir, "tile_" + x.ToString("D2") + "_" + minY.ToString("D2") + ".tdmp"); files[2] = Path.Combine(srcDir, "tile_" + maxX.ToString("D2") + "_" + minY.ToString("D2") + ".tdmp"); files[3] = Path.Combine(srcDir, "tile_" + minX.ToString("D2") + "_" + y.ToString("D2") + ".tdmp"); files[4] = Path.Combine(srcDir, "tile_" + x.ToString("D2") + "_" + y.ToString("D2") + ".tdmp"); files[5] = Path.Combine(srcDir, "tile_" + maxX.ToString("D2") + "_" + y.ToString("D2") + ".tdmp"); files[6] = Path.Combine(srcDir, "tile_" + minX.ToString("D2") + "_" + maxY.ToString("D2") + ".tdmp"); files[7] = Path.Combine(srcDir, "tile_" + x.ToString("D2") + "_" + maxY.ToString("D2") + ".tdmp"); files[8] = Path.Combine(srcDir, "tile_" + maxX.ToString("D2") + "_" + maxY.ToString("D2") + ".tdmp"); bool[] exists = new bool[9]; bool passed = false; for (int i = 0; i < files.Length; i++) { exists[i] = File.Exists(files[i]); passed |= exists[i]; } passed &= exists[4]; if (passed) { int width = 0; int height = 0; int bits = 32; bool parsed = false; TDMPIO[] dataBlocks = new TDMPIO[9]; for (int i = 0; i < 9; i++) { if (exists[i]) { TDMPIO d1 = new TDMPIO(); d1.Load(new DevFileLocation(files[i])); if (!parsed) { width = d1.Width; height = d1.Height; bits = d1.Bits; parsed = true; } dataBlocks[i] = d1; } } float[] original = dataBlocks[4].Data; float[] sampleSrc1 = dataBlocks[0] == null ? null : BathymetrySlopSampleData(dataBlocks[0].Data); float[] sampleSrc2 = dataBlocks[1] == null ? null : BathymetrySlopSampleData(dataBlocks[1].Data); float[] sampleSrc3 = dataBlocks[2] == null ? null : BathymetrySlopSampleData(dataBlocks[2].Data); float[] sampleSrc4 = dataBlocks[3] == null ? null : BathymetrySlopSampleData(dataBlocks[3].Data); float[] sampleSrc5 = dataBlocks[4] == null ? null : BathymetrySlopSampleData(dataBlocks[4].Data); float[] sampleSrc6 = dataBlocks[5] == null ? null : BathymetrySlopSampleData(dataBlocks[5].Data); float[] sampleSrc7 = dataBlocks[6] == null ? null : BathymetrySlopSampleData(dataBlocks[6].Data); float[] sampleSrc8 = dataBlocks[7] == null ? null : BathymetrySlopSampleData(dataBlocks[7].Data); float[] sampleSrc9 = dataBlocks[8] == null ? null : BathymetrySlopSampleData(dataBlocks[8].Data); DataGetter dg = new DataGetter( dataBlocks[0] == null ? null : sampleSrc1, dataBlocks[1] == null ? null : sampleSrc2, dataBlocks[2] == null ? null : sampleSrc3, dataBlocks[3] == null ? null : sampleSrc4, dataBlocks[4] == null ? null : sampleSrc5, dataBlocks[5] == null ? null : sampleSrc6, dataBlocks[6] == null ? null : sampleSrc7, dataBlocks[7] == null ? null : sampleSrc8, dataBlocks[8] == null ? null : sampleSrc9, width, height); #region 高斯模糊 int brushSize = 65; float[] databy = new float[width * height]; float[] weights = MathEx.ComputeGuassFilter1D((float)Math.Sqrt(1 * brushSize), brushSize); #region Normalize float maxValue = 0; for (int i = 0; i < brushSize; i++) { maxValue += weights[i]; } if (maxValue != 0) { float scale = 1.0f / maxValue; for (int i = 0; i < brushSize; i++) { weights[i] *= scale; } } #endregion int mid = brushSize / 2; #region Y方向模糊 for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { int idx = i * width + j; if (original[idx] < 1600) { float val = 0; for (int ii = 0; ii < brushSize; ii++) { val += weights[ii] * dg[i + ii - mid + width, j + height]; } databy[idx] = MathEx.Clamp(0, 1600, val); } else { databy[idx] = original[idx]; } } } #endregion float[] databx = new float[width * height]; dg.MainData = databy; #region X方向模糊 for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { int idx = i * width + j; if (original[idx] < 1600) { float val = 0; for (int ii = 0; ii < brushSize; ii++) { val += weights[ii] * dg[i + width, j + ii - mid + height]; } databx[idx] = MathEx.Clamp(0, 1600, val); } else { databx[idx] = original[idx]; } } } #endregion #endregion string fileName = Path.Combine(dstDir, Path.GetFileName(files[4])); string fileNameImg = Path.Combine(dstDir, Path.GetFileName(files[4]) + "s.png"); string fileNameImg2 = Path.Combine(dstDir, Path.GetFileName(files[4]) + "d.png"); TDMPIO result = new TDMPIO(); result.Data = databx; result.Bits = 16; result.Height = height; result.Width = width; result.XSpan = dataBlocks[4].XSpan; result.YSpan = dataBlocks[4].YSpan; result.Xllcorner = dataBlocks[4].Xllcorner; result.Yllcorner = dataBlocks[4].Yllcorner; result.Save(File.Open(fileName, FileMode.OpenOrCreate, FileAccess.Write)); #region 预览图 for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { int idx = i * width + j; original[idx] /= 7000; databx[idx] /= 7000; } } OutPng(databx, width, height, fileNameImg); OutPng(original, width, height, fileNameImg2); #endregion } } } }