<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>&nbsp;</div>
<div>Thank you very much for your suggestions.</div>
<div>&nbsp;</div>
<div>Andrea<br><br>&nbsp;</div>
<div><span class="gmail_quote">On 3/22/06, <b class="gmail_sendername">Goodwin Lawlor</b> &lt;<a href="mailto:goodwin.lawlor@ucd.ie">goodwin.lawlor@ucd.ie</a>&gt; 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>&gt; Hello Goodwin,<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; thank you very much for your suggestions. This is what I have tried:<br>&gt;<br>&gt; 1) Call SetNumberOfComponents() before SetNumberOfTuples() =&gt; VTK Crashes
<br>&gt;<br>&gt; 2) Take vtkExtractGrid out of the pipeline =&gt; VTK Crashes<br>&gt;<br>&gt; 3) Try using vtkPoints::Allocate() and vtkPoints::SetTuple3(): VTK<br>&gt; crashes even before showing the 3D window: the problem is here, as you
<br>&gt; suggested in your point. I am unable to finish the call to SetTuple3 in<br>&gt; a loop if the number of points is greater than 100 or something. I can<br>&gt; finish the loop if I choose, i.e., 50 points. I attach the example with
<br>&gt; SetTuple3 as &quot;prova3.py&quot; (using real simple grid data)<br>&gt;<br>&gt; 4) I get the same runtime error from Windows if I simply use SetData()<br>&gt; instead of SetTuple3() and Allocate(), if I choose more than 100 points.
<br>&gt; If I use 50 points, for example, I get the 3D window with a nice cube. I<br>&gt; attach another example as &quot; prova4.py&quot; with SetData() instead of<br>&gt; SetTuple3() and Allocate().<br>&gt;<br>&gt; Probably I have made some mistake somewhere for the SetTuple3/Allocate
<br>&gt; example, but I am quite sure about the SetData() example. It is<br>&gt; fantastically difficult to find examples of use of VTK in Python on the<br>&gt; net...<br>&gt;<br>&gt; For the samples I used Numpy instead of Numeric because Numpy is much
<br>&gt; more friendly in creating a 3D grid... I get the error message when I<br>&gt; change the values for nx, ny, nz to bigger values.<br>&gt;<br>&gt; Does anyone have some suggestion for me? It's really complicated to find
<br>&gt; out what the problem is when I get only a windows error message... at<br>&gt; least a Python/VTK error messages would be much more useful...<br>&gt;<br>&gt; Thank you very much for your help and suggestions.<br>&gt;
<br>&gt; Andrea.<br>&gt;<br>&gt;<br>&gt;<br>&gt;<br>&gt;<br>&gt;<br>&gt; ------------------------------------------------------------------------<br>&gt;<br>&gt; import numpy as N<br>&gt; import vtk<br>&gt; import wx<br>&gt; from 
vtk.wx.wxVTKRenderWindowInteractor import wxVTKRenderWindowInteractor<br>&gt;<br>&gt; app = wx.App(0)<br>&gt;<br>&gt; # create regular grid<br>&gt; xmin, ymin, zmin = -N.pi, -N.pi, 0<br>&gt; xmax, ymax, zmax =&nbsp;&nbsp;N.pi, N.pi
, 2*N.pi<br>&gt;<br>&gt; nx, ny, nz = 5, 5, 2<br>&gt; dx, dy, dz = (xmax-xmin)/(nx-1), (ymax-ymin)/(ny-1), (zmax-zmin)/(nz-1)<br>&gt;<br>&gt; ZZ, YY, XX = N.mgrid[zmin:zmax+dz:dz, ymin:ymax+dy:dy, xmin:xmax+dx:dx]<br>&gt; XX = 
XX.astype(N.Float32)<br>&gt; YY = YY.astype(N.Float32)<br>&gt; ZZ = ZZ.astype(N.Float32)<br>&gt;<br>&gt; # set scalar function f(x,y,z)<br>&gt; RR = N.sqrt(XX**2 + YY**2 + ZZ**2)<br>&gt; WW = N.cos(2*RR)/(RR + 0.5)<br>&gt;
<br>&gt; xyz = N.zeros( (nx*ny*nz,3), N.Float32 )<br>&gt;<br>&gt; xyz[:,0] = XX.flatten()<br>&gt; xyz[:,1] = YY.flatten()<br>&gt; xyz[:,2] = ZZ.flatten()<br>&gt;<br>&gt; # 3-Dcoordinates<br>&gt; vtk_xyz = vtk.vtkFloatArray
()<br>&gt; vtk_xyz.SetNumberOfTuples(nx*ny*nz)<br>&gt; vtk_xyz.SetNumberOfComponents(3)<br>&gt;<br>&gt; vtk_pts = vtk.vtkPoints()<br>&gt; vtk_pts.Allocate(nx*ny*nz, nx*ny*nz)<br>&gt; vtk_pts.SetDataTypeToFloat()<br>&gt;<br>
&gt; count = 0<br>&gt;<br>&gt; for ii in xrange(nx):<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; for jj in xrange(ny):<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for kk in xrange(nz):<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; vtk_xyz.SetTuple3(count, xyz[count, 0], xyz[count, 1], xyz[count, 2])<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; count = count + 1
<br>&gt;<br>&gt; vtk_pts.SetData(vtk_xyz)<br>&gt;<br>&gt; # create and fill vtk array<br>&gt; vtk_zz = vtk.vtkFloatArray()<br>&gt; vtk_zz.SetNumberOfTuples(nx*ny*nz)<br>&gt; vtk_zz.SetNumberOfComponents(1)<br>&gt; vtk_zz.SetVoidArray(
WW.flatten(), nx*ny*nz, 1)<br>&gt;<br>&gt; # create vtk data<br>&gt; grid = vtk.vtkStructuredGrid()<br>&gt; grid.SetDimensions(nx, ny, nz)<br>&gt; grid.SetPoints(vtk_pts)<br>&gt; grid.GetPointData().SetScalars(vtk_zz)<br>
&gt;<br>&gt; # Create Actor<br>&gt; surfaceMapper = vtk.vtkDataSetMapper()<br>&gt; surfaceMapper.SetInput(grid)<br>&gt;<br>&gt; surfaceActor = vtk.vtkActor()<br>&gt; surfaceActor.SetMapper(surfaceMapper)<br>&gt;<br>&gt; # show
<br>&gt; frame = wx.Frame(None, -1, &quot;BlaBla&quot;)<br>&gt;<br>&gt; widget = wxVTKRenderWindowInteractor(frame, -1)<br>&gt; hiren = vtk.vtkRenderer()<br>&gt; widget.GetRenderWindow().AddRenderer(hiren)<br>&gt;<br>&gt; 
hiren.AddActor(surfaceActor)<br>&gt;<br>&gt; widget.AddObserver(&quot;ExitEvent&quot;, lambda o,e,f=frame: f.Close())<br>&gt; widget.Enable(1)<br>&gt;<br>&gt; sizer = wx.BoxSizer(wx.VERTICAL)<br>&gt; sizer.Add(widget, 1, 
wx.EXPAND)<br>&gt; frame.SetSizer(sizer)<br>&gt; sizer.Layout()<br>&gt;<br>&gt; frame.SetSize((800, 600))<br>&gt; frame.Show()<br>&gt;<br>&gt; app.MainLoop()<br>&gt;<br>&gt;<br>&gt;<br>&gt; ------------------------------------------------------------------------
<br>&gt;<br>&gt; import numpy as N<br>&gt; import vtk<br>&gt; import wx<br>&gt; from vtk.wx.wxVTKRenderWindowInteractor import wxVTKRenderWindowInteractor<br>&gt;<br>&gt; app = wx.App(0)<br>&gt;<br>&gt; # create regular grid
<br>&gt; xmin, ymin, zmin = -N.pi, -N.pi, 0<br>&gt; xmax, ymax, zmax =&nbsp;&nbsp;N.pi, N.pi, 2*N.pi<br>&gt;<br>&gt; nx, ny, nz = 5, 5, 2<br>&gt; dx, dy, dz = (xmax-xmin)/(nx-1), (ymax-ymin)/(ny-1), (zmax-zmin)/(nz-1)<br>&gt;<br>&gt; ZZ, YY, XX = 
N.mgrid[zmin:zmax+dz:dz, ymin:ymax+dy:dy, xmin:xmax+dx:dx]<br>&gt; XX = XX.astype(N.Float32)<br>&gt; YY = YY.astype(N.Float32)<br>&gt; ZZ = ZZ.astype(N.Float32)<br>&gt;<br>&gt; # set scalar function f(x,y,z)<br>&gt; RR = 
N.sqrt(XX**2 + YY**2 + ZZ**2)<br>&gt; WW = N.cos(2*RR)/(RR + 0.5)<br>&gt;<br>&gt; xyz = N.zeros( (nx*ny*nz,3), N.Float32 )<br>&gt;<br>&gt; xyz[:,0] = XX.flatten()<br>&gt; xyz[:,1] = YY.flatten()<br>&gt; xyz[:,2] = ZZ.flatten
()<br>&gt;<br>&gt; # 3-Dcoordinates<br>&gt; vtk_xyz = vtk.vtkFloatArray()<br>&gt; vtk_xyz.SetNumberOfTuples(nx*ny*nz)<br>&gt; vtk_xyz.SetNumberOfComponents(3)<br>&gt; vtk_xyz.SetVoidArray(xyz.flatten(), 3*nx*ny*nz, 1)<br>
&gt;<br>&gt; vtk_pts = vtk.vtkPoints()<br>&gt; vtk_pts.Allocate(nx*ny*nz, nx*ny*nz)<br>&gt; vtk_pts.SetDataTypeToFloat()<br>&gt; vtk_pts.SetData(vtk_xyz)<br>&gt;<br>&gt; # create and fill vtk array<br>&gt; vtk_zz = vtk.vtkFloatArray
()<br>&gt; vtk_zz.SetNumberOfTuples(nx*ny*nz)<br>&gt; vtk_zz.SetNumberOfComponents(1)<br>&gt; vtk_zz.SetVoidArray(WW.flatten(), nx*ny*nz, 1)<br>&gt;<br>&gt; # create vtk data<br>&gt; grid = vtk.vtkStructuredGrid()<br>&gt; 
grid.SetDimensions(nx, ny, nz)<br>&gt; grid.SetPoints(vtk_pts)<br>&gt; grid.GetPointData().SetScalars(vtk_zz)<br>&gt;<br>&gt; # Create Actor<br>&gt; surfaceMapper = vtk.vtkDataSetMapper()<br>&gt; surfaceMapper.SetInput(grid)
<br>&gt;<br>&gt; surfaceActor = vtk.vtkActor()<br>&gt; surfaceActor.SetMapper(surfaceMapper)<br>&gt;<br>&gt; # show<br>&gt; frame = wx.Frame(None, -1, &quot;BlaBla&quot;)<br>&gt;<br>&gt; widget = wxVTKRenderWindowInteractor(frame, -1)
<br>&gt; hiren = vtk.vtkRenderer()<br>&gt; widget.GetRenderWindow().AddRenderer(hiren)<br>&gt;<br>&gt; hiren.AddActor(surfaceActor)<br>&gt;<br>&gt; widget.AddObserver(&quot;ExitEvent&quot;, lambda o,e,f=frame: f.Close())<br>
&gt; widget.Enable(1)<br>&gt;<br>&gt; sizer = wx.BoxSizer(wx.VERTICAL)<br>&gt; sizer.Add(widget, 1, wx.EXPAND)<br>&gt; frame.SetSizer(sizer)<br>&gt; sizer.Layout()<br>&gt;<br>&gt; frame.SetSize((800, 600))<br>&gt; frame.Show
()<br>&gt;<br>&gt; app.MainLoop()<br>&gt;<br>&gt;<br>&gt;<br>&gt; ------------------------------------------------------------------------<br>&gt;<br>&gt; _______________________________________________<br>&gt; This is the private VTK discussion list.
<br>&gt; 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>&gt; Follow this link to subscribe/unsubscribe:<br>&gt; <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>&quot;Imagination Is The Only Weapon In The War Against Reality.&quot;<br><br><a href="http://xoomer.virgilio.it/infinity77/">http://xoomer.virgilio.it/infinity77/</a><br>