@cornerstonejs/tools 4.8.4 → 4.9.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.
@@ -0,0 +1,3 @@
1
+ import type { SegmentationRemovedEventType } from '../../types/EventTypes';
2
+ declare const segmentationRemovedListener: (evt: SegmentationRemovedEventType) => void;
3
+ export default segmentationRemovedListener;
@@ -0,0 +1,11 @@
1
+ import { getAllAnnotations, removeAnnotation, } from '../../stateManagement/annotation/annotationState';
2
+ const segmentationRemovedListener = function (evt) {
3
+ const { segmentationId } = evt.detail;
4
+ const annotationsToRemove = getAllAnnotations().filter((annotation) => segmentationId ===
5
+ annotation?.data?.segmentation
6
+ ?.segmentationId);
7
+ annotationsToRemove.forEach((annotation) => {
8
+ removeAnnotation(annotation.annotationUID);
9
+ });
10
+ };
11
+ export default segmentationRemovedListener;
package/dist/esm/init.js CHANGED
@@ -9,6 +9,7 @@ import * as ToolGroupManager from './store/ToolGroupManager';
9
9
  import { defaultSegmentationStateManager } from './stateManagement/segmentation/SegmentationStateManager';
10
10
  import segmentationRepresentationModifiedListener from './eventListeners/segmentation/segmentationRepresentationModifiedListener';
11
11
  import { setConfig } from './config';
12
+ import segmentationRemovedListener from './eventListeners/segmentation/segmentationRemovedEventListener';
12
13
  let csToolsInitialized = false;
