XMLPolyDataReader

Introduction

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

Methods

extend

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

newInstance

Method used to create a new instance of vtkPLYReader

Argument Type Required Description
initialValues IXMLPolyDataReaderInitialValues 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 IXMLPolyDataReaderInitialValues extends IXMLReaderInitialValues{
dataType?: string;
}

export interface vtkXMLPolyDataReader 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 vtkXMLPolyDataReader characteristics.
*
* @param publicAPI object on which methods will be bounds (public)
* @param model object on which data structure will be bounds (protected)
* @param {IXMLPolyDataReaderInitialValues} [initialValues] (default: {})
*/
export function extend(publicAPI: object, model: object, initialValues?: IXMLPolyDataReaderInitialValues): void;

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

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

// ----------------------------------------------------------------------------
// Global method
// ----------------------------------------------------------------------------

function handleArray(
polydata,
cellType,
piece,
compressor,
byteOrder,
headerType,
binaryBuffer
) {
const size = Number(piece.getAttribute(`NumberOf${cellType}`));
if (size > 0) {
const dataArrayElem = piece
.getElementsByTagName(cellType)[0]
.getElementsByTagName('DataArray')[0];
const { values, numberOfComponents } = vtkXMLReader.processDataArray(
size,
dataArrayElem,
compressor,
byteOrder,
headerType,
binaryBuffer
);
polydata[`get${cellType}`]().setData(values, numberOfComponents);
}
return size;
}

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

function handleCells(
polydata,
cellType,
piece,
compressor,
byteOrder,
headerType,
binaryBuffer
) {
const size = Number(piece.getAttribute(`NumberOf${cellType}`));
if (size > 0) {
const values = vtkXMLReader.processCells(
size,
piece.getElementsByTagName(cellType)[0],
compressor,
byteOrder,
headerType,
binaryBuffer
);
polydata[`get${cellType}`]().setData(values);
}
return size;
}

// ----------------------------------------------------------------------------
// vtkXMLPolyDataReader methods
// ----------------------------------------------------------------------------

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

publicAPI.parseXML = (rootElem, type, compressor, byteOrder, headerType) => {
const datasetElem = rootElem.getElementsByTagName(model.dataType)[0];
const pieces = datasetElem.getElementsByTagName('Piece');
const nbPieces = pieces.length;

for (let outputIndex = 0; outputIndex < nbPieces; outputIndex++) {
// Create dataset
const polydata = vtkPolyData.newInstance();
const piece = pieces[outputIndex];

// Points
const nbPoints = handleArray(
polydata,
'Points',
piece,
compressor,
byteOrder,
headerType,
model.binaryBuffer
);

// Cells
let nbCells = 0;
['Verts', 'Lines', 'Strips', 'Polys'].forEach((cellType) => {
nbCells += handleCells(
polydata,
cellType,
piece,
compressor,
byteOrder,
headerType,
model.binaryBuffer
);
});

// Fill data
vtkXMLReader.processFieldData(
nbPoints,
piece.getElementsByTagName('PointData')[0],
polydata.getPointData(),
compressor,
byteOrder,
headerType,
model.binaryBuffer
);
vtkXMLReader.processFieldData(
nbCells,
piece.getElementsByTagName('CellData')[0],
polydata.getCellData(),
compressor,
byteOrder,
headerType,
model.binaryBuffer
);

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

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

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

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

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

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

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

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

export default { newInstance, extend };