Upload
trannhan
View
215
Download
0
Embed Size (px)
Citation preview
Pivyan Open Inventor Python binding
Tamer Fahmy
Interactive Media Systems Group
– p.1/15
What does Pivy do?
� Pivy allows you to write Open Inventorapplications in Python
� Possibility to interactively edit Open Inventorprograms from within the Python interpreteror by using a console in the scene graphwhich can be switched in and away at runtime
� An Open Inventor Python scripting nodeallows you to incorporate nodes into yourscene graph from your C++ application whichwill be capable of executing python code andcallbacksTamer Fahmy Interactive Media Systems Group – p.2/15
Why Pivy?
� I needed a “Praktikum” ;-)
� Scripting language for Rapid Applicationdevelopment
� No compile cycles -> easy effortless testing ofnew ideas
� Python offers a rich set of useful modules,e.g. regular expressions, xml parsing,persistent objects, etc.
� All the comfort of a truly dynamic language
Tamer Fahmy Interactive Media Systems Group – p.3/15
A few words about Python...
� Combines remarkable power with very clearsyntax
� Modules, classes, exceptions, very high leveldynamic data types, dynamic typing
� Interfaces to many system calls and librariesas well as to various windowing systems(X11, Motif, Tk, Gtk, Qt, wxWindows, Mac,MFC)
Tamer Fahmy Interactive Media Systems Group – p.4/15
A few words about Python...
� Built in modules are easily written in C or C++
� Also usable as an extension language forapplications that need a programmableinterface
� Python implementation is portable: it runs onmany brands of UNIX, on Windows, DOS,OS/2, Mac, Amiga...
� Python is copyrighted but freely usable anddistributable, even for commercial use
Tamer Fahmy Interactive Media Systems Group – p.5/15
A few words about Python...
� Python provides facilities for introspection
� Large applications can be developped withthe use of modules, packages, exceptionhandling (Zope, Mailman,...)
� YOU NEED PYTHON!
Tamer Fahmy Interactive Media Systems Group – p.6/15
How did I do it?
� Using SWIG - a tool for scripting languagewrapper generation
� Instead of writing interface files, gave SWIGthe raw header files to parse (idea proofedand inspired by Robert Tobler and MarcJaeger at VRViS)
� Wrote “glue”-code to translate C++ data typesto Python ones (%typemap)
� C++ constructor and method overloadingusing %rename
Tamer Fahmy Interactive Media Systems Group – p.7/15
How did I do it?
� Python uses copy by value semantics. C++methods that return values in the methodparameters have to be treated specially to beuseful
� Used %apply directive for this or really“ugly”(tm) workarounds
� Wrote glue code to treat basic datatypes likee.g. SbName as native Python datatypesinstead of classes
Tamer Fahmy Interactive Media Systems Group – p.8/15
How did I do it?
� Made overall handling of the API be more likea Pythoneer expects it -> conveniencefunctions (SbVec2f, SbMatrix, ...)
� Wrote a cast function, e.g. support =cast(userData, "SoShapeKit")
� Wrote “glue”-code to allow callbacks inPython
� During the “Pivyzation” of the Open InventorMentor C++ examples I discovered what wasmissing and so completed the functionality tolet them work
Tamer Fahmy Interactive Media Systems Group – p.9/15
Differences to the C++ API
� Not many
� Callback functions are named differently, e.g.instead of saying setCallback() you have tosay setPythonCallback()
� this has been done for 2 reasons:
� to allow you to call C++ callbacks from thePivyKit
� to make a clean separation betweencallbacks in Python and in C++
Tamer Fahmy Interactive Media Systems Group – p.10/15
Differences to the C++ API
� Values of fields can be either set by thesetValue() method or by calling the field as afunction, e.g.SomeNode.ambientColor.setValue(1.0, 0.0, 0.0) orSomeNode.ambientColor((1.0, 0.0, 0.0)) as there isno equal sign operator overloading in Python
Tamer Fahmy Interactive Media Systems Group – p.11/15
PivyKit
� A scripting node similar to VRML scriptingallows you to execute Python code duringtraversal of the scene graph in your C++programs
� Allows you to connect incoming and outgoingfields to take out calculations or modificationsof the fields
� Can be incorporated into .iv files
� This allows rapid prototyping withoutmodifying your C++ application
Tamer Fahmy Interactive Media Systems Group – p.12/15
PivyKit
� Offers a lot of flexibility
� Cool ideas can be implemented with thisnode like simple synchronization over TCP/IPsockets or a chess interface that updates aZope server with xml-rpc calls
� Curious to see in what ideas people will comeup with in using (abusing?) the PivyKit
Tamer Fahmy Interactive Media Systems Group – p.13/15
Future Developments
� Write the Pivy console to allow introspectionand modification during runtime
� SoGui - to decouple the need for a single Guibinding and make Pivy maintainable
� Build bridges to other GUI bindings availablefor python like pyGtk, pyQt, etc. like I did forPyOpenGL
� Port it to and test it on other platforms likeMS Windows and MacOSX
Tamer Fahmy Interactive Media Systems Group – p.14/15
Resources
Pivy: an Open Inventor Python bindinghttp://pivy.tammura.at/
Coin3D: an Open Inventor 2.1 implementationhttp://www.coin3d.org/
Swig: wrapper generator for scripting languageshttp://www.swig.org/
Python: an interpreted programming languagehttp://www.python.org/
Tamer Fahmy Interactive Media Systems Group – p.15/15