Skip to content

Commit

Permalink
Fix bug in OHIFCornerstoneViewport and CornerstoneViewportService
Browse files Browse the repository at this point in the history
  • Loading branch information
sedghi committed Apr 24, 2024
1 parent a1a99ec commit 75f4fd2
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,10 @@ function _subscribeToJumpToMeasurementEvents(
cornerstoneViewportService.getViewportIdToJump(
jumpId,
measurement.displaySetInstanceUID,
{ referencedImageId: measurement.referencedImageId }
{
referencedImageId:
measurement.referencedImageId || measurement.metadata?.referencedImageId,
}
);
}
if (cacheJumpToMeasurementEvent.cornerstoneViewport !== viewportId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,11 @@ class CornerstoneViewportService extends PubSubService implements IViewportServi
cameraProps: unknown
): string {
const viewportInfo = this.getViewportInfo(activeViewportId);

if (viewportInfo.getViewportType() === csEnums.ViewportType.VOLUME_3D) {
return null;
}

const { referencedImageId } = cameraProps;
if (viewportInfo?.contains(displaySetInstanceUID, referencedImageId)) {
return activeViewportId;
Expand Down
47 changes: 40 additions & 7 deletions extensions/cornerstone/src/services/ViewportService/Viewport.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { Types, Enums } from '@cornerstonejs/core';
import {
Types,
Enums,
getEnabledElementByViewportId,
VolumeViewport,
utilities,
} from '@cornerstonejs/core';
import { Types as CoreTypes } from '@ohif/core';
import { StackViewportData, VolumeViewportData } from '../../types/CornerstoneCacheService';
import getCornerstoneBlendMode from '../../utils/getCornerstoneBlendMode';
Expand Down Expand Up @@ -89,13 +95,30 @@ const DEFAULT_TOOLGROUP_ID = 'default';

// Return true if the data contains the given display set UID OR the imageId
// if it is a composite object.
const dataContains = (data, displaySetUID: string, imageId?: string): boolean => {
if (data.displaySetInstanceUID === displaySetUID) {
return true;
}
const dataContains = ({ data, displaySetUID, imageId, viewport }): boolean => {
if (imageId && data.isCompositeStack && data.imageIds) {
return !!data.imageIds.find(dataId => dataId === imageId);
}

if (imageId && (data.volumeId || viewport instanceof VolumeViewport)) {
const isAcquisition = !!viewport.getCurrentImageId();

if (!isAcquisition) {
return false;
}

const imageURI = utilities.imageIdToURI(imageId);
const hasImageId = viewport.hasImageURI(imageURI);

if (hasImageId) {
return true;
}
}

if (data.displaySetInstanceUID === displaySetUID) {
return true;
}

return false;
};

Expand All @@ -122,10 +145,20 @@ class ViewportInfo {
return false;
}

const { viewport } = getEnabledElementByViewportId(this.viewportId) || {};

if (this.viewportData.data.length) {
return !!this.viewportData.data.find(data => dataContains(data, displaySetUID, imageId));
return !!this.viewportData.data.find(data =>
dataContains({ data, displaySetUID, imageId, viewport })
);
}
return dataContains(this.viewportData.data, displaySetUID, imageId);

return dataContains({
data: this.viewportData.data,
displaySetUID,
imageId,
viewport,
});
}

public destroy = (): void => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ function getMappedAnnotations(annotation, DisplaySetService) {
unit: modalityUnit,
mean,
stdDev,
metadata,
max,
area,
areaUnit,
Expand Down

0 comments on commit 75f4fd2

Please sign in to comment.