Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | 128x | import { Events as EVENTS, ViewportType } from '../../../enums';
import triggerEvent from '../../../utilities/triggerEvent';
import { getDicomMicroscopyViewer } from '../../../utilities/WSIUtilities';
import type {
DataAddOptions,
LoadedData,
RenderPathAttachment,
RenderPathDefinition,
RenderPath,
} from '../ViewportArchitectureTypes';
import type {
WSIDataPresentation,
WSIRendering,
WSIPayload,
WSIViewState,
WSIViewportRenderContext,
} from './WSIViewportTypes';
const EVENT_POSTRENDER = 'postrender';
/** @internal */
export class DicomMicroscopyRenderPath
implements RenderPath<WSIViewportRenderContext>
{
async addData(
ctx: WSIViewportRenderContext,
data: LoadedData,
options: DataAddOptions
): Promise<RenderPathAttachment<WSIDataPresentation>> {
const payload: WSIPayload = data as unknown as LoadedData<WSIPayload>;
const DicomMicroscopyViewer = await getDicomMicroscopyViewer();
const microscopyElement = document.createElement('div');
microscopyElement.setAttribute('class', 'DicomMicroscopyViewer');
microscopyElement.style.background = 'black';
microscopyElement.style.width = '100%';
microscopyElement.style.height = '100%';
microscopyElement.style.position = 'absolute';
microscopyElement.style.left = '0';
microscopyElement.style.top = '0';
ctx.element.appendChild(microscopyElement);
const viewer = new DicomMicroscopyViewer.viewer.VolumeImageViewer({
client: payload.client,
metadata: payload.volumeImages,
controls: ['overview', 'position'],
retrieveRendered: false,
bindings: {},
});
viewer.render({ container: microscopyElement });
viewer.deactivateDragPanInteraction();
const map = viewer.getMap();
const postrenderHandler = () => {
triggerEvent(ctx.element, EVENTS.IMAGE_RENDERED, {
element: ctx.element,
viewportId: ctx.viewportId,
renderingEngineId: ctx.renderingEngineId,
rendering: {
dataId: data.id,
renderMode: 'wsi2d',
},
});
};
map.on(EVENT_POSTRENDER, postrenderHandler);
Object.assign(microscopyElement.style, {
'--ol-partial-background-color': 'rgba(127, 127, 127, 0.7)',
'--ol-foreground-color': '#000000',
'--ol-subtle-foreground-color': '#000',
'--ol-subtle-background-color': 'rgba(78, 78, 78, 0.5)',
background: 'none',
});
const rendering: WSIRendering = {
renderMode: 'wsi2d',
microscopyElement,
viewer,
map,
transformUtils: DicomMicroscopyViewer.utils,
postrenderHandler,
};
return {
rendering,
updateDataPresentation: (props) => {
this.updateDataPresentation(rendering, props);
},
applyViewState: (camera) => {
this.applyViewState(rendering, camera);
},
getFrameOfReferenceUID: () => {
return this.getFrameOfReferenceUID(payload);
},
render: () => {
map.render?.();
},
resize: () => {
map.updateSize?.();
map.render?.();
},
removeData: () => {
this.removeData(rendering);
},
};
}
private updateDataPresentation(
rendering: WSIRendering,
props: unknown
): void {
const wsiProps = props as WSIDataPresentation | undefined;
const { microscopyElement } = rendering;
microscopyElement.style.display = wsiProps?.visible === false ? 'none' : '';
microscopyElement.style.opacity = String(wsiProps?.opacity ?? 1);
}
private applyViewState(rendering: WSIRendering, camera: unknown): void {
const wsiCamera = camera as WSIViewState;
const { map } = rendering;
const view = map?.getView?.();
if (!view) {
return;
}
if (typeof wsiCamera.resolution === 'number') {
view.setResolution?.(wsiCamera.resolution);
}
if (typeof wsiCamera.zoom === 'number') {
view.setZoom(wsiCamera.zoom);
}
if (wsiCamera.centerIndex) {
view.setCenter(wsiCamera.centerIndex);
}
if (typeof wsiCamera.rotation === 'number') {
view.setRotation(wsiCamera.rotation);
}
}
private getFrameOfReferenceUID(payload: WSIPayload): string | undefined {
return payload.frameOfReferenceUID ?? undefined;
}
private removeData(rendering: WSIRendering): void {
const { map, microscopyElement, viewer, postrenderHandler } = rendering;
map?.un?.(EVENT_POSTRENDER, postrenderHandler);
viewer?.cleanup?.();
microscopyElement.remove();
}
}
/** @internal */
export class DicomMicroscopyPath
implements RenderPathDefinition<WSIViewportRenderContext>
{
readonly id = 'wsi:dicom-microscopy-viewer';
readonly type = ViewportType.WHOLE_SLIDE_NEXT;
matches(data: LoadedData, options: DataAddOptions): boolean {
return data.type === 'wsi' && options.renderMode === 'wsi2d';
}
createRenderPath() {
return new DicomMicroscopyRenderPath();
}
}
|