public static VolumeTexture FromMRC(string path) { VolumeTexture NewTexture = new VolumeTexture(); HeaderMRC Header = HeaderMRC.ReadFromFile(path) as HeaderMRC; NewTexture.Size = Header.Dimensions; NewTexture.Scale = new Vector3(Header.Pixelsize.X, Header.Pixelsize.Y, Header.Pixelsize.Z); NewTexture.Offset = new Vector3(Header.Origin.X, Header.Origin.Y, Header.Origin.Z); unsafe { float[] OriginalData = IOHelper.ReadSmallMapFloat(path, new int2(1, 1), 0, typeof(float)); float DataMin = float.MaxValue, DataMax = float.MinValue; fixed(float *DataPtr = OriginalData) { float *DataP = DataPtr; for (int i = 0; i < OriginalData.Length; i++) { DataMin = Math.Min(DataMin, *DataP); DataMax = Math.Max(DataMax, *DataP++); } float Range = (DataMax - DataMin) / 255f; byte[] DataByte = new byte[OriginalData.Length]; fixed(byte *DataBytePtr = DataByte) { byte *DataByteP = DataBytePtr; DataP = DataPtr; for (int i = 0; i < OriginalData.Length; i++) { *DataByteP++ = (byte)((*DataP++ - DataMin) / Range); } } NewTexture.Data = DataByte; } NewTexture.OriginalData = OriginalData; } return(NewTexture); }
public static VolumeTexture FromMRC(string path) { VolumeTexture NewTexture = new VolumeTexture(); HeaderMRC Header = HeaderMRC.ReadFromFile(path) as HeaderMRC; NewTexture.Size = Header.Dimensions; NewTexture.Scale = new Vector3(Header.Pixelsize.X, Header.Pixelsize.Y, Header.Pixelsize.Z); NewTexture.Offset = new Vector3(Header.Origin.X, Header.Origin.Y, Header.Origin.Z); unsafe { float[] OriginalData = IOHelper.ReadSmallMapFloat(path, new int2(1, 1), 0, typeof(float)); float DataMin = float.MaxValue, DataMax = float.MinValue; fixed (float* DataPtr = OriginalData) { float* DataP = DataPtr; for (int i = 0; i < OriginalData.Length; i++) { DataMin = Math.Min(DataMin, *DataP); DataMax = Math.Max(DataMax, *DataP++); } float Range = (DataMax - DataMin) / 255f; byte[] DataByte = new byte[OriginalData.Length]; fixed (byte* DataBytePtr = DataByte) { byte* DataByteP = DataBytePtr; DataP = DataPtr; for (int i = 0; i < OriginalData.Length; i++) *DataByteP++ = (byte)((*DataP++ - DataMin) / Range); } NewTexture.Data = DataByte; } NewTexture.OriginalData = OriginalData; } return NewTexture; }
public void LoadTomogram(string path) { if (string.IsNullOrEmpty(path)) { return; } if (TomogramTexture != null) { TomogramTexture.FreeBuffers(); } // Make null and go through temp so subsequent parameter updates don't cause a viewport redraw. TomogramTexture = null; VolumeTexture Temp = VolumeTexture.FromMRC(path); PathTomogram = path; MainWindow.Options.PixelScale = Temp.Scale; TomogramTexture = Temp; TomogramTexture.UpdateBuffers(); Viewport.Redraw(); }
public void LoadTomogram(string path) { if (string.IsNullOrEmpty(path)) return; if (TomogramTexture != null) TomogramTexture.FreeBuffers(); // Make null and go through temp so subsequent parameter updates don't cause a viewport redraw. TomogramTexture = null; VolumeTexture Temp = VolumeTexture.FromMRC(path); PathTomogram = path; MainWindow.Options.PixelScale = Temp.Scale; TomogramTexture = Temp; TomogramTexture.UpdateBuffers(); Viewport.Redraw(); }