@cornerstonejs/core 5.10.2 → 5.10.4

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/esm/init.js CHANGED
@@ -5,7 +5,7 @@ import CentralizedWebWorkerManager from './webWorkerManager/webWorkerManager.js'
5
5
  import { getRenderingCapabilities } from './utilities/renderingCapabilities.js';
6
6
  import triggerEvent from './utilities/triggerEvent.js';
7
7
  import eventTarget from './eventTarget.js';
8
- import { Events, RenderBackends, RenderingEngineModeEnum } from './enums/index.js';
8
+ import { Events, RenderBackends, RenderingEngineModeEnum, VoxelManagerEnum, } from './enums/index.js';
9
9
  import { isRegisteredRenderBackend } from './RenderingEngine/helpers/renderBackendRegistry.js';
10
10
  import { coreLog } from './utilities/logger.js';
11
11
  const log = coreLog.getLogger('init');
@@ -29,6 +29,9 @@ const defaultConfig = {
29
29
  sampleDistanceMultiplier: 1,
30
30
  },
31
31
  },
32
+ segmentation: {
33
+ labelmapVoxelRepresentation: VoxelManagerEnum.Volume,
34
+ },
32
35
  debug: {
33
36
  statsOverlay: false,
34
37
  },
@@ -37,6 +40,7 @@ const defaultConfig = {
37
40
  let config = {
38
41
  ...defaultConfig,
39
42
  rendering: { ...defaultConfig.rendering },
43
+ segmentation: { ...defaultConfig.segmentation },
40
44
  };
41
45
  let webWorkerManager = null;
42
46
  function _hasNorm16TextureSupport() {
@@ -44,6 +44,7 @@ export declare function cancelLoadAll(): void;
44
44
  export declare function registerImageLoader(scheme: string, imageLoader: ImageLoaderFn): void;
45
45
  export declare function registerUnknownImageLoader(imageLoader: ImageLoaderFn): ImageLoaderFn;
46
46
  export declare function unregisterAllImageLoaders(): void;
47
+ export declare function getDefaultLabelmapVoxelRepresentation(): VoxelManagerEnum;
47
48
  export declare function createAndCacheDerivedLabelmapImages(referencedImageIds: string[], options?: DerivedImageOptions): IImage[];
48
49
  export declare function createAndCacheDerivedLabelmapImage(referencedImageId: string, options?: DerivedImageOptions): IImage;
49
50
  export {};
@@ -7,10 +7,11 @@ import genericMetadataProvider from '../utilities/genericMetadataProvider.js';
7
7
  import { getBufferConfiguration } from '../utilities/getBufferConfiguration.js';
8
8
  import triggerEvent from '../utilities/triggerEvent.js';
9
9
  import uuidv4 from '../utilities/uuidv4.js';
10
- import VoxelManager from '../utilities/VoxelManager.js';
10
+ import VoxelManager, { DEFAULT_RLE_SIZE } from '../utilities/VoxelManager.js';
11
11
  import imageLoadPoolManager from '../requestPool/imageLoadPoolManager.js';
12
12
  import * as metaData from '../metaData.js';
13
13
  import VoxelManagerEnum from '../enums/VoxelManagerEnum.js';
14
+ import { getConfiguration } from '../init.js';
14
15
  const imageLoaders = {};
15
16
  let unknownImageLoader;
16
17
  function getRequestedImageQualityStatus(options) {
@@ -105,7 +106,8 @@ export function createAndCacheDerivedImage(referencedImageId, options = {}) {
105
106
  const imagePlaneModule = metaData.get(MetadataModules.IMAGE_PLANE, referencedImageId);
106
107
  const length = imagePlaneModule.rows * imagePlaneModule.columns;
107
108
  const { TypedArrayConstructor } = getBufferConfiguration(options.targetBuffer?.type, length);
108
- const imageScalarData = new TypedArrayConstructor(skipCreateBuffer ? 1 : length);
109
+ const isRleRepresentation = voxelRepresentation === VoxelManagerEnum.RLE;
110
+ const imageScalarData = new TypedArrayConstructor(skipCreateBuffer || isRleRepresentation ? 1 : length);
109
111
  const derivedImageId = imageId;
110
112
  const referencedImagePlaneMetadata = metaData.get(MetadataModules.IMAGE_PLANE, referencedImageId);
111
113
  genericMetadataProvider.add(derivedImageId, {
@@ -264,8 +266,14 @@ export function createAndCacheLocalImage(imageId, options) {
264
266
  });
265
267
  });
266
268
  const id = imageId;
267
- const voxelManager = (voxelRepresentation === VoxelManagerEnum.RLE &&
268
- VoxelManager.createRLEImageVoxelManager({ dimensions, id })) ||
269
+ const isRle = voxelRepresentation === VoxelManagerEnum.RLE;
270
+ const voxelManager = (isRle &&
271
+ VoxelManager.createRLEImageVoxelManager({
272
+ dimensions,
273
+ id,
274
+ pixelDataConstructor: scalarDataToUse.constructor,
275
+ defaultValue: 0,
276
+ })) ||
269
277
  VoxelManager.createImageVoxelManager({
270
278
  height,
271
279
  width,
@@ -273,6 +281,9 @@ export function createAndCacheLocalImage(imageId, options) {
273
281
  scalarData: scalarDataToUse,
274
282
  id,
275
283
  });
284
+ if (isRle && scalarDataToUse.length >= length) {
285
+ voxelManager.setFromScalarData(scalarDataToUse);
286
+ }
276
287
  let minPixelValue = scalarDataToUse[0];
277
288
  let maxPixelValue = scalarDataToUse[0];
278
289
  for (let i = 1; i < scalarDataToUse.length; i++) {
@@ -306,7 +317,7 @@ export function createAndCacheLocalImage(imageId, options) {
306
317
  invert: false,
307
318
  getPixelData: () => voxelManager.getScalarData(),
308
319
  voxelManager,
309
- sizeInBytes: scalarData.byteLength,
320
+ sizeInBytes: isRle ? DEFAULT_RLE_SIZE : scalarData.byteLength,
310
321
  referencedImageId,
311
322
  };
312
323
  onCacheAdd?.(image);
@@ -368,15 +379,33 @@ export function unregisterAllImageLoaders() {
368
379
  Object.keys(imageLoaders).forEach((imageLoader) => delete imageLoaders[imageLoader]);
369
380
  unknownImageLoader = undefined;
370
381
  }
382
+ export function getDefaultLabelmapVoxelRepresentation() {
383
+ const configured = getConfiguration().segmentation?.labelmapVoxelRepresentation;
384
+ if (configured === undefined) {
385
+ return VoxelManagerEnum.Volume;
386
+ }
387
+ if (configured === VoxelManagerEnum.RLE ||
388
+ configured === VoxelManagerEnum.Volume) {
389
+ return configured;
390
+ }
391
+ console.warn(`Unrecognized segmentation.labelmapVoxelRepresentation "${configured}"; expected ` +
392
+ `"${VoxelManagerEnum.RLE}" or "${VoxelManagerEnum.Volume}". Falling back to ` +
393
+ `"${VoxelManagerEnum.Volume}".`);
394
+ return VoxelManagerEnum.Volume;
395
+ }
371
396
  export function createAndCacheDerivedLabelmapImages(referencedImageIds, options = {}) {
397
+ const { voxelRepresentation = getDefaultLabelmapVoxelRepresentation(), ...rest } = options;
372
398
  return createAndCacheDerivedImages(referencedImageIds, {
373
- ...options,
399
+ ...rest,
400
+ voxelRepresentation,
374
401
  targetBuffer: { type: 'Uint8Array' },
375
402
  });
376
403
  }
377
404
  export function createAndCacheDerivedLabelmapImage(referencedImageId, options = {}) {
405
+ const { voxelRepresentation = getDefaultLabelmapVoxelRepresentation(), ...rest } = options;
378
406
  return createAndCacheDerivedImage(referencedImageId, {
379
- ...options,
407
+ ...rest,
408
+ voxelRepresentation,
380
409
  targetBuffer: { type: 'Uint8Array' },
381
410
  });
382
411
  }
@@ -1,5 +1,5 @@
1
1
  import type { RenderingEngineModeType } from '../types/index.js';
2
- import type { RenderBackendValue } from '../enums/index.js';
2
+ import type { RenderBackendValue, VoxelManagerEnum } from '../enums/index.js';
3
3
  interface Cornerstone3DConfig {
4
4
  isMobile?: boolean;
5
5
  rendering?: {
@@ -21,6 +21,9 @@ interface Cornerstone3DConfig {
21
21
  };
22
22
  useGenericViewport?: boolean;
23
23
  };
24
+ segmentation?: {
25
+ labelmapVoxelRepresentation?: VoxelManagerEnum | `${VoxelManagerEnum}`;
26
+ };
24
27
  debug: {
25
28
  statsOverlay?: boolean;
26
29
  };
@@ -21,10 +21,10 @@ export default class RLEVoxelMap<T> {
21
21
  protected kMultiple: number;
22
22
  protected numComps: number;
23
23
  defaultValue: T;
24
- pixelDataConstructor: Uint8ArrayConstructor;
24
+ pixelDataConstructor?: typeof Uint8Array;
25
25
  static copyMap<T>(destination: RLEVoxelMap<T>, source: RLEVoxelMap<T>): void;
26
26
  constructor(width: number, height: number, depth?: number);
27
- static getScalarData: (ArrayType?: Uint8ClampedArrayConstructor) => Uint8ClampedArray;
27
+ static getScalarData: (ArrayType?: any) => any;
28
28
  updateScalarData: (scalarData: PixelDataTypedArray) => void;
29
29
  get: (index: number) => T;
30
30
  toIJK(index: number): Point3;
@@ -33,9 +33,8 @@ class RLEVoxelMap {
33
33
  this.jMultiple = 1;
34
34
  this.kMultiple = 1;
35
35
  this.numComps = 1;
36
- this.pixelDataConstructor = Uint8Array;
37
36
  this.updateScalarData = function (scalarData) {
38
- scalarData.fill(0);
37
+ scalarData.fill((this.defaultValue ?? 0));
39
38
  const callback = (index, rle, row) => {
40
39
  const { start, end, value } = rle;
41
40
  for (let i = start; i < end; i++) {
@@ -234,11 +233,16 @@ class RLEVoxelMap {
234
233
  return [...this.rows.keys()];
235
234
  }
236
235
  getPixelData(k = 0, pixelData) {
236
+ const unwritten = (this.defaultValue ?? 0);
237
237
  if (!pixelData) {
238
- pixelData = new this.pixelDataConstructor(this.width * this.height * this.numComps);
238
+ const Constructor = this.pixelDataConstructor ?? Uint8Array;
239
+ pixelData = new Constructor(this.width * this.height * this.numComps);
240
+ if (unwritten !== 0) {
241
+ pixelData.fill(unwritten);
242
+ }
239
243
  }
240
244
  else {
241
- pixelData.fill(0);
245
+ pixelData.fill(unwritten);
242
246
  }
243
247
  const { width, height, numComps } = this;
244
248
  for (let j = 0; j < height; j++) {
@@ -369,8 +373,10 @@ class RLEVoxelMap {
369
373
  return adjacents;
370
374
  }
371
375
  }
372
- RLEVoxelMap.getScalarData = function (ArrayType = Uint8ClampedArray) {
373
- const scalarData = new ArrayType(this.frameSize);
376
+ RLEVoxelMap.getScalarData = function (ArrayType) {
377
+ const Constructor = ArrayType ?? this.map?.pixelDataConstructor ?? Uint8ClampedArray;
378
+ const depth = this.map?.depth || 1;
379
+ const scalarData = new Constructor(this.frameSize * depth);
374
380
  this.map.updateScalarData(scalarData);
375
381
  return scalarData;
376
382
  };
@@ -1,6 +1,7 @@
1
1
  import { InterpolationType } from '../enums/index.js';
2
2
  import type { BoundsIJK, Mat3, Point3, PixelDataTypedArray, IImage, RGB, CPUImageData, IVoxelManager, IRLEVoxelMap, Point2 } from '../types/index.js';
3
3
  import type vtkImageData from '@kitware/vtk.js/Common/DataModel/ImageData';
4
+ export declare const DEFAULT_RLE_SIZE: number;
4
5
  type VoxelVolumeGeometry = {
5
6
  origin: Point3;
6
7
  spacing: Point3;
@@ -80,6 +81,8 @@ export default class VoxelManager<T> {
80
81
  rleForEach(callback: any, options?: any): void;
81
82
  getScalarData(storeScalarData?: boolean): PixelDataTypedArray;
82
83
  setScalarData(newScalarData: PixelDataTypedArray): void;
84
+ getWritableScalarData(): PixelDataTypedArray | undefined;
85
+ setFromScalarData(scalarData: ArrayLike<number>): void;
83
86
  getScalarDataLength(): number;
84
87
  get sizeInBytes(): number;
85
88
  get bytePerVoxel(): number;
@@ -146,13 +149,17 @@ export default class VoxelManager<T> {
146
149
  planeFactory: (width: number, height: number) => T;
147
150
  id?: string;
148
151
  }): VoxelManager<T>;
149
- static createRLEVolumeVoxelManager<T>({ dimensions, id, }: {
152
+ static createRLEVolumeVoxelManager<T>({ dimensions, id, pixelDataConstructor, defaultValue, }: {
150
153
  dimensions: Point3;
151
154
  id?: string;
155
+ pixelDataConstructor?: new (length: number) => PixelDataTypedArray;
156
+ defaultValue?: T;
152
157
  }): VoxelManager<T>;
153
- static createRLEImageVoxelManager<T>({ dimensions, id, }: {
158
+ static createRLEImageVoxelManager<T>({ dimensions, id, pixelDataConstructor, defaultValue, }: {
154
159
  dimensions: Point2;
155
160
  id?: string;
161
+ pixelDataConstructor?: new (length: number) => PixelDataTypedArray;
162
+ defaultValue?: T;
156
163
  }): VoxelManager<T>;
157
164
  static addInstanceToImage(image: IImage): void;
158
165
  static: any;
@@ -6,7 +6,7 @@ import isEqual from './isEqual.js';
6
6
  import { iterateOverPointsInShapeVoxelManager } from './pointInShapeCallback.js';
7
7
  import { coreLog } from './logger.js';
8
8
  const log = coreLog.getLogger('utilities', 'VoxelManager');
9
- const DEFAULT_RLE_SIZE = 5 * 1024;
9
+ export const DEFAULT_RLE_SIZE = 5 * 1024;
10
10
  const worldToIndexDeltaScratch = [0, 0, 0];
11
11
  const worldToIndexResultScratch = [0, 0, 0];
12
12
  const worldToIndexTransformCache = new WeakMap();
@@ -247,7 +247,6 @@ export default class VoxelManager {
247
247
  log.warn('No map found, you need to use a map voxel manager to use rleForEach');
248
248
  return;
249
249
  }
250
- map.defaultValue = undefined;
251
250
  for (let k = boundsIJK[2][0]; k <= boundsIJK[2][1]; k++) {
252
251
  for (let j = boundsIJK[1][0]; j <= boundsIJK[1][1]; j++) {
253
252
  const row = map.getRun(j, k);
@@ -291,6 +290,30 @@ export default class VoxelManager {
291
290
  this.scalarData = newScalarData;
292
291
  this._scalarDataIsCachedExpansion = false;
293
292
  }
293
+ getWritableScalarData() {
294
+ return this._scalarDataIsCachedExpansion
295
+ ? undefined
296
+ : (this.scalarData ?? undefined);
297
+ }
298
+ setFromScalarData(scalarData) {
299
+ const map = this.map;
300
+ if (map instanceof RLEVoxelMap) {
301
+ const [width, height, depth] = this.dimensions;
302
+ const sparseValue = (map.defaultValue ?? 0);
303
+ map.clear();
304
+ map.fillFrom((i, j, k) => {
305
+ const value = scalarData[i + j * width + k * this.frameSize];
306
+ return (value === sparseValue ? undefined : value);
307
+ }, [
308
+ [0, width - 1],
309
+ [0, height - 1],
310
+ [0, (depth ?? 1) - 1],
311
+ ]);
312
+ this.invalidateCachedScalarExpansion();
313
+ return;
314
+ }
315
+ this.getScalarData().set(scalarData);
316
+ }
294
317
  getScalarDataLength() {
295
318
  if (this.scalarData) {
296
319
  return this.scalarData.length;
@@ -298,6 +321,10 @@ export default class VoxelManager {
298
321
  if (this._getScalarDataLength) {
299
322
  return this._getScalarDataLength();
300
323
  }
324
+ const [width, height, depth] = this.dimensions ?? [];
325
+ if (width && height) {
326
+ return width * height * (depth || 1) * this.numberOfComponents;
327
+ }
301
328
  throw new Error('No scalar data available');
302
329
  }
303
330
  get sizeInBytes() {
@@ -307,6 +334,16 @@ export default class VoxelManager {
307
334
  if (this.scalarData) {
308
335
  return this.scalarData.BYTES_PER_ELEMENT;
309
336
  }
337
+ const Constructor = this._getConstructor?.();
338
+ if (Constructor?.BYTES_PER_ELEMENT) {
339
+ return Constructor.BYTES_PER_ELEMENT;
340
+ }
341
+ if (this.map instanceof RLEVoxelMap) {
342
+ const ExpansionConstructor = this.map.pixelDataConstructor
343
+ ? this.map.pixelDataConstructor
344
+ : Uint8ClampedArray;
345
+ return ExpansionConstructor.BYTES_PER_ELEMENT;
346
+ }
310
347
  const value = this._get(0);
311
348
  return value.BYTES_PER_ELEMENT;
312
349
  }
@@ -966,9 +1003,16 @@ export default class VoxelManager {
966
1003
  voxelManager.map = map;
967
1004
  return voxelManager;
968
1005
  }
969
- static createRLEVolumeVoxelManager({ dimensions, id, }) {
1006
+ static createRLEVolumeVoxelManager({ dimensions, id, pixelDataConstructor, defaultValue, }) {
970
1007
  const [width, height, depth] = dimensions;
971
1008
  const map = new RLEVoxelMap(width, height, depth);
1009
+ if (pixelDataConstructor) {
1010
+ map.pixelDataConstructor =
1011
+ pixelDataConstructor;
1012
+ }
1013
+ if (defaultValue !== undefined) {
1014
+ map.defaultValue = defaultValue;
1015
+ }
972
1016
  const voxelManager = new VoxelManager(dimensions, {
973
1017
  _get: (index) => map.get(index),
974
1018
  _set: (index, v) => {
@@ -976,6 +1020,9 @@ export default class VoxelManager {
976
1020
  return true;
977
1021
  },
978
1022
  _getScalarData: RLEVoxelMap.getScalarData,
1023
+ _getConstructor: pixelDataConstructor
1024
+ ? () => map.pixelDataConstructor
1025
+ : undefined,
979
1026
  _updateScalarData: (scalarData) => {
980
1027
  map.updateScalarData(scalarData);
981
1028
  return scalarData;
@@ -986,11 +1033,13 @@ export default class VoxelManager {
986
1033
  voxelManager.getPixelData = map.getPixelData.bind(map);
987
1034
  return voxelManager;
988
1035
  }
989
- static createRLEImageVoxelManager({ dimensions, id, }) {
1036
+ static createRLEImageVoxelManager({ dimensions, id, pixelDataConstructor, defaultValue, }) {
990
1037
  const [width, height] = dimensions;
991
1038
  return VoxelManager.createRLEVolumeVoxelManager({
992
1039
  dimensions: [width, height, 1],
993
1040
  id,
1041
+ pixelDataConstructor,
1042
+ defaultValue,
994
1043
  });
995
1044
  }
996
1045
  static addInstanceToImage(image) {
@@ -1 +1 @@
1
- export declare const version = "5.10.2";
1
+ export declare const version = "5.10.4";
@@ -1 +1 @@
1
- export const version = '5.10.2';
1
+ export const version = '5.10.4';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cornerstonejs/core",
3
- "version": "5.10.2",
3
+ "version": "5.10.4",
4
4
  "description": "Cornerstone3D Core",
5
5
  "module": "./dist/esm/index.js",
6
6
  "types": "./dist/esm/index.d.ts",
@@ -85,18 +85,18 @@
85
85
  "prepublishOnly": "pnpm run build"
86
86
  },
87
87
  "dependencies": {
88
- "@cornerstonejs/utils": "5.10.2",
88
+ "@cornerstonejs/utils": "5.10.4",
89
89
  "@kitware/vtk.js": "36.4.1",
90
90
  "comlink": "4.4.2",
91
91
  "gl-matrix": "3.4.3",
92
92
  "loglevel": "1.9.2"
93
93
  },
94
94
  "devDependencies": {
95
- "@cornerstonejs/metadata": "5.10.2"
95
+ "@cornerstonejs/metadata": "5.10.4"
96
96
  },
97
97
  "peerDependencies": {
98
- "@cornerstonejs/metadata": "5.10.2",
99
- "@cornerstonejs/utils": "5.10.2"
98
+ "@cornerstonejs/metadata": "5.10.4",
99
+ "@cornerstonejs/utils": "5.10.4"
100
100
  },
101
101
  "contributors": [
102
102
  {