react-cornerstone-viewport icon indicating copy to clipboard operation
react-cornerstone-viewport copied to clipboard

Question: Would there be any example for consuming a custom cornerstone tool please?

Open getnsv opened this issue 5 years ago • 3 comments

Hi @dannyrb ,

Am trying to create a custom tool using cornerstone base tool. Got the code from https://tools.cornerstonejs.org/custom-tools/#creating-your-tool.

But am stuck on how to consume this, as just using the below is giving me an exception. the variable is undefined...

const MyTool = cornerstoneTools.MyTool; //is coming undefined and hence exception cornerstoneTools.addTool(MyTool); cornerstoneTools.setToolActive('myTool', { mouseButtonMask: 1 });

Any guidance will be very helpful.

thanks, Sreevani

getnsv avatar Sep 03 '20 11:09 getnsv

Hi, also trying to create a custom tool.

Code Sandbox: https://codesandbox.io/s/thirsty-payne-fpc5f?file=/src/initCornerstone.js

Using example tool from https://tools.cornerstonejs.org/custom-tools/#event-dispatcher-callbacks and followed steps from https://github.com/cornerstonejs/react-cornerstone-viewport/issues/63

Expected behavior: console log upon mouse click, initial console log upon tool activation.

Actual behavior: Unable to find tool "HelloWorldMouse" for enabledElement + none of the expected actions

lennart-g avatar Jan 19 '22 14:01 lennart-g

By the way, the long term goal is to write my own annotation tools (more simplistic than the currently provided ones), I hope I'm on the right track with the above.

Thanks

lennart-g avatar Jan 19 '22 15:01 lennart-g

Moved the tool adding part to the Viewports onElementEnabled event and now everything works. Code in the sandbox is updated. I guess this also answers the question for the thread author.

lennart-g avatar Jan 19 '22 22:01 lennart-g