LineManipulator

Introduction

vtkLineManipulator.

Methods

extend

Method use to decorate a given object (publicAPI+model) with vtkLineManipulator 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 ILineManipulatorInitialValues No (default: {})

getNormal

Set the normal of the line

getNormalByReference

Set the normal of the line

getOrigin

Set the origin of the line

getOriginByReference

Set the origin of the line

handleEvent

Argument Type Required Description
callData Yes
glRenderWindow Yes

newInstance

Method use to create a new instance of vtkLineManipulator

projectDisplayToLine

Argument Type Required Description
x Number Yes
y Number Yes
lineOrigin Array. Yes
lineDirection Array. Yes
renderer Yes
glRenderWindow Yes

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.

setOrigin

Set the origin of the line

Argument Type Required Description
x Number Yes The x coordinate of the origin point.
y Number Yes The y coordinate of the origin point.
z Number Yes The z coordinate of the origin point.

setOrigin

Set the origin of the line.

Argument Type Required Description
origin Array. Yes The coordinate of the origin point.

setOriginFrom

Set the origin of the line

Argument Type Required Description
origin Array. Yes The coordinate of the origin point.

Source

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

/**
*
*/
interface ILineManipulatorInitialValues {
origin?: number[];
normal?: number[];
}

export interface vtkLineManipulator extends vtkObject {

/**
* Set the normal of the line
*/
getNormal(): number[];

/**
* Set the normal of the line
*/
getNormalByReference(): number[];

/**
* Set the origin of the line
*/
getOrigin(): number[];

/**
* Set the origin of the line
*/
getOriginByReference(): number[];

/**
*
* @param callData
* @param glRenderWindow
*/
handleEvent(callData: any, glRenderWindow: any): number[];

/**
* 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;

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

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

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


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

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

/**
*
* @param {Number} x
* @param {Number} y
* @param {Number[]} lineOrigin
* @param {Number[]} lineDirection
* @param renderer
* @param glRenderWindow
*/
export function projectDisplayToLine(x: number, y: number, lineOrigin: number[], lineDirection: number[], renderer: any, glRenderWindow: any): number[];

/**
* vtkLineManipulator.
*/
export declare const vtkLineManipulator: {
newInstance: typeof newInstance,
extend: typeof extend,
projectDisplayToLine: typeof projectDisplayToLine;
};
export default vtkLineManipulator;
index.js
import macro from 'vtk.js/Sources/macros';
import * as vtkMath from 'vtk.js/Sources/Common/Core/Math';

export function projectDisplayToLine(
x,
y,
lineOrigin,
lineDirection,
renderer,
glRenderWindow
) {
const near = glRenderWindow.displayToWorld(x, y, 0, renderer);
const far = glRenderWindow.displayToWorld(x, y, 1, renderer);
const viewDir = [0, 0, 0];
vtkMath.subtract(far, near, viewDir);

const normal = [0, 0, 0];
vtkMath.cross(lineDirection, viewDir, normal);
vtkMath.cross(normal, viewDir, normal);

const numerator = vtkMath.dot(
[near[0] - lineOrigin[0], near[1] - lineOrigin[1], near[2] - lineOrigin[2]],
normal
);
const denominator = vtkMath.dot(normal, lineDirection);

const result = lineDirection.slice();
vtkMath.multiplyScalar(result, numerator / denominator);
vtkMath.add(lineOrigin, result, result);

return result;
}

// ----------------------------------------------------------------------------
// vtkLineManipulator methods
// ----------------------------------------------------------------------------

function vtkLineManipulator(publicAPI, model) {
// Set our classNae
model.classHierarchy.push('vtkLineManipulator');

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

publicAPI.handleEvent = (callData, glRenderWindow) =>
projectDisplayToLine(
callData.position.x,
callData.position.y,
model.origin,
model.normal,
callData.pokedRenderer,
glRenderWindow
);
}

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

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

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

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

vtkLineManipulator(publicAPI, model);
}

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

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

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

export default { projectDisplayToLine, extend, newInstance };