Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(scroll): was not able to scroll back #593

Merged
merged 2 commits into from
May 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/core/src/RenderingEngine/StackViewport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1461,11 +1461,13 @@ class StackViewport extends Viewport implements IStackViewport {
numComps,
pixelArray,
}): void {
const values = new pixelArray.constructor(pixelArray.length);

// Todo: I guess nothing should be done for use16bit?
const scalarArray = vtkDataArray.newInstance({
name: 'Pixels',
numberOfComponents: numComps,
values: pixelArray,
values: values,
});

this._imageData = vtkImageData.newInstance();
Expand Down
4 changes: 2 additions & 2 deletions packages/tools/src/tools/StackScrollTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class StackScrollTool extends BaseTool {
configuration: {
invert: false,
debounceIfNotLoaded: true,
loop: false
loop: false,
},
}
) {
Expand Down Expand Up @@ -65,7 +65,7 @@ class StackScrollTool extends BaseTool {
delta: invert ? -imageIdIndexOffset : imageIdIndexOffset,
volumeId,
debounceLoading: debounceIfNotLoaded,
loop: loop
loop: loop,
});

this.deltaY = deltaY % pixelsPerImage;
Expand Down
67 changes: 45 additions & 22 deletions packages/tools/test/StackScrollToolMouseWheelTool_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as testUtils from '../../../utils/test/testUtils';

import * as volumeURI_100_100_10_1_1_1_0_scrolled from './groundTruth/volumeURI_100_100_10_1_1_1_0_scrolled.png';
import * as imageURI_64_64_0_20_1_1_0_scrolled from './groundTruth/imageURI_64_64_0_20_1_1_0_scrolled.png';
import * as imageURI_64_64_15_5_3_2_0 from './groundTruth/imageURI_64_64_15_5_3_2_0.png';
import * as imageURI_64_64_10_5_3_2_0 from './groundTruth/imageURI_64_64_10_5_3_2_0.png';

const {
Expand All @@ -19,12 +20,7 @@ const {
const { Events, ViewportType, InterpolationType } = Enums;

const { registerVolumeLoader } = volumeLoader;
const {
StackScrollMouseWheelTool,
ZoomTool,
ToolGroupManager,
Enums: { MouseBindings },
} = csTools3d;
const { StackScrollMouseWheelTool, ZoomTool, ToolGroupManager } = csTools3d;

const {
fakeImageLoader,
Expand Down Expand Up @@ -80,17 +76,7 @@ describe('Cornerstone Tools Scroll Wheel: ', () => {
this.stackToolGroup.addTool(StackScrollMouseWheelTool.toolName, {
debounceIfNotLoaded: false,
});
this.stackToolGroup.addTool(ZoomTool.toolName, {
debounceIfNotLoaded: false,
});
this.stackToolGroup.setToolActive(StackScrollMouseWheelTool.toolName);
this.stackToolGroup.setToolActive(ZoomTool.toolName, {
bindings: [
{
mouseButton: MouseBindings.Secondary, // Right Click
},
],
});

this.renderingEngine = new RenderingEngine(renderingEngineId);
imageLoader.registerImageLoader('fakeImageLoader', fakeImageLoader);
Expand Down Expand Up @@ -273,7 +259,7 @@ describe('Cornerstone Tools Scroll Wheel: ', () => {
}
});

it('Should successfully scroll through stack of images of non square spacing', function (done) {
it('Should successfully scroll through stack of images and then go back', function (done) {
const element = createViewport(
this.renderingEngine,
ViewportType.STACK,
Expand All @@ -287,6 +273,8 @@ describe('Cornerstone Tools Scroll Wheel: ', () => {
const vp = this.renderingEngine.getViewport(viewportId);

let handlerRun = false;
let pageX1;
let pageY1;
function renderEventHandler() {
if (handlerRun) return;
handlerRun = true;
Expand All @@ -298,12 +286,15 @@ describe('Cornerstone Tools Scroll Wheel: ', () => {
const { imageData } = vp.getImageData();

const {
pageX: pageX1,
pageY: pageY1,
pageX,
pageY,
clientX: clientX1,
clientY: clientY1,
} = createNormalizedMouseEvent(imageData, index1, element, vp);

pageX1 = pageX;
pageY1 = pageY;

const {
pageX: pageX2,
pageY: pageY2,
Expand Down Expand Up @@ -353,18 +344,50 @@ describe('Cornerstone Tools Scroll Wheel: ', () => {
}

function attachEventHandler() {
const canvas = vp.getCanvas();

element.addEventListener(
Events.IMAGE_RENDERED,
function secondImageRendered() {
// Second render is as a result of scrolling
const image = canvas.toDataURL('image/png');
element.removeEventListener(
Events.IMAGE_RENDERED,
secondImageRendered
);

// Scroll back
setTimeout(() => {
const evt = new WheelEvent('wheel', {
target: element,
pageX: pageX1,
pageY: pageY1,
deltaX: 0,
deltaY: -12,
deltaMode: 0,
wheelDelta: 36,
wheelDeltaX: 0,
wheelDeltaY: 36,
});

attachThirdImageRenderedHandler();

element.dispatchEvent(evt);
}, 500);
}
);
}

function attachThirdImageRenderedHandler() {
const canvas = vp.getCanvas();

element.addEventListener(
Events.IMAGE_RENDERED,
function thirdImageRendered() {
// Third render is as a result of scrolling back
const image = canvas.toDataURL('image/png');
element.removeEventListener(
Events.IMAGE_RENDERED,
thirdImageRendered
);

compareImages(
image,
imageURI_64_64_10_5_3_2_0,
Expand Down
Binary file modified packages/tools/test/groundTruth/imageURI_64_64_10_5_3_2_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.