@cornerstonejs/tools 5.4.1 → 5.4.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.
@@ -11,6 +11,7 @@ import { getSegmentBinding } from '../../../stateManagement/segmentation/helpers
11
11
  import { segmentationStyle } from '../../../stateManagement/segmentation/SegmentationStyle.js';
12
12
  import { getLabelmapForActorReference } from './volumeLabelmapImageMapper.js';
13
13
  const actorTransferFunctions = new WeakMap();
14
+ const lastAppliedLabelmapStyle = new WeakMap();
14
15
  const MAX_NUMBER_COLORS = 255;
15
16
  function setLabelmapColorAndOpacity(viewportId, labelmapActorEntry, segmentationRepresentation) {
16
17
  const { segmentationId } = segmentationRepresentation;
@@ -49,9 +50,6 @@ function setLabelmapColorAndOpacity(viewportId, labelmapActorEntry, segmentation
49
50
  type: SegmentationRepresentations.Labelmap,
50
51
  });
51
52
  const labelmapActor = labelmapActorEntry.actor;
52
- const { cfun, ofun } = getOrCreateTransferFunctions(labelmapActor);
53
- cfun.removeAllPoints();
54
- ofun.removeAllPoints();
55
53
  const colorNodes = [
56
54
  { x: 0, r: 0, g: 0, b: 0, midpoint: 0.5, sharpness: 1.0 },
57
55
  ];
@@ -96,6 +94,41 @@ function setLabelmapColorAndOpacity(viewportId, labelmapActorEntry, segmentation
96
94
  });
97
95
  }
98
96
  });
97
+ const activeSegmentIndex = getActiveSegmentIndex(segmentationRepresentation.segmentationId);
98
+ const outlineWidths = new Array(numColors - 1).fill(0);
99
+ if (renderOutline) {
100
+ labelValueEntries.forEach(({ labelValue, segmentIndex }) => {
101
+ if (segmentsHidden.has(segmentIndex)) {
102
+ return;
103
+ }
104
+ outlineWidths[labelValue - 1] =
105
+ segmentIndex === activeSegmentIndex
106
+ ? outlineWidth + activeSegmentOutlineWidthDelta
107
+ : outlineWidth;
108
+ });
109
+ }
110
+ const visible = isActiveLabelmap || renderInactiveSegmentations;
111
+ const useImageSliceProperties = labelmapActorEntry.actorMapper?.renderMode === ActorRenderMode.VTK_IMAGE ||
112
+ labelmapActorEntry.actorMapper?.renderMode ===
113
+ ActorRenderMode.VTK_VOLUME_SLICE;
114
+ const { preLoad } = labelmapActor.get?.('preLoad') || { preLoad: null };
115
+ const styleSignature = JSON.stringify({
116
+ colorNodes,
117
+ opacityNodes,
118
+ renderOutline,
119
+ outlineOpacity,
120
+ outlineWidths,
121
+ visible,
122
+ useImageSliceProperties,
123
+ });
124
+ const canUseStyleCache = !preLoad;
125
+ if (canUseStyleCache &&
126
+ lastAppliedLabelmapStyle.get(labelmapActor) === styleSignature) {
127
+ return;
128
+ }
129
+ const { cfun, ofun } = getOrCreateTransferFunctions(labelmapActor);
130
+ cfun.removeAllPoints();
131
+ ofun.removeAllPoints();
99
132
  cfun.setNodes(colorNodes);
100
133
  ofun.setNodes(opacityNodes);
101
134
  ofun.setClamping(false);
