@cornerstonejs/core 0.46.1 → 0.47.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cornerstonejs/core",
3
- "version": "0.46.1",
3
+ "version": "0.47.0",
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": "a853107a5b908984ec3649ec3c0d9a61e7c3397f"
46
+ "gitHead": "2c2efd8536d4af3ede72a47bdab199efe67bb1d3"
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: (colormap: CPUFallbackColormapData) => void;
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: CPUFallbackColormapData) {
2657
- // TODO -> vtk has full colormaps which are piecewise and frankly better?
2658
- // Do we really want a pre defined 256 color map just for the sake of harmonization?
2659
- throw new Error('setColorMapGPU not implemented.');
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() {
@@ -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
  */
@@ -44,6 +44,17 @@ export default function renderToCanvasGPU(
44
44
  element.style.visibility = 'hidden';
45
45
  element.style.position = 'absolute';
46
46
 
47
+ // Up-sampling the provided canvas to match the device pixel ratio
48
+ // since we use device pixel ratio to determine the size of the canvas
49
+ // inside the rendering engine.
50
+ const devicePixelRatio = window.devicePixelRatio || 1;
51
+ const originalWidth = canvas.width;
52
+ const originalHeight = canvas.height;
53
+ canvas.width = originalWidth * devicePixelRatio;
54
+ canvas.height = originalHeight * devicePixelRatio;
55
+ canvas.style.width = `${originalWidth}px`;
56
+ canvas.style.height = `${originalHeight}px`;
57
+
47
58
  document.body.appendChild(element);
48
59
 
49
60
  // add id to the element so we can find it later, and fix the : which is not allowed in css
@@ -85,7 +96,18 @@ export default function renderToCanvasGPU(
85
96
 
86
97
  // Copy the temporary canvas to the given canvas
87
98
  const context = canvas.getContext('2d');
88
- context.drawImage(temporaryCanvas, 0, 0);
99
+ context.drawImage(
100
+ temporaryCanvas,
101
+ 0,
102
+ 0,
103
+ temporaryCanvas.width,
104
+ temporaryCanvas.height, // source dimensions
105
+ 0,
106
+ 0,
107
+ canvas.width,
108
+ canvas.height // destination dimensions
109
+ );
110
+
89
111
  elementRendered = true;
90
112
 
91
113
  // remove based on id