Skip to content

Commit

Permalink
Merge branch 'master' into add-point-cell-support-to-hardware-selector
Browse files Browse the repository at this point in the history
  • Loading branch information
floryst authored May 20, 2022
2 parents c4dd985 + e0df8f0 commit 5b43bd7
Show file tree
Hide file tree
Showing 24 changed files with 596 additions and 240 deletions.
12 changes: 11 additions & 1 deletion BREAKING_CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## From 23.x to 24

All old-style widgets except OrientationMarkerWidget and PiecewiseGaussianWidget have been removed.
- All old-style widgets except OrientationMarkerWidget and PiecewiseGaussianWidget have been removed.

| **Old-style/deprecated widget** | **New-style widget** |
|-----------------------------------|---------------------------------|
Expand All @@ -15,6 +15,16 @@ All old-style widgets except OrientationMarkerWidget and PiecewiseGaussianWidget
| ResliceCursor | ResliceCursorWidget |

- In SVGLandmarkRepresentation: `model.showCircle` is replaced by `model.circleProps.visible`
- In vtk.js subclasses, prefix with '_' the following "protected" model variables:
- vtk*: model.openglRenderWindow -> model._openglRenderWindow
- vtk*: model.openglRenderer -> model._openglRenderer
- vtkInteractorObserver, vtkOrientationMarkerWidget : model.interactor -> model._interactor
- vtkAbstractWidget, vtkViewNode: model.parent -> model._parent
- vtkProp: model.parentProp -> model._parentProp
- vtkRenderWindowInteractor: model.view -> model._view
- vtkRenderer: model.renderWindow -> model._renderWindow
- vtkHardwareSelector: model.renderer -> model._renderer
- vtkAbstractWidget: model.widgetManager -> model._widgetManager

## From 22.x to 23

Expand Down
7 changes: 2 additions & 5 deletions Sources/Common/Core/Math/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,8 @@ function vtkSwapVectors3(v1, v2) {
}

function createArray(size = 3) {
const array = [];
while (array.length < size) {
array.push(0);
}
return array;
// faster than Array.from and/or while loop
return Array(size).fill(0);
}

