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

[Feature Request] Update vtk.js to prevent memory increasing #1411

Open
Sergey1888888 opened this issue Jul 31, 2024 · 5 comments
Open

[Feature Request] Update vtk.js to prevent memory increasing #1411

Sergey1888888 opened this issue Jul 31, 2024 · 5 comments

Comments

@Sergey1888888
Copy link
Contributor

What feature or change would you like to see made?

Since 30.10.0 version developers of vtk.js added garbage collection to shared graphics resources. But if I will update it to myself, I will get error in cornerstone vtkStreamingOpenGLVolumeMapper file. Could you update vtk.js?
The problem is infinite increasing memory space when I use setStack on the elements to replace images.

Why should we prioritize this feature?

Without this update we have infinite increasing memory space when using setStack on the elements to replace images.

@arlagonix
Copy link

My colleague on work constantly faces that problem. He's in anguish and pain. It would be great if this could be fixed as soon as possible!

@sedghi
Copy link
Member

sedghi commented Aug 2, 2024

This is not about the garbage collection you're referring to. They recently added a new shared mapper (which we already have), and that is related to garbage collection.

If you give me reproducible steps i can take a look at the memory leak

@Sergey1888888
Copy link
Contributor Author

Sergey1888888 commented Aug 2, 2024

@sedghi

Initial values:

image
image

After some clicks on elements:

image
image

I have changed your example with basic StackViewport and able to reproduce:

import { Enums, RenderingEngine, Types } from '@cornerstonejs/core';
import {
  createImageIdsAndCacheMetaData,
  initDemo,
  setTitleAndDescription,
} from '../../../../utils/demo/helpers';

// This is for debugging purposes
console.warn(
  'Click on index.ts to open source code for this example --------->'
);

const { ViewportType } = Enums;

// ======== Set up page ======== //
setTitleAndDescription(
  'Basic Stack',
  'Displays a single DICOM image in a Stack viewport.'
);

const content = document.getElementById('content');
const element1 = document.createElement('div');
element1.id = 'cornerstone-element1';
element1.style.width = '500px';
element1.style.height = '500px';
const element2 = document.createElement('div');
element2.id = 'cornerstone-element2';
element2.style.width = '500px';
element2.style.height = '500px';

content.appendChild(element1);
content.appendChild(element2);
// ============================= //

/**
 * Runs the demo
 */
async function run() {
  // Init Cornerstone and related libraries
  await initDemo();

  // Get Cornerstone imageIds and fetch metadata into RAM
  const imageIds = await createImageIdsAndCacheMetaData({
    StudyInstanceUID:
      '1.3.6.1.4.1.14519.5.2.1.7009.2403.334240657131972136850343327463',
    SeriesInstanceUID:
      '1.3.6.1.4.1.14519.5.2.1.7009.2403.226151125820845824875394858561',
    wadoRsRoot: 'https://d3t6nz73ql33tx.cloudfront.net/dicomweb',
  });

  // Instantiate a rendering engine
  const renderingEngineId = 'myRenderingEngine';
  const renderingEngine = new RenderingEngine(renderingEngineId);

  // Create a stack viewport
  const viewportId1 = 'CT_STACK1';
  const viewportInput1 = {
    viewportId: viewportId1,
    type: ViewportType.STACK,
    element: element1,
    defaultOptions: {
      background: <Types.Point3>[0.2, 0, 0.2],
    },
  };
  const viewportId2 = 'CT_STACK2';
  const viewportInput2 = {
    viewportId: viewportId2,
    type: ViewportType.STACK,
    element: element2,
    defaultOptions: {
      background: <Types.Point3>[0.2, 0, 0.2],
    },
  };

  renderingEngine.enableElement(viewportInput1);
  renderingEngine.enableElement(viewportInput2);

  // Get the stack viewport that was created
  const viewport1 = <Types.IStackViewport>(
    renderingEngine.getViewport(viewportId1)
  );
  const viewport2 = <Types.IStackViewport>(
    renderingEngine.getViewport(viewportId2)
  );

  // Define a stack containing a single image
  const stack1 = [imageIds[0]];
  const stack2 = [imageIds[1]];

  // Set the stack on the viewport
  await viewport1.setStack(stack1);
  await viewport2.setStack(stack2);

  element1.addEventListener('click', async () => {
    const imageId = viewport1.getCurrentImageId();
    if (imageId === imageIds[0]) {
      await viewport1.setStack([imageIds[1]]);
    } else {
      await viewport1.setStack([imageIds[0]]);
    }
  });

  element2.addEventListener('click', async () => {
    const imageId = viewport2.getCurrentImageId();
    if (imageId === imageIds[0]) {
      await viewport2.setStack([imageIds[1]]);
    } else {
      await viewport2.setStack([imageIds[0]]);
    }
  });

  // Render the image
  viewport1.render();
  viewport2.render();
}

run();

@Sergey1888888
Copy link
Contributor Author

@sedghi Were you able to reproduce it?

@sedghi
Copy link
Member

sedghi commented Aug 6, 2024

Haven't looked at it, but will upgrade vtk in near future since i'm pushing on cornerstone 2.0

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

No branches or pull requests

3 participants