cornerstoneTools: How to trigger a tool recalculation after 'addToolState' for RectangleRoiTool?

Prerequisites

  • Are you running the latest version?
  • Are you reporting to the correct repository?
  • Did you perform a cursory search?

For more information, see the CONTRIBUTING guide.

Description

I am working currently on a tool that has to calculate a volume, this means, I draw an area using the RectangleRoiTool, and then I have to replicate that area on X number of images. I am doing this by using addToolState on each image, using the toolState from the area I created. The problem is, when the script scrolls to the next image and adds the tool state, it doesn’t recalculate the Mean and StdDev of the current image, but it is saving the data from the created area. Is there an option to recalculate the state once it is added? Specifically for the RectangleRoiTool.

Thanks!

Steps to Reproduce

  1. Draw a rectangle using RectangleRoiTool.
  2. Save the tool state on a variable.
  3. Add the saved tool state on any other image. The calculations are still the ones from the variable, not the ones that should be from this new image.

Expected behavior: Once the tool state is added, it should recalculate the information from this new image.

Actual behavior: After setting the tool state, the information from the saved state is static, no recalculation is being triggered.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 18 (9 by maintainers)

Most upvoted comments

Hi @JamesAPetts, I think it is an excellent idea, mainly because right now it is complicated to achieve what I wanted, though it was relatively easy to accomplish, I think this would resolve a lot of issues.

Hi @dannyrb. For now is OK. I will work in the future on a PR to have an automated method to accomplish this without any of these processes. I will let you know. Thanks!

👋 Hi @pzehle, I’m going to close this issue for now. It sounds like there’s an “okay” workaround that helped you accomplish your goal.

If you think there’s an improvement we can make to simplify this, please feel free to create a separate discussion issue for the change.

Hello @dannyrb, as always, thank you very much.

I managed to accomplish this setting invalidated as true and cachedStats as undefined as you suggested. I was having the problem of the tool still not updating, but I’ve restructured my process with a lot of promises, and have a timeout to wait for the tool to recalculate, this was the trick.

I will work on the PR you suggested to add this functionality. Thanks!

How are you console.log()-ing? I could be wrong, but for objects I think the value is evaluated when you expand the object in the console, not at the time of logging.

When you restore state, are you making sure invalidated is true and cachedStats is undefined?