All files / packages/tools/src/tools/displayTools/Contour removeContourFromElement.ts

0% Statements 0/6
0% Branches 0/3
0% Functions 0/2
0% Lines 0/6

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                                                                           
import { getEnabledElement } from '@cornerstonejs/core';
import type { Types } from '@cornerstonejs/core';
 
/**
 * Remove the contour representation from the viewport's HTML Element.
 * NOTE: This function should not be called directly.
 *
 * @param element - The element that the segmentation is being added to.
 * @param segmentationRepresentationUID - The UID of the contour representation to remove.
 * @param removeFromCache - boolean
 *
 * @internal
 */
function removeContourFromElement(
  element: HTMLDivElement,
  segmentationRepresentationUID: string,
  removeFromCache = false // Todo
): void {
  const enabledElement = getEnabledElement(element);
  const { viewport } = enabledElement;
 
  const actorEntries = (viewport as Types.IVolumeViewport).getActors();
 
  // remove actors whose id has the same prefix as the segmentationRepresentationUID
  const actorUIDsToRemove = actorEntries
    .map(({ uid }) =>
      uid.includes(segmentationRepresentationUID) ? uid : undefined
    )
    .filter(Boolean);
 
  // @ts-ignore
  viewport.removeActors(actorUIDsToRemove);
 
  // Todo: add the logic to remove the svg contour segmentation representations as well
}
 
export default removeContourFromElement;