How to use the cornerstone-tools.clearToolState function in cornerstone-tools

To help you get started, weโ€™ve selected a few cornerstone-tools examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cornerstonejs / react-cornerstone-viewport / src / CornerstoneViewport / CornerstoneViewport.js View on Github external
this._bindInternalEventListeners();
    this._bindExternalEventListeners();
    this._handleOnElementEnabledEvent();

    // Fire 'er up
    cornerstone.enable(this.element, cornerstoneOptions);
    if (resizeThrottleMs) {
      windowResizeHandler.enable(this.element, resizeThrottleMs);
    }

    // Only after `uuid` is set for enabledElement
    this._setupLoadHandlers();

    try {
      // Setup "Stack State"
      cornerstoneTools.clearToolState(this.element, 'stack');
      cornerstoneTools.addStackStateManager(this.element, [
        'stack',
        'playClip',
        'referenceLines',
      ]);
      cornerstoneTools.addToolState(this.element, 'stack', {
        imageIds: [...imageIds],
        currentImageIdIndex: imageIdIndex,
      });

      // Load first image in stack
      const image = await cornerstone.loadAndCacheImage(imageId);

      // Display
      cornerstone.displayImage(this.element, image);
github cornerstonejs / react-cornerstone-viewport / src / CornerstoneViewport / CornerstoneViewport.js View on Github external
imageIds: stack,
      imageIdIndex: imageIndex,
      isStackPrefetchEnabled,
    } = this.props;
    const {
      imageIds: prevStack,
      imageIdIndex: prevImageIndex,
      isStackPrefetchEnabled: prevIsStackPrefetchEnabled,
    } = prevProps;
    const hasStackChanged = !areStringArraysEqual(prevStack, stack);
    const hasImageIndexChanged = imageIndex !== prevImageIndex;
    let updatedState = {};

    if (hasStackChanged) {
      // update stack toolstate
      cornerstoneTools.clearToolState(this.element, 'stack');
      cornerstoneTools.addToolState(this.element, 'stack', {
        imageIds: [...stack],
        currentImageIdIndex: imageIndex,
      });

      // New stack; reset counter
      updatedState['numImagesLoaded'] = 0;
      updatedState['error'] = null; // Reset error on new stack

      try {
        // load + display image
        const imageId = stack[imageIndex];
        const image = await cornerstone.loadAndCacheImage(imageId);

        cornerstone.displayImage(this.element, image);
        cornerstone.reset(this.element);
github cornerstonejs / react-cornerstone-viewport / src / CornerstoneViewport / CornerstoneViewport.js View on Github external
componentWillUnmount() {
    const clear = true;

    this._bindInternalEventListeners(clear);
    this._bindExternalEventListeners(clear);
    this._setupLoadHandlers(clear);
    if (this.props.isStackPrefetchEnabled) {
      _enableStackPrefetching(this.element, clear);
    }
    cornerstoneTools.clearToolState(this.element, 'stackPrefetch');
    cornerstoneTools.stopClip(this.element);
    if (this.props.resizeThrottleMs) {
      windowResizeHandler.disable(this.element);
    }
    cornerstone.disable(this.element);
  }