-
Notifications
You must be signed in to change notification settings - Fork 327
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
feat: added MIP option to StackScrollTool #537
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,19 +15,30 @@ import { PublicToolProps, ToolProps, EventTypes } from '../types'; | |
class StackScrollTool extends BaseTool { | ||
static toolName; | ||
deltaY: number; | ||
deltaX: number; | ||
constructor( | ||
toolProps: PublicToolProps = {}, | ||
defaultToolProps: ToolProps = { | ||
supportedInteractionTypes: ['Mouse', 'Touch'], | ||
configuration: { | ||
invert: false, | ||
leftRightMode: false, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what is the difference between leftRightMode and mipMode? can leftRightMode be not mipMode? to me this configuration is complex and not clear at the first glance. there are multiple levels that has configuration: {
activeMode: 'stackScrollMode', // or 'mipMode'
stackScrollMode: {
invert: false,
loop: false,
debounceIfNotLoaded: true,
},
mipMode: {
pixelsPerThickness: 5,
minSlabThickness: 5e-2,
maxSlabThickness: 30,
},
},
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So the following options need some way to be selected... leftRight vs upDown Both MIP and StackScroll can be active at the same time. What about something like this: configuration: {
direction: {
stackScrollMode: enums['upDown', 'downUp', null]
mipMode: enums['leftRight', 'rightLeft', null]
},
stackScrollMode: {
loop: false,
debounceIfNotLoaded: true,
},
mipMode: {
pixelsPerThickness: 5,
minSlabThickness: 5e-2,
maxSlabThickness: 30,
},
}, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how about we stick to horizontal and vertical and assume (naturally) that right is more and up is more, and we have a invert flag? configuration: {
stackScrollMode: {
enabled: true,
invert: true,
direction: 'vertical'
loop: false,
debounceIfNotLoaded: true,
},
mipMode: {
enabled: false,
invert: true,
direction: 'horizontal'
pixelsPerThickness: 5,
minSlabThickness: 5e-2,
maxSlabThickness: 30,
},
}, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. works for me! |
||
debounceIfNotLoaded: true, | ||
loop: false | ||
loop: false, | ||
stackScrollEnabled: true, | ||
mipMode: { | ||
enabled: true, | ||
invert: false, | ||
pixelsPerThickness: 5, | ||
minSlabThickness: 5e-2, | ||
maxSlabThickness: 30, | ||
}, | ||
}, | ||
} | ||
) { | ||
super(toolProps, defaultToolProps); | ||
this.deltaY = 1; | ||
this.deltaX = 1; | ||
} | ||
|
||
mouseDragCallback(evt: EventTypes.InteractionEventType) { | ||
|
@@ -42,9 +53,16 @@ class StackScrollTool extends BaseTool { | |
const { viewport } = getEnabledElementByIds(viewportId, renderingEngineId); | ||
|
||
const targetId = this.getTargetId(viewport); | ||
const { debounceIfNotLoaded, invert, loop } = this.configuration; | ||
const { | ||
debounceIfNotLoaded, | ||
invert, | ||
loop, | ||
leftRightMode, | ||
stackScrollEnabled, | ||
} = this.configuration; | ||
|
||
const deltaPointY = deltaPoints.canvas[1]; | ||
const deltaPointX = deltaPoints.canvas[0]; | ||
|
||
let volumeId; | ||
if (viewport instanceof VolumeViewport) { | ||
|
@@ -53,24 +71,66 @@ class StackScrollTool extends BaseTool { | |
|
||
const pixelsPerImage = this._getPixelPerImage(viewport); | ||
const deltaY = deltaPointY + this.deltaY; | ||
const deltaX = deltaPointX + this.deltaX; | ||
|
||
if (!pixelsPerImage) { | ||
return; | ||
} | ||
|
||
if (Math.abs(deltaY) >= pixelsPerImage) { | ||
const imageIdIndexOffset = Math.round(deltaY / pixelsPerImage); | ||
if (stackScrollEnabled && !leftRightMode) { | ||
if (Math.abs(deltaY) >= pixelsPerImage) { | ||
const imageIdIndexOffset = Math.round(deltaY / pixelsPerImage); | ||
|
||
scroll(viewport, { | ||
delta: invert ? -imageIdIndexOffset : imageIdIndexOffset, | ||
volumeId, | ||
debounceLoading: debounceIfNotLoaded, | ||
loop: loop | ||
}); | ||
scroll(viewport, { | ||
delta: invert ? -imageIdIndexOffset : imageIdIndexOffset, | ||
volumeId, | ||
debounceLoading: debounceIfNotLoaded, | ||
loop: loop, | ||
}); | ||
|
||
this.deltaY = deltaY % pixelsPerImage; | ||
} else { | ||
this.deltaY = deltaY; | ||
this.deltaY = deltaY % pixelsPerImage; | ||
} else { | ||
this.deltaY = deltaY; | ||
} | ||
} | ||
|
||
if (stackScrollEnabled && leftRightMode) { | ||
if (Math.abs(deltaX) >= pixelsPerImage) { | ||
const imageIdIndexOffset = Math.round(deltaX / pixelsPerImage); | ||
|
||
scroll(viewport, { | ||
delta: invert ? -imageIdIndexOffset : imageIdIndexOffset, | ||
volumeId, | ||
debounceLoading: debounceIfNotLoaded, | ||
loop: loop, | ||
}); | ||
|
||
this.deltaX = deltaX % pixelsPerImage; | ||
} else { | ||
this.deltaX = deltaX; | ||
} | ||
} | ||
|
||
const { mipMode } = this.configuration; | ||
if (!mipMode?.enabled) return; | ||
const { pixelsPerThickness, mipModeInvert } = mipMode; | ||
|
||
if (mipMode?.enabled && leftRightMode) { | ||
if (Math.abs(deltaY) >= pixelsPerThickness) { | ||
this._triggerMIP(viewport, deltaY > 0 ? -1 : 1, mipModeInvert); | ||
this.deltaY = deltaY % pixelsPerThickness; | ||
} else { | ||
this.deltaY = deltaY; | ||
} | ||
} | ||
|
||
if (mipMode?.enabled && !leftRightMode) { | ||
if (Math.abs(deltaX) >= pixelsPerThickness) { | ||
this._triggerMIP(viewport, deltaX > 0 ? 1 : -1, mipModeInvert); | ||
this.deltaX = deltaX % pixelsPerThickness; | ||
} else { | ||
this.deltaX = deltaX; | ||
} | ||
} | ||
} | ||
|
||
|
@@ -91,6 +151,28 @@ class StackScrollTool extends BaseTool { | |
return viewport.getImageIds().length; | ||
} | ||
} | ||
|
||
_triggerMIP(viewport, delta, invert) { | ||
const inversionValue = invert ? -1 : 1; | ||
const { minSlabThickness, maxSlabThickness } = this.configuration.mipMode; | ||
if (viewport instanceof VolumeViewport) { | ||
const slabThickness = Math.min( | ||
maxSlabThickness, | ||
viewport.getSlabThickness() + inversionValue * delta | ||
); | ||
if (slabThickness <= minSlabThickness) { | ||
viewport.setBlendMode(0); | ||
viewport.setSlabThickness(minSlabThickness); | ||
viewport.render(); | ||
} else { | ||
viewport.setBlendMode(1); | ||
viewport.setSlabThickness( | ||
slabThickness >= maxSlabThickness ? maxSlabThickness : slabThickness | ||
); | ||
viewport.render(); | ||
} | ||
} | ||
} | ||
} | ||
|
||
StackScrollTool.toolName = 'StackScroll'; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this example should get updated too right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep still need to push the changes