@cornerstonejs/core 1.77.12 → 1.78.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/RenderingEngine/RenderingEngine.d.ts +0 -2
- package/dist/cjs/RenderingEngine/RenderingEngine.js +0 -9
- package/dist/cjs/RenderingEngine/RenderingEngine.js.map +1 -1
- package/dist/cjs/RenderingEngine/StackViewport.js +2 -2
- package/dist/cjs/RenderingEngine/VideoViewport.d.ts +2 -1
- package/dist/cjs/RenderingEngine/VideoViewport.js +15 -6
- package/dist/cjs/RenderingEngine/VideoViewport.js.map +1 -1
- package/dist/cjs/RenderingEngine/Viewport.d.ts +2 -1
- package/dist/cjs/RenderingEngine/Viewport.js +3 -0
- package/dist/cjs/RenderingEngine/Viewport.js.map +1 -1
- package/dist/cjs/RenderingEngine/WSIViewport.d.ts +82 -0
- package/dist/cjs/RenderingEngine/WSIViewport.js +447 -0
- package/dist/cjs/RenderingEngine/WSIViewport.js.map +1 -0
- package/dist/cjs/RenderingEngine/helpers/viewportTypeToViewportClass.d.ts +2 -0
- package/dist/cjs/RenderingEngine/helpers/viewportTypeToViewportClass.js +2 -0
- package/dist/cjs/RenderingEngine/helpers/viewportTypeToViewportClass.js.map +1 -1
- package/dist/cjs/enums/MetadataModules.d.ts +2 -1
- package/dist/cjs/enums/MetadataModules.js +1 -0
- package/dist/cjs/enums/MetadataModules.js.map +1 -1
- package/dist/cjs/enums/ViewportType.d.ts +2 -1
- package/dist/cjs/enums/ViewportType.js +1 -0
- package/dist/cjs/enums/ViewportType.js.map +1 -1
- package/dist/cjs/index.d.ts +2 -1
- package/dist/cjs/index.js +4 -2
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/IRenderingEngine.d.ts +0 -2
- package/dist/cjs/types/IViewport.d.ts +7 -0
- package/dist/cjs/types/IWSIViewport.d.ts +13 -0
- package/dist/cjs/types/IWSIViewport.js +3 -0
- package/dist/cjs/types/IWSIViewport.js.map +1 -0
- package/dist/cjs/types/WSIViewportProperties.d.ts +3 -0
- package/dist/cjs/types/WSIViewportProperties.js +3 -0
- package/dist/cjs/types/WSIViewportProperties.js.map +1 -0
- package/dist/cjs/types/WSIViewportTypes.d.ts +13 -0
- package/dist/cjs/types/WSIViewportTypes.js +3 -0
- package/dist/cjs/types/WSIViewportTypes.js.map +1 -0
- package/dist/cjs/types/index.d.ts +5 -2
- package/dist/cjs/utilities/genericMetadataProvider.js +3 -1
- package/dist/cjs/utilities/genericMetadataProvider.js.map +1 -1
- package/dist/cjs/utilities/uuidv4.js +1 -1
- package/dist/cjs/utilities/uuidv4.js.map +1 -1
- package/dist/esm/RenderingEngine/RenderingEngine.js +0 -9
- package/dist/esm/RenderingEngine/RenderingEngine.js.map +1 -1
- package/dist/esm/RenderingEngine/StackViewport.js +2 -2
- package/dist/esm/RenderingEngine/VideoViewport.js +14 -6
- package/dist/esm/RenderingEngine/VideoViewport.js.map +1 -1
- package/dist/esm/RenderingEngine/Viewport.js +3 -0
- package/dist/esm/RenderingEngine/Viewport.js.map +1 -1
- package/dist/esm/RenderingEngine/WSIViewport.js +405 -0
- package/dist/esm/RenderingEngine/WSIViewport.js.map +1 -0
- package/dist/esm/RenderingEngine/helpers/viewportTypeToViewportClass.js +2 -0
- package/dist/esm/RenderingEngine/helpers/viewportTypeToViewportClass.js.map +1 -1
- package/dist/esm/enums/MetadataModules.js +1 -0
- package/dist/esm/enums/MetadataModules.js.map +1 -1
- package/dist/esm/enums/ViewportType.js +1 -0
- package/dist/esm/enums/ViewportType.js.map +1 -1
- package/dist/esm/index.js +2 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/IWSIViewport.js +2 -0
- package/dist/esm/types/IWSIViewport.js.map +1 -0
- package/dist/esm/types/WSIViewportProperties.js +2 -0
- package/dist/esm/types/WSIViewportProperties.js.map +1 -0
- package/dist/esm/types/WSIViewportTypes.js +2 -0
- package/dist/esm/types/WSIViewportTypes.js.map +1 -0
- package/dist/esm/utilities/genericMetadataProvider.js +2 -1
- package/dist/esm/utilities/genericMetadataProvider.js.map +1 -1
- package/dist/esm/utilities/uuidv4.js +1 -1
- package/dist/esm/utilities/uuidv4.js.map +1 -1
- package/dist/types/RenderingEngine/RenderingEngine.d.ts +0 -2
- package/dist/types/RenderingEngine/RenderingEngine.d.ts.map +1 -1
- package/dist/types/RenderingEngine/VideoViewport.d.ts +2 -1
- package/dist/types/RenderingEngine/VideoViewport.d.ts.map +1 -1
- package/dist/types/RenderingEngine/Viewport.d.ts +2 -1
- package/dist/types/RenderingEngine/Viewport.d.ts.map +1 -1
- package/dist/types/RenderingEngine/WSIViewport.d.ts +83 -0
- package/dist/types/RenderingEngine/WSIViewport.d.ts.map +1 -0
- package/dist/types/RenderingEngine/helpers/viewportTypeToViewportClass.d.ts +2 -0
- package/dist/types/RenderingEngine/helpers/viewportTypeToViewportClass.d.ts.map +1 -1
- package/dist/types/enums/MetadataModules.d.ts +2 -1
- package/dist/types/enums/MetadataModules.d.ts.map +1 -1
- package/dist/types/enums/ViewportType.d.ts +2 -1
- package/dist/types/enums/ViewportType.d.ts.map +1 -1
- package/dist/types/index.d.ts +2 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/types/IRenderingEngine.d.ts +0 -2
- package/dist/types/types/IRenderingEngine.d.ts.map +1 -1
- package/dist/types/types/IViewport.d.ts +7 -0
- package/dist/types/types/IViewport.d.ts.map +1 -1
- package/dist/types/types/IWSIViewport.d.ts +14 -0
- package/dist/types/types/IWSIViewport.d.ts.map +1 -0
- package/dist/types/types/WSIViewportProperties.d.ts +4 -0
- package/dist/types/types/WSIViewportProperties.d.ts.map +1 -0
- package/dist/types/types/WSIViewportTypes.d.ts +14 -0
- package/dist/types/types/WSIViewportTypes.d.ts.map +1 -0
- package/dist/types/types/index.d.ts +5 -2
- package/dist/types/types/index.d.ts.map +1 -1
- package/dist/types/utilities/genericMetadataProvider.d.ts.map +1 -1
- package/dist/types/utilities/uuidv4.d.ts.map +1 -1
- package/dist/umd/index.js +1 -1
- package/dist/umd/index.js.map +1 -1
- package/package.json +2 -2
- package/src/RenderingEngine/RenderingEngine.ts +0 -20
- package/src/RenderingEngine/StackViewport.ts +2 -2
- package/src/RenderingEngine/VideoViewport.ts +38 -10
- package/src/RenderingEngine/Viewport.ts +8 -0
- package/src/RenderingEngine/WSIViewport.ts +661 -0
- package/src/RenderingEngine/helpers/viewportTypeToViewportClass.ts +2 -0
- package/src/enums/MetadataModules.ts +5 -0
- package/src/enums/ViewportType.ts +4 -0
- package/src/index.ts +2 -0
- package/src/types/IRenderingEngine.ts +0 -2
- package/src/types/IViewport.ts +20 -0
- package/src/types/IWSIViewport.ts +59 -0
- package/src/types/WSIViewportProperties.ts +8 -0
- package/src/types/WSIViewportTypes.ts +14 -0
- package/src/types/index.ts +8 -0
- package/src/utilities/genericMetadataProvider.ts +3 -2
- package/src/utilities/uuidv4.ts +1 -5
|
@@ -0,0 +1,661 @@
|
|
|
1
|
+
import { vec3 } from 'gl-matrix';
|
|
2
|
+
import { Events as EVENTS, MetadataModules } from '../enums';
|
|
3
|
+
import {
|
|
4
|
+
IWSIViewport,
|
|
5
|
+
WSIViewportProperties,
|
|
6
|
+
Point3,
|
|
7
|
+
Point2,
|
|
8
|
+
ICamera,
|
|
9
|
+
WSIViewportInput,
|
|
10
|
+
VOIRange,
|
|
11
|
+
} from '../types';
|
|
12
|
+
import * as metaData from '../metaData';
|
|
13
|
+
import { Transform } from './helpers/cpuFallback/rendering/transform';
|
|
14
|
+
import Viewport from './Viewport';
|
|
15
|
+
import { getOrCreateCanvas } from './helpers';
|
|
16
|
+
import { EPSILON } from '../constants';
|
|
17
|
+
import { triggerEvent } from '../utilities';
|
|
18
|
+
|
|
19
|
+
const _map = Symbol.for('map');
|
|
20
|
+
const EVENT_POSTRENDER = 'postrender';
|
|
21
|
+
/**
|
|
22
|
+
* An object representing a single stack viewport, which is a camera
|
|
23
|
+
* looking into an internal scene, and an associated target output `canvas`.
|
|
24
|
+
*/
|
|
25
|
+
class WSIViewport extends Viewport implements IWSIViewport {
|
|
26
|
+
public modality;
|
|
27
|
+
// Viewport Data
|
|
28
|
+
protected imageIds: string[];
|
|
29
|
+
readonly uid;
|
|
30
|
+
readonly renderingEngineId: string;
|
|
31
|
+
|
|
32
|
+
private frameOfReferenceUID: string;
|
|
33
|
+
|
|
34
|
+
// First is some specific metadata on the current image
|
|
35
|
+
protected metadata;
|
|
36
|
+
// Then the metadata array containing the dicomweb metadata definitions
|
|
37
|
+
protected metadataDicomweb;
|
|
38
|
+
|
|
39
|
+
private microscopyElement: HTMLDivElement;
|
|
40
|
+
|
|
41
|
+
protected map;
|
|
42
|
+
|
|
43
|
+
private internalCamera = {
|
|
44
|
+
rotation: 0,
|
|
45
|
+
centerIndex: [0, 0],
|
|
46
|
+
extent: [0, -2, 1, -1],
|
|
47
|
+
xSpacing: 1,
|
|
48
|
+
ySpacing: 1,
|
|
49
|
+
resolution: 1,
|
|
50
|
+
zoom: 1,
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
private viewer;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* The VOI Range is used to apply contrast/brightness adjustments to the image.
|
|
57
|
+
*/
|
|
58
|
+
private voiRange: VOIRange = {
|
|
59
|
+
lower: 0,
|
|
60
|
+
upper: 255,
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
constructor(props: WSIViewportInput) {
|
|
64
|
+
super({
|
|
65
|
+
...props,
|
|
66
|
+
canvas: props.canvas || getOrCreateCanvas(props.element),
|
|
67
|
+
});
|
|
68
|
+
this.renderingEngineId = props.renderingEngineId;
|
|
69
|
+
|
|
70
|
+
this.element.setAttribute('data-viewport-uid', this.id);
|
|
71
|
+
this.element.setAttribute(
|
|
72
|
+
'data-rendering-engine-uid',
|
|
73
|
+
this.renderingEngineId
|
|
74
|
+
);
|
|
75
|
+
// Need to set the top level position as relative to make nested items
|
|
76
|
+
// use absolute positioning internally.
|
|
77
|
+
this.element.style.position = 'relative';
|
|
78
|
+
this.microscopyElement = document.createElement('div');
|
|
79
|
+
this.microscopyElement.id = crypto.randomUUID();
|
|
80
|
+
this.microscopyElement.innerText = 'Initial';
|
|
81
|
+
this.microscopyElement.style.background = 'grey';
|
|
82
|
+
this.microscopyElement.style.width = '100%';
|
|
83
|
+
this.microscopyElement.style.height = '100%';
|
|
84
|
+
this.microscopyElement.style.position = 'absolute';
|
|
85
|
+
this.microscopyElement.style.left = '0';
|
|
86
|
+
this.microscopyElement.style.top = '0';
|
|
87
|
+
const cs3dElement = this.element.firstElementChild;
|
|
88
|
+
cs3dElement.insertBefore(this.microscopyElement, cs3dElement.childNodes[1]);
|
|
89
|
+
|
|
90
|
+
this.addEventListeners();
|
|
91
|
+
this.resize();
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
public static get useCustomRenderingPipeline() {
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
private addEventListeners() {
|
|
99
|
+
this.canvas.addEventListener(
|
|
100
|
+
EVENTS.ELEMENT_DISABLED,
|
|
101
|
+
this.elementDisabledHandler
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
private removeEventListeners() {
|
|
106
|
+
this.canvas.removeEventListener(
|
|
107
|
+
EVENTS.ELEMENT_DISABLED,
|
|
108
|
+
this.elementDisabledHandler
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
private elementDisabledHandler() {
|
|
113
|
+
this.removeEventListeners();
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
private getImageDataMetadata(imageIndex = 0) {
|
|
117
|
+
const maxImage = this.metadataDicomweb.reduce((maxImage, image) => {
|
|
118
|
+
return maxImage?.NumberOfFrames < image.NumberOfFrames ? image : maxImage;
|
|
119
|
+
});
|
|
120
|
+
const {
|
|
121
|
+
TotalPixelMatrixColumns: columns,
|
|
122
|
+
TotalPixelMatrixRows: rows,
|
|
123
|
+
ImageOrientationSlide,
|
|
124
|
+
ImagedVolumeWidth: width,
|
|
125
|
+
ImagedVolumeHeight: height,
|
|
126
|
+
ImagedVolumeDepth: depth,
|
|
127
|
+
} = maxImage;
|
|
128
|
+
|
|
129
|
+
const imagePlaneModule = metaData.get(
|
|
130
|
+
MetadataModules.IMAGE_PLANE,
|
|
131
|
+
this.imageIds[imageIndex]
|
|
132
|
+
);
|
|
133
|
+
|
|
134
|
+
let rowCosines = ImageOrientationSlide.slice(0, 3);
|
|
135
|
+
let columnCosines = ImageOrientationSlide.slice(3, 6);
|
|
136
|
+
|
|
137
|
+
// if null or undefined
|
|
138
|
+
if (rowCosines == null || columnCosines == null) {
|
|
139
|
+
rowCosines = <Point3>[1, 0, 0];
|
|
140
|
+
columnCosines = <Point3>[0, 1, 0];
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const rowCosineVec = vec3.fromValues(
|
|
144
|
+
rowCosines[0],
|
|
145
|
+
rowCosines[1],
|
|
146
|
+
rowCosines[2]
|
|
147
|
+
);
|
|
148
|
+
const colCosineVec = vec3.fromValues(
|
|
149
|
+
columnCosines[0],
|
|
150
|
+
columnCosines[1],
|
|
151
|
+
columnCosines[2]
|
|
152
|
+
);
|
|
153
|
+
const scanAxisNormal = vec3.create();
|
|
154
|
+
vec3.cross(scanAxisNormal, rowCosineVec, colCosineVec);
|
|
155
|
+
|
|
156
|
+
const {
|
|
157
|
+
XOffsetInSlideCoordinateSystem = 0,
|
|
158
|
+
YOffsetInSlideCoordinateSystem = 0,
|
|
159
|
+
ZOffsetInSlideCoordinateSystem = 0,
|
|
160
|
+
} = maxImage.TotalPixelMatrixOriginSequence?.[0] || {};
|
|
161
|
+
const origin = [
|
|
162
|
+
XOffsetInSlideCoordinateSystem,
|
|
163
|
+
YOffsetInSlideCoordinateSystem,
|
|
164
|
+
ZOffsetInSlideCoordinateSystem,
|
|
165
|
+
];
|
|
166
|
+
|
|
167
|
+
const xSpacing = width / columns;
|
|
168
|
+
const ySpacing = height / rows;
|
|
169
|
+
const xVoxels = columns;
|
|
170
|
+
const yVoxels = rows;
|
|
171
|
+
|
|
172
|
+
const zSpacing = depth;
|
|
173
|
+
const zVoxels = 1;
|
|
174
|
+
|
|
175
|
+
this.hasPixelSpacing = !!(width && height);
|
|
176
|
+
return {
|
|
177
|
+
bitsAllocated: 8,
|
|
178
|
+
numComps: 3,
|
|
179
|
+
origin,
|
|
180
|
+
direction: [...rowCosineVec, ...colCosineVec, ...scanAxisNormal],
|
|
181
|
+
dimensions: [xVoxels, yVoxels, zVoxels],
|
|
182
|
+
spacing: [xSpacing, ySpacing, zSpacing],
|
|
183
|
+
hasPixelSpacing: this.hasPixelSpacing,
|
|
184
|
+
numVoxels: xVoxels * yVoxels * zVoxels,
|
|
185
|
+
imagePlaneModule,
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// Sets the frame number - note according to DICOM, this is 1 based
|
|
190
|
+
public async setFrameNumber(frame: number) {
|
|
191
|
+
// No-op right now, not sure what this will be
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
public setProperties(props: WSIViewportProperties) {
|
|
195
|
+
// No-op - todo implement this
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
public getProperties = (): WSIViewportProperties => {
|
|
199
|
+
return {};
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
public resetProperties() {
|
|
203
|
+
this.setProperties({});
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
protected getScalarData() {
|
|
207
|
+
return null;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
public getImageData() {
|
|
211
|
+
const { metadata } = this;
|
|
212
|
+
|
|
213
|
+
const spacing = metadata.spacing;
|
|
214
|
+
|
|
215
|
+
return {
|
|
216
|
+
dimensions: metadata.dimensions,
|
|
217
|
+
spacing,
|
|
218
|
+
numComps: 3,
|
|
219
|
+
origin: metadata.origin,
|
|
220
|
+
direction: metadata.direction,
|
|
221
|
+
metadata: { Modality: this.modality },
|
|
222
|
+
getScalarData: () => this.getScalarData(),
|
|
223
|
+
imageData: {
|
|
224
|
+
getDirection: () => metadata.direction,
|
|
225
|
+
getDimensions: () => metadata.dimensions,
|
|
226
|
+
getRange: () => [0, 255],
|
|
227
|
+
getScalarData: () => this.getScalarData(),
|
|
228
|
+
getSpacing: () => metadata.spacing,
|
|
229
|
+
worldToIndex: (point: Point3) => {
|
|
230
|
+
const canvasPoint = this.worldToCanvas(point);
|
|
231
|
+
const pixelCoord = this.canvasToIndex(canvasPoint);
|
|
232
|
+
return [pixelCoord[0], pixelCoord[1], 0];
|
|
233
|
+
},
|
|
234
|
+
indexToWorld: (point: Point3) => {
|
|
235
|
+
const canvasPoint = this.indexToCanvas([point[0], point[1]]);
|
|
236
|
+
return this.canvasToWorld(canvasPoint);
|
|
237
|
+
},
|
|
238
|
+
},
|
|
239
|
+
hasPixelSpacing: this.hasPixelSpacing,
|
|
240
|
+
calibration: this.calibration,
|
|
241
|
+
preScale: {
|
|
242
|
+
scaled: false,
|
|
243
|
+
},
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Checks to see if the imageURI is currently being displayed. The imageURI
|
|
249
|
+
* may contain frame numbers according to the DICOM standard format, which
|
|
250
|
+
* will be stripped to compare the base image URI, and then the values used
|
|
251
|
+
* to check if that frame is currently being displayed.
|
|
252
|
+
*
|
|
253
|
+
* The DICOM standard allows for comma separated values as well, however,
|
|
254
|
+
* this is not supported here, with only a single range or single value
|
|
255
|
+
* being tested.
|
|
256
|
+
*
|
|
257
|
+
* For a single value, the time range +/- 5 frames is permitted to allow
|
|
258
|
+
* the detection to actually succeed when nearby without requiring an exact
|
|
259
|
+
* time frame to be matched.
|
|
260
|
+
*
|
|
261
|
+
* @param imageURI - containing frame number or range.
|
|
262
|
+
* @returns
|
|
263
|
+
*/
|
|
264
|
+
public hasImageURI(imageURI: string) {
|
|
265
|
+
// TODO - implement this
|
|
266
|
+
return true;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
public setCamera(camera: ICamera): void {
|
|
270
|
+
const previousCamera = this.getCamera();
|
|
271
|
+
const { parallelScale, focalPoint } = camera;
|
|
272
|
+
const view = this.getView();
|
|
273
|
+
const { xSpacing } = this.internalCamera;
|
|
274
|
+
|
|
275
|
+
if (parallelScale) {
|
|
276
|
+
const worldToCanvasRatio = this.element.clientHeight / parallelScale;
|
|
277
|
+
const resolution = 1 / xSpacing / worldToCanvasRatio;
|
|
278
|
+
|
|
279
|
+
view.setResolution(resolution);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
if (focalPoint) {
|
|
283
|
+
const newCanvas = this.worldToCanvas(focalPoint);
|
|
284
|
+
const newIndex = this.canvasToIndex(newCanvas);
|
|
285
|
+
view.setCenter(newIndex);
|
|
286
|
+
}
|
|
287
|
+
const updatedCamera = this.getCamera();
|
|
288
|
+
this.triggerCameraModifiedEventIfNecessary(previousCamera, updatedCamera);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* This function returns the imageID associated with either the current
|
|
293
|
+
* frame being displayed, or the range of frames being played. This may not
|
|
294
|
+
* correspond to any particular imageId that has imageId metadata, as the
|
|
295
|
+
* format is one of:
|
|
296
|
+
* `<DICOMweb URI>/frames/<Start Frame>(-<End Frame>)?`
|
|
297
|
+
* or
|
|
298
|
+
* `<Other URI>[?&]frameNumber=<Start Frame>(-<EndFrame>)?`
|
|
299
|
+
* for a URL parameter.
|
|
300
|
+
*
|
|
301
|
+
* @returns an imageID for video
|
|
302
|
+
*/
|
|
303
|
+
public getCurrentImageId() {
|
|
304
|
+
return this.imageIds[0];
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
public getFrameNumber() {
|
|
308
|
+
return 1;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
public getCamera(): ICamera {
|
|
312
|
+
this.refreshRenderValues();
|
|
313
|
+
const { resolution, xSpacing } = this.internalCamera;
|
|
314
|
+
const canvasToWorldRatio = resolution * xSpacing;
|
|
315
|
+
|
|
316
|
+
const canvasCenter: Point2 = [
|
|
317
|
+
this.element.clientWidth / 2,
|
|
318
|
+
this.element.clientHeight / 2,
|
|
319
|
+
];
|
|
320
|
+
const focalPoint = this.canvasToWorld(canvasCenter);
|
|
321
|
+
|
|
322
|
+
return {
|
|
323
|
+
parallelProjection: true,
|
|
324
|
+
focalPoint,
|
|
325
|
+
position: focalPoint,
|
|
326
|
+
viewUp: [0, -1, 0],
|
|
327
|
+
parallelScale: this.element.clientHeight * canvasToWorldRatio, // Reverse zoom direction back
|
|
328
|
+
viewPlaneNormal: [0, 0, 1],
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
public resetCamera = (): boolean => {
|
|
333
|
+
return true;
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* Gets the number of slices - this will be the number of focal planes,
|
|
338
|
+
* and not hte actual number of slices in the image sets.
|
|
339
|
+
*/
|
|
340
|
+
public getNumberOfSlices = (): number => {
|
|
341
|
+
return 1;
|
|
342
|
+
};
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* Need to return this as a function to prevent webpack from munging it.
|
|
346
|
+
*/
|
|
347
|
+
private getImportPath() {
|
|
348
|
+
return '/dicom-microscopy-viewer/dicomMicroscopyViewer.min.js';
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
* The FOR for whole slide imaging is the frame of reference in the DICOM
|
|
353
|
+
* metadata, and should be the same for all slices being viewed.
|
|
354
|
+
*/
|
|
355
|
+
public getFrameOfReferenceUID = (): string => {
|
|
356
|
+
return this.frameOfReferenceUID;
|
|
357
|
+
};
|
|
358
|
+
|
|
359
|
+
public resize = (): void => {
|
|
360
|
+
const canvas = this.canvas;
|
|
361
|
+
const { clientWidth, clientHeight } = canvas;
|
|
362
|
+
|
|
363
|
+
// Set the canvas to be same resolution as the client.
|
|
364
|
+
if (canvas.width !== clientWidth || canvas.height !== clientHeight) {
|
|
365
|
+
canvas.width = clientWidth;
|
|
366
|
+
canvas.height = clientHeight;
|
|
367
|
+
}
|
|
368
|
+
this.refreshRenderValues();
|
|
369
|
+
};
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* Converts a VideoViewport canvas coordinate to a video coordinate.
|
|
373
|
+
*
|
|
374
|
+
* @param canvasPosition - to convert to world
|
|
375
|
+
* @returns World position
|
|
376
|
+
*/
|
|
377
|
+
public canvasToWorld = (canvasPos: Point2): Point3 => {
|
|
378
|
+
if (!this.metadata) {
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
381
|
+
// compute the pixel coordinate in the image
|
|
382
|
+
const [px, py] = this.canvasToIndex(canvasPos);
|
|
383
|
+
// convert pixel coordinate to world coordinate
|
|
384
|
+
const { origin, spacing, direction } = this.getImageData();
|
|
385
|
+
|
|
386
|
+
const worldPos = vec3.fromValues(0, 0, 0);
|
|
387
|
+
|
|
388
|
+
// Calculate size of spacing vector in normal direction
|
|
389
|
+
const iVector = direction.slice(0, 3) as Point3;
|
|
390
|
+
const jVector = direction.slice(3, 6) as Point3;
|
|
391
|
+
|
|
392
|
+
// Calculate the world coordinate of the pixel
|
|
393
|
+
vec3.scaleAndAdd(worldPos, origin, iVector, px * spacing[0]);
|
|
394
|
+
vec3.scaleAndAdd(worldPos, worldPos, jVector, py * spacing[1]);
|
|
395
|
+
|
|
396
|
+
return [worldPos[0], worldPos[1], worldPos[2]] as Point3;
|
|
397
|
+
};
|
|
398
|
+
|
|
399
|
+
/**
|
|
400
|
+
* Converts and [x,y] video coordinate to a Cornerstone3D VideoViewport.
|
|
401
|
+
*
|
|
402
|
+
* @param worldPos - world coord to convert to canvas
|
|
403
|
+
* @returns Canvas position
|
|
404
|
+
*/
|
|
405
|
+
public worldToCanvas = (worldPos: Point3): Point2 => {
|
|
406
|
+
if (!this.metadata) {
|
|
407
|
+
return;
|
|
408
|
+
}
|
|
409
|
+
const { spacing, direction, origin } = this.metadata;
|
|
410
|
+
|
|
411
|
+
const iVector = direction.slice(0, 3) as Point3;
|
|
412
|
+
const jVector = direction.slice(3, 6) as Point3;
|
|
413
|
+
|
|
414
|
+
const diff = vec3.subtract([0, 0, 0], worldPos, origin);
|
|
415
|
+
|
|
416
|
+
const indexPoint: Point2 = [
|
|
417
|
+
vec3.dot(diff, iVector) / spacing[0],
|
|
418
|
+
vec3.dot(diff, jVector) / spacing[1],
|
|
419
|
+
];
|
|
420
|
+
|
|
421
|
+
// pixel to canvas
|
|
422
|
+
const canvasPoint = this.indexToCanvas(indexPoint);
|
|
423
|
+
return canvasPoint;
|
|
424
|
+
};
|
|
425
|
+
|
|
426
|
+
/**
|
|
427
|
+
* This is a wrapper for setWSI to allow generic behaviour
|
|
428
|
+
*/
|
|
429
|
+
public setDataIds(imageIds: string[]) {
|
|
430
|
+
const webClient = metaData.get(MetadataModules.WEB_CLIENT, imageIds[0]);
|
|
431
|
+
if (!webClient) {
|
|
432
|
+
throw new Error(
|
|
433
|
+
`To use setDataIds on WSI data, you must provide metaData.webClient for ${imageIds[0]}`
|
|
434
|
+
);
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
this.setWSI(imageIds, webClient);
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
public async setWSI(imageIds: string[], client) {
|
|
441
|
+
this.microscopyElement.style.background = 'red';
|
|
442
|
+
this.microscopyElement.innerText = 'Loading';
|
|
443
|
+
this.imageIds = imageIds;
|
|
444
|
+
// Import the straight module so that webpack doesn't touch it.
|
|
445
|
+
await import(/* webpackIgnore: true */ this.getImportPath());
|
|
446
|
+
const DicomMicroscopyViewer = (window as any).dicomMicroscopyViewer;
|
|
447
|
+
this.frameOfReferenceUID = null;
|
|
448
|
+
|
|
449
|
+
const metadataDicomweb = this.imageIds.map((imageId) => {
|
|
450
|
+
const imageMetadata = client.getDICOMwebMetadata(imageId);
|
|
451
|
+
|
|
452
|
+
Object.defineProperty(imageMetadata, 'isMultiframe', {
|
|
453
|
+
value: imageMetadata.isMultiframe,
|
|
454
|
+
enumerable: false,
|
|
455
|
+
});
|
|
456
|
+
Object.defineProperty(imageMetadata, 'frameNumber', {
|
|
457
|
+
value: undefined,
|
|
458
|
+
enumerable: false,
|
|
459
|
+
});
|
|
460
|
+
const imageType = imageMetadata['00080008']?.Value;
|
|
461
|
+
if (imageType?.length === 1) {
|
|
462
|
+
imageMetadata['00080008'].Value = imageType[0].split('\\');
|
|
463
|
+
}
|
|
464
|
+
const frameOfReference = imageMetadata['00200052']?.Value?.[0];
|
|
465
|
+
if (!this.frameOfReferenceUID) {
|
|
466
|
+
this.frameOfReferenceUID = frameOfReference;
|
|
467
|
+
} else if (frameOfReference !== this.frameOfReferenceUID) {
|
|
468
|
+
imageMetadata['00200052'].Value = [this.frameOfReferenceUID];
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
return imageMetadata;
|
|
472
|
+
});
|
|
473
|
+
const volumeImages = [];
|
|
474
|
+
metadataDicomweb.forEach((m) => {
|
|
475
|
+
const image =
|
|
476
|
+
new DicomMicroscopyViewer.metadata.VLWholeSlideMicroscopyImage({
|
|
477
|
+
metadata: m,
|
|
478
|
+
});
|
|
479
|
+
const imageFlavor = image.ImageType[2];
|
|
480
|
+
if (imageFlavor === 'VOLUME' || imageFlavor === 'THUMBNAIL') {
|
|
481
|
+
volumeImages.push(image);
|
|
482
|
+
}
|
|
483
|
+
});
|
|
484
|
+
this.metadataDicomweb = volumeImages;
|
|
485
|
+
|
|
486
|
+
// Construct viewer instance
|
|
487
|
+
const viewer = new DicomMicroscopyViewer.viewer.VolumeImageViewer({
|
|
488
|
+
client,
|
|
489
|
+
metadata: volumeImages,
|
|
490
|
+
controls: [],
|
|
491
|
+
bindings: {},
|
|
492
|
+
});
|
|
493
|
+
|
|
494
|
+
// Render viewer instance in the "viewport" HTML element
|
|
495
|
+
viewer.render({ container: this.microscopyElement });
|
|
496
|
+
|
|
497
|
+
this.metadata = this.getImageDataMetadata();
|
|
498
|
+
|
|
499
|
+
viewer.deactivateDragPanInteraction();
|
|
500
|
+
this.viewer = viewer;
|
|
501
|
+
this.map = viewer[_map];
|
|
502
|
+
this.map.on(EVENT_POSTRENDER, this.postrender);
|
|
503
|
+
this.resize();
|
|
504
|
+
this.microscopyElement.innerText = '';
|
|
505
|
+
Object.assign(this.microscopyElement.style, {
|
|
506
|
+
'--ol-partial-background-color': 'rgba(127, 127, 127, 0.7)',
|
|
507
|
+
'--ol-foreground-color': '#000000',
|
|
508
|
+
'--ol-subtle-foreground-color': '#000',
|
|
509
|
+
'--ol-subtle-background-color': 'rgba(78, 78, 78, 0.5)',
|
|
510
|
+
background: 'none',
|
|
511
|
+
});
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
public postrender = () => {
|
|
515
|
+
this.refreshRenderValues();
|
|
516
|
+
triggerEvent(this.element, EVENTS.IMAGE_RENDERED, {
|
|
517
|
+
element: this.element,
|
|
518
|
+
viewportId: this.id,
|
|
519
|
+
viewport: this,
|
|
520
|
+
renderingEngineId: this.renderingEngineId,
|
|
521
|
+
});
|
|
522
|
+
};
|
|
523
|
+
|
|
524
|
+
/**
|
|
525
|
+
* Scrolls the image - for WSI, this changes the zoom ratio since different
|
|
526
|
+
* images are used to represent different zoom levels, although this also
|
|
527
|
+
* allows fractional zoom levels
|
|
528
|
+
*/
|
|
529
|
+
public scroll(delta: number) {
|
|
530
|
+
const camera = this.getCamera();
|
|
531
|
+
this.setCamera({
|
|
532
|
+
parallelScale: camera.parallelScale * (1 + 0.1 * delta),
|
|
533
|
+
});
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
public getRotation = () => 0;
|
|
537
|
+
|
|
538
|
+
protected canvasToIndex = (canvasPos: Point2): Point2 => {
|
|
539
|
+
const transform = this.getTransform();
|
|
540
|
+
transform.invert();
|
|
541
|
+
return transform.transformPoint(canvasPos);
|
|
542
|
+
};
|
|
543
|
+
|
|
544
|
+
protected indexToCanvas = (indexPos: Point2): Point2 => {
|
|
545
|
+
const transform = this.getTransform();
|
|
546
|
+
return transform.transformPoint(indexPos);
|
|
547
|
+
};
|
|
548
|
+
|
|
549
|
+
/** This can be implemented later when multi-slice WSI is supported */
|
|
550
|
+
public getSliceIndex() {
|
|
551
|
+
return 0;
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
/**
|
|
555
|
+
* Gets the internal OpenLayers view object being rendered
|
|
556
|
+
* Note this is not typeds right now, but might add typing later.
|
|
557
|
+
*/
|
|
558
|
+
getView() {
|
|
559
|
+
if (!this.viewer) {
|
|
560
|
+
return;
|
|
561
|
+
}
|
|
562
|
+
// TODO - use a native method rather than accessing internals directly
|
|
563
|
+
const map = this.viewer[_map];
|
|
564
|
+
// TODO - remove the globals setter
|
|
565
|
+
const anyWindow = window as unknown as Record<string, unknown>;
|
|
566
|
+
anyWindow.map = map;
|
|
567
|
+
anyWindow.viewer = this.viewer;
|
|
568
|
+
anyWindow.view = map?.getView();
|
|
569
|
+
anyWindow.wsi = this;
|
|
570
|
+
return map?.getView();
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
/**
|
|
574
|
+
* Updates the internal camera rendering values from the underlying open layers
|
|
575
|
+
* data.
|
|
576
|
+
*/
|
|
577
|
+
private refreshRenderValues() {
|
|
578
|
+
const view = this.getView();
|
|
579
|
+
if (!view) {
|
|
580
|
+
return;
|
|
581
|
+
}
|
|
582
|
+
const resolution = view.getResolution();
|
|
583
|
+
if (!resolution || resolution < EPSILON) {
|
|
584
|
+
return;
|
|
585
|
+
}
|
|
586
|
+
// The location of the center right now
|
|
587
|
+
const centerIndex = view.getCenter();
|
|
588
|
+
const extent = view.getProjection().getExtent();
|
|
589
|
+
const rotation = view.getRotation();
|
|
590
|
+
const zoom = view.getZoom();
|
|
591
|
+
|
|
592
|
+
const {
|
|
593
|
+
metadata: {
|
|
594
|
+
spacing: [xSpacing, ySpacing],
|
|
595
|
+
},
|
|
596
|
+
} = this;
|
|
597
|
+
|
|
598
|
+
// this means that each unit (pixel) in the world (video) would be
|
|
599
|
+
// represented by n pixels in the canvas.
|
|
600
|
+
const worldToCanvasRatio = 1 / resolution / xSpacing;
|
|
601
|
+
|
|
602
|
+
Object.assign(this.internalCamera, {
|
|
603
|
+
extent,
|
|
604
|
+
centerIndex,
|
|
605
|
+
worldToCanvasRatio,
|
|
606
|
+
xSpacing,
|
|
607
|
+
ySpacing,
|
|
608
|
+
resolution,
|
|
609
|
+
rotation,
|
|
610
|
+
zoom,
|
|
611
|
+
});
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
public customRenderViewportToCanvas = () => {
|
|
615
|
+
// console.log('TODO - custom render');
|
|
616
|
+
};
|
|
617
|
+
|
|
618
|
+
public getZoom() {
|
|
619
|
+
return this.getView()?.getZoom();
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
public setZoom(zoom: number) {
|
|
623
|
+
this.getView()?.setZoom(zoom);
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
/**
|
|
627
|
+
* The transform here is from index to canvas points, so this takes
|
|
628
|
+
* into account the scaling applied and the center location, but nothing to do
|
|
629
|
+
* with world coordinate transforms.
|
|
630
|
+
* Note that the 'index' values are often negative values with respect to the overall
|
|
631
|
+
* image area, as that is what is used internally for the view.
|
|
632
|
+
*
|
|
633
|
+
* @returns A transform from index to canvas points
|
|
634
|
+
*/
|
|
635
|
+
protected getTransform() {
|
|
636
|
+
this.refreshRenderValues();
|
|
637
|
+
const { centerIndex: center, resolution, rotation } = this.internalCamera;
|
|
638
|
+
|
|
639
|
+
const halfCanvas = [this.canvas.width / 2, this.canvas.height / 2];
|
|
640
|
+
const transform = new Transform();
|
|
641
|
+
|
|
642
|
+
// Translate to the center of the canvas (move origin of the transform
|
|
643
|
+
// to the center of the canvas)
|
|
644
|
+
transform.translate(halfCanvas[0], halfCanvas[1]);
|
|
645
|
+
// Difference in sign for x/y to account for screen coordinates
|
|
646
|
+
transform.rotate(rotation);
|
|
647
|
+
transform.scale(1 / resolution, -1 / resolution);
|
|
648
|
+
transform.translate(-center[0], -center[1]);
|
|
649
|
+
return transform;
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
public getReferenceId(): string {
|
|
653
|
+
return `imageId:${this.getCurrentImageId()}`;
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
public getCurrentImageIdIndex() {
|
|
657
|
+
return 0;
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
export default WSIViewport;
|
|
@@ -4,6 +4,7 @@ import VolumeViewport from '../VolumeViewport';
|
|
|
4
4
|
import ViewportType from '../../enums/ViewportType';
|
|
5
5
|
import VolumeViewport3D from '../VolumeViewport3D';
|
|
6
6
|
import VideoViewport from '../VideoViewport';
|
|
7
|
+
import WSIViewport from '../WSIViewport';
|
|
7
8
|
|
|
8
9
|
const viewportTypeToViewportClass = {
|
|
9
10
|
[ViewportType.ORTHOGRAPHIC]: VolumeViewport,
|
|
@@ -11,6 +12,7 @@ const viewportTypeToViewportClass = {
|
|
|
11
12
|
[ViewportType.STACK]: StackViewport,
|
|
12
13
|
[ViewportType.VOLUME_3D]: VolumeViewport3D,
|
|
13
14
|
[ViewportType.VIDEO]: VideoViewport,
|
|
15
|
+
[ViewportType.WholeSlide]: WSIViewport,
|
|
14
16
|
};
|
|
15
17
|
|
|
16
18
|
export default viewportTypeToViewportClass;
|
|
@@ -27,6 +27,11 @@ enum MetadataModules {
|
|
|
27
27
|
SOP_COMMON = 'sopCommonModule',
|
|
28
28
|
ULTRASOUND_ENHANCED_REGION = 'ultrasoundEnhancedRegionModule',
|
|
29
29
|
VOI_LUT = 'voiLutModule',
|
|
30
|
+
/**
|
|
31
|
+
* Some modules need direct access to a web client. This allows getting
|
|
32
|
+
* it as metadata in order to get it generically.
|
|
33
|
+
*/
|
|
34
|
+
WEB_CLIENT = 'webClient',
|
|
30
35
|
}
|
|
31
36
|
|
|
32
37
|
export default MetadataModules;
|
package/src/index.ts
CHANGED
|
@@ -13,6 +13,7 @@ import VolumeViewport3D from './RenderingEngine/VolumeViewport3D';
|
|
|
13
13
|
import BaseVolumeViewport from './RenderingEngine/BaseVolumeViewport';
|
|
14
14
|
import StackViewport from './RenderingEngine/StackViewport';
|
|
15
15
|
import VideoViewport from './RenderingEngine/VideoViewport';
|
|
16
|
+
import WSIViewport from './RenderingEngine/WSIViewport';
|
|
16
17
|
import Viewport from './RenderingEngine/Viewport';
|
|
17
18
|
import eventTarget from './eventTarget';
|
|
18
19
|
import {
|
|
@@ -104,6 +105,7 @@ export {
|
|
|
104
105
|
Viewport,
|
|
105
106
|
StackViewport,
|
|
106
107
|
VideoViewport,
|
|
108
|
+
WSIViewport,
|
|
107
109
|
RenderingEngine,
|
|
108
110
|
ImageVolume,
|
|
109
111
|
Surface,
|