@cornerstonejs/tools 3.19.0 → 3.19.1

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.
@@ -12,7 +12,7 @@ import * as Types from './types';
12
12
  import * as annotation from './stateManagement/annotation';
13
13
  import * as segmentation from './stateManagement/segmentation';
14
14
  import * as splines from './tools/annotation/splines';
15
- import { BaseTool, AnnotationTool, AnnotationDisplayTool, PanTool, TrackballRotateTool, DragProbeTool, WindowLevelTool, ZoomTool, StackScrollTool, SegmentBidirectionalTool, PlanarRotateTool, MIPJumpToClickTool, LabelTool, LengthTool, HeightTool, ProbeTool, RectangleROITool, EllipticalROITool, CircleROITool, ETDRSGridTool, SplineROITool, SplineContourSegmentationTool, BidirectionalTool, PlanarFreehandROITool, PlanarFreehandContourSegmentationTool, LivewireContourTool, LivewireContourSegmentationTool, ArrowAnnotateTool, KeyImageTool, CrosshairsTool, ReferenceLinesTool, RectangleScissorsTool, CircleScissorsTool, SphereScissorsTool, RectangleROIThresholdTool, RectangleROIStartEndThresholdTool, CircleROIStartEndThresholdTool, BrushTool, AngleTool, CobbAngleTool, UltrasoundDirectionalTool, UltrasoundPleuraBLineTool, MagnifyTool, AdvancedMagnifyTool, ReferenceCursors, PaintFillTool, ScaleOverlayTool, OrientationMarkerTool, OverlayGridTool, SegmentationIntersectionTool, EraserTool, SculptorTool, SegmentSelectTool, WindowLevelRegionTool, VolumeRotateTool, RegionSegmentPlusTool, RegionSegmentTool, WholeBodySegmentTool, LabelmapBaseTool, SegmentLabelTool } from './tools';
15
+ import { BaseTool, AnnotationTool, AnnotationDisplayTool, PanTool, TrackballRotateTool, DragProbeTool, WindowLevelTool, ZoomTool, StackScrollTool, SegmentBidirectionalTool, PlanarRotateTool, MIPJumpToClickTool, LabelTool, LengthTool, HeightTool, ProbeTool, RectangleROITool, EllipticalROITool, CircleROITool, ETDRSGridTool, SplineROITool, SplineContourSegmentationTool, BidirectionalTool, PlanarFreehandROITool, PlanarFreehandContourSegmentationTool, LivewireContourTool, LivewireContourSegmentationTool, ArrowAnnotateTool, KeyImageTool, CrosshairsTool, ReferenceLinesTool, RectangleScissorsTool, CircleScissorsTool, SphereScissorsTool, RectangleROIThresholdTool, RectangleROIStartEndThresholdTool, CircleROIStartEndThresholdTool, BrushTool, AngleTool, CobbAngleTool, UltrasoundDirectionalTool, UltrasoundPleuraBLineTool, MagnifyTool, AdvancedMagnifyTool, ReferenceCursors, PaintFillTool, ScaleOverlayTool, OrientationMarkerTool, OverlayGridTool, SegmentationIntersectionTool, EraserTool, SculptorTool, SegmentSelectTool, WindowLevelRegionTool, VolumeRotateTool, RegionSegmentPlusTool, RegionSegmentTool, WholeBodySegmentTool, LabelmapBaseTool, SegmentLabelTool, LabelMapEditWithContourTool } from './tools';
16
16
  import VideoRedactionTool from './tools/annotation/VideoRedactionTool';
17
17
  import * as Enums from './enums';
