<div dir="ltr"><div><div><div><div>Good day,<br></div>Thank you very much. It works!<br></div>Below the code for the latest vtk.<br></div>Best regards,<br></div>George<br><br>import vtk
<p style="margin:0px;text-indent:0px"># Create polyhedron (cube)</p>
<p style="margin:0px;text-indent:0px">pointIds = vtk.vtkIdList()</p>
<p style="margin:0px;text-indent:0px">pointIds.SetNumberOfIds(8)</p>
<p style="margin:0px;text-indent:0px">for i in range(8):</p>
<p style="margin:0px;text-indent:0px">    pointIds.InsertNextId(i)</p>
<p style="margin:0px;text-indent:0px">points = vtk.vtkPoints()</p>
<p style="margin:0px;text-indent:0px">points.InsertNextPoint(-1.0,-1.0,-1.0)</p>
<p style="margin:0px;text-indent:0px">points.InsertNextPoint( 1.0,-1.0,-1.0)</p>
<p style="margin:0px;text-indent:0px">points.InsertNextPoint( 1.0, 1.0,-1.0)</p>
<p style="margin:0px;text-indent:0px">points.InsertNextPoint(-1.0, 1.0,-1.0)</p>
<p style="margin:0px;text-indent:0px">points.InsertNextPoint(-1.0,-1.0, 1.0)</p>
<p style="margin:0px;text-indent:0px">points.InsertNextPoint( 1.0,-1.0, 1.0)</p>
<p style="margin:0px;text-indent:0px">points.InsertNextPoint( 1.0, 1.0, 1.0)</p>
<p style="margin:0px;text-indent:0px">points.InsertNextPoint(-1.0, 1.0, 1.0)</p>
<p style="margin:0px;text-indent:0px"><br></p>
<p style="margin:0px;text-indent:0px"># List of pointIds that make up the face</p>
<p style="margin:0px;text-indent:0px">faceList = [[0, 3, 2, 1],[0, 4, 7, 3],[4, 5, 6, 7],[5, 1, 2, 6],[0, 1, 5, 4],[2, 3, 7, 6]]</p>
<p style="margin:0px;text-indent:0px">faceId = vtk.vtkIdList()</p>
<p style="margin:0px;text-indent:0px">faceId.InsertNextId(6) # Number faces that make up the cell.</p>
<p style="margin:0px;text-indent:0px">for face in faceList: # Loop over all the faces</p>
<p style="margin:0px;text-indent:0px">    faceId.InsertNextId(len(face)) # Number of points in face</p>
<p style="margin:0px;text-indent:0px">    [faceId.InsertNextId(i) for i in face] # Insert the pointIds for the face</p>
<p style="margin:0px;text-indent:0px"><br></p>
<p style="margin:0px;text-indent:0px">ugrid = vtk.vtkUnstructuredGrid()</p>
<p style="margin:0px;text-indent:0px">ugrid.SetPoints(points)</p>
<p style="margin:0px;text-indent:0px">ugrid.InsertNextCell(vtk.VTK_POLYHEDRON, faceId)</p>
<p style="margin:0px;text-indent:0px"><br></p>
<p style="margin:0px;text-indent:0px">writer = vtk.vtkXMLUnstructuredGridWriter()</p>
<p style="margin:0px;text-indent:0px">writer.SetInputData(ugrid)</p>
<p style="margin:0px;text-indent:0px">writer.SetFileName("polyhedron.vtu")</p>
<p style="margin:0px;text-indent:0px">writer.SetDataModeToAscii()</p>
<p style="margin:0px;text-indent:0px">writer.Update()</p><br></div><div class="gmail_extra"><br><div class="gmail_quote">On 3 November 2014 01:48, Guðni Karl Rosenkjær <span dir="ltr"><<a href="mailto:grosenkj@eos.ubc.ca" target="_blank">grosenkj@eos.ubc.ca</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi George,<div><br></div><div>In your example you are only defining a single face and I am pretty sure that a polyhedron requires a closed / "watertight" volume by definition. </div><div><div><br></div><div>I am using vtk 5.10.1 with python 2.7 and the following example works for me (translation of C++ example Bill posted above). </div><div><br></div><div><div>Code:</div><div><div>  import vtk</div><div>  # Create polyhedron (cube)</div><div>  pointIds = vtk.vtkIdList()</div><div>  pointIds.SetNumberOfIds(8)</div><div>  for i in range(8):</div><div>    pointIds.InsertNextId(i)</div><div>  points = vtk.vtkPoints()</div><div>  points.InsertNextPoint(-1.0,-1.0,-1.0)</div><div>  points.InsertNextPoint( 1.0,-1.0,-1.0)</div><div>  points.InsertNextPoint( 1.0, 1.0,-1.0)</div><div>  points.InsertNextPoint(-1.0, 1.0,-1.0)</div><div>  points.InsertNextPoint(-1.0,-1.0, 1.0)</div><div>  points.InsertNextPoint( 1.0,-1.0, 1.0)</div><div>  points.InsertNextPoint( 1.0, 1.0, 1.0)</div><div>  points.InsertNextPoint(-1.0, 1.0, 1.0)</div><div><br></div><div>  # List of pointIds that make up the face</div><div>  faceList = [[0, 3, 2, 1],[0, 4, 7, 3],[4, 5, 6, 7],[5, 1, 2, 6],[0, 1, 5, 4],[2, 3, 7, 6]]</div><div>  faceId = vtk.vtkIdList()</div><div>  faceId.InsertNextId(6) # Number faces that make up the cell.</div><div>  for face in faceList: # Loop over all the faces</div><div>    faceId.InsertNextId(len(face)) # Number of points in face</div><div>    [faceId.InsertNextId(i) for i in face] # Insert the pointIds for the face</div><div><br></div><div><br></div><div>  ugrid = vtk.vtkUnstructuredGrid()</div><div>  ugrid.SetPoints(points)</div><div>  ugrid.InsertNextCell(vtk.VTK_POLYHEDRON, faceId)</div><div><br></div><div>  writer = vtk.vtkXMLUnstructuredGridWriter()</div><div>  writer.SetInput(ugrid)</div><div>  writer.SetFileName("polyhedron.vtu")</div><div>  writer.SetDataModeToAscii()</div><div>  writer.Update()</div></div></div><div>Code ends</div><div><br></div><div>The main difference is that the ugrid.InsertNextCells takes 2 arguments: type of cell and the vtkIdList of point Ids that make up the cell. For polyhedrons, the IdList has to contain information about the number faces that make up the cell and then the point Ids of the the faces. </div></div><div><br></div><div>I hope this helps,</div><div>Gudni </div></div><div class="gmail_extra"><br><div class="gmail_quote"><span class="">On 2 November 2014 13:33, George <span dir="ltr"><<a href="mailto:george.gerber@gmail.com" target="_blank">george.gerber@gmail.com</a>></span> wrote:<br></span><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Good day,<br>
<br>
I have translated the example of Bill into the best Python I know. I get the<br>
following error:<br>
Traceback (most recent call last):<br>
  File "C:\Users\george limited\Desktop\unstructuredgrid.py", line 19, in<br>
