public void TestMCAAccuracy() { var heights = HeightmapImporter.ImportHeightmapRaw(Path.Combine(inputPath, sampleHeightmapFile), 0, 0, 512, 512); HeightData data = new HeightData(512, 512, null) { lowPoint = 0, highPoint = 255 }; for (int i = 0; i < 512; i++) { for (int j = 0; j < 512; j++) { data.SetHeight(i, j, heights[i, j]); } } var sampleLocations = GetSampleLocations(data.GridWidth, data.GridHeight); var sourceSamples = GetHeightSamples(data, sampleLocations); string mcaname = "accuracy-test-r.0.0.mca"; AssertExport(data, "MCR-RAW", mcaname); var reimported = ImportManager.ImportFile(Path.Combine(outputPath, mcaname)); var convSamples = GetHeightSamples(reimported, sampleLocations); AssertExport(data, "IMG_PNG-HM", "reconstructed_mca.png"); Assert.AreEqual(sourceSamples, convSamples); }
public static bool ConvertFile(string inputPath, string outputPath, ExportSettings settings, params string[] importArgs) { if (!isInitialized) { throw new ArgumentException("The application must be initialized before it can be used"); } HeightData data = ImportManager.ImportFile(inputPath, importArgs); return(true); }
public void TestMCAFileHandling() { HeightData data = ImportManager.ImportFile(Path.Combine(inputPath, sampleMCAFile)); data.lowPoint = 0; data.highPoint = 255; //var sampleLocations = GetSampleLocations(data.GridWidth, data.GridHeight); //var sourceSamples = GetHeightSamples(data, sampleLocations); currentJob.exportSettings.SetCustomSetting("mcaOffsetX", 16); currentJob.exportSettings.SetCustomSetting("mcaOffsetZ", 26); AssertExport(data, "MCR", sampleMCAFile); AssertExport(data, "IMG_PNG-HS", sampleMCAFile); AssertExport(data, "IMG_PNG-HM", sampleMCAFile); }
public void TestHeightmapHandling() { HeightData data = ImportManager.ImportFile(Path.Combine(inputPath, sampleHeightmapFile)); var sampleLocations = GetSampleLocations(data.GridWidth, data.GridHeight); var sourceSamples = GetHeightSamples(data, sampleLocations); AssertExport(data, "IMG_PNG-HM", sampleHeightmapFile); data = ImportManager.ImportFile(Path.Combine(outputPath, sampleHeightmapFile)); var exportedSamples = GetHeightSamples(data, sampleLocations); for (int i = 0; i < sourceSamples.Length; i++) { Assert.AreEqual(sourceSamples[i], exportedSamples[i], 0.0001d, $"Index {i}, location [{sampleLocations[i].x},{sampleLocations[i].y}]"); } }
public void TestMCAHeightRounding() { HeightData data = new HeightData(512, 512, null); for (int z = 0; z < 128; z++) { for (int x = 0; x < 512; x++) { float h1 = MathUtils.Clamp01(x / 510f); float h2 = MathUtils.Clamp01(x / 255f); float h3 = 0.5f; float h4 = (x + 1) / 512f * 0.33f; data.SetHeight(x, z, h1); data.SetHeight(x, 128 + z, h2); data.SetHeight(x, 256 + z, h3); data.SetHeight(x, 384 + z, h4); } } data.cellSize = 1; data.lowPoint = 0; data.highPoint = 1; data.Rescale(0, 255); for (int x = 0; x < 512; x++) { data.SetHeight(x, 1, (float)Math.Round(data.GetHeight(x, 1), MidpointRounding.AwayFromZero)); } var samples = GetHeightSamples(data, GetSampleLocations(512, 512)); for (int i = 0; i < samples.Length; i++) { samples[i] = (float)Math.Round(samples[i], MidpointRounding.AwayFromZero); } AssertExport(data, "ASC", gradientMCAFile + "_asc"); AssertExport(data, "IMG_PNG-HM-S", gradientMCAFile + "_pre_hm"); AssertExport(data, "IMG_PNG-HS", gradientMCAFile + "_pre_hs"); AssertExport(data, "MCR-RAW", gradientMCAFile); data = ImportManager.ImportFile(Path.Combine(outputPath, gradientMCAFile) + ".mca"); AssertExport(data, "IMG_PNG-HM-S", gradientMCAFile + "_conv_hm"); AssertExport(data, "IMG_PNG-HS", gradientMCAFile + "_conv_hs"); var mcaSamples = GetHeightSamples(data, GetSampleLocations(512, 512)); Assert.AreEqual(samples, mcaSamples); }
public void TestASCAccurateResizing() { HeightData data = ImportManager.ImportFile(Path.Combine(inputPath, sampleASCFile)); var sampleLocationsOriginal = GetSampleLocations(data.GridWidth, data.GridHeight); var sourceSamples = GetHeightSamples(data, sampleLocationsOriginal); HeightData resized = new HeightData(data); resized.Resize(data.GridWidth * 2, false); Assert.AreEqual(4000, resized.GridWidth); AssertExport(data, "IMG_PNG-HM", "asc-original"); AssertExport(resized, "IMG_PNG-HM", "asc-resized"); var resizedLocations = GetSampleLocations(resized.GridWidth, resized.GridHeight); var resizedSamples = GetHeightSamples(resized, resizedLocations); double delta = 0.05f; for (int i = 0; i < sourceSamples.Length; i++) { Assert.AreEqual(sourceSamples[i], resizedSamples[i], delta, $"Index {i}, location in original [{sampleLocationsOriginal[i].x},{sampleLocationsOriginal[i].y}], in resized [{resizedLocations[i].x},{resizedLocations[i].y}]"); } Assert.AreEqual(data.highestValue, resized.highestValue, delta); Assert.AreEqual(data.lowestValue, resized.lowestValue, delta); }
public HeightData NextFile() { CurrentData = null; CurrentFileIndex++; if (CurrentFileIndex < InputFileList.Count) { string f = InputFileList[0]; string ext = Path.GetExtension(f).ToLower().Replace(".", ""); HeightData d; try { d = ImportManager.ImportFile(InputFileList[CurrentFileIndex], importArgs); if (d != null) { //CurrentExportJobInfo.importedFilePath = f; CurrentData = d; if (FileImported != null) { FileImported(CurrentFileIndex, f); } return(d); } else { throw new IOException("Unsupported file type: " + ext); } } catch (Exception e) { if (FileImportFailed != null) { FileImportFailed(CurrentFileIndex, f, e); } return(null); } } else { return(null); } }
public void TestASCResizing() { HeightData data = ImportManager.ImportFile(Path.Combine(inputPath, sampleASCFile)); var sampleLocationsOriginal = GetSampleLocations(data.GridWidth, data.GridHeight); var sourceSamples = GetHeightSamples(data, sampleLocationsOriginal); int scale = (int)(data.GridWidth * 1.39f); HeightData resized = new HeightData(data); resized.Resize(scale, false); HeightData rescaled = new HeightData(data); rescaled.Resize(scale, true); AssertExport(rescaled, "IMG_PNG-HS", resizedASCFileHS); var resizedSamples = GetHeightSamples(resized, GetSampleLocations(resized.GridWidth, resized.GridHeight)); double delta = 0.4f; for (int i = 0; i < sourceSamples.Length; i++) { Assert.AreEqual(sourceSamples[i], resizedSamples[i], delta, $"Index {i}, location in original [{sampleLocationsOriginal[i].x},{sampleLocationsOriginal[i].y}]"); } Assert.AreEqual(data.highestValue, resized.highestValue, delta / 2); Assert.AreEqual(data.lowestValue, resized.lowestValue, delta / 2); }