[vtkusers] What's Wrong With This?!?
andrea_gavana at tin.it
andrea_gavana at tin.it
Mon Mar 20 04:34:45 EST 2006
Hello NG,
I am using VTK 5.0.0 (downloaded from the website),
Windows XP, Python 2.4.1 and wxPython 2.6.2.1. I have tried this small
piece of code that worked in the past. Now I get a "segmentation
fault", a message window telling me that Python has performed some
illegal operation and it will be shut down. Does anyone know what's
wrong with this piece of code?
Thank you very much for your help.
Andrea.
import wx
import vtk
import Numeric
from vtk.wx.
wxVTKRenderWindowInteractor import wxVTKRenderWindowInteractor
class
ReadEclipseData(wx.Frame):
def __init__(self, parent, id=-1,
title="", pos=wx.DefaultPosition,
size=wx.DefaultSize,
style = wx.DEFAULT_FRAME_STYLE):
wx.Frame.__init__(self,
parent, id, title, pos, size, style)
widget =
wxVTKRenderWindowInteractor(self, -1)
sizer = wx.BoxSizer(wx.
VERTICAL)
sizer.Add(widget, 1, wx.EXPAND)
self.SetSizer
(sizer)
self.Layout()
nx = 19
ny = 28
nz = 5
xyz_data = Numeric.zeros((24*nx*ny*nz, 1), Numeric.
Float)
vtk_xyz = vtk.vtkFloatArray()
vtk_xyz.
SetNumberOfTuples(8*nx*ny*nz)
vtk_xyz.SetNumberOfComponents(3)
vtk_xyz.SetVoidArray(xyz_data,24*nx*ny*nz,1)
vtk_pts =
vtk.vtkPoints()
vtk_pts.SetNumberOfPoints(8*nx*ny*nz)
vtk_pts.SetDataTypeToFloat()
vtk_pts.SetData(vtk_xyz)
# create vtk data
a = vtk.vtkStructuredGrid()
a.
SetDimensions(2*nx, 2*ny, 2*nz)
a.SetPoints(vtk_pts)
#
create scalars
scalar_data = Numeric.ones((8*nx*ny*nz, 1),
Numeric.Float)
vtk_scal = vtk.vtkFloatArray()
vtk_scal.
SetNumberOfTuples(8*nx*ny*nz)
vtk_scal.SetNumberOfComponents(1)
vtk_scal.SetVoidArray(scalar_data,8*nx*ny*nz,1)
a.
GetPointData().SetScalars(vtk_scal)
data_range = a.
GetScalarRange()
meshGeom = vtk.vtkExtractGrid()
meshGeom.SetInput(a)
surfaceMapper = vtk.
vtkDataSetMapper()
surfaceMapper.SetInput(meshGeom.GetOutput())
surfaceMapper.SetScalarRange(data_range)
surfaceMapper.
ScalarVisibilityOn()
surfaceActor = vtk.vtkActor()
surfaceActor.SetMapper(surfaceMapper)
hiren = vtk.vtkRenderer()
widget.GetRenderWindow().AddRenderer
(hiren)
widget.AddObserver("ExitEvent", lambda o,e,
f=self: f.Close())
hiren.AddActor(surfaceActor)
widget.Enable(1)
self.SetSize((800, 600))
self.Show()
def main():
app = wx.App(0)
frame = ReadEclipseData(None, -1, "BlaBla")
frame.Show()
app.
MainLoop()
if __name__ == "__main__":
main()
"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.virgilio.it/infinity77
More information about the vtkusers
mailing list