XMLImageDataReader

Introduction

vtkXMLImageDataReader is a source object that parses a VTK XML input file.

Methods

extend

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

newInstance

Method used to create a new instance of vtkPLYReader

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

parseXML

Parse data as XML.

Argument Type Required Description
rootElem Yes
type Yes
compressor String Yes
byteOrder String Yes
headerType String Yes

Source

index.d.ts
import vtkXMLReader, { IXMLReaderInitialValues } from "../XMLReader";

/**
*
*/
export interface IXMLImageDataReaderInitialValues extends IXMLReaderInitialValues {
dataType?: string;
}

export interface vtkXMLImageDataReader extends vtkXMLReader {

/**
* Parse data as XML.
* @param rootElem
* @param type
* @param {String} compressor
* @param {String} byteOrder
* @param {String} headerType
*/
parseXML(rootElem: any, type: any, compressor: string, byteOrder: string, headerType: string): void;
}

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

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

/**
* vtkXMLImageDataReader is a source object that parses a VTK XML input file.
*/
export declare const vtkXMLImageDataReader: {
extend: typeof extend;
newInstance: typeof newInstance;
}
export default vtkXMLImageDataReader;
index.js
import vtkXMLReader from 'vtk.js/Sources/IO/XML/XMLReader';
import macro from 'vtk.js/Sources/macros';
import vtkImageData from 'vtk.js/Sources/Common/DataModel/ImageData';

// ----------------------------------------------------------------------------
// vtkXMLImageDataReader methods
// ----------------------------------------------------------------------------

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

publicAPI.parseXML = (rootElem, type, compressor, byteOrder, headerType) => {
const imageDataElem = rootElem.getElementsByTagName(model.dataType)[0];
const origin = imageDataElem
.getAttribute('Origin')
.split(' ')
.map((t) => Number(t));
const spacing = imageDataElem
.getAttribute('Spacing')
.split(' ')
.map((t) => Number(t));
const direction = imageDataElem
.getAttribute('Direction')
?.split(' ')
.map((t) => Number(t));
const pieces = imageDataElem.getElementsByTagName('Piece');
const nbPieces = pieces.length;

for (let outputIndex = 0; outputIndex < nbPieces; outputIndex++) {
// Create image data
const piece = pieces[outputIndex];
const extent = piece
.getAttribute('Extent')
.split(' ')
.map((t) => Number(t));
const imageData = vtkImageData.newInstance({
origin,
spacing,
direction,
extent,
});

// Fill data
vtkXMLReader.processFieldData(
imageData.getNumberOfPoints(),
piece.getElementsByTagName('PointData')[0],
imageData.getPointData(),
compressor,
byteOrder,
headerType,
model.binaryBuffer
);

vtkXMLReader.processFieldData(
imageData.getNumberOfCells(),
piece.getElementsByTagName('CellData')[0],
imageData.getCellData(),
compressor,
byteOrder,
headerType,
model.binaryBuffer
);

// Add new output
model.output[outputIndex] = imageData;
}
};
}

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

const DEFAULT_VALUES = {
dataType: 'ImageData',
};

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

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

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

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

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

export default { newInstance, extend };