scenerygraphics / scenery

Flexible VR Visualisation for Volumetric and Geometric Data on the Java VM, powered by Kotlin and Vulkan.
https://scenery.graphics
GNU Lesser General Public License v3.0
128 stars 31 forks source link

Bug: mouse hover over color map panel editor turns volume black #757

Open smlpt opened 1 month ago

smlpt commented 1 month ago

328846765-05e42f2b-e950-4a5e-8239-11d2d7d2f91b

The bug is likely caused by repainting the colormap panel and loading the color map from buffer here, introduced in this commit.

The issue was moved here from this sciview issue.

odinsbane commented 1 month ago

I played around with it a bit, and this line appears to be the culprit. The returned colormap always seems to be black.

odinsbane commented 1 month ago

I was looking at Colormap.kt, and I am not sure I understand what it does.

When I look at Colormap#sample I expect it should interpolate the color along the center line of the byte buffer. globalOffset seems to make some assumptions that aren't always true.

val globalOffset = width * 4 * height / 2

This assumes the buffer is always 4 bytes per sample and the height is greater than 1.

I know the first assumption can be wrong from based on Image#bufferedImageToRGBABuffer

raster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE, texWidth, texHeight, 3, null)

That occurs if the provided image doesn't have an alpha component. Which will create a 3 byte version. I think that clause should be removed and make a 4 byte raster either way. Java should draw the image ok and the buffer will always be 4 bytes.

How should a Colormap#fromColor work?

Currently it starts at the target color and ends at black. It also ignores the A component of the provided color. This seems to contradict the ColormapPanel where a "yellow.lut" is drawn from left to right.

If I understand the Colormap a bit better I could make a pull request regarding this issue.

odinsbane commented 1 month ago

The problem is caused by this line in ColormapPanel The gradient image is only being filled halfway because of the h-10. Then sample is taking the "center" of the buffered image which happens to be a section that is blank.