Clear all annotations with cornerstone-tools

823 Views Asked by At

Using cornerstone-tools, After I load a image, I start to draw some annotations such as angle, rectangle, arrow.

I´d like to know a method to clear all annotations. I try the next but no look

removeAll(element) {
      cornerstoneTools.state.tools.forEach(function (tool) {
        const toolState = cornerstoneTools.getToolState(element, tool.name)
        if (toolState) {
          // Modifying in a foreach? Probably not ideal
          cornerstoneTools.toolState.data.forEach(function (data) {
            cornerstoneTools.removeToolState(element, tool.name, data)
          })
        }
      })
      cornerstone.updateImage(element)
    },
1

There are 1 best solutions below

0
On

To solve this issue, you can use the clearToolState function. You have several examples and issues concerning this problem, that you may follow. However, it seems a good option to use the clearToolState function in your case. The clearToolState function will remove all states from the state manager corresponding to the name and element of that tool.

Indeed, the documentation describes the clearToolState function as:

Removes all toolState from the toolStateManager corresponding to the toolName and element.

It is also important to understand how does [1, 2] the cornerstoneTool store its values. Additionally, you can also follow similar answers when using a new tool or function.

References

[1] Francisco Maria Calisto, Carlos Santiago, Nuno Nunes, and Jacinto C. Nascimento. 2021. Introduction of human-centric AI assistant to aid radiologists for multimodal breast image classification. International Journal of Human-Computer Studies 150, 102607. https://doi.org/10.1016/j.ijhcs.2021.102607

[2] Francisco Maria Calisto, Nuno Nunes, and Jacinto C. Nascimento. 2020. BreastScreening. Proceedings of the International Conference on Advanced Visual Interfaces. https://doi.org/10.1145/3399715.3399744