[vtkusers] Simple 2D unstructured grid

Andrea Gavana andrea.gavana at gmail.com
Wed Sep 26 13:51:36 EDT 2018


Hi,

On Wed, 26 Sep 2018 at 20.16, Ruben Di Battista <rubendibattista at gmail.com>
wrote:

> I would probably guess that's not your laptop *per se*, but probably how
> you compiled/installed VTK on it. You could try to use, for example, a
> Virtual Machine to check that...
>
> Are you using Conda?
>
>
No, as I wrote in a previous message, I used Christophe Gohlke’s
precompiled Python wheel for Windows. Since they are for Python 2.7 64 bit,
there is no underlying reason for them not to work, unless VTK is
incompatible with my graphics card for some reason.

Even then, though, I don’t think VTK should bomb out the interpreter. Some
sort of exception raised is surely far more preferable to a hard crash, no?

Andrea.



On Wed, Sep 26, 2018 at 6:25 PM Andrea Gavana <andrea.gavana at gmail.com>
> wrote:
>
>> Hi Andras,
>>
>>
>> On Wed, 26 Sep 2018 at 19.00, Andras Lasso <lasso at queensu.ca> wrote:
>>
>>> Your script works well in Paraview’s embedded Python interpreter, too.
>>>
>>>
>>>
>>> It seems that something is wrong in your Python/VTK environment. To
>>> confirm, you can check if other VTK Python examples
>>> <https://lorensen.github.io/VTKExamples/site/> crash, too.
>>>
>>
>>
>> It appears that the issue is due to my laptop Intel’s integrated graphics
>> card (!). I have tried on another, more serious machine with a NVidia
>> graphics card and the script works flawlessly...
>>
>> I understand that my laptop may not be super duper (it’s fairly new
>> though) in terms of GPU processing but I was not trying to visualize
>> millions of polyhedrons, just 6 polygons... I wonder why VTK bombs out like
>> that...
>>
>> Thank you again for investigating and for your suggestions.
>>
>> Andrea.
>>
>>
>>
>>>
>>> Andras
>>>
>>>
>>>
>>> *From:* Andrea Gavana <andrea.gavana at gmail.com>
>>> *Sent:* Wednesday, September 26, 2018 11:53 AM
>>> *To:* Andras Lasso <lasso at queensu.ca>
>>> *Cc:* vtkusers at public.kitware.com
>>> *Subject:* Re: [vtkusers] Simple 2D unstructured grid
>>>
>>>
>>>
>>> Hi Andras,
>>>
>>> On Wed, 26 Sep 2018 at 17:37, Andras Lasso <lasso at queensu.ca> wrote:
>>>
>>> Works well for me in 3D Slicer’s embedded Python 2.7 64 bit, both with
>>> latest VTK master and VTK 7.1.0.
>>>
>>>
>>>
>>>
>>>
>>> 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?
>>>
>>>
>>>
>>> Andrea.
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> Andras
>>>
>>>
>>>
>>> *From:* vtkusers <vtkusers-bounces at public.kitware.com> *On Behalf Of *Andrea
>>> Gavana
>>> *Sent:* Wednesday, September 26, 2018 10:23 AM
>>> *To:* vtkusers at public.kitware.com
>>> *Subject:* [vtkusers] Simple 2D unstructured grid
>>>
>>>
>>>
>>> Hello list,
>>>
>>>
>>>
>>>     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...".
>>>
>>>
>>>
>>> A simplified version of my grid is in the picture below (done in Excel,
>>> sorry...):
>>>
>>>
>>>
>>> [image: image.png]
>>>
>>>
>>>
>>> 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.
>>>
>>>
>>>
>>> Thank you in advance for your help.
>>>
>>>
>>>
>>> Andrea.
>>>
>>>
>>>
>>>
>>>
>>> # -- BEGIN CODE -- #
>>>
>>>
>>>
>>> import numpy
>>>
>>> import vtk
>>>
>>>
>>>
>>> import vtk.util.numpy_support as numpy_support
>>>
>>>
>>>
>>> # X, Y coordinates of a simple grid - Z is zero
>>>
>>>
>>>
>>> X = [600.4957421, 600.5, 600.5, 600.4957421, 600.4913048, 600.5,
>>>
>>>      600.5, 600.4957421, 600.4913048, 600.4868674, 600.5, 600.5,
>>>
>>>      600.4913048, 600.4868674, 600.4824301, 600.5, 600.5, 600.4868674,
>>>
>>>      600.4824301, 600.4779928, 600.5, 600.5, 600.4824301, 600.4779928,
>>>
>>>      600.4735554, 600.5, 600.5, 600.4779928, 600.4735554]
>>>
>>>
>>>
>>> Y = [2940.5, 2940.5, 2940.404044, 2940.5, 2940.6, 2940.6, 2940.5,
>>>
>>>      2940.5, 2940.6, 2940.7, 2940.7, 2940.6, 2940.6, 2940.7, 2940.8,
>>>
>>>      2940.8, 2940.7, 2940.7, 2940.8, 2940.9, 2940.9, 2940.8, 2940.8,
>>>
>>>      2940.9, 2941, 2941, 2940.9, 2940.9, 2941]
>>>
>>>
>>>
>>> # First face is triangular, everything else is a 4-sided polygon
>>>
>>> IDS = [range(4)]
>>>
>>> IDS += numpy.split(numpy.arange(4, len(X)), 5)
>>>
>>>
>>>
>>> npoints = len(X)
>>>
>>> matrix = numpy.zeros((npoints, 3), numpy.float32)
>>>
>>>
>>>
>>> matrix[:, 0] = X
>>>
>>> matrix[:, 1] = Y
>>>
>>>
>>>
>>> # Create the grid points
>>>
>>> vtk_pts = vtk.vtkPoints()
>>>
>>> vtk_pts.SetData(numpy_support.numpy_to_vtk(matrix, deep=1))
>>>
>>>
>>>
>>> # Create the unstructured grid
>>>
>>> grid = vtk.vtkUnstructuredGrid()
>>>
>>> grid.SetPoints(vtk_pts)
>>>
>>>
>>>
>>> # Allocate space for the cells in the grid
>>>
>>> nc = len(IDS)
>>>
>>> grid.Allocate(nc)
>>>
>>>
>>>
>>> # Loop through all cells
>>>
>>> for i in xrange(nc):
>>>
>>>     cell_ids = IDS[i]
>>>
>>>     ncoords = len(cell_ids)
>>>
>>>     grid.InsertNextCell(vtk.VTK_POLYGON, ncoords, cell_ids)
>>>
>>>
>>>
>>> print grid.GetNumberOfCells(), nc
>>>
>>>
>>>
>>> mapper = vtk.vtkDataSetMapper()
>>>
>>> mapper.SetInputData(grid)
>>>
>>>
>>>
>>> actor = vtk.vtkActor()
>>>
>>> actor.SetMapper(mapper)
>>>
>>>
>>>
>>> ren = vtk.vtkRenderer()
>>>
>>> renWin = vtk.vtkRenderWindow()
>>>
>>> renWin.AddRenderer(ren)
>>>
>>> iren = vtk.vtkRenderWindowInteractor()
>>>
>>> iren.SetRenderWindow(renWin)
>>>
>>>
>>>
>>> # Add the actors to the renderer, set the background and size
>>>
>>> ren.AddActor(actor)
>>>
>>> ren.SetBackground(0, 0, 0)
>>>
>>>
>>>
>>> # This allows the interactor to initalize itself. It has to be
>>>
>>> # called before an event loop.
>>>
>>> iren.Initialize()
>>>
>>>
>>>
>>> ren.ResetCamera()
>>>
>>> renWin.Render()
>>>
>>>
>>>
>>> # Start the event loop.
>>>
>>> iren.Start()
>>>
>>>
>>>
>>>
>>>
>>> _______________________________________________
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at
>> http://www.kitware.com/opensource/opensource.html
>>
>> Please keep messages on-topic and check the VTK FAQ at:
>> http://www.vtk.org/Wiki/VTK_FAQ
>>
>> Search the list archives at: http://markmail.org/search/?q=vtkusers
>>
>> Follow this link to subscribe/unsubscribe:
>> https://public.kitware.com/mailman/listinfo/vtkusers
>
>
>>
>
> --
>           _
> -.     .´  |∞∞∞∞
>   ',  ;    |∞∞∞∞∞∞
>     ˜˜     |∞∞∞∞∞∞∞∞∞ RdB
>     ,.,    |∞∞∞∞∞∞
>   .'   '.  |∞∞∞∞
> -'       `'
> https://rdb.is <http://rdb.is>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://public.kitware.com/pipermail/vtkusers/attachments/20180926/c5b9bf96/attachment.html>


More information about the vtkusers mailing list