How to use the cornerstone-core.getEnabledElement function in cornerstone-core

To help you get started, we’ve selected a few cornerstone-core 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 / lib / getImageAttributes.js View on Github external
export default function(element) {
  // Get the Cornerstone imageId
  const enabledElement = cornerstone.getEnabledElement(element);
  const imageId = enabledElement.image.imageId;

  // Get studyInstanceUid & patientId
  const study = cornerstone.metaData.get('study', imageId);
  const studyInstanceUid = study.studyInstanceUid;
  const patientId = study.patientId;

  // Get seriesInstanceUid
  const series = cornerstone.metaData.get('series', imageId);
  const seriesInstanceUid = series.seriesInstanceUid;

  // Get sopInstanceUid
  const sopInstance = cornerstone.metaData.get('instance', imageId);
  const sopInstanceUid = sopInstance.sopInstanceUid;
  const frameIndex = sopInstance.frame || 0;
github OHIF / ohif-core / src / lib / cornerstone.js View on Github external
function pixelToPage(element, position) {
  const enabledElement = cornerstone.getEnabledElement(element);
  const result = {
    x: 0,
    y: 0,
  };

  // Stop here if the cornerstone element is not enabled or position is not an object
  if (!enabledElement || typeof position !== 'object') {
    return result;
  }

  const canvas = enabledElement.canvas;

  const canvasOffset = $(canvas).offset();
  result.x += canvasOffset.left;
  result.y += canvasOffset.top;
github OHIF / ohif-core / src / lib / cornerstone.js View on Github external
function repositionTextBox(eventData, measurementData, config) {
  // Stop here if it's not a measurement creating
  if (!measurementData.isCreating) {
    return;
  }

  const element = eventData.element;
  const enabledElement = cornerstone.getEnabledElement(element);
  const image = enabledElement.image;

  const allowedBorders = OHIF.uiSettings.autoPositionMeasurementsTextCallOuts;
  const allow = {
    T: !allowedBorders || allowedBorders.includes('T'),
    R: !allowedBorders || allowedBorders.includes('R'),
    B: !allowedBorders || allowedBorders.includes('B'),
    L: !allowedBorders || allowedBorders.includes('L'),
  };

  const getAvailableBlankAreas = (enabledElement, labelWidth, labelHeight) => {
    const { element, canvas, image } = enabledElement;

    const topLeft = cornerstone.pixelToCanvas(element, {
      x: 0,
      y: 0,
github OHIF / Viewers / platform / viewer / src / connectedComponents / ConnectedDownloadDialog.js View on Github external
new Promise(resolve => {
        if (activeViewport && viewportElement) {
          const enabledElement = cornerstone.getEnabledElement(activeViewport);
          const viewport = Object.assign({}, enabledElement.viewport);
          delete viewport.scale;
          viewport.translation = {
            x: 0,
            y: 0,
          };

          cornerstone.loadImage(enabledElement.image.imageId).then(image => {
            cornerstone.displayImage(viewportElement, image);
            cornerstone.setViewport(viewportElement, viewport);
            cornerstone.resize(viewportElement, true);

            const newWidth = Math.min(width || image.width, MAX_TEXTURE_SIZE);
            const newHeight = Math.min(
              height || image.height,
              MAX_TEXTURE_SIZE
github OHIF / react-vtkjs-viewport / examples / VTKCornerstonePaintingSyncExample.js View on Github external
onPaintEnd = strokeBuffer => {
    const element = this.cornerstoneElements[0];
    const enabledElement = cornerstone.getEnabledElement(element);
    const { getters, setters } = cornerstoneTools.getModule('segmentation');
    const labelmap3D = getters.labelmap3D(element);
    const stackState = cornerstoneTools.getToolState(element, 'stack');
    const { rows, columns } = enabledElement.image;

    if (!stackState || !labelmap3D) {
      return;
    }

    const stackData = stackState.data[0];
    const numberOfFrames = stackData.imageIds.length;
    const segmentIndex = labelmap3D.activeSegmentIndex;

    for (let i = 0; i < numberOfFrames; i++) {
      let labelmap2D = labelmap3D.labelmaps2D[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];
github OHIF / ohif-core / src / classes / StackImagePositionOffsetSynchronizer.js View on Github external
getViewportImageNormal(element) {
    if (!element) {
      return;
    }

    element = $(element).get(0);

    try {
      const enabledElement = cornerstone.getEnabledElement(element);

      if (!enabledElement.image) {
        return;
      }

      const imageId = enabledElement.image.imageId;
      const imagePlane = cornerstone.metaData.get('imagePlane', imageId);

      if (!imagePlane || !imagePlane.rowCosines || !imagePlane.columnCosines) {
        return;
      }

      return imagePlane.rowCosines.clone().cross(imagePlane.columnCosines);
    } catch (error) {
      const errorMessage = error.message || error;
      log.info(
github OHIF / Viewers / platform / viewer / src / connectedComponents / ConnectedDownloadDialog.js View on Github external
function updateViewport(event) {
            const enabledElement = cornerstone.getEnabledElement(event.target)
              .element;
            const type = 'image/' + fileType;
            const dataUrl = downloadCanvas.toDataURL(type, 1);

            let newWidth = enabledElement.offsetHeight;
            let newHeight = enabledElement.offsetWidth;

            if (newWidth > DEFAULT_SIZE || newHeight > DEFAULT_SIZE) {
              const multiplier = DEFAULT_SIZE / Math.max(newWidth, newHeight);
              newHeight *= multiplier;
              newWidth *= multiplier;
            }

            resolve({ dataUrl, width: newWidth, height: newHeight });

            viewportElement.removeEventListener(