FIX NaN values in Volume/Vertex rendering as black instead of transparent#612
FIX NaN values in Volume/Vertex rendering as black instead of transparent#612
Conversation
Agent-Logs-Url: https://github.com/gallantlab/pycortex/sessions/a5d0ee68-41d6-4451-8ed5-a84b060a457f Co-authored-by: mvdoc <6150554+mvdoc@users.noreply.github.com>
…rtex raw When using Volume.raw or Vertex.raw, NaN values in data were rendered as opaque black because: (1) colormap conversion maps NaN to black RGB, and (2) after uint8 conversion, the NaN info is lost so the alpha getter's NaN detection fails. Fix: - In Dataview.raw: explicitly set alpha=0 for NaN positions before returning the RGBA channels - In Volume.raw/Vertex.raw: store a _nan_mask on the RGB object - In VolumeRGB/VertexRGB alpha getters: apply stored _nan_mask to enforce alpha=0 for NaN positions, even after user alpha override Agent-Logs-Url: https://github.com/gallantlab/pycortex/sessions/a5d0ee68-41d6-4451-8ed5-a84b060a457f Co-authored-by: mvdoc <6150554+mvdoc@users.noreply.github.com>
Agent-Logs-Url: https://github.com/gallantlab/pycortex/sessions/a5d0ee68-41d6-4451-8ed5-a84b060a457f Co-authored-by: mvdoc <6150554+mvdoc@users.noreply.github.com>
Agent-Logs-Url: https://github.com/gallantlab/pycortex/sessions/a5d0ee68-41d6-4451-8ed5-a84b060a457f Co-authored-by: mvdoc <6150554+mvdoc@users.noreply.github.com>
Agent-Logs-Url: https://github.com/gallantlab/pycortex/sessions/a5d0ee68-41d6-4451-8ed5-a84b060a457f Co-authored-by: mvdoc <6150554+mvdoc@users.noreply.github.com>
|
This is possibly related to #455 |
…ssue #455) Add NaN detection in the surface_vertex shader's colormap lookup. When vertex data contains NaN, the normalized colormap coordinates (cuv.x/cuv.y) become NaN. Use the GLSL idiom (x != x) to detect NaN and set vColor to vec4(0.) (fully transparent) so NaN vertices are discarded instead of rendered as colored. Agent-Logs-Url: https://github.com/gallantlab/pycortex/sessions/4091acc2-7dc4-4b78-bd80-52e45c73d1ea Co-authored-by: mvdoc <6150554+mvdoc@users.noreply.github.com>
Yes, issue #455 is directly related. It describes two problems:
Fixed in |
WebGL drivers sanitize NaN values in vertex attributes to 0, so the shader-only NaN detection (cuv.x != cuv.x) never fires. Instead, detect NaN in JavaScript when vertex data is loaded, build a nanmask attribute (1=valid, 0=NaN), replace NaN with 0 in the data, and check the mask in the vertex shader. Also refactors the Python side: - Dataview.raw returns (rgba, nan_mask) to avoid redundant np.isnan - Volume.raw / Vertex.raw reuse the mask from the parent - DataviewRGB._apply_nan_mask() consolidates duplicated logic
…widget-dvTkg * origin/main: FIX NaN values in Volume/Vertex rendering as black instead of transparent (gallantlab#612) Fix docs version display and update copyright to Gallant Lab (gallantlab#614) Disable flatmap tilt by default; respect allow_tilt checkbox in controls (gallantlab#618) Split 'r' hotkey: fold-only vs full view reset (gallantlab#617) Bump codecov/codecov-action from 5 to 6 (gallantlab#615) FIX deprecated scipy APIs (gallantlab#609) # Conflicts: # docs/conf.py

NaN values in
Volume.raw/Vertex.rawrender as opaque black instead of transparent. After colormap conversion to uint8, NaN information is lost, so the alpha getter'snp.isnan(rgb)check on uint8 data is alwaysFalse. Additionally,Vertexobjects with NaN data render as colored (not transparent) in the WebGL viewer due to missing NaN detection in thesurface_vertexshader.Changes
Dataview.raw: Capture NaN mask before uint8 conversion, explicitly zero out alpha for NaN positionsVolume.raw/Vertex.raw: Store_nan_maskon the returned RGB object so it survives alpha overridesVolumeRGB.alpha/VertexRGB.alphagetters: Apply stored_nan_maskto enforce alpha=0 for NaN positions, even after user sets a custom alpha channelsurface_vertexWebGL shader: Add NaN detection in the colormap lookup using the GLSL idiomcuv.x != cuv.x. When vertex data is NaN, setvColor = vec4(0.)so the fragment shader discards the vertex. Handles both 1D and 2D cases. Thesurface_pixelshader already had NaN detection viacolorlut(), butsurface_vertexwas missing it.⚡ Quickly spin up Copilot coding agent tasks from anywhere on your macOS or Windows machine with Raycast.