刺猬型球体




观察上图,cone包围的中间是没有球体的。

#! /usr/bin/env python

import vtk

sphere = vtk.vtkSphereSource()
cone = vtk.vtkConeSource()
glyph = vtk.vtkGlyph3D()
glyph.SetInputConnection( sphere.GetOutputPort() )
glyph.SetSourceConnection( cone.GetOutputPort() )
glyph.SetVectorModeToUseNormal()
glyph.SetScaleModeToScaleByVector()
glyph.SetScaleFactor( 0.25 )

pdMapper = vtk.vtkPolyDataMapper()
pdMapper.SetInputConnection( glyph.GetOutputPort() )

maceActor = vtk.vtkLODActor()
maceActor.SetMapper( pdMapper )
maceActor.VisibilityOn()

ren1= vtk.vtkRenderer()
ren1.AddActor( maceActor )
ren1.SetBackground( 0, 0, 0 )

renWin = vtk.vtkRenderWindow()
renWin.AddRenderer( ren1 )

renWinInteractor = vtk.vtkRenderWindowInteractor()
renWinInteractor.SetRenderWindow( renWin )
renWinInteractor.Start()

加上小球

单独加上小球




新增code:

sphereMapper = vtk.vtkPolyDataMapper()
sphereMapper.SetInputConnection( sphere.GetOutputPort() )

sphereActor = vtk.vtkActor()
sphereActor.SetMapper( sphereMapper )

使用vtkAppendPolyData

当然,我们也可以使用vtkAppendPolyData将glyph和sphere的输出统一管理,最后使用一个actor来显示。

import vtk

sphere = vtk.vtkSphereSource()
cone = vtk.vtkConeSource()
glyph = vtk.vtkGlyph3D()
glyph.SetInputConnection( sphere.GetOutputPort() )
glyph.SetSourceConnection( cone.GetOutputPort() )
glyph.SetVectorModeToUseNormal()
glyph.SetScaleModeToScaleByVector()
glyph.SetScaleFactor( 0.25 )

apd = vtk.vtkAppendPolyData()
apd.AddInputConnection(glyph.GetOutputPort())
apd.AddInputConnection(sphere.GetOutputPort())

maceMapper = vtk.vtkPolyDataMapper()
maceMapper.SetInputConnection(apd.GetOutputPort())

maceActor = vtk.vtkActor()
maceActor.SetMapper(maceMapper)
maceActor.VisibilityOn()

ren1= vtk.vtkRenderer()
ren1.AddActor( maceActor )
ren1.SetBackground( 0, 0, 0 )

renWin = vtk.vtkRenderWindow()
renWin.AddRenderer( ren1 )

renWinInteractor = vtk.vtkRenderWindowInteractor()
renWinInteractor.SetRenderWindow( renWin )
renWinInteractor.Start()

代码变更:

分类: python

发表评论

电子邮件地址不会被公开。 必填项已用*标注