@cornerstonejs/core 0.46.2 → 0.47.1
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.js +1 -0
- package/dist/cjs/RenderingEngine/RenderingEngine.js.map +1 -1
- package/dist/cjs/RenderingEngine/StackViewport.d.ts +3 -2
- package/dist/cjs/RenderingEngine/StackViewport.js +26 -1
- package/dist/cjs/RenderingEngine/StackViewport.js.map +1 -1
- package/dist/cjs/RenderingEngine/VolumeViewport.d.ts +0 -1
- package/dist/cjs/RenderingEngine/VolumeViewport.js +10 -21
- package/dist/cjs/RenderingEngine/VolumeViewport.js.map +1 -1
- package/dist/cjs/types/IStackViewport.d.ts +2 -1
- package/dist/cjs/utilities/getClosestImageId.d.ts +1 -1
- package/dist/cjs/utilities/getClosestImageId.js +3 -2
- package/dist/cjs/utilities/getClosestImageId.js.map +1 -1
- package/dist/esm/RenderingEngine/RenderingEngine.js +1 -0
- package/dist/esm/RenderingEngine/RenderingEngine.js.map +1 -1
- package/dist/esm/RenderingEngine/StackViewport.d.ts +3 -2
- package/dist/esm/RenderingEngine/StackViewport.js +26 -1
- package/dist/esm/RenderingEngine/StackViewport.js.map +1 -1
- package/dist/esm/RenderingEngine/VolumeViewport.d.ts +0 -1
- package/dist/esm/RenderingEngine/VolumeViewport.js +12 -23
- package/dist/esm/RenderingEngine/VolumeViewport.js.map +1 -1
- package/dist/esm/types/IStackViewport.d.ts +2 -1
- package/dist/esm/utilities/getClosestImageId.d.ts +1 -1
- package/dist/esm/utilities/getClosestImageId.js +3 -2
- package/dist/esm/utilities/getClosestImageId.js.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 +1 -2
- package/src/RenderingEngine/StackViewport.ts +40 -5
- package/src/RenderingEngine/VolumeViewport.ts +26 -45
- package/src/types/IStackViewport.ts +2 -1
- package/src/utilities/getClosestImageId.ts +3 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cornerstonejs/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.47.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/umd/index.js",
|
|
6
6
|
"types": "dist/esm/index.d.ts",
|
|
@@ -43,5 +43,5 @@
|
|
|
43
43
|
"type": "individual",
|
|
44
44
|
"url": "https://ohif.org/donate"
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "fe634bf0a19f588638aaa21d4bcbbc8df33897b3"
|
|
47
47
|
}
|
|
@@ -148,9 +148,8 @@ class RenderingEngine implements IRenderingEngine {
|
|
|
148
148
|
|
|
149
149
|
// 1.a) If there is a found viewport, we remove the viewport and create a new viewport
|
|
150
150
|
if (viewport) {
|
|
151
|
+
console.log('Viewport already exists, disabling it first');
|
|
151
152
|
this.disableElement(viewportId);
|
|
152
|
-
// todo: if only removing the viewport, make sure resize also happens
|
|
153
|
-
// this._removeViewport(viewportId)
|
|
154
153
|
}
|
|
155
154
|
|
|
156
155
|
// 2.a) See if viewport uses a custom rendering pipeline.
|
|
@@ -6,6 +6,7 @@ import vtkCamera from '@kitware/vtk.js/Rendering/Core/Camera';
|
|
|
6
6
|
import { vec2, vec3, mat4 } from 'gl-matrix';
|
|
7
7
|
import vtkImageMapper from '@kitware/vtk.js/Rendering/Core/ImageMapper';
|
|
8
8
|
import vtkImageSlice from '@kitware/vtk.js/Rendering/Core/ImageSlice';
|
|
9
|
+
import vtkColorTransferFunction from '@kitware/vtk.js/Rendering/Core/ColorTransferFunction';
|
|
9
10
|
import * as metaData from '../metaData';
|
|
10
11
|
import Viewport from './Viewport';
|
|
11
12
|
import eventTarget from '../eventTarget';
|
|
@@ -39,6 +40,7 @@ import {
|
|
|
39
40
|
IStackViewport,
|
|
40
41
|
VolumeActor,
|
|
41
42
|
Mat3,
|
|
43
|
+
ColormapRegistration,
|
|
42
44
|
} from '../types';
|
|
43
45
|
import { ViewportInput } from '../types/IViewport';
|
|
44
46
|
import drawImageSync from './helpers/cpuFallback/drawImageSync';
|
|
@@ -267,7 +269,9 @@ class StackViewport extends Viewport implements IStackViewport {
|
|
|
267
269
|
* Sets the colormap for the current viewport.
|
|
268
270
|
* @param colormap - The colormap data to use.
|
|
269
271
|
*/
|
|
270
|
-
public setColormap: (
|
|
272
|
+
public setColormap: (
|
|
273
|
+
colormap: CPUFallbackColormapData | ColormapRegistration
|
|
274
|
+
) => void;
|
|
271
275
|
|
|
272
276
|
/**
|
|
273
277
|
* If the user has selected CPU rendering, return the CPU camera, otherwise
|
|
@@ -1494,6 +1498,8 @@ class StackViewport extends Viewport implements IStackViewport {
|
|
|
1494
1498
|
imageIds: Array<string>,
|
|
1495
1499
|
currentImageIdIndex = 0
|
|
1496
1500
|
): Promise<string> {
|
|
1501
|
+
this._throwIfDestroyed();
|
|
1502
|
+
|
|
1497
1503
|
this.imageIds = imageIds;
|
|
1498
1504
|
this.currentImageIdIndex = currentImageIdIndex;
|
|
1499
1505
|
this.targetImageIdIndex = currentImageIdIndex;
|
|
@@ -1527,6 +1533,19 @@ class StackViewport extends Viewport implements IStackViewport {
|
|
|
1527
1533
|
return imageId;
|
|
1528
1534
|
}
|
|
1529
1535
|
|
|
1536
|
+
/**
|
|
1537
|
+
* Throws an error if you are using a destroyed instance of the stack viewport
|
|
1538
|
+
*/
|
|
1539
|
+
private _throwIfDestroyed() {
|
|
1540
|
+
if (this.isDisabled) {
|
|
1541
|
+
throw new Error(
|
|
1542
|
+
'The stack viewport has been destroyed and is no longer usable. Renderings will not be performed. If you ' +
|
|
1543
|
+
'are using the same viewportId and have re-enabled the viewport, you need to grab the new viewport instance ' +
|
|
1544
|
+
'using renderingEngine.getViewport(viewportId), instead of using your lexical scoped reference to the viewport instance.'
|
|
1545
|
+
);
|
|
1546
|
+
}
|
|
1547
|
+
}
|
|
1548
|
+
|
|
1530
1549
|
/**
|
|
1531
1550
|
* It checks if the new image object matches the dimensions, spacing,
|
|
1532
1551
|
* and direction of the previously displayed image in the viewport or not.
|
|
@@ -2278,6 +2297,8 @@ class StackViewport extends Viewport implements IStackViewport {
|
|
|
2278
2297
|
* provided imageIds in setStack
|
|
2279
2298
|
*/
|
|
2280
2299
|
public async setImageIdIndex(imageIdIndex: number): Promise<string> {
|
|
2300
|
+
this._throwIfDestroyed();
|
|
2301
|
+
|
|
2281
2302
|
// If we are already on this imageId index, stop here
|
|
2282
2303
|
if (this.currentImageIdIndex === imageIdIndex) {
|
|
2283
2304
|
return this.getCurrentImageId();
|
|
@@ -2653,10 +2674,24 @@ class StackViewport extends Viewport implements IStackViewport {
|
|
|
2653
2674
|
this.render();
|
|
2654
2675
|
}
|
|
2655
2676
|
|
|
2656
|
-
private setColormapGPU(colormap:
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
|
|
2677
|
+
private setColormapGPU(colormap: ColormapRegistration) {
|
|
2678
|
+
const ActorEntry = this.getDefaultActor();
|
|
2679
|
+
const actor = ActorEntry.actor as ImageActor;
|
|
2680
|
+
const actorProp = actor.getProperty();
|
|
2681
|
+
const rgbTransferFunction = actorProp.getRGBTransferFunction();
|
|
2682
|
+
|
|
2683
|
+
if (!rgbTransferFunction) {
|
|
2684
|
+
const cfun = vtkColorTransferFunction.newInstance();
|
|
2685
|
+
const voiRange = this._getVOIRangeForCurrentImage();
|
|
2686
|
+
cfun.applyColorMap(colormap);
|
|
2687
|
+
cfun.setMappingRange(voiRange.lower, voiRange.upper);
|
|
2688
|
+
actorProp.setRGBTransferFunction(0, cfun);
|
|
2689
|
+
} else {
|
|
2690
|
+
rgbTransferFunction.applyColorMap(colormap);
|
|
2691
|
+
actorProp.setRGBTransferFunction(0, rgbTransferFunction);
|
|
2692
|
+
}
|
|
2693
|
+
|
|
2694
|
+
this.render();
|
|
2660
2695
|
}
|
|
2661
2696
|
|
|
2662
2697
|
private unsetColormapGPU() {
|
|
@@ -12,7 +12,7 @@ import type {
|
|
|
12
12
|
Point3,
|
|
13
13
|
} from '../types';
|
|
14
14
|
import type { ViewportInput } from '../types/IViewport';
|
|
15
|
-
import { actorIsA } from '../utilities';
|
|
15
|
+
import { actorIsA, getClosestImageId } from '../utilities';
|
|
16
16
|
import transformWorldToIndex from '../utilities/transformWorldToIndex';
|
|
17
17
|
import BaseVolumeViewport from './BaseVolumeViewport';
|
|
18
18
|
|
|
@@ -336,15 +336,29 @@ class VolumeViewport extends BaseVolumeViewport {
|
|
|
336
336
|
}
|
|
337
337
|
|
|
338
338
|
/**
|
|
339
|
-
* Uses
|
|
340
|
-
* is looking at the volume in the direction of acquisition (imageIds).
|
|
341
|
-
* If so, it uses the origin and focalPoint to calculate the slice index.
|
|
339
|
+
* Uses the origin and focalPoint to calculate the slice index.
|
|
342
340
|
* Todo: This only works if the imageIds are properly sorted
|
|
343
341
|
*
|
|
344
342
|
* @returns The slice index
|
|
345
343
|
*/
|
|
346
344
|
public getCurrentImageIdIndex = (): number | undefined => {
|
|
347
|
-
|
|
345
|
+
const { viewPlaneNormal, focalPoint } = this.getCamera();
|
|
346
|
+
|
|
347
|
+
// Todo: handle scenario of fusion of multiple volumes
|
|
348
|
+
// we cannot only check number of actors, because we might have
|
|
349
|
+
// segmentations ...
|
|
350
|
+
const { origin, spacing } = this.getImageData();
|
|
351
|
+
|
|
352
|
+
// how many steps are from the origin to the focal point in the
|
|
353
|
+
// normal direction
|
|
354
|
+
const spacingInNormal = spacing[2];
|
|
355
|
+
const sub = vec3.create();
|
|
356
|
+
vec3.sub(sub, focalPoint, origin);
|
|
357
|
+
const distance = vec3.dot(sub, viewPlaneNormal);
|
|
358
|
+
|
|
359
|
+
// divide by the spacing in the normal direction to get the
|
|
360
|
+
// number of steps, and subtract 1 to get the index
|
|
361
|
+
return Math.round(Math.abs(distance) / spacingInNormal);
|
|
348
362
|
};
|
|
349
363
|
|
|
350
364
|
/**
|
|
@@ -356,10 +370,12 @@ class VolumeViewport extends BaseVolumeViewport {
|
|
|
356
370
|
* @returns ImageId
|
|
357
371
|
*/
|
|
358
372
|
public getCurrentImageId = (): string | undefined => {
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
373
|
+
if (this.getActors().length > 1) {
|
|
374
|
+
console.warn(
|
|
375
|
+
`Using the first/default actor of ${
|
|
376
|
+
this.getActors().length
|
|
377
|
+
} actors for getCurrentImageId.`
|
|
378
|
+
);
|
|
363
379
|
}
|
|
364
380
|
|
|
365
381
|
const actorEntry = this.getDefaultActor();
|
|
@@ -374,44 +390,9 @@ class VolumeViewport extends BaseVolumeViewport {
|
|
|
374
390
|
return;
|
|
375
391
|
}
|
|
376
392
|
|
|
377
|
-
const imageIds = volume.imageIds;
|
|
378
|
-
|
|
379
|
-
return imageIds[index];
|
|
380
|
-
};
|
|
381
|
-
|
|
382
|
-
private _getImageIdIndex = () => {
|
|
383
393
|
const { viewPlaneNormal, focalPoint } = this.getCamera();
|
|
384
394
|
|
|
385
|
-
|
|
386
|
-
// we cannot only check number of actors, because we might have
|
|
387
|
-
// segmentations ...
|
|
388
|
-
const { direction, origin, spacing } = this.getImageData();
|
|
389
|
-
|
|
390
|
-
// get the last 3 components of the direction - axis normal
|
|
391
|
-
const dir = direction.slice(direction.length - 3);
|
|
392
|
-
|
|
393
|
-
const dot = Math.abs(
|
|
394
|
-
dir[0] * viewPlaneNormal[0] +
|
|
395
|
-
dir[1] * viewPlaneNormal[1] +
|
|
396
|
-
dir[2] * viewPlaneNormal[2]
|
|
397
|
-
);
|
|
398
|
-
|
|
399
|
-
// if dot is not 1 or -1 return null since it means
|
|
400
|
-
// viewport is not looking at the image acquisition plane
|
|
401
|
-
if (dot - 1 > EPSILON) {
|
|
402
|
-
return;
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
// how many steps are from the origin to the focal point in the
|
|
406
|
-
// normal direction
|
|
407
|
-
const spacingInNormal = spacing[2];
|
|
408
|
-
const sub = vec3.create();
|
|
409
|
-
vec3.sub(sub, focalPoint, origin);
|
|
410
|
-
const distance = vec3.dot(sub, viewPlaneNormal);
|
|
411
|
-
|
|
412
|
-
// divide by the spacing in the normal direction to get the
|
|
413
|
-
// number of steps, and subtract 1 to get the index
|
|
414
|
-
return Math.round(Math.abs(distance) / spacingInNormal);
|
|
395
|
+
return getClosestImageId(volume, focalPoint, viewPlaneNormal);
|
|
415
396
|
};
|
|
416
397
|
|
|
417
398
|
getRotation = (): number => 0;
|
|
@@ -7,6 +7,7 @@ import Point2 from './Point2';
|
|
|
7
7
|
import Point3 from './Point3';
|
|
8
8
|
import { Scaling } from './ScalingParameters';
|
|
9
9
|
import StackViewportProperties from './StackViewportProperties';
|
|
10
|
+
import { ColormapRegistration } from './Colormap';
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
13
|
* Interface for Stack Viewport
|
|
@@ -130,7 +131,7 @@ export default interface IStackViewport extends IViewport {
|
|
|
130
131
|
* Sets the colormap for the current viewport.
|
|
131
132
|
* @param colormap - The colormap data to use.
|
|
132
133
|
*/
|
|
133
|
-
setColormap(colormap: CPUFallbackColormapData): void;
|
|
134
|
+
setColormap(colormap: CPUFallbackColormapData | ColormapRegistration): void;
|
|
134
135
|
/**
|
|
135
136
|
* It sets the colormap to the default colormap.
|
|
136
137
|
*/
|
|
@@ -3,6 +3,7 @@ import * as metaData from '../metaData';
|
|
|
3
3
|
import type { IImageVolume, Point3 } from '../types';
|
|
4
4
|
|
|
5
5
|
import getSpacingInNormalDirection from './getSpacingInNormalDirection';
|
|
6
|
+
import { EPSILON } from '../constants';
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Given an image, a point in space and the viewPlaneNormal it returns the
|
|
@@ -11,15 +12,13 @@ import getSpacingInNormalDirection from './getSpacingInNormalDirection';
|
|
|
11
12
|
* @param imageVolume - The image volume
|
|
12
13
|
* @param worldPos - The position in the world coordinate system (from mouse click)
|
|
13
14
|
* @param viewPlaneNormal - The normal vector of the viewport
|
|
14
|
-
* @param viewUp - The viewUp vector of the camera.
|
|
15
15
|
*
|
|
16
16
|
* @returns The imageId for the tool.
|
|
17
17
|
*/
|
|
18
18
|
export default function getClosestImageId(
|
|
19
19
|
imageVolume: IImageVolume,
|
|
20
20
|
worldPos: Point3,
|
|
21
|
-
viewPlaneNormal: Point3
|
|
22
|
-
viewUp: Point3
|
|
21
|
+
viewPlaneNormal: Point3
|
|
23
22
|
): string {
|
|
24
23
|
if (!imageVolume) {
|
|
25
24
|
return;
|
|
@@ -39,7 +38,7 @@ export default function getClosestImageId(
|
|
|
39
38
|
|
|
40
39
|
// 2.a if imagePlane is not parallel to the camera: tool is not drawn on an
|
|
41
40
|
// imaging plane, return
|
|
42
|
-
if (Math.abs(dotProducts) <
|
|
41
|
+
if (Math.abs(dotProducts) < 1 - EPSILON) {
|
|
43
42
|
return;
|
|
44
43
|
}
|
|
45
44
|
|