Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Local dicom file not rendered #1742

Open
robot300795 opened this issue Jan 9, 2025 · 0 comments
Open

[Bug] Local dicom file not rendered #1742

robot300795 opened this issue Jan 9, 2025 · 0 comments

Comments

@robot300795
Copy link

Describe the Bug

Using the example to display local files, i wrote a loadDicomFile that gets a file object. Problem is, that the viewport stays black. There is no error. The metadata is also undefined.

import { init as coreInit, Enums, RenderingEngine } from '@cornerstonejs/core';
import cornerstoneDICOMImageLoader, { init as dicomImageLoaderInit } from '@cornerstonejs/dicom-image-loader';

// Initialize the Cornerstone Core and DICOM Image Loader modules
coreInit();
dicomImageLoaderInit();
console.log('Cornerstone modules initialized');

function loadDicomFile(file, imagePreview) {
  // Add the DICOM file to the file manager and get the image ID
  const imageId = cornerstoneDICOMImageLoader.wadouri.fileManager.add(file);
  console.log('Image ID:', imageId);

  // Create a new element and append it to the image preview container
  const element = document.createElement('div');
  element.style.width  = '512px';
  element.style.height = '512px';

  // Append the element to the image preview container
  imagePreview.appendChild(element);

  // Instantiate a rendering engine
  const renderingEngine = new RenderingEngine('CornerstoneRenderingEngine');
  const ctVoiRange = { windowWidth: 400, windowCenter: 40 }; 

  // Create a stack viewport
  const viewportId = 'CT_STACK';
  const viewportInput = {
    viewportId,
    type: Enums.ViewportType.STACK,
    element,
  };

  renderingEngine.enableElement(viewportInput);
  // Get the stack viewport that was created
  const viewport = renderingEngine.getViewport(viewportId);
  // Set the stack on the viewport
  viewport.setStack([imageId]);
  // Set the VOI of the stack
  viewport.setProperties({ voiRange: ctVoiRange });
  // Render the image
  viewport.render();
  // Get the image data of the rendered image
  const metadata = viewport.getImageData();
  console.log('Image metadata:', metadata);

  // Purge all loaded image data and empty the image cache before loading a new image
  cornerstoneDICOMImageLoader.wadouri.fileManager.purge();
}

image

Steps to Reproduce

  1. "@cornerstonejs/core": "^2.14.9",
    "@cornerstonejs/dicom-image-loader": "^2.14.9",
    "@cornerstonejs/tools": "^2.14.9",
    "@originjs/vite-plugin-commonjs": "^1.0.3"

  2. files are bundled with vite

  3. use python with flask, create a minimal project

  4. upload dialog, then render the files

The current behavior

Rendering is not working.

The expected behavior

Render the Dicom file.

OS

Windows 11

Node version

v22.12.0

Browser

Chrome Version 131.0.6778.205

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant