Skip to content

Commit

Permalink
feat(XMLReader): XMLImageDataReader supports FieldData of DataSet.
Browse files Browse the repository at this point in the history
  • Loading branch information
yarous224 committed Jul 7, 2021
1 parent ee751f0 commit e2e6142
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 45 deletions.
45 changes: 0 additions & 45 deletions Sources/IO/XML/XMLPolyDataReader/index.js
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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
// ----------------------------------------------------------------------------
Expand All @@ -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();
Expand Down Expand Up @@ -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;
}
Expand Down
43 changes: 43 additions & 0 deletions Sources/IO/XML/XMLReader/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
// ----------------------------------------------------------------------------
Expand Down Expand Up @@ -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;
};

Expand Down

0 comments on commit e2e6142

Please sign in to comment.