How to use the cornerstone-tools.globalImageIdSpecificToolStateManager 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 OHIF / ohif-core / src / measurements / classes / MeasurementApi.js View on Github external
const toolData = toolState[imageId][toolType];
          const measurementEntries = toolData && toolData.data;
          const measurementEntry = measurementEntries.find(
            mEntry => mEntry._id === entry._id
          );
          if (measurementEntry) {
            const index = measurementEntries.indexOf(measurementEntry);
            measurementEntries.splice(index, 1);
          }
        }
      });

      this.onMeasurementRemoved(toolType, entry);
    });

    cornerstoneTools.globalImageIdSpecificToolStateManager.restoreToolState(
      toolState
    );

    // Synchronize the updated measurements with Cornerstone Tools
    // toolData to make sure the displayed measurements show 'Target X' correctly
    const syncFilter = Object.assign({}, filter);
    delete syncFilter.timepointId;
    delete syncFilter.lesionNamingNumber;

    const syncFilterKeys = Object.keys(syncFilter);

    const toolTypes = [...new Set(entries.map(entry => entry.toolType))];
    toolTypes.forEach(toolType => {
      const collection = this.tools[toolType];
      collection
        .filter(tool => {
github OHIF / Viewers / platform / core / src / measurements / classes / MeasurementApi.js View on Github external
static syncMeasurementAndToolData(measurement) {
    log.info('syncMeasurementAndToolData');

    const measurementLabel = getLabel(measurement);
    if (measurementLabel) {
      measurement.labels = [measurementLabel];
    }

    const toolState = cornerstoneTools.globalImageIdSpecificToolStateManager.saveToolState();

    // Stop here if the metadata for the measurement's study is not loaded yet
    const { studyInstanceUid } = measurement;
    const metadata = studyMetadataManager.get(studyInstanceUid);
    if (!metadata) return;

    // Iterate each child tool if the current tool has children
    const toolType = measurement.toolType;
    const { tool } = MeasurementApi.getToolConfiguration(toolType);
    if (Array.isArray(tool.childTools)) {
      tool.childTools.forEach(childToolKey => {
        const childMeasurement = measurement[childToolKey];
        if (!childMeasurement) return;
        childMeasurement._id = measurement._id;
        childMeasurement.measurementNumber = measurement.measurementNumber;
        childMeasurement.lesionNamingNumber = measurement.lesionNamingNumber;
github OHIF / ohif-core / src / measurements / classes / MeasurementApi.js View on Github external
entries.push(collection[toolIndex]);
        collection.splice(toolIndex, 1);
      }
    });

    // Stop here if no entries were found
    if (!entries.length) {
      return;
    }

    // If the filter doesn't have the measurement number, get it from the first entry
    const lesionNamingNumber =
      filter.lesionNamingNumber || entries[0].lesionNamingNumber;

    // Synchronize the new data with cornerstone tools
    const toolState = cornerstoneTools.globalImageIdSpecificToolStateManager.saveToolState();

    entries.forEach(entry => {
      const measurementsData = [];
      const { tool } = MeasurementApi.getToolConfiguration(entry.toolType);
      if (Array.isArray(tool.childTools)) {
        tool.childTools.forEach(key => {
          const childMeasurement = entry[key];
          if (!childMeasurement) return;
          measurementsData.push(childMeasurement);
        });
      } else {
        measurementsData.push(entry);
      }

      measurementsData.forEach(measurementData => {
        const { imagePath, toolType } = measurementData;
github OHIF / ohif-core / src / measurements / lib / syncMeasurementAndToolData.js View on Github external
export default function syncMeasurementAndToolData(measurement) {
  log.info('syncMeasurementAndToolData');

  const toolState = cornerstoneTools.globalImageIdSpecificToolStateManager.saveToolState();

  // Stop here if the metadata for the measurement's study is not loaded yet
  const { studyInstanceUid } = measurement;
  const metadata = studyMetadataManager.get(studyInstanceUid);
  if (!metadata) return;

  // Iterate each child tool if the current tool has children
  const toolType = measurement.toolType;
  const { tool } = MeasurementApi.getToolConfiguration(toolType);
  if (Array.isArray(tool.childTools)) {
    tool.childTools.forEach(childToolKey => {
      const childMeasurement = measurement[childToolKey];
      if (!childMeasurement) return;
      childMeasurement._id = measurement._id;
      childMeasurement.measurementNumber = measurement.measurementNumber;
      childMeasurement.lesionNamingNumber = measurement.lesionNamingNumber;
github OHIF / ohif-core / src / measurements / lib / syncMeasurementAndToolData.js View on Github external
return;
    }
  } else {
    // If no toolData exists for this toolType, create an empty array to hold some
    toolState[imageId][toolType] = {
      data: []
    };
  }

  // If we have reached this point, it means we haven't found the Measurement we are looking for
  // in the current toolData. This means we need to add it.

  // Add the MeasurementData into the toolData for this imageId
  toolState[imageId][toolType].data.push(measurement);

  cornerstoneTools.globalImageIdSpecificToolStateManager.restoreToolState(
    toolState
  );
}
github OHIF / Viewers / platform / core / src / measurements / classes / MeasurementApi.js View on Github external
return;
      }
    } else {
      // If no toolData exists for this toolType, create an empty array to hold some
      toolState[imageId][toolType] = {
        data: [],
      };
    }

    // If we have reached this point, it means we haven't found the Measurement we are looking for
    // in the current toolData. This means we need to add it.

    // Add the MeasurementData into the toolData for this imageId
    toolState[imageId][toolType].data.push(measurement);

    cornerstoneTools.globalImageIdSpecificToolStateManager.restoreToolState(
      toolState
    );
  }
github OHIF / Viewers / extensions / cornerstone / src / handleSegmentationStorage.js View on Github external
function addSegMetadataToCornerstoneToolState(
  segMetadata,
  toolState,
  displaySetInstanceUid
) {
  cornerstoneTools.globalImageIdSpecificToolStateManager.restoreToolState(
    toolState
  );

  const brushModule = cornerstoneTools.store.modules.brush;

  for (let i = 0; i < segMetadata.length; i++) {
    brushModule.setters.metadata(displaySetInstanceUid, i, segMetadata[i]);
  }
}
github OHIF / Viewers / extensions / cornerstone / src / commandsModule.js View on Github external
clearAnnotations: ({ viewports }) => {
      const element = getEnabledElement(viewports.activeViewportIndex);
      if (!element) {
        return;
      }

      const enabledElement = cornerstone.getEnabledElement(element);
      if (!enabledElement || !enabledElement.image) {
        return;
      }

      const {
        toolState,
      } = cornerstoneTools.globalImageIdSpecificToolStateManager;
      if (
        !toolState ||
        toolState.hasOwnProperty(enabledElement.image.imageId) === false
      ) {
        return;
      }

      const imageIdToolState = toolState[enabledElement.image.imageId];

      const measurementsToRemove = [];

      Object.keys(imageIdToolState).forEach(toolType => {
        const { data } = imageIdToolState[toolType];

        data.forEach(measurementData => {
          const {
github Kitware / paraview-glance / Sources / externals / MedicalCornerstone / CornerstoneToolControl / index.js View on Github external
disabled={forceDisable}
              onClick={() => this.toggleTool(name)}
            >
              
            
          
        );
      });

    const measurements = [];
    if (view && view.getContainer()) {
      const element = view.getContainer();
      const stateManager = cornerstoneTools.getElementToolStateManager(element);

      if (
        stateManager !== cornerstoneTools.globalImageIdSpecificToolStateManager
      ) {
        const getSliceIndex = (imageId) => {
          const { params } = parseImageId(imageId);
          return params.slice;
        };

        const toolState = stateManager.getToolState();
        Object.values(toolState).forEach((states) => {
          Object.keys(states).forEach((toolType) => {
            states[toolType].data.forEach((item) =>
              measurements.push({
                key: item.metadata.measurementId,
                type: item.metadata.toolType,
                sliceIndex: getSliceIndex(item.metadata.imageId),
                icon: this.toolManager.getTool(item.metadata.toolType).config
                  .icon,