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: {})

getNormal

Get normal

getNormalByReference

Get normal

handleEvent

Argument Type Required Description
callData Yes
glRenderWindow Yes

newInstance

Method use to create a new instance of vtkTrackballManipulator

reset

setNormal

Set the normal of the line.

Argument Type Required Description
x Number Yes The x coordinate.
y Number Yes The y coordinate.
z Number Yes The z coordinate.

setNormal

Set the normal of the line.

Argument Type Required Description
normal Array. Yes The normal coordinate.

setNormalFrom

Set the normal of the line.

Argument Type Required Description
normal Array. Yes The normal coordinate.

trackballRotate

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

Source

index.d.ts
import { vtkObject } from "../../../interfaces";

/**
*
*/
export interface ITrackballManipulatorInitialValues {
normal?: number[];
}

export interface vtkTrackballManipulator extends vtkObject {

/**
* Get normal
*/
getNormal(): number[];

/**
* Get normal
*/
getNormalByReference(): number[];

/**
*
* @param callData
* @param glRenderWindow
*/
handleEvent(callData: any, glRenderWindow: any): void;

/**
* Set the normal of the line.
* @param {Number[]} normal The normal coordinate.
*/
setNormal(normal: number[]): boolean;

/**
* Set the normal of the line.
* @param {Number} x The x coordinate.
* @param {Number} y The y coordinate.
* @param {Number} z The z coordinate.
*/
setNormal(x: number, y: number, z: number): boolean;

/**
* Set the normal of the line.
* @param {Number[]} normal The normal coordinate.
*/
setNormalFrom(normal: number[]): boolean;

/**
*
*/
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 {Number[]} origin
* @param {Number[]} direction
* @param renderer
* @param glRenderWindow
*/
export function trackballRotate(prevX: number, prevY: number, curX: number, curY: number, origin: number[], direction: number[], 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';

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().getSize();
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,
model.origin,
model.normal,
callData.pokedRenderer,
glRenderWindow
);
prevX = callData.position.x;
prevY = callData.position.y;
return newDirection;
};

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

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

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

const DEFAULT_VALUES = {
normal: [0, 0, 1],
};

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

export function extend(publicAPI, model, initialValues = {}) {
Object.assign(model, DEFAULT_VALUES, initialValues);
macro.obj(publicAPI, model);
macro.setGetArray(publicAPI, model, ['normal'], 3);

vtkTrackballManipulator(publicAPI, model);
}

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

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

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

export default { trackballRotate, extend, newInstance };