Skip to content
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
16 changes: 8 additions & 8 deletions Sources/Common/DataModel/BoundingBox/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,14 +285,14 @@ function oppositeSign(a, b) {
}

export function getCorners(bounds, corners) {
let count = 0;
for (let ix = 0; ix < 2; ix++) {
for (let iy = 2; iy < 4; iy++) {
for (let iz = 4; iz < 6; iz++) {
corners[count++] = [bounds[ix], bounds[iy], bounds[iz]];
}
}
}
corners[0] = [bounds[0], bounds[2], bounds[4]];
corners[1] = [bounds[0], bounds[2], bounds[5]];
corners[2] = [bounds[0], bounds[3], bounds[4]];
corners[3] = [bounds[0], bounds[3], bounds[5]];
corners[4] = [bounds[1], bounds[2], bounds[4]];
corners[5] = [bounds[1], bounds[2], bounds[5]];
corners[6] = [bounds[1], bounds[3], bounds[4]];
corners[7] = [bounds[1], bounds[3], bounds[5]];
return corners;
}

Expand Down
60 changes: 20 additions & 40 deletions Sources/Interaction/Style/InteractorStyleMPRSlice/index.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,18 @@
import macro from 'vtk.js/Sources/macros';
import * as vtkMath from 'vtk.js/Sources/Common/Core/Math';
import vtkMatrixBuilder from 'vtk.js/Sources/Common/Core/MatrixBuilder';
import vtkBoundingBox from 'vtk.js/Sources/Common/DataModel/BoundingBox';
import vtkInteractorStyleManipulator from 'vtk.js/Sources/Interaction/Style/InteractorStyleManipulator';
import vtkMouseCameraTrackballRotateManipulator from 'vtk.js/Sources/Interaction/Manipulators/MouseCameraTrackballRotateManipulator';
import vtkMouseCameraTrackballPanManipulator from 'vtk.js/Sources/Interaction/Manipulators/MouseCameraTrackballPanManipulator';
import vtkMouseCameraTrackballZoomManipulator from 'vtk.js/Sources/Interaction/Manipulators/MouseCameraTrackballZoomManipulator';
import vtkMouseRangeManipulator from 'vtk.js/Sources/Interaction/Manipulators/MouseRangeManipulator';

import { mat4 } from 'gl-matrix';
// ----------------------------------------------------------------------------
// Global methods
// ----------------------------------------------------------------------------

function boundsToCorners(bounds) {
return [
[bounds[0], bounds[2], bounds[4]],
[bounds[0], bounds[2], bounds[5]],
[bounds[0], bounds[3], bounds[4]],
[bounds[0], bounds[3], bounds[5]],
[bounds[1], bounds[2], bounds[4]],
[bounds[1], bounds[2], bounds[5]],
[bounds[1], bounds[3], bounds[4]],
[bounds[1], bounds[3], bounds[5]],
];
}

// ----------------------------------------------------------------------------

function clamp(value, min, max) {
Expand Down Expand Up @@ -153,14 +142,9 @@ function vtkInteractorStyleMPRSlice(publicAPI, model) {

if (model.volumeMapper) {
const range = publicAPI.getSliceRange();
const bounds = model.volumeMapper.getBounds();

const clampedSlice = clamp(slice, ...range);
const center = [
(bounds[0] + bounds[1]) / 2.0,
(bounds[2] + bounds[3]) / 2.0,
(bounds[4] + bounds[5]) / 2.0,
];
const center = model.volumeMapper.getCenter();

const distance = camera.getDistance();
const dop = camera.getDirectionOfProjection();
Expand Down Expand Up @@ -193,37 +177,33 @@ function vtkInteractorStyleMPRSlice(publicAPI, model) {
if (model.volumeMapper) {
const sliceNormal = publicAPI.getSliceNormal();

if (
sliceNormal[0] === cache.sliceNormal[0] &&
sliceNormal[1] === cache.sliceNormal[1] &&
sliceNormal[2] === cache.sliceNormal[2]
) {
if (vtkMath.areEquals(sliceNormal, cache.sliceNormal)) {
return cache.sliceRange;
}

const bounds = model.volumeMapper.getBounds();
const points = boundsToCorners(bounds);

// Get rotation matrix from normal to +X (since bounds is aligned to XYZ)
const transform = vtkMatrixBuilder
const sliceOrientation = vtkMatrixBuilder
.buildFromDegree()
.identity()
.rotateFromDirections(sliceNormal, [1, 0, 0]);
const imageAlongSliceNormal = mat4.create();
mat4.multiply(
imageAlongSliceNormal,
sliceOrientation.getMatrix(),
model.volumeMapper.getInputData().getIndexToWorld()
);

points.forEach((pt) => transform.apply(pt));
// Transform the 8 corners of the input data's bounding box
// to rotate into the slice plane space without the intermediate
// axis-aligned box (provided by getBounds) which would grow the bounds.
const transformedBounds = vtkBoundingBox.transformBounds(
model.volumeMapper.getInputData().getSpatialExtent(),
imageAlongSliceNormal
);

// range is now maximum X distance
let minX = Infinity;
let maxX = -Infinity;
for (let i = 0; i < 8; i++) {
const x = points[i][0];
if (x > maxX) {
maxX = x;
}
if (x < minX) {
minX = x;
}
}
const minX = transformedBounds[0];
const maxX = transformedBounds[1];

cache.sliceNormal = sliceNormal;
cache.sliceRange = [minX, maxX];
Expand Down
7 changes: 7 additions & 0 deletions Sources/Rendering/Core/Prop3D/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,13 @@ function vtkProp3D(publicAPI, model) {
return model.properties[mapperInputPort];
};

publicAPI.getProperties = () => {
if (model.properties.length === 0) {
model.properties[0] = publicAPI.makeProperty?.();
}
return model.properties;
};

publicAPI.setProperty = (firstArg, secondArg) => {
// Two options for argument layout:
// - (mapperInputPort, property)
Expand Down