18
- export { VideoRedactionTool, init, destroy, addTool, removeTool, cancelActiveManipulations, BaseTool, AnnotationTool, AnnotationDisplayTool, PanTool, SegmentBidirectionalTool, TrackballRotateTool, DragProbeTool, WindowLevelTool, WindowLevelRegionTool, ZoomTool, StackScrollTool, PlanarRotateTool, MIPJumpToClickTool, LabelTool, LengthTool, HeightTool, CrosshairsTool, ReferenceLinesTool, OverlayGridTool, SegmentationIntersectionTool, ProbeTool, RectangleROITool, EllipticalROITool, CircleROITool, ETDRSGridTool, SplineROITool, SplineContourSegmentationTool, BidirectionalTool, PlanarFreehandROITool, PlanarFreehandContourSegmentationTool, LivewireContourTool, LivewireContourSegmentationTool, ArrowAnnotateTool, AngleTool, CobbAngleTool, UltrasoundDirectionalTool, UltrasoundPleuraBLineTool, KeyImageTool, MagnifyTool, AdvancedMagnifyTool, ReferenceCursors, ScaleOverlayTool, SculptorTool, EraserTool, RectangleScissorsTool, CircleScissorsTool, SphereScissorsTool, RectangleROIThresholdTool, RectangleROIStartEndThresholdTool, CircleROIStartEndThresholdTool, BrushTool, OrientationMarkerTool, SegmentSelectTool, SegmentLabelTool, synchronizers, Synchronizer, SynchronizerManager, PaintFillTool, Types, state, ToolGroupManager, store, Enums, CONSTANTS, drawing, annotation, segmentation, utilities, cursors, VolumeRotateTool, RegionSegmentPlusTool, RegionSegmentTool, WholeBodySegmentTool, LabelmapBaseTool, splines, version, };
18
+ export { VideoRedactionTool, init, destroy, addTool, removeTool, cancelActiveManipulations, BaseTool, AnnotationTool, AnnotationDisplayTool, PanTool, SegmentBidirectionalTool, TrackballRotateTool, DragProbeTool, WindowLevelTool, WindowLevelRegionTool, ZoomTool, StackScrollTool, PlanarRotateTool, MIPJumpToClickTool, LabelTool, LengthTool, HeightTool, CrosshairsTool, ReferenceLinesTool, OverlayGridTool, SegmentationIntersectionTool, ProbeTool, RectangleROITool, EllipticalROITool, CircleROITool, ETDRSGridTool, SplineROITool, SplineContourSegmentationTool, BidirectionalTool, PlanarFreehandROITool, PlanarFreehandContourSegmentationTool, LivewireContourTool, LivewireContourSegmentationTool, ArrowAnnotateTool, AngleTool, CobbAngleTool, UltrasoundDirectionalTool, UltrasoundPleuraBLineTool, KeyImageTool, MagnifyTool, AdvancedMagnifyTool, ReferenceCursors, ScaleOverlayTool, SculptorTool, EraserTool, RectangleScissorsTool, CircleScissorsTool, SphereScissorsTool, RectangleROIThresholdTool, RectangleROIStartEndThresholdTool, CircleROIStartEndThresholdTool, BrushTool, OrientationMarkerTool, SegmentSelectTool, SegmentLabelTool, synchronizers, Synchronizer, SynchronizerManager, PaintFillTool, Types, state, ToolGroupManager, store, Enums, CONSTANTS, drawing, annotation, segmentation, utilities, cursors, VolumeRotateTool, RegionSegmentPlusTool, RegionSegmentTool, WholeBodySegmentTool, LabelmapBaseTool, LabelMapEditWithContourTool, splines, version, };
package/dist/esm/index.js CHANGED
@@ -12,7 +12,7 @@ import * as Types from './types';
12
12
  import * as annotation from './stateManagement/annotation';
13
13
  import * as segmentation from './stateManagement/segmentation';
14
14
  import * as splines from './tools/annotation/splines';
15
- import { BaseTool, AnnotationTool, AnnotationDisplayTool, PanTool, TrackballRotateTool, DragProbeTool, WindowLevelTool, ZoomTool, StackScrollTool, SegmentBidirectionalTool, PlanarRotateTool, MIPJumpToClickTool, LabelTool, LengthTool, HeightTool, ProbeTool, RectangleROITool, EllipticalROITool, CircleROITool, ETDRSGridTool, SplineROITool, SplineContourSegmentationTool, BidirectionalTool, PlanarFreehandROITool, PlanarFreehandContourSegmentationTool, LivewireContourTool, LivewireContourSegmentationTool, ArrowAnnotateTool, KeyImageTool, CrosshairsTool, ReferenceLinesTool, RectangleScissorsTool, CircleScissorsTool, SphereScissorsTool, RectangleROIThresholdTool, RectangleROIStartEndThresholdTool, CircleROIStartEndThresholdTool, BrushTool, AngleTool, CobbAngleTool, UltrasoundDirectionalTool, UltrasoundPleuraBLineTool, MagnifyTool, AdvancedMagnifyTool, ReferenceCursors, PaintFillTool, ScaleOverlayTool, OrientationMarkerTool, OverlayGridTool, SegmentationIntersectionTool, EraserTool, SculptorTool, SegmentSelectTool, WindowLevelRegionTool, VolumeRotateTool, RegionSegmentPlusTool, RegionSegmentTool, WholeBodySegmentTool, LabelmapBaseTool, SegmentLabelTool, } from './tools';
15
+ import { BaseTool, AnnotationTool, AnnotationDisplayTool, PanTool, TrackballRotateTool, DragProbeTool, WindowLevelTool, ZoomTool, StackScrollTool, SegmentBidirectionalTool, PlanarRotateTool, MIPJumpToClickTool, LabelTool, LengthTool, HeightTool, ProbeTool, RectangleROITool, EllipticalROITool, CircleROITool, ETDRSGridTool, SplineROITool, SplineContourSegmentationTool, BidirectionalTool, PlanarFreehandROITool, PlanarFreehandContourSegmentationTool, LivewireContourTool, LivewireContourSegmentationTool, ArrowAnnotateTool, KeyImageTool, CrosshairsTool, ReferenceLinesTool, RectangleScissorsTool, CircleScissorsTool, SphereScissorsTool, RectangleROIThresholdTool, RectangleROIStartEndThresholdTool, CircleROIStartEndThresholdTool, BrushTool, AngleTool, CobbAngleTool, UltrasoundDirectionalTool, UltrasoundPleuraBLineTool, MagnifyTool, AdvancedMagnifyTool, ReferenceCursors, PaintFillTool, ScaleOverlayTool, OrientationMarkerTool, OverlayGridTool, SegmentationIntersectionTool, EraserTool, SculptorTool, SegmentSelectTool, WindowLevelRegionTool, VolumeRotateTool, RegionSegmentPlusTool, RegionSegmentTool, WholeBodySegmentTool, LabelmapBaseTool, SegmentLabelTool, LabelMapEditWithContourTool, } from './tools';
16
16
  import VideoRedactionTool from './tools/annotation/VideoRedactionTool';
17
17
  import * as Enums from './enums';
