From 30b575833614d5c418f1296291bea19b8b26072c Mon Sep 17 00:00:00 2001 From: Sebastien Jourdain Date: Wed, 25 Apr 2018 10:25:14 -0600 Subject: [PATCH] fix(vtk): add vtk export of cell types --- src/MainView.js | 20 +++++++++ src/utils/ModelHelper.js | 87 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 106 insertions(+), 1 deletion(-) diff --git a/src/MainView.js b/src/MainView.js index 9a8c325..f5010db 100644 --- a/src/MainView.js +++ b/src/MainView.js @@ -207,6 +207,15 @@ export default class MainView extends React.Component { }; } } + + if (newState.core && newState.elevations && newState.pitch) { + newState.rectilinearGrid = ModelHelper.exportRectilinearGrid( + newState.elevations, + newState.core, + newState.pitch + ); + } + this.setState(newState); }); return false; @@ -328,6 +337,17 @@ export default class MainView extends React.Component { )} + {this.state.rectilinearGrid ? ( + + + + ) : null} i * pitch).join(' ')); + lines.push('Y_COORDINATES 256 float'); + lines.push(new Float64Array(256).map((v, i) => i * pitch).join(' ')); + lines.push(`Z_COORDINATES ${elevations.length} float`); + lines.push(elevations.join(' ')); + + // Add cell data + lines.push(`CELL_DATA ${255 * 255 * (elevations.length - 1)}`); + lines.push('SCALARS cellType unsigned_char 1'); + lines.push('LOOKUP_TABLE default'); + + // Write each elevation map + const size = 255 * 255; + const buffer = new Uint8Array(size); + for (let i = 0; i < elevations.length - 1; i++) { + buffer.fill(0); + const { layouts } = core[elevations[i]].has3D; + for (let j = 0; j < layouts.length; j++) { + fillBufferLayer(pitch, layouts[j], buffer); + } + + for (let j = 0; j < 255; j++) { + const line = []; + for (let k = 0; k < 255; k++) { + line.push(buffer[k + 255 * j]); + } + lines.push(line.join(' ')); + } + } + + const blob = new Blob([lines.join('\n')], { + type: 'application/octet-stream', + }); + const url = URL.createObjectURL(blob); + // window.open(url, '_blank'); + // setTimeout(() => { + // URL.revokeObjectURL(url); + // }, 10000); + return url; +} +// END ---- New viz as cell map --- + // make an ID out of materials and radii, to recognize cell-reuse. function cellToId(cell) { const layers = []; @@ -565,8 +647,10 @@ function parseFile(file, imageSize, updateFn) { controls, detectors, inserts, - core, states, + core, // needed for vtk export + elevations, // needed for vtk export + pitch: lastPPitch, // needed for vtk export }); }); @@ -598,4 +682,5 @@ export default { extractCoremapElevations, extractBaffleLayoutFrom, parseFile, + exportRectilinearGrid, };