ArrowSource

Introduction

vtkArrowSource was intended to be used as the source for a glyph.
The shaft base is always at (0,0,0). The arrow tip is always at (1,0,0).
If “Invert” is true, then the ends are flipped i.e. tip is at (0,0,0) while base is at (1, 0, 0).
The resolution of the cone and shaft can be set and default to 6.
The radius of the cone and shaft can be set and default to 0.03 and 0.1.
The length of the tip can also be set, and defaults to 0.35.

Usage

import vtkArrowSource from 'vtk.js/Sources/Filters/Sources/ArrowSource';

const arrow = vtkArrowSource.newInstance({
tipResolution: 6,
tipRadius: 0.1,
tipLength: 0.35,
shaftResolution: 6,
shaftRadius: 0.03,
invert: false,
direction: [1.0, 0.0, 0.0]});
const polydata = arrow.getOutputData();

Methods

extend

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

getDirection

Get the orientation vector of the cone.

getDirectionByReference

Get the orientation vector of the cone.

getInvert

getShaftRadius

Get the resolution of the shaft.

getShaftResolution

Get the resolution of the shaft.

getTipLength

Get the length of the tip.

getTipRadius

Get the radius of the tip.

getTipResolution

Get the resolution of the tip.

newInstance

Method used to create a new instance of vtkArrowSource.

Argument Type Required Description
initialValues IArrowSourceInitialValues No for pre-setting some of its content

requestData

Expose methods

Argument Type Required Description
inData Yes
outData Yes

setDirection

Set the direction for the arrow.

Argument Type Required Description
direction Array. Yes The direction coordinates.

setDirection

Set the direction for the arrow.

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

setDirectionFrom

Set the direction for the arrow.

Argument Type Required Description
direction Array. Yes The direction coordinates.

setInvert

Inverts the arrow direction.
When set to true, base is at [1, 0, 0] while the tip is at [0, 0, 0].

Argument Type Required Description
invert Booolean Yes

setShaftRadius

Set the radius of the shaft.

Argument Type Required Description
shaftRadius Number Yes

setShaftResolution

Set the resolution of the shaft.

Argument Type Required Description
shaftResolution Number Yes

setTipLength

Set the length of the tip.

Argument Type Required Description
tipLength Number Yes

setTipRadius

Set the radius of the tip.

Argument Type Required Description
tipRadius Number Yes

setTipResolution

Set the resolution of the tip.

Argument Type Required Description
tipResolution Number Yes

Source

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

export enum ShapeType {
TRIANGLE,
STAR,
ARROW_4,
ARROW_6
}

/**
*
*/
interface IArrowSourceInitialValues {
tipResolution?: number;
tipRadius?: number;
tipLength?: number;
shaftResolution?: number;
shaftRadius?: number;
invert?: boolean;
direction?: number[];
pointType?: string;
}

type vtkArrowSourceBase = vtkObject & Omit<vtkAlgorithm,
| 'getInputData'
| 'setInputData'
| 'setInputConnection'
| 'getInputConnection'
| 'addInputConnection'
| 'addInputData'>;

export interface vtkArrowSource extends vtkArrowSourceBase {

/**
* Get the orientation vector of the cone.
* @default [1.0, 0.0, 0.0]
*/
getDirection(): number[];

/**
* Get the orientation vector of the cone.
*/
getDirectionByReference(): number[];

/**
*
* @default false
*/
getInvert(): boolean;

/**
* Get the resolution of the shaft.
* @default 0.03
*/
getShaftRadius(): number;

/**
* Get the resolution of the shaft.
* @default 6
*/
getShaftResolution(): number;

/**
* Get the length of the tip.
* @default 0.35
*/
getTipLength(): number;

/**
* Get the radius of the tip.
* @default 0.1
*/
getTipRadius(): number;

/**
* Get the resolution of the tip.
* @default 6
*/
getTipResolution(): number;

/**
* Expose methods
* @param inData
* @param outData
*/
requestData(inData: any, outData: any): void;

/**
* Set the direction for the arrow.
* @param {Number} x The x coordinate.
* @param {Number} y The y coordinate.
* @param {Number} z The z coordinate.
*/
setDirection(x: number, y: number, z: number): boolean;

/**
* Set the direction for the arrow.
* @param {Number[]} direction The direction coordinates.
*/
setDirection(direction: number[]): boolean;

/**
* Set the direction for the arrow.
* @param {Number[]} direction The direction coordinates.
*/
setDirectionFrom(direction: number[]): boolean;

/**
* Inverts the arrow direction.
* When set to true, base is at [1, 0, 0] while the tip is at [0, 0, 0].
* @param {Booolean} invert
*/
setInvert(invert: boolean): boolean;

/**
* Set the radius of the shaft.
* @param {Number} shaftRadius
*/
setShaftRadius(shaftRadius: number): boolean;

/**
* Set the resolution of the shaft.
* @param {Number} shaftResolution
*/
setShaftResolution(shaftResolution: number): boolean;

/**
* Set the length of the tip.
* @param {Number} tipLength
*/
setTipLength(tipLength: number): boolean;

/**
* Set the radius of the tip.
* @param {Number} tipRadius
*/
setTipRadius(tipRadius: number): boolean;

/**
* Set the resolution of the tip.
* @param {Number} tipResolution
*/
setTipResolution(tipResolution: number): boolean;
}

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