18
- export { VideoRedactionTool, init, destroy, addTool, removeTool, cancelActiveManipulations, BaseTool, AnnotationTool, AnnotationDisplayTool, PanTool, SegmentBidirectionalTool, TrackballRotateTool, DragProbeTool, WindowLevelTool, WindowLevelRegionTool, ZoomTool, StackScrollTool, PlanarRotateTool, MIPJumpToClickTool, LabelTool, LengthTool, HeightTool, CrosshairsTool, ReferenceLinesTool, OverlayGridTool, SegmentationIntersectionTool, ProbeTool, RectangleROITool, EllipticalROITool, CircleROITool, ETDRSGridTool, SplineROITool, SplineContourSegmentationTool, BidirectionalTool, PlanarFreehandROITool, PlanarFreehandContourSegmentationTool, LivewireContourTool, LivewireContourSegmentationTool, ArrowAnnotateTool, AngleTool, CobbAngleTool, UltrasoundDirectionalTool, UltrasoundPleuraBLineTool, KeyImageTool, MagnifyTool, AdvancedMagnifyTool, ReferenceCursors, ScaleOverlayTool, SculptorTool, EraserTool, RectangleScissorsTool, CircleScissorsTool, SphereScissorsTool, RectangleROIThresholdTool, RectangleROIStartEndThresholdTool, CircleROIStartEndThresholdTool, BrushTool, OrientationMarkerTool, SegmentSelectTool, SegmentLabelTool, synchronizers, Synchronizer, SynchronizerManager, PaintFillTool, Types, state, ToolGroupManager, store, Enums, CONSTANTS, drawing, annotation, segmentation, utilities, cursors, VolumeRotateTool, RegionSegmentPlusTool, RegionSegmentTool, WholeBodySegmentTool, LabelmapBaseTool, splines, version, };
18
+ export { VideoRedactionTool, init, destroy, addTool, removeTool, cancelActiveManipulations, BaseTool, AnnotationTool, AnnotationDisplayTool, PanTool, SegmentBidirectionalTool, TrackballRotateTool, DragProbeTool, WindowLevelTool, WindowLevelRegionTool, ZoomTool, StackScrollTool, PlanarRotateTool, MIPJumpToClickTool, LabelTool, LengthTool, HeightTool, CrosshairsTool, ReferenceLinesTool, OverlayGridTool, SegmentationIntersectionTool, ProbeTool, RectangleROITool, EllipticalROITool, CircleROITool, ETDRSGridTool, SplineROITool, SplineContourSegmentationTool, BidirectionalTool, PlanarFreehandROITool, PlanarFreehandContourSegmentationTool, LivewireContourTool, LivewireContourSegmentationTool, ArrowAnnotateTool, AngleTool, CobbAngleTool, UltrasoundDirectionalTool, UltrasoundPleuraBLineTool, KeyImageTool, MagnifyTool, AdvancedMagnifyTool, ReferenceCursors, ScaleOverlayTool, SculptorTool, EraserTool, RectangleScissorsTool, CircleScissorsTool, SphereScissorsTool, RectangleROIThresholdTool, RectangleROIStartEndThresholdTool, CircleROIStartEndThresholdTool, BrushTool, OrientationMarkerTool, SegmentSelectTool, SegmentLabelTool, synchronizers, Synchronizer, SynchronizerManager, PaintFillTool, Types, state, ToolGroupManager, store, Enums, CONSTANTS, drawing, annotation, segmentation, utilities, cursors, VolumeRotateTool, RegionSegmentPlusTool, RegionSegmentTool, WholeBodySegmentTool, LabelmapBaseTool, LabelMapEditWithContourTool, splines, version, };
@@ -53,21 +53,36 @@ class ZoomTool extends BaseTool {
53
53
  }
54
54
  const imageData = viewport.getImageData();
55
55
  let spacing = [1, 1, 1];
56
- if (imageData) {
57
- spacing = imageData.spacing;
58
- }
59
- const { minZoomScale, maxZoomScale } = this.configuration;
60
- const t = element.clientHeight * spacing[1] * 0.5;
61
- const scale = t / parallelScaleToSet;
62
56
  let cappedParallelScale = parallelScaleToSet;
63
57
  let thresholdExceeded = false;
