InteractorStyle

Methods

endCameraPose

Ends a CameraPose event.

endDolly

Ends a Dolly event.

endPan

Ends a Pan event.

endRotate

Ends a Rotate event.

endSlice

Ends a Slice event.

endSpin

Ends a Spin event.

endWindowLevel

Ends a WindowLevel event.

getFocusedRenderer

Get the renderer used for event handling, returns null if not set.

handleKeyPress

Handles a keypress.

invokeEndCameraPoseEvent

Invoke an EndCameraPose event.

invokeEndDollyEvent

Invoke an EndDolly event.

invokeEndPanEvent

Invoke an EndPan event.

invokeEndRotateEvent

Invoke an EndRotate event.

invokeEndSliceEvent

Invoke an EndSlice event.

invokeEndSpinEvent

Invoke an EndSpin event.

invokeEndWindowLevelEvent

Invoke an EndWindowLevel event.

invokeStartCameraPoseEvent

Invoke a StartCameraPose event.

invokeStartDollyEvent

Invoke a StartDolly event.

invokeStartPanEvent

Invoke a StartPan event.

invokeStartRotateEvent

Invoke a StartRotate event.

invokeStartSliceEvent

Invoke a StartSlice event.

invokeStartSpinEvent

Invoke a StartSpin event.

invokeStartWindowLevelEvent

Invoke a StartWindowLevel event.

onEndCameraPoseEvent

Registers a callback on an EndCameraPose event.

onEndDollyEvent

Registers a callback on an EndDolly event.

onEndPanEvent

Registers a callback on an EndPan event.

onEndRotateEvent

Registers a callback on an EndRotate event.

onEndSliceEvent

Registers a callback on an EndSlice event.

onEndSpinEvent

Registers a callback on an EndSpin event.

onEndWindowLevelEvent

Registers a callback on an EndWindowLevel event.

onStartCameraPoseEvent

Registers a callback on a StartCameraPose event.

onStartDollyEvent

Registers a callback on a StartDolly event.

onStartPanEvent

Registers a callback on a StartPan event.

onStartRotateEvent

Registers a callback on a StartRotate event.

onStartSliceEvent

Registers a callback on a StartSlice event.

onStartSpinEvent

Registers a callback on a StartSpin event.

onStartWindowLevelEvent

Registers a callback on a StartWindowLevel event.

setFocusedRenderer

Explicitly defines a renderer to be used for event handling.
If never called or called with null, the pokedRenderer of the event will be used.

Argument Type Required Description
renderer Nullable. Yes

startCameraPose

Start a CameraPose event.

startDolly

Start a Dolly event.

startPan

Start a Pan event.

startRotate

Start a Rotate event.

startSlice

Start a Slice event.

startSpin

Start a Spin event.

startWindowLevel

Start a WindowLevel event.

Source

Constants.d.ts
export declare enum States {
IS_START = 0,
IS_NONE = 0,
IS_ROTATE = 1,
IS_PAN = 2,
IS_SPIN = 3,
IS_DOLLY = 4,
IS_CAMERA_POSE = 11,
IS_WINDOW_LEVEL = 1024,
IS_SLICE = 1025,
}

declare const _default: {
States: States;
};
export default _default;
Constants.js
export const States = {
IS_START: 0,
IS_NONE: 0,

IS_ROTATE: 1,
IS_PAN: 2,
IS_SPIN: 3,
IS_DOLLY: 4,

IS_CAMERA_POSE: 11,

IS_WINDOW_LEVEL: 1024,
IS_SLICE: 1025,
};

export default {
States,
};
index.d.ts
import { EventHandler, vtkSubscription } from '../../../interfaces';
import { Nullable } from '../../../types';
import vtkInteractorObserver from '../InteractorObserver';
import vtkRenderer from '../Renderer';

