From b5203a8fadaf57ee13f4f0fc9499f16453b29f8a Mon Sep 17 00:00:00 2001 From: Paul Elliott Date: Wed, 11 Nov 2026 20:52:30 -0500 Subject: [PATCH 1/6] feat(volume-rendering): reset color and opacity to the preset defaults Adds a reset button beside the Shift and Width sliders that reapplies the selected preset to the current image. Lighting and the other cinematic rendering settings are kept. --- src/components/VolumeRendering.vue | 91 +++++++++---- tests/specs/volume-coloring-reset.e2e.ts | 150 +++++++++++++++++++++ tests/specs/volume-modality-presets.e2e.ts | 54 +------- tests/specs/volumeTestUtils.ts | 52 +++++++ 4 files changed, 275 insertions(+), 72 deletions(-) create mode 100644 tests/specs/volume-coloring-reset.e2e.ts create mode 100644 tests/specs/volumeTestUtils.ts diff --git a/src/components/VolumeRendering.vue b/src/components/VolumeRendering.vue index 4771ca312..b71c61dfb 100644 --- a/src/components/VolumeRendering.vue +++ b/src/components/VolumeRendering.vue @@ -275,6 +275,13 @@ export default defineComponent({ ); }; + const canResetColoring = computed( + () => !!viewId.value && !!currentImageID.value && !!selectedPreset.value + ); + const resetColoring = () => { + if (selectedPreset.value) selectPreset(selectedPreset.value); + }; + // --- mapping range editing --- // onKeyDown('Control', () => pwfWidget.setShiftOpacityValues(true)); @@ -352,6 +359,8 @@ export default defineComponent({ request3DAnimation, cancel3DAnimation, selectPreset, + canResetColoring, + resetColoring, }; }, }); @@ -359,32 +368,66 @@ export default defineComponent({ diff --git a/tests/specs/volume-coloring-reset.e2e.ts b/tests/specs/volume-coloring-reset.e2e.ts new file mode 100644 index 000000000..b9ca054d1 --- /dev/null +++ b/tests/specs/volume-coloring-reset.e2e.ts @@ -0,0 +1,150 @@ +import { volViewPage } from '../pageobjects/volview.page'; +import { captureViewPixels, waitForModuleTransitions } from './utils'; +import { + floatVoxels, + nrrd, + openWith3DLayout, + writeNrrd, +} from './volumeTestUtils'; + +const SIZE = 16; +const EDITOR = '[data-testid="volume-opacity-editor"]'; +const RESET = '[data-testid="volume-reset-color-opacity"]'; + +const thumb = (slider: string) => $(slider).$('[role="slider"]'); +const shiftThumb = () => thumb('[data-testid="volume-color-shift"]'); +const widthThumb = () => thumb('[data-testid="volume-color-width"]'); +const ambientThumb = () => $('.v-slider*=Ambient').$('[role="slider"]'); +const sliderValue = async (slider: ChainablePromiseElement) => + String(await slider.getAttribute('aria-valuenow')); + +async function pixels(selector: string, inset: number, file: string) { + const [{ data }] = await captureViewPixels(selector, inset, file); + return data; +} + +function differingFraction(a: Buffer, b: Buffer) { + let differing = 0; + for (let index = 0; index < a.length; index += 4) { + const delta = Math.max( + Math.abs(a[index] - b[index]), + Math.abs(a[index + 1] - b[index + 1]), + Math.abs(a[index + 2] - b[index + 2]) + ); + if (delta > 8) differing++; + } + return differing / (a.length / 4); +} + +async function waitForPixels( + selector: string, + inset: number, + expected: Buffer, + matches: boolean, + timeoutMsg: string +) { + await browser.waitUntil( + async () => { + const fraction = differingFraction( + await pixels(selector, inset, 'volume-coloring-reset.png'), + expected + ); + return matches ? fraction < 0.01 : fraction > 0.05; + }, + { timeoutMsg } + ); +} + +async function stablePixels(selector: string, inset: number) { + let previous = await pixels(selector, inset, 'volume-coloring-stable.png'); + await browser.waitUntil(async () => { + const next = await pixels(selector, inset, 'volume-coloring-stable.png'); + const same = next.equals(previous); + previous = next; + return same; + }); + return previous; +} + +async function pressOn(slider: ChainablePromiseElement, key: string) { + await slider.scrollIntoView({ block: 'center', behavior: 'instant' }); + await slider.click(); + await browser.keys(key); +} + +async function dragOpacityCurve(steps: number) { + const editor = $(EDITOR).$('canvas'); + await editor.scrollIntoView({ block: 'center', behavior: 'instant' }); + const drag = browser + .action('pointer') + .move({ origin: editor, x: -60, y: 0 }) + .down(); + for (let step = 0; step < steps; step++) + drag.move({ origin: 'pointer', x: 30, y: 0, duration: 50 }); + await drag.up().perform(); +} + +describe('3D rendering color and opacity reset', () => { + it('restores Shift, Width, and the opacity curve while keeping lighting', async () => { + const name = 'volume-coloring-reset'; + const voxels = floatVoxels(SIZE, (index) => { + const offsets = [ + index % SIZE, + Math.floor(index / SIZE) % SIZE, + Math.floor(index / SIZE ** 2), + ].map((c) => c - SIZE / 2); + return Math.max(0, 1000 * (1 - Math.hypot(...offsets) / (SIZE / 2))); + }); + await openWith3DLayout( + writeNrrd(name, nrrd([], 'float', SIZE), voxels), + name + ); + await volViewPage.renderingModuleTab.waitForClickable(); + await volViewPage.renderingModuleTab.click(); + await waitForModuleTransitions(); + const reset = $(RESET); + await expect(reset).toBeEnabled(); + await expect(reset).toHaveAttribute( + 'aria-label', + 'Reset color and opacity' + ); + + // A gaussian stays highlighted once clicked, so select it before the baseline. + await dragOpacityCurve(0); + await pressOn(ambientThumb(), 'ArrowRight'); + await expect(ambientThumb()).toHaveAttribute('aria-valuenow', '0.3'); + + const shift = await sliderValue(shiftThumb()); + const width = await sliderValue(widthThumb()); + // The editor draws both the opacity curve and the color bar for Shift and Width. + const editor = await stablePixels(EDITOR, 0); + + await dragOpacityCurve(3); + await waitForPixels( + EDITOR, + 0, + editor, + false, + 'Expected dragging to change the opacity curve' + ); + await pressOn(shiftThumb(), 'End'); + await pressOn(widthThumb(), 'Home'); + await expect(shiftThumb()).not.toHaveAttribute('aria-valuenow', shift); + await expect(widthThumb()).not.toHaveAttribute('aria-valuenow', width); + + await browser.keys('Tab'); + await expect(reset).toBeFocused(); + await browser.keys('Enter'); + + await expect(shiftThumb()).toHaveAttribute('aria-valuenow', shift); + await expect(widthThumb()).toHaveAttribute('aria-valuenow', width); + await waitForPixels( + EDITOR, + 0, + editor, + true, + 'Expected reset to restore the opacity curve and color bar' + ); + await expect(ambientThumb()).toHaveAttribute('aria-valuenow', '0.3'); + }); +}); diff --git a/tests/specs/volume-modality-presets.e2e.ts b/tests/specs/volume-modality-presets.e2e.ts index c3e2d0985..da3a061d4 100644 --- a/tests/specs/volume-modality-presets.e2e.ts +++ b/tests/specs/volume-modality-presets.e2e.ts @@ -8,36 +8,17 @@ import { waitForModuleTransitions, writeManifestToFile, } from './utils'; - -const LAYOUT = { - layouts: { - default: { - direction: 'row', - items: [{ type: '3D', viewDirection: 'Superior', viewUp: 'Anterior' }], - }, - }, -}; +import { + floatVoxels, + nrrd, + openWith3DLayout, + writeNrrd, +} from './volumeTestUtils'; const VOXELS = Buffer.from( Array.from({ length: 512 }, (_, index) => index % 256) ); -const nrrd = (fields: string[], type = 'uchar', size = 8) => - [ - 'NRRD0005', - `type: ${type}`, - 'dimension: 3', - `sizes: ${size} ${size} ${size}`, - 'endian: little', - 'space: left-posterior-superior', - 'space directions: (1,0,0) (0,1,0) (0,0,1)', - 'space origin: (0,0,0)', - 'encoding: raw', - ...fields, - '', - '', - ].join('\n'); - const mha = (fields: string[]) => [ 'ObjectType = Image', @@ -49,22 +30,6 @@ const mha = (fields: string[]) => '', ].join('\n'); -function floatVoxels(size: number, valueAt: (index: number) => number) { - const buffer = Buffer.alloc(size ** 3 * 4); - for (let index = 0; index < size ** 3; index++) - buffer.writeFloatLE(valueAt(index), index * 4); - return buffer; -} - -function writeNrrd(name: string, header: string, voxels: Buffer) { - const directory = makeTempDir(name); - fs.writeFileSync( - path.join(directory, `${name}.nrrd`), - Buffer.concat([Buffer.from(header), voxels]) - ); - return `tmp/${name}/${name}.nrrd`; -} - const sliceValue = (index: number) => 100 * (index + 1); function writeDicomSeries(directory: string, modality: string, slices = 4) { @@ -91,13 +56,6 @@ function writeDicomSeries(directory: string, modality: string, slices = 4) { }); } -async function openWith3DLayout(dataUrl: string, name: string) { - const config = `${name}-layout.json`; - await writeManifestToFile(LAYOUT, config); - await volViewPage.open(`?urls=[tmp/${config},${dataUrl}]`); - await volViewPage.waitForViewCounts(0, true); -} - async function expectSelectedPreset(label: string) { await volViewPage.renderingModuleTab.waitForClickable(); await volViewPage.renderingModuleTab.click(); diff --git a/tests/specs/volumeTestUtils.ts b/tests/specs/volumeTestUtils.ts new file mode 100644 index 000000000..2adeb2dc0 --- /dev/null +++ b/tests/specs/volumeTestUtils.ts @@ -0,0 +1,52 @@ +import fs from 'node:fs'; +import path from 'node:path'; +import { volViewPage } from '../pageobjects/volview.page'; +import { makeTempDir, writeManifestToFile } from './utils'; + +const LAYOUT = { + layouts: { + default: { + direction: 'row', + items: [{ type: '3D', viewDirection: 'Superior', viewUp: 'Anterior' }], + }, + }, +}; + +export const nrrd = (fields: string[], type = 'uchar', size = 8) => + [ + 'NRRD0005', + `type: ${type}`, + 'dimension: 3', + `sizes: ${size} ${size} ${size}`, + 'endian: little', + 'space: left-posterior-superior', + 'space directions: (1,0,0) (0,1,0) (0,0,1)', + 'space origin: (0,0,0)', + 'encoding: raw', + ...fields, + '', + '', + ].join('\n'); + +export function floatVoxels(size: number, valueAt: (index: number) => number) { + const buffer = Buffer.alloc(size ** 3 * 4); + for (let index = 0; index < size ** 3; index++) + buffer.writeFloatLE(valueAt(index), index * 4); + return buffer; +} + +export function writeNrrd(name: string, header: string, voxels: Buffer) { + const directory = makeTempDir(name); + fs.writeFileSync( + path.join(directory, `${name}.nrrd`), + Buffer.concat([Buffer.from(header), voxels]) + ); + return `tmp/${name}/${name}.nrrd`; +} + +export async function openWith3DLayout(dataUrl: string, name: string) { + const config = `${name}-layout.json`; + await writeManifestToFile(LAYOUT, config); + await volViewPage.open(`?urls=[tmp/${config},${dataUrl}]`); + await volViewPage.waitForViewCounts(0, true); +} From 87f93d54aeb622805acdea1a3b2b2182a3d7ca98 Mon Sep 17 00:00:00 2001 From: Paul Elliott Date: Fri, 13 Nov 2026 18:53:17 -0500 Subject: [PATCH 2/6] test(volume-rendering): share pixel diff helper and extend reset spec timeout --- tests/specs/volume-coloring-reset.e2e.ts | 16 ++-------------- tests/specs/volume-modality-presets.e2e.ts | 15 +-------------- tests/specs/volumeTestUtils.ts | 14 ++++++++++++++ 3 files changed, 17 insertions(+), 28 deletions(-) diff --git a/tests/specs/volume-coloring-reset.e2e.ts b/tests/specs/volume-coloring-reset.e2e.ts index b9ca054d1..28696ad87 100644 --- a/tests/specs/volume-coloring-reset.e2e.ts +++ b/tests/specs/volume-coloring-reset.e2e.ts @@ -1,6 +1,7 @@ import { volViewPage } from '../pageobjects/volview.page'; import { captureViewPixels, waitForModuleTransitions } from './utils'; import { + differingFraction, floatVoxels, nrrd, openWith3DLayout, @@ -23,19 +24,6 @@ async function pixels(selector: string, inset: number, file: string) { return data; } -function differingFraction(a: Buffer, b: Buffer) { - let differing = 0; - for (let index = 0; index < a.length; index += 4) { - const delta = Math.max( - Math.abs(a[index] - b[index]), - Math.abs(a[index + 1] - b[index + 1]), - Math.abs(a[index + 2] - b[index + 2]) - ); - if (delta > 8) differing++; - } - return differing / (a.length / 4); -} - async function waitForPixels( selector: string, inset: number, @@ -146,5 +134,5 @@ describe('3D rendering color and opacity reset', () => { 'Expected reset to restore the opacity curve and color bar' ); await expect(ambientThumb()).toHaveAttribute('aria-valuenow', '0.3'); - }); + }).timeout(180_000); }); diff --git a/tests/specs/volume-modality-presets.e2e.ts b/tests/specs/volume-modality-presets.e2e.ts index da3a061d4..db8641a62 100644 --- a/tests/specs/volume-modality-presets.e2e.ts +++ b/tests/specs/volume-modality-presets.e2e.ts @@ -9,6 +9,7 @@ import { writeManifestToFile, } from './utils'; import { + differingFraction, floatVoxels, nrrd, openWith3DLayout, @@ -133,20 +134,6 @@ async function brightCenterPixels(name: string, inset: number, level = 40) { return { bright, fraction: bright / (data.length / 4) }; } -/** Fraction of RGBA pixels whose largest channel difference exceeds 8. */ -function differingFraction(a: Buffer, b: Buffer) { - let differing = 0; - for (let index = 0; index < a.length; index += 4) { - const delta = Math.max( - Math.abs(a[index] - b[index]), - Math.abs(a[index + 1] - b[index + 1]), - Math.abs(a[index + 2] - b[index + 2]) - ); - if (delta > 8) differing++; - } - return differing / (a.length / 4); -} - /** Captures the 3D view until two consecutive frames match. */ async function stableViewPixels() { const capture = async () => diff --git a/tests/specs/volumeTestUtils.ts b/tests/specs/volumeTestUtils.ts index 2adeb2dc0..f64e0c051 100644 --- a/tests/specs/volumeTestUtils.ts +++ b/tests/specs/volumeTestUtils.ts @@ -50,3 +50,17 @@ export async function openWith3DLayout(dataUrl: string, name: string) { await volViewPage.open(`?urls=[tmp/${config},${dataUrl}]`); await volViewPage.waitForViewCounts(0, true); } + +/** Fraction of RGBA pixels whose largest channel difference exceeds 8. */ +export function differingFraction(a: Buffer, b: Buffer) { + let differing = 0; + for (let index = 0; index < a.length; index += 4) { + const delta = Math.max( + Math.abs(a[index] - b[index]), + Math.abs(a[index + 1] - b[index + 1]), + Math.abs(a[index + 2] - b[index + 2]) + ); + if (delta > 8) differing++; + } + return differing / (a.length / 4); +} From 7acbed4eb6b1c3d9a80385158185bac69b684a04 Mon Sep 17 00:00:00 2001 From: Paul Elliott Date: Sun, 15 Nov 2026 03:39:38 -0500 Subject: [PATCH 3/6] refactor(volume-rendering): enable color reset once a preset is selected --- src/components/VolumeRendering.vue | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/components/VolumeRendering.vue b/src/components/VolumeRendering.vue index b71c61dfb..451d624a7 100644 --- a/src/components/VolumeRendering.vue +++ b/src/components/VolumeRendering.vue @@ -275,9 +275,7 @@ export default defineComponent({ ); }; - const canResetColoring = computed( - () => !!viewId.value && !!currentImageID.value && !!selectedPreset.value - ); + const canResetColoring = computed(() => !!selectedPreset.value); const resetColoring = () => { if (selectedPreset.value) selectPreset(selectedPreset.value); }; From 349595c3a1c61323d0c6e1f9154f5639f64bae99 Mon Sep 17 00:00:00 2001 From: Paul Elliott Date: Sun, 15 Nov 2026 03:39:44 -0500 Subject: [PATCH 4/6] test(volume-rendering): check color reset keeps a chosen preset --- tests/specs/volume-coloring-reset.e2e.ts | 13 ++++++++++++- tests/specs/volume-modality-presets.e2e.ts | 10 ++++------ tests/specs/volumeTestUtils.ts | 10 ++++++++++ 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/tests/specs/volume-coloring-reset.e2e.ts b/tests/specs/volume-coloring-reset.e2e.ts index 28696ad87..33aa2750c 100644 --- a/tests/specs/volume-coloring-reset.e2e.ts +++ b/tests/specs/volume-coloring-reset.e2e.ts @@ -4,7 +4,9 @@ import { differingFraction, floatVoxels, nrrd, + showColorPresets, openWith3DLayout, + selectedPreset, writeNrrd, } from './volumeTestUtils'; @@ -84,7 +86,7 @@ describe('3D rendering color and opacity reset', () => { return Math.max(0, 1000 * (1 - Math.hypot(...offsets) / (SIZE / 2))); }); await openWith3DLayout( - writeNrrd(name, nrrd([], 'float', SIZE), voxels), + writeNrrd(name, nrrd(['modality:=MR'], 'float', SIZE), voxels), name ); await volViewPage.renderingModuleTab.waitForClickable(); @@ -97,6 +99,13 @@ describe('3D rendering color and opacity reset', () => { 'Reset color and opacity' ); + // Reset must keep a preset chosen over the MR default. + await showColorPresets(); + await $('.thumbnail-container*=Grayscale').click(); + await expect(selectedPreset()).toHaveText('Grayscale'); + // The open preset grid pushes the opacity editor out of the capture area. + await showColorPresets(false); + // A gaussian stays highlighted once clicked, so select it before the baseline. await dragOpacityCurve(0); await pressOn(ambientThumb(), 'ArrowRight'); @@ -134,5 +143,7 @@ describe('3D rendering color and opacity reset', () => { 'Expected reset to restore the opacity curve and color bar' ); await expect(ambientThumb()).toHaveAttribute('aria-valuenow', '0.3'); + await showColorPresets(); + await expect(selectedPreset()).toHaveText('Grayscale'); }).timeout(180_000); }); diff --git a/tests/specs/volume-modality-presets.e2e.ts b/tests/specs/volume-modality-presets.e2e.ts index db8641a62..015ba3b0c 100644 --- a/tests/specs/volume-modality-presets.e2e.ts +++ b/tests/specs/volume-modality-presets.e2e.ts @@ -12,7 +12,9 @@ import { differingFraction, floatVoxels, nrrd, + showColorPresets, openWith3DLayout, + selectedPreset, writeNrrd, } from './volumeTestUtils'; @@ -61,12 +63,8 @@ async function expectSelectedPreset(label: string) { await volViewPage.renderingModuleTab.waitForClickable(); await volViewPage.renderingModuleTab.click(); await waitForModuleTransitions(); - const title = $('.v-expansion-panel-title*=Color Presets'); - await title.scrollIntoView({ block: 'center', behavior: 'instant' }); - if ((await title.getAttribute('aria-expanded')) !== 'true') { - await title.click(); - } - await expect($('.thumbnail-container.bg-blue')).toHaveText(label); + await showColorPresets(); + await expect(selectedPreset()).toHaveText(label); } describe('volume preset from declared modality', () => { diff --git a/tests/specs/volumeTestUtils.ts b/tests/specs/volumeTestUtils.ts index f64e0c051..96ab092bb 100644 --- a/tests/specs/volumeTestUtils.ts +++ b/tests/specs/volumeTestUtils.ts @@ -44,6 +44,16 @@ export function writeNrrd(name: string, header: string, voxels: Buffer) { return `tmp/${name}/${name}.nrrd`; } +export async function showColorPresets(show = true) { + const title = $('.v-expansion-panel-title*=Color Presets'); + await title.scrollIntoView({ block: 'center', behavior: 'instant' }); + if (((await title.getAttribute('aria-expanded')) === 'true') !== show) { + await title.click(); + } +} + +export const selectedPreset = () => $('.thumbnail-container.bg-blue'); + export async function openWith3DLayout(dataUrl: string, name: string) { const config = `${name}-layout.json`; await writeManifestToFile(LAYOUT, config); From 1162b6167833c9234535e1ec0b0ede33cfa8ad45 Mon Sep 17 00:00:00 2001 From: Paul Elliott Date: Mon, 16 Nov 2026 17:22:51 -0500 Subject: [PATCH 5/6] refactor(volume-rendering): make the reset button its own tooltip activator --- src/components/VolumeRendering.vue | 32 ++++++++---------------- tests/specs/volume-coloring-reset.e2e.ts | 1 - 2 files changed, 10 insertions(+), 23 deletions(-) diff --git a/src/components/VolumeRendering.vue b/src/components/VolumeRendering.vue index 451d624a7..76b33c615 100644 --- a/src/components/VolumeRendering.vue +++ b/src/components/VolumeRendering.vue @@ -275,7 +275,6 @@ export default defineComponent({ ); }; - const canResetColoring = computed(() => !!selectedPreset.value); const resetColoring = () => { if (selectedPreset.value) selectPreset(selectedPreset.value); }; @@ -357,7 +356,6 @@ export default defineComponent({ request3DAnimation, cancel3DAnimation, selectPreset, - canResetColoring, resetColoring, }; }, @@ -401,29 +399,19 @@ export default defineComponent({ /> diff --git a/tests/specs/volume-coloring-reset.e2e.ts b/tests/specs/volume-coloring-reset.e2e.ts index 33aa2750c..0860aec7a 100644 --- a/tests/specs/volume-coloring-reset.e2e.ts +++ b/tests/specs/volume-coloring-reset.e2e.ts @@ -93,7 +93,6 @@ describe('3D rendering color and opacity reset', () => { await volViewPage.renderingModuleTab.click(); await waitForModuleTransitions(); const reset = $(RESET); - await expect(reset).toBeEnabled(); await expect(reset).toHaveAttribute( 'aria-label', 'Reset color and opacity' From 327aebb317d6d93364f6b4ce14659ea1923f53d2 Mon Sep 17 00:00:00 2001 From: Paul Elliott Date: Mon, 16 Nov 2026 21:30:01 -0500 Subject: [PATCH 6/6] test(volume-rendering): wait for the load toast before using volume controls --- tests/specs/volumeTestUtils.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/specs/volumeTestUtils.ts b/tests/specs/volumeTestUtils.ts index 96ab092bb..554d391fc 100644 --- a/tests/specs/volumeTestUtils.ts +++ b/tests/specs/volumeTestUtils.ts @@ -59,6 +59,10 @@ export async function openWith3DLayout(dataUrl: string, name: string) { await writeManifestToFile(LAYOUT, config); await volViewPage.open(`?urls=[tmp/${config},${dataUrl}]`); await volViewPage.waitForViewCounts(0, true); + // The load-complete toast covers the lower panel controls for a few seconds. + await browser.waitUntil( + async () => (await $$('.Vue-Toastification__toast').length) === 0 + ); } /** Fraction of RGBA pixels whose largest channel difference exceeds 8. */