cornerstoneTools icon indicating copy to clipboard operation
cornerstoneTools copied to clipboard

How to clear the length tool and ellipsoid tool marks on click?

Open QeassureGitHub opened this issue 5 years ago • 2 comments

Prerequisites

  • [x] Which version are you using? (Is it latest?)
  • [x] Are you reporting to the correct repository?
  • [ ] Did you search existing issues? (Were any related?)

Description

I want to clear the selected mark which is done by tools on select. Now, I am using clearToolstate API. It will clear all the markings done by tools. cornerstoneTools.clearToolState(this.element, "Length");

Steps to Reproduce the issue

  1. first I enable the length tool and mark some changes(I draw more than one line)
  2. Then I clear it using the ClearToolState
  3. It will clear all the markings.

Expected behavior: I expect to clear the specific mark rather than clear all the markings.

Actual behavior: The clearToolState clear all the markings done by the length tool

CodeSandbox With Reproduction of Issue:

QeassureGitHub avatar Jul 07 '20 10:07 QeassureGitHub

This problem is realized?

WangLei802 avatar Aug 20 '21 07:08 WangLei802

To clear a specific mark made by a tool, you can use the removeToolState function instead of clearToolState. The removeToolState function will remove a specific tool state from the state manager corresponding to the name, element, and toolIndex of that tool.

Here's an example of how you can use the removeToolState function for the Length tool:

const toolStateManager = cornerstoneTools.globalImageIdSpecificToolStateManager;
const element = document.getElementById('example');
const toolName = 'Length';
const toolIndex = 0;
const data = toolStateManager.get(element, toolName);
data.data.splice(toolIndex, 1);
toolStateManager.save(element);
cornerstone.updateImage(element);

Note that you'll need to use cornerstoneTools.globalImageIdSpecificToolStateManager instead of cornerstoneTools.getElementToolStateManager to access the tool state manager for the ImageId specific state. Also, cornerstone.updateImage is called to redraw the image after the mark is removed.

In case you want to learn more about this issue, I suggest reading the answer I wrote on StackOverflow, which provides more information and references to other related materials:

https://stackoverflow.com/a/73204850/2371987

FMCalisto avatar Mar 14 '23 20:03 FMCalisto