All files / packages/tools/src/utilities/segmentation invalidateBrushCursor.ts

80% Statements 12/15
50% Branches 2/4
66.66% Functions 2/3
80% Lines 12/15

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49                            2x   2x       2x   2x           2x   2x 2x     2x       2x       2x   2x   2x    
import { getToolGroup } from '../../store/ToolGroupManager';
import BrushTool from '../../tools/segmentation/BrushTool';
import triggerAnnotationRenderForViewportIds from '../triggerAnnotationRenderForViewportIds';
import { getRenderingEngine } from '@cornerstonejs/core';
import { getBrushToolInstances } from './utilities';
 
/**
 * Invalidates the brush cursor for a specific tool group.
 * This function triggers the update of the brush being rendered.
 * It also triggers an annotation render for any viewports on the tool group.
 *
 * @param toolGroupId - The ID of the tool group.
 */
export function invalidateBrushCursor(toolGroupId: string): void {
  const toolGroup = getToolGroup(toolGroupId);
 
  Iif (toolGroup === undefined) {
    return;
  }
 
  const brushBasedToolInstances = getBrushToolInstances(toolGroupId);
 
  brushBasedToolInstances.forEach((tool: BrushTool) => {
    // Invalidate the brush being rendered so it can update.
    tool.invalidateBrushCursor();
  });
 
  // Trigger an annotation render for any viewports on the toolgroup
  const viewportsInfo = toolGroup.getViewportsInfo();
 
  const viewportsInfoArray = Object.keys(viewportsInfo).map(
    (key) => viewportsInfo[key]
  );
 
  Iif (!viewportsInfoArray.length) {
    return;
  }
 
  const { renderingEngineId } = viewportsInfoArray[0];
 
  // Use helper to get array of viewportIds, or we just end up doing this mapping
  // ourselves here.
  const viewportIds = toolGroup.getViewportIds();
 
  const renderingEngine = getRenderingEngine(renderingEngineId);
 
  triggerAnnotationRenderForViewportIds(renderingEngine, viewportIds);
}