Skip to content

Commit 1f2a50a

Browse files
authored
Merge pull request #2623 from Kitware/perf-widget-manager
perf(WidgetManager): reduce capture/render calls
2 parents 5495580 + bd9590d commit 1f2a50a

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed

Sources/Widgets/Core/AbstractWidget/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,11 @@ export function extend(publicAPI, model, initialValues = {}) {
112112
'handleVisibility',
113113
'_widgetManager',
114114
]);
115-
macro.get(publicAPI, model, ['representations', 'widgetState']);
115+
macro.get(publicAPI, model, [
116+
'representations',
117+
'widgetState',
118+
'activeState',
119+
]);
116120
macro.moveToProtected(publicAPI, model, ['widgetManager']);
117121
macro.event(publicAPI, model, 'ActivateHandle');
118122

Sources/Widgets/Core/WidgetManager/index.js

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -283,23 +283,25 @@ function vtkWidgetManager(publicAPI, model) {
283283
// Default cursor behavior
284284
model._apiSpecificRenderWindow.setCursor(widget ? 'pointer' : 'default');
285285

286+
let wantRender = false;
286287
if (model.widgetInFocus === widget && widget.hasFocus()) {
287288
activateHandle(widget);
288-
// Ken FIXME
289-
model._interactor.render();
290-
model._interactor.render();
289+
wantRender = true;
291290
} else {
292291
for (let i = 0; i < model.widgets.length; i++) {
293292
const w = model.widgets[i];
294293
if (w === widget && w.getNestedPickable()) {
295294
activateHandle(w);
296295
model.activeWidget = w;
296+
wantRender = true;
297297
} else {
298+
wantRender ||= !!w.getActiveState();
298299
w.deactivateAllHandles();
299300
}
300301
}
301-
// Ken FIXME
302-
model._interactor.render();
302+
}
303+
304+
if (wantRender) {
303305
model._interactor.render();
304306
}
305307
}
@@ -524,17 +526,17 @@ function vtkWidgetManager(publicAPI, model) {
524526
// do we require a new capture?
525527
if (!model._capturedBuffers || model.captureOn === CaptureOn.MOUSE_MOVE) {
526528
await captureBuffers(x, y, x, y);
527-
}
528-
529-
// or do we need a pixel that is outside the last capture?
530-
const capturedRegion = model._capturedBuffers.area;
531-
if (
532-
x < capturedRegion[0] ||
533-
x > capturedRegion[2] ||
534-
y < capturedRegion[1] ||
535-
y > capturedRegion[3]
536-
) {
537-
await captureBuffers(x, y, x, y);
529+
} else {
530+
// or do we need a pixel that is outside the last capture?
531+
const capturedRegion = model._capturedBuffers.area;
532+
if (
533+
x < capturedRegion[0] ||
534+
x > capturedRegion[2] ||
535+
y < capturedRegion[1] ||
536+
y > capturedRegion[3]
537+
) {
538+
await captureBuffers(x, y, x, y);
539+
}
538540
}
539541

540542
model.selections = model._capturedBuffers.generateSelection(x, y, x, y);

0 commit comments

Comments
 (0)