Actor2D

Introduction

vtkActor2D is used to represent a 2D entity in a rendering scene. It inherits
functions related to the actors position, and orientation from
vtkProp. The actor also has scaling and maintains a reference to the
defining geometry (i.e., the mapper), rendering properties, and possibly a
texture map.

See Also

vtkMapper2D

vtkProperty2D

Methods

extend

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

getActors2D

getActualPositionCoordinate

Return the actual vtkCoordinate reference that the mapper should use
to position the actor. This is used internally by the mappers and should
be overridden in specialized subclasses and otherwise ignored.

getActualPositionCoordinate2

getBounds

Get the bounds as [xmin, xmax, ymin, ymax, zmin, zmax].

getHeight

getIsOpaque

getMapper

Gets the 2D mapper.

getProperty

Return the property object that controls this actors surface
properties. This should be an instance of a vtkProperty2D object. Every
actor must have a property associated with it. If one isn’t specified,
then one will be generated automatically. Multiple actors can share one
property object.

getWidth

hasTranslucentPolygonalGeometry

makeProperty

Create a new property suitable for use with this type of Actor.

Argument Type Required Description
initialValues IProperty2DInitialValues No (default: {})

newInstance

Method use to create a new instance of vtkActor2D

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

setDisplayPosition

Set the Prop2D’s position in display coordinates.

Argument Type Required Description
XPos Yes
YPos Yes

setHeight

Argument Type Required Description
w Yes

setMapper

Sets the 2D mapper.

setWidth

Argument Type Required Description
w Yes

Source

index.d.ts
import vtkProp, { IPropInitialValues } from '../Prop';
import vtkCoordinate from '../Coordinate';
import vtkMapper from '../Mapper';
import vtkProperty2D, { IProperty2DInitialValues } from '../Property2D';
import vtkMapper2D from '../Mapper2D';
import { Bounds } from '../../../types';

/**
*
*/
export interface IActor2DInitialValues extends IPropInitialValues {
mapper?: vtkMapper;
property?: vtkProperty2D;
layerNumber?: number;
positionCoordinate?: vtkCoordinate;
positionCoordinate2?: vtkCoordinate;
}

export interface vtkActor2D extends vtkProp {
/**
*
* @return
*/
getActors2D(): any;

/**
*
* @return
*/
getIsOpaque(): boolean;

/**
* Return the property object that controls this actors surface
* properties. This should be an instance of a vtkProperty2D object. Every
* actor must have a property associated with it. If one isn’t specified,
* then one will be generated automatically. Multiple actors can share one
* property object.
*/
getProperty(): vtkProperty2D;

/**
* Create a new property suitable for use with this type of Actor.
* @param {IProperty2DInitialValues} [initialValues] (default: {})
*/
makeProperty(initialValues?: IProperty2DInitialValues): vtkProperty2D;

/**
* Sets the 2D mapper.
*/
setMapper(mapper: vtkMapper2D): boolean;

/**
* Gets the 2D mapper.
*/
getMapper(): vtkMapper2D;

/**
*
*/
hasTranslucentPolygonalGeometry(): boolean;

/**
* Set the Prop2D's position in display coordinates.
* @param XPos
* @param YPos
*/
setDisplayPosition(XPos: any, YPos: any): void;

/**
*
* @param w
*/
setWidth(w: number): void;

/**
*
* @param w
*/
setHeight(h: number): void;

/**
*
*/
getWidth(): number;

/**
*
*/
getHeight(): number;

/**
* Get the bounds as [xmin, xmax, ymin, ymax, zmin, zmax].
* @return {Bounds} The bounds for the mapper.
*/
getBounds(): Bounds;

/**
* Return the actual vtkCoordinate reference that the mapper should use
* to position the actor. This is used internally by the mappers and should
* be overridden in specialized subclasses and otherwise ignored.
*/
getActualPositionCoordinate(): vtkCoordinate;

/**
*
*/
getActualPositionCoordinate2(): vtkCoordinate;
}

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

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

/**
* vtkActor2D is used to represent a 2D entity in a rendering scene. It inherits
* functions related to the actors position, and orientation from
* vtkProp. The actor also has scaling and maintains a reference to the
* defining geometry (i.e., the mapper), rendering properties, and possibly a
* texture map.
* @see [vtkMapper2D](./Rendering_Core_Mapper2D.html)
* @see [vtkProperty2D](./Rendering_Core_Property2D.html)
*/
export declare const vtkActor2D: {
newInstance: typeof newInstance;
extend: typeof extend;
};
export default vtkActor2D;
index.js
import macro from 'vtk.js/Sources/macros';
import vtkCoordinate from 'vtk.js/Sources/Rendering/Core/Coordinate';
import vtkProp from 'vtk.js/Sources/Rendering/Core/Prop';
import vtkProperty2D from 'vtk.js/Sources/Rendering/Core/Property2D';
import { Coordinate } from 'vtk.js/Sources/Rendering/Core/Coordinate/Constants';

