public void SetDicom(DICOM2D dicom) { if (mMaterial == null) { mMaterial = new Material(Shader.Find("Unlit/DICOM2D")); GetComponent <RawImage> ().material = mMaterial; } Texture2D tex = dicom.getTexture2D(); currentViewSettings.slice = dicom.slice; mMaterial.SetFloat("globalMinimum", (float)dicom.seriesInfo.minPixelValue); mMaterial.SetFloat("globalMaximum", (float)dicom.seriesInfo.maxPixelValue); GetComponent <RawImage> ().texture = tex; // If this is a new DICOM series, make sure to re-load the View Settings: bool seriesChanged = false; if (currentDICOM == null || currentDICOM.seriesInfo.seriesUID != dicom.seriesInfo.seriesUID) { seriesChanged = true; } currentDICOM = dicom; loadingSlice = false; // Allow loading a new slice if (seriesChanged) { LoadViewSettings(); } UpdateLevelWindow(); ApplyScaleAndPosition(); }
public void OnDICOMLoaded(object obj = null) { DICOM2D dicom = obj as DICOM2D; if (dicom == null) { return; } if (dicom.dimensions != 3) { return; } Image volume = dicom.image; Debug.Log("Width: " + volume.GetWidth() + ", height: " + volume.GetHeight() + ", depth: " + volume.GetDepth()); VectorUInt32 position = new VectorUInt32 { volume.GetWidth() / 2, volume.GetHeight() / 2, volume.GetDepth() / 2 }; // Asumes that the pixel type stored in the image is grayscale int32: int value = volume.GetPixelAsInt16(position); Debug.Log("Value of center pixel: " + value); }
public void OnDisable() { currentDICOM = null; }
void eventNewDICOM(object obj = null) { if (displayMode == DisplayMode.OFF) { gameObject.SetActive(false); return; } DICOM dicom = DICOMLoader.instance.currentDICOM; if (dicom != null) { // If the series has changed, modify the bounding box: /*if (dicom.seriesInfo.seriesUID != currentSeriesUID && dicom.seriesInfo.isConsecutiveVolume) { * * Debug.Log ("3"); * * // Calculate the positions of the corners of this stack of slices: * int lastSlice = dicom.seriesInfo.numberOfSlices - 1; * Vector3 c1 = dicom.transformPixelToPatientPos (Vector2.zero, 0f); * Vector3 c2 = dicom.transformPixelToPatientPos (new Vector2 (dicom.origTexWidth, 0f), 0f); * Vector3 c3 = dicom.transformPixelToPatientPos (new Vector2 (0f, dicom.origTexHeight), 0f); * Vector3 c4 = dicom.transformPixelToPatientPos (new Vector2 (dicom.origTexWidth, dicom.origTexHeight), 0f); * Vector3 c5 = dicom.transformPixelToPatientPos (Vector2.zero, lastSlice); * Vector3 c6 = dicom.transformPixelToPatientPos (new Vector2 (dicom.origTexWidth, 0f), lastSlice); * Vector3 c7 = dicom.transformPixelToPatientPos (new Vector2 (0f, dicom.origTexHeight), lastSlice); * Vector3 c8 = dicom.transformPixelToPatientPos (new Vector2 (dicom.origTexWidth, dicom.origTexHeight), lastSlice); * * // Display the bounding box: * Edge1.SetPosition (0, c1); * Edge1.SetPosition (1, c2); * Edge2.SetPosition (0, c1); * Edge2.SetPosition (1, c3); * Edge3.SetPosition (0, c2); * Edge3.SetPosition (1, c4); * Edge4.SetPosition (0, c3); * Edge4.SetPosition (1, c4); * * Edge5.SetPosition (0, c5); * Edge5.SetPosition (1, c6); * Edge6.SetPosition (0, c5); * Edge6.SetPosition (1, c7); * Edge7.SetPosition (0, c6); * Edge7.SetPosition (1, c8); * Edge8.SetPosition (0, c7); * Edge8.SetPosition (1, c8); * * Edge9.SetPosition (0, c1); * Edge9.SetPosition (1, c5); * Edge10.SetPosition (0, c2); * Edge10.SetPosition (1, c6); * Edge11.SetPosition (0, c3); * Edge11.SetPosition (1, c7); * Edge12.SetPosition (0, c4); * Edge12.SetPosition (1, c8); * * // Remember which series we're currently using: * currentSeriesUID = dicom.seriesInfo.seriesUID; * Edge1.enabled = true; * Edge2.enabled = true; * Edge3.enabled = true; * Edge4.enabled = true; * Edge5.enabled = true; * Edge6.enabled = true; * Edge7.enabled = true; * Edge8.enabled = true; * Edge9.enabled = true; * Edge10.enabled = true; * Edge11.enabled = true; * Edge12.enabled = true; * } else { * Edge1.enabled = false; * Edge2.enabled = false; * Edge3.enabled = false; * Edge4.enabled = false; * Edge5.enabled = false; * Edge6.enabled = false; * Edge7.enabled = false; * Edge8.enabled = false; * Edge9.enabled = false; * Edge10.enabled = false; * Edge11.enabled = false; * Edge12.enabled = false; * }*/ if (dicom is DICOM2D) { DICOM2D dicom2D = dicom as DICOM2D; // Display the position of the current slice: Vector3 p1 = dicom2D.transformPixelToPatientPos(Vector2.zero); Vector3 p2 = dicom2D.transformPixelToPatientPos(new Vector2(dicom2D.origTexWidth, 0f)); Vector3 p3 = dicom2D.transformPixelToPatientPos(new Vector2(dicom2D.origTexWidth, dicom2D.origTexHeight)); Vector3 p4 = dicom2D.transformPixelToPatientPos(new Vector2(0, dicom2D.origTexHeight)); RectXMin.SetPosition(0, p1); RectXMin.SetPosition(1, p4); RectXMax.SetPosition(0, p2); RectXMax.SetPosition(1, p3); RectYMin.SetPosition(0, p1); RectYMin.SetPosition(1, p2); RectYMax.SetPosition(0, p3); RectYMax.SetPosition(1, p4); RectXMin.enabled = true; RectXMax.enabled = true; RectYMin.enabled = true; RectYMax.enabled = true; //itk.simple.VectorDouble vec = dicom2D.origin; //Debug.Log ("dicom2D.origin " + vec [0] + " " + vec [1] + " " + vec [2]); } else { RectXMin.enabled = false; RectXMax.enabled = false; RectYMin.enabled = false; RectYMax.enabled = false; } gameObject.SetActive(true); } else { gameObject.SetActive(false); } }