A little note about Python 3D display, STL file format, and C++ Calling.
Python FAQ
PyGame Resources
VPython
VPython is the Python programming language plus a 3D graphics module called “visual” originated by David Scherer in 2000. VPython makes it easy to create navigable 3D displays and animations, even for those with limited programming experience. Because it is based on Python, it also has much to offer for experienced programmers and researchers.Albow
A Little Bit of Widgetry for PyGame
This is a widget set for creating a GUI using PyGame. It has been developed over the course of several PyWeek game competition entries. I am documenting and releasing it as a separate package so that others may benefit from it, and so that it will be permissible for use in future PyGame entries.PyQtGraph
PyQtGraph is a pure-python graphics and GUI library built on PyQt4 / PySide and numpy. It is intended for use in mathematics / scientific / engineering applications. Despite being written entirely in python, the library is very fast due to its heavy leverage of numpy for number crunching and Qt’s GraphicsView framework for fast display. PyQtGraph is distributed under the MIT open-source license.
TVTK STL Reader and Writer
This package is based on VTK.
The Visualization Toolkit (VTK) is an open-source, freely available software system for 3D computer graphics, image processing and visualization. VTK consists of a C++ class library and several interpreted interface layers including Tcl/Tk, Java, and Python. Kitware, whose team created and continues to extend the toolkit, offers professional support and consulting services for VTK. VTK supports a wide variety of visualization algorithms including: scalar, vector, tensor, texture, and volumetric methods; and advanced modeling techniques such as: implicit modeling, polygon reduction, mesh smoothing, cutting, contouring, and Delaunay triangulation. VTK has an extensive information visualization framework, has a suite of 3D interaction widgets, supports parallel processing, and integrates with various databases on GUI toolkits such as Qt and Tk. VTK is cross-platform and runs on Linux, Windows, Mac and Unix platforms.
Python 调用外部 DLL
Python:使用ctypes库调用外部DLL
详细的例子和流程最简ctypes实例(只能调用DLL文件中的C函数,不能调用C++类内成员函数)
from ctypes import *
user32 = windll.LoadLibrary(‘user32.dll’) # load dll
user32.MessageBoxA(0, ‘Ctypes is cool!’, ‘Ctypes’, 0)call message box function
对于 C 函数 DLL 来说,不知道头文件也是可以调用的
用微软 depends 工具,查询到函数名称。
手动编写函数输入输出参数格式,然后调用
from ctypes import *
pdi = cdll.LoadLibrary(r’PDI.dll’) # load dll
DiscoverCnx=getattr(pdi, “?DiscoverCnx@CPDIdev@@UAE?AW4ePiCommType@@H@Z”)
DiscoverCnx.argtypes=[c_void_p];
DiscoverCnx.restype=c_int;
print DiscoverCnx(c_void_p(0))
可惜 类成员函数调用类内成员变量或函数会造成访问越界。
HOPE - A solution to call C++ member function from Python
boost
Rewrite the .h file to a Python Class
Consider a C++ class/struct that we want to expose to Python:
struct World
{
void set(std::string msg) { this->msg = msg; }
std::string greet() { return msg; }
std::string msg;
};
We can expose this to Python by writing a corresponding Boost.Python C++ Wrapper:
#include <boost/python.hpp>
using namespace boost::python;
BOOST_PYTHON_MODULE(hello)
{
class_<World>("World")
.def("greet", &World::greet)
.def("set", &World::set)
;
}
Here, we wrote a C++ class wrapper that exposes the member functions greet and set. Now, after building our module as a shared library, we may use our class World in Python. Here’s a sample Python session:
>>> import hello
>>> planet = hello.World()
>>> planet.set('howdy')
>>> planet.greet()
'howdy'
Boost.Python
This is the actual package responsible for the interoperability between C++ and Python
SWIG
SWIG is another possible solution. Maybe later.