Skip to content

Commit

Permalink
Make swapToFrame method faster (#633)
Browse files Browse the repository at this point in the history
* Debounce render method so frame slider will respond faster

* Remove console log

Co-authored-by: Zach Mullen <[email protected]>

* Add explanatory comment and remove start time const

Co-authored-by: Zach Mullen <[email protected]>
  • Loading branch information
annehaley and zachmullen authored Nov 14, 2022
1 parent e08fc2c commit fe9111a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 34 deletions.
10 changes: 4 additions & 6 deletions web_client/src/components/ControlPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ export default {
methods: {
...mapActions([
'setLock',
'setCurrentFrame',
]),
...mapMutations([
'setShowCrosshairs',
'setStoreCrosshairs',
'setCurrentFrameId',
]),
openScanLink() {
window.open(this.currentViewData.scanLink, '_blank');
Expand Down Expand Up @@ -135,13 +135,13 @@ export default {
}
},
slideToFrame(framePosition) {
this.setCurrentFrameId(this.currentViewData.scanFramesList[framePosition - 1]);
this.setCurrentFrame(this.currentViewData.scanFramesList[framePosition - 1]);
},
updateImage() {
if (this.direction === 'back') {
this.setCurrentFrameId(this.previousFrame);
this.setCurrentFrame(this.previousFrame);
} else if (this.direction === 'forward') {
this.setCurrentFrameId(this.nextFrame);
this.setCurrentFrame(this.nextFrame);
} else if (this.direction === 'previous') {
this.navigateToScan(this.currentViewData.upTo);
} else if (this.direction === 'next') {
Expand Down Expand Up @@ -379,8 +379,6 @@ export default {
</div>
<v-slider
:value="currentViewData.framePosition"
ticks="always"
tick-size="4"
:min="1"
:max="currentViewData.scanFramesList.length"
@input="slideToFrame"
Expand Down
61 changes: 33 additions & 28 deletions web_client/src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { createDirectStore } from 'direct-vuex';
import Vue from 'vue';
import Vuex from 'vuex';
import vtkProxyManager from 'vtk.js/Sources/Proxy/Core/ProxyManager';
import macro from 'vtk.js/Sources/macros';
import { InterpolationType } from 'vtk.js/Sources/Rendering/Core/ImageProperty/Constants';

import '../utils/registerReaders';
Expand Down Expand Up @@ -49,9 +50,12 @@ function prepareProxyManager(proxyManager) {
view.setOrientationAxesVisibility(false);
view.getRepresentations().forEach((representation) => {
representation.setInterpolationType(InterpolationType.NEAREST);
representation.onModified(() => {
representation.onModified(macro.debounce(() => {
view.render(true);
});
}, 0));
// debounce timer doesn't need a wait time because
// the many onModified changes that it needs to collapse to a single rerender
// all happen simultaneously when the input data is changed.
});
});
}
Expand Down Expand Up @@ -755,38 +759,39 @@ const {
},
async swapToFrame({
state, dispatch, getters, commit,
}, { frame, onDownloadProgress = null }) {
}, { frame, onDownloadProgress = null, loadAll = true }) {
if (!frame) {
throw new Error("frame id doesn't exist");
}
commit('setLoadingFrame', true);
commit('setErrorLoadingFrame', false);
const oldScan = getters.currentScan;
const newScan = state.scans[frame.scan];

if (newScan !== oldScan && newScan) {
queueLoadScan(
newScan, 3,
);
}

let newProxyManager = false;
if (oldScan !== newScan && state.proxyManager) {
// If we don't "shrinkProxyManager()" and reinitialize it between
// scans, then we can end up with no frame
// slices displayed, even though we have the data and attempted
// to render it. This may be due to frame extents changing between
// scans, which is not the case from one timestep of a single scan
// to tne next.
shrinkProxyManager(state.proxyManager);
newProxyManager = true;
}
if (loadAll) {
const oldScan = getters.currentScan;
const newScan = state.scans[frame.scan];

if (!state.proxyManager || newProxyManager) {
state.proxyManager = vtkProxyManager.newInstance({
proxyConfiguration: proxy,
});
state.vtkViews = [];
if (newScan !== oldScan && newScan) {
queueLoadScan(
newScan, 3,
);
}
let newProxyManager = false;
if (oldScan !== newScan && state.proxyManager) {
// If we don't "shrinkProxyManager()" and reinitialize it between
// scans, then we can end up with no frame
// slices displayed, even though we have the data and attempted
// to render it. This may be due to frame extents changing between
// scans, which is not the case from one timestep of a single scan
// to tne next.
shrinkProxyManager(state.proxyManager);
newProxyManager = true;
}
if (!state.proxyManager || newProxyManager) {
state.proxyManager = vtkProxyManager.newInstance({
proxyConfiguration: proxy,
});
state.vtkViews = [];
}
}

let sourceProxy = state.proxyManager.getActiveSource();
Expand Down Expand Up @@ -829,7 +834,7 @@ const {
}

// check for window lock expiry
if (state.windowLocked.lock) {
if (loadAll && state.windowLocked.lock) {
const { currentViewData } = getters;
const unlock = () => {
commit('setWindowLocked', {
Expand Down
1 change: 1 addition & 0 deletions web_client/src/views/Scan.vue
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export default {
await this.swapToFrame({
frame: this.frames[frameId],
onDownloadProgress: this.onFrameDownloadProgress,
loadAll: false,
});
},
},
Expand Down

0 comments on commit fe9111a

Please sign in to comment.