public static Texture2D GenerateHistogramTexture(VolumeTextureLoader dataset) { int numSamples = (int)dataset.getHighestHound() + (int)Mathf.Abs(dataset.getLowestHound()) + 1; int[] values = new int[numSamples]; Color[] cols = new Color[numSamples]; Texture2D texture = new Texture2D(numSamples, 1, TextureFormat.RGBAFloat, false); int[] data = dataset.getArr(); int maxFreq = 0; for (int iData = 0; iData < data.Length; iData++) { int value = data[iData] + (int)Mathf.Abs(dataset.getLowestHound()); values[value] += 1; maxFreq = System.Math.Max(values[value], maxFreq); } for (int iSample = 0; iSample < numSamples; iSample++) { cols[iSample] = new Color(Mathf.Log10((float)values[iSample]) / Mathf.Log10((float)maxFreq), 0.0f, 0.0f, 1.0f); } texture.SetPixels(cols); texture.Apply(); return(texture); }
public void reloadTexture() { currTexture = textLoader.getTexture(); if (currTexture == null) { Debug.LogError("Texture not ready"); return; } firstLoad = true; float scaleZ = ((currTexture.depth + 0.0f) / currTexture.height); transform.localScale = new Vector3(1f, 1f, scaleZ); render.material.SetTexture("_Volume", currTexture); render.material.SetFloat("_HoundLow", textLoader.getLowestHound()); render.material.SetFloat("_HoundMax", textLoader.getHighestHound()); Debug.Log("HU Scale -- Low: " + textLoader.getLowestHound() + " Upper: " + textLoader.getHighestHound()); Debug.Log("Scale: " + scaleZ + " dep: " + currTexture.depth + " heigth: " + currTexture.height); render.material.SetTexture("_Volume", currTexture); render.material.SetTexture("_NoiseTex", noiseTexture); }