public void OnDICOMLoaded(object obj = null)
    {
        DICOM dicom = obj as DICOM;

        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);
    }
Example #2
0
        /// <summary>
        /// 胶片格式转换
        /// </summary>
        /// <param name="JPEGPath"></param>
        /// <param name="DICOMPath"></param>
        private void JPEGtoDICOM(string JPEGPath, string DICOMPath)
        {
            if (!Directory.Exists(JPEGPath))
            {
                MessageBox.Show("请指定存放jpeg胶片的路径!", "错误");
                return;
            }

            if (!Directory.Exists(DICOMPath))
            {
                Directory.CreateDirectory(DICOMPath);
            }

            var FileNames = Directory.GetFiles(JPEGPath);

            string DICOMFileName = string.Empty;

            foreach (var JPEGFileName in FileNames)
            {
                DICOMFileName = Path.GetFileNameWithoutExtension(JPEGFileName) + ".DCM";

                if (File.Exists(DICOMFileName))
                {
                    continue;
                }
                else
                {
                    DICOM.ConvertFileToDICOMasGray(JPEGFileName, DICOMFileName);
                }
            }
        }
Example #3
0
    public void OnPointerClick(UnityEngine.EventSystems.PointerEventData eventData)
    {
        // Get the currently loaded DICOM:
        DICOM dicom = DICOMLoader.instance.currentDICOM;

        if (dicom != null)
        {
            // The world position which was clicked:
            Vector3 worldPos = eventData.pointerCurrentRaycast.worldPosition;
            // Transform the position to the patient coordinate system (i.e. in mm)
            Vector3 localPos = transform.InverseTransformPoint(worldPos);

            Debug.Log("Clicked: " + worldPos + " (local: " + localPos + ")");

            // Now we can either transform the position to a continuous pixel position...
            // (to do so, we use the series Info associated with the DICOM:
            Vector3 pixel = dicom.seriesInfo.transformPatientPosToPixel(localPos);
            Debug.Log("Pixel: " + pixel.x + "," + pixel.y + " on layer " + pixel.z);

            // ... or we can transform it to a discrete pixel position:
            Vector3 pixelRounded = dicom.seriesInfo.transformPatientPosToDiscretePixel(localPos);
            Debug.Log("Rounded: " + pixelRounded.x + "," + pixelRounded.y + " on layer " + pixelRounded.z);
        }
        else
        {
            Debug.Log("No DICOM loaded.");
        }
    }
    public void SetDicom(DICOM 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();
    }
Example #5
0
 /*! Loads a DICOM. Called in thread!
  * \note if sliceToLoad is negative, this will load the whole volume. */
 public void load(object sender, DoWorkEventArgs e)
 {
     try {
         DICOM newDICOM = new DICOM(seriesToLoad, sliceToLoad);
         newlyLoadedDICOM = newDICOM;
     } catch (System.Exception err) {
         Debug.LogError("[DICOM] " + err.Message);
         newlyLoadedDICOM = null;
     }
 }
Example #6
0
    //! Called when a new DICOM was loaded:
    void eventDisplayCurrentDicom(object obj = null)
    {
        DICOM dicom = DICOMLoader.instance.currentDICOM;

        if (dicom != null)
        {
            DicomImage.SetDicom(dicom);
            DicomImage.gameObject.SetActive(true);
            StatusText.gameObject.SetActive(false);
            ImageScreen.SetActive(true);
            ListScreen.SetActive(false);
        }
    }
 /*! Loads a DICOM. Called in thread!
  * \note if sliceToLoad is negative, this will load the whole volume. */
 public void load(object sender, DoWorkEventArgs e)
 {
     try {
         Debug.Log("[DICOM] Loading: " + seriesToLoad.seriesUID + " " + sliceToLoad);
         if (sliceToLoad >= 0)
         {
             newlyLoadedDICOM = new DICOM2D(seriesToLoad, sliceToLoad);
         }
         else
         {
             newlyLoadedDICOM = new DICOM3D(seriesToLoad);
         }
         currentDICOMSeries = seriesToLoad;
     } catch (System.Exception err) {
         Debug.LogError("[DICOM] " + err.Message);
         newlyLoadedDICOM = null;
     }
 }
 public void OnDisable()
 {
     currentDICOM = null;
 }
Example #9
0
    void eventNewDICOM(object obj = null)
    {
        DICOM dicom = DICOMLoader.instance.currentDICOM;

        if (dicom != null)
        {
            // If the series has changed, modify the bounding box:
            if (dicom.seriesInfo.seriesUID != currentSeriesUID)
            {
                // Calculate the positions of the corners of this stack of slices:
                int     lastSlice = dicom.seriesInfo.numberOfSlices - 1;
                Vector3 c1        = dicom.seriesInfo.transformPixelToPatientPos(Vector2.zero, 0f);
                Vector3 c2        = dicom.seriesInfo.transformPixelToPatientPos(new Vector2(dicom.origTexWidth, 0f), 0f);
                Vector3 c3        = dicom.seriesInfo.transformPixelToPatientPos(new Vector2(0f, dicom.origTexHeight), 0f);
                Vector3 c4        = dicom.seriesInfo.transformPixelToPatientPos(new Vector2(dicom.origTexWidth, dicom.origTexHeight), 0f);
                Vector3 c5        = dicom.seriesInfo.transformPixelToPatientPos(Vector2.zero, lastSlice);
                Vector3 c6        = dicom.seriesInfo.transformPixelToPatientPos(new Vector2(dicom.origTexWidth, 0f), lastSlice);
                Vector3 c7        = dicom.seriesInfo.transformPixelToPatientPos(new Vector2(0f, dicom.origTexHeight), lastSlice);
                Vector3 c8        = dicom.seriesInfo.transformPixelToPatientPos(new Vector2(dicom.origTexWidth, dicom.origTexHeight), lastSlice);
                Debug.Log("lastSlice " + lastSlice);
                Debug.Log("dicom.texWidth " + dicom.origTexWidth);
                Debug.Log("dicom.texHeight " + dicom.origTexHeight);
                Debug.Log("dicom.directionCosX " + dicom.seriesInfo.directionCosineX.x + " " + dicom.seriesInfo.directionCosineX.y + " " + dicom.seriesInfo.directionCosineX.z);
                Debug.Log("dicom.directionCosY " + dicom.seriesInfo.directionCosineY.x + " " + dicom.seriesInfo.directionCosineY.y + " " + dicom.seriesInfo.directionCosineY.z);
                Debug.Log("c1 " + c1);
                Debug.Log("c4 " + c4);

                // 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;
            }

            // Display the position of the current slice:
            Vector3 p1 = dicom.seriesInfo.transformPixelToPatientPos(Vector2.zero, dicom.slice);
            Vector3 p2 = dicom.seriesInfo.transformPixelToPatientPos(new Vector2(dicom.origTexWidth, 0f), dicom.slice);
            Vector3 p3 = dicom.seriesInfo.transformPixelToPatientPos(new Vector2(dicom.origTexWidth, dicom.origTexHeight), dicom.slice);
            Vector3 p4 = dicom.seriesInfo.transformPixelToPatientPos(new Vector2(0, dicom.origTexHeight), dicom.slice);
            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);
            itk.simple.VectorDouble vec = dicom.image.GetOrigin();
            Debug.Log("dicom.origin " + vec [0] + " " + vec [1] + " " + vec [2]);

            gameObject.SetActive(true);
        }
        else
        {
            gameObject.SetActive(false);
        }
    }
Example #10
0
    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);
        }
    }