<div dir="ltr">Hi Andras,<br><div class="gmail_quote"><div dir="ltr">On Wed, 26 Sep 2018 at 17:37, Andras Lasso <<a href="mailto:lasso@queensu.ca">lasso@queensu.ca</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div lang="EN-US" link="#0563C1" vlink="#954F72">
<div class="m_-4479680425648124611WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">Works well for me in 3D Slicer’s embedded Python 2.7 64 bit, both with latest VTK master and VTK 7.1.0.</span></p></div></div></blockquote><div><br></div><div><br></div><div>Thank you for trying it out. I have upgraded VTK to 7.1.1 from Gohlke's site but the program still crashes Python hard. Does anyone know what might be going on?</div><div><br></div><div>Andrea.</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div lang="EN-US" link="#0563C1" vlink="#954F72"><div class="m_-4479680425648124611WordSection1"><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">Andras<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">From:</span></b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"> vtkusers <<a href="mailto:vtkusers-bounces@public.kitware.com" target="_blank">vtkusers-bounces@public.kitware.com</a>>
<b>On Behalf Of </b>Andrea Gavana<br>
<b>Sent:</b> Wednesday, September 26, 2018 10:23 AM<br>
<b>To:</b> <a href="mailto:vtkusers@public.kitware.com" target="_blank">vtkusers@public.kitware.com</a><br>
<b>Subject:</b> [vtkusers] Simple 2D unstructured grid<u></u><u></u></span></p>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<div>
<p class="MsoNormal">Hello list,<u></u><u></u></p>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"> I m trying to create a very, very simple 2D unstructured grid but every time I run my script - no matter what modifications I do - Python crashes hard with a Windows message "Python has stopped working...".<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">A simplified version of my grid is in the picture below (done in Excel, sorry...):<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<div>
<p class="MsoNormal"><img width="481" height="289" style="width:5.0104in;height:3.0104in" id="m_-4479680425648124611_x0000_i1025" src="cid:image001.png@01D4558D.56BD6730" alt="image.png"><u></u><u></u></p>
</div>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">I attach a copy of my script below. Could anyone offer some suggestions on what I am doing wrong? I am using VTK 7.1.0 on Windows 7 64 bit, Python 2.7 64 bit - VTK comes from Christophe Gohlke very useful Python binary wheels.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Thank you in advance for your help.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Andrea.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"># -- BEGIN CODE -- #<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<div>
<p class="MsoNormal">import numpy<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">import vtk<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">import vtk.util.numpy_support as numpy_support<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"># X, Y coordinates of a simple grid - Z is zero<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">X = [600.4957421, 600.5, 600.5, 600.4957421, 600.4913048, 600.5,<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> 600.5, 600.4957421, 600.4913048, 600.4868674, 600.5, 600.5,<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> 600.4913048, 600.4868674, 600.4824301, 600.5, 600.5, 600.4868674,<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> 600.4824301, 600.4779928, 600.5, 600.5, 600.4824301, 600.4779928,<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> 600.4735554, 600.5, 600.5, 600.4779928, 600.4735554]<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Y = [2940.5, 2940.5, 2940.404044, 2940.5, 2940.6, 2940.6, 2940.5,<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> 2940.5, 2940.6, 2940.7, 2940.7, 2940.6, 2940.6, 2940.7, 2940.8,<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> 2940.8, 2940.7, 2940.7, 2940.8, 2940.9, 2940.9, 2940.8, 2940.8,<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> 2940.9, 2941, 2941, 2940.9, 2940.9, 2941]<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"># First face is triangular, everything else is a 4-sided polygon<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">IDS = [range(4)]<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">IDS += numpy.split(numpy.arange(4, len(X)), 5)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">npoints = len(X)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">matrix = numpy.zeros((npoints, 3), numpy.float32)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">matrix[:, 0] = X<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">matrix[:, 1] = Y<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"># Create the grid points<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">vtk_pts = vtk.vtkPoints()<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">vtk_pts.SetData(numpy_support.numpy_to_vtk(matrix, deep=1))<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"># Create the unstructured grid<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">grid = vtk.vtkUnstructuredGrid()<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">grid.SetPoints(vtk_pts)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"># Allocate space for the cells in the grid<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">nc = len(IDS)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">grid.Allocate(nc)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"># Loop through all cells<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">for i in xrange(nc):<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> cell_ids = IDS[i]<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> ncoords = len(cell_ids)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> grid.InsertNextCell(vtk.VTK_POLYGON, ncoords, cell_ids)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">print grid.GetNumberOfCells(), nc<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">mapper = vtk.vtkDataSetMapper()<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">mapper.SetInputData(grid)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">actor = vtk.vtkActor()<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">actor.SetMapper(mapper)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">ren = vtk.vtkRenderer()<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">renWin = vtk.vtkRenderWindow()<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">renWin.AddRenderer(ren)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">iren = vtk.vtkRenderWindowInteractor()<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">iren.SetRenderWindow(renWin)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"># Add the actors to the renderer, set the background and size<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">ren.AddActor(actor)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">ren.SetBackground(0, 0, 0)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"># This allows the interactor to initalize itself. It has to be<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"># called before an event loop.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">iren.Initialize()<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">ren.ResetCamera()<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">renWin.Render()<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"># Start the event loop.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">iren.Start()<u></u><u></u></p>
</div>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
</div>
</div>
</div>
</div>
</blockquote></div></div>