From e2e614243f543601ece0b693e9efc7adc3d57e51 Mon Sep 17 00:00:00 2001 From: yrs224 Date: Wed, 7 Jul 2021 19:31:10 +0800 Subject: [PATCH] feat(XMLReader): XMLImageDataReader supports FieldData of DataSet. --- Sources/IO/XML/XMLPolyDataReader/index.js | 45 ----------------------- Sources/IO/XML/XMLReader/index.js | 43 ++++++++++++++++++++++ 2 files changed, 43 insertions(+), 45 deletions(-) diff --git a/Sources/IO/XML/XMLPolyDataReader/index.js b/Sources/IO/XML/XMLPolyDataReader/index.js index 1147adb85dc..0b232139c27 100644 --- a/Sources/IO/XML/XMLPolyDataReader/index.js +++ b/Sources/IO/XML/XMLPolyDataReader/index.js @@ -1,5 +1,4 @@ import macro from 'vtk.js/Sources/macro'; -import vtkDataArray from 'vtk.js/Sources/Common/Core/DataArray'; import vtkPolyData from 'vtk.js/Sources/Common/DataModel/PolyData'; import vtkXMLReader from 'vtk.js/Sources/IO/XML/XMLReader'; @@ -60,28 +59,6 @@ function handleCells( return size; } -// ---------------------------------------------------------------------------- - -function handleFieldDataArray( - dataArrayElem, - compressor, - byteOrder, - headerType, - binaryBuffer -) { - const size = Number(dataArrayElem.getAttribute('NumberOfTuples')); - return vtkDataArray.newInstance( - vtkXMLReader.processDataArray( - size, - dataArrayElem, - compressor, - byteOrder, - headerType, - binaryBuffer - ) - ); -} - // ---------------------------------------------------------------------------- // vtkXMLPolyDataReader methods // ---------------------------------------------------------------------------- @@ -92,26 +69,9 @@ function vtkXMLPolyDataReader(publicAPI, model) { publicAPI.parseXML = (rootElem, type, compressor, byteOrder, headerType) => { const datasetElem = rootElem.getElementsByTagName(model.dataType)[0]; - const fieldDataElem = datasetElem.getElementsByTagName('FieldData')[0]; const pieces = datasetElem.getElementsByTagName('Piece'); const nbPieces = pieces.length; - // field data - let fieldDataArrays = []; - if (fieldDataElem) { - fieldDataArrays = [ - ...fieldDataElem.getElementsByTagName('DataArray'), - ].map((daElem) => - handleFieldDataArray( - daElem, - compressor, - byteOrder, - headerType, - model.binaryBuffer - ) - ); - } - for (let outputIndex = 0; outputIndex < nbPieces; outputIndex++) { // Create dataset const polydata = vtkPolyData.newInstance(); @@ -162,11 +122,6 @@ function vtkXMLPolyDataReader(publicAPI, model) { model.binaryBuffer ); - const fieldData = polydata.getFieldData(); - for (let i = 0; i < fieldDataArrays.length; i++) { - fieldData.addArray(fieldDataArrays[i]); - } - // Add new output model.output[outputIndex] = polydata; } diff --git a/Sources/IO/XML/XMLReader/index.js b/Sources/IO/XML/XMLReader/index.js index 0310ad1eb5a..1fd5073d0e8 100644 --- a/Sources/IO/XML/XMLReader/index.js +++ b/Sources/IO/XML/XMLReader/index.js @@ -320,6 +320,28 @@ function processFieldData( } } +// ---------------------------------------------------------------------------- +function handleFieldDataArrays( + fieldDataElem, + compressor, + byteOrder, + headerType, + binaryBuffer +) { + return [...fieldDataElem.getElementsByTagName('DataArray')].map((daElem) => + vtkDataArray.newInstance( + processDataArray( + Number(daElem.getAttribute('NumberOfTuples')), + daElem, + compressor, + byteOrder, + headerType, + binaryBuffer + ) + ) + ); +} + // ---------------------------------------------------------------------------- // vtkXMLReader methods // ---------------------------------------------------------------------------- @@ -513,6 +535,27 @@ function vtkXMLReader(publicAPI, model) { } publicAPI.parseXML(rootElem, type, compressor, byteOrder, headerType); + + const datasetElem = rootElem.getElementsByTagName(type)[0]; + const fieldDataElem = datasetElem.getElementsByTagName('FieldData')[0]; + + if (fieldDataElem) { + const fieldDataArrays = handleFieldDataArrays( + fieldDataElem, + compressor, + byteOrder, + headerType, + model.binaryBuffer + ); + + for (let i = 0; i < model.output.length; i++) { + const fieldData = model.output[i].getFieldData(); + for (let j = 0; j < fieldDataArrays.length; j++) { + fieldData.addArray(fieldDataArrays[j]); + } + } + } + return true; };