VTK的扫掠(Extrusion)造型算法

2020-04-01 21:21:35|?次阅读|上传:wustguangh【已有?条评论】发表评论

关键词:VTK|来源:唯设编程网

vtk直线扫掠.PNG

下面的例子先在平面构造一个近似平面圆的polydata,然后使用vtkRotationalExtrusionFilter螺旋扫掠得到弹簧架构,程序的主要代码如下:

    points = vtk.vtkPoints()
    points.InsertPoint(0, 1.0, 0.0, 0.0)
    points.InsertPoint(1, 1.0732, 0.0, -0.1768)
    points.InsertPoint(2, 1.25, 0.0, -0.25)
    points.InsertPoint(3, 1.4268, 0.0, -0.1768)
    points.InsertPoint(4, 1.5, 0.0, 0.0)
    points.InsertPoint(5, 1.4268, 0.0, 0.1768)
    points.InsertPoint(6, 1.25, 0.0, 0.25)
    points.InsertPoint(7, 1.0732, 0.0, 0.1768)

    poly = vtk.vtkCellArray()

    poly.InsertNextCell(8)
    poly.InsertCellPoint(0)
    poly.InsertCellPoint(1)
    poly.InsertCellPoint(2)
    poly.InsertCellPoint(3)
    poly.InsertCellPoint(4)
    poly.InsertCellPoint(5)
    poly.InsertCellPoint(6)
    poly.InsertCellPoint(7)

    profile = vtk.vtkPolyData()
    profile.SetPoints(points)
    profile.SetPolys(poly)

    #拉伸
    extrude = vtk.vtkRotationalExtrusionFilter()
    extrude.SetInputData(profile)
    extrude.SetResolution(360)
    extrude.SetTranslation(6)
    extrude.SetDeltaRadius(1.0)
    extrude.SetAngle(2160.0)

    normals = vtk.vtkPolyDataNormals()
    normals.SetInputConnection(extrude.GetOutputPort())
    normals.SetFeatureAngle(60)

    mapper = vtk.vtkPolyDataMapper()
    mapper.SetInputConnection(normals.GetOutputPort())

    spring = vtk.vtkActor()
    spring.SetMapper(mapper)
    spring.GetProperty().SetColor(0.0, 0.79, 0.34)

    ren = vtk.vtkRenderer()
    renWin = vtk.vtkRenderWindow()
    renWin.AddRenderer(ren)

    iren = vtk.vtkRenderWindowInteractor()
    iren.SetRenderWindow(renWin)

    ren.AddActor(spring)

    renWin.Render()
    iren.Start()

最终的运行效果如下:

发表评论0条 】
网友评论(共?条评论)..
VTK的扫掠(Extrusion)造型算法