<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">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>