/**
* Method used to create a new instance of vtkArrowSource.
* @param {IArrowSourceInitialValues} [initialValues] for pre-setting some of its content
*/
export function newInstance(initialValues?: IArrowSourceInitialValues): vtkArrowSource;

/**
* vtkArrowSource was intended to be used as the source for a glyph.
* The shaft base is always at (0,0,0). The arrow tip is always at (1,0,0).
* If "Invert" is true, then the ends are flipped i.e. tip is at (0,0,0) while base is at (1, 0, 0).
* The resolution of the cone and shaft can be set and default to 6.
* The radius of the cone and shaft can be set and default to 0.03 and 0.1.
* The length of the tip can also be set, and defaults to 0.35.
*
* @example
* ```js
* import vtkArrowSource from 'vtk.js/Sources/Filters/Sources/ArrowSource';
*
* const arrow = vtkArrowSource.newInstance({
* tipResolution: 6,
* tipRadius: 0.1,
* tipLength: 0.35,
* shaftResolution: 6,
* shaftRadius: 0.03,
* invert: false,
* direction: [1.0, 0.0, 0.0]});
* const polydata = arrow.getOutputData();
* ```
*/
export declare const vtkArrowSource: {
newInstance: typeof newInstance,
extend: typeof extend,
};
export default vtkArrowSource;
index.js
import macro from 'vtk.js/Sources/macro';
import vtkAppendPolyData from 'vtk.js/Sources/Filters/General/AppendPolyData';
import vtkConeSource from 'vtk.js/Sources/Filters/Sources/ConeSource';
import vtkCylinderSource from 'vtk.js/Sources/Filters/Sources/CylinderSource';
import vtkMatrixBuilder from 'vtk.js/Sources/Common/Core/MatrixBuilder';

// ----------------------------------------------------------------------------
// vtkArrowSource methods
// ----------------------------------------------------------------------------

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

function requestData(inData, outData) {
if (model.deleted) {
return;
}

const cylinder = vtkCylinderSource.newInstance({ capping: true });
cylinder.setResolution(model.shaftResolution);
cylinder.setRadius(model.shaftRadius);
cylinder.setHeight(1.0 - model.tipLength);
cylinder.setCenter(0, (1.0 - model.tipLength) * 0.5, 0.0);

const cylinderPD = cylinder.getOutputData();
const cylinderPts = cylinderPD.getPoints().getData();
const cylinderNormals = cylinderPD.getPointData().getNormals().getData();

// Apply transformation to the cylinder
vtkMatrixBuilder
.buildFromDegree()
.rotateZ(-90)
.apply(cylinderPts)
.apply(cylinderNormals);

const cone = vtkConeSource.newInstance();
cone.setResolution(model.tipResolution);
cone.setHeight(model.tipLength);
cone.setRadius(model.tipRadius);

const conePD = cone.getOutputData();
const conePts = conePD.getPoints().getData();

// Apply transformation to the cone
vtkMatrixBuilder
.buildFromRadian()
.translate(1.0 - model.tipLength * 0.5, 0.0, 0.0)
.apply(conePts);

const append = vtkAppendPolyData.newInstance();
append.setInputData(cylinderPD);
append.addInputData(conePD);

const appendPD = append.getOutputData();
const appendPts = appendPD.getPoints().getData();
// Center the arrow about [0, 0, 0]
vtkMatrixBuilder
.buildFromRadian()
.translate(-0.5 + model.tipLength * 0.5, 0.0, 0.0)
.apply(appendPts);
if (model.invert) {
// Apply transformation to the arrow
vtkMatrixBuilder
.buildFromRadian()
.rotateFromDirections([1, 0, 0], model.direction)
.scale(-1, -1, -1)
.apply(appendPts);

// Update output
outData[0] = appendPD;
} else {
// Apply transformation to the arrow
vtkMatrixBuilder
.buildFromRadian()
.rotateFromDirections([1, 0, 0], model.direction)
.scale(1, 1, 1)
.apply(appendPts);

// Update output
outData[0] = append.getOutputData();
}
}

// Expose methods
publicAPI.requestData = requestData;
}

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

const DEFAULT_VALUES = {
tipResolution: 6,
tipRadius: 0.1,
tipLength: 0.35,
shaftResolution: 6,
shaftRadius: 0.03,
invert: false,
direction: [1.0, 0.0, 0.0],
pointType: 'Float32Array',
};

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

export function extend(publicAPI, model, initialValues = {}) {
Object.assign(model, DEFAULT_VALUES, initialValues);

// Build VTK API
macro.obj(publicAPI, model);
macro.setGet(publicAPI, model, [
'tipResolution',
'tipRadius',
'tipLength',
'shaftResolution',
'shaftRadius',
'invert',
]);
macro.setGetArray(publicAPI, model, ['direction'], 3);
macro.algo(publicAPI, model, 0, 1);
vtkArrowSource(publicAPI, model);
}

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

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

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

export default { newInstance, extend };