Skip to content

Commit 464d07d

Browse files
feat(BrushTool): added logic to check for min/max radius while set brush (#2449)
1 parent e5b8e0b commit 464d07d

File tree

1 file changed

+8
-19
lines changed

1 file changed

+8
-19
lines changed

packages/tools/src/utilities/segmentation/brushSizeForToolGroup.ts

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { getToolGroup } from '../../store/ToolGroupManager';
22
import type BrushTool from '../../tools/segmentation/BrushTool';
33
import triggerAnnotationRenderForViewportIds from '../triggerAnnotationRenderForViewportIds';
4-
import { getRenderingEngine } from '@cornerstonejs/core';
54
import { getBrushToolInstances } from './getBrushToolInstances';
65

76
/**
@@ -25,31 +24,21 @@ export function setBrushSizeForToolGroup(
2524
const brushBasedToolInstances = getBrushToolInstances(toolGroupId, toolName);
2625

2726
brushBasedToolInstances.forEach((tool: BrushTool) => {
28-
tool.configuration.brushSize = brushSize;
27+
const minRadius = tool.configuration.minRadius;
28+
const maxRadius = tool.configuration.maxRadius;
29+
30+
let newBrushSize = minRadius ? Math.max(brushSize, minRadius) : brushSize;
31+
newBrushSize = maxRadius ? Math.min(newBrushSize, maxRadius) : newBrushSize;
32+
33+
tool.configuration.brushSize = newBrushSize;
2934

3035
// Invalidate the brush being rendered so it can update.
3136
tool.invalidateBrushCursor();
3237
});
3338

3439
// Trigger an annotation render for any viewports on the toolgroup
35-
const viewportsInfo = toolGroup.getViewportsInfo();
36-
37-
const viewportsInfoArray = Object.keys(viewportsInfo).map(
38-
(key) => viewportsInfo[key]
39-
);
40-
41-
if (!viewportsInfoArray.length) {
42-
return;
43-
}
44-
45-
const { renderingEngineId } = viewportsInfoArray[0];
46-
47-
// Use helper to get array of viewportIds, or we just end up doing this mapping
48-
// ourselves here.
4940
const viewportIds = toolGroup.getViewportIds();
5041

51-
const renderingEngine = getRenderingEngine(renderingEngineId);
52-
5342
triggerAnnotationRenderForViewportIds(viewportIds);
5443
}
5544

@@ -63,7 +52,7 @@ export function setBrushSizeForToolGroup(
6352
export function getBrushSizeForToolGroup(
6453
toolGroupId: string,
6554
toolName?: string
66-
): void {
55+
): number {
6756
const toolGroup = getToolGroup(toolGroupId);
6857

6958
if (toolGroup === undefined) {

0 commit comments

Comments
 (0)