Repository navigation
Conversation
The WebGL label outlines of vtkVolumeMapper, vtkImageMapper and vtkImageResliceMapper read the label under a fragment as int(sample * 255.0), which is the label only for an 8-bit labelmap. A 16-bit or float labelmap had label n read as 255 * n, so its per-segment outline thickness and opacity came from the wrong entries; stored as norm16, every label read as 0 and nothing was drawn. Scale the sample back by the texture's own normalization, and round, as the WebGPU volume pass does. The volume and image mappers also sample the thickness texture with the width it was built with rather than 1024, and the image mapper rebuilds its outline textures when that width changes.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
The WebGL label outlines (
setUseLabelOutline(true)) ofvtkVolumeMapper,vtkImageMapperandvtkImageResliceMapperfind the label under a fragment asint(sample * 255.0). That is the label only for an 8-bit labelmap, whose texture is normalized by 255. For any other type the segment is wrong, in a way that depends on how the texture stores it:Float32Arraylabelmap, or a 16-bit one without norm16): label n reads as 255·n. The outline is drawn, but its per-segment thickness (and, in the image and reslice mappers, opacity) is read past the given values, from the first entry. Per-segment thickness does nothing, and neither does hiding one segment's outline with a thickness of 0.EXT_texture_norm16is available): every label below 257 reads as 0 (below 129 for signed data), and nothing is drawn. Through Cornerstone3D, aUint16Arraylabelmap drew no outline at all.Nothing documents an 8-bit limit (
setLabelOutlineTextureWidth()even suggests a wider texture "if you have more than 1024 labels"), and the WebGPU volume pass already reads the label whatever its type:i32(round(centerValue.r * volumeSSBO.values[vNum].labelOutline.z)), the texture's scale.Results
The image mapper with a
Uint16Arraylabelmap whose segment 2 has an outline thickness of 0. Before, segment 2 is outlined anyway; after, it is drawn as with aUint8Array:New tests draw the same labelmap through each of the three mappers, against one baseline per mapper: stored as
Uint8Array,Uint16Array,Float32Arrayand, for the volume and reslice mappers,Int16Array; and, for the volume and image mappers, an 8-bit one with a 2048-wide outline table. On master all but the three plain 8-bit cases fail. With the change all thirteen pass, both with SwiftShader, as in CI, and on an Apple GPU. The full suite passes.vtk.js's test browser (Playwright's Chromium headless shell) doesn't offer
EXT_texture_norm16, so the 16-bit cases run on half float there. With Playwright's full Chromium, which offers it, the 16-bit cases also fail on master and pass with the change, in all three mappers.Changes
vtkVolumeFS.glslandOpenGL/VolumeMapper: the volume uniform gets each component's texture scale and offset (volume.textureScale,volume.textureOffset), andgetColorForLabelOutline()reads the label asint(round(sample * scale + offset)).OpenGL/ImageMapper: alabelScaleuniform, the image texture's normalization (255; 65535 or 32767 for unsigned or signed norm16; 1 for float and half float). NotgetShiftAndScale(), which maps signed samples half a unit off for the color lookup (see below) and would put each signed label on a rounding boundary.OpenGL/ImageResliceMapper:labelScale<i>andlabelOffset<i>uniforms per input, used by the single-input, multi-input and slab label outlines, including the slab outline's label-to-color lookup and its test for an empty slab. The tests cover the single-input outline; the multi-input and slab outlines take the same uniforms.labelOutlineTextureWidthuniform as the reslice mapper already does, rather than1024.0, sosetLabelOutlineTextureWidth()takes effect there too. The image mapper now rebuilds its outline textures when that width changes.testImageLabelOutlineDataTypes,testImageResliceMapperLabelOutlineDataTypesandtestLabelOutlineDataTypes(volume mapper), with baselines. No API change.Left as it is:
LABELMAP_EDGE_PROJECTION_BLENDstill reads its labels raw (right for float storage; fix(vtkVolumeFS): round the labels read by labelmap edge projection #3765 fixes its truncation) and tracks 256 segments.* 255.vtkImageMapper's color lookup of a signed norm16 texture:getShiftAndScale()decodesSHORTassample * 32767.5 - 0.5, the desktop GL mapping, where WebGL2 storesc / 32767. A signed 16-bit labelmap's segments are colored as if half a unit lower, which is why the image test has noInt16Arraycase.PR Checklist