Communication between components for measurement load
Hello,
I'm working with the segmentation tool and I am now able to save measurements in a JSON format, from the measurement table. Now, I would like to be able to load back these measurements in the viewer, but I am struggling understanding how the different components and packages communicate.
I get how the connectedMeasurementTable (that get information from its state) give information to measurementTable like here
But how could I communicate from the measurementTable to the FreehandMouseTool to create the measurement that was loaded?
Many thanks in advance, Mat
I'm not up to date on how the measurement table's data flow works, but I believe the easiest way to render loaded freehand data is to use CornerstoneTool's addToolState. Because the MeasurementTable is now an extension that should only exist in the cornerstone context, it should be safe to call Cornerstone directly for manipulations like this.
@swederik may be able to provide scope/implementation information if this is something you're interested in contributing back. I believe functionality like this is on our roadmap, as it existed in the previous version.
Thanks for you answer, I am aware of this addToolState method, and of how to create new measurement from x,y coords. But how can I get the tool instance (here freehandMouseTool) in the measurementTable? I think I don't understand what you mean by 'call Cornerstone directly'. I would be happy to create a P.R for this for anyone who is interested in saving/loading measurements.
Hi Mathis,
I think @dannyrb just mean to use cornerstoneTools.addToolState(...) and that it should be automatically added to the measurement table, if the table is monitoring that tool type.
Here is the MeasurementApi itself:
- https://github.com/OHIF/ohif-core/blob/master/src/measurements/classes/MeasurementApi.js#L11
Here is where it is configured in the viewer:
- https://github.com/OHIF/Viewers/blob/5bd3af0cca09eca2be9bc267451acd35d631fc87/src/connectedComponents/Viewer.js#L67
- Tool configuration: https://github.com/OHIF/ohif-core/blob/38547f4f491ba51245f94e281247e44067f57cf6/src/measurements/configuration.js#L13
The way it works is that you configure the API for specific types of tools. If freehand isn't showing up in the table, you need to check the ohif-core tool configuration. I think this can also be overridden at the viewer level.
You basically need to configure the storeMeasurements and retrieveMeasurements functions, which are currently basically no-ops (https://github.com/OHIF/Viewers/blob/5bd3af0cca09eca2be9bc267451acd35d631fc87/src/connectedComponents/Viewer.js#L93).
Here is how we did it in the Meteor version. We were reading any DICOM-SR files that were present in the study and adding any measurements found inside into the MeasurementApi. When we were saving, we were writing out the measurements into a DICOM-SR and using DICOMWeb's STOW-RS to push it back to the PACS. I would like to add this workflow back to the React version, we just haven't had time yet. Similarly, we would like to do the same for DICOM Segmentation files, once we can create them via the brush tools.
- https://github.com/OHIF/Viewers/blob/v1.x/Packages/ohif-measurement-table/client/configuration/dataExchange.js#L25
- https://github.com/OHIF/Viewers/blob/v1.x/Packages/ohif-measurement-table/client/utils/handleSR.js#L28
- https://github.com/OHIF/Viewers/tree/v1.x/Packages/ohif-measurement-table/client/configuration
That would be very usefull for me to be able to write out measurement into a DICOM-SR, and I will certainly dive into in later, but for the moment I want to make simple. Thanks to your advices, I managed to load some data that I previously saved, and display them. But the problem is that the addToolState method takes the 'element' as an argument. With cornerstone method getEnabledElements, I am only able to get the element of the currently displayed image, but not the others. Is there a way of doing this? I tried getEnabledElementsByImageId but it would always return undefined excepted for the currently displayed image.
Thank you very much for the support, I appreciate.
You can add tool state using cornerstoneTools.globalImageIdSpecificToolStateManager.
I think you can do like cornerstoneTools.globalImageIdSpecificToolStateManager.saveToolState and cornerstoneTools.globalImageIdSpecificToolStateManager.restoreToolState, but I don't know if this will trigger the same handlers that addToolState would call. You can see that addToolState also triggers things here: https://github.com/cornerstonejs/cornerstoneTools/blob/7d67e2a944c8fcd29eae58fdb6935eeaff8516f2/src/stateManagement/toolState.js#L42
I tried to use cornerstoneTools.globalImageIdSpecificToolStateManager.
I saved the toolState in the measurementTable with cornerstoneTools.globalImageIdSpecificToolStateManager.saveToolState where I loaded my measurementfile.
But when I try to restore it in the FreehandMouseTool with cornerstoneTools.globalImageIdSpecificToolStateManager.restoreToolState, it seems to be another instance of the globalImageIidSpecificToolStateManager because there isn't any toolState available.
I don't know if you have any clues on this, otherwise I'll try to figure out something else.
Thank you very much again
Oh that's not good. There should only be one instance of cornerstoneTools.
I must be missing something...
In the measurement Table, I store the measurement with
cornerstoneTools.globalImageIdSpecificToolStateManager.saveToolState
(by the way, i find weird that I don't have to import cornerstoneTools and it's still working)
I can access this measurement in any package with
import cornerstoneTools from 'cornerstone-tools';
cornerstoneTools.globalImageIdSpecificToolStateManager.restoreToolState
except in cornerstoneTools. In my FreehandMouseTool, I import it locally with
import {
newImageIdSpecificToolStateManager,
globalImageIdSpecificToolStateManager,
} from '../../stateManagement/imageIdSpecificStateManager.js';
var stateManager = globalImageIdSpecificToolStateManager;
but there is no data stored. Do you know what could be wrong? Otherwise what could be another way to communicate between these two components? Thank you
I solved my problem. globalImageIdSpecificToolStateManager can be used to communicate between these components. Thank you for the support