// ----------------------------------------------------------------------------
// vtkActor2D methods
// ----------------------------------------------------------------------------

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

publicAPI.getActors2D = () => publicAPI;

publicAPI.getIsOpaque = () => {
// make sure we have a property
if (!model.property) {
// force creation of a property
publicAPI.getProperty();
}

let isOpaque = model.property.getOpacity() >= 1.0;

// are we using an opaque texture, if any?
isOpaque = isOpaque && (!model.texture || !model.texture.isTranslucent());

return isOpaque;
};

publicAPI.hasTranslucentPolygonalGeometry = () => {
if (model.mapper === null) {
return false;
}
// make sure we have a property
if (model.property === null) {
// force creation of a property
publicAPI.setProperty(publicAPI.makeProperty());
}

// is this actor opaque ?
return !publicAPI.getIsOpaque();
};

publicAPI.makeProperty = vtkProperty2D.newInstance;

publicAPI.getProperty = () => {
if (model.property === null) {
model.property = publicAPI.makeProperty();
}
return model.property;
};

//----------------------------------------------------------------------------
// Set the Prop2D's position in display coordinates.
publicAPI.setDisplayPosition = (XPos, YPos) => {
model.positionCoordinate.setCoordinateSystem(Coordinate.DISPLAY);
model.positionCoordinate.setValue(XPos, YPos, 0.0);
};

//----------------------------------------------------------------------------
publicAPI.setWidth = (w) => {
const pos = model.position2Coordinate.getValue();
model.position2Coordinate.setCoordinateSystemToNormalizedViewport();
model.position2Coordinate.setValue(w, pos[1]);
};

//----------------------------------------------------------------------------
publicAPI.setHeight = (w) => {
const pos = model.position2Coordinate.getValue();
model.position2Coordinate.setCoordinateSystemToNormalizedViewport();
model.position2Coordinate.setValue(pos[0], w);
};

//----------------------------------------------------------------------------
publicAPI.getWidth = () => model.position2Coordinate.getValue()[0];

//----------------------------------------------------------------------------
publicAPI.getHeight = () => model.position2Coordinate.getValue()[1];

publicAPI.getMTime = () => {
let mt = model.mtime;
if (model.property !== null) {
const time = model.property.getMTime();
mt = time > mt ? time : mt;
}

mt =
model.positionCoordinate.getMTime() > mt
? model.positionCoordinate.getMTime()
: mt;
mt =
model.positionCoordinate2.getMTime() > mt
? model.positionCoordinate2.getMTime()
: mt;

// TBD: Handle array of textures here.

return mt;
};

publicAPI.getRedrawMTime = () => {
let mt = model.mtime;
if (model.mapper !== null) {
let time = model.mapper.getMTime();
mt = time > mt ? time : mt;
if (model.mapper.getInput() !== null) {
// FIXME !!! getInputAlgorithm / getInput
model.mapper.getInputAlgorithm().update();
time = model.mapper.getInput().getMTime();
mt = time > mt ? time : mt;
}
}
return mt;
};

publicAPI.getBounds = () => {
// does our mapper support bounds
if (typeof publicAPI.getMapper().getBounds === 'function') {
model.useBounds = true;
return publicAPI.getMapper().getBounds();
}
model.useBounds = false;
return [];
};

// Description:
// Return the actual vtkCoordinate reference that the mapper should use
// to position the actor. This is used internally by the mappers and should
// be overridden in specialized subclasses and otherwise ignored.
publicAPI.getActualPositionCoordinate = () => model.positionCoordinate;
publicAPI.getActualPositionCoordinate2 = () => model.positionCoordinate2;
}

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

const DEFAULT_VALUES = {
mapper: null,
property: null,
layerNumber: 0,
positionCoordinate: null,
positionCoordinate2: null,
};

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

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

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

model.positionCoordinate = vtkCoordinate.newInstance();
model.positionCoordinate.setCoordinateSystemToViewport();
model.positionCoordinate2 = vtkCoordinate.newInstance();
model.positionCoordinate2.setCoordinateSystemToNormalizedViewport();
model.positionCoordinate2.setValue(0.5, 0.5);
model.positionCoordinate2.setReferenceCoordinate(model.positionCoordinate);

// Build VTK API
macro.set(publicAPI, model, ['property']);
macro.setGet(publicAPI, model, ['mapper']);

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

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

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

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

export default { newInstance, extend };