@cornerstonejs/tools 1.15.0 → 1.16.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.
Files changed (33) hide show
  1. package/dist/cjs/tools/displayTools/Labelmap/labelmapDisplay.js.map +1 -1
  2. package/dist/cjs/tools/displayTools/SegmentationDisplayTool.js +5 -6
  3. package/dist/cjs/tools/displayTools/SegmentationDisplayTool.js.map +1 -1
  4. package/dist/cjs/types/CINETypes.d.ts +2 -0
  5. package/dist/cjs/utilities/cine/playClip.js +11 -2
  6. package/dist/cjs/utilities/cine/playClip.js.map +1 -1
  7. package/dist/cjs/utilities/segmentation/brushSizeForToolGroup.d.ts +2 -2
  8. package/dist/cjs/utilities/segmentation/brushSizeForToolGroup.js +4 -4
  9. package/dist/cjs/utilities/segmentation/brushSizeForToolGroup.js.map +1 -1
  10. package/dist/cjs/utilities/segmentation/utilities.d.ts +1 -2
  11. package/dist/cjs/utilities/segmentation/utilities.js +4 -1
  12. package/dist/cjs/utilities/segmentation/utilities.js.map +1 -1
  13. package/dist/esm/tools/displayTools/Labelmap/labelmapDisplay.js.map +1 -1
  14. package/dist/esm/tools/displayTools/SegmentationDisplayTool.js +5 -6
  15. package/dist/esm/tools/displayTools/SegmentationDisplayTool.js.map +1 -1
  16. package/dist/esm/types/CINETypes.d.ts +2 -0
  17. package/dist/esm/utilities/cine/playClip.js +11 -3
  18. package/dist/esm/utilities/cine/playClip.js.map +1 -1
  19. package/dist/esm/utilities/segmentation/brushSizeForToolGroup.d.ts +2 -2
  20. package/dist/esm/utilities/segmentation/brushSizeForToolGroup.js +4 -4
  21. package/dist/esm/utilities/segmentation/brushSizeForToolGroup.js.map +1 -1
  22. package/dist/esm/utilities/segmentation/utilities.d.ts +1 -2
  23. package/dist/esm/utilities/segmentation/utilities.js +4 -1
  24. package/dist/esm/utilities/segmentation/utilities.js.map +1 -1
  25. package/dist/umd/index.js +1 -1
  26. package/dist/umd/index.js.map +1 -1
  27. package/package.json +3 -3
  28. package/src/tools/displayTools/Labelmap/labelmapDisplay.ts +3 -0
  29. package/src/tools/displayTools/SegmentationDisplayTool.ts +12 -18
  30. package/src/types/CINETypes.ts +8 -2
  31. package/src/utilities/cine/playClip.ts +17 -2
  32. package/src/utilities/segmentation/brushSizeForToolGroup.ts +22 -4
  33. package/src/utilities/segmentation/utilities.ts +8 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cornerstonejs/tools",
3
- "version": "1.15.0",
3
+ "version": "1.16.0",
4
4
  "description": "Cornerstone3D Tools",
5
5
  "main": "dist/umd/index.js",
6
6
  "types": "dist/esm/index.d.ts",
@@ -29,7 +29,7 @@
29
29
  "webpack:watch": "webpack --mode development --progress --watch --config ./.webpack/webpack.dev.js"
30
30
  },
31
31
  "dependencies": {
32
- "@cornerstonejs/core": "^1.15.0",
32
+ "@cornerstonejs/core": "^1.16.0",
33
33
  "lodash.clonedeep": "4.5.0",
34
34
  "lodash.get": "^4.4.2"
35
35
  },
@@ -52,5 +52,5 @@
52
52
  "type": "individual",
53
53
  "url": "https://ohif.org/donate"
54
54
  },
55
- "gitHead": "d4478aa1242c48e10c95ef6dd511f2497e19b5e8"
55
+ "gitHead": "e36741ef4ad046104fc63c1169073b48cbef8856"
56
56
  }
@@ -276,6 +276,9 @@ function _setLabelmapColorAndOpacity(
276
276
  isActiveLabelmap
277
277
  );
278
278
 
