Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 59 additions & 4 deletions packages/core/src/RenderingEngine/WSIViewport.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { vec3, mat4 } from 'gl-matrix';
import { Events as EVENTS, MetadataModules } from '../enums';
import EVENTS from '../enums/Events';
import MetadataModules from '../enums/MetadataModules';
import type {
WSIViewportProperties,
Point3,
Expand All @@ -19,6 +20,8 @@ import triggerEvent from '../utilities/triggerEvent';
import { peerImport } from '../init';
import microscopyViewportCss from '../constants/microscopyViewportCss';
import type { DataSetOptions } from '../types/IViewport';
import eventTarget from '../eventTarget';
import imageIdToURI from '../utilities/imageIdToURI';

let WSIUtilFunctions = null;
const EVENT_POSTRENDER = 'postrender';
Expand Down Expand Up @@ -49,6 +52,7 @@ class WSIViewport extends Viewport {
private microscopyElement: HTMLDivElement;

protected map;
private imageURISet: Set<string> = new Set();

private internalCamera = {
rotation: 0,
Expand All @@ -61,6 +65,42 @@ class WSIViewport extends Viewport {
};

private viewer;
private annotationRemovedListener: EventListener = (evt: Event) => {
const { detail } = evt as CustomEvent<{
annotation?: {
metadata?: {
FrameOfReferenceUID?: string;
referencedImageId?: string;
referencedImageURI?: string;
};
};
}>;

const metadata = detail?.annotation?.metadata;

if (!metadata) {
this.postrender();
return;
}

const referencedImageURI =
metadata.referencedImageURI ??
(metadata.referencedImageId
? imageIdToURI(metadata.referencedImageId)
: null);

if (referencedImageURI && !this.hasImageURI(referencedImageURI)) {
return;
}

const annotationFOR = metadata.FrameOfReferenceUID ?? null;

if (annotationFOR && annotationFOR !== this.frameOfReferenceUID) {
return;
}

this.postrender();
};

/**
* The VOI Range is used to apply contrast/brightness adjustments to the image.
Expand Down Expand Up @@ -130,13 +170,21 @@ class WSIViewport extends Viewport {
EVENTS.ELEMENT_DISABLED,
this.elementDisabledHandler
);
eventTarget.addEventListener(
EVENTS.ANNOTATION_REMOVED,
this.annotationRemovedListener
);
}

private removeEventListeners() {
this.canvas.removeEventListener(
EVENTS.ELEMENT_DISABLED,
this.elementDisabledHandler
);
eventTarget.removeEventListener(
EVENTS.ANNOTATION_REMOVED,
this.annotationRemovedListener
);
}

private elementDisabledHandler() {
Expand All @@ -146,6 +194,7 @@ class WSIViewport extends Viewport {
const cs3dElement = this.element.firstElementChild;
cs3dElement.removeChild(this.microscopyElement);
this.microscopyElement = null;
this.imageURISet.clear();
}

private getImageDataMetadata(imageIndex = 0) {
Expand Down Expand Up @@ -368,9 +417,12 @@ class WSIViewport extends Viewport {
* @param imageURI - containing frame number or range.
* @returns
*/
public hasImageURI(imageURI: string) {
// TODO - implement this
return true;
public hasImageURI(imageURI: string): boolean {
if (!imageURI) {
return false;
}

return this.imageURISet.has(imageURI);
}

public setCamera(camera: ICamera): void {
Expand Down Expand Up @@ -591,6 +643,9 @@ class WSIViewport extends Viewport {
this.microscopyElement.style.background = 'black';
this.microscopyElement.innerText = 'Loading';
this.imageIds = imageIds;
this.imageURISet = new Set(
imageIds.map((imageId) => imageIdToURI(imageId))
);
const DicomMicroscopyViewer = await WSIViewport.getDicomMicroscopyViewer();
WSIUtilFunctions ||= DicomMicroscopyViewer.utils;
this.frameOfReferenceUID = null;
Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/enums/Events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ enum Events {
* and see what event detail is included in {@link EventTypes.ImageRenderedEventDetail | ImageRendered Event Detail }
*/
IMAGE_RENDERED = 'CORNERSTONE_IMAGE_RENDERED',
/**
* Triggers when a tools annotation has been removed.
*/
ANNOTATION_REMOVED = 'CORNERSTONE_TOOLS_ANNOTATION_REMOVED',
/**
* Triggers on the eventTarget when the image volume data is modified. This happens
* in the streamingImageLoader when each frame is loaded and inserted into a volume.
Expand Down
Loading