TrackballManipulator

Introduction

vtkTrackballManipulator.

Methods

extend

Method use to decorate a given object (publicAPI+model) with vtkTrackballManipulator characteristics.

Argument Type Required Description
publicAPI Yes object on which methods will be bounds (public)
model Yes object on which data structure will be bounds (protected)
initialValues ITrackballManipulatorInitialValues No (default: {})

newInstance

Method use to create a new instance of vtkTrackballManipulator

reset

trackballRotate

Argument Type Required Description
prevX Number Yes
prevY Number Yes
curX Number Yes
curY Number Yes
origin Vector3 Yes
direction Vector3 Yes
renderer Yes
glRenderWindow Yes

Source

index.d.ts
import {
IAbstractManipulatorInitialValues,
vtkAbstractManipulator,
} from '../AbstractManipulator';
import { Vector3 } from '../../../types';

/**
*
*/
export interface ITrackballManipulatorInitialValues
extends IAbstractManipulatorInitialValues {}

export interface vtkTrackballManipulator extends vtkAbstractManipulator {
/**
*
*/
reset(callData: any): void;
}

/**
* Method use to decorate a given object (publicAPI+model) with vtkTrackballManipulator characteristics.
*
* @param publicAPI object on which methods will be bounds (public)
* @param model object on which data structure will be bounds (protected)
* @param {ITrackballManipulatorInitialValues} [initialValues] (default: {})
*/
export function extend(
publicAPI: object,
model: object,
initialValues?: ITrackballManipulatorInitialValues
): void;

/**
* Method use to create a new instance of vtkTrackballManipulator
*/
export function newInstance(
initialValues?: ITrackballManipulatorInitialValues
): vtkTrackballManipulator;

/**
*
* @param {Number} prevX
* @param {Number} prevY
* @param {Number} curX
* @param {Number} curY
* @param {Vector3} origin
* @param {Vector3} direction
* @param renderer
* @param glRenderWindow
*/
export function trackballRotate(
prevX: number,
prevY: number,
curX: number,
curY: number,
origin: Vector3,
direction: Vector3,
renderer: any,
glRenderWindow: any
): void;

/**
* vtkTrackballManipulator.
*/
export declare const vtkTrackballManipulator: {
newInstance: typeof newInstance;
extend: typeof extend;
trackballRotate: typeof trackballRotate;
};
export default vtkTrackballManipulator;
index.js
import { mat4, vec3 } from 'gl-matrix';
import macro from 'vtk.js/Sources/macros';
import * as vtkMath from 'vtk.js/Sources/Common/Core/Math';

import vtkAbstractManipulator from 'vtk.js/Sources/Widgets/Manipulators/AbstractManipulator';

export function trackballRotate(
prevX,
prevY,
curX,
curY,
origin,
direction,
renderer,
glRenderWindow
) {
const dx = curX - prevX;
const dy = curY - prevY;

const camera = renderer.getActiveCamera();
const viewUp = camera.getViewUp();
const dop = camera.getDirectionOfProjection();

const size = renderer
.getRenderWindow()
.getInteractor()
.getView()
.getViewportSize(renderer);
const xdeg = (360.0 * dx) / size[0];
const ydeg = (360.0 * dy) / size[1];

const newDirection = new Float64Array([
direction[0],
direction[1],
direction[2],
]);

const xDisplayAxis = viewUp;
const yDisplayAxis = [0, 0, 0];
vtkMath.cross(dop, viewUp, yDisplayAxis);

const rot = mat4.identity(new Float64Array(16));
mat4.rotate(rot, rot, vtkMath.radiansFromDegrees(xdeg), xDisplayAxis);
mat4.rotate(rot, rot, vtkMath.radiansFromDegrees(-ydeg), yDisplayAxis);

vec3.transformMat4(newDirection, newDirection, rot);
return newDirection;
}

// ----------------------------------------------------------------------------
// vtkTrackballManipulator methods
// ----------------------------------------------------------------------------

function vtkTrackballManipulator(publicAPI, model) {
// Set our className
model.classHierarchy.push('vtkTrackballManipulator');

let prevX = 0;
let prevY = 0;

publicAPI.handleEvent = (callData, glRenderWindow) => {
const newDirection = trackballRotate(
prevX,
prevY,
callData.position.x,
callData.position.y,
publicAPI.getOrigin(callData),
publicAPI.getNormal(callData),
callData.pokedRenderer,
glRenderWindow
);
prevX = callData.position.x;
prevY = callData.position.y;
return model._addWorldDeltas({ worldCoords: newDirection });
};

publicAPI.reset = (callData) => {
prevX = callData.position.x;
prevY = callData.position.y;
};
}

// ----------------------------------------------------------------------------
// Object factory
// ----------------------------------------------------------------------------

function defaultValues(initialValues) {
return {
...initialValues,
};
}

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

export function extend(publicAPI, model, initialValues = {}) {
vtkAbstractManipulator.extend(publicAPI, model, defaultValues(initialValues));

vtkTrackballManipulator(publicAPI, model);
}

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

export const newInstance = macro.newInstance(extend, 'vtkTrackballManipulator');

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

export default { trackballRotate, extend, newInstance };