Skip to content

Commit d7b7f8c

Browse files
committed
feat(RenderWindowViewNode): add getComputedDevicePixelRatio
vtkRenderWindowViewNode.getComputedDevicePixelRatio uses DOM container CSS pixel size and the user set renderer pixel size.
1 parent c39cbbd commit d7b7f8c

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

Sources/Rendering/OpenGL/RenderWindow/index.d.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,18 @@ export interface vtkOpenGLRenderWindow extends vtkOpenGLRenderWindowBase {
361361
*
362362
*/
363363
getVrResolution(): Vector2;
364+
365+
/**
366+
* Use to scale the size of a rendered canvas pixel to a browser CSS pixel.
367+
* `const cssPixelWidth = renderedPixelWidth / apiRenderWindow.getComputedDevicePixelRatio()`
368+
* Rather than using window.devicePixelRatio directly, the device pixel ratio is inferred
369+
* from the container CSS pixel size and rendered image pixel size. The user can reduce the rendered size.
370+
* `apiSpecificRenderWindow.setSize(Math.floor(container.width * window.devicePixelRatio / 2), Math.floor(container.height * window.devicePixelRatio / 2))`
371+
*
372+
* @see getContainerSize()
373+
* @see getSize()
374+
*/
375+
getComputedDevicePixelRatio(): number;
364376
}
365377

366378
/**

Sources/Rendering/SceneGraph/RenderWindowViewNode/index.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,19 @@ function vtkRenderWindowViewNode(publicAPI, model) {
135135
return publicAPI.displayToNormalizedDisplay(x2, y2, z);
136136
};
137137

138+
publicAPI.getComputedDevicePixelRatio = () =>
139+
model.size[0] / publicAPI.getContainerSize()[0];
140+
141+
publicAPI.getContainerSize = () => {
142+
macro.vtkErrorMacro('not implemented');
143+
};
144+
138145
publicAPI.getPixelData = (x1, y1, x2, y2) => {
139146
macro.vtkErrorMacro('not implemented');
140-
return undefined;
141147
};
142148

143149
publicAPI.createSelector = () => {
144150
macro.vtkErrorMacro('not implemented');
145-
return undefined;
146151
};
147152
}
148153

0 commit comments

Comments
 (0)