@cornerstonejs/tools 2.17.1 → 2.17.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,20 +1,47 @@
1
1
  import drawLine from './drawLine';
2
+ const svgns = 'http://www.w3.org/2000/svg';
2
3
  export default function drawArrow(svgDrawingHelper, annotationUID, arrowUID, start, end, options = {}) {
3
4
  if (isNaN(start[0]) || isNaN(start[1]) || isNaN(end[0]) || isNaN(end[1])) {
4
5
  return;
5
6
  }
6
- const { color, width, lineWidth, lineDash } = Object.assign({
7
- color: 'rgb(0, 255, 0)',
8
- width: '2',
9
- lineWidth: undefined,
10
- lineDash: undefined,
11
- }, options);
12
- drawLine(svgDrawingHelper, annotationUID, arrowUID, start, end, {
13
- color,
14
- width,
15
- lineWidth,
16
- lineDash,
17
- });
7
+ const { viaMarker = false, color = 'rgb(0, 255, 0)', markerSize = 10, } = options;
8
+ if (!viaMarker) {
9
+ legacyDrawArrow(svgDrawingHelper, annotationUID, arrowUID, start, end, options);
10
+ return;
11
+ }
12
+ const layerId = svgDrawingHelper.svgLayerElement.id;
13
+ const markerBaseId = `arrow-${annotationUID}`;
14
+ const markerFullId = `${markerBaseId}-${layerId}`;
15
+ const defs = svgDrawingHelper.svgLayerElement.querySelector('defs');
16
+ let arrowMarker = defs.querySelector(`#${markerFullId}`);
17
+ if (!arrowMarker) {
18
+ arrowMarker = document.createElementNS(svgns, 'marker');
19
+ arrowMarker.setAttribute('id', markerFullId);
20
+ arrowMarker.setAttribute('viewBox', '0 0 10 10');
21
+ arrowMarker.setAttribute('refX', '8');
22
+ arrowMarker.setAttribute('refY', '5');
23
+ arrowMarker.setAttribute('markerWidth', `${markerSize}`);
24
+ arrowMarker.setAttribute('markerHeight', `${markerSize}`);
25
+ arrowMarker.setAttribute('orient', 'auto');
26
+ const arrowPath = document.createElementNS(svgns, 'path');
27
+ arrowPath.setAttribute('d', 'M 0 0 L 10 5 L 0 10 z');
28
+ arrowPath.setAttribute('fill', color);
29
+ arrowMarker.appendChild(arrowPath);
30
+ defs.appendChild(arrowMarker);
31
+ }
32
+ else {
33
+ arrowMarker.setAttribute('markerWidth', `${markerSize}`);
34
+ arrowMarker.setAttribute('markerHeight', `${markerSize}`);
35
+ const arrowPath = arrowMarker.querySelector('path');
36
+ if (arrowPath) {
37
+ arrowPath.setAttribute('fill', color);
38
+ }
39
+ }
40
+ options.markerEndId = markerFullId;
41
+ drawLine(svgDrawingHelper, annotationUID, arrowUID, start, end, options);
42
+ }
43
+ function legacyDrawArrow(svgDrawingHelper, annotationUID, arrowUID, start, end, options = {}) {
44
+ const { color = 'rgb(0, 255, 0)', width = 2, lineWidth, lineDash } = options;
18
45
  const headLength = 10;
19
46
  const angle = Math.atan2(end[1] - start[1], end[0] - start[0]);
20
47
  const firstLine = {
@@ -31,14 +58,22 @@ export default function drawArrow(svgDrawingHelper, annotationUID, arrowUID, sta
31
58
  ],
32
59
  end: end,
33
60
  };
61
+ drawLine(svgDrawingHelper, annotationUID, arrowUID, start, end, {
62
+ color,
63
+ width,
64
+ lineWidth,
65
+ lineDash,
66
+ });
34
67
  drawLine(svgDrawingHelper, annotationUID, '2', firstLine.start, firstLine.end, {
35
68
  color,
36
69
  width,
37
70
  lineWidth,
71
+ lineDash,
38
72
  });
39
73
  drawLine(svgDrawingHelper, annotationUID, '3', secondLine.start, secondLine.end, {
40
74
  color,
41
75
  width,
42
76
  lineWidth,
77
+ lineDash,
43
78
  });
44
79
  }
