I want to clip a vtkPolygon in vtkUnstructuredGrid, the result should only have one vtkcell(vtkPolygon).
I used vtkClipdataset, vtkTablebaseclipdataset, but the two algorithm may generate more than one vtkcell(vtkTriangle) in the result. Is there any method to meet the previous requirement?
Here is the code, thanks.
points = vtkPoints()
points.InsertNextPoint(1, 0, 0)
points.InsertNextPoint(1, 1, 0)
points.InsertNextPoint(-1, 1, 1)
points.InsertNextPoint(-1, 0, 1)
polygon = vtkPolygon()
polygon.GetPointIds().SetNumberOfIds(4)
polygon.GetPointIds().SetId(0, 0)
polygon.GetPointIds().SetId(1, 1)
polygon.GetPointIds().SetId(2, 2)
polygon.GetPointIds().SetId(3, 3)
u_grid = vtkUnstructuredGrid()
u_grid.InsertNextCell(polygon.GetCellType(), polygon.GetPointIds())
u_grid.SetPoints(points)
origin = (0, 0, 0)
normal = (1, 0, 0)
clip_plane_1 = vtkPlane()
clip_plane_1.SetOrigin(origin)
clip_plane_1.SetNormal(normal)
clipper = vtkClipDataSet()
clipper.SetClipFunction(clip_plane_1)
clipper.SetInputData(u_grid)
clipper.Update()
result = clipper.GetOutput()
print(result.GetNumberOfCells()) # number = 3
writer = vtkXMLUnstructuredGridWriter()
writer.SetFileName(file_path)
writer.SetInputData(vtk_model)
writer.Write()
Result in Paraview: