3D plotting in a GUI

B

Baris Demir

Hi all,

I need to develop a GUI for some scientific data processing operations
and this GUI should work well with a 3D plotting module, also with NumPy
and SciPy for sure. I made a search about packages but, there are plenty
of these modules available. What kind of a package or a package of
packages might be the best way for this work. BTW I do not want to use
MayaVi. It is too much actually.

Thanks in advance.
BD
 
R

R Fritz

I've been doing 3D modeling for lighting simulation and I found two
reasonably well-supported solutions: VTK and OpenSceneGraph. VTK
generally has a research slant and has what I believe are reasonably
strong Python bindings. OSG is closer to VR/AR/Flight Simulation
applications and the Python bindings are pre-alpha--you'll probably have
to roll your own for some purposes. Both are OpenGL based; if you need
an easy Windows install you'll have to go with something that supports
DirectX.

If your app is simple, you might just be able to write OpenGL code.

Anyone who knows of other reasonably current libraries, please follow
up--there are a lot of libraries that don't seem to see much activity,
and I'm not sure if this is because they are complete or because they
are not much used.
 
E

Eric Carlson

Baris said:
Hi all,

I need to develop a GUI for some scientific data processing operations
and this GUI should work well with a 3D plotting module, also with NumPy
and SciPy for sure. I made a search about packages but, there are plenty
of these modules available. What kind of a package or a package of
packages might be the best way for this work. BTW I do not want to use
MayaVi. It is too much actually.

Thanks in advance.
BD


The attached example should give you some idea of embedding mayavi (and
then using the very high-level mlab) and vtk in wxpython apps. This
example requires wxpython, vtk, numpy, and ETS. If you are really after
visualization of data, you will need to spend years to get even a
fraction of the capability of mayavi. On the other hand, rolling out a
py2exe'd version of a program is currently a major challenge if you need
ETS.

The mayavi.mlab module is so easy to use and embed that I would
recommend using it to create a rapid software prototype to compare
against whatever system you decide to go with. It is designed with a
seamless interface to numpy/scipy, and provides high-level routines to
modify low-level properties.

Cheers,
Eric

"""
This example show how to embedded Mayavi in a wx aui notebook, and
also shows how to embed a generic vtk window

This is a slightly more complex example than the wx_embedding.py one, and
can be used to see how a large wx application can use different
Mayavi views.
"""

from numpy import ogrid, sin

from enthought.traits.api import HasTraits, Instance
from enthought.traits.ui.api import View, Item

from enthought.mayavi.sources.api import ArraySource
from enthought.mayavi.modules.api import IsoSurface

from enthought.tvtk.pyface.scene_editor import SceneEditor
from enthought.mayavi.tools.mlab_scene_model import MlabSceneModel

class MayaviView(HasTraits):

scene = Instance(MlabSceneModel, ())

view = View(Item('scene', editor=SceneEditor(), resizable=True,
show_label=False),
resizable=True)

def __init__(self):
HasTraits.__init__(self)
x, y, z = ogrid[-10:10:100j, -10:10:100j, -10:10:100j]
scalars = sin(x*y*z)/(x*y*z)
src = ArraySource(scalar_data=scalars)
self.scene.engine.add_source(src)
src.add_module(IsoSurface())
#
# Wx Code
import wx
import vtk
from vtk.wx import *
from enthought.mayavi import mlab
class MainWindow(wx.Frame):

def __init__(self, parent, id):
wx.Frame.__init__(self, parent, id, 'Mayavi in a Wx notebook')
self.notebook = wx.aui.AuiNotebook(self, id=-1,
style=wx.aui.AUI_NB_TAB_SPLIT | wx.aui.AUI_NB_CLOSE_ON_ALL_TABS
| wx.aui.AUI_NB_LEFT)
sizer = wx.BoxSizer()
sizer.Add(self.notebook,1, wx.EXPAND)
self.SetSizer(sizer)

self.mayavi_view = MayaviView()

self.control = self.mayavi_view.edit_traits(
parent=self,
kind='subpanel').control
self.notebook.AddPage(page=self.control, caption='Display 1')
self.mayavi_view2 = MayaviView()

self.control2 = self.mayavi_view2.edit_traits(
parent=self,
kind='subpanel').control
self.notebook.AddPage(page=self.control2, caption='Display 2')
#the following clears the second panel,
#then shows the output of test_contour3d in the same panel
mlab.clf() #clear the figure in Display 2
mlab.test_contour3d() #add some stuff there
mlab.show_pipeline() #display the mayavi pipeline viewer


#the following creates a VTK window and embeds in our notebook
self.notebook.AddPage(page=wxVTKRenderWindowInteractor.wxVTKRenderWindowInteractor(self, -1), caption='VTK Panel')

widget = self.notebook.GetPage(2)
widget.Enable(1)
widget.AddObserver('ExitEvent', lambda o,e,f=self: f.Close())
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)
style = vtk.vtkInteractorStyleTrackballCamera()
widget._Iren.SetInteractorStyle(style)

self.Show(True)

if __name__ == '__main__':
app = wx.PySimpleApp()
frame = MainWindow(None, wx.ID_ANY)
app.MainLoop()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top