cornerstoneTools
cornerstoneTools copied to clipboard
Reset cornerstone before loading new image.
I have a website where I need to load the next image-stack after working on the first one (without reloading the entire page). How do I reset cornerstone including all tools.
I tried the following:
cornerstoneTools.globalImageIdSpecificToolStateManager.restoreToolState({}); cornerstone.disable(element); stack = {}; cornerstone.enable(element);
Loading the next image works and the tool annotations are gone. However, the tools do not work anymore.
Readding the tools using addTool() and then calling setToolActive() does not work.
What is the prefered method to reset and reload the next image?
Transfering this issue to the cornerstone-tools
repository.
@hubtub2, most toolState / annotations are specific to an imageId
. If you're viewing a new stack of different imageIds, you likely don't need to clear tool state. I also believe there's clearToolState
if you need something more granular.
When you disable
an element, cornerstone-tools
should tear down all of it's tool additions. enable
should give you a clean slate you can addTool
and setToolActive
before. If you're encountering issues and can provide a reproduction, this may be worth a bug fix PR. Lastly, if you want addTool
and setToolActive
to persist across newly enabled elements, you may want to look into the globalToolSyncEnabled option for cornerstone-tools
.
Chances are, you're doing more than you need to. You can likely swap out the image stack and call it a day. Depending on the kind of application you're building, you can see how we handle lifecycle events like this in our react-cornerstone-viewport
, which includes an example for swapping stacks.
It seems like you're asking how to reset cornerstone before loading a new image stack without reloading the entire page. The suggested method for resetting cornerstone and its tools is to disable the element, which should tear down all the tool additions, and then enable it again for a clean slate. If you encounter any issues, you can try using the clearToolState
function, which removes all toolState
from the toolStateManager
corresponding to the toolName
and element.
You can find more information and examples regarding this issue by following the link to my answer on StackOverflow below:
https://stackoverflow.com/a/73204850/2371987