// ----------------------------------------------------------------------------
Expand Down
9 changes: 6 additions & 3 deletions Sources/Interaction/Style/InteractorStyleManipulator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,16 @@ function dollyToPosition(fact, position, renderer, rwi) {

if (cam.getParallelProjection()) {
// Zoom relatively to the cursor
const aSize = rwi.getView().getViewportSize(renderer);
const view = rwi.getView();
const aSize = view.getViewportSize(renderer);
const viewport = renderer.getViewport();
const viewSize = view.getSize();
const w = aSize[0];
const h = aSize[1];
const x0 = w / 2;
const y0 = h / 2;
const x1 = position.x;
const y1 = position.y;
const x1 = position.x - viewport[0] * viewSize[0];
const y1 = position.y - viewport[1] * viewSize[1];
translateCamera(renderer, rwi, x0, y0, x1, y1);
cam.setParallelScale(cam.getParallelScale() / fact);
translateCamera(renderer, rwi, x1, y1, x0, y0);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import test from 'tape-catch';
import { vec3 } from 'gl-matrix';
import testUtils from 'vtk.js/Sources/Testing/testUtils';

import 'vtk.js/Sources/Rendering/Misc/RenderingAPIs';
import vtkRenderWindow from 'vtk.js/Sources/Rendering/Core/RenderWindow';
import vtkRenderer from 'vtk.js/Sources/Rendering/Core/Renderer';
import vtkRenderWindowInteractor from 'vtk.js/Sources/Rendering/Core/RenderWindowInteractor';
import vtkInteractorStyleManipulator from 'vtk.js/Sources/Interaction/Style/InteractorStyleManipulator';

function setup(t) {
// set up environment
const gc = testUtils.createGarbageCollector(t);
const container = document.querySelector('body');
const renderWindowContainer = gc.registerDOMElement(
document.createElement('div')
);
container.appendChild(renderWindowContainer);

const renderWindow = gc.registerResource(vtkRenderWindow.newInstance());
const renderer = gc.registerResource(vtkRenderer.newInstance());
renderWindow.addRenderer(renderer);

const view = gc.registerResource(renderWindow.newAPISpecificView());
view.setContainer(renderWindowContainer);
renderWindow.addView(view);
view.setSize(400, 400);

const interactor = gc.registerResource(
vtkRenderWindowInteractor.newInstance()
);
interactor.setView(view);
interactor.initialize();
interactor.bindEvents(renderWindowContainer);

const style = vtkInteractorStyleManipulator.newInstance();
interactor.setInteractorStyle(style);

return { gc, renderWindow, renderer, view, interactor, style };
}

test.onlyIfWebGL('Test dollyToPosition with 2D renderers', (t) => {
const { gc, renderer, renderWindow, interactor } = setup(t);
const camera = renderer.getActiveCamera();
camera.setParallelProjection(true);
let baseline = [];

function resetCamera() {
camera.setPosition(0, 0, 0);
camera.setDirectionOfProjection(0, 0, 1);
camera.setViewUp(0, 1, 0);
camera.setFocalPoint(0, 0, 2);
renderer.resetCamera([0, 1, 0, 1, 0, 1]);
}

resetCamera();
renderWindow.render();

baseline = camera.getPosition();
vtkInteractorStyleManipulator.dollyToPosition(
1,
{ x: 10, y: 20 },
renderer,
interactor
);
t.deepEquals(
camera.getPosition(),
baseline,
'Factor=1 does not change position'
);

resetCamera();
renderer.setViewport(0, 0, 0.5, 0.5);
renderWindow.render();

vtkInteractorStyleManipulator.dollyToPosition(
0.5,
{ x: 10, y: 10 },
renderer,
interactor
);
baseline = camera.getPosition();

resetCamera();
renderer.setViewport(0.5, 0, 1, 0.5);
renderWindow.render();

vtkInteractorStyleManipulator.dollyToPosition(
0.5,
// adjust mouse position to be in the same spot on the renderer
// as before.
{ x: 210, y: 10 },
renderer,
interactor
);

t.ok(
vec3.equals(camera.getPosition(), baseline),
'Factor=0.5, right positioned renderer'
);

gc.releaseResources();
});
29 changes: 25 additions & 4 deletions Sources/Rendering/Core/Camera/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ function vtkCamera(publicAPI, model) {
const dopbasis = new Float64Array([0.0, 0.0, -1.0]);
const upbasis = new Float64Array([0.0, 1.0, 0.0]);
const tmpMatrix = mat4.identity(new Float64Array(16));
const tmpMatrix2 = mat4.identity(new Float64Array(16));
const tmpvec1 = new Float64Array(3);
const tmpvec2 = new Float64Array(3);
const tmpvec3 = new Float64Array(3);
Expand Down Expand Up @@ -71,7 +72,7 @@ function vtkCamera(publicAPI, model) {

// recompute the focal distance
publicAPI.computeDistance();

publicAPI.computeCameraLightTransform();
publicAPI.modified();
};

Expand All @@ -90,7 +91,7 @@ function vtkCamera(publicAPI, model) {

// recompute the focal distance
publicAPI.computeDistance();

publicAPI.computeCameraLightTransform();
publicAPI.modified();
};

Expand All @@ -113,7 +114,7 @@ function vtkCamera(publicAPI, model) {
model.focalPoint[0] = model.position[0] + vec[0] * model.distance;
model.focalPoint[1] = model.position[1] + vec[1] * model.distance;
model.focalPoint[2] = model.position[2] + vec[2] * model.distance;

publicAPI.computeCameraLightTransform();
publicAPI.modified();
};

Expand Down Expand Up @@ -348,7 +349,26 @@ function vtkCamera(publicAPI, model) {
publicAPI.getFrustumPlanes = (aspect) => {
// Return array of 24 params (4 params for each of 6 plane equations)
};
publicAPI.getCameraLightTransformMatrix = () => {};
publicAPI.getCameraLightTransformMatrix = (matrix) => {
mat4.copy(matrix, model.cameraLightTransform);
return matrix;
};

publicAPI.computeCameraLightTransform = () => {
// not sure if this is the correct transformation, based on the same funciton in VTK
mat4.copy(tmpMatrix, publicAPI.getViewMatrix());
mat4.invert(tmpMatrix, tmpMatrix);

mat4.fromScaling(tmpMatrix2, [
model.distance,
model.distance,
model.distance,
]);
mat4.multiply(tmpMatrix, tmpMatrix, tmpMatrix2);
mat4.identity(model.cameraLightTransform);
mat4.translate(model.cameraLightTransform, tmpMatrix, [0.0, 0.0, -1.0]);
};

publicAPI.deepCopy = (sourceCamera) => {};

publicAPI.physicalOrientationToWorldDirection = (ori) => {
Expand Down Expand Up @@ -715,6 +735,7 @@ export const DEFAULT_VALUES = {
freezeFocalPoint: false,
projectionMatrix: null,
viewMatrix: null,
cameraLightTransform: mat4.create(),

// used for world to physical transformations
physicalTranslation: [0, 0, 0],
Expand Down
17 changes: 17 additions & 0 deletions Sources/Rendering/Core/ColorTransferFunction/Constants.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export declare enum ColorSpace {
RGB = 0,
HSV = 1,
LAB = 2,
DIVERGING = 3,
}

export declare enum Scale {
LINEAR = 0,
LOG10 = 1,
}

declare const _default: {
ColorSpace: typeof ColorSpace;
Scale: typeof Scale;
};
export default _default;
14 changes: 3 additions & 11 deletions Sources/Rendering/Core/ColorTransferFunction/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
import { vtkObject } from '../../../interfaces';
import { ColorSpace, Scale } from "./Constants";

export enum ColorSpace {
RGB,
HSV,
LAB,
DIVERGING,
}

export enum Scale {
LINEAR,
LOG10,
}

/* TODO: use VtkScalarsToColors instead of VtkObject */
export interface vtkColorTransferFunction extends vtkObject {
Expand Down Expand Up @@ -358,5 +348,7 @@ export function newInstance(initialValues?: object): vtkColorTransferFunction;
export declare const vtkColorTransferFunction: {
newInstance: typeof newInstance;
extend: typeof extend;
ColorSpace: typeof ColorSpace;
Scale: typeof Scale;
};
export default vtkColorTransferFunction;
14 changes: 14 additions & 0 deletions Sources/Rendering/Core/Coordinate/Constants.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export declare enum Coordinate {
DISPLAY = 0,
NORMALIZED_DISPLAY = 1,
VIEWPORT = 2,
NORMALIZED_VIEWPORT = 3,
PROJECTION = 4,
VIEW = 5,
WORLD = 6,
}

declare const _default: {
Coordinate: typeof Coordinate;
};
export default _default;
17 changes: 5 additions & 12 deletions Sources/Rendering/Core/Coordinate/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
import { vtkObject, vtkProperty } from "../../../interfaces";
import vtkRenderer from '../Renderer';
import { Coordinate } from "./Constants";

export enum Coordinate {
DISPLAY,
NORMALIZED_DISPLAY,
VIEWPORT,
NORMALIZED_VIEWPORT,
PROJECTION,
VIEW,
WORLD,
}

/**
*
Expand Down Expand Up @@ -73,7 +65,7 @@ export interface vtkCoordinate extends vtkObject {
* options are Display, Normalized Display, Viewport, Normalized Viewport,
* View, and World.
*/
getCoordinateSystem(): number;
getCoordinateSystem(): Coordinate;

/**
* Get the coordinate system which this coordinate is defined in as string.
Expand Down Expand Up @@ -251,7 +243,8 @@ export function newInstance(initialValues?: ICoordinateInitialValues): vtkCoordi
* @see [vtkActor](./Rendering_Core_Actor.html)2D
*/
export declare const vtkCoordinate: {
newInstance: typeof newInstance,
extend: typeof extend,
newInstance: typeof newInstance;
extend: typeof extend;
Coordinate: typeof Coordinate;
};
export default vtkCoordinate;
17 changes: 17 additions & 0 deletions Sources/Rendering/Core/Glyph3DMapper/Constants.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export declare enum OrientationModes {
DIRECTION = 0,
ROTATION = 1,
MATRIX = 2,
}

export declare enum ScaleModes {
SCALE_BY_CONSTANT = 0,
SCALE_BY_MAGNITUDE = 1,
SCALE_BY_COMPONENTS = 2,
}

declare const _default: {
OrientationModes: typeof OrientationModes;
ScaleModes: typeof ScaleModes;
};
export default _default;
14 changes: 3 additions & 11 deletions Sources/Rendering/Core/Glyph3DMapper/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
import { Bounds } from "../../../types";
import vtkMapper, { IMapperInitialValues } from "../Mapper";
import { OrientationModes, ScaleModes } from "./Constants";

export enum OrientationModes {
DIRECTION,
ROTATION,
MATRIX,
}

export enum ScaleModes {
SCALE_BY_CONSTANT,
SCALE_BY_MAGNITUDE,
SCALE_BY_COMPONENTS,
}

interface IPrimitiveCount {
points: number;
Expand Down Expand Up @@ -168,5 +158,7 @@ export function newInstance(initialValues?: IGlyph3DMapperInitialValues): vtkGly
export declare const vtkGlyph3DMapper: {
newInstance: typeof newInstance;
extend: typeof extend;
OrientationModes: typeof OrientationModes;
ScaleModes: typeof ScaleModes;
}
export default vtkGlyph3DMapper;
14 changes: 14 additions & 0 deletions Sources/Rendering/Core/ImageMapper/Constants.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export declare enum SlicingMode {
NONE = -1,
I = 0,
J = 1,
K = 2,
X = 3,
Y = 4,
Z = 5,
}

declare const _default: {
SlicingMode: typeof SlicingMode;
};
export default _default;
Loading

0 comments on commit 5b43bd7

Please sign in to comment.