Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/3dcursor #1882

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 27 additions & 13 deletions packages/core/src/RenderingEngine/BaseVolumeViewport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1520,36 +1520,50 @@ abstract class BaseVolumeViewport extends Viewport {
vtkCamera.setIsPerformingCoordinateTransformation?.(true);

const renderer = this.getRenderer();
const displayCoords = this.getVTKDisplayCoords(canvasPos);
const offscreenMultiRenderWindow =
this.getRenderingEngine().offscreenMultiRenderWindow;
const openGLRenderWindow =
offscreenMultiRenderWindow.getOpenGLRenderWindow();
const size = openGLRenderWindow.getSize();
const worldCoord = openGLRenderWindow.displayToWorld(
displayCoords[0],
displayCoords[1],
displayCoords[2],
renderer
);

vtkCamera.setIsPerformingCoordinateTransformation?.(false);

return [worldCoord[0], worldCoord[1], worldCoord[2]];
};

/**
* Returns the VTK.js display coordinates of the given `canvasPos` projected onto the
* `Viewport`'s `vtkCamera`'s focal point and the direction of projection.
* @param canvasPos - The position in canvas coordinates.
* @returns The corresponding display coordinates.
*
*/
public getVTKDisplayCoords = (canvasPos: Point2): Point3 => {
const devicePixelRatio = window.devicePixelRatio || 1;
const canvasPosWithDPR = [
canvasPos[0] * devicePixelRatio,
canvasPos[1] * devicePixelRatio,
];
const offscreenMultiRenderWindow =
this.getRenderingEngine().offscreenMultiRenderWindow;
const openGLRenderWindow =
offscreenMultiRenderWindow.getOpenGLRenderWindow();
const size = openGLRenderWindow.getSize();
const displayCoord = [
canvasPosWithDPR[0] + this.sx,
canvasPosWithDPR[1] + this.sy,
];

// The y axis display coordinates are inverted with respect to canvas coords
displayCoord[1] = size[1] - displayCoord[1];

const worldCoord = openGLRenderWindow.displayToWorld(
displayCoord[0],
displayCoord[1],
0,
renderer
);

vtkCamera.setIsPerformingCoordinateTransformation?.(false);

return [worldCoord[0], worldCoord[1], worldCoord[2]];
return [displayCoord[0], displayCoord[1], 0];
};

/**
* Returns the canvas coordinates of the given `worldPos`
* projected onto the `Viewport`'s `canvas`.
Expand Down
Loading
Loading