64
58
  if (imageData) {
65
- if (scale < minZoomScale) {
66
- cappedParallelScale = t / minZoomScale;
59
+ spacing = imageData.spacing;
60
+ const { dimensions } = imageData;
61
+ const imageWidth = dimensions[0] * spacing[0];
62
+ const imageHeight = dimensions[1] * spacing[1];
63
+ const canvasAspect = size[0] / size[1];
64
+ const displayArea = viewport.options?.displayArea;
65
+ const imageAreaScaleX = displayArea?.imageArea?.[0] ?? 1.1;
66
+ const imageAreaScaleY = displayArea?.imageArea?.[1] ?? 1.1;
67
+ const scaledImageWidth = imageWidth * imageAreaScaleX;
68
+ const scaledImageHeight = imageHeight * imageAreaScaleY;
69
+ const scaledImageAspect = scaledImageWidth / scaledImageHeight;
70
+ let minParallelScaleRequired;
71
+ if (scaledImageAspect > canvasAspect) {
72
+ minParallelScaleRequired = (scaledImageWidth / canvasAspect) * 0.5;
73
+ }
74
+ else {
75
+ minParallelScaleRequired = scaledImageHeight * 0.5;
76
+ }
77
+ const { minZoomScale, maxZoomScale } = this.configuration;
78
+ const minScaleInWorld = minParallelScaleRequired / maxZoomScale;
79
+ const maxScaleInWorld = minParallelScaleRequired / minZoomScale;
80
+ if (parallelScaleToSet < minScaleInWorld) {
81
+ cappedParallelScale = minScaleInWorld;
67
82
  thresholdExceeded = true;
68
83
  }
69
- else if (scale >= maxZoomScale) {
70
- cappedParallelScale = t / maxZoomScale;
84
+ else if (parallelScaleToSet > maxScaleInWorld) {
85
+ cappedParallelScale = maxScaleInWorld;
71
86
  thresholdExceeded = true;
72
87
  }
73
88
  }
@@ -57,4 +57,5 @@ import SegmentSelectTool from './segmentation/SegmentSelectTool';
57
57
  import SegmentBidirectionalTool from './segmentation/SegmentBidirectionalTool';
58
58
  import * as strategies from './segmentation/strategies';
59
59
  import SegmentLabelTool from './segmentation/SegmentLabelTool';
60
- export { BaseTool, AnnotationTool, AnnotationDisplayTool, PanTool, TrackballRotateTool, DragProbeTool, WindowLevelTool, WindowLevelRegionTool, StackScrollTool, PlanarRotateTool, ZoomTool, MIPJumpToClickTool, ReferenceCursors, CrosshairsTool, ReferenceLinesTool, OverlayGridTool, SegmentationIntersectionTool, BidirectionalTool, LabelTool, LengthTool, HeightTool, ProbeTool, RectangleROITool, EllipticalROITool, CircleROITool, ETDRSGridTool, SplineROITool, PlanarFreehandROITool, PlanarFreehandContourSegmentationTool, LivewireContourTool, LivewireContourSegmentationTool, ArrowAnnotateTool, AngleTool, CobbAngleTool, UltrasoundDirectionalTool, UltrasoundPleuraBLineTool, KeyImageTool, AnnotationEraserTool as EraserTool, RectangleScissorsTool, CircleScissorsTool, SphereScissorsTool, RectangleROIThresholdTool, RectangleROIStartEndThresholdTool, CircleROIStartEndThresholdTool, SplineContourSegmentationTool, BrushTool, MagnifyTool, AdvancedMagnifyTool, PaintFillTool, ScaleOverlayTool, OrientationMarkerTool, SculptorTool, SegmentSelectTool, VolumeRotateTool, RegionSegmentTool, RegionSegmentPlusTool, WholeBodySegmentTool, LabelmapBaseTool, SegmentBidirectionalTool, SegmentLabelTool, strategies, };
60
+ import LabelMapEditWithContourTool from './segmentation/LabelmapEditWithContour';
61
+ export { BaseTool, AnnotationTool, AnnotationDisplayTool, PanTool, TrackballRotateTool, DragProbeTool, WindowLevelTool, WindowLevelRegionTool, StackScrollTool, PlanarRotateTool, ZoomTool, MIPJumpToClickTool, ReferenceCursors, CrosshairsTool, ReferenceLinesTool, OverlayGridTool, SegmentationIntersectionTool, BidirectionalTool, LabelTool, LengthTool, HeightTool, ProbeTool, RectangleROITool, EllipticalROITool, CircleROITool, ETDRSGridTool, SplineROITool, PlanarFreehandROITool, PlanarFreehandContourSegmentationTool, LivewireContourTool, LivewireContourSegmentationTool, ArrowAnnotateTool, AngleTool, CobbAngleTool, UltrasoundDirectionalTool, UltrasoundPleuraBLineTool, KeyImageTool, AnnotationEraserTool as EraserTool, RectangleScissorsTool, CircleScissorsTool, SphereScissorsTool, RectangleROIThresholdTool, RectangleROIStartEndThresholdTool, CircleROIStartEndThresholdTool, SplineContourSegmentationTool, BrushTool, MagnifyTool, AdvancedMagnifyTool, PaintFillTool, ScaleOverlayTool, OrientationMarkerTool, SculptorTool, SegmentSelectTool, VolumeRotateTool, RegionSegmentTool, RegionSegmentPlusTool, WholeBodySegmentTool, LabelmapBaseTool, SegmentBidirectionalTool, SegmentLabelTool, LabelMapEditWithContourTool, strategies, };
@@ -57,4 +57,5 @@ import SegmentSelectTool from './segmentation/SegmentSelectTool';
57
57
  import SegmentBidirectionalTool from './segmentation/SegmentBidirectionalTool';
58
58
  import * as strategies from './segmentation/strategies';
59
59
  import SegmentLabelTool from './segmentation/SegmentLabelTool';
60
- export { BaseTool, AnnotationTool, AnnotationDisplayTool, PanTool, TrackballRotateTool, DragProbeTool, WindowLevelTool, WindowLevelRegionTool, StackScrollTool, PlanarRotateTool, ZoomTool, MIPJumpToClickTool, ReferenceCursors, CrosshairsTool, ReferenceLinesTool, OverlayGridTool, SegmentationIntersectionTool, BidirectionalTool, LabelTool, LengthTool, HeightTool, ProbeTool, RectangleROITool, EllipticalROITool, CircleROITool, ETDRSGridTool, SplineROITool, PlanarFreehandROITool, PlanarFreehandContourSegmentationTool, LivewireContourTool, LivewireContourSegmentationTool, ArrowAnnotateTool, AngleTool, CobbAngleTool, UltrasoundDirectionalTool, UltrasoundPleuraBLineTool, KeyImageTool, AnnotationEraserTool as EraserTool, RectangleScissorsTool, CircleScissorsTool, SphereScissorsTool, RectangleROIThresholdTool, RectangleROIStartEndThresholdTool, CircleROIStartEndThresholdTool, SplineContourSegmentationTool, BrushTool, MagnifyTool, AdvancedMagnifyTool, PaintFillTool, ScaleOverlayTool, OrientationMarkerTool, SculptorTool, SegmentSelectTool, VolumeRotateTool, RegionSegmentTool, RegionSegmentPlusTool, WholeBodySegmentTool, LabelmapBaseTool, SegmentBidirectionalTool, SegmentLabelTool, strategies, };
60
+ import LabelMapEditWithContourTool from './segmentation/LabelmapEditWithContour';
61
+ export { BaseTool, AnnotationTool, AnnotationDisplayTool, PanTool, TrackballRotateTool, DragProbeTool, WindowLevelTool, WindowLevelRegionTool, StackScrollTool, PlanarRotateTool, ZoomTool, MIPJumpToClickTool, ReferenceCursors, CrosshairsTool, ReferenceLinesTool, OverlayGridTool, SegmentationIntersectionTool, BidirectionalTool, LabelTool, LengthTool, HeightTool, ProbeTool, RectangleROITool, EllipticalROITool, CircleROITool, ETDRSGridTool, SplineROITool, PlanarFreehandROITool, PlanarFreehandContourSegmentationTool, LivewireContourTool, LivewireContourSegmentationTool, ArrowAnnotateTool, AngleTool, CobbAngleTool, UltrasoundDirectionalTool, UltrasoundPleuraBLineTool, KeyImageTool, AnnotationEraserTool as EraserTool, RectangleScissorsTool, CircleScissorsTool, SphereScissorsTool, RectangleROIThresholdTool, RectangleROIStartEndThresholdTool, CircleROIStartEndThresholdTool, SplineContourSegmentationTool, BrushTool, MagnifyTool, AdvancedMagnifyTool, PaintFillTool, ScaleOverlayTool, OrientationMarkerTool, SculptorTool, SegmentSelectTool, VolumeRotateTool, RegionSegmentTool, RegionSegmentPlusTool, WholeBodySegmentTool, LabelmapBaseTool, SegmentBidirectionalTool, SegmentLabelTool, LabelMapEditWithContourTool, strategies, };
@@ -0,0 +1,21 @@
1
+ import PlanarFreehandContourSegmentationTool from '../annotation/PlanarFreehandContourSegmentationTool';
2
+ import type { PublicToolProps } from '../../types';
3
+ declare class LabelMapEditWithContourTool extends PlanarFreehandContourSegmentationTool {
4
+ static toolName: string;
5
+ static annotationsToViewportMap: Map<any, any>;
6
+ private onViewportAddedToToolGroupBinded;
7
+ private onSegmentationModifiedBinded;
8
+ static viewportIdsChecked: any[];
9
+ constructor(toolProps?: PublicToolProps);
10
+ protected initializeListeners(): void;
11
+ protected cleanUpListeners(): void;
12
+ protected checkContourSegmentation(viewportId: string): Promise<boolean>;
13
+ protected onViewportAddedToToolGroup(evt: any): void;
14
+ protected onSegmentationModified(evt: any): void;
15
+ onSetToolEnabled(): void;
16
+ onSetToolActive(): void;
17
+ onSetToolDisabled(): void;
18
+ annotationModified(evt: any): void;
19
+ annotationCompleted(evt: any): void;
20
+ }
21
+ export default LabelMapEditWithContourTool;
@@ -0,0 +1,117 @@
1
+ import { Events, SegmentationRepresentations } from '../../enums';
2
+ import { eventTarget, utilities, getRenderingEngine, } from '@cornerstonejs/core';
3
+ import PlanarFreehandContourSegmentationTool from '../annotation/PlanarFreehandContourSegmentationTool';
4
+ import BrushTool from './BrushTool';
5
+ import * as segmentation from '../../stateManagement/segmentation';
6
+ import { getSegmentationRepresentationsBySegmentationId } from '../../stateManagement/segmentation/getSegmentationRepresentation';
7
+ class LabelMapEditWithContourTool extends PlanarFreehandContourSegmentationTool {
8
+ static { this.toolName = 'LabelMapEditWithContour'; }
9
+ static { this.annotationsToViewportMap = new Map(); }
10
+ static { this.viewportIdsChecked = []; }
11
+ constructor(toolProps = {}) {
12
+ const initialProps = utilities.deepMerge({
13
+ configuration: {
14
+ calculateStats: false,
15
+ allowOpenContours: false,
16
+ },
17
+ }, toolProps);
18
+ super(initialProps);
19
+ this.onViewportAddedToToolGroupBinded =
20
+ this.onViewportAddedToToolGroup.bind(this);
21
+ this.onSegmentationModifiedBinded = this.onSegmentationModified.bind(this);
22
+ }
23
+ initializeListeners() {
24
+ LabelMapEditWithContourTool.annotationsToViewportMap.clear();
25
+ LabelMapEditWithContourTool.viewportIdsChecked = [];
26
+ eventTarget.addEventListener(Events.ANNOTATION_MODIFIED, this.annotationModified);
27
+ eventTarget.addEventListener(Events.ANNOTATION_COMPLETED, this.annotationCompleted);
28
+ eventTarget.addEventListener(Events.TOOLGROUP_VIEWPORT_ADDED, this.onViewportAddedToToolGroupBinded);
29
+ eventTarget.addEventListener(Events.SEGMENTATION_MODIFIED, this.onSegmentationModifiedBinded);
30
+ }
31
+ cleanUpListeners() {
32
+ LabelMapEditWithContourTool.annotationsToViewportMap.clear();
33
+ LabelMapEditWithContourTool.viewportIdsChecked = [];
34
+ eventTarget.removeEventListener(Events.ANNOTATION_MODIFIED, this.annotationModified);
35
+ eventTarget.removeEventListener(Events.ANNOTATION_COMPLETED, this.annotationCompleted);
36
+ eventTarget.removeEventListener(Events.TOOLGROUP_VIEWPORT_ADDED, this.onViewportAddedToToolGroup.bind(this));
37
+ eventTarget.removeEventListener(Events.SEGMENTATION_MODIFIED, this.onSegmentationModified.bind(this));
38
+ }
39
+ async checkContourSegmentation(viewportId) {
40
+ if (LabelMapEditWithContourTool.viewportIdsChecked.includes(viewportId)) {
41
+ return;
42
+ }
43
+ const activeSeg = segmentation.getActiveSegmentation(viewportId);
44
+ if (!activeSeg) {
45
+ console.log('No active segmentation detected');
46
+ return false;
47
+ }
48
+ const segmentationId = activeSeg.segmentationId;
49
+ if (!activeSeg.representationData.Contour) {
50
+ LabelMapEditWithContourTool.viewportIdsChecked.push(viewportId);
51
+ await segmentation.addContourRepresentationToViewport(viewportId, [
52
+ {
53
+ segmentationId,
54
+ type: SegmentationRepresentations.Contour,
55
+ },
56
+ ]);
57
+ segmentation.addRepresentationData({
58
+ segmentationId,
59
+ type: SegmentationRepresentations.Contour,
60
+ data: {},
61
+ });
62
+ }
63
+ return true;
64
+ }
65
+ onViewportAddedToToolGroup(evt) {
66
+ const { toolGroupId, viewportId } = evt.detail;
67
+ if (toolGroupId !== this.toolGroupId) {
68
+ return;
69
+ }
70
+ this.checkContourSegmentation(viewportId);
71
+ }
72
+ onSegmentationModified(evt) {
73
+ const { segmentationId } = evt.detail || {};
74
+ if (!segmentationId) {
75
+ return;
76
+ }
77
+ const representations = getSegmentationRepresentationsBySegmentationId(segmentationId);
78
+ if (!representations) {
79
+ return;
80
+ }
81
+ representations.forEach(async ({ viewportId }) => await this.checkContourSegmentation(viewportId));
82
+ }
83
+ onSetToolEnabled() {
84
+ this.initializeListeners();
85
+ }
86
+ onSetToolActive() {
87
+ this.initializeListeners();
88
+ }
89
+ onSetToolDisabled() {
90
+ this.cleanUpListeners();
91
+ }
92
+ annotationModified(evt) {
93
+ const { annotation, renderingEngineId, viewportId } = evt.detail;
94
+ const viewport = getRenderingEngine(renderingEngineId)?.getViewport(viewportId);
95
+ if (!viewport) {
96
+ return;
97
+ }
98
+ LabelMapEditWithContourTool.annotationsToViewportMap.set(annotation.annotationUID, viewport);
99
+ }
100
+ annotationCompleted(evt) {
101
+ const { annotation } = evt.detail;
102
+ const { polyline } = annotation.data?.contour || {};
103
+ if (annotation?.metadata?.toolName !== LabelMapEditWithContourTool.toolName) {
104
+ return;
105
+ }
106
+ if (!polyline) {
107
+ return;
108
+ }
109
+ if (LabelMapEditWithContourTool.annotationsToViewportMap.has(annotation.annotationUID)) {
110
+ const viewport = LabelMapEditWithContourTool.annotationsToViewportMap.get(annotation.annotationUID);
111
+ if (polyline.length > 3) {
112
+ BrushTool.viewportContoursToLabelmap(viewport);
113
+ }
114
+ }
115
+ }
116
+ }
117
+ export default LabelMapEditWithContourTool;
@@ -1 +1 @@
1
- export declare const version = "3.19.0";
1
+ export declare const version = "3.19.1";
@@ -1 +1 @@
1
- export const version = '3.19.0';
1
+ export const version = '3.19.1';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cornerstonejs/tools",
3
- "version": "3.19.0",
3
+ "version": "3.19.1",
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.1.0"
109
109
  },
110
110
  "peerDependencies": {
111
- "@cornerstonejs/core": "^3.19.0",
111
+ "@cornerstonejs/core": "^3.19.1",
112
112
  "@kitware/vtk.js": "32.12.1",
113
113
  "@types/d3-array": "^3.0.4",
114
114
  "@types/d3-interpolate": "^3.0.1",
@@ -127,5 +127,5 @@
127
127
  "type": "individual",
128
128
  "url": "https://ohif.org/donate"
129
129
  },
130
- "gitHead": "fe1658758c774bc78e81a8a0e5933111ee2665b4"
130
+ "gitHead": "bbd1940e51060d73897b9f9021c8453ac928550f"
131
131
  }