Skip to content

Commit

Permalink
fix(SR): KO series being displayed in browser list (#3382)
Browse files Browse the repository at this point in the history
* fix: KO series being displayed in browser list

* fix sr for volume viewports

* move highlight labelmap to RAF

* remove commented code

* fix the hydration bug for the SR

* apply review comments

* revert the key images for sr

* Remove some obsolete changes

* set initial image for sr instead of jump

* Remove viewportType stack

---------

Co-authored-by: Alireza <[email protected]>
  • Loading branch information
wayfarer3130 and sedghi authored May 15, 2023
1 parent 4172d04 commit d5c5951
Show file tree
Hide file tree
Showing 20 changed files with 249 additions and 229 deletions.
10 changes: 5 additions & 5 deletions extensions/cornerstone-dicom-rt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,20 @@
"webpack-merge": "^5.7.3"
},
"dependencies": {
"@babel/runtime": "7.7.6",
"@babel/runtime": "^7.20.13",
"react-color": "^2.19.3"
},
"devDependencies": {
"@babel/core": "^7.5.0",
"@babel/core": "^7.21.4",
"@babel/plugin-proposal-class-properties": "^7.5.0",
"@babel/plugin-proposal-object-rest-spread": "^7.5.5",
"@babel/plugin-syntax-dynamic-import": "^7.2.0",
"@babel/plugin-transform-arrow-functions": "^7.2.0",
"@babel/plugin-transform-regenerator": "^7.4.5",
"@babel/plugin-transform-runtime": "^7.5.0",
"@babel/plugin-transform-regenerator": "^7.16.7",
"@babel/plugin-transform-runtime": "^7.17.0",
"babel-plugin-inline-react-svg": "^2.0.1",
"@babel/preset-env": "^7.5.0",
"@babel/preset-react": "^7.0.0",
"@babel/preset-react": "^7.16.7",
"babel-eslint": "^8.0.3",
"babel-loader": "^8.0.0-beta.4",
"clean-webpack-plugin": "^4.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ function OHIFCornerstoneRTViewport(props) {
}}
onElementEnabled={onElementEnabled}
onElementDisabled={onElementDisabled}
// initialImageIndex={initialImageIndex}
></Component>
);
}, [viewportIndex, rtDisplaySet, toolGroupId]);
Expand Down
8 changes: 4 additions & 4 deletions extensions/cornerstone-dicom-seg/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,16 @@
"react-color": "^2.19.3"
},
"devDependencies": {
"@babel/core": "^7.5.0",
"@babel/core": "^7.21.4",
"@babel/plugin-proposal-class-properties": "^7.5.0",
"@babel/plugin-proposal-object-rest-spread": "^7.5.5",
"@babel/plugin-syntax-dynamic-import": "^7.2.0",
"@babel/plugin-transform-arrow-functions": "^7.2.0",
"@babel/plugin-transform-regenerator": "^7.4.5",
"@babel/plugin-transform-runtime": "^7.5.0",
"@babel/plugin-transform-regenerator": "^7.16.7",
"@babel/plugin-transform-runtime": "^7.17.0",
"babel-plugin-inline-react-svg": "^2.0.1",
"@babel/preset-env": "^7.5.0",
"@babel/preset-react": "^7.0.0",
"@babel/preset-react": "^7.16.7",
"babel-eslint": "^8.0.3",
"babel-loader": "^8.0.0-beta.4",
"clean-webpack-plugin": "^4.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,6 @@ function addInstances(
// gets loaded, and to navigate among them.
this.instance = this.instances[this.instances.length - 1];
this.isLoaded = false;
if (this.keyImageDisplaySet) {
this.load();
this.keyImageDisplaySet.updateInstances();
displaySetService.setDisplaySetMetadataInvalidated(
this.keyImageDisplaySet.displaySetInstanceUID
);
}
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const findReferencedInstances = (
const createReferencedImageDisplaySet = (displaySetService, displaySet) => {
const instances = findReferencedInstances(displaySetService, displaySet);
// This will be a member function of the created image set
const updateInstances = function () {
const updateInstances = function() {
this.images.splice(
0,
this.images.length,
Expand Down Expand Up @@ -78,6 +78,7 @@ const createReferencedImageDisplaySet = (displaySetService, displaySet) => {
// This object is made of multiple instances from other series
isCompositeStack: true,
madeInClient: true,
excludeFromThumbnailBrowser: true,
updateInstances,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { setTrackingUniqueIdentifiersForElement } from '../tools/modules/dicomSR

import { Icon, Tooltip, useViewportGrid, ViewportActionBar } from '@ohif/ui';
import hydrateStructuredReport from '../utils/hydrateStructuredReport';
import createReferencedImageDisplaySet from '../utils/createReferencedImageDisplaySet';

const { formatDate } = utils;

Expand All @@ -22,8 +21,8 @@ function OHIFCornerstoneSRViewport(props) {
dataSource,
displaySets,
viewportIndex,
viewportOptions,
viewportLabel,
viewportOptions,
servicesManager,
extensionManager,
} = props;
Expand Down Expand Up @@ -80,9 +79,9 @@ function OHIFCornerstoneSRViewport(props) {
{ servicesManager, extensionManager },
displaySetInstanceUID
);
const displaySets = srDisplaySet.keyImageDisplaySet
? [srDisplaySet.keyImageDisplaySet]
: displaySetService.getDisplaySetsForSeries(SeriesInstanceUIDs[0]);
const displaySets = displaySetService.getDisplaySetsForSeries(
SeriesInstanceUIDs[0]
);
if (displaySets.length) {
viewportGridService.setDisplaySetsForViewports([
{
Expand Down Expand Up @@ -210,9 +209,19 @@ function OHIFCornerstoneSRViewport(props) {
// should be passed second since we don't want SR displaySet to
// override the activeImageDisplaySetData
displaySets={[activeImageDisplaySetData]}
// It is possible that there is a hanging protocol applying viewportOptions
// for the SR, so inherit the viewport options
// TODO: Ensure the viewport options are set correctly with respect to
// stack etc, in the incoming viewport options.
viewportOptions={{
...viewportOptions,
toolGroupId: `${SR_TOOLGROUP_BASE_NAME}`,
// viewportType should not be required, as the stack type should be
// required already in order to view SR, but sometimes segmentation
// views set the viewport type without fixing the allowed display
viewportType: 'stack',
// The positionIds for the viewport aren't meaningful for the child display sets
positionIds: null,
}}
onElementEnabled={onElementEnabled}
initialImageIndex={initialImageIndex}
Expand Down Expand Up @@ -420,18 +429,14 @@ async function _getViewportReferencedDisplaySetData(
measurementSelected,
displaySetService
) {
if (!displaySet.keyImageDisplaySet) {
// Create a new display set, and preserve a reference to it here,
// so that it can be re-displayed and shown inside the SR viewport.
// This is only for ease of redisplay - the display set is stored in the
// usual manner in the display set service.
displaySet.keyImageDisplaySet = createReferencedImageDisplaySet(
displaySetService,
displaySet
);
}
const { measurements } = displaySet;
const measurement = measurements[measurementSelected];

const { displaySetInstanceUID } = measurement;

const referencedDisplaySet = displaySet.keyImageDisplaySet;
const referencedDisplaySet = displaySetService.getDisplaySetByUID(
displaySetInstanceUID
);

const image0 = referencedDisplaySet.images[0];
const referencedDisplaySetMetadata = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -567,8 +567,9 @@ function _subscribeToJumpToMeasurementEvents(
{ referencedImageId: measurement.referencedImageId }
);
}
if (cacheJumpToMeasurementEvent.cornerstoneViewport !== viewportIndex)
if (cacheJumpToMeasurementEvent.cornerstoneViewport !== viewportIndex) {
return;
}
_jumpToMeasurement(
measurement,
elementRef,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1247,37 +1247,39 @@ class SegmentationService extends PubSubService {

const { fillAlpha } = this.getConfiguration(toolGroupId);

let count = 0;
const intervalTime = 16;
const numberOfFrames = Math.ceil(animationLength / intervalTime);
let startTime: number = null;
const animation = (timestamp: number) => {
if (startTime === null) {
startTime = timestamp;
}

const elapsed = timestamp - startTime;
const progress = Math.min(elapsed / animationLength, 1);

this.highlightIntervalId = setInterval(() => {
const x = (count * intervalTime) / animationLength;
cstSegmentation.config.setSegmentSpecificConfig(
toolGroupId,
segmentationRepresentation.segmentationRepresentationUID,
{
[segmentIndex]: {
LABELMAP: {
fillAlpha: easeInOutBell(x, fillAlpha),
fillAlpha: easeInOutBell(progress, fillAlpha),
},
},
}
);

count++;

if (count === numberOfFrames) {
clearInterval(this.highlightIntervalId);
if (progress < 1) {
requestAnimationFrame(animation);
} else {
cstSegmentation.config.setSegmentSpecificConfig(
toolGroupId,
segmentationRepresentation.segmentationRepresentationUID,
{}
);

this.highlightIntervalId = null;
}
}, intervalTime);
};

requestAnimationFrame(animation);
}

private _highlightContour(
Expand Down
54 changes: 28 additions & 26 deletions extensions/default/src/Panels/PanelStudyBrowser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -296,34 +296,36 @@ function _mapDisplaySets(displaySets, thumbnailImageSrcMap) {
const thumbnailDisplaySets = [];
const thumbnailNoImageDisplaySets = [];

displaySets.forEach(ds => {
const imageSrc = thumbnailImageSrcMap[ds.displaySetInstanceUID];
const componentType = _getComponentType(ds.Modality);

const array =
componentType === 'thumbnail'
? thumbnailDisplaySets
: thumbnailNoImageDisplaySets;

array.push({
displaySetInstanceUID: ds.displaySetInstanceUID,
description: ds.SeriesDescription || '',
seriesNumber: ds.SeriesNumber,
modality: ds.Modality,
seriesDate: ds.SeriesDate,
seriesTime: ds.SeriesTime,
numInstances: ds.numImageFrames,
countIcon: ds.countIcon,
StudyInstanceUID: ds.StudyInstanceUID,
componentType,
imageSrc,
dragData: {
type: 'displayset',
displaySets
.filter(ds => !ds.excludeFromThumbnailBrowser)
.forEach(ds => {
const imageSrc = thumbnailImageSrcMap[ds.displaySetInstanceUID];
const componentType = _getComponentType(ds.Modality);

const array =
componentType === 'thumbnail'
? thumbnailDisplaySets
: thumbnailNoImageDisplaySets;

array.push({
displaySetInstanceUID: ds.displaySetInstanceUID,
// .. Any other data to pass
},
description: ds.SeriesDescription || '',
seriesNumber: ds.SeriesNumber,
modality: ds.Modality,
seriesDate: ds.SeriesDate,
seriesTime: ds.SeriesTime,
numInstances: ds.numImageFrames,
countIcon: ds.countIcon,
StudyInstanceUID: ds.StudyInstanceUID,
componentType,
imageSrc,
dragData: {
type: 'displayset',
displaySetInstanceUID: ds.displaySetInstanceUID,
// .. Any other data to pass
},
});
});
});

return [...thumbnailDisplaySets, ...thumbnailNoImageDisplaySets];
}
Expand Down
8 changes: 4 additions & 4 deletions extensions/dicom-microscopy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@
},
"dependencies": {
"@babel/runtime": "^7.20.13",
"@cornerstonejs/codec-charls": "^0.1.1",
"@cornerstonejs/codec-libjpeg-turbo-8bit": "^0.0.7",
"@cornerstonejs/codec-openjpeg": "^0.1.1",
"@cornerstonejs/codec-charls": "^1.2.3",
"@cornerstonejs/codec-libjpeg-turbo-8bit": "^1.2.2",
"@cornerstonejs/codec-openjpeg": "^1.2.2",
"colormap": "^2.3",
"dicom-microscopy-viewer": "^0.44.0",
"dicomicc": "^0.1"
},
"devDependencies": {
"@babel/core": "^7.17.8",
"@babel/core": "^7.21.4",
"@babel/plugin-proposal-class-properties": "^7.16.7",
"@babel/plugin-proposal-object-rest-spread": "^7.17.3",
"@babel/plugin-proposal-private-methods": "^7.18.6",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,11 @@ function TrackedMeasurementsContextProvider(
) {
const [viewportGrid, viewportGridService] = useViewportGrid();
const { activeViewportIndex, viewports } = viewportGrid;
const { measurementService, displaySetService } = servicesManager.services;

const machineOptions = Object.assign({}, defaultOptions);
machineOptions.actions = Object.assign({}, machineOptions.actions, {
jumpToFirstMeasurementInActiveViewport: (ctx, evt) => {
const { measurementService } = servicesManager.services;

const { trackedStudy, trackedSeries } = ctx;
const measurements = measurementService.getMeasurements();
const trackedMeasurements = measurements.filter(
Expand All @@ -45,21 +44,51 @@ function TrackedMeasurementsContextProvider(
trackedSeries.includes(m.referenceSeriesUID)
);

const uid = trackedMeasurements[0].uid;

console.log(
'jumping to measurement reset viewport',
viewportGrid.activeViewportIndex,
trackedMeasurements[0]
);

const referencedDisplaySetUID =
trackedMeasurements[0].displaySetInstanceUID;
const referencedDisplaySet = displaySetService.getDisplaySetByUID(
referencedDisplaySetUID
);

const referencedImages = referencedDisplaySet.images;
const isVolumeIdReferenced = referencedImages[0].imageId.startsWith(
'volumeId'
);

const measurementData = trackedMeasurements[0].data;

let imageIndex = 0;
if (!isVolumeIdReferenced && measurementData) {
// if it is imageId referenced find the index of the imageId, we don't have
// support for volumeId referenced images yet
imageIndex = referencedImages.findIndex(image => {
const imageIdToUse = Object.keys(measurementData)[0].substring(8);
return image.imageId === imageIdToUse;
});

if (imageIndex === -1) {
console.warn(
'Could not find image index for tracked measurement, using 0'
);
imageIndex = 0;
}
}

viewportGridService.setDisplaySetsForViewport({
viewportIndex: viewportGrid.activeViewportIndex,
displaySetInstanceUIDs: [trackedMeasurements[0].displaySetInstanceUID],
displaySetInstanceUIDs: [referencedDisplaySetUID],
viewportOptions: {
initialImageOptions: {
index: imageIndex,
},
},
});
measurementService.jumpToMeasurement(
viewportGrid.activeViewportIndex,
uid
);
},
showStructuredReportDisplaySetInActiveViewport: (ctx, evt) => {
if (evt.data.createdDisplaySetInstanceUIDs.length > 0) {
Expand All @@ -73,7 +102,6 @@ function TrackedMeasurementsContextProvider(
}
},
discardPreviouslyTrackedMeasurements: (ctx, evt) => {
const { measurementService } = servicesManager.services;
const measurements = measurementService.getMeasurements();
const filteredMeasurements = measurements.filter(ms =>
ctx.prevTrackedSeries.includes(ms.referenceSeriesUID)
Expand All @@ -85,7 +113,6 @@ function TrackedMeasurementsContextProvider(
}
},
clearAllMeasurements: (ctx, evt) => {
const { measurementService } = servicesManager.services;
const measurements = measurementService.getMeasurements();
const measurementIds = measurements.map(fm => fm.uid);

Expand Down
Loading

0 comments on commit d5c5951

Please sign in to comment.