279
+ // Todo: the below loop probably can be optimized so that we don't hit it
280
+ // unless a config has changed. Right now we get into the following loop
281
+ // even for brush drawing which does not makes sense
279
282
  for (let i = 0; i < numColors; i++) {
280
283
  const segmentIndex = i;
281
284
  const segmentColor = colorLUT[segmentIndex];
@@ -143,26 +143,20 @@ class SegmentationDisplayTool extends BaseTool {
143
143
  const config = this._getMergedRepresentationsConfig(toolGroupId);
144
144
 
145
145
  const viewportsRenderList = [];
146
+ const display =
147
+ representation.type === Representations.Labelmap
148
+ ? labelmapDisplay
149
+ : contourDisplay;
150
+
146
151
  for (const viewport of toolGroupViewports) {
147
- if (representation.type == Representations.Labelmap) {
148
- viewportsRenderList.push(
149
- labelmapDisplay.render(
150
- viewport as Types.IVolumeViewport,
151
- representation,
152
- config
153
- )
154
- );
155
- } else if (representation.type == Representations.Contour) {
156
- viewportsRenderList.push(
157
- contourDisplay.render(
158
- viewport as Types.IVolumeViewport,
159
- representation,
160
- config
161
- )
162
- );
163
- }
164
- }
152
+ const renderedViewport = display.render(
153
+ viewport as Types.IVolumeViewport,
154
+ representation,
155
+ config
156
+ );
165
157
 
158
+ viewportsRenderList.push(renderedViewport);
159
+ }
166
160
  return viewportsRenderList;
167
161
  }
168
162
  );
