1,451
社区成员




import vtk
aRender = vtk.vtkRenderer()
Renwin = vtk.vtkRenderWindow()
Renwin.AddRenderer(aRender)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(Renwin)
# 定义个图片读取接口
Jpg_Reader = vtk.vtkBMPReader()
Jpg_Reader.SetNumberOfScalarComponents(1)
Jpg_Reader.SetFileDimensionality(3) # 说明图像是三维的
Jpg_Reader.SetDataSpacing(3.2, 3.2, 1.5)
Jpg_Reader.SetDataExtent(0, 289, 0, 289, 0, 240)
# 设置图像的存放位置
Jpg_Reader.SetFilePrefix("D://bisheshuju//all biaoding//50p//dong5//dong5//")
# 设置图像前缀名字
Jpg_Reader.SetFilePattern("%s%03d.bmp")
Jpg_Reader.SetAllow8BitBMP(16)
Jpg_Reader.Update()
Jpg_Reader.SetDataByteOrderToLittleEndian()
contour = vtk.vtkMarchingCubes()
contour.SetInputConnection(Jpg_Reader.GetOutputPort())
contour.ComputeNormalsOn()
contour.SetValue(0, 175)
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(contour.GetOutputPort())
mapper.ScalarVisibilityOff()
actor = vtk.vtkActor()
actor.SetMapper(mapper)
renderer = vtk.vtkRenderer()
renderer.SetBackground([0.1, 0.1, 0.5])
renderer.AddActor(actor)
window = vtk.vtkRenderWindow()
window.SetSize(512, 512)
window.AddRenderer(renderer)
interactor = vtk.vtkRenderWindowInteractor()
interactor.SetRenderWindow(window)
# 开始显示
window.Render()
interactor.Initialize()
interactor.Start()