JSFiddle - React, Tailwind, and code Playground
TypeScript ES6 for-of
by k_udilovich
HTML
<script src="https://unpkg.com/vtk.js@8.11.1/dist/vtk.js"></script>
TypeScript
class Point3d {
id: String;
x:number;
y:number;
z: number;
constructor(id: String, x:number, y:number, z:number) {
this.id = id;
this.x =x;
this.y=y;
this.z=z;
}
}
class MeshCell {
id: String;
NumberOfPoints:number;
PointsIds:number[];
constructor(id:String, NumberOfPoints:number, PointsIds:number[]) {
this.id=id;
this.NumberOfPoints=NumberOfPoints;
this.PointsIds = PointsIds;
}
}
let points: Point3d[] =
[
new Point3d('0', 0.0,0.0 ,0),
new Point3d('1', 0.0,10.0,0),
new Point3d('2', 5.0,10.0,0),
new Point3d('3', 5.0,0.0 ,0),
]
;
let triangularMesh: MeshCell[] = [
new MeshCell("", 3, [0, 1, 2]),
new MeshCell("", 3, [0, 2, 3]),
]
let fullscreenRenderWindow = vtk.Rendering.Misc.vtkFullScreenRenderWindow.newInstance({
background: [0.9, 0.9, 0.9],
});
const renderer = fullscreenRenderWindow.getRenderer();
var vertexArray = [];
var polysArray = [];
var valuesArray=[];
var i;
for (i = 0; i < points.length; i++) {
let point = points[i];
vertexArray.push(point.x, point.y, point.z);
valuesArray.push(Math.random() * 10)
}
for (i = 0; i < triangularMesh.length; i++) {
let cell = triangularMesh[i];
polysArray.push(cell.NumberOfPoints, cell.PointsIds[0], cell.PointsIds[1], cell.PointsIds[2]);
}
var polydata = vtk.Common.DataModel.vtkPolyData.newInstance();
polydata.getPoints().setData(Float32Array.from(vertexArray), 3);
polydata.getPolys().setData(Uint16Array.from(polysArray));
//THIS LINE THROWS THE EXCEPTION
//"vtk_js_Sources_Common_Core__WEBPACK_IMPORTED_MODULE_13__.default.newInstance is not a function"
let array1 = vtk.Common.Core.vtkDataArray.newInstance();
//ULTIMATELY THIS IS WHAT I AM TRYING TO ACCOMPLISH
// polydata.getCellData().setScalars(...