@@ -28,15 +28,18 @@ export default function drawHeight(svgDrawingHelper, annotationUID, heightUID, s
28
28
  color,
29
29
  width,
30
30
  lineWidth,
31
+ lineDash,
31
32
  });
32
33
  drawLine(svgDrawingHelper, annotationUID, '2', secondLine.start, secondLine.end, {
33
34
  color,
34
35
  width,
35
36
  lineWidth,
37
+ lineDash,
36
38
  });
37
39
  drawLine(svgDrawingHelper, annotationUID, '3', threeLine.start, threeLine.end, {
38
40
  color,
39
41
  width,
40
42
  lineWidth,
43
+ lineDash,
41
44
  });
42
45
  }
@@ -5,20 +5,13 @@ export default function drawLine(svgDrawingHelper, annotationUID, lineUID, start
5
5
  if (isNaN(start[0]) || isNaN(start[1]) || isNaN(end[0]) || isNaN(end[1])) {
6
6
  return;
7
7
  }
8
- const { color, width, lineWidth, lineDash, shadow } = Object.assign({
9
- color: 'rgb(0, 255, 0)',
10
- width: '2',
11
- lineWidth: undefined,
12
- lineDash: undefined,
13
- shadow: undefined,
14
- }, options);
8
+ const { color = 'rgb(0, 255, 0)', width = 10, lineWidth, lineDash, markerStartId = null, markerEndId = null, shadow = false, } = options;
15
9
  const strokeWidth = lineWidth || width;
16
10
  const svgns = 'http://www.w3.org/2000/svg';
17
11
  const svgNodeHash = _getHash(annotationUID, 'line', lineUID);
18
12
  const existingLine = svgDrawingHelper.getSvgNode(svgNodeHash);
19
- const dropShadowStyle = shadow
20
- ? `filter:url(#shadow-${svgDrawingHelper.svgLayerElement.id});`
21
- : '';
13
+ const layerId = svgDrawingHelper.svgLayerElement.id;
14
+ const dropShadowStyle = shadow ? `filter:url(#shadow-${layerId});` : '';
22
15
  const attributes = {
23
16
  x1: `${start[0]}`,
24
17
  y1: `${start[1]}`,
@@ -28,6 +21,8 @@ export default function drawLine(svgDrawingHelper, annotationUID, lineUID, start
28
21
  style: dropShadowStyle,
29
22
  'stroke-width': strokeWidth,
30
23
  'stroke-dasharray': lineDash,
24
+ 'marker-start': markerStartId ? `url(#${markerStartId})` : '',
25
+ 'marker-end': markerEndId ? `url(#${markerEndId})` : '',
31
26
  };
32
27
  if (existingLine) {
33
28
  setAttributesIfNecessary(attributes, existingLine);
@@ -8,4 +8,6 @@ export default function drawPolyline(svgDrawingHelper: SVGDrawingHelper, annotat
8
8
  lineWidth?: number;
9
9
  lineDash?: string;
10
10
  closePath?: boolean;
11
+ markerStartId?: string;
12
+ markerEndId?: string;
11
13
  }): void;
@@ -5,7 +5,7 @@ export default function drawPolyline(svgDrawingHelper, annotationUID, polylineUI
5
5
  if (points.length < 2) {
6
6
  return;
7
7
  }
8
- const { color = 'rgb(0, 255, 0)', width = 10, fillColor = 'none', fillOpacity = 0, lineWidth, lineDash, closePath = false, } = options;
8
+ const { color = 'rgb(0, 255, 0)', width = 10, fillColor = 'none', fillOpacity = 0, lineWidth, lineDash, closePath = false, markerStartId = null, markerEndId = null, } = options;
9
9
  const strokeWidth = lineWidth || width;
10
10
  const svgns = 'http://www.w3.org/2000/svg';
11
11
  const svgNodeHash = _getHash(annotationUID, 'polyline', polylineUID);
@@ -25,6 +25,8 @@ export default function drawPolyline(svgDrawingHelper, annotationUID, polylineUI
25
25
  'fill-opacity': fillOpacity,
26
26
  'stroke-width': strokeWidth,
27
27
  'stroke-dasharray': lineDash,
28
+ 'marker-start': markerStartId ? `url(#${markerStartId})` : '',
29
+ 'marker-end': markerEndId ? `url(#${markerEndId})` : '',
28
30
  };
29
31
  if (existingPolyLine) {
30
32
  setAttributesIfNecessary(attributes, existingPolyLine);
@@ -19,6 +19,7 @@ class ToolStyle {
19
19
  textBoxLinkLineWidth: '1',
20
20
  textBoxLinkLineDash: '2,3',
21
21
  textBoxShadow: true,
22
+ markerSize: '10',
22
23
  };
23
24
  this._initializeConfig(defaultConfig);
24
25
  }
@@ -20,6 +20,7 @@ class ArrowAnnotateTool extends AnnotationTool {
20
20
  changeTextCallback,
21
21
  preventHandleOutsideImage: false,
22
22
  arrowFirst: true,
23
+ arrowHeadStyle: 'legacy',
23
24
  },
24
25
  }) {
25
26
  super(toolProps, defaultToolProps);
@@ -302,7 +303,7 @@ class ArrowAnnotateTool extends AnnotationTool {
302
303
  const { handles, text } = data;
303
304
  const { points, activeHandleIndex } = handles;
304
305
  styleSpecifier.annotationUID = annotationUID;
305
- const { color, lineWidth, lineDash } = this.getAnnotationStyle({
306
+ const { color, lineWidth, lineDash, markerSize } = this.getAnnotationStyle({
306
307
  annotation,
307
308
  styleSpecifier,
308
309
  });
@@ -333,6 +334,8 @@ class ArrowAnnotateTool extends AnnotationTool {
333
334
  color,
334
335
  width: lineWidth,
335
336
  lineDash: lineDash,
337
+ viaMarker: this.configuration.arrowHeadStyle !== 'legacy',
338
+ markerSize,
336
339
  });
337
340
  }
338
341
  else {
@@ -340,6 +343,8 @@ class ArrowAnnotateTool extends AnnotationTool {
340
343
  color,
341
344
  width: lineWidth,
342
345
  lineDash: lineDash,
346
+ viaMarker: this.configuration.arrowHeadStyle !== 'legacy',
347
+ markerSize,
343
348
  });
344
349
  }
345
350
  renderStatus = true;
@@ -158,6 +158,7 @@ class AnnotationTool extends AnnotationDisplayTool {
158
158
  const lineWidth = getStyle('lineWidth');
159
159
  const lineDash = getStyle('lineDash');
160
160
  const color = getStyle('color');
161
+ const markerSize = getStyle('markerSize');
161
162
  const shadow = getStyle('shadow');
162
163
  const textboxStyle = this.getLinkedTextBoxStyle(styleSpecifier, annotation);
163
164
  return {
@@ -171,6 +172,7 @@ class AnnotationTool extends AnnotationDisplayTool {
171
172
  fillOpacity: 0,
172
173
  shadow,
173
174
  textbox: textboxStyle,
175
+ markerSize,
174
176
  };
175
177
  }
176
178
  _imagePointNearToolOrHandle(element, annotation, canvasCoords, proximity) {
@@ -2,6 +2,7 @@ import type { Types } from '@cornerstonejs/core';
2
2
  import { BaseTool } from '../base';
3
3
  import type vtkImageData from '@kitware/vtk.js/Common/DataModel/ImageData';
4
4
  import * as LabelmapMemo from '../../utilities/segmentation/createLabelmapMemo';
5
+ import type { LabelmapToolOperationData } from '../../types/LabelmapToolOperationData';
5
6
  export type PreviewData = {
6
7
  preview: unknown;
7
8
  timer?: number;
@@ -10,6 +11,25 @@ export type PreviewData = {
10
11
  element: HTMLDivElement;
11
12
  isDrag: boolean;
12
13
  };
14
+ type EditDataReturnType = {
15
+ volumeId: string;
16
+ referencedVolumeId: string;
17
+ segmentsLocked: number[];
18
+ } | {
19
+ imageId: string;
20
+ segmentsLocked: number[];
21
+ override?: {
22
+ voxelManager: Types.IVoxelManager<number> | Types.IVoxelManager<Types.RGB>;
23
+ imageData: vtkImageData;
24
+ };
25
+ } | null;
26
+ type ModifiedLabelmapToolOperationData = Omit<LabelmapToolOperationData, 'voxelManager' | 'override'> & {
27
+ voxelManager?: Types.IVoxelManager<number> | Types.IVoxelManager<Types.RGB>;
28
+ override?: {
29
+ voxelManager: Types.IVoxelManager<number> | Types.IVoxelManager<Types.RGB>;
30
+ imageData: vtkImageData;
31
+ };
32
+ };
13
33
  export default class LabelmapBaseTool extends BaseTool {
14
34
  protected _editData: {
15
35
  override: {
@@ -35,28 +55,14 @@ export default class LabelmapBaseTool extends BaseTool {
35
55
  constructor(toolProps: any, defaultToolProps: any);
36
56
  protected get _previewData(): PreviewData;
37
57
  createMemo(segmentId: string, segmentationVoxelManager: any, preview: any): LabelmapMemo.LabelmapMemo;
38
- createEditData(element: any): {
39
- volumeId: string;
40
- referencedVolumeId: any;
41
- segmentsLocked: number[] | [];
42
- imageId?: undefined;
43
- override?: undefined;
44
- } | {
45
- imageId: string;
46
- segmentsLocked: number[] | [];
47
- override: {
48
- voxelManager: Types.IVoxelManager<number> | Types.IVoxelManager<Types.RGB>;
49
- imageData: vtkImageData;
50
- };
51
- volumeId?: undefined;
52
- referencedVolumeId?: undefined;
53
- } | {
54
- imageId: string;
55
- segmentsLocked: number[] | [];
56
- volumeId?: undefined;
57
- referencedVolumeId?: undefined;
58
- override?: undefined;
59
- };
58
+ protected createEditData(element: any): EditDataReturnType;
59
+ protected getEditData({ viewport, representationData, segmentsLocked, segmentationId, volumeOperation, }: {
60
+ viewport: any;
61
+ representationData: any;
62
+ segmentsLocked: any;
63
+ segmentationId: any;
64
+ volumeOperation?: boolean;
65
+ }): EditDataReturnType;
60
66
  protected createHoverData(element: any, centerCanvas?: any): {
61
67
  brushCursor: {
62
68
  metadata: {
@@ -81,78 +87,7 @@ export default class LabelmapBaseTool extends BaseTool {
81
87
  segmentationId: string;
82
88
  segmentColor: Types.Color;
83
89
  };
84
- protected getOperationData(element?: any): {
85
- points: any;
86
- segmentIndex: number;
87
- previewColors: any;
88
- viewPlaneNormal: any;
89
- toolGroupId: string;
90
- segmentationId: string;
91
- viewUp: any;
92
- strategySpecificConfiguration: any;
93
- preview: unknown;
94
- createMemo: (segmentId: string, segmentationVoxelManager: any, preview: any) => LabelmapMemo.LabelmapMemo;
95
- override: {
96
- voxelManager: Types.IVoxelManager<number>;
97
- imageData: vtkImageData;
98
- };
99
- segmentsLocked: number[];
100
- imageId?: string;
101
- imageIds?: string[];
102
- volumeId?: string;
103
- referencedVolumeId?: string;
104
- } | {
105
- points: any;
106
- segmentIndex: number;
107
- previewColors: any;
108
- viewPlaneNormal: any;
109
- toolGroupId: string;
110
- segmentationId: string;
111
- viewUp: any;
112
- strategySpecificConfiguration: any;
113
- preview: unknown;
114
- createMemo: (segmentId: string, segmentationVoxelManager: any, preview: any) => LabelmapMemo.LabelmapMemo;
115
- volumeId: string;
116
- referencedVolumeId: any;
117
- segmentsLocked: number[] | [];
118
- imageId?: undefined;
119
- override?: undefined;
120
- } | {
121
- points: any;
122
- segmentIndex: number;
123
- previewColors: any;
124
- viewPlaneNormal: any;
125
- toolGroupId: string;
126
- segmentationId: string;
127
- viewUp: any;
128
- strategySpecificConfiguration: any;
129
- preview: unknown;
130
- createMemo: (segmentId: string, segmentationVoxelManager: any, preview: any) => LabelmapMemo.LabelmapMemo;
131
- imageId: string;
132
- segmentsLocked: number[] | [];
133
- override: {
134
- voxelManager: Types.IVoxelManager<number> | Types.IVoxelManager<Types.RGB>;
135
- imageData: vtkImageData;
136
- };
137
- volumeId?: undefined;
138
- referencedVolumeId?: undefined;
139
- } | {
140
- points: any;
141
- segmentIndex: number;
142
- previewColors: any;
143
- viewPlaneNormal: any;
144
- toolGroupId: string;
145
- segmentationId: string;
146
- viewUp: any;
147
- strategySpecificConfiguration: any;
148
- preview: unknown;
149
- createMemo: (segmentId: string, segmentationVoxelManager: any, preview: any) => LabelmapMemo.LabelmapMemo;
150
- imageId: string;
151
- segmentsLocked: number[] | [];
152
- volumeId?: undefined;
153
- referencedVolumeId?: undefined;
154
- override?: undefined;
155
- };
90
+ protected getOperationData(element?: any): ModifiedLabelmapToolOperationData;
156
91
  addPreview(element?: HTMLDivElement, options?: {
157
92
  acceptReject: boolean;
158
93
  }): unknown;
@@ -162,3 +97,4 @@ export default class LabelmapBaseTool extends BaseTool {
162
97
  removeContours: boolean;
163
98
  }): void;
164
99
  }
100
+ export {};
@@ -53,6 +53,15 @@ export default class LabelmapBaseTool extends BaseTool {
53
53
  const { segmentationId } = activeSegmentation;
54
54
  const segmentsLocked = getLockedSegmentIndices(segmentationId);
55
55
  const { representationData } = getSegmentation(segmentationId);
56
+ const editData = this.getEditData({
57
+ viewport,
58
+ representationData,
59
+ segmentsLocked,
60
+ segmentationId,
61
+ });
62
+ return editData;
63
+ }
64
+ getEditData({ viewport, representationData, segmentsLocked, segmentationId, volumeOperation = false, }) {
56
65
  if (viewport instanceof BaseVolumeViewport) {
57
66
  const { volumeId } = representationData[SegmentationRepresentations.Labelmap];
58
67
  const actors = viewport.getActors();
@@ -82,7 +91,8 @@ export default class LabelmapBaseTool extends BaseTool {
82
91
  if (!segmentationImageId) {
83
92
  return;
84
93
  }
85
- if (this.configuration.activeStrategy.includes('SPHERE')) {
94
+ if (this.configuration.activeStrategy.includes('SPHERE') ||
95
+ volumeOperation) {
86
96
  const referencedImageIds = viewport.getImageIds();
87
97
  const isValidVolumeForSphere = csUtils.isValidVolume(referencedImageIds);
88
98
  if (!isValidVolumeForSphere) {
@@ -101,7 +111,7 @@ export default class LabelmapBaseTool extends BaseTool {
101
111
  };
102
112
  }
103
113
  else {
104
- const labelmapImageIds = getStackSegmentationImageIdsForViewport(viewport.id, segmentationId);
114
+ const { imageIds: labelmapImageIds } = representationData.Labelmap;
105
115
  if (!labelmapImageIds || labelmapImageIds.length === 1) {
106
116
  return {
107
117
  imageId: segmentationImageId,
@@ -1,5 +1,4 @@
1
- import { BaseVolumeViewport, cache, getEnabledElement, } from '@cornerstonejs/core';
2
- import { BaseTool } from '../base';
1
+ import { getEnabledElement } from '@cornerstonejs/core';
3
2
  import { fillInsideSphere } from './strategies/fillSphere';
4
3
  import { eraseInsideSphere } from './strategies/eraseSphere';
5
4
  import { Events, SegmentationRepresentations } from '../../enums';
@@ -88,21 +87,17 @@ class SphereScissorsTool extends LabelmapBaseTool {
88
87
  imageId: null,
89
88
  };
90
89
  const { representationData } = getSegmentation(segmentationId);
91
- const labelmapData = representationData[SegmentationRepresentations.Labelmap];
92
- if (viewport instanceof BaseVolumeViewport) {
93
- const { volumeId } = labelmapData;
94
- const segmentation = cache.getVolume(volumeId);
95
- this.editData = {
96
- ...this.editData,
97
- volumeId,
98
- referencedVolumeId: segmentation.referencedVolumeId,
99
- };
100
- }
101
- else {
102
- this.editData = {
103
- ...this.editData,
104
- };
105
- }
90
+ const editData = this.getEditData({
91
+ viewport,
92
+ representationData,
93
+ segmentsLocked,
94
+ segmentationId,
95
+ volumeOperation: true,
96
+ });
97
+ this.editData = {
98
+ ...this.editData,
99
+ ...editData,
100
+ };
106
101
  this._activateDraw(element);
107
102
  hideElementCursor(element);
108
103
  evt.preventDefault();
@@ -1,6 +1,6 @@
1
1
  type Modes = '' | 'Active' | 'Passive' | 'Enabled';
2
2
  type States = '' | 'Highlighted' | 'Selected' | 'Locked' | 'AutoGenerated';
3
- type Properties = 'color' | 'colorAutoGenerated' | 'lineWidth' | 'lineWidthAutoGenerated' | 'lineDash' | 'textBoxFontFamily' | 'textBoxFontSize' | 'textBoxColor' | 'textBoxBackground' | 'textBoxLinkLineWidth' | 'textBoxLinkLineDash' | 'locked' | 'fillColor' | 'fillOpacity' | 'textbox' | 'shadow' | 'visibility';
3
+ type Properties = 'color' | 'colorAutoGenerated' | 'lineWidth' | 'lineWidthAutoGenerated' | 'lineDash' | 'textBoxFontFamily' | 'textBoxFontSize' | 'textBoxColor' | 'textBoxBackground' | 'textBoxLinkLineWidth' | 'textBoxLinkLineDash' | 'locked' | 'fillColor' | 'fillOpacity' | 'textbox' | 'shadow' | 'visibility' | 'markerSize';
4
4
  export type AnnotationStyle = {
5
5
  [key in `${Properties}${States}${Modes}`]?: string | number | boolean | Record<string, unknown>;
6
6
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cornerstonejs/tools",
3
- "version": "2.17.1",
3
+ "version": "2.17.3",
4
4
  "description": "Cornerstone3D Tools",
5
5
  "types": "./dist/esm/index.d.ts",
6
6
  "module": "./dist/esm/index.js",
@@ -104,7 +104,7 @@
104
104
  "canvas": "^2.11.2"
105
105
  },
106
106
  "peerDependencies": {
107
- "@cornerstonejs/core": "^2.17.1",
107
+ "@cornerstonejs/core": "^2.17.3",
108
108
  "@kitware/vtk.js": "32.9.0",
109
109
  "@types/d3-array": "^3.0.4",
110
110
  "@types/d3-interpolate": "^3.0.1",
@@ -123,5 +123,5 @@
123
123
  "type": "individual",
124
124
  "url": "https://ohif.org/donate"
125
125
  },
126
- "gitHead": "b68b0b87867bfe60b19cdadb8248654a09f9c8ce"
126
+ "gitHead": "8fe548248197e61fba869257fdebdd33714e42f8"
127
127
  }