@@ -103,7 +136,6 @@ function setLabelmapColorAndOpacity(viewportId, labelmapActorEntry, segmentation
103
136
  const labelmapMapper = actorMapper?.mapper
104
137
  ? actorMapper.mapper
105
138
  : labelmapActor.getMapper();
106
- const { preLoad } = labelmapActor.get?.('preLoad') || { preLoad: null };
107
139
  if (preLoad) {
108
140
  preLoad({ cfun, ofun, actor: labelmapActor });
109
141
  }
@@ -112,9 +144,7 @@ function setLabelmapColorAndOpacity(viewportId, labelmapActorEntry, segmentation
112
144
  labelmapActor.getProperty().setScalarOpacity(0, ofun);
113
145
  labelmapActor.getProperty().setInterpolationTypeToNearest();
114
146
  }
115
- if (labelmapActorEntry.actorMapper?.renderMode === ActorRenderMode.VTK_IMAGE ||
116
- labelmapActorEntry.actorMapper?.renderMode ===
117
- ActorRenderMode.VTK_VOLUME_SLICE) {
147
+ if (useImageSliceProperties) {
118
148
  const imageSlice = labelmapActor;
119
149
  imageSlice.setForceTranslucent(true);
120
150
  imageSlice.setForceOpaque(false);
@@ -123,33 +153,24 @@ function setLabelmapColorAndOpacity(viewportId, labelmapActorEntry, segmentation
123
153
  if (renderOutline) {
124
154
  labelmapActor.getProperty().setUseLabelOutline(renderOutline);
125
155
  labelmapActor.getProperty().setLabelOutlineOpacity(outlineOpacity);
126
- const activeSegmentIndex = getActiveSegmentIndex(segmentationRepresentation.segmentationId);
127
- const outlineWidths = new Array(numColors - 1).fill(0);
128
- labelValueEntries.forEach(({ labelValue, segmentIndex }) => {
129
- const isHidden = segmentsHidden.has(segmentIndex);
130
- if (isHidden) {
131
- return;
132
- }
133
- outlineWidths[labelValue - 1] =
134
- segmentIndex === activeSegmentIndex
135
- ? outlineWidth + activeSegmentOutlineWidthDelta
136
- : outlineWidth;
137
- });
138
156
  labelmapActor.getProperty().setLabelOutlineThickness(outlineWidths);
139
157
  labelmapActor.modified();
140
158
  labelmapActor.getProperty().modified();
141
159
  labelmapMapper?.modified?.();
142
160
  }
143
161
  else {
144
- labelmapActor
145
- .getProperty()
146
- .setLabelOutlineThickness(new Array(numColors - 1).fill(0));
162
+ labelmapActor.getProperty().setLabelOutlineThickness(outlineWidths);
147
163
  }
148
- const visible = isActiveLabelmap || renderInactiveSegmentations;
149
164
  labelmapActor.setVisibility(visible);
150
165
  labelmapActor.modified();
151
166
  labelmapActor.getProperty().modified();
152
167
  labelmapMapper?.modified?.();
168
+ if (canUseStyleCache) {
169
+ lastAppliedLabelmapStyle.set(labelmapActor, styleSignature);
170
+ }
171
+ else {
172
+ lastAppliedLabelmapStyle.delete(labelmapActor);
173
+ }
153
174
  }
154
175
  function getOrCreateTransferFunctions(actor) {
155
176
  const existing = actorTransferFunctions.get(actor);
@@ -141,14 +141,18 @@ class ColorbarCanvas {
141
141
  const range = this._showFullImageRange ? this._imageRange : { ...voiRange };
142
142
  let previousColorPoint = undefined;
143
143
  let currentColorPoint = getColorPoint(0);
144
+ const minPosition = rgbPoints[0];
145
+ const maxPosition = rgbPoints[rgbPoints.length - 4];
146
+ const colormapRange = maxPosition - minPosition;
144
147
  const incRawPixelValue = (range.upper - range.lower) / (maxValue - 1);
145
148
  let rawPixelValue = range.lower;
146
149
  for (let i = 0; i < maxValue; i++) {
147
150
  const tVoiRange = (rawPixelValue - voiRange.lower) /
148
151
  Math.abs(voiRange.upper - voiRange.lower);
152
+ const tColormapPosition = minPosition + tVoiRange * colormapRange;
149
153
  if (currentColorPoint) {
150
154
  for (let i = currentColorPoint.index; i < colorsCount; i++) {
151
- if (tVoiRange <= currentColorPoint.position) {
155
+ if (tColormapPosition <= currentColorPoint.position) {
152
156
  break;
153
157
  }
154
158
  previousColorPoint = currentColorPoint;
@@ -163,7 +167,7 @@ class ColorbarCanvas {
163
167
  normColor = [...previousColorPoint.color];
164
168
  }
165
169
  else {
166
- const tColorRange = (tVoiRange - previousColorPoint.position) /
170
+ const tColorRange = (tColormapPosition - previousColorPoint.position) /
167
171
  (currentColorPoint.position - previousColorPoint.position);
168
172
  normColor = interpolateVec3(previousColorPoint.color, currentColorPoint.color, tColorRange);
169
173
  }
@@ -1 +1 @@
1
- export declare const version = "5.4.1";
1
+ export declare const version = "5.4.2";
@@ -1 +1 @@
1
- export const version = '5.4.1';
1
+ export const version = '5.4.2';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cornerstonejs/tools",
3
- "version": "5.4.1",
3
+ "version": "5.4.2",
4
4
  "description": "Cornerstone3D Tools",
5
5
  "types": "./dist/esm/index.d.ts",
6
6
  "module": "./dist/esm/index.js",
@@ -126,11 +126,11 @@
126
126
  "lodash.get": "4.4.2"
127
127
  },
128
128
  "devDependencies": {
129
- "@cornerstonejs/core": "5.4.1",
129
+ "@cornerstonejs/core": "5.4.2",
130
130
  "canvas": "3.2.0"
131
131
  },
132
132
  "peerDependencies": {
133
- "@cornerstonejs/core": "5.4.1",
133
+ "@cornerstonejs/core": "5.4.2",
134
134
  "@kitware/vtk.js": "35.5.3",
135
135
  "@types/d3-array": "3.2.1",
136
136
  "@types/d3-interpolate": "3.0.4",
@@ -149,5 +149,5 @@
149
149
  "type": "individual",
150
150
  "url": "https://ohif.org/donate"
151
151
  },
152
- "gitHead": "2a6a97cfa5353f69116de006aa59f5d6e5624511"
152
+ "gitHead": "34e073e17bd1da9dbee6f422100042fa90e4ddf7"
153
153
  }