Property2D

Introduction

vtkProperty2D is an object that represents lighting and other surface
properties of a 2D geometric object. The primary properties that can be
set are colors (overall, ambient, diffuse, specular, and edge color);
specular power; opacity of the object; the representation of the
object (points, wireframe, or surface); and the shading method to be
used (flat, Gouraud, and Phong). Also, some special graphics features
like backface properties can be set and manipulated with this object.

Methods

extend

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

getColor

Get the color of the object.

getColorByReference

Get the color of the object.

getDisplayLocation

Get the display location of the object.

getLineWidth

Get the width of a Line.
The width is expressed in screen units.

getOpacity

Get the opacity of the object.

getPointSize

Get the diameter of a point.
The size is expressed in screen units.

newInstance

Method use to create a new instance of vtkProperty2D with object color, ambient color, diffuse color,
specular color, and edge color white; ambient coefficient=0; diffuse
coefficient=0; specular coefficient=0; specular power=1; Gouraud shading;
and surface representation. Backface and frontface culling are off.

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

setColor

Set the color of the object. Has the side effect of setting the
ambient diffuse and specular colors as well. This is basically
a quick overall color setting method.

Argument Type Required Description
color RGBColor Yes Defines the RGB color array..

setColor

Set the color of the object. Has the side effect of setting the
ambient diffuse and specular colors as well. This is basically
a quick overall color setting method.

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).

setColorFrom

Set the color of the object. Has the side effect of setting the
ambient diffuse and specular colors as well. This is basically
a quick overall color setting method.

Argument Type Required Description
color RGBColor Yes Defines the RGB color array..

setColorFrom

Set the color of the object. Has the side effect of setting the
ambient diffuse and specular colors as well. This is basically
a quick overall color setting method.

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).

setDisplayLocation

Set the display location of the object.

Argument Type Required Description
displayLocation String Yes

setLineWidth

Set the width of a Line. The width is expressed in screen units.
This is only implemented for OpenGL.

Argument Type Required Description
lineWidth Number Yes The width of the Line.

setOpacity

Set the object’s opacity. 1.0 is totally opaque and 0.0 is
completely transparent.

Argument Type Required Description
opacity Number Yes The opacity value.

setPointSize

Set the diameter of a point. The size is expressed in screen units.
This is only implemented for OpenGL.

Argument Type Required Description
pointSize Number Yes The diameter of the point.

Source

Constants.d.ts
export declare enum DisplayLocation {
BACKGROUND = 0,
FOREGROUND = 1,
}

declare const _default: {
DisplayLocation: typeof DisplayLocation;
};
export default _default;
Constants.js
export const DisplayLocation = {
BACKGROUND: 0,
FOREGROUND: 1,
};

export default {
DisplayLocation,
};
index.d.ts
import { vtkObject } from '../../../interfaces';
import { RGBColor } from '../../../types';
import { DisplayLocation } from './Constants';

export interface IProperty2DInitialValues {
color?: RGBColor;
opacity?: number;
pointSize?: number;
lineWidth?: number;
displayLocation?: DisplayLocation;
}

