public static VolumeDataInfo ReadFromFile(DescriptionFile desc, IAsyncReaderProgressNotifier notifier) { var twidth = CeilToBinary(desc.width); var theight = CeilToBinary(desc.height); var tdepth = CeilToBinary(desc.depth); var fileData = new int[twidth * theight * tdepth]; FileStream currentFile = null; bool flag = false; int?minData = null; int?maxData = null; int volumeFileIndex = 0; for (int z = 0; z < desc.depth; z++) { if (flag) { break; } for (int y = 0; y < desc.height; y++) { if (flag) { break; } for (int x = 0; x < desc.width; x++) { if (currentFile == null) { if (volumeFileIndex < desc.volumeData.Length) //we have next file { var nextFilePath = desc.volumeData[volumeFileIndex++]; currentFile = new FileStream(desc.relativePath + "/../" + nextFilePath, FileMode.Open); if (notifier != null) { notifier.Notify("Reading file.. : " + nextFilePath); } } else //all input finished. { flag = true; break; } } //read it. byte[] byData = new byte[desc.byteCount]; if (currentFile.Read(byData, 0, desc.byteCount) == 0) { x--; currentFile.Close(); currentFile = null; continue; } int data = 0; for (int i = 0; i < desc.byteCount; i++) { data <<= 8; data += byData[i]; } fileData[x + y * twidth + z * twidth * theight] = data; if (minData == null) { minData = data; } else { minData = Mathf.Min(minData.Value, data); } if (maxData == null) { maxData = data; } else { maxData = Mathf.Max(maxData.Value, data); } } } } var result = new VolumeDataInfo(twidth, theight, tdepth); for (int i = 0; i < twidth; i++) { notifier.Notify("Filling texture...(" + (int)((float)i / twidth * 100) + "%)"); for (int j = 0; j < theight; j++) { for (int k = 0; k < tdepth; k++) { var data = (float)fileData[i + j * twidth + k * theight * twidth] / (maxData.Value - minData.Value); result[i, j, k] = new Color(data, data, data, data); } } } return(result); }
public AsyncGradientCalculator(VolumeDataInfo info, IAsyncReaderProgressNotifier notifier) { this.info = info; this.notifier = notifier; }
public AsyncReader(DescriptionFile descFile, IAsyncReaderProgressNotifier notifier) { this.descFile = descFile; this.notifier = notifier; }