13
14
  export function init(defaultConfiguration = {}) {
14
15
  if (csToolsInitialized) {
@@ -56,15 +57,18 @@ function _addCornerstoneToolsEventListeners() {
56
57
  eventTarget.addEventListener(TOOLS_EVENTS.SEGMENTATION_DATA_MODIFIED, segmentationDataModifiedEventListener);
57
58
  eventTarget.addEventListener(TOOLS_EVENTS.SEGMENTATION_REPRESENTATION_MODIFIED, segmentationRepresentationModifiedListener);
58
59
  eventTarget.addEventListener(TOOLS_EVENTS.SEGMENTATION_REPRESENTATION_ADDED, segmentationRepresentationModifiedListener);
60
+ eventTarget.addEventListener(TOOLS_EVENTS.SEGMENTATION_REMOVED, segmentationRemovedListener);
59
61
  }
60
62
  function _removeCornerstoneToolsEventListeners() {
61
63
  eventTarget.removeEventListener(TOOLS_EVENTS.ANNOTATION_COMPLETED, annotationCompletedListener);
62
64
  eventTarget.removeEventListener(TOOLS_EVENTS.ANNOTATION_MODIFIED, annotationModifiedListener);
63
65
  eventTarget.removeEventListener(TOOLS_EVENTS.ANNOTATION_SELECTION_CHANGE, annotationSelectionListener);
64
66
  eventTarget.removeEventListener(TOOLS_EVENTS.ANNOTATION_SELECTION_CHANGE, annotationSelectionListener);
67
+ eventTarget.removeEventListener(TOOLS_EVENTS.ANNOTATION_REMOVED, annotationRemovedListener);
65
68
  eventTarget.removeEventListener(TOOLS_EVENTS.SEGMENTATION_MODIFIED, segmentationModifiedListener);
66
69
  eventTarget.removeEventListener(TOOLS_EVENTS.SEGMENTATION_DATA_MODIFIED, segmentationDataModifiedEventListener);
67
70
  eventTarget.removeEventListener(TOOLS_EVENTS.SEGMENTATION_REPRESENTATION_MODIFIED, segmentationRepresentationModifiedListener);
68
71
  eventTarget.removeEventListener(TOOLS_EVENTS.SEGMENTATION_REPRESENTATION_ADDED, segmentationRepresentationModifiedListener);
72
+ eventTarget.removeEventListener(TOOLS_EVENTS.SEGMENTATION_REMOVED, segmentationRemovedListener);
69
73
  }
70
74
  export default init;
@@ -259,13 +259,17 @@ class PlanarFreehandROITool extends ContourSegmentationBaseTool {
259
259
  if (!annotations || !annotations.length) {
260
260
  return;
261
261
  }
262
+ const baseFilteredAnnotations = super.filterInteractableAnnotationsForElement(element, annotations);
263
+ if (!baseFilteredAnnotations || !baseFilteredAnnotations.length) {
264
+ return;
265
+ }
262
266
  const enabledElement = getEnabledElement(element);
263
267
  const { viewport } = enabledElement;
264
268
  let annotationsToDisplay;
265
269
  if (viewport instanceof VolumeViewport) {
266
270
  const camera = viewport.getCamera();
267
271
  const { spacingInNormalDirection } = csUtils.getTargetVolumeAndSpacingInNormalDir(viewport, camera);
268
- annotationsToDisplay = this.filterAnnotationsWithinSlice(annotations, camera, spacingInNormalDirection);
272
+ annotationsToDisplay = this.filterAnnotationsWithinSlice(baseFilteredAnnotations, camera, spacingInNormalDirection);
269
273
  }
270
274
  else {
271
275
  annotationsToDisplay = filterAnnotationsForDisplay(viewport, annotations);
@@ -1,4 +1,4 @@
1
- import type { Annotation, EventTypes, PublicToolProps, ToolProps, AnnotationRenderContext } from '../../types';
1
+ import type { Annotation, EventTypes, PublicToolProps, ToolProps, AnnotationRenderContext, Annotations } from '../../types';
2
2
  import type { ContourAnnotation } from '../../types/ToolSpecificAnnotationTypes';
3
3
  import type { StyleSpecifier } from '../../types/AnnotationStyle';
4
4
  import ContourBaseTool from './ContourBaseTool';
@@ -15,6 +15,7 @@ declare abstract class ContourSegmentationBaseTool extends ContourBaseTool {
15
15
  styleSpecifier: StyleSpecifier;
16
16
  }): any;
17
17
  protected renderAnnotationInstance(renderContext: AnnotationRenderContext): boolean;
18
+ filterInteractableAnnotationsForElement(element: HTMLDivElement, annotations: Annotations): Annotations;
18
19
  private _getContourSegmentationStyle;
19
20
  }
20
21
  export { ContourSegmentationBaseTool as default, ContourSegmentationBaseTool };
@@ -12,6 +12,7 @@ import { getViewportIdsWithSegmentation } from '../../stateManagement/segmentati
12
12
  import { getActiveSegmentIndex } from '../../stateManagement/segmentation/getActiveSegmentIndex';
13
13
  import { getLockedSegmentIndices } from '../../stateManagement/segmentation/segmentLocking';
14
14
  import { getSVGStyleForSegment } from '../../utilities/segmentation/getSVGStyleForSegment';
15
+ import { defaultSegmentationStateManager } from '../../stateManagement/segmentation/SegmentationStateManager';
15
16
  class ContourSegmentationBaseTool extends ContourBaseTool {
16
17
  static { this.PreviewSegmentIndex = 255; }
17
18
  constructor(toolProps, defaultToolProps) {
@@ -99,6 +100,28 @@ class ContourSegmentationBaseTool extends ContourBaseTool {
99
100
  }
100
101
  return renderResult;
101
102
  }
103
+ filterInteractableAnnotationsForElement(element, annotations) {
104
+ if (!annotations || !annotations.length) {
105
+ return;
106
+ }
107
+ const baseFilteredAnnotations = super.filterInteractableAnnotationsForElement(element, annotations);
108
+ if (!baseFilteredAnnotations || !baseFilteredAnnotations.length) {
109
+ return;
110
+ }
111
+ const enabledElement = getEnabledElement(element);
112
+ const { viewport } = enabledElement;
113
+ return baseFilteredAnnotations.filter((annotation) => {
114
+ const segmentationId = annotation?.data
115
+ ?.segmentation?.segmentationId;
116
+ if (!segmentationId) {
117
+ return true;
118
+ }
119
+ return !!defaultSegmentationStateManager.getSegmentationRepresentation(viewport.id, {
120
+ segmentationId,
121
+ type: SegmentationRepresentations.Contour,
122
+ });
123
+ });
124
+ }
102
125
  _getContourSegmentationStyle(context) {
103
126
  const annotation = context.annotation;
104
127
  const { segmentationId, segmentIndex } = annotation.data.segmentation;
@@ -16,7 +16,6 @@ function removeRepresentation(viewportId, segmentationId, renderImmediate = fals
16
16
  return;
17
17
  }
18
18
  const { viewport } = enabledElement;
19
- removeContourFromElement(viewportId, segmentationId);
20
19
  if (!renderImmediate) {
21
20
  return;
22
21
  }
@@ -58,7 +58,7 @@ export default function filterAnnotationsWithinSlice(annotations, camera, spacin
58
58
  continue;
59
59
  }
60
60
  const point = metadata.planeRestriction?.point ||
61
- data.handles.points[0] ||
61
+ data.handles?.points?.[0] ||
62
62
  data.contour?.polyline[0];
63
63
  if (!point) {
64
64
  annotationsWithinSlice.push(annotation);
@@ -1,2 +1,2 @@
1
1
  export declare function setBrushSizeForToolGroup(toolGroupId: string, brushSize: number, toolName?: string): void;
2
- export declare function getBrushSizeForToolGroup(toolGroupId: string, toolName?: string): void;
2
+ export declare function getBrushSizeForToolGroup(toolGroupId: string, toolName?: string): number;
@@ -1,6 +1,5 @@
1
1
  import { getToolGroup } from '../../store/ToolGroupManager';
2
2
  import triggerAnnotationRenderForViewportIds from '../triggerAnnotationRenderForViewportIds';
3
- import { getRenderingEngine } from '@cornerstonejs/core';
4
3
  import { getBrushToolInstances } from './getBrushToolInstances';
5
4
  export function setBrushSizeForToolGroup(toolGroupId, brushSize, toolName) {
6
5
  const toolGroup = getToolGroup(toolGroupId);
@@ -9,17 +8,14 @@ export function setBrushSizeForToolGroup(toolGroupId, brushSize, toolName) {
9
8
  }
10
9
  const brushBasedToolInstances = getBrushToolInstances(toolGroupId, toolName);
11
10
  brushBasedToolInstances.forEach((tool) => {
12
- tool.configuration.brushSize = brushSize;
11
+ const minRadius = tool.configuration.minRadius;
12
+ const maxRadius = tool.configuration.maxRadius;
13
+ let newBrushSize = minRadius ? Math.max(brushSize, minRadius) : brushSize;
14
+ newBrushSize = maxRadius ? Math.min(newBrushSize, maxRadius) : newBrushSize;
15
+ tool.configuration.brushSize = newBrushSize;
13
16
  tool.invalidateBrushCursor();
14
17
  });
15
- const viewportsInfo = toolGroup.getViewportsInfo();
16
- const viewportsInfoArray = Object.keys(viewportsInfo).map((key) => viewportsInfo[key]);
17
- if (!viewportsInfoArray.length) {
18
- return;
19
- }
20
- const { renderingEngineId } = viewportsInfoArray[0];
21
18
  const viewportIds = toolGroup.getViewportIds();
22
- const renderingEngine = getRenderingEngine(renderingEngineId);
23
19
  triggerAnnotationRenderForViewportIds(viewportIds);
24
20
  }
25
21
  export function getBrushSizeForToolGroup(toolGroupId, toolName) {
@@ -1 +1 @@
1
- export declare const version = "4.8.4";
1
+ export declare const version = "4.9.0";
@@ -1 +1 @@
1
- export const version = '4.8.4';
1
+ export const version = '4.9.0';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cornerstonejs/tools",
3
- "version": "4.8.4",
3
+ "version": "4.9.0",
4
4
  "description": "Cornerstone3D Tools",
5
5
  "types": "./dist/esm/index.d.ts",
6
6
  "module": "./dist/esm/index.js",
@@ -108,7 +108,7 @@
108
108
  "canvas": "3.2.0"
109
109
  },
110
110
  "peerDependencies": {
111
- "@cornerstonejs/core": "4.8.4",
111
+ "@cornerstonejs/core": "4.9.0",
112
112
  "@kitware/vtk.js": "32.12.1",
113
113
  "@types/d3-array": "3.2.1",
114
114
  "@types/d3-interpolate": "3.0.4",
@@ -127,5 +127,5 @@
127
127
  "type": "individual",
128
128
  "url": "https://ohif.org/donate"
129
129
  },
130
- "gitHead": "b0f9014b28fdbc7cdeac242badef0c6c522fce7f"
130
+ "gitHead": "8f00d5d14582cd878595324d8480e3d00a5c92a6"
131
131
  }