cornerstonejs / cornerstoneTools

A framework for tools built on top of Cornerstone.
https://tools.cornerstonejs.org/
MIT License
574 stars 456 forks source link

zoom tool ERROR - Zoom out is not working as expected #1353

Open marcosnode1990 opened 3 years ago

marcosnode1990 commented 3 years ago

Description

The zoom tool is presenting a problem using an MG instance. the zoom tool is not zooming out as it should.

Steps to Reproduce the issue

Just add the zoom tool as shown in the code below:

<script>

// Externals
  cornerstoneWADOImageLoader.external.cornerstone = cornerstone;
  cornerstoneWADOImageLoader.external.dicomParser = dicomParser;            
  cornerstoneTools.external.cornerstoneMath = cornerstoneMath;
  cornerstoneWebImageLoader.external.cornerstone = cornerstone;
  cornerstoneTools.external.cornerstone = cornerstone;
  cornerstoneTools.external.Hammer = Hammer;

      const cTools = cornerstoneTools.init({mouseEnabled: true, showSVGCursors: true});
      const element = document.getElementById('cornerstone-element');

      cornerstone.enable(element);

            const imageIds = [
      'wadouri:http://127.0.0.1:8080/assets/dicom/08'
            ];

            const stack = {
                currentImageIdIndex: 0,
                imageIds: imageIds,
            };

            element.tabIndex = 0;
            element.focus();

            cornerstone.loadImage(imageIds[0]).then(function(image) {
                cornerstoneTools.addStackStateManager(element, ['stack']);
                cornerstoneTools.addToolState(element, 'stack', stack);
        cornerstone.displayImage(element, image);
            });

            cTools.addEnabledElement(element);

      const toolName = 'zoom';
            //const toolName = 'probe';

            // Add the tool
            cTools.addToolForElement(element, cornerstoneTools[`${toolName}Tool`]);
            cTools.setToolEnabledForElement(element, toolName);
            cTools.setToolActiveForElement(element, toolName, { mouseButtonMask: 1, isTouchActive: true, isMouseActive: true });
 </script>

Expected behavior: (What you expected to happen) https://www.loom.com/share/af0d2609dabf499ca5d64db134736bff Actual behavior: (What actually happened) https://www.loom.com/share/5f0034a5a47c441aa81703cac78f831d

I also attach an anonymized instance of a DICOM study. 08.zip

alimorsy commented 3 years ago

Hey, this is more than a month after your post but I had this exact same issue (with MG instances as well) and figured out the solution:

The Zoom tool comes with a default config that specifies the minimum value the tool will work for (minScale: 0.25x). MG instances usually start with a default zoom way below that. Activating the tool will cause your image to zoom out (or jump) to the 0.25x scale then will refuse to let you go below it. The solution is to explicitly set the tool's config when enabling it as such:

cornerstoneTools.addToolForElement(<YOUR ELEMENT>, cornerstoneTools.ZoomTool, { configuration: { invert: true, preventZoomOutsideImage: false, minScale: <YOUR DESIRED MINIMUM HERE>, maxScale: 20.0, } });