我通过旋转一堆圆柱体创建了一个管道模型,但我不知道如何过滤公共部分,我正在运行一个for循环来创建圆柱体并在圆上旋转它们。这有一个问题,我需要设置在循环中的位置,我想将所有圆柱体附加到一个polydata对象然后使用它 这是我的代码
import vtk
import math
import wx
# create a rendering window and renderer
ren = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren)
# create a renderwindowinteractor
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
i=0
sourc=[]
mapper=[]
actor=[]
for i in range(0,360):
sourc.append(vtk.vtkCylinderSource())
sourc[i].SetRadius(0.3)
sourc[i].SetHeight(6)
sourc[i].SetCenter(2*math.cos(i),0,2*math.sin(i))
sourc[i].SetResolution(100.0)
sourc[i].Update()
mapper.append(vtk.vtkPolyDataMapper())
mapper[i].SetInput(sourc[i].GetOutput())
actor.append(vtk.vtkActor())
actor[i].SetMapper(mapper[i])
#actor[i].SetPosition(0,2*math.cos(j),2*math.sin(j))
#actor[i].RotateZ(j)
actor[i].GetProperty().SetOpacity(1)
#actor[i].SetPosition(2*cos(i),2*sin(i),0)
ren.AddActor(actor[i])
i=i+1
# create source
#
transform = vtk.vtkTransform()
transform.Translate(0.0, 0.0,0)
axes = vtk.vtkAxesActor()
# The axes are positioned with a user transform
axes.SetUserTransform(transform)
ren.AddActor(axes)
# enable user interface interactor
iren.Initialize()
renWin.Render()
iren.Start()
答案 0 :(得分:0)
要将多个PolyData
个对象添加到一个中,请使用vtkAppendPolyData
对象:
import vtk
append = vtk.vtkAppendPolyData()
for i in range(0, 360):
(...)
append.SetInputData(sourc[i].GetOutput())
append.Update()
然后你可以添加actor并在循环之外渲染。