This commit is contained in:
mozzie 2023-12-22 13:20:48 +08:00
parent f245d3c210
commit 2761357eac
2 changed files with 53 additions and 35 deletions

View File

@ -90,9 +90,6 @@ export const CrosshairMpr = (props: CrosshairMprProps) => {
const renderingEngine = useRef<RenderingEngine>(); const renderingEngine = useRef<RenderingEngine>();
const imageIds = useRef<string[]>(); const imageIds = useRef<string[]>();
cornerstoneTools.addTool(StackScrollMouseWheelTool);
cornerstoneTools.addTool(CrosshairsTool);
const run = async () => { const run = async () => {
initDemo(); initDemo();
@ -107,7 +104,7 @@ export const CrosshairMpr = (props: CrosshairMprProps) => {
// Define a volume in memory // Define a volume in memory
const volume = await volumeLoader.createAndCacheVolume(volumeId, { const volume = await volumeLoader.createAndCacheVolume(volumeId, {
imageIds: imageIds.current, imageIds: imageIds.current ?? [],
}); });
// Instantiate a rendering engine // Instantiate a rendering engine
@ -146,6 +143,8 @@ export const CrosshairMpr = (props: CrosshairMprProps) => {
renderingEngine.current.setViewports(viewportInputArray); renderingEngine.current.setViewports(viewportInputArray);
console.log(volume);
// Set the volume to load // Set the volume to load
volume.load(); volume.load();
@ -164,31 +163,33 @@ export const CrosshairMpr = (props: CrosshairMprProps) => {
// Define tool groups to add the segmentation display tool to // Define tool groups to add the segmentation display tool to
const toolGroup = ToolGroupManager.createToolGroup(toolGroupId); const toolGroup = ToolGroupManager.createToolGroup(toolGroupId);
// For the crosshairs to operate, the viewports must currently be if (toolGroup) {
// added ahead of setting the tool active. This will be improved in the future. // For the crosshairs to operate, the viewports must currently be
toolGroup.addViewport(viewportId1, renderingEngineId); // added ahead of setting the tool active. This will be improved in the future.
toolGroup.addViewport(viewportId2, renderingEngineId); toolGroup.addViewport(viewportId1, renderingEngineId);
toolGroup.addViewport(viewportId3, renderingEngineId); toolGroup.addViewport(viewportId2, renderingEngineId);
toolGroup.addViewport(viewportId3, renderingEngineId);
// Manipulation Tools // Manipulation Tools
toolGroup.addTool(StackScrollMouseWheelTool.toolName); toolGroup.addTool(StackScrollMouseWheelTool.toolName);
// Add Crosshairs tool and configure it to link the three viewports // Add Crosshairs tool and configure it to link the three viewports
// These viewports could use different tool groups. See the PET-CT example // These viewports could use different tool groups. See the PET-CT example
// for a more complicated used case. // for a more complicated used case.
toolGroup.addTool(CrosshairsTool.toolName, { toolGroup.addTool(CrosshairsTool.toolName, {
getReferenceLineColor, getReferenceLineColor,
getReferenceLineControllable, getReferenceLineControllable,
getReferenceLineDraggableRotatable, getReferenceLineDraggableRotatable,
getReferenceLineSlabThicknessControlsOn, getReferenceLineSlabThicknessControlsOn,
}); });
toolGroup.setToolActive(CrosshairsTool.toolName, { toolGroup.setToolActive(CrosshairsTool.toolName, {
bindings: [{ mouseButton: 1 }], bindings: [{ mouseButton: 1 }],
}); });
// As the Stack Scroll mouse wheel is a tool using the `mouseWheelCallback` // As the Stack Scroll mouse wheel is a tool using the `mouseWheelCallback`
// hook instead of mouse buttons, it does not need to assign any mouse button. // hook instead of mouse buttons, it does not need to assign any mouse button.
toolGroup.setToolActive(StackScrollMouseWheelTool.toolName); toolGroup.setToolActive(StackScrollMouseWheelTool.toolName);
}
renderingEngine.current.renderViewports([ renderingEngine.current.renderViewports([
viewportId1, viewportId1,
@ -198,14 +199,36 @@ export const CrosshairMpr = (props: CrosshairMprProps) => {
}; };
useEffect(() => { useEffect(() => {
cornerstoneTools.addTool(StackScrollMouseWheelTool);
cornerstoneTools.addTool(CrosshairsTool);
console.log("添加tool1");
run(); run();
return () => {
// TODO: 是否需要写在组件,根据页面需要
console.log("卸载tool2");
cornerstoneTools.removeTool(StackScrollMouseWheelTool);
cornerstoneTools.removeTool(CrosshairsTool);
};
}, []); }, []);
useEffect(() => { useEffect(() => {
window.addEventListener("resize", () => { window.addEventListener("resize", () => {
renderingEngine.current?.resize(); renderingEngine.current?.resize();
}); });
}); }, []);
const test = () => {
// console.log(volumeLoader)
console.log(cornerstone.cache.getVolume(volumeId).getScalarData());
};
useEffect(() => {
document.addEventListener(Enums.Events.VOLUME_CACHE_VOLUME_ADDED, () => {
console.log(111);
});
}, []);
return ( return (
<div> <div>
@ -214,6 +237,7 @@ export const CrosshairMpr = (props: CrosshairMprProps) => {
<div style={{ width: 300, height: 300 }} ref={viewportId2Ref}></div> <div style={{ width: 300, height: 300 }} ref={viewportId2Ref}></div>
<div style={{ width: 300, height: 300 }} ref={viewportId3Ref}></div> <div style={{ width: 300, height: 300 }} ref={viewportId3Ref}></div>
</div> </div>
<button onClick={test}></button>
</div> </div>
); );
}; };

View File

@ -26,14 +26,8 @@ export default function initCornerstoneDICOMImageLoader() {
}, },
}); });
let maxWebWorkers = 1; const config = {
maxWebWorkers: navigator.hardwareConcurrency ? Math.min(navigator.hardwareConcurrency, 7) : 1,
if (navigator.hardwareConcurrency) {
maxWebWorkers = Math.min(navigator.hardwareConcurrency, 7);
}
var config = {
maxWebWorkers,
startWebWorkersOnDemand: false, startWebWorkersOnDemand: false,
taskConfiguration: { taskConfiguration: {
decodeTask: { decodeTask: {