一直对三维挺感兴趣,但一直没怎么深入下去,这几天兴致又上来了,想写点代码体验一下。好吧,从现在开始有功夫就写点吧,慢慢积累。
wxPython+VTK
这里使用的工具是pythonxy, http://code.google.com/p/pythonxy/
wxPython+VTK都在里面了,方便
开始的时候在网上东找西找,凑了个小程序,后来发现site-packages/vtk/wx目录下的wxVTKRenderWindow.py和wxVTKRenderWindowInteractor.py文件中都有例子,先看最简单的

看代码吧,很简单
#
!/usr/bin/env python
#
coding=utf-8
import
vtk
from
wxPython.wx
import
*
from
vtk.wx.wxVTKRenderWindow
import
wxVTKRenderWindow
#
----------------------------------------------------------------------------
def
wxVTKRenderWindowConeExample():
"""
Like it says, just a simple example
"""
#
every wx app needs an app
app
=
wxPySimpleApp()
#
create the widget
frame
=
wxFrame(None,
-
1
,
"test
"
, size
=
wxSize(
400
,
400
))
widget
=
wxVTKRenderWindow(frame,
-
1
)
ren
=
vtk.vtkRenderer()
widget.GetRenderWindow().AddRenderer(ren)
cone
=
vtk.vtkConeSource()
cone.SetResolution(
8
)
coneMapper
=
vtk.vtkPolyDataMapper()
coneMapper.SetInput(cone.GetOutput())
coneActor
=
vtk.vtkActor()
coneActor.SetMapper(coneMapper)
ren.AddActor(coneActor)
#
show the window
frame.Show(
1
)
app.MainLoop()
if
__name__
==
"
__main__
"
:
wxVTKRenderWindowConeExample()
638

被折叠的 条评论
为什么被折叠?



