前言:
最近特别忙,又涉及到换工作的问题,导致好长时间也没有更新过了。今天做公司的项目,遇到一些cornerstoneTools的问题。那我想,不如就续上以前的坑算了,今天就来随便说说cornerstoneTools的stateManagement
(一)有几种stateManagement?
现在用的是cornerstoneTools@3.18.4,有globalImageIdSpecificToolStateManager和stackSpecificStateManager,它俩定义是这样的
const stackSpecificStateManager = newStackSpecificToolStateManager( stackTools, oldStateManager );stackStateManagers.push(stackSpecificStateManager);
const globalImageIdSpecificToolStateManager = newImageIdSpecificToolStateManager();
先说globalImageIdSpecificToolStateManager吧
(二)globalImageIdSpecificToolStateManager
先来看它所在js文件imageIdSpecificStateManager.js开头的一句话
/** * Implements an imageId specific tool state management strategy. This means that * Measurements data is tied to a specific imageId and only visible for enabled elements * That are displaying that imageId. * 实现一个图像 ID 指定 的工具状态管理策略。 这意味着测量数据与特定图像 ID 是绑定的,
* 并且仅对显示该图像 ID 的已启用元素可见。
*/
相信熟悉cornerstoneTools中annotationTools的小伙伴已经能猜到这是什么东西了,没错,就是在annotationTools里经常用的取toolData的那个stateManage,里面定义了常用的存取annotation工具数据方法
function saveImageIdToolState(imageId) { return toolState[imageId]; } function restoreImageIdToolState(imageId, imageIdToolState) { toolState[imageId] = imageIdToolState; } function saveToolState() { return toolState; } function restoreToolState(savedToolState) { toolState = savedToolState; }
function addImageIdSpecificToolState(element, toolType, data) {}
function getImageIdSpecificToolState(element, toolType) {} function clearImageIdSpecificToolStateManager(element) {}
看着这些名字熟悉吗?(不熟悉cornerstoneTools的同学就当我没说)
然后咱们来看第二个stateManager
(二)stackSpecificStateManager
这玩意儿我真是不常用的,但是写高级工具的时候总会碰到,今天就来做个了断(实在不行就开个头)。
先看import
import { globalImageIdSpecificToolStateManager } from './imageIdSpecificStateManager.js';import { getElementToolStateManager, setElementToolStateManager,} from './toolState.js';
看到没,这玩意儿依赖上面提到的globalImageIdSpecificToolStateManager
再看下面那个import,toolState.js,就是globalImageIdSpecificToolStateManager的代理壳子
然后是介绍
/* Implements an Stack specific tool state management strategy. This means * That tool data is shared between all imageIds in a given stack. * 实现特定于 Stack 的工具状态管理策略,这意味着工具数据在给定堆栈中的所有 imageId 之间共享。
*/
说的明白不?
(三)总结
不好意思,前面两节是前几天后半夜写的,脑子已经不清醒了,难得今天不忙,我就来用人话总结一下imageIdSpecificStateManager与stackSpecificStateManager的区别,
imageIdSpecificStateManager这个玩意儿是用imageId做key来保存对应图像的各种工具数据的,数据结构是这样的
let toolState = {};toolState[imageId] = {};
toolState[imageId][toolName] = {data:[measurementData1, measurementData2, measurementData3, ...]}
然后提供了几个api
get: getImageIdSpecificToolState,add: addImageIdSpecificToolState,clear: clearImageIdSpecificToolStateManager,saveImageIdToolState,
restoreImageIdToolState,saveToolState,restoreToolState,toolState,
stackSpecificStateManager这个玩意儿是用来存不对应ImageId的工具数据的。想想,之前那个东西存所有的数据是不是都要用imageId当作key?这个玩意儿不用,而且内置了8个工具类型
let stackTools = [ 'stack', 'stackPrefetch', 'playClip', 'volume', 'slab', 'referenceLines', 'crosshairs', 'stackRenderer', ];
如果有需要,还可以追加自定义类型。
提供的api上也是差不多,而且,如果你提供的工具名称(工具类型)在stackTools里没有,它会从imageIdSpecificStateManager里给你找。
好了,这期分享就到这里了。