我是VTK的新手
当我尝试可视化一个球体,并在sphere.SetCenter(0.0,0.0,z_值)中调整z值时,我只能可视化切割球体
我猜有一个可视框(:立方体)。如何扩展我的ViewCube
z_value = -1.0
ren = vtk.vtkRenderer()
sphere = vtk.vtkSphere()
sphere.SetCenter(0.0, 0.0, z_value)
sphere.SetRadius(0.1)
# The sample function generates a distance function from the implicit
# function. This is then contoured to get a polygonal surface.
sample = vtk.vtkSampleFunction()
sample.SetImplicitFunction(sphere)
#sample.SetModelBounds(-100.0, 100.0, -100.0, 100.0, -100.0, 100.0)
#sample.SetSampleDimensions(20, 20, 20)
sample.ComputeNormalsOff()
# contour
surface = vtk.vtkContourFilter()
surface.SetInputConnection(sample.GetOutputPort())
surface.SetValue(0, 0.0)
# mapper
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(surface.GetOutputPort())
mapper.ScalarVisibilityOff()
actor = vtk.vtkActor()
actor.SetMapper(mapper)
actor.GetProperty().EdgeVisibilityOn()
actor.GetProperty().SetEdgeColor(.2, .2, .5)
# A renderer and render window
ren = vtk.vtkRenderer()
ren.SetBackground(0, 0, 0)
# add the actor
ren.AddActor(actor)
renWin = vtk.vtkRenderWindow()
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
renWin.AddRenderer(ren)
# This allows the interactor to initalize itself. It has to be
# called before an event loop.
iren.Initialize()
# We'll zoom in a little by accessing the camera and invoking a "Zoom"
# method on it.
ren.ResetCamera()
#ren.GetActiveCamera().Zoom(1.5)
renWin.Render()
# Start the event loop.
iren.Start()
要修复脚本,应该取消对
sample.SetModelBounds()
行的注释,并设置球体的实际边界,即sample.SetModelBounds(centerX - radius, centerX + radius, centerY - radius, centerY + radius, centerZ - radius, centerZ + radius,)
也就是说,如果您只想显示一个球体,那么最好使用
vtkSphereSource
。因此,可以通过以下方式替换球体采样轮廓零件:及以下
mapper.SetInputConnection(sphere.GetOutputPort())
相关问题 更多 >
编程相关推荐