export interface vtkInteractorStyle extends vtkInteractorObserver {
/**
* Start a Rotate event.
*/
startRotate(): void;

/**
* Invoke a StartRotate event.
*/
invokeStartRotateEvent(...args: unknown[]): void;

/**
* Registers a callback on a StartRotate event.
*/
onStartRotateEvent(cb: EventHandler, priority?: number): vtkSubscription;

/**
* Ends a Rotate event.
*/
endRotate(): void;

/**
* Invoke an EndRotate event.
*/
invokeEndRotateEvent(...args: unknown[]): void;

/**
* Registers a callback on an EndRotate event.
*/
onEndRotateEvent(cb: EventHandler, priority?: number): vtkSubscription;
/**
* Start a Pan event.
*/
startPan(): void;

/**
* Invoke a StartPan event.
*/
invokeStartPanEvent(...args: unknown[]): void;

/**
* Registers a callback on a StartPan event.
*/
onStartPanEvent(cb: EventHandler, priority?: number): vtkSubscription;

/**
* Ends a Pan event.
*/
endPan(): void;

/**
* Invoke an EndPan event.
*/
invokeEndPanEvent(...args: unknown[]): void;

/**
* Registers a callback on an EndPan event.
*/
onEndPanEvent(cb: EventHandler, priority?: number): vtkSubscription;
/**
* Start a Spin event.
*/
startSpin(): void;

/**
* Invoke a StartSpin event.
*/
invokeStartSpinEvent(...args: unknown[]): void;

/**
* Registers a callback on a StartSpin event.
*/
onStartSpinEvent(cb: EventHandler, priority?: number): vtkSubscription;

/**
* Ends a Spin event.
*/
endSpin(): void;

/**
* Invoke an EndSpin event.
*/
invokeEndSpinEvent(...args: unknown[]): void;

/**
* Registers a callback on an EndSpin event.
*/
onEndSpinEvent(cb: EventHandler, priority?: number): vtkSubscription;
/**
* Start a Dolly event.
*/
startDolly(): void;

/**
* Invoke a StartDolly event.
*/
invokeStartDollyEvent(...args: unknown[]): void;

/**
* Registers a callback on a StartDolly event.
*/
onStartDollyEvent(cb: EventHandler, priority?: number): vtkSubscription;

/**
* Ends a Dolly event.
*/
endDolly(): void;

/**
* Invoke an EndDolly event.
*/
invokeEndDollyEvent(...args: unknown[]): void;

/**
* Registers a callback on an EndDolly event.
*/
onEndDollyEvent(cb: EventHandler, priority?: number): vtkSubscription;
/**
* Start a CameraPose event.
*/
startCameraPose(): void;

/**
* Invoke a StartCameraPose event.
*/
invokeStartCameraPoseEvent(...args: unknown[]): void;

/**
* Registers a callback on a StartCameraPose event.
*/
onStartCameraPoseEvent(cb: EventHandler, priority?: number): vtkSubscription;

/**
* Ends a CameraPose event.
*/
endCameraPose(): void;

/**
* Invoke an EndCameraPose event.
*/
invokeEndCameraPoseEvent(...args: unknown[]): void;

/**
* Registers a callback on an EndCameraPose event.
*/
onEndCameraPoseEvent(cb: EventHandler, priority?: number): vtkSubscription;
/**
* Start a WindowLevel event.
*/
startWindowLevel(): void;

/**
* Invoke a StartWindowLevel event.
*/
invokeStartWindowLevelEvent(...args: unknown[]): void;

/**
* Registers a callback on a StartWindowLevel event.
*/
onStartWindowLevelEvent(cb: EventHandler, priority?: number): vtkSubscription;

/**
* Ends a WindowLevel event.
*/
endWindowLevel(): void;

/**
* Invoke an EndWindowLevel event.
*/
invokeEndWindowLevelEvent(...args: unknown[]): void;

/**
* Registers a callback on an EndWindowLevel event.
*/
onEndWindowLevelEvent(cb: EventHandler, priority?: number): vtkSubscription;
/**
* Start a Slice event.
*/
startSlice(): void;

/**
* Invoke a StartSlice event.
*/
invokeStartSliceEvent(...args: unknown[]): void;

/**
* Registers a callback on a StartSlice event.
*/
onStartSliceEvent(cb: EventHandler, priority?: number): vtkSubscription;

/**
* Ends a Slice event.
*/
endSlice(): void;

/**
* Invoke an EndSlice event.
*/
invokeEndSliceEvent(...args: unknown[]): void;

/**
* Registers a callback on an EndSlice event.
*/
onEndSliceEvent(cb: EventHandler, priority?: number): vtkSubscription;

/**
* Handles a keypress.
*/
handleKeyPress(callData: unknown): void;

/**
* Explicitly defines a renderer to be used for event handling.
* If never called or called with null, the pokedRenderer of the event will be used.
*
* @param {Nullable<vtkRenderer>} renderer
*/
setFocusedRenderer(renderer: Nullable<vtkRenderer>): boolean;

/**
* Get the renderer used for event handling, returns null if not set.
*/
getFocusedRenderer(): Nullable<vtkRenderer>;
}

export interface IInteractorStyleInitialValues {
autoAdjustCameraClippingRange?: boolean;
}

export function extend(
publicAPI: object,
model: object,
initialValues?: IInteractorStyleInitialValues
): void;

export const vtkInteractorStyle: {
extend: typeof extend;
};

export default vtkInteractorStyle;
index.js
import macro from 'vtk.js/Sources/macros';
import vtkInteractorObserver from 'vtk.js/Sources/Rendering/Core/InteractorObserver';
import Constants from 'vtk.js/Sources/Rendering/Core/InteractorStyle/Constants';

const { States } = Constants;

// ----------------------------------------------------------------------------
// Global methods
// ----------------------------------------------------------------------------

// Add module-level functions or api that you want to expose statically via
// the next section...

const stateNames = {
Rotate: States.IS_ROTATE,
Pan: States.IS_PAN,
Spin: States.IS_SPIN,
Dolly: States.IS_DOLLY,
CameraPose: States.IS_CAMERA_POSE,
WindowLevel: States.IS_WINDOW_LEVEL,
Slice: States.IS_SLICE,
};

// ----------------------------------------------------------------------------
// vtkInteractorStyle methods
// ----------------------------------------------------------------------------

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

// Public API methods
// create bunch of Start/EndState methods
Object.keys(stateNames).forEach((key) => {
macro.event(publicAPI, model, `Start${key}Event`);
publicAPI[`start${key}`] = () => {
if (model.state !== States.IS_NONE) {
return;
}
model.state = stateNames[key];
model._interactor.requestAnimation(publicAPI);
publicAPI.invokeStartInteractionEvent({ type: 'StartInteractionEvent' });
publicAPI[`invokeStart${key}Event`]({ type: `Start${key}Event` });
};
macro.event(publicAPI, model, `End${key}Event`);
publicAPI[`end${key}`] = () => {
if (model.state !== stateNames[key]) {
return;
}
model.state = States.IS_NONE;
model._interactor.cancelAnimation(publicAPI);
publicAPI.invokeEndInteractionEvent({ type: 'EndInteractionEvent' });
publicAPI[`invokeEnd${key}Event`]({ type: `End${key}Event` });
model._interactor.render();
};
});

model.getRenderer = (callData) =>
model.focusedRenderer || callData.pokedRenderer;

//----------------------------------------------------------------------------
publicAPI.handleKeyPress = (callData) => {
const rwi = model._interactor;
let ac = null;
switch (callData.key) {
case 'r':
case 'R':
model.getRenderer(callData).resetCamera();
rwi.render();
break;

case 'w':
case 'W':
ac = model.getRenderer(callData).getActors();
ac.forEach((anActor) => {
const prop = anActor.getProperty();
if (prop.setRepresentationToWireframe) {
prop.setRepresentationToWireframe();
}
});
rwi.render();
break;

case 's':
case 'S':
ac = model.getRenderer(callData).getActors();
ac.forEach((anActor) => {
const prop = anActor.getProperty();
if (prop.setRepresentationToSurface) {
prop.setRepresentationToSurface();
}
});
rwi.render();
break;

case 'v':
case 'V':
ac = model.getRenderer(callData).getActors();
ac.forEach((anActor) => {
const prop = anActor.getProperty();
if (prop.setRepresentationToPoints) {
prop.setRepresentationToPoints();
}
});
rwi.render();
break;

default:
break;
}
};
}

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

const DEFAULT_VALUES = {
state: States.IS_NONE,
handleObservers: 1,
autoAdjustCameraClippingRange: 1,
};

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

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

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

macro.setGet(publicAPI, model, ['focusedRenderer']);

// Object specific methods
vtkInteractorStyle(publicAPI, model);
}

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

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

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

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