@@ -1,5 +1,3 @@
1
- import { Types } from '@cornerstonejs/core';
2
-
3
1
  type PlayClipOptions = {
4
2
  framesPerSecond?: number;
5
3
  frameTimeVector?: number[];
@@ -7,6 +5,11 @@ type PlayClipOptions = {
7
5
  loop?: boolean;
8
6
  dynamicCineEnabled?: boolean;
9
7
  frameTimeVectorSpeedMultiplier?: number;
8
+ // How many CINE frames to wait for a rendered event to occur before
9
+ // trying to display the image after the next one
10
+ // A CINE frame is attempted every 1 / fps seconds
11
+ // The default is 30 tries, or 1.25 seconds at 24 fps
12
+ waitForRendered?: number;
10
13
  };
11
14
 
12
15
  interface ToolData {
@@ -26,6 +29,9 @@ type CinePlayContext = {
26
29
  get numScrollSteps(): number;
27
30
  get currentStepIndex(): number;
28
31
  get frameTimeVectorEnabled(): boolean;
32
+ // How many times has the wait for rendered been tried without showing
33
+ // the next image.
34
+ waitForRenderedCount?: number;
29
35
  scroll(delta: number): void;
30
36
  };
31
37
 
@@ -6,6 +6,7 @@ import {
6
6
  VolumeViewport,
7
7
  cache,
8
8
  BaseVolumeViewport,
9
+ Enums,
9
10
  } from '@cornerstonejs/core';
10
11
 
11
12
  import { Types } from '@cornerstonejs/core';
@@ -14,6 +15,7 @@ import { addToolState, getToolState } from './state';
14
15
  import { CINETypes } from '../../types';
15
16
  import scroll from '../scroll';
16
17
 
18
+ const { ViewportStatus } = Enums;
17
19
  const { triggerEvent } = csUtils;
18
20
 
19
21
  const debounced = true;
@@ -315,7 +317,8 @@ function _getVolumeFromViewport(viewport): Types.IImageVolume {
315
317
  }
316
318
 
317
319
  function _createStackViewportCinePlayContext(
318
- viewport: StackViewport
320
+ viewport: StackViewport,
321
+ waitForRendered: number
319
322
  ): CINETypes.CinePlayContext {
320
323
  const imageIds = viewport.getImageIds();
321
324
 
@@ -330,7 +333,16 @@ function _createStackViewportCinePlayContext(
330
333
  // It is always in acquired orientation
331
334
  return true;
332
335
  },
336
+ waitForRenderedCount: 0,
333
337
  scroll(delta: number): void {
338
+ if (
339
+ this.waitForRenderedCount <= waitForRendered &&
340
+ viewport.viewportStatus !== ViewportStatus.RENDERED
341
+ ) {
342
+ this.waitForRenderedCount++;
343
+ return;
344
+ }
345
+ this.waitForRenderedCount = 0;
334
346
  scroll(viewport, { delta, debounceLoading: debounced });
335
347
  },
336
348
  };
@@ -419,7 +431,10 @@ function _createCinePlayContext(
419
431
  playClipOptions: CINETypes.PlayClipOptions
420
432
  ): CINETypes.CinePlayContext {
421
433
  if (viewport instanceof StackViewport) {
422
- return _createStackViewportCinePlayContext(viewport);
434
+ return _createStackViewportCinePlayContext(
435
+ viewport,
436
+ playClipOptions.waitForRendered ?? 30
437
+ );
423
438
  }
424
439
 
425
440
  if (viewport instanceof VolumeViewport) {
@@ -4,9 +4,17 @@ import triggerAnnotationRenderForViewportIds from '../triggerAnnotationRenderFor
4
4
  import { getRenderingEngine } from '@cornerstonejs/core';
5
5
  import getBrushToolInstances from './utilities';
6
6
 
7
+ /**
8
+ * Sets the brush size for all brush-based tools in a given tool group.
9
+ * @param toolGroupId - The ID of the tool group to set the brush size for.
10
+ * @param brushSize - The new brush size to set.
11
+ * @param toolName - The name of the specific tool to set the brush size for (optional)
12
+ * If not provided, all brush-based tools in the tool group will be affected.
13
+ */
7
14
  export function setBrushSizeForToolGroup(
8
15
  toolGroupId: string,
9
- brushSize: number
16
+ brushSize: number,
17
+ toolName?: string
10
18
  ): void {
11
19
  const toolGroup = getToolGroup(toolGroupId);
12
20
 
@@ -14,7 +22,7 @@ export function setBrushSizeForToolGroup(
14
22
  return;
15
23
  }
16
24
 
17
- const brushBasedToolInstances = getBrushToolInstances(toolGroupId);
25
+ const brushBasedToolInstances = getBrushToolInstances(toolGroupId, toolName);
18
26
 
19
27
  brushBasedToolInstances.forEach((tool: BrushTool) => {
20
28
  tool.configuration.brushSize = brushSize;
@@ -45,7 +53,17 @@ export function setBrushSizeForToolGroup(
45
53
  triggerAnnotationRenderForViewportIds(renderingEngine, viewportIds);
46
54
  }
47
55
 
48
- export function getBrushSizeForToolGroup(toolGroupId: string): void {
56
+ /**
57
+ * Gets the brush size for the first brush-based tool instance in a given tool group.
58
+ * @param toolGroupId - The ID of the tool group to get the brush size for.
59
+ * @param toolName - The name of the specific tool to get the brush size for (Optional)
60
+ * If not provided, the first brush-based tool instance in the tool group will be used.
61
+ * @returns The brush size of the selected tool instance, or undefined if no brush-based tool instance is found.
62
+ */
63
+ export function getBrushSizeForToolGroup(
64
+ toolGroupId: string,
65
+ toolName?: string
66
+ ): void {
49
67
  const toolGroup = getToolGroup(toolGroupId);
50
68
 
51
69
  if (toolGroup === undefined) {
@@ -58,7 +76,7 @@ export function getBrushSizeForToolGroup(toolGroupId: string): void {
58
76
  return;
59
77
  }
60
78
 
61
- const brushBasedToolInstances = getBrushToolInstances(toolGroupId);
79
+ const brushBasedToolInstances = getBrushToolInstances(toolGroupId, toolName);
62
80
 
63
81
  // one is enough as they share the same brush size
64
82
  const brushToolInstance = brushBasedToolInstances[0];
@@ -10,7 +10,10 @@ export type ThresholdInformation = {
10
10
  upper: number;
11
11
  };
12
12
 
13
- export default function getBrushToolInstances(toolGroupId) {
13
+ export default function getBrushToolInstances(
14
+ toolGroupId: string,
15
+ toolName?: string
16
+ ) {
14
17
  const toolGroup = getToolGroup(toolGroupId);
15
18
 
16
19
  if (toolGroup === undefined) {
@@ -23,6 +26,10 @@ export default function getBrushToolInstances(toolGroupId) {
23
26
  return;
24
27
  }
25
28
 
29
+ if (toolName && toolInstances[toolName]) {
30
+ return [toolInstances[toolName]];
31
+ }
32
+
26
33
  // For each tool that has BrushTool as base class, set the brush size.
27
34
  const brushBasedToolInstances = Object.values(toolInstances).filter(
28
35
  (toolInstance) => toolInstance instanceof BrushTool