Kitware / vtk-js

Visualization Toolkit for the Web
https://kitware.github.io/vtk-js/
BSD 3-Clause "New" or "Revised" License
1.23k stars 371 forks source link

Intergrate cornerstoneTools into vtk-js #1662

Closed StevenRoger closed 3 years ago

StevenRoger commented 3 years ago

I plan to do some measurements and annotations on the vtk's VIEW2D viewport, I have no idea to intergrage cornerstoneTools, Is there any better way to do it? Expect some suggestion.

floryst commented 3 years ago

Hi, there will be difficulties integrating cornerstone tools and vtk.js views. At a technical level, vtk.js is inherently 3D, and cornerstone tools work in 2D. As a result, there will likely be lots of cases if you tried to sync the two.

As an alternative, you can check out vtk.js widgets to see if those suit your needs. While we do not have a comprehensive widget suite yet, you can see some examples here (search the page for "Widget") and see a working demo of measurements in ParaView Glance.

StevenRoger commented 3 years ago

Thanks for your help, I tried to use vtkRectangleWidget in react-vtkjs-viewport's View2D.js like this

this.rectangleWidget = vtkRectangleWidget.newInstance({
      resetAfterPointPlacement: false,
      useHandles: true,
});

...
this.viewWidget = this.widgetManager.addWidget(
      this.rectangleWidget,
      ViewTypes.SLICE
);

this.widgetManager.grabFocus(this.rectangleWidget);
this.widgetManager.enablePicking();
this.genericRenderWindow.resize();

but error occurred image

Am I using it in the wrong way?

floryst commented 3 years ago

That's odd. It might be possible that the vtk.js version of react-vtkjs-viewport needs updating? There shouldn't be any shader compilation issues. Is there any more info when you expand the error?

StevenRoger commented 3 years ago

In the OHIF/Viewer project, I've updated the version of vtk.js to latest, this error still exist. More error info:

image

floryst commented 3 years ago

Does the error persist if you remove the widget code? It would seem odd that the widget code results in invalid shader code.

StevenRoger commented 3 years ago

No, if i don't use vtkRectangleWidget, the error won't occur. I guess there are some problems with the webpack config in OHIF. All of the examples in Source/Widgets/Widgets3D runs fine.

Related issue: https://github.com/OHIF/Viewers/issues/2215

floryst commented 3 years ago

Hm, if you can provide some reproduction steps or a proof of concept then I can help debug this issue further.

StevenRoger commented 3 years ago

Thx, I found another clue that if i removed all view props before adding the rectangleWidget, the program runs fine.

this.renderer.removeAllViewProps();
this.viewWidget = this.widgetManager.addWidget(this.rectangleWidget);

Before i use the rectangleWidget, i had rendered images and labelmaps. so i think this error was due to my wrong use of vtk.js. But i still can't figure out the reason why i can't do that.

StevenRoger commented 3 years ago

I rendered image by vtkVolume

const volumeActor = vtkVolume.newInstance();
const volumeMapper = vtkVolumeMapper.newInstance();

volumeActor.setMapper(volumeMapper);
volumeMapper.setInputData(vtkImageData);

In this case, can i use rectangleWidget? expect some guidance.

floryst commented 3 years ago

I'm not sure how to reproduce the issue. The rectangle widget should be usable, but I don't know what specifically is missing. (maybe some glsl code is not being included?)

Can you save the entire shader error to a file and attach it here?

finetjul commented 3 years ago

@StevenRoger did you get your issue fixed ?

jourdain commented 3 years ago

If this is still an issue, please re-open.