AxesActor

Introduction

vtkAxesActor is a hybrid 2D/3D actor used to represent 3D axes in a scene.
The user can define the geometry to use for the shaft or the tip,
and the user can set the text for the three axes. The text will appear
to follow the camera since it is implemented by means of vtkCaptionActor2D.
All of the functionality of the underlying vtkCaptionActor2D objects are accessible so that,
for instance, the font attributes of the axes text can be manipulated through vtkTextProperty.
Since this class inherits from vtkProp3D, one can apply a user transform to the underlying
geometry and the positioning of the labels. For example, a rotation transform could be used to
generate a left-handed axes representation.

See Also

vtkAnnotatedCubeActor

vtkOrientationMarkerWidget

Methods

extend

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

getConfig

getXAxisColor

getXAxisColorByReference

getYAxisColor

getYAxisColorByReference

getZAxisColor

getZAxisColorByReference

newInstance

Method use to create a new instance of vtkAxesActor.

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

setConfig

Argument Type Required Description
config Yes

setXAxisColor

Set X axis color.

Argument Type Required Description
r Number Yes Defines the red component (between 0 and 1).
g Number Yes Defines the green component (between 0 and 1).
b Number Yes Defines the blue component (between 0 and 1).

setXAxisColorFrom

Set X axis color.

Argument Type Required Description
XAxisColor Yes

setYAxisColor

Set Y axis color.

Argument Type Required Description
r Number Yes Defines the red component (between 0 and 1).
g Number Yes Defines the green component (between 0 and 1).
b Number Yes Defines the blue component (between 0 and 1).

setYAxisColorFrom

Set Y axis color.

Argument Type Required Description
YAxisColor Yes

setZAxisColor

Set Z axis color.

Argument Type Required Description
r Number Yes Defines the red component (between 0 and 1).
g Number Yes Defines the green component (between 0 and 1).
b Number Yes Defines the blue component (between 0 and 1).

setZAxisColorFrom

Set E axis color.

Argument Type Required Description
ZAxisColor Yes

update

Source

index.d.ts
import vtkActor, { IActorInitialValues } from '../Actor';

/**
*
*/
export interface IAxesActorInitialValues extends IActorInitialValues {}

export interface vtkAxesActor extends vtkActor {

/**
*
*/
getConfig(): object;

/**
*
*/
getXAxisColor(): number[];

/**
*
*/
getXAxisColorByReference(): number[];

/**
*
*/
getYAxisColor(): number[];

/**
*
*/
getYAxisColorByReference(): number[];

/**
*
*/
getZAxisColor(): number[];

/**
*
*/
getZAxisColorByReference(): number[];

/**
*
* @param config
*/
setConfig(config: object): boolean;

/**
* Set X axis color.
* @param {Number} r Defines the red component (between 0 and 1).
* @param {Number} g Defines the green component (between 0 and 1).
* @param {Number} b Defines the blue component (between 0 and 1).
*/
setXAxisColor(r: number, g: number, b: number): boolean;

/**
* Set X axis color.
* @param XAxisColor
*/
setXAxisColorFrom(XAxisColor: number[]): boolean;

/**
* Set Y axis color.
* @param {Number} r Defines the red component (between 0 and 1).
* @param {Number} g Defines the green component (between 0 and 1).
* @param {Number} b Defines the blue component (between 0 and 1).
*/
setYAxisColor(r: number, g: number, b: number): boolean;

/**
* Set Y axis color.
* @param YAxisColor
*/
setYAxisColorFrom(YAxisColor: number[]): boolean;

/**
* Set Z axis color.
* @param {Number} r Defines the red component (between 0 and 1).
* @param {Number} g Defines the green component (between 0 and 1).
* @param {Number} b Defines the blue component (between 0 and 1).
*/
setZAxisColor(r: number, g: number, b: number): boolean;

/**
* Set E axis color.
* @param ZAxisColor
*/
setZAxisColorFrom(ZAxisColor: number[]): boolean;

/**
*
*/
update(): void;
}

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

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

