OHIF / Viewers

OHIF zero-footprint DICOM viewer and oncology specific Lesion Tracker, plus shared extension packages
https://docs.ohif.org/
MIT License
2.98k stars 3.12k forks source link

fix(CustomViewportOverlay): pass accurate data to Custom Viewport Functions #4224

Closed Michael-Andersen closed 1 week ago

Michael-Andersen commented 2 weeks ago

Context

The current CustomViewportOverlay does not provide very useful data to any custom overlay function defined in the config.

This was discussed in a previous OHIF Office Hours: https://github.com/OHIF/OHIF-Office-Hours/blob/main/notes/2024-06-07.md

Changes & Results

This change is to provide the current displayed instance(s) if it is in the acquisition plane and a general reference instance for all other viewports. The current instance allows the user to write custom functions which might display particular instance level tags in the acquisition plane viewport such as SliceLocation and the reference instance allows the user to write custom functions which will make use of general tags such as SeriesDescription or ImagePositionPatient.

Testing

Here is an example of a custom overlay function you can define in the config to display SliceLocation:

cornerstoneOverlayTopRight: {
      id: 'cornerstoneOverlayTopRight',
      items: [
        {
          id: 'InstanceNmber',
          customizationType: 'ohif.overlayItem.instanceNumber',
        },
        {
          id: 'SliceLocation',
          customizationType: 'ohif.overlayItem',
          label: 'Loc:',
          title: 'Slice Location',
          instanceIndex: 0,
          contentF: ({ referenceInstance,
            currentInstance,
            viewportData,
            imageSliceData,
            viewportId,
            instanceNumber, formatters: { formatNumberPrecision } }) =>
            { 
            if (!referenceInstance) {
                              return;
                           }
              var instanceNum;
              if (referenceInstance.ImagePositionPatient == null) {
                return;
              }
              if (viewportId.toLowerCase().includes("fusion")) {
                return;
              }
              if (viewportId.toLowerCase().includes("sagittal")) {
                instanceNum = imageSliceData.imageIndex;
                var res = formatNumberPrecision(referenceInstance.ImagePositionPatient[0] + (referenceInstance.PixelSpacing[0] * instanceNum), 2) + ' mm';
                return res;
              } else if (viewportId.toLowerCase().includes("coronal")) {
                instanceNum = imageSliceData.imageIndex;
                var res = formatNumberPrecision(referenceInstance.ImagePositionPatient[1] + (referenceInstance.PixelSpacing[1] * instanceNum), 2) + ' mm';
                return res;
              } else {
              instanceNum = currentInstance.ImageIndex - 1;
              var res = formatNumberPrecision(currentInstance.SliceLocation, 2) + ' mm';
              return res;
            }},
            }

Checklist

PR

Code

Public Documentation Updates

Tested Environment

netlify[bot] commented 2 weeks ago

Deploy Preview for ohif-platform-docs ready!

Name Link
Latest commit c0834e8c59d292c56abc493483fca0b56f769faa
Latest deploy log https://app.netlify.com/sites/ohif-platform-docs/deploys/6675dbedcbaded0008250b1f
Deploy Preview https://deploy-preview-4224--ohif-platform-docs.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

netlify[bot] commented 2 weeks ago

Deploy Preview for ohif-dev canceled.

Name Link
Latest commit c0834e8c59d292c56abc493483fca0b56f769faa
Latest deploy log https://app.netlify.com/sites/ohif-dev/deploys/6675dbedac0a4c0008f1bc3b
Michael-Andersen commented 2 weeks ago

@wayfarer3130 As discussed last Thursday in Office Hours

wayfarer3130 commented 1 week ago

I pushed an update to your branch to merge master. Going to add a couple of changes and then let you look at them.

sedghi commented 1 week ago

@wayfarer3130 Can you please check if these two issues are resolved? if not we fix it in this PR?

https://github.com/OHIF/Viewers/issues/4175 https://github.com/OHIF/Viewers/issues/4168

sedghi commented 1 week ago

This has broken the sorting of the studies https://github.com/OHIF/Viewers/pull/4214