Skip to content

Commit a9aca35

Browse files
committed
fix(WidgetManager): use renderer pixel ratio for ScaleInPixels
1 parent d7b7f8c commit a9aca35

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

Sources/Widgets/Core/WidgetManager/index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ function vtkWidgetManager(publicAPI, model) {
121121
const [cwidth, cheight] = model._apiSpecificRenderWindow.getViewportSize(
122122
model._renderer
123123
);
124-
const ratio = window.devicePixelRatio || 1;
124+
const ratio = model._apiSpecificRenderWindow.getComputedDevicePixelRatio();
125125
const bwidth = String(cwidth / ratio);
126126
const bheight = String(cheight / ratio);
127127
const viewBox = `0 0 ${cwidth} ${cheight}`;
@@ -224,7 +224,11 @@ function vtkWidgetManager(publicAPI, model) {
224224
if (_renderer && _apiSpecificRenderWindow && _camera) {
225225
const [rwW, rwH] = _apiSpecificRenderWindow.getSize();
226226
const [vxmin, vymin, vxmax, vymax] = _renderer.getViewport();
227-
const rendererPixelDims = [rwW * (vxmax - vxmin), rwH * (vymax - vymin)];
227+
const pixelRatio = _apiSpecificRenderWindow.getComputedDevicePixelRatio();
228+
const rendererPixelDims = [
229+
(rwW * (vxmax - vxmin)) / pixelRatio,
230+
(rwH * (vymax - vymin)) / pixelRatio,
231+
];
228232

229233
const cameraPosition = _camera.getPosition();
230234
const cameraDir = _camera.getDirectionOfProjection();

Sources/Widgets/Core/WidgetManager/test/testWidgetManager.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ test.onlyIfWebGL('Test getPixelWorldHeightAtCoord', (t) => {
3434

3535
const container = document.querySelector('body');
3636
const rwContainer = gc.registerDOMElement(document.createElement('div'));
37+
// maintain consistent container size across browsers
38+
rwContainer.style.width = '300px';
39+
rwContainer.style.height = '300px';
40+
3741
container.appendChild(rwContainer);
3842

3943
const grw = vtkGenericRenderWindow.newInstance({ listenWindowResize: false });

Sources/Widgets/Widgets3D/ResliceCursorWidget/example/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ const widget = vtkResliceCursorWidget.newInstance();
4848
const widgetState = widget.getWidgetState();
4949
widgetState.setKeepOrthogonality(true);
5050
widgetState.setOpacity(0.6);
51-
// Use devicePixelRatio in order to have the same display handle size on all devices
52-
widgetState.setSphereRadius(10 * window.devicePixelRatio);
51+
// Set size in CSS pixel space because scaleInPixels defaults to true
52+
widgetState.setSphereRadius(10);
5353
widgetState.setLineThickness(5);
5454

5555
const showDebugActors = true;

0 commit comments

Comments
 (0)