public void Index16() { int width = 8; int height = 16; int depth = 32; int channels = 3; int bitDepth = 16; TextureData3D data = TextureData3D.CreateData(width, height, depth, channels, bitDepth); float[,,,] arr = new float[width, height, depth, channels]; Random rnd = new Random(0); for (int z = 0; z < data.GetDepth(); z++) { for (int y = 0; y < data.GetHeight(); y++) { for (int x = 0; x < data.GetWidth(); x++) { for (int c = 0; c < data.Channels; c++) { short v = (short)rnd.Next(short.MinValue, short.MaxValue); arr[x, y, z, c] = v / (float)short.MaxValue; data[x, y, z, c] = arr[x, y, z, c]; } } } } EqualsWithError(arr, data, 1e-4f); }
public void Index32() { int width = 8; int height = 16; int depth = 32; int channels = 3; int bitDepth = 32; TextureData3D data = TextureData3D.CreateData(width, height, depth, channels, bitDepth); float[,,,] arr = new float[width, height, depth, channels]; Random rnd = new Random(0); for (int z = 0; z < data.GetDepth(); z++) { for (int y = 0; y < data.GetHeight(); y++) { for (int x = 0; x < data.GetWidth(); x++) { for (int c = 0; c < data.Channels; c++) { arr[x, y, z, c] = (float)rnd.NextDouble(); data[x, y, z, c] = arr[x, y, z, c]; } } } } EqualsWithError(arr, data, 0); }
public void DimensionsCorrect() { int width = 8; int height = 16; int depth = 32; int channels = 3; int bitDepth = 8; TextureData3D data = TextureData3D.CreateData(width, height, depth, channels, bitDepth); Assert.AreEqual(width, data.GetWidth()); Assert.AreEqual(height, data.GetHeight()); Assert.AreEqual(depth, data.GetDepth()); Assert.AreEqual(channels, data.Channels); }
void EqualsWithError(float[,,,] arr, TextureData3D data, float error) { for (int z = 0; z < data.GetDepth(); z++) { for (int y = 0; y < data.GetHeight(); y++) { for (int x = 0; x < data.GetWidth(); x++) { for (int c = 0; c < data.Channels; c++) { float diff = Math.Abs(arr[x, y, z, c] - data[x, y, z, c]); Assert.IsTrue(diff <= error, arr[x, y, z, c] + " and " + data[x, y, z, c] + " have a error of " + diff); } } } } }