diff --git a/SDFMapCreator/Program.cs b/SDFMapCreator/Program.cs index 6c31d26..082c163 100644 --- a/SDFMapCreator/Program.cs +++ b/SDFMapCreator/Program.cs @@ -63,7 +63,6 @@ public static class Program { ConsoleUpdateLine($"Creating mask {i}..."); var mask = GetABMask(Images[i].Pixels, Images[i + 1].Pixels); TransitionMasks.Add(new(mask, Images[i], Images[i + 1])); - if (debug) mask.SaveImage($"Debug/mask{i}.png"); } //EdgeDetect all masks @@ -182,6 +181,25 @@ public static class Program { sw.Start(); kernels.Sdf(mask.Edges.ToArray(), (int)width, (int)height, out var temp); Console.WriteLine($"\nSDF Generation Time: {sw.Elapsed.TotalSeconds:N4}s ({width * height / sw.Elapsed.TotalSeconds:N0} pixels/s)"); + + sw.Restart(); + var absMax = 0f; + foreach (var pixel in temp) { + if (pixel.X > absMax) absMax = pixel.X; + } + + Parallel.For(0, width * height, parallelOptions, (i) => + { + //convert 1D index to 2D index + var x = (int)(i % width); + var y = (int)(i / width); + temp[x, y] = new(Remap(temp[x, y].X, 0, absMax, MIN, MAX)); + }); + sw.Stop(); + + Console.WriteLine( + $"SDF Normalization Time: {sw.Elapsed.TotalSeconds:N4}s ({width*height / sw.Elapsed.TotalSeconds:N0} pixels/s)"); + return new(temp); }