Skip to content

fix(vtkVolumeFS): round the labels read by labelmap edge projection - #3765

Open
xapple wants to merge 1 commit into
Kitware:masterfrom
xapple:fix-edge-proj-labels
Open

xapple wants to merge 1 commit into
Kitware:masterfrom
xapple:fix-edge-proj-labels

Conversation

@xapple

@xapple xapple commented Nov 19, 2026

Copy link
Copy Markdown

Context

LABELMAP_EDGE_PROJECTION_BLEND reads a voxel's segment from the volume's second component with int(value.g), in four places of vtkVolumeFS.glsl (twice on the center ray, twice in checkOnEdgeForNeighbor()). int() truncates, so a label that comes back a hair under its whole number becomes the segment below it. The center ray reads the label through getTextureValue(), a filtered texture sample (at the voxel's center when the component forces nearest interpolation), while checkOnEdgeForNeighbor() fetches the texel exactly.

In an application using this blend mode (a two-component float volume, image and labels, with setForceNearestInterpolation(1, true); Chrome on macOS, Apple silicon), several segments were outlined in the color of the segment numbered one below them, 25 in 24's color for example. Adding 0.5 before the int(), through a shader replacement, fixed every case. We haven't pinned down why the sampled label came back under its whole number there, but truncation turns any such error into the segment below, and rounding absorbs it.

The WebGPU edge projection already rounds (i32(round(sample.y * labelScale)) in VolumePassFSQ), as do the WebGL ImageResliceMapper's slab label outlines (int(... * 255.0 + 0.5)).

Results

The new test draws three segments whose labels are stored a hair off their whole number, 0.99, 2.01 and 2.99, colored red, green and blue:

  • before: segment 1 has no outline (read as 0), and segment 3 is outlined in segment 2's green;
  • after: each segment is outlined in its own color.
Before (master) and after (rounded)

The test fails on master (6.88% of the pixels differ, against a tolerance of 1.5%) and passes with the change, both with SwiftShader, as in CI, and on an Apple GPU, which render it identically.

Changes

  • vtkVolumeFS.glsl: the four reads of the segment label in LABELMAP_EDGE_PROJECTION_BLEND round, int(round(x.g)), instead of truncating. No API change; the code is only compiled for that blend mode.
  • New test testLabelmapEdgeProjection, with its baseline, in Rendering/Core/VolumeMapper/test: the first test of this blend mode in the WebGL volume mapper. Skipped without WebGL, as the change is WebGL-only.

PR Checklist

  • GitHub Actions CI passed: semantic-release commit messages, lint, and tests
  • Test coverage added
  • Documentation and TypeScript definitions are updated to match these changes (no API change)

LABELMAP_EDGE_PROJECTION_BLEND read each voxel's segment with int(), which
truncates. A label sampled a hair under its whole number (25 as 24.99...)
became the segment below it, so a segment's projected outline took that
segment's color, or vanished for segment 1. Round the label instead, as the
WebGPU edge projection already does.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant