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

fix: viewRight was calculated wrong for tools #255

Merged
merged 2 commits into from
Oct 28, 2022
Merged
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
4 changes: 1 addition & 3 deletions packages/core/examples/stackEvents/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,10 @@ addButtonToToolbar({
const newParallelScale = parallelScale * randomModifier;

// Move the camera in plane by some random number
let viewRight = vec3.create(); // Get the X direction of the viewport
const viewRight = vec3.create(); // Get the X direction of the viewport

vec3.cross(viewRight, <vec3>viewUp, <vec3>viewPlaneNormal);

viewRight = [-viewRight[0], -viewRight[1], -viewRight[2]];

const randomPanX = 50 * (2.0 * Math.random() - 1);
const randomPanY = 50 * (2.0 * Math.random() - 1);

Expand Down
9 changes: 5 additions & 4 deletions packages/core/src/RenderingEngine/Viewport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1038,12 +1038,10 @@ class Viewport implements IViewport {
const viewUpCorners = this._getCorners(bounds);
const viewRightCorners = this._getCorners(bounds);

let viewRight = vec3.create();
const viewRight = vec3.create();

vec3.cross(viewRight, viewUp, viewPlaneNormal);

viewRight = [-viewRight[0], -viewRight[1], -viewRight[2]];

let transform = vtkMatrixBuilder
.buildFromDegree()
.identity()
Expand All @@ -1067,7 +1065,10 @@ class Viewport implements IViewport {
transform = vtkMatrixBuilder
.buildFromDegree()
.identity()
.rotateFromDirections(viewRight, [1, 0, 0]);
.rotateFromDirections(
[viewRight[0], viewRight[1], viewRight[2]],
[1, 0, 0]
);

viewRightCorners.forEach((pt) => transform.apply(pt));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,10 @@ const getSubPixelSpacingAndXYDirections = (
const jVector = direction.slice(3, 6) as Types.Point3;
const kVector = direction.slice(6, 9) as Types.Point3;

let viewRight = vec3.create(); // Get the X direction of the viewport
const viewRight = vec3.create(); // Get the X direction of the viewport

vec3.cross(viewRight, <vec3>viewUp, <vec3>viewPlaneNormal);

viewRight = [-viewRight[0], -viewRight[1], -viewRight[2]];

const absViewRightDotI = Math.abs(vec3.dot(viewRight, iVector));
const absViewRightDotJ = Math.abs(vec3.dot(viewRight, jVector));
const absViewRightDotK = Math.abs(vec3.dot(viewRight, kVector));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@ export default function getWorldWidthAndHeightFromCorners(
topLeftWorld: Types.Point3,
bottomRightWorld: Types.Point3
): { worldWidth: number; worldHeight: number } {
let viewRight = vec3.create();
const viewRight = vec3.create();

vec3.cross(viewRight, <vec3>viewUp, <vec3>viewPlaneNormal);

viewRight = [-viewRight[0], -viewRight[1], -viewRight[2]];

const pos1 = vec3.fromValues(...topLeftWorld);
const pos2 = vec3.fromValues(...bottomRightWorld);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@ export default function getWorldWidthAndHeightFromTwoPoints(
worldPos1: Types.Point3,
worldPos2: Types.Point3
): { worldWidth: number; worldHeight: number } {
let viewRight = vec3.create();
const viewRight = vec3.create();

vec3.cross(viewRight, <vec3>viewUp, <vec3>viewPlaneNormal);

viewRight = [-viewRight[0], -viewRight[1], -viewRight[2]];

const pos1 = vec3.fromValues(...worldPos1);
const pos2 = vec3.fromValues(...worldPos2);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,9 @@ function _computeBoundsIJKWithCamera(
camera.viewPlaneNormal[1],
camera.viewPlaneNormal[2]
);
let viewRight = vec3.create();
const viewRight = vec3.create();

vec3.cross(viewRight, viewUp, viewPlaneNormal);
viewRight = [-viewRight[0], -viewRight[1], -viewRight[2]];

// we need to find the bounding box of the sphere in the image, e.g., the
// topLeftWorld and bottomRightWorld points of the bounding box.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ export default function getRandomlyTranslatedAndZoomedCameraProperties(

vec3.cross(viewRight, viewUp, viewPlaneNormal);

viewRight = [-viewRight[0], -viewRight[1], -viewRight[2]];

const randomPanX = maxTranslateInMM * (2.0 * Math.random() - 1);
const randomPanY = maxTranslateInMM * (2.0 * Math.random() - 1);

Expand Down