/**
* vtkAxesActor is a hybrid 2D/3D actor used to represent 3D axes in a scene.
* The user can define the geometry to use for the shaft or the tip,
* and the user can set the text for the three axes. The text will appear
* to follow the camera since it is implemented by means of vtkCaptionActor2D.
* All of the functionality of the underlying vtkCaptionActor2D objects are accessible so that,
* for instance, the font attributes of the axes text can be manipulated through vtkTextProperty.
* Since this class inherits from vtkProp3D, one can apply a user transform to the underlying
* geometry and the positioning of the labels. For example, a rotation transform could be used to
* generate a left-handed axes representation.
* @see [vtkAnnotatedCubeActor](./Rendering_Core_AnnotatedCubeActor.html)
* @see [vtkOrientationMarkerWidget](./Interaction_Widgets_OrientationMarkerWidget.html)
*/
export declare const vtkAxesActor: {
newInstance: typeof newInstance,
extend: typeof extend,
};
export default vtkAxesActor;
index.js
import macro from 'vtk.js/Sources/macros';
import vtkMatrixBuilder from 'vtk.js/Sources/Common/Core/MatrixBuilder';
import vtkDataArray from 'vtk.js/Sources/Common/Core/DataArray';
import vtkActor from 'vtk.js/Sources/Rendering/Core/Actor';
import vtkMapper from 'vtk.js/Sources/Rendering/Core/Mapper';
import vtkArrowSource from 'vtk.js/Sources/Filters/Sources/ArrowSource';
import vtkAppendPolyData from 'vtk.js/Sources/Filters/General/AppendPolyData';

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

function centerDataSet(ds) {
const bounds = ds.getPoints().getBounds();
const center = [
-(bounds[0] + bounds[1]) * 0.5,
-(bounds[2] + bounds[3]) * 0.5,
-(bounds[4] + bounds[5]) * 0.5,
];
vtkMatrixBuilder
.buildFromDegree()
.translate(...center)
.apply(ds.getPoints().getData());
}

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

function addColor(ds, r, g, b) {
const size = ds.getPoints().getData().length;
const rgbArray = new Uint8Array(size);
let offset = 0;

while (offset < size) {
rgbArray[offset++] = r;
rgbArray[offset++] = g;
rgbArray[offset++] = b;
}

ds.getPointData().setScalars(
vtkDataArray.newInstance({
name: 'color',
numberOfComponents: 3,
values: rgbArray,
})
);
}

// ----------------------------------------------------------------------------
// vtkAxesActor
// ----------------------------------------------------------------------------

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

publicAPI.update = () => {
const xAxis = vtkArrowSource
.newInstance({ direction: [1, 0, 0], ...model.config })
.getOutputData();
centerDataSet(xAxis);
addColor(xAxis, ...model.xAxisColor);

const yAxis = vtkArrowSource
.newInstance({ direction: [0, 1, 0], ...model.config })
.getOutputData();
centerDataSet(yAxis);
addColor(yAxis, ...model.yAxisColor);

const zAxis = vtkArrowSource
.newInstance({ direction: [0, 0, 1], ...model.config })
.getOutputData();
centerDataSet(zAxis);
addColor(zAxis, ...model.zAxisColor);

const source = vtkAppendPolyData.newInstance();
source.setInputData(xAxis);
source.addInputData(yAxis);
source.addInputData(zAxis);

// set mapper
const mapper = vtkMapper.newInstance();
mapper.setInputConnection(source.getOutputPort());
publicAPI.setMapper(mapper);
};

publicAPI.update();
}

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

export const DEFAULT_VALUES = {
config: {
tipResolution: 60,
tipRadius: 0.1,
tipLength: 0.2,
shaftResolution: 60,
shaftRadius: 0.03,
invert: false,
},
xAxisColor: [255, 0, 0],
yAxisColor: [255, 255, 0],
zAxisColor: [0, 128, 0],
};

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

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

// Inheritance
vtkActor.extend(publicAPI, model, initialValues);

macro.setGet(publicAPI, model, ['config']);
macro.setGetArray(
publicAPI,
model,
['xAxisColor', 'yAxisColor', 'zAxisColor'],
3,
255
);

// Object methods
vtkAxesActor(publicAPI, model);
}

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

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

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

export default { newInstance, extend };