Skip to content

Commit fe9111a

Browse files
Make swapToFrame method faster (#633)
* Debounce render method so frame slider will respond faster * Remove console log Co-authored-by: Zach Mullen <zach.mullen@kitware.com> * Add explanatory comment and remove start time const Co-authored-by: Zach Mullen <zach.mullen@kitware.com>
1 parent e08fc2c commit fe9111a

3 files changed

Lines changed: 38 additions & 34 deletions

File tree

web_client/src/components/ControlPanel.vue

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,11 @@ export default {
8888
methods: {
8989
...mapActions([
9090
'setLock',
91+
'setCurrentFrame',
9192
]),
9293
...mapMutations([
9394
'setShowCrosshairs',
9495
'setStoreCrosshairs',
95-
'setCurrentFrameId',
9696
]),
9797
openScanLink() {
9898
window.open(this.currentViewData.scanLink, '_blank');
@@ -135,13 +135,13 @@ export default {
135135
}
136136
},
137137
slideToFrame(framePosition) {
138-
this.setCurrentFrameId(this.currentViewData.scanFramesList[framePosition - 1]);
138+
this.setCurrentFrame(this.currentViewData.scanFramesList[framePosition - 1]);
139139
},
140140
updateImage() {
141141
if (this.direction === 'back') {
142-
this.setCurrentFrameId(this.previousFrame);
142+
this.setCurrentFrame(this.previousFrame);
143143
} else if (this.direction === 'forward') {
144-
this.setCurrentFrameId(this.nextFrame);
144+
this.setCurrentFrame(this.nextFrame);
145145
} else if (this.direction === 'previous') {
146146
this.navigateToScan(this.currentViewData.upTo);
147147
} else if (this.direction === 'next') {
@@ -379,8 +379,6 @@ export default {
379379
</div>
380380
<v-slider
381381
:value="currentViewData.framePosition"
382-
ticks="always"
383-
tick-size="4"
384382
:min="1"
385383
:max="currentViewData.scanFramesList.length"
386384
@input="slideToFrame"

web_client/src/store/index.ts

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { createDirectStore } from 'direct-vuex';
44
import Vue from 'vue';
55
import Vuex from 'vuex';
66
import vtkProxyManager from 'vtk.js/Sources/Proxy/Core/ProxyManager';
7+
import macro from 'vtk.js/Sources/macros';
78
import { InterpolationType } from 'vtk.js/Sources/Rendering/Core/ImageProperty/Constants';
89

910
import '../utils/registerReaders';
@@ -49,9 +50,12 @@ function prepareProxyManager(proxyManager) {
4950
view.setOrientationAxesVisibility(false);
5051
view.getRepresentations().forEach((representation) => {
5152
representation.setInterpolationType(InterpolationType.NEAREST);
52-
representation.onModified(() => {
53+
representation.onModified(macro.debounce(() => {
5354
view.render(true);
54-
});
55+
}, 0));
56+
// debounce timer doesn't need a wait time because
57+
// the many onModified changes that it needs to collapse to a single rerender
58+
// all happen simultaneously when the input data is changed.
5559
});
5660
});
5761
}
@@ -755,38 +759,39 @@ const {
755759
},
756760
async swapToFrame({
757761
state, dispatch, getters, commit,
758-
}, { frame, onDownloadProgress = null }) {
762+
}, { frame, onDownloadProgress = null, loadAll = true }) {
759763
if (!frame) {
760764
throw new Error("frame id doesn't exist");
761765
}
762766
commit('setLoadingFrame', true);
763767
commit('setErrorLoadingFrame', false);
764-
const oldScan = getters.currentScan;
765-
const newScan = state.scans[frame.scan];
766-
767-
if (newScan !== oldScan && newScan) {
768-
queueLoadScan(
769-
newScan, 3,
770-
);
771-
}
772768

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

785-
if (!state.proxyManager || newProxyManager) {
786-
state.proxyManager = vtkProxyManager.newInstance({
787-
proxyConfiguration: proxy,
788-
});
789-
state.vtkViews = [];
773+
if (newScan !== oldScan && newScan) {
774+
queueLoadScan(
775+
newScan, 3,
776+
);
777+
}
778+
let newProxyManager = false;
779+
if (oldScan !== newScan && state.proxyManager) {
780+
// If we don't "shrinkProxyManager()" and reinitialize it between
781+
// scans, then we can end up with no frame
782+
// slices displayed, even though we have the data and attempted
783+
// to render it. This may be due to frame extents changing between
784+
// scans, which is not the case from one timestep of a single scan
785+
// to tne next.
786+
shrinkProxyManager(state.proxyManager);
787+
newProxyManager = true;
788+
}
789+
if (!state.proxyManager || newProxyManager) {
790+
state.proxyManager = vtkProxyManager.newInstance({
791+
proxyConfiguration: proxy,
792+
});
793+
state.vtkViews = [];
794+
}
790795
}
791796

792797
let sourceProxy = state.proxyManager.getActiveSource();
@@ -829,7 +834,7 @@ const {
829834
}
830835

831836
// check for window lock expiry
832-
if (state.windowLocked.lock) {
837+
if (loadAll && state.windowLocked.lock) {
833838
const { currentViewData } = getters;
834839
const unlock = () => {
835840
commit('setWindowLocked', {

web_client/src/views/Scan.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ export default {
8282
await this.swapToFrame({
8383
frame: this.frames[frameId],
8484
onDownloadProgress: this.onFrameDownloadProgress,
85+
loadAll: false,
8586
});
8687
},
8788
},

0 commit comments

Comments
 (0)