VTK 挤出多边形点和孔问题

VTK Extrude Polygon Points and Holes Issue

我正在使用 VTK 创建我的网格。我是新手,我面临 2 个问题。

  1. 我找不到合适的文档来将孔添加到多边形网格中
  2. 多边形曲线有问题

我的代码示例是:

def extrude_polygon(vertices, holes, extrude):
    cell = vtkIdList()
    points = [[point[0], point[1]] for point in vertices]
    # points = remove_recursion(points)
    # Create points
    poly_points = vtkPoints()
    poly_points.SetDataTypeToDouble()

    [(poly_points.InsertNextPoint(pt[0], pt[1], 0), cell.InsertNextId(i)) for i, pt in enumerate(points)]

    # Create a PolyData object and add points
    pd = vtkPolyData()
    pd.Allocate(1, 1)
    pd.SetPoints(poly_points)
    # pd.InsertNextCell(VTK_POLYGON, cell)
    pd.InsertNextCell(vtkConstants.VTK_POLYGON, cell)

    prod = vtkTrivialProducer()
    prod.SetOutput(pd)

    extr = vtkLinearExtrusionFilter()
    extr.SetInputConnection(prod.GetOutputPort())
    extr.SetVector(0, 0, extrude)

    pn = vtkPolyDataNormals()
    pn.SetInputConnection(extr.GetOutputPort())
    pn.AutoOrientNormalsOn()

    return pn

当前输出:

预期输出:

您可以尝试使用 vtkContourTriangulator,例如使用 vedo:

from vedo import Line, merge, show

outpts = [
    (515.5, 146.0),
    (516.1, 429.8),
    (460.0, 440.8),
    (423.3, 489.6),
    (425.2, 534.2),
    (131.6, 532.3),
    (132.2, 337.7),
    (242.7, 339.5),
    (278.7, 323.0),
    (300.7, 304.1),
    (320.2, 268.1),
    (323.9, 236.4),
    (323.9, 146.0),
]
    
inpts = [
    (395.9, 352.9),
    (384.9, 358.4),
    (371.5, 356.0),
    (364.1, 347.4),
    (367.2, 331.6),
    (376.4, 324.8),
    (386.7, 324.2),
    (398.3, 328.5),
]

l1 = Line(outpts, lw=3, closed=True)
l2 = Line(inpts,  lw=3, closed=True)
m = merge(l1, l2).triangulate().lw(0)
sm = m.extrude(50).flat().lighting("default")

show(l1, l2, sm, axes=1)