@cornerstonejs/core 2.0.0-beta.2 → 2.0.0-beta.3
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/StackViewport.js +2 -2
- package/dist/cjs/RenderingEngine/StackViewport.js.map +1 -1
- package/dist/cjs/RenderingEngine/VolumeViewport.js +13 -0
- package/dist/cjs/RenderingEngine/VolumeViewport.js.map +1 -1
- package/dist/cjs/cache/cache.d.ts +3 -1
- package/dist/cjs/cache/cache.js +12 -7
- package/dist/cjs/cache/cache.js.map +1 -1
- package/dist/cjs/types/IImage.d.ts +2 -0
- package/dist/esm/RenderingEngine/StackViewport.js +2 -2
- package/dist/esm/RenderingEngine/StackViewport.js.map +1 -1
- package/dist/esm/RenderingEngine/VolumeViewport.js +15 -2
- package/dist/esm/RenderingEngine/VolumeViewport.js.map +1 -1
- package/dist/esm/cache/cache.d.ts +3 -1
- package/dist/esm/cache/cache.js +12 -7
- package/dist/esm/cache/cache.js.map +1 -1
- package/dist/esm/types/IImage.d.ts +2 -0
- package/dist/umd/index.js +1 -1
- package/dist/umd/index.js.map +1 -1
- package/package.json +2 -2
- package/src/RenderingEngine/StackViewport.ts +2 -2
- package/src/RenderingEngine/Viewport.ts +1 -1
- package/src/RenderingEngine/VolumeViewport.ts +20 -3
- package/src/cache/cache.ts +33 -18
- package/src/types/IImage.ts +2 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cornerstonejs/core",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/umd/index.js",
|
|
6
6
|
"types": "dist/esm/index.d.ts",
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"type": "individual",
|
|
47
47
|
"url": "https://ohif.org/donate"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "d78cf780d4383a61ea0a9762bafa4104666757a4"
|
|
50
50
|
}
|
|
@@ -1017,7 +1017,7 @@ class StackViewport extends Viewport implements IStackViewport {
|
|
|
1017
1017
|
? vec3.negate(vec3.create(), this.initialViewUp)
|
|
1018
1018
|
: this.initialViewUp;
|
|
1019
1019
|
|
|
1020
|
-
this.
|
|
1020
|
+
this.setCameraNoEvent({
|
|
1021
1021
|
viewUp: initialViewUp as Point3,
|
|
1022
1022
|
});
|
|
1023
1023
|
|
|
@@ -2239,7 +2239,7 @@ class StackViewport extends Viewport implements IStackViewport {
|
|
|
2239
2239
|
|
|
2240
2240
|
const targetImageId = imageIds[newTargetImageIdIndex];
|
|
2241
2241
|
|
|
2242
|
-
const imageAlreadyLoaded = cache.
|
|
2242
|
+
const imageAlreadyLoaded = cache.isLoaded(targetImageId);
|
|
2243
2243
|
|
|
2244
2244
|
// If image is already cached we want to scroll right away; however, if it is
|
|
2245
2245
|
// not cached, we can debounce the scroll event to avoid firing multiple scroll
|
|
@@ -126,7 +126,7 @@ class Viewport implements IViewport {
|
|
|
126
126
|
|
|
127
127
|
/**
|
|
128
128
|
* Indicate that the image has been rendered.
|
|
129
|
-
* This will set
|
|
129
|
+
* This will set the viewportStatus to RENDERED if there is image data
|
|
130
130
|
* available to actually be rendered - otherwise, the rendering simply showed
|
|
131
131
|
* the background image.
|
|
132
132
|
*/
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import vtkPlane from '@kitware/vtk.js/Common/DataModel/Plane';
|
|
2
|
+
import vtkVolume from '@kitware/vtk.js/Rendering/Core/Volume';
|
|
3
|
+
|
|
2
4
|
import { vec3 } from 'gl-matrix';
|
|
3
5
|
|
|
4
6
|
import cache from '../cache';
|
|
5
7
|
import { MPR_CAMERA_VALUES, RENDERING_DEFAULTS } from '../constants';
|
|
6
|
-
import { BlendModes, OrientationAxis } from '../enums';
|
|
8
|
+
import { BlendModes, OrientationAxis, Events } from '../enums';
|
|
7
9
|
import type {
|
|
8
10
|
ActorEntry,
|
|
9
11
|
IImageVolume,
|
|
@@ -12,10 +14,9 @@ import type {
|
|
|
12
14
|
Point3,
|
|
13
15
|
} from '../types';
|
|
14
16
|
import type { ViewportInput } from '../types/IViewport';
|
|
15
|
-
import { actorIsA, getClosestImageId } from '../utilities';
|
|
17
|
+
import { actorIsA, getClosestImageId, triggerEvent } from '../utilities';
|
|
16
18
|
import BaseVolumeViewport from './BaseVolumeViewport';
|
|
17
19
|
import setDefaultVolumeVOI from './helpers/setDefaultVolumeVOI';
|
|
18
|
-
import vtkVolume from '@kitware/vtk.js/Rendering/Core/Volume';
|
|
19
20
|
|
|
20
21
|
/**
|
|
21
22
|
* An object representing a VolumeViewport. VolumeViewports are used to render
|
|
@@ -383,6 +384,22 @@ class VolumeViewport extends BaseVolumeViewport {
|
|
|
383
384
|
);
|
|
384
385
|
}
|
|
385
386
|
setDefaultVolumeVOI(volumeActor.actor as vtkVolume, imageVolume, false);
|
|
387
|
+
|
|
388
|
+
const range = (volumeActor.actor as vtkVolume)
|
|
389
|
+
.getProperty()
|
|
390
|
+
.getRGBTransferFunction(0)
|
|
391
|
+
.getMappingRange();
|
|
392
|
+
|
|
393
|
+
const eventDetails = {
|
|
394
|
+
viewportId: volumeActor.uid,
|
|
395
|
+
range: {
|
|
396
|
+
lower: range[0],
|
|
397
|
+
upper: range[1],
|
|
398
|
+
},
|
|
399
|
+
volumeId: volumeActor.uid,
|
|
400
|
+
};
|
|
401
|
+
|
|
402
|
+
triggerEvent(this.element, Events.VOI_MODIFIED, eventDetails);
|
|
386
403
|
}
|
|
387
404
|
}
|
|
388
405
|
|
package/src/cache/cache.ts
CHANGED
|
@@ -15,34 +15,40 @@ import { triggerEvent, imageIdToURI } from '../utilities';
|
|
|
15
15
|
import eventTarget from '../eventTarget';
|
|
16
16
|
import Events from '../enums/Events';
|
|
17
17
|
|
|
18
|
-
const
|
|
18
|
+
const ONE_GB = 1073741824;
|
|
19
19
|
|
|
20
|
+
/**
|
|
21
|
+
* Stores images, volumes and geometry.
|
|
22
|
+
* There are two sizes - the max cache size, that controls the overal maximum
|
|
23
|
+
* size, and the instance size, which controls how big any single object can
|
|
24
|
+
* be. Defaults are 3 GB and 2 GB - 8 bytes (just enough to allow allocating it
|
|
25
|
+
* without crashing).
|
|
26
|
+
* The 3 gb is tuned to the chromium garbage collection cycle to allow image volumes
|
|
27
|
+
* to be used/discarded.
|
|
28
|
+
*/
|
|
20
29
|
class Cache implements ICache {
|
|
21
|
-
|
|
22
|
-
private readonly
|
|
30
|
+
// used to store image data (2d)
|
|
31
|
+
private readonly _imageCache = new Map<string, ICachedImage>(); // volatile space
|
|
32
|
+
// used to store volume data (3d)
|
|
33
|
+
private readonly _volumeCache = new Map<string, ICachedVolume>(); // non-volatile space
|
|
23
34
|
// Todo: contour for now, but will be used for surface, etc.
|
|
24
35
|
private readonly _geometryCache: Map<string, ICachedGeometry>;
|
|
25
|
-
|
|
26
|
-
private
|
|
27
|
-
private
|
|
36
|
+
|
|
37
|
+
private _imageCacheSize = 0;
|
|
38
|
+
private _volumeCacheSize = 0;
|
|
39
|
+
private _maxCacheSize = 3 * ONE_GB;
|
|
40
|
+
private _maxInstanceSize = 2 * ONE_GB - 8;
|
|
28
41
|
|
|
29
42
|
constructor() {
|
|
30
|
-
// used to store image data (2d)
|
|
31
|
-
this._imageCache = new Map();
|
|
32
|
-
// used to store volume data (3d)
|
|
33
|
-
this._volumeCache = new Map();
|
|
34
43
|
// used to store object data (contour, surface, etc.)
|
|
35
44
|
this._geometryCache = new Map();
|
|
36
|
-
this._imageCacheSize = 0;
|
|
37
|
-
this._volumeCacheSize = 0;
|
|
38
|
-
this._maxCacheSize = MAX_CACHE_SIZE_1GB; // Default 1GB
|
|
39
45
|
}
|
|
40
46
|
|
|
41
47
|
/**
|
|
42
48
|
* Set the maximum cache Size
|
|
43
49
|
*
|
|
44
|
-
* Maximum cache size should be set before adding the data
|
|
45
|
-
* will
|
|
50
|
+
* Maximum cache size should be set before adding the data. If set after,
|
|
51
|
+
* and it is smaller than the current size, will cause issues.
|
|
46
52
|
*
|
|
47
53
|
* @param newMaxCacheSize - new maximum cache size
|
|
48
54
|
*
|
|
@@ -59,7 +65,7 @@ class Cache implements ICache {
|
|
|
59
65
|
/**
|
|
60
66
|
* Checks if there is enough space in the cache for requested byte size
|
|
61
67
|
*
|
|
62
|
-
* It
|
|
68
|
+
* It returns false, if the sum of volatile (image) cache and unallocated cache
|
|
63
69
|
* is less than the requested byteLength
|
|
64
70
|
*
|
|
65
71
|
* @param byteLength - byte length of requested byte size
|
|
@@ -67,6 +73,9 @@ class Cache implements ICache {
|
|
|
67
73
|
* @returns - boolean indicating if there is enough space in the cache
|
|
68
74
|
*/
|
|
69
75
|
public isCacheable = (byteLength: number): boolean => {
|
|
76
|
+
if (byteLength > this._maxInstanceSize) {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
70
79
|
const unallocatedSpace = this.getBytesAvailable();
|
|
71
80
|
const imageCacheSize = this._imageCacheSize;
|
|
72
81
|
const availableSpace = unallocatedSpace + imageCacheSize;
|
|
@@ -81,6 +90,13 @@ class Cache implements ICache {
|
|
|
81
90
|
*/
|
|
82
91
|
public getMaxCacheSize = (): number => this._maxCacheSize;
|
|
83
92
|
|
|
93
|
+
/**
|
|
94
|
+
* Returns maximum size of a single instance (volume or single image)
|
|
95
|
+
*
|
|
96
|
+
* @returns maximum instance size
|
|
97
|
+
*/
|
|
98
|
+
public getMaxInstanceSize = (): number => this._maxInstanceSize;
|
|
99
|
+
|
|
84
100
|
/**
|
|
85
101
|
* Returns current size of the cache
|
|
86
102
|
*
|
|
@@ -384,7 +400,6 @@ class Cache implements ICache {
|
|
|
384
400
|
cachedImage.image = image;
|
|
385
401
|
cachedImage.sizeInBytes = image.sizeInBytes;
|
|
386
402
|
this._incrementImageCacheSize(cachedImage.sizeInBytes);
|
|
387
|
-
|
|
388
403
|
const eventDetails: EventTypes.ImageCacheImageAddedEventDetail = {
|
|
389
404
|
image: cachedImage,
|
|
390
405
|
};
|
|
@@ -429,7 +444,7 @@ class Cache implements ICache {
|
|
|
429
444
|
* @param imageId - image Id to check
|
|
430
445
|
* @returns boolean
|
|
431
446
|
*/
|
|
432
|
-
public
|
|
447
|
+
public isLoaded(imageId: string): boolean {
|
|
433
448
|
const cachedImage = this._imageCache.get(imageId);
|
|
434
449
|
|
|
435
450
|
if (!cachedImage) {
|
package/src/types/IImage.ts
CHANGED