<div dir="ltr"><div><div><div>Ok, found it. It was not a big issue... ! Just had to take a look on the help. <br></div></div><br>I had to switch to lines in the SetCells method, according to the description in the help. <br>
<br><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex" class="gmail_quote">bloc.SetCells(
<br> numpy_support.numpy_to_vtk(cellslocations, deep = 1, array_type = vtk.vtkUnsignedCharArray().GetDataType()),
<br> numpy_support.numpy_to_vtk(cellstypes, deep = 1, array_type = vtk.vtkIdTypeArray().GetDataType()),
<br> vtkCells
<br> )
</blockquote></div><div><div><br></div><div>becomes :<br></div><div><br><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex" class="gmail_quote">bloc.SetCells(
<br> numpy_support.numpy_to_vtk(cellstypes, deep = 1, array_type = vtk.vtkUnsignedCharArray().GetDataType()),
<br> numpy_support.numpy_to_vtk(cellslocations, deep = 1, array_type = vtk.vtkIdTypeArray().GetDataType()),
<br> vtkCells
<br> )<br></blockquote><div><br></div><div>(note the switch between cellstypes and cellslocations in the method) <br><br></div><div>All is working well now. <br>Sorry for the email. (but an example of defining an UnstructuredGrid from numpy arrays is now online) <br>
<br></div><div>Regards, <br><br></div><div>Aurélien<br></div></div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">2014-07-30 17:07 GMT-04:00 Aurélien Marsan <span dir="ltr"><<a href="mailto:aur.marsan@gmail.com" target="_blank">aur.marsan@gmail.com</a>></span>:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div><div><div><div><div><div>Hi all, <br><br>I am still facing some issues in order to build a vtkUnstructuredGrid from numpy arrays. <br>
<br></div>I have read the example, that shows how to build a vtkUnstructuredGrid cell by cell : <br>
<a href="http://vtk.org/gitweb?p=VTK.git;a=blob;f=Examples/DataManipulation/Python/pointToCellData.py" target="_blank">http://vtk.org/gitweb?p=VTK.git;a=blob;f=Examples/DataManipulation/Python/pointToCellData.py</a><br><br>
</div>But in my case, I have large numpy arrays which contains<br>
</div>- the points coordinates<br></div>- the cell types<br></div>- the definition of cells (npts,p0,p1,...p(npts-1)<br><br></div>and I would like to avoid any loops in the python code. <br></div><br></div>Then, I tried the following code, where <br>
<ul><li><cells> contains the definition of the cells (npts,p0,p1,...p(npts-1)</li><li><cellslocations> contains the index of the cells in the <cells> array</li><li><cellstype> is an array of integer that describes the types of the cells<br>
</li></ul><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex" class="gmail_quote"> bloc = vtk.vtkUnstructuredGrid()
<br><br><br> vtkArray = numpy_support.numpy_to_vtk(numpy.ascontiguousarray(coords), deep = 1)
<br> points = vtk.vtkPoints()
<br> points.SetData(vtkArray)
<br><br> bloc.SetPoints(points)
<br>
<br> vtkCells = vtk.vtkCellArray()
<br> vtkCells.SetCells(number_of_cells, numpy_support.numpy_to_vtk(cells, deep = 1, array_type = vtk.vtkIdTypeArray().GetDataType()))
</blockquote><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex" class="gmail_quote"> bloc.SetCells(
<br> numpy_support.numpy_to_vtk(cellslocations, deep = 1, array_type = vtk.vtkUnsignedCharArray().GetDataType()),
<br> numpy_support.numpy_to_vtk(cellstypes, deep = 1, array_type = vtk.vtkIdTypeArray().GetDataType()),
<br> vtkCells
<br> )
<br> bloc.Update()
<br> bloc.UpdateData()
<br> print bloc
<br> return bloc<br></blockquote><div><br></div><div>This code works. But when I am trying to cut the resulting block using a VTKCutter, I have the following error message: <br><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex" class="gmail_quote">
Generic Warning: In /home/builder/pisi/tmp/VTK-5.6.0-2/work/VTK/Graphics/vtkContourGrid.cxx, line 195<br>Unknown cell type 171<br></blockquote><br></div><div>It is obvious that I do something wrong.... But I can not find where. <br>
</div><div>Do you have some advice ? <br></div><div>is it really possible to define an unstructured grid like this, avoiding any python loop ? <br></div><div><br></div><div>Many thanks in advance, <br><br></div><div>Regards, <br>
<br></div><div>Aurélien <br></div></div>
</blockquote></div><br></div>