export interface vtkProperty2D extends vtkObject {
/**
* Get the color of the object.
*/
getColor(): RGBColor;

/**
* Get the color of the object.
*/
getColorByReference(): RGBColor;

/**
* Get the display location of the object.
* @default 'Foreground'
*/
getDisplayLocation(): DisplayLocation;

/**
* Get the width of a Line.
* The width is expressed in screen units.
*/
getLineWidth(): number;

/**
* Get the opacity of the object.
*/
getOpacity(): number;

/**
* Get the diameter of a point.
* The size is expressed in screen units.
*/
getPointSize(): number;

/**
* Set the color of the object. Has the side effect of setting the
* ambient diffuse and specular colors as well. This is basically
* a quick overall color setting method.
* @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).
*/
setColor(r: number, g: number, b: number): boolean;

/**
* Set the color of the object. Has the side effect of setting the
* ambient diffuse and specular colors as well. This is basically
* a quick overall color setting method.
* @param {RGBColor} color Defines the RGB color array..
*/
setColor(color: RGBColor): boolean;

/**
* Set the color of the object. Has the side effect of setting the
* ambient diffuse and specular colors as well. This is basically
* a quick overall color setting method.
* @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).
*/
setColorFrom(r: number, g: number, b: number): boolean;

/**
* Set the color of the object. Has the side effect of setting the
* ambient diffuse and specular colors as well. This is basically
* a quick overall color setting method.
* @param {RGBColor} color Defines the RGB color array..
*/
setColorFrom(color: RGBColor): boolean;

/**
* Set the display location of the object.
* @param {String} displayLocation
*/
setDisplayLocation(displayLocation: DisplayLocation): boolean;

/**
* Set the width of a Line. The width is expressed in screen units.
* This is only implemented for OpenGL.
* @param {Number} lineWidth The width of the Line.
* @default 1.0
*/
setLineWidth(lineWidth: number): boolean;

/**
* Set the object’s opacity. 1.0 is totally opaque and 0.0 is
* completely transparent.
* @param {Number} opacity The opacity value.
*/
setOpacity(opacity: number): boolean;

/**
* Set the diameter of a point. The size is expressed in screen units.
* This is only implemented for OpenGL.
* @param {Number} pointSize The diameter of the point.
* @default 1.0
*/
setPointSize(pointSize: number): boolean;
}

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

/**
* Method use to create a new instance of vtkProperty2D with object color, ambient color, diffuse color,
* specular color, and edge color white; ambient coefficient=0; diffuse
* coefficient=0; specular coefficient=0; specular power=1; Gouraud shading;
* and surface representation. Backface and frontface culling are off.
* @param {IProperty2DInitialValues} [initialValues] for pre-setting some of its content
*/
export function newInstance(
initialValues?: IProperty2DInitialValues
): vtkProperty2D;

/**
* vtkProperty2D is an object that represents lighting and other surface
* properties of a 2D geometric object. The primary properties that can be
* set are colors (overall, ambient, diffuse, specular, and edge color);
* specular power; opacity of the object; the representation of the
* object (points, wireframe, or surface); and the shading method to be
* used (flat, Gouraud, and Phong). Also, some special graphics features
* like backface properties can be set and manipulated with this object.
*/
export declare const vtkProperty2D: {
newInstance: typeof newInstance;
extend: typeof extend;
};
export default vtkProperty2D;
index.js
import macro from 'vtk.js/Sources/macros';
import Constants from 'vtk.js/Sources/Rendering/Core/Property2D/Constants';

import { Representation } from 'vtk.js/Sources/Rendering/Core/Property/Constants';

const { DisplayLocation } = Constants;

// ----------------------------------------------------------------------------
// vtkProperty2D methods
// ----------------------------------------------------------------------------

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

publicAPI.setDisplayLocationToBackground = () =>
publicAPI.setDisplayLocation(DisplayLocation.BACKGROUND);
publicAPI.setDisplayLocationToForeground = () =>
publicAPI.setDisplayLocation(DisplayLocation.FOREGROUND);

publicAPI.setRepresentationToWireframe = () =>
publicAPI.setRepresentation(Representation.WIREFRAME);
publicAPI.setRepresentationToSurface = () =>
publicAPI.setRepresentation(Representation.SURFACE);
publicAPI.setRepresentationToPoints = () =>
publicAPI.setRepresentation(Representation.POINTS);
publicAPI.getRepresentationAsString = () =>
macro.enumToString(Representation, model.representation);
}

// ----------------------------------------------------------------------------
// Object factory
// ----------------------------------------------------------------------------
const DEFAULT_VALUES = {
color: [1, 1, 1],
opacity: 1,
pointSize: 1,
lineWidth: 1,
representation: Representation.SURFACE,
displayLocation: DisplayLocation.FOREGROUND,
};

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

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

// Build VTK API
macro.obj(publicAPI, model);
macro.setGet(publicAPI, model, [
'opacity',
'lineWidth',
'pointSize',
'displayLocation',
'representation',
]);
macro.setGetArray(publicAPI, model, ['color'], 3);

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

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

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

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

export default { newInstance, extend, ...Constants };