<module><br>
    ug.InsertNextCell(vtk.VTK_POLYHEDRON,4,pointids,1,faces)<br>
TypeError: InsertNextCell argument 5: expected a sequence of 0 values, got<br>
vtkobject<br>
<br>
Any advice will be very much appreciated.<br>
Best regards,<br>
George<br>
<br>
The code is:<br>
import vtk<br>
<br>
points = vtk.vtkPoints()<br>
pointids = [0,1,2,3]<br>
<br>
points.InsertNextPoint(0,0,0)<br>
points.InsertNextPoint(1,0,0)<br>
points.InsertNextPoint(1,1,0)<br>
points.InsertNextPoint(0,1,0)<br>
<br>
faces = vtk.vtkCellArray()<br>
<br>
face0 = [0,1,2,3]<br>
<br>
faces.InsertNextCell(4,face0)<br>
<br>
ug = vtk.vtkUnstructuredGrid()<br>
ug.SetPoints(points)<br>
ug.InsertNextCell(vtk.VTK_POLYHEDRON,4,pointids,1,faces.GetPointer())<span class=""><br>
<span><br>
writer = vtk.vtkUnstructuredGridWriter()<br>
writer.SetFileName("polyhedron.vtu")<br>
writer.SetInputData(ug)<br>
writer.Write()<br>
<br>
<br>
<br>
--<br>
</span></span>View this message in context: <a href="http://vtk.1045678.n5.nabble.com/polyhedron-in-python-tp5728643p5729319.html" target="_blank">http://vtk.1045678.n5.nabble.com/polyhedron-in-python-tp5728643p5729319.html</a><span class=""><br>
<div><div>Sent from the VTK - Users mailing list archive at Nabble.com.<br>
_______________________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://public.kitware.com/mailman/listinfo/vtkusers" target="_blank">http://public.kitware.com/mailman/listinfo/vtkusers</a><br>
</div></div></span></blockquote></div><span class="HOEnZb"><font color="#888888"><br><br clear="all"><div><br></div>-- <br><div dir="ltr"><div>Gudni Karl Rosenkjaer,</div><div>PhD student at Geophysical Inversion Facility</div><div>Department of Earth, Ocean and Atmospheric Sciences,</div><div>University of British Columbia</div></div>
</font></span></div>
</blockquote></div><br></div>