cornerstoneTools icon indicating copy to clipboard operation
cornerstoneTools copied to clipboard

programmatically changing annotations

Open paul-asvb opened this issue 4 years ago • 3 comments

Prerequisites

  • v4.15.1
  • I hope so
  • Found some related issues but most of them had problems with the drawing-function itself.

Description

I want to load annotation from a DB or something similar into the cornerstone Tools and be able to edit them afterwards. I already hooked into the events for saving meta-information about the single annotations.

Is that even possible, i looked through the store and the tools but couldn't even find the store for the annotations.

What am i missing?

paul-asvb avatar Sep 02 '20 13:09 paul-asvb

You probably want to be looking at the ToolStateManager. You can get it by calling:

var el = document.getElementById('CornerstoneElement');
var stateManager = cornerstoneTools.getElementToolStateManager(el);

By default you'll be using the imageIdSpecificStateManager. https://github.com/cornerstonejs/cornerstoneTools/blob/master/src/stateManagement/imageIdSpecificStateManager.js

mikehazell avatar Sep 14 '20 03:09 mikehazell

Thanks for the answer. Got it worked out. Not sure if this is the best solution. SET ArrowAnnotations:

cornerstoneTools.clearToolState(this.element, 'ArrowAnnotator');
MeasurementArray.forEach((measurementData) => {
    cornerstoneTools.addToolState(element, 'ArrowAnnotator', measurementData);
});

GET ArrowAnnotations:

const toolStateManager = cornerstoneTools.getElementToolStateManager(element);
const toolState = toolStateManager.get(element, 'ArrowAnnotator');
const measurementData = toolState.data;

paul-asvb avatar Sep 14 '20 05:09 paul-asvb

As a matter of fact, I have already posted an answer on StackOverflow that addresses this issue:

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

In this answer, I explain how to use the clearToolState function to remove all states from the state manager corresponding to the name and element of that tool. I also provide some references and additional information that you may find helpful. If you have any further questions or concerns, please do not hesitate to ask.

FMCalisto avatar Mar 14 '23 20:03 FMCalisto

i wanted to load annotation from code , below is my sample const annotation = { invalidated: false, // Whether the annotation data has been invalidated by e.g., moving its handles highlighted: true, // Whether the annotation is highlighted by mouse over isVisible: true, annotationUID: "fffeed7b-7816-4d1a-8f51-18202b9f26b1", // The UID of the annotation metadata: { viewPlaneNormal: [-0.06155037366661628, -0.02036620071150582, -0.9978961716381513] as [number, number, number],// The view plane normal of the camera viewUp: [-0.023753562942147255, -0.9994787573814392, 0.021863622590899467] as [number, number, number], // The view up vector of the camera FrameOfReferenceUID: "1.3.12.2.1107.5.19.1.4557795277953746265012973942050562024810235", // viewport's FrameOfReferenceUID the annotation has been drawn on referencedImageId:"wadouri:https://orthanc:[email protected]:8081/instances/38b569cb-22c256f7-07f6e197-08363fab-4ec72194/file", // The image ID the annotation has been drawn on (if applicable) toolName: "Length", // The tool name }, data: { handles: { points: [[-100.56742742147189, -49.25666634824417, 66.16763968193578],[18.712716732979494, 3.2646742334327037, 57.73850862932346]] as [number, number, number][], // The handles points in world coordinates (probe tool = 1 handle = 1 x,y,z point) }, cachedStats: { "imageId:wadouri:https://orthanc:[email protected]:8081/instances/38b569cb-22c256f7-07f6e197-08363fab-4ec72194/file": { "length": 130.60357673626444, "unit": "mm" } }, // Stored Statistics for the annotation }, } cornerstoneTools.annotation.state.addAnnotation(annotation, imageSegment); const toolGroup = ToolGroupManager.createToolGroup(this.toolGroupId); toolGroup.addTool(ZoomTool.toolName);
toolGroup.addTool(PanTool.toolName);
toolGroup.addTool(StackScrollMouseWheelTool.toolName , { loop: true }); toolGroup.addTool(ArrowAnnotateTool.toolName); toolGroup.addTool(StackScrollTool.toolName, { loop: true }) toolGroup.addTool(LengthTool.toolName, { loop: true })

toolGroup.setToolActive(StackScrollMouseWheelTool.toolName);
toolGroup.setToolActive(StackScrollTool.toolName, { bindings: [ { mouseButton: MouseBindings.Primary } ] });

await toolGroup.addViewport('RESULT-PREVIEW-STACK', resultPreviewStackCornerstone3DRenderingEngine);

const viewport = <Types.IStackViewport>(await renderingEngine.getViewport(resultPreviewStackRenderingEngineId));
await viewport.setStack( seriesInstanceUrls, liverLesionSliceIndex );
await viewport.render(); annotation not displaying on the image segement. kindly provide me the sample to draw length annotation from code

manimarangit avatar Aug 22 '24 07:08 manimarangit