cornerstoneTools icon indicating copy to clipboard operation
cornerstoneTools copied to clipboard

how to reset the enable element

Open girlfighting opened this issue 4 years ago • 2 comments

how to reset the enable element? Remove the effect of dragging or zooming, and restore the position and size

girlfighting avatar Jul 05 '21 07:07 girlfighting

Do you still need help?

import cornerstone from 'cornerstone-core'
import cornerstoneTools, {
  clearToolState,
  getToolState
} from 'cornerstone-tools'

const reset = () => {
    const originalSeriesElement = document.getElementById('cornerstone-target')
    const stackData = getToolState(originalSeriesElement, 'stack')
    if (!stackData || !stackData.data || !stackData.data.length) return
    scrollToIndex(originalSeriesElement, 0)
    cornerstone.reset(originalSeriesElement)
  }

// some tools like ScaleOverlay need to be handled separately
// myTools: all of tools i added
const clearTool = () => {
    const element = document.getElementById('cornerstone-target')
    myTools.forEach((el) => {
      clearToolState(element, el.name)
    })
    cornerstoneTools.setToolDisabledForElement(element, 'ScaleOverlay', {})
    cornerstone.updateImage(element)
  }

aizela avatar Jul 27 '21 08:07 aizela

To solve this issue, one approach is to use the clearToolState function from the cornerstoneTools library, which removes all toolState from the toolStateManager corresponding to the toolName and element. You can also consider using other tools or functions that can help you achieve your goal.

In case you want to learn more about this issue, I suggest reading the answer I wrote on StackOverflow, which provides more information and references to other related materials:

https://stackoverflow.com/a/73204850/2371987

FMCalisto avatar Mar 14 '23 20:03 FMCalisto