<div>Thank you anyway Goodwin to have looked at the scripts. It seems strange to me that no one else has had the same problems with VTK + Python. I have somewhat to assume that either there are no Windows+VTK+Python users, or none of them is using VTK to build structured grids.
</div>
<div>I haven't ever tried to compile a debug version of Python, and I suppose it would be quite a nightmare on Windows. And, even if a miracle happens and I am able to find the bug, I don't think it would make any difference: the bug will stay there until VTK/Python developers find a way to correct it, which may take weeks or months (years?).
</div>
<div>That's a pity. I have left VTK one year ago because I was frustrated. Now I can't even think to restart.</div>
<div> </div>
<div>Thank you very much for your suggestions.</div>
<div> </div>
<div>Andrea<br><br> </div>
<div><span class="gmail_quote">On 3/22/06, <b class="gmail_sendername">Goodwin Lawlor</b> <<a href="mailto:goodwin.lawlor@ucd.ie">goodwin.lawlor@ucd.ie</a>> wrote:</span>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">Hi Andrea,<br><br>I've run out of ideas except to compile a debug version of python and<br>vtk and step through the script.
<br><br>I've run Examples\DataManipulation\Tcl\Arrays.tcl and its ok even when I<br>change the number of tuples to 200- its seems to be just a python problem.<br><br>I can't see anything wrong with your python scripts below... sorry!
<br><br>Goodwin<br><br>Andrea Gavana wrote:<br>> Hello Goodwin,<br>><br>> thank you very much for your suggestions. This is what I have tried:<br>><br>> 1) Call SetNumberOfComponents() before SetNumberOfTuples() => VTK Crashes
<br>><br>> 2) Take vtkExtractGrid out of the pipeline => VTK Crashes<br>><br>> 3) Try using vtkPoints::Allocate() and vtkPoints::SetTuple3(): VTK<br>> crashes even before showing the 3D window: the problem is here, as you
<br>> suggested in your point. I am unable to finish the call to SetTuple3 in<br>> a loop if the number of points is greater than 100 or something. I can<br>> finish the loop if I choose, i.e., 50 points. I attach the example with
<br>> SetTuple3 as "prova3.py" (using real simple grid data)<br>><br>> 4) I get the same runtime error from Windows if I simply use SetData()<br>> instead of SetTuple3() and Allocate(), if I choose more than 100 points.
<br>> If I use 50 points, for example, I get the 3D window with a nice cube. I<br>> attach another example as " prova4.py" with SetData() instead of<br>> SetTuple3() and Allocate().<br>><br>> Probably I have made some mistake somewhere for the SetTuple3/Allocate
<br>> example, but I am quite sure about the SetData() example. It is<br>> fantastically difficult to find examples of use of VTK in Python on the<br>> net...<br>><br>> For the samples I used Numpy instead of Numeric because Numpy is much
<br>> more friendly in creating a 3D grid... I get the error message when I<br>> change the values for nx, ny, nz to bigger values.<br>><br>> Does anyone have some suggestion for me? It's really complicated to find
<br>> out what the problem is when I get only a windows error message... at<br>> least a Python/VTK error messages would be much more useful...<br>><br>> Thank you very much for your help and suggestions.<br>>
<br>> Andrea.<br>><br>><br>><br>><br>><br>><br>> ------------------------------------------------------------------------<br>><br>> import numpy as N<br>> import vtk<br>> import wx<br>> from
vtk.wx.wxVTKRenderWindowInteractor import wxVTKRenderWindowInteractor<br>><br>> app = wx.App(0)<br>><br>> # create regular grid<br>> xmin, ymin, zmin = -N.pi, -N.pi, 0<br>> xmax, ymax, zmax = N.pi, N.pi
, 2*N.pi<br>><br>> nx, ny, nz = 5, 5, 2<br>> dx, dy, dz = (xmax-xmin)/(nx-1), (ymax-ymin)/(ny-1), (zmax-zmin)/(nz-1)<br>><br>> ZZ, YY, XX = N.mgrid[zmin:zmax+dz:dz, ymin:ymax+dy:dy, xmin:xmax+dx:dx]<br>> XX =
XX.astype(N.Float32)<br>> YY = YY.astype(N.Float32)<br>> ZZ = ZZ.astype(N.Float32)<br>><br>> # set scalar function f(x,y,z)<br>> RR = N.sqrt(XX**2 + YY**2 + ZZ**2)<br>> WW = N.cos(2*RR)/(RR + 0.5)<br>>
<br>> xyz = N.zeros( (nx*ny*nz,3), N.Float32 )<br>><br>> xyz[:,0] = XX.flatten()<br>> xyz[:,1] = YY.flatten()<br>> xyz[:,2] = ZZ.flatten()<br>><br>> # 3-Dcoordinates<br>> vtk_xyz = vtk.vtkFloatArray
()<br>> vtk_xyz.SetNumberOfTuples(nx*ny*nz)<br>> vtk_xyz.SetNumberOfComponents(3)<br>><br>> vtk_pts = vtk.vtkPoints()<br>> vtk_pts.Allocate(nx*ny*nz, nx*ny*nz)<br>> vtk_pts.SetDataTypeToFloat()<br>><br>
> count = 0<br>><br>> for ii in xrange(nx):<br>> for jj in xrange(ny):<br>> for kk in xrange(nz):<br>> vtk_xyz.SetTuple3(count, xyz[count, 0], xyz[count, 1], xyz[count, 2])<br>> count = count + 1
<br>><br>> vtk_pts.SetData(vtk_xyz)<br>><br>> # create and fill vtk array<br>> vtk_zz = vtk.vtkFloatArray()<br>> vtk_zz.SetNumberOfTuples(nx*ny*nz)<br>> vtk_zz.SetNumberOfComponents(1)<br>> vtk_zz.SetVoidArray(
WW.flatten(), nx*ny*nz, 1)<br>><br>> # create vtk data<br>> grid = vtk.vtkStructuredGrid()<br>> grid.SetDimensions(nx, ny, nz)<br>> grid.SetPoints(vtk_pts)<br>> grid.GetPointData().SetScalars(vtk_zz)<br>
><br>> # Create Actor<br>> surfaceMapper = vtk.vtkDataSetMapper()<br>> surfaceMapper.SetInput(grid)<br>><br>> surfaceActor = vtk.vtkActor()<br>> surfaceActor.SetMapper(surfaceMapper)<br>><br>> # show
<br>> frame = wx.Frame(None, -1, "BlaBla")<br>><br>> widget = wxVTKRenderWindowInteractor(frame, -1)<br>> hiren = vtk.vtkRenderer()<br>> widget.GetRenderWindow().AddRenderer(hiren)<br>><br>>
hiren.AddActor(surfaceActor)<br>><br>> widget.AddObserver("ExitEvent", lambda o,e,f=frame: f.Close())<br>> widget.Enable(1)<br>><br>> sizer = wx.BoxSizer(wx.VERTICAL)<br>> sizer.Add(widget, 1,
wx.EXPAND)<br>> frame.SetSizer(sizer)<br>> sizer.Layout()<br>><br>> frame.SetSize((800, 600))<br>> frame.Show()<br>><br>> app.MainLoop()<br>><br>><br>><br>> ------------------------------------------------------------------------
<br>><br>> import numpy as N<br>> import vtk<br>> import wx<br>> from vtk.wx.wxVTKRenderWindowInteractor import wxVTKRenderWindowInteractor<br>><br>> app = wx.App(0)<br>><br>> # create regular grid
<br>> xmin, ymin, zmin = -N.pi, -N.pi, 0<br>> xmax, ymax, zmax = N.pi, N.pi, 2*N.pi<br>><br>> nx, ny, nz = 5, 5, 2<br>> dx, dy, dz = (xmax-xmin)/(nx-1), (ymax-ymin)/(ny-1), (zmax-zmin)/(nz-1)<br>><br>> ZZ, YY, XX =
N.mgrid[zmin:zmax+dz:dz, ymin:ymax+dy:dy, xmin:xmax+dx:dx]<br>> XX = XX.astype(N.Float32)<br>> YY = YY.astype(N.Float32)<br>> ZZ = ZZ.astype(N.Float32)<br>><br>> # set scalar function f(x,y,z)<br>> RR =
N.sqrt(XX**2 + YY**2 + ZZ**2)<br>> WW = N.cos(2*RR)/(RR + 0.5)<br>><br>> xyz = N.zeros( (nx*ny*nz,3), N.Float32 )<br>><br>> xyz[:,0] = XX.flatten()<br>> xyz[:,1] = YY.flatten()<br>> xyz[:,2] = ZZ.flatten
()<br>><br>> # 3-Dcoordinates<br>> vtk_xyz = vtk.vtkFloatArray()<br>> vtk_xyz.SetNumberOfTuples(nx*ny*nz)<br>> vtk_xyz.SetNumberOfComponents(3)<br>> vtk_xyz.SetVoidArray(xyz.flatten(), 3*nx*ny*nz, 1)<br>
><br>> vtk_pts = vtk.vtkPoints()<br>> vtk_pts.Allocate(nx*ny*nz, nx*ny*nz)<br>> vtk_pts.SetDataTypeToFloat()<br>> vtk_pts.SetData(vtk_xyz)<br>><br>> # create and fill vtk array<br>> vtk_zz = vtk.vtkFloatArray
()<br>> vtk_zz.SetNumberOfTuples(nx*ny*nz)<br>> vtk_zz.SetNumberOfComponents(1)<br>> vtk_zz.SetVoidArray(WW.flatten(), nx*ny*nz, 1)<br>><br>> # create vtk data<br>> grid = vtk.vtkStructuredGrid()<br>>
grid.SetDimensions(nx, ny, nz)<br>> grid.SetPoints(vtk_pts)<br>> grid.GetPointData().SetScalars(vtk_zz)<br>><br>> # Create Actor<br>> surfaceMapper = vtk.vtkDataSetMapper()<br>> surfaceMapper.SetInput(grid)
<br>><br>> surfaceActor = vtk.vtkActor()<br>> surfaceActor.SetMapper(surfaceMapper)<br>><br>> # show<br>> frame = wx.Frame(None, -1, "BlaBla")<br>><br>> widget = wxVTKRenderWindowInteractor(frame, -1)
<br>> hiren = vtk.vtkRenderer()<br>> widget.GetRenderWindow().AddRenderer(hiren)<br>><br>> hiren.AddActor(surfaceActor)<br>><br>> widget.AddObserver("ExitEvent", lambda o,e,f=frame: f.Close())<br>
> widget.Enable(1)<br>><br>> sizer = wx.BoxSizer(wx.VERTICAL)<br>> sizer.Add(widget, 1, wx.EXPAND)<br>> frame.SetSizer(sizer)<br>> sizer.Layout()<br>><br>> frame.SetSize((800, 600))<br>> frame.Show
()<br>><br>> app.MainLoop()<br>><br>><br>><br>> ------------------------------------------------------------------------<br>><br>> _______________________________________________<br>> This is the private VTK discussion list.
<br>> Please keep messages on-topic. Check the FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ">http://www.vtk.org/Wiki/VTK_FAQ</a><br>> Follow this link to subscribe/unsubscribe:<br>> <a href="http://www.vtk.org/mailman/listinfo/vtkusers">
http://www.vtk.org/mailman/listinfo/vtkusers</a><br><br>_______________________________________________<br>This is the private VTK discussion list.<br>Please keep messages on-topic. Check the FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ">
http://www.vtk.org/Wiki/VTK_FAQ</a><br>Follow this link to subscribe/unsubscribe:<br><a href="http://www.vtk.org/mailman/listinfo/vtkusers">http://www.vtk.org/mailman/listinfo/vtkusers</a><br></blockquote></div><br><br clear="all">
<br>-- <br>"Imagination Is The Only Weapon In The War Against Reality."<br><br><a href="http://xoomer.virgilio.it/infinity77/">http://xoomer.virgilio.it/infinity77/</a><br>