Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | 1x 1x 1x 1x 1x 1x 1x 1x | import macro from 'vtk.js/Sources/macros'; import vtkDataArray from 'vtk.js/Sources/Common/Core/DataArray'; import vtkXMLWriter from 'vtk.js/Sources/IO/XML/XMLWriter'; import { POLYDATA_FIELDS } from 'vtk.js/Sources/Common/DataModel/PolyData/Constants'; // ---------------------------------------------------------------------------- // Global methods // ---------------------------------------------------------------------------- // ---------------------------------------------------------------------------- // ---------------------------------------------------------------------------- // vtkXMLPolyDataWriter methods // ---------------------------------------------------------------------------- function vtkXMLPolyDataWriter(publicAPI, model) { // Set our className model.classHierarchy.push('vtkXMLPolyDataWriter'); // Capture "parentClass" api for internal use const superClass = { ...publicAPI }; function camelize(str) { return str .replace(/(?:^\w|[A-Z]|\b\w)/g, (letter) => letter.toUpperCase()) .replace(/\s+/g, ''); } publicAPI.create = (dataObject) => { const parent = superClass.create(dataObject); const polyData = parent.ele('PolyData', {}); const piece = polyData.ele('Piece', { NumberOfPoints: dataObject.getPoints().getNumberOfPoints(), NumberOfVerts: dataObject.getNumberOfVerts(), NumberOfLines: dataObject.getNumberOfLines(), NumberOfStrips: dataObject.getNumberOfStrips(), NumberOfPolys: dataObject.getNumberOfPolys(), }); publicAPI.processDataSetAttributes( piece, 'PointData', dataObject.getPointData() ); publicAPI.processDataSetAttributes( piece, 'CellData', dataObject.getCellData() ); publicAPI.processDataArray(piece.ele('Points'), dataObject.getPoints()); POLYDATA_FIELDS.forEach((cellType) => { const cellTypeName = camelize(cellType); const cells = dataObject[`get${cellTypeName}`](); const connectivity = []; const offsets = []; const cellsData = cells.getData(); let npts = cellsData[0]; let offset = 0; for (let i = 0; i < cellsData.length; ) { npts = cellsData[i++]; for (let j = 0; j < npts; ++j) { connectivity.push(cellsData[i++]); } offset += npts; offsets.push(offset); } const connectivityDataArray = vtkDataArray.newInstance({ numberOfComponents: 1, name: 'connectivity', values: Int32Array.from(connectivity), }); const offsetsDataArray = vtkDataArray.newInstance({ numberOfComponents: 1, name: 'offsets', values: Int32Array.from(offsets), }); const cellEle = piece.ele(cellTypeName); publicAPI.processDataArray(cellEle, connectivityDataArray); publicAPI.processDataArray(cellEle, offsetsDataArray); }); return parent; }; } // ---------------------------------------------------------------------------- // Object factory // ---------------------------------------------------------------------------- const DEFAULT_VALUES = { dataType: 'PolyData', }; // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { Object.assign(model, DEFAULT_VALUES, initialValues); vtkXMLWriter.extend(publicAPI, model, initialValues); vtkXMLPolyDataWriter(publicAPI, model); } // ---------------------------------------------------------------------------- export const newInstance = macro.newInstance(extend, 'vtkXMLPolyDataWriter'); // ---------------------------------------------------------------------------- export default { newInstance, extend }; |