Kitware / itk-vtk-viewer

2D / 3D web image, mesh, and point set viewer using itk-wasm and vtk.js
https://kitware.github.io/itk-vtk-viewer/
BSD 3-Clause "New" or "Revised" License
210 stars 64 forks source link

Problem volume rendering some images with large values #273

Open scottwittenburg opened 4 years ago

scottwittenburg commented 4 years ago

When I "compose" just the 190216_t2_extracted.nrrd image with itself, using the itk.imread('190216_t2_extracted.nrrd', itk.F) method to read the image, it seems the use of itk.F causes the input values (which are Float64Array) to be "downcast" to Float32Array. When I use the viewer to volume render the resulting data, the view is initially black, but if I turn off "Use Shadow", I can see something, but it's still wrong.

Here's an animated gif illustrating the problem.

volren-issue

scottwittenburg commented 4 years ago

I think this is related to #272 in that it is caused by volume rendering large scalar values. The reason the Float64Array version of the data doesn't suffer from the issue is that it fails this check, resulting in "conversion to float", here. That code path transforms the large values to a smaller range before uploading them to texture, at the same time sending extra uniforms to the shader so the values can be transformed back after being retrieved from the texture.

By commenting out lines 1058 -1065, linked above, the transformation path is forced, which resolves the issue, but probably causes other problems (e.g. inefficiency in a lot of use cases). So we should look for a better solution.