cornerstone icon indicating copy to clipboard operation
cornerstone copied to clipboard

Does WebGL work for layers?

Open MaksimShymko opened this issue 4 years ago • 3 comments

cornerstone-core version: 2.6.0

I've faced the issue that images added with addLayer don't use WebGL. There is a code in the internal function drawImageSync which adds conditional branching:

if (layers && layers.length) {
  // render when layers specified
  drawCompositeImage(enabledElement, invalidated);
} else if (image) { // render when layers not specified

Currently, WebGL works only for displayImage function. But it isn't possible to combine multiple images on the same canvas with displayImage.

  1. Is there any workaround to use multiple layers with WebGL?
  2. Do you have plans to add WebGL support for layers in the nearest future?

MaksimShymko avatar Nov 03 '21 10:11 MaksimShymko

I don't have an answer to your question, but I am curious what you are trying to accomplish with the layersApi, perhaps there is a different workaround

shanebenlolo avatar Nov 12 '21 15:11 shanebenlolo

@shanebenlolo I want to display a CT scan and can perform windowing, panning, and zooming operations. Also, I want to put a png image overlay on top of the CT scan. CT scan and overlay should be synchronized during panning and zooming.

I am considering three solutions:

  • Use layers API. Cons: cornerstone doesn't use WebGL while windowing, so FPS becomes lower
  • Use two cornerstone canvases. One for CT scan and one for overlay image. Cons: cornerstone adds black background to the overlay image, but the overlay background should be transparent. I didn't find any flag to make a background transparent, so the only solution I found is to set a background transparent on each rendering frame.
  • Use two canvases. Cornerstone canvas for CT scan and custom canvas for overlay image. Cons: I have to write additional code to resize, translate and synchronize the overlay image.

Maybe there is another approach that mitigates all cons?

MaksimShymko avatar Nov 15 '21 06:11 MaksimShymko

Have you considered using the react-vtkjs-viewport? https://react-vtkjs-viewport.netlify.app/

shanebenlolo avatar Nov 15 '21 16:11 shanebenlolo