I want to convert vtkCutter’s cutting results to surface,
First,I use vtkClosedPolyLineToSurfaceFilter,The main code is as follows
const polyLineToSurfaceFilter = vtkClosedPolyLineToSurfaceFilter.newInstance();
polyLineToSurfaceFilter.setInputData(cutter.getOutputData());
polyLineToSurfaceFilter.update();
const cutSurfaceMapper = vtkMapper.newInstance();
cutSurfaceMapper.setInputData(polyLineToSurfaceFilter.getOutputData());
const cutSurfaceActor = vtkActor.newInstance();
cutSurfaceActor.setMapper(cutSurfaceMapper);
renderer.addActor(cutSurfaceActor);
the result, as shown below, is that the surface is out of contour range
Then,I use vtkContourTriangulator according to vtkclipclosesurface implementation code,The main code is as follows
const polysArray = vtkCellArray.newInstance({
dataType: VtkDataTypes.DOUBLE,
empty: true
});
const cutterData = cutter.getOutputData();
cutterData.setPolys(polysArray);
vtkContourTriangulator.triangulateContours(cutterData, 0, cutterData.getLines().getNumberOfCells(), polysArray, [-normal[0], -normal[1], -normal[2]]);
const cutSurfaceMapper = vtkMapper.newInstance();
cutSurfaceMapper.setInputData(cutterData);
const cutSurfaceActor = vtkActor.newInstance();
cutSurfaceActor.setMapper(cutSurfaceMapper);
renderer.addActor(cutSurfaceActor);
the result as shown below,no surface
The vtkContourTriangulator is written in almost the same way in the following code,the result is ok
const source = vtkPolyData.newInstance();
const nbPoints = 16;
const points = vtkPoints.newInstance({
size: nbPoints * 3
});
source.setPoints(points);
const lines = vtkCellArray.newInstance();
source.setLines(lines);
for (let i = 0; i < nbPoints; i++) {
const phi = (i * (2 * Math.PI)) / nbPoints;
points.setPoint(i, Math.cos(phi), Math.sin(phi), 0);
if(i === nbPoints - 1) {
lines.insertNextCell([i, 0]);
} else {
lines.insertNextCell([i, i + 1]);
}
}
const polysArray = vtkCellArray.newInstance({
dataType: VtkDataTypes.DOUBLE,
empty: true
});
source.setPolys(polysArray);
vtkContourTriangulator.triangulateContours(source, 0, source.getLines().getNumberOfCells(), polysArray, [0, 0, 1]);
mapper.setInputData(source);
The reason I didn’t use vtkclipclosesurface directly is that it takes a long time to clip multiple planes,
Is there any good way to convert vtkCutter cutting results to surface