diff --git a/Assets/Importing.meta b/Assets/Importing.meta new file mode 100644 index 0000000..0fe8276 --- /dev/null +++ b/Assets/Importing.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: a9c03434ec9e4124b83fc4630dc53023 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Importing/RawDatasetImporter.cs b/Assets/Importing/RawDatasetImporter.cs new file mode 100644 index 0000000..bcd964d --- /dev/null +++ b/Assets/Importing/RawDatasetImporter.cs @@ -0,0 +1,81 @@ +using System; +using System.IO; +using UnityEngine; + +public enum DataContentFormat +{ + Int8, + Uint8, + Int16, + Uint16, + Int32, + Uint32 +} + +public class RawDatasetImporter +{ + string filePath; + private int dimX; + private int dimY; + private int dimZ; + private DataContentFormat contentFormat; + + public RawDatasetImporter(string filePath, int dimX, int dimY, int dimZ, DataContentFormat contentFormat) + { + this.filePath = filePath; + this.dimX = dimX; + this.dimY = dimY; + this.dimZ = dimZ; + this.contentFormat = contentFormat; + } + + public VolumeDataset Import() + { + VolumeDataset dataset = new VolumeDataset(); + + FileStream fs = new FileStream(filePath, FileMode.Open); + BinaryReader reader = new BinaryReader(fs); + + int uDimension = dimX * dimY * dimZ; + dataset.texture = new Texture3D(dimX, dimY, dimZ, TextureFormat.RGBAFloat, false); + dataset.colours = new Color[uDimension]; + + float minVal = float.PositiveInfinity; + float maxVal = float.NegativeInfinity; + float val = 0.0f; + for (int i = 0; i < uDimension; i++) + { + switch(contentFormat) + { + case DataContentFormat.Int8: + val = (float)reader.ReadByte(); + break; + case DataContentFormat.Int16: + val = (float)reader.ReadInt16(); + break; + case DataContentFormat.Int32: + val = (float)reader.ReadInt32(); + break; + case DataContentFormat.Uint8: + val = (float)reader.ReadByte(); + break; + case DataContentFormat.Uint16: + val = (float)reader.ReadUInt16(); + break; + case DataContentFormat.Uint32: + val = (float)reader.ReadUInt32(); + break; + } + minVal = Mathf.Min(minVal, val); + maxVal = Mathf.Max(maxVal, val); + dataset.colours[i] = new Color(val, 0.0f, 0.0f); + } + Debug.Log("Loaded dataset in range: " + minVal + " - " + maxVal); + Debug.Log(minVal + " - " + maxVal); + + dataset.texture.SetPixels(dataset.colours); + dataset.texture.Apply(); + + return dataset; + } +} diff --git a/Assets/Importing/RawDatasetImporter.cs.meta b/Assets/Importing/RawDatasetImporter.cs.meta new file mode 100644 index 0000000..ba081fc --- /dev/null +++ b/Assets/Importing/RawDatasetImporter.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 45cd99ee9f504d44ca6d48b0d06a6423 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/VolumeRenderer.cs b/Assets/Scripts/VolumeRenderer.cs index 2bee0d3..37248c2 100644 --- a/Assets/Scripts/VolumeRenderer.cs +++ b/Assets/Scripts/VolumeRenderer.cs @@ -16,41 +16,21 @@ public class VolumeRenderer : MonoBehaviour ushort dimY = reader.ReadUInt16(); ushort dimZ = reader.ReadUInt16(); + reader.Close(); + fs.Close(); + Debug.Log(dimX + ", " + dimY + ", " + dimZ); int uDimension = dimX * dimY * dimZ; - Texture3D tex = new Texture3D(dimX, dimY, dimZ, TextureFormat.RGBAFloat, false); - Color[] cols = new Color[uDimension]; - float minVal = float.PositiveInfinity; - float maxVal = float.NegativeInfinity; - for(int i = 0; i < uDimension; i++) - { - float val = (float)reader.ReadInt16(); - minVal = Mathf.Min(minVal, val); - maxVal = Mathf.Max(maxVal, val); - cols[i] = new Color(val, 0.0f, 0.0f); - } - Debug.Log(minVal + " - " + maxVal); - tex.SetPixels(cols); - tex.Apply(); + RawDatasetImporter importer = new RawDatasetImporter("DataFiles//manix.dat", dimX, dimY, dimZ, DataContentFormat.Int16); + VolumeDataset dataset = importer.Import(); + + Texture3D tex = dataset.texture; const int noiseDimX = 512; const int noiseDimY = 512; - - Texture2D noiseTexture = new Texture2D(noiseDimX, noiseDimY); - Color[] noiseCols = new Color[noiseDimX * noiseDimY]; - for(int iY = 0; iY < noiseDimY; iY++) - { - for (int iX = 0; iX < noiseDimX; iX++) - { - float pixVal = Random.Range(0.0f, 1.0f); - noiseCols[iX + iY * noiseDimX] = new Color(pixVal, pixVal, pixVal); - } - } - - noiseTexture.SetPixels(noiseCols); - noiseTexture.Apply(); + Texture2D noiseTexture = NoiseTextureGenerator.GenerateNoiseTexture(noiseDimX, noiseDimY); tf = new TransferFunction(); tf.AddControlPoint(new TFColourControlPoint(0.0f, new Color(0.11f, 0.14f, 0.13f, 1.0f))); diff --git a/Assets/Utils.meta b/Assets/Utils.meta new file mode 100644 index 0000000..a041f02 --- /dev/null +++ b/Assets/Utils.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 25442e9d1d762de439428ed034dc4c09 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Utils/NoiseTextureGenerator.cs b/Assets/Utils/NoiseTextureGenerator.cs new file mode 100644 index 0000000..d3ff79c --- /dev/null +++ b/Assets/Utils/NoiseTextureGenerator.cs @@ -0,0 +1,22 @@ +using UnityEngine; + +public class NoiseTextureGenerator +{ + public static Texture2D GenerateNoiseTexture(int noiseDimX, int noiseDimY) + { + Texture2D noiseTexture = new Texture2D(noiseDimX, noiseDimY); + Color[] noiseCols = new Color[noiseDimX * noiseDimY]; + for (int iY = 0; iY < noiseDimY; iY++) + { + for (int iX = 0; iX < noiseDimX; iX++) + { + float pixVal = Random.Range(0.0f, 1.0f); + noiseCols[iX + iY * noiseDimX] = new Color(pixVal, pixVal, pixVal); + } + } + + noiseTexture.SetPixels(noiseCols); + noiseTexture.Apply(); + return noiseTexture; + } +} diff --git a/Assets/Utils/NoiseTextureGenerator.cs.meta b/Assets/Utils/NoiseTextureGenerator.cs.meta new file mode 100644 index 0000000..298eabf --- /dev/null +++ b/Assets/Utils/NoiseTextureGenerator.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ed6362746a619f540963023e61710552 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/VolumeData.meta b/Assets/VolumeData.meta new file mode 100644 index 0000000..0737c1e --- /dev/null +++ b/Assets/VolumeData.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 71839df0988a2de4cb18650e448bb973 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/VolumeData/VolumeDataset.cs b/Assets/VolumeData/VolumeDataset.cs new file mode 100644 index 0000000..868d987 --- /dev/null +++ b/Assets/VolumeData/VolumeDataset.cs @@ -0,0 +1,8 @@ +using System; +using UnityEngine; + +public class VolumeDataset +{ + public Color[] colours = null; + public Texture3D texture = null; +} diff --git a/Assets/VolumeData/VolumeDataset.cs.meta b/Assets/VolumeData/VolumeDataset.cs.meta new file mode 100644 index 0000000..202fe7d --- /dev/null +++ b/Assets/VolumeData/VolumeDataset.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 6c292ee2920c4d64989a78d4ed9abb7e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: