
Security News
ECMAScript 2025 Finalized with Iterator Helpers, Set Methods, RegExp.escape, and More
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
vtk-unstructured-viewer
Advanced tools
A lightweight, standalone JavaScript library for parsing and processing VTK Unstructured Grid (.vtu) files in both browser and Node.js environments. Complete VTK-style API with zero dependencies for scientific visualization.
Pure‑JS toolkit for parsing, filtering, and exporting VTK Unstructured Grid (
.vtu
) data in Browser & Node.js.
vtkXMLUnstructuredGridReader
(ASCII, binary, appended)vtkThreshold
, vtkImplicitCut
, vtkClipByScalar
, vtkCellDataToPointData
extractBoundary(grid)
→ minimal polydata for WebGLvtkUnstructuredGridToVTP
for one‑call round‑trip back to ParaViewVTKDebugger.analyzeUnstructuredGrid(grid)
, VTKDebugger.analyzePolyData(polydata)
serializeUnstructuredGrid
/ deserializeUnstructuredGrid
and polydata equivalentsnpm install vtk-unstructured-viewer
Requires Node.js 14+ or any evergreen browser (Chrome 60+, Firefox 55+, Safari 11+, Edge 79+).
import vtkXMLUnstructuredGridReader from 'vtk-unstructured-viewer/vtkUnstructuredGridReader.js';
// 1. Instantiate reader
const reader = new vtkXMLUnstructuredGridReader();
// 2. Load VTU file as ArrayBuffer
const buffer = await fetch('/data/mesh.vtu').then(r => r.arrayBuffer());
// 3. Parse binary content
await reader.parseAsArrayBuffer(buffer);
// 4. Access the unstructured grid
const grid = reader.grid;
console.log('Points:', grid.getPoints().getData().length / grid.getPoints().getNumberOfComponents());
console.log('Cells :', grid.getConnectivity().length);
Alternatively, you can fetch text and call await reader.parseAsText(xmlString)
or await reader.setUrl(url)
(fetch+parse).
Method | Description |
---|---|
new vtkXMLUnstructuredGridReader() | Create reader instance |
await reader.parseAsArrayBuffer(buf) | Parse binary/appended VTU content |
await reader.parseAsText(text) | Parse ASCII VTU XML |
await reader.setUrl(url, opts) | Fetch & parse VTU from URL |
reader.grid | Instance of vtkUnstructuredGrid |
reader.setDataAccessHelper(helper) | Use custom fetch helper |
Method | Description |
---|---|
new vtkUnstructuredGrid() | Create empty grid |
setPoints({values,numberOfComponents,getData,getNumberOfComponents}) | Set vertex coordinates |
getPoints() | DataArray-like object (getData() , getNumberOfComponents() ) |
setConnectivity(Uint32Array) | Cell‑to‑point connectivity |
getConnectivity() | Pair with getOffsets() and getTypes() |
setOffsets(Uint32Array) | Cell offsets |
getOffsets() | ― |
setTypes(Uint8Array) | VTK cell type codes |
getTypes() | ― |
setFacesConnectivity(Uint32Array) | Polyhedron face connectivity |
getFacesConnectivity() | ― |
setFacesOffsets(Uint32Array) | Face offsets |
getFacesOffsets() | ― |
setPolyhedronToFaces(Int32Array) | Map polyhedron→face IDs |
setPolyhedronOffsets(Uint32Array) | Polyhedron offsets |
getBounds(): [xmin,xmax,ymin,ymax,zmin,zmax] | Axis‑aligned bounding box |
toVTPString() | Serialize entire grid → VTP XML string |
const f = new vtkThreshold();
f.setScalarArrayName('pressure');
f.setLowerThreshold(0.0);
f.setUpperThreshold(1.0);
f.setInvert(false);
const filteredGrid = f.execute(grid);
const cutter = new vtkImplicitCut();
cutter.setScalarArrayName('velocity');
cutter.setCutFunction((x,y,z) => x+y-z);
cutter.setCutValue(0.5);
const slicePoly = cutter.execute(grid);
const clipper = new vtkClipByScalar();
clipper.setScalarArrayName('temperature');
clipper.setClipValue(300);
clipper.setInsideOut(true);
const isoPoly = clipper.execute(grid, { perfect: true });
const c2p = new vtkCellDataToPointData();
c2p.setInputArrayName('velocity');
c2p.setOutputArrayName('velocity_pt');
const gridWithPoints = c2p.execute(grid);
import { extractBoundary } from 'vtk-unstructured-viewer/vtkGeometryFilter.js';
import vtkUnstructuredGridToVTP from 'vtk-unstructured-viewer/vtkUnstructuredGridToVTP.js';
// Extract exterior faces
const polyData = extractBoundary(grid);
// Serialize / save VTP
const writer = new vtkUnstructuredGridToVTP();
writer.setExtractBoundaryCells(true);
writer.setPassPointData(true);
writer.setPassCellData(false);
const surfacePoly = writer.execute(grid);
const xml = writer.getVTPString(surfacePoly);
writer.saveVTP('output.vtp');
import VTKDebugger from 'vtk-unstructured-viewer/vtkDebugger.js';
import { serializeUnstructuredGrid, deserializeUnstructuredGrid } from 'vtk-unstructured-viewer/utils.js';
VTKDebugger.analyzeUnstructuredGrid(grid);
VTKDebugger.analyzePolyData(polyData);
const json = serializeUnstructuredGrid(grid);
const restoredGrid = deserializeUnstructuredGrid(json);
async function processVtu(url) {
const reader = new vtkXMLUnstructuredGridReader();
const buffer = await fetch(url).then(r => r.arrayBuffer());
await reader.parseAsArrayBuffer(buffer);
let grid = reader.grid;
// Threshold
const thresh = new vtkThreshold();
thresh.setScalarArrayName('alpha.water');
thresh.setLowerThreshold(0.2);
thresh.setUpperThreshold(1.0);
grid = thresh.execute(grid);
// Interpolate to points
const c2p = new vtkCellDataToPointData();
c2p.setInputArrayName('alpha.water');
grid = c2p.execute(grid);
// Clip
const clipper = new vtkClipByScalar();
clipper.setScalarArrayName('alpha.water');
clipper.setClipValue(0.5);
const surfacePoly = clipper.execute(grid);
// Export
const writer = new vtkUnstructuredGridToVTP();
writer.setPassPointData(true);
writer.saveVTP('phase.vtp');
}
Supports all standard and higher‑order VTK cell types: triangles, quads, tets, hexes, wedges, pyramids, voxels, polygons, polyhedra, and their quadratic/Lagrange variants.
Environment | Requirement |
---|---|
Chrome | ≥ 60 |
Firefox | ≥ 55 |
Safari | ≥ 11 |
Edge (Chromium) | ≥ 79 |
Node.js | ≥ 14 (ESM) |
try {
const reader = new vtkXMLUnstructuredGridReader();
const buf = await fetch('bad.vtu').then(r => r.arrayBuffer());
await reader.parseAsArrayBuffer(buf);
} catch (err) {
console.error('VTU parse error:', err.message);
}
This package is proprietary. See LICENSE.
VTK • VTU • unstructured grid • vtk.js • CFD • FEA • WebGL • JavaScript • mesh processing • iso‑surface • threshold filter • geometry filter • browser visualization • Node.js
FAQs
A lightweight, standalone JavaScript library for parsing and processing VTK Unstructured Grid (.vtu) files in both browser and Node.js environments. Complete VTK-style API with zero dependencies for scientific visualization.
The npm package vtk-unstructured-viewer receives a total of 8 weekly downloads. As such, vtk-unstructured-viewer popularity was classified as not popular.
We found that vtk-unstructured-viewer demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.
Research
North Korean threat actors linked to the Contagious Interview campaign return with 35 new malicious npm packages using a stealthy multi-stage malware loader.