cornerstoneTool.js使用记录五

1,205 阅读1分钟

Segmentation

这系列API是用来截取部位,不过要自己实现。cornerstoneTools.addTool第二个参数可有可无。(PS: 使用这系列会比较卡, 使用这系列的API要添加堆栈)


html

<div id="dicomImage" style="width: 512px;height: 512px;" oncontextmenu="return false" onmousedown="return false"></div>

script

<script src="https://unpkg.com/hammerjs@2.0.8/hammer.js"></script>
<script src="https://unpkg.com/cornerstone-core@2.3.0/dist/cornerstone.js"></script>
<script src="https://unpkg.com/cornerstone-math@0.1.9/dist/cornerstoneMath.min.js"></script>
<script src="https://unpkg.com/cornerstone-wado-image-loader@3.3.1/dist/cornerstoneWADOImageLoader.min.js"></script>
<script src="https://unpkg.com/cornerstone-web-image-loader@2.1.1/dist/cornerstoneWebImageLoader.min.js"></script>
<script src="https://unpkg.com/cornerstone-tools@5.1.4/dist/cornerstoneTools.js"></script>
<script src="https://unpkg.com/dicom-parser@1.8.7/dist/dicomParser.min.js"></script>
<script>
    cornerstoneTools.external.cornerstone = cornerstone;
    cornerstoneTools.external.Hammer = Hammer;
    cornerstoneTools.external.cornerstoneMath = cornerstoneMath;
    cornerstoneWADOImageLoader.external.dicomParser = dicomParser;
    cornerstoneWADOImageLoader.external.cornerstone = cornerstone;
    cornerstoneTools.init([{
        moduleName: 'globalConfiguration',
        configuration: {
            showSVGCursors: true
        }
    }, {
        moduleName: 'segmentation',
        configuration: {
            outlineWidth: 2
        }
    }]);
    
    let el = document.querySelector("#dicomImage");
    
    cornerstone.enable(el);
    
    const imageIds = [
        `wadouri:http://127.0.0.1/download/1.dcm`,
        `wadouri:http://127.0.0.1/download/2.dcm`,
    ];
    const stack = {
        currentImageIdIndex: 0,
        imageIds: imageIds,
    };
    
    cornerstone.loadAndCacheImage(imageIds[0]).then(function(image) {
        cornerstoneTools.addStackStateManager(el, ['stack']); //必须的 Segmentation
        cornerstoneTools.addToolState(el, 'stack', stack); //必须的 Segmentation
        cornerstone.displayImage(el, image);
    });
    
    
    //要想查看它有几种模式
    function getStrategies(element,toolName){
        const ActiveTool = cornerstoneTools.getToolForElement(element,toolName);
        return ActiveTool.strategies;
    }
    //切换使用
    //ActiveTool.setActiveStrategy(ERASE_OUTSIDE);
</script>

BrushTool

点擦除

let BrushTool = cornerstoneTools.BrushTool;
cornerstoneTools.addTool(BrushTool, {
    configuration: {
        alwaysEraseOnClick: false, //点击擦除,true 会没有红点显示, false会出现红点, 但实际上没啥效果
    }
});
cornerstoneTools.setToolActive("Brush", {
    mouseButtonMask: 1
});

CircleScissorsTool

圆擦除(PS:不要直接在添加Tool时改默认Strategy)

let CircleScissorsTool = cornerstoneTools.CircleScissorsTool;
cornerstoneTools.addTool(CircleScissorsTool, {
    defaultStrategy: "FILL_INSIDE", //四种模式  FILL_INSIDE 圈内填充   FILL_OUTSIDE 圈外填充  ERASE_INSIDE 擦除圈内  ERASE_OUTSIDE 擦除圈外
});
cornerstoneTools.setToolActive("CircleScissors", {
    mouseButtonMask: 1
});

FreehandScissorsTool

手绘擦除(PS:不要直接在添加Tool时改默认Strategy)

let FreehandScissorsTool = cornerstoneTools.FreehandScissorsTool; //segmentation
cornerstoneTools.addTool(FreehandScissorsTool, {
    defaultStrategy: "FILL_INSIDE", //四种模式  FILL_INSIDE 圈内填充   FILL_OUTSIDE 圈外填充  ERASE_INSIDE 擦除圈内  ERASE_OUTSIDE 擦除圈外
});
cornerstoneTools.setToolActive("FreehandScissors", {
    mouseButtonMask: 1
});

RectangleScissorsTool

矩形擦除(PS:不要直接在添加Tool时改默认Strategy)

let RectangleScissorsTool = cornerstoneTools.RectangleScissorsTool;
cornerstoneTools.addTool(RectangleScissorsTool, {
    defaultStrategy: "FILL_INSIDE", //四种模式  FILL_INSIDE 圈内填充   FILL_OUTSIDE 圈外填充  ERASE_INSIDE 擦除圈内  ERASE_OUTSIDE 擦除圈外
});
cornerstoneTools.setToolActive("RectangleScissors", {
    mouseButtonMask: 1
});
基本也就这些了。