ImageSliceFilter

Methods

extend

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

getOrientation

getSliceIndex

newInstance

Method used to create a new instance of vtkImageSliceFilter

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

requestData

Argument Type Required Description
inData Yes
outData Yes

setOrientation

Argument Type Required Description
orientation Yes

setSliceIndex

Argument Type Required Description
sliceIndex Yes

Source

index.d.ts
import { vtkAlgorithm, vtkObject } from '../../../interfaces';

/**
*
*/
export interface IImageSliceFilterInitialValues {
sliceIndex?: number;
}

type vtkImageSliceFilterBase = vtkObject & vtkAlgorithm;

export interface vtkImageSliceFilter extends vtkImageSliceFilterBase {
/**
*
*/
getOrientation(): any;

/**
*
* @default 0
*/
getSliceIndex(): number;

/**
*
* @param inData
* @param outData
*/
requestData(inData: any, outData: any): void;

/**
*
* @param orientation
*/
setOrientation(orientation: any): boolean;

/**
*
* @param sliceIndex
*/
setSliceIndex(sliceIndex: number): boolean;
}

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

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

/**
*
*/
export declare const vtkImageSliceFilter: {
newInstance: typeof newInstance;
extend: typeof extend;
};
export default vtkImageSliceFilter;
index.js
import macro from 'vtk.js/Sources/macros';
import vtkImageData from 'vtk.js/Sources/Common/DataModel/ImageData';
import vtkDataArray from 'vtk.js/Sources/Common/Core/DataArray';

const { vtkErrorMacro } = macro;

// ----------------------------------------------------------------------------
// vtkImageSliceFilter methods
// ----------------------------------------------------------------------------

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

publicAPI.requestData = (inData, outData) => {
// implement requestData
const input = inData[0];

if (!input) {
vtkErrorMacro('Invalid or missing input');
return;
}

const scalars = input.getPointData().getScalars();

if (!scalars) {
vtkErrorMacro('No scalars from input');
return;
}

const datasetDefinition = input.get('extent', 'spacing', 'origin');
datasetDefinition.extent[4] = model.sliceIndex;
datasetDefinition.extent[5] = datasetDefinition.extent[4];

const numberOfComponents = scalars.getNumberOfComponents();
const sliceSize =
(datasetDefinition.extent[1] - datasetDefinition.extent[0] + 1) *
(datasetDefinition.extent[3] - datasetDefinition.extent[2] + 1) *
numberOfComponents;
const offset = sliceSize * model.sliceIndex;
const sliceRawArray = scalars.getData().slice(offset, offset + sliceSize);
const sliceArray = vtkDataArray.newInstance({
name: scalars.getName(),
numberOfComponents,
values: sliceRawArray,
});

const output = vtkImageData.newInstance(datasetDefinition);
output.getPointData().setScalars(sliceArray);

outData[0] = output;
};
}

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

const DEFAULT_VALUES = {
sliceIndex: 0,
};

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

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

// Make this a VTK object
macro.obj(publicAPI, model);

// Also make it an algorithm with one input and one output
macro.algo(publicAPI, model, 1, 1);

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

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

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

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

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

export default { newInstance, extend };