@cornerstonejs/core 1.2.0 → 1.2.2

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": "1.2.0",
3
+ "version": "1.2.2",
4
4
  "description": "",
5
5
  "main": "dist/umd/index.js",
6
6
  "types": "dist/esm/index.d.ts",
@@ -44,5 +44,5 @@
44
44
  "type": "individual",
45
45
  "url": "https://ohif.org/donate"
46
46
  },
47
- "gitHead": "d70e58f4be761fe9d35ece1956bec78073a80e45"
47
+ "gitHead": "bb726d9517425ba7be1f7d9d3b7de379d324ba55"
48
48
  }
@@ -244,9 +244,9 @@ abstract class BaseVolumeViewport extends Viewport implements IVolumeViewport {
244
244
  mapper.setSampleDistance(1.0);
245
245
 
246
246
  const cfun = vtkColorTransferFunction.newInstance();
247
- let colormapObj = colormapUtils.getColormap(colormap);
247
+ let colormapObj = colormapUtils.getColormap(colormap.name);
248
248
 
249
- const { name, opacityMapping } = colormap;
249
+ const { name } = colormap;
250
250
 
251
251
  if (!colormapObj) {
252
252
  colormapObj = vtkColorMaps.getPresetByName(name);
@@ -264,20 +264,37 @@ abstract class BaseVolumeViewport extends Viewport implements IVolumeViewport {
264
264
  cfun.applyColorMap(colormapObj);
265
265
  cfun.setMappingRange(range[0], range[1]);
266
266
  volumeActor.getProperty().setRGBTransferFunction(0, cfun);
267
+ }
267
268
 
268
- const ofun = vtkPiecewiseFunction.newInstance();
269
- ofun.addPoint(range[0], 0.0);
270
- ofun.addPoint(range[1], 1.0);
271
- volumeActor.getProperty().setScalarOpacity(0, ofun);
272
-
273
- if (!opacityMapping) {
269
+ /**
270
+ * Sets the opacity for the volume with the given ID.
271
+ *
272
+ * @param colormap - An object containing opacity that can be a number or an array of OpacityMapping
273
+ * @param volumeId - The ID of the volume to set the opacity for.
274
+ *
275
+ * @returns void
276
+ */
277
+ private setOpacity(colormap: ColormapPublic, volumeId: string) {
278
+ const applicableVolumeActorInfo = this._getApplicableVolumeActor(volumeId);
279
+ if (!applicableVolumeActorInfo) {
274
280
  return;
275
281
  }
282
+ const { volumeActor } = applicableVolumeActorInfo;
283
+ const ofun = vtkPiecewiseFunction.newInstance();
284
+ if (typeof colormap.opacity === 'number') {
285
+ const range = volumeActor
286
+ .getProperty()
287
+ .getRGBTransferFunction(0)
288
+ .getRange();
276
289
 
277
- // add custom opacity points
278
- opacityMapping.forEach(({ opacity, value }) => {
279
- ofun.addPoint(value, opacity);
280
- });
290
+ ofun.addPoint(range[0], colormap.opacity);
291
+ ofun.addPoint(range[1], colormap.opacity);
292
+ } else {
293
+ colormap.opacity.forEach(({ opacity, value }) => {
294
+ ofun.addPoint(value, opacity);
295
+ });
296
+ }
297
+ volumeActor.getProperty().setScalarOpacity(0, ofun);
281
298
  }
282
299
 
283
300
  /**
@@ -435,9 +452,13 @@ abstract class BaseVolumeViewport extends Viewport implements IVolumeViewport {
435
452
  ): void {
436
453
  // Note: colormap should always be done first, since we can then
437
454
  // modify the voiRange
438
- if (colormap !== undefined) {
455
+
456
+ if (colormap?.name) {
439
457
  this.setColormap(colormap, volumeId, suppressEvents);
440
458
  }
459
+ if (colormap?.opacity != null) {
460
+ this.setOpacity(colormap, volumeId);
461
+ }
441
462
 
442
463
  if (voiRange !== undefined) {
443
464
  this.setVOI(voiRange, volumeId, suppressEvents);
@@ -500,8 +521,7 @@ abstract class BaseVolumeViewport extends Viewport implements IVolumeViewport {
500
521
  const [lower, upper] =
501
522
  this.VOILUTFunction === 'SIGMOID'
502
523
  ? getVoiFromSigmoidRGBTransferFunction(cfun)
503
- : // @ts-ignore
504
- cfun.getRange();
524
+ : cfun.getRange();
505
525
  return { volumeId, voiRange: { lower, upper } };
506
526
  })
507
527
  .filter(Boolean);
@@ -599,7 +619,6 @@ abstract class BaseVolumeViewport extends Viewport implements IVolumeViewport {
599
619
  `imageVolume with id: ${firstImageVolume.volumeId} does not exist`
600
620
  );
601
621
  }
602
-
603
622
  const volumeActors = [];
604
623
 
605
624
  await this._isValidVolumeInputArray(
@@ -15,7 +15,8 @@ type OpacityMapping = {
15
15
 
16
16
  type ColormapPublic = {
17
17
  /** name of the colormap */
18
- name: string;
18
+ name?: string;
19
+ opacity?: OpacityMapping[] | number;
19
20
  /** midpoint mapping between values to opacity if the colormap
20
21
  * is getting used for fusion, this is an array of arrays which
21
22
  * each array containing 2 values, the first value is the value
@@ -25,7 +26,6 @@ type ColormapPublic = {
25
26
  * the points in the middle to be mapped to different opacities
26
27
  * instead of a linear mapping from 0 to 1.
27
28
  */
28
- opacityMapping?: OpacityMapping[];
29
29
  };
30
30
 
31
- export type { ColormapRegistration, ColormapPublic };
31
+ export type { ColormapRegistration, ColormapPublic, OpacityMapping };