@cornerstonejs/tools 4.20.1 → 4.20.3

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.
@@ -1,4 +1,4 @@
1
- import { getEnabledElement, eventTarget } from '@cornerstonejs/core';
1
+ import { getEnabledElement, eventTarget, Enums } from '@cornerstonejs/core';
2
2
  import { vec3, vec2 } from 'gl-matrix';
3
3
  import { Events, ToolModes, StrategyCallbacks } from '../../enums';
4
4
  import { fillInsideSphere, thresholdInsideSphere, thresholdInsideSphereIsland, } from './strategies/fillSphere';
@@ -9,6 +9,7 @@ import { resetElementCursor, hideElementCursor, } from '../../cursors/elementCur
9
9
  import triggerAnnotationRenderForViewportUIDs from '../../utilities/triggerAnnotationRenderForViewportIds';
10
10
  import LabelmapBaseTool from './LabelmapBaseTool';
11
11
  import { getStrategyData } from './strategies/utils/getStrategyData';
12
+ import { getActiveSegmentation } from '../../stateManagement/segmentation/getActiveSegmentation';
12
13
  class BrushTool extends LabelmapBaseTool {
13
14
  constructor(toolProps = {}, defaultToolProps = {
14
15
  supportedInteractionTypes: ['Mouse', 'Touch'],
@@ -94,6 +95,18 @@ class BrushTool extends LabelmapBaseTool {
94
95
  const { element, currentPoints } = eventData;
95
96
  const enabledElement = getEnabledElement(element);
96
97
  const { viewport } = enabledElement;
98
+ const activeSegmentation = getActiveSegmentation(viewport.id);
99
+ if (!activeSegmentation) {
100
+ const event = new CustomEvent(Enums.Events.ERROR_EVENT, {
101
+ detail: {
102
+ type: 'Segmentation',
103
+ message: 'No active segmentation detected, create a segmentation representation before using the brush tool',
104
+ },
105
+ cancelable: true,
106
+ });
107
+ eventTarget.dispatchEvent(event);
108
+ return false;
109
+ }
97
110
  this._editData = this.createEditData(element);
98
111
  this._activateDraw(element);
99
112
  hideElementCursor(element);
@@ -86,14 +86,6 @@ export default class LabelmapBaseTool extends BaseTool {
86
86
  const { viewport } = enabledElement;
87
87
  const activeSegmentation = getActiveSegmentation(viewport.id);
88
88
  if (!activeSegmentation) {
89
- const event = new CustomEvent(Enums.Events.ERROR_EVENT, {
90
- detail: {
91
- type: 'Segmentation',
92
- message: 'No active segmentation detected, create a segmentation representation before using the brush tool',
93
- },
94
- cancelable: true,
95
- });
96
- eventTarget.dispatchEvent(event);
97
89
  return null;
98
90
  }
99
91
  const { segmentationId } = activeSegmentation;
@@ -99,28 +99,36 @@ function _findSvgLayer(element) {
99
99
  return internalDiv?.querySelector(':scope > .svg-layer') || null;
100
100
  }
101
101
  function _determineCorners(canvasPoints) {
102
- const p0 = canvasPoints[0];
103
- if (!p0 || canvasPoints.length < 2) {
102
+ const validPoints = canvasPoints.filter(Boolean);
103
+ const p0 = validPoints[0];
104
+ if (!p0 || validPoints.length < 2) {
104
105
  return { left: p0, right: p0, top: p0, bottom: p0 };
105
106
  }
106
- const handlesLeftToRight = [canvasPoints[0], canvasPoints[1]].sort(_compareX);
107
- const handlesTopToBottom = [canvasPoints[0], canvasPoints[1]].sort(_compareY);
108
- const left = handlesLeftToRight[0];
109
- const right = handlesLeftToRight[handlesLeftToRight.length - 1];
110
- const top = handlesTopToBottom[0];
111
- const bottom = handlesTopToBottom[handlesTopToBottom.length - 1];
107
+ let left = p0;
108
+ let right = p0;
109
+ let top = p0;
110
+ let bottom = p0;
111
+ for (let i = 1; i < validPoints.length; i++) {
112
+ const point = validPoints[i];
113
+ if (point[0] < left[0]) {
114
+ left = point;
115
+ }
116
+ if (point[0] > right[0]) {
117
+ right = point;
118
+ }
119
+ if (point[1] < top[1]) {
120
+ top = point;
121
+ }
122
+ if (point[1] > bottom[1]) {
123
+ bottom = point;
124
+ }
125
+ }
112
126
  return {
113
127
  left,
114
128
  top,
115
129
  bottom,
116
130
  right,
117
131
  };
118
- function _compareX(a, b) {
119
- return a[0] < b[0] ? -1 : 1;
120
- }
121
- function _compareY(a, b) {
122
- return a[1] < b[1] ? -1 : 1;
123
- }
124
132
  }
125
133
  function _estimateTextBoxSize(textLines) {
126
134
  const estimatedPadding = 25;
@@ -1 +1 @@
1
- export declare const version = "4.20.1";
1
+ export declare const version = "4.20.3";
@@ -1 +1 @@
1
- export const version = '4.20.1';
1
+ export const version = '4.20.3';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cornerstonejs/tools",
3
- "version": "4.20.1",
3
+ "version": "4.20.3",
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.20.1",
111
+ "@cornerstonejs/core": "4.20.3",
112
112
  "@kitware/vtk.js": "34.15.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": "67fb3a5cec834cdac65dec315c6d25553e935cce"
130
+ "gitHead": "43df78bf93b86d67b0c546661d327d1d14ae13eb"
131
131
  }