/*! Given a uv coordinate on the DicomDisplayImage (for example a mouse position), calculate which pixel was hit.
     * This uses the Dicom's current displacement and zooming to calculate the pixel */
    public Vector2 uvToPixel(Vector2 uv)
    {
        // Transfer the uv-coordinate in the space of the full DICOM window to
        // uv-coordinates for the current layer:
        Vector2 dicomUV = imageUVtoLayerUV(uv);
        // Calculate which pixel this uv represents:
        Vector2 pixel = new Vector3(dicomUV.x * currentDICOM.getTexture2D().width,
                                    dicomUV.y * currentDICOM.getTexture2D().height);

        return(pixel);
    }
    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();
    }