Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions packages/tools/src/tools/segmentation/SegmentLabelTool.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { getEnabledElement } from '@cornerstonejs/core';
import type { Types } from '@cornerstonejs/core';

import { config as segmentationConfig } from '../../stateManagement/segmentation';

import { BaseTool } from '../base';
import type {
PublicToolProps,
Expand All @@ -14,7 +16,8 @@ import { getActiveSegmentation } from '../../stateManagement/segmentation/active
import { getSegmentIndexAtWorldPoint } from '../../utilities/segmentation';
import { state } from '../../store/state';
import type { Segmentation } from '../../types/SegmentationStateTypes';
import { drawLinkedTextBox as drawLinkedTextBoxSvg } from '../../drawingSvg';
import { drawTextBox as drawTextBoxSvg } from '../../drawingSvg';
import type { Point2 } from 'packages/core/dist/esm/types';

/**
* Represents a tool used for segment selection. It is used to select a segment
Expand Down Expand Up @@ -140,13 +143,18 @@ class SegmentLabelTool extends BaseTool {
}
);
const segment = activeSegmentation.segments[hoveredSegmentIndex];
const color = segmentationConfig.color.getSegmentIndexColor(
viewport.id,
segmentationId,
hoveredSegmentIndex
);
const label = segment?.label;
const canvasCoordinates = viewport.worldToCanvas(worldPoint);
this._editData = {
hoveredSegmentIndex,
hoveredSegmentLabel: label,
canvasCoordinates,
worldPoint,
color,
};

// No need to select background
Expand Down Expand Up @@ -176,24 +184,28 @@ class SegmentLabelTool extends BaseTool {
hoveredSegmentIndex,
hoveredSegmentLabel,
canvasCoordinates,
worldPoint,
color,
} = this._editData;

if (!hoveredSegmentIndex) {
return;
}

const textBoxPosition = viewport.worldToCanvas(worldPoint);
const offset = -15;
const textBoxPosition = [
canvasCoordinates[0] + offset,
canvasCoordinates[1] + offset,
] as Point2;

const boundingBox = drawLinkedTextBoxSvg(
const boundingBox = drawTextBoxSvg(
svgDrawingHelper,
'segmentSelectLabelAnnotation',
'segmentSelectLabelTextBox',
[hoveredSegmentLabel ? hoveredSegmentLabel : '(unnamed segment)'],
[hoveredSegmentLabel ?? '(unnamed segment)'],
textBoxPosition,
[canvasCoordinates],
{},
{}
{
color: `rgba(${color[0]}, ${color[1]}, ${color[2]}, ${color[3]})`,
}
);

const left = canvasCoordinates[0];
Expand Down
Loading