I have multiple lines that defines an object and I need to present them in VTK. I figured out how to do that in VTK.js and vtkPolyData, by adding all points of all lines and defining the lines. The problem is that the last point of the previous line is connected to the first one of the actual line. How could I separate the lines?
function createPolyData(pointsList) {
const pointList = roiData.pointsList;
const polygon = vtkPolyData.newInstance();
const pointArray = [];
let index = 0;
const lines = vtkCellArray.newInstance();
for (let i = 0; i < pointList.length; i++) {
const points = pointList[i].points;
const lineArray = [];
for (let j = 0; j < points.length; j++) {
pointArray.push(points[j].x);
pointArray.push(points[j].y);
pointArray.push(points[j].z);
lineArray.push(index + j);
}
// Uniting the last point with the first
lineArray.push(index);
lines.insertNextCell(lineArray);
index = index + points.length;
}
polygon.getPoints().setData(Float32Array.from(pointArray), 3);
polygon.setLines(lines);
const mapper = vtkMapper.newInstance();
mapper.setInputData(polygon);
const actor = vtkActor.newInstance();
actor.setMapper(mapper);
return actor;
}
I didnt know how to use the vtkCellArray. After I found one example, I applyed to my problem and it works!!! I am sharing the code here of my function…