Actor

vtkActor is used to represent an entity in a rendering scene. It inherits
functions related to the actors position, and orientation from
vtkProp3D. The actor also has scaling and maintains a reference to the
defining geometry (i.e., the mapper), rendering properties, and possibly a
texture map. vtkActor combines these instance variables into one 4x4
transformation matrix as follows: [x y z 1] = [x y z 1] Translate(-origin)
Scale(scale) Rot(y) Rot(x) Rot (z) Trans(origin) Trans(position)

See Also

vtkMapper
vtkProperty

newInstance()

Create an actor with the following defaults:

  • origin = (0,0,0)
  • position = (0,0,0)
  • scale = (1,1,1)
  • visibility = 1
  • pickable = 1
  • dragable = 1
  • orientation = (0,0,0).
    No user defined matrix and no texture map.

getActors() TBD

For some exporters and other other operations we must be
able to collect all the actors or volumes. These methods
are used in that process.

virtual void GetActors(vtkPropCollection *);

hasTranslucentPolygonalGeometry()

Does this prop have some translucent polygonal geometry?

property

Set/Get the property object that controls this actors surface
properties. This should be an instance of a vtkProperty 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.

makeProperty()

Create a new property suitable for use with this type of Actor.
For example, a vtkMesaActor should create a vtkMesaProperty
in this function. The default is to create a vtkProperty.

backfaceProperty

Set/Get the property object that controls this actors backface surface
properties. This should be an instance of a vtkProperty object. If one
isn’t specified, then the front face properties will be used. Multiple
actors can share one property object.

texture TBD

Set/Get the texture object to control rendering texture maps. This will
be a vtkTexture object. An actor does not need to have an associated
texture map and multiple actors can share one texture.

mapper

This is the method that is used to connect an actor to the end of a
visualization pipeline, i.e. the mapper. This should be a subclass
of vtkMapper. Typically vtkPolyDataMapper and vtkDataSetMapper will
be used.

bounds()

Get the bounds for this Actor as (Xmin,Xmax,Ymin,Ymax,Zmin,Zmax).

applyProperties()

Apply the current properties to all parts that compose this actor.
This method is overloaded in vtkAssembly to apply the assemblies’
properties to all its parts in a recursive manner. Typically the
use of this method is to set the desired properties in the assembly,
and then push the properties down to the assemblies parts with
applyProperties().

getMTime()

Get the newest “modification time” of the actor, its properties, and texture (if set).

getRedrawMTime()

Return the mtime of anything that would cause the rendered image to
appear differently. Usually this involves checking the mtime of the
prop plus anything else it depends on such as properties, textures,
etc.

forceOpaque and forceTranslucent

Force the actor to be treated as opaque or translucent

// is this actor opaque
int GetIsOpaque();
bool ForceOpaque;
bool ForceTranslucent;

// Bounds are cached in an actor - the MapperBounds are also cache to
// help know when the Bounds need to be recomputed.
double MapperBounds[6];
vtkTimeStamp BoundsMTime;

Source

index.js
import { vec3, mat4 } from 'gl-matrix';
import macro from 'vtk.js/Sources/macro';
import vtkProp3D from 'vtk.js/Sources/Rendering/Core/Prop3D';
import vtkProperty from 'vtk.js/Sources/Rendering/Core/Property';

const { vtkDebugMacro } = macro;

// ----------------------------------------------------------------------------
// vtkActor methods
// ----------------------------------------------------------------------------

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

// Capture 'parentClass' api for internal use
const superClass = Object.assign({}, publicAPI);

publicAPI.getActors = () => publicAPI;

publicAPI.getIsOpaque = () => {
if (model.forceOpaque) {
return true;
}
if (model.forceTranslucent) {
return false;
}
// 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());

// are we using an opaque scalar array, if any?
isOpaque = isOpaque && (!model.mapper || model.mapper.getIsOpaque());

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 = vtkProperty.newInstance;

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

publicAPI.getBounds = () => {
if (model.mapper === null) {
return model.bounds;
}

// Check for the special case when the mapper's bounds are unknown
const bds = model.mapper.getBounds();
if (!bds || bds.length !== 6) {
return bds;
}

// Check for the special case when the actor is empty.
if (bds[0] > bds[1]) {
model.mapperBounds = bds.concat(); // copy the mapper's bounds
model.bounds = [1, -1, 1, -1, 1, -1];
model.boundsMTime.modified();
return bds;
}

// Check if we have cached values for these bounds - we cache the
// values returned by model.mapper.getBounds() and we store the time
// of caching. If the values returned this time are different, or
// the modified time of this class is newer than the cached time,
// then we need to rebuild.
if (
!model.mapperBounds ||
bds[0] !== model.mapperBounds[0] ||
bds[1] !== model.mapperBounds[1] ||
bds[2] !== model.mapperBounds[2] ||
bds[3] !== model.mapperBounds[3] ||
bds[4] !== model.mapperBounds[4] ||
bds[5] !== model.mapperBounds[5] ||
publicAPI.getMTime() > model.boundsMTime.getMTime()
) {
vtkDebugMacro('Recomputing bounds...');
model.mapperBounds = bds.concat(); // copy the mapper's bounds
const bbox = [
vec3.fromValues(bds[1], bds[3], bds[5]),
vec3.fromValues(bds[1], bds[2], bds[5]),
vec3.fromValues(bds[0], bds[2], bds[5]),
vec3.fromValues(bds[0], bds[3], bds[5]),
vec3.fromValues(bds[1], bds[3], bds[4]),
vec3.fromValues(bds[1], bds[2], bds[4]),
vec3.fromValues(bds[0], bds[2], bds[4]),
vec3.fromValues(bds[0], bds[3], bds[4]),
];

publicAPI.computeMatrix();
const tmp4 = mat4.create();
mat4.transpose(tmp4, model.matrix);
bbox.forEach((pt) => vec3.transformMat4(pt, pt, tmp4));

/* eslint-disable no-multi-assign */
model.bounds[0] = model.bounds[2] = model.bounds[4] = Number.MAX_VALUE;
model.bounds[1] = model.bounds[3] = model.bounds[5] = -Number.MAX_VALUE;
/* eslint-enable no-multi-assign */

model.bounds = model.bounds.map(
(d, i) =>
i % 2 === 0
? bbox.reduce((a, b) => (a > b[i / 2] ? b[i / 2] : a), d)
: bbox.reduce(
(a, b) => (a < b[(i - 1) / 2] ? b[(i - 1) / 2] : a),
d
)
);

model.boundsMTime.modified();
}
return model.bounds;
};

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

if (model.backfaceProperty !== null) {
const time = model.backfaceProperty.getMTime();
mt = time > mt ? time : mt;
}

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.getSupportsSelection = () =>
model.mapper ? model.mapper.getSupportsSelection() : false;
}

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

const DEFAULT_VALUES = {
mapper: null,
property: null,
backfaceProperty: null,

forceOpaque: false,
forceTranslucent: false,

bounds: [1, -1, 1, -1, 1, -1],
};

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

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

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

// vtkTimeStamp
model.boundsMTime = {};
macro.obj(model.boundsMTime);

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

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

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

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

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

export default { newInstance, extend };