<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=utf-8"><meta name=Generator content="Microsoft Word 15 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:Tahoma;
panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:#954F72;
text-decoration:underline;}
.MsoChpDefault
{mso-style-type:export-only;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:70.85pt 70.85pt 70.85pt 70.85pt;}
div.WordSection1
{page:WordSection1;}
--></style></head><body lang=NL link=blue vlink="#954F72"><div class=WordSection1><p class=MsoNormal>Hi all,<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>I am trying to create a programmable filter where multiple(>1000) cubes(hexahedrons) are stored in an unstructured grid. <o:p></o:p></p><p class=MsoNormal>Each of the cubes has an own attribute value which will be used for colouring. <o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>The centre points, the edge length and the attribute value of each cubes is extracted from a PostgreSQL database via the python extension psycopg2. In the code I created all writes all points and attributes to paraview, but the actual cell data is not. Each time I try to view the cell data in the spreadsheetview Paraview stops working. </p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>To store the hexahedron data I create a vtkUnstructuredGrid and write all cell data to this grid. Finally I use the output.vtkUnstructuredGrid to writethe grid in the output. The code I use is described bellow. Does anyone know why my cell data is not stored and why paraview keeps stalling?</p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Thanks in advance.</p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><em><span style='font-family:"Calibri",sans-serif;color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'>def DBMSToGeom(octree):<o:p></o:p></span></em></p><p class=MsoNormal><em><span style='font-family:"Calibri",sans-serif;color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'> n=0<o:p></o:p></span></em></p><p class=MsoNormal><em><span style='font-family:"Calibri",sans-serif;color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'><o:p> </o:p></span></em></p><p class=MsoNormal><em><span style='font-family:"Calibri",sans-serif;color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'> #Create the attribute<o:p></o:p></span></em></p><p class=MsoNormal><em><span style='font-family:"Calibri",sans-serif;color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'> NodeLength = vtk.vtkDoubleArray()<o:p></o:p></span></em></p><p class=MsoNormal><em><span style='font-family:"Calibri",sans-serif;color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'> NodeLength.SetName('Node length')<o:p></o:p></span></em></p><p class=MsoNormal><em><span style='font-family:"Calibri",sans-serif;color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'><o:p> </o:p></span></em></p><p class=MsoNormal><em><span style='font-family:"Calibri",sans-serif;color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'> #create vtkpoints and vtkUnstructuredGrid()<o:p></o:p></span></em></p><p class=MsoNormal><em><span style='font-family:"Calibri",sans-serif;color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'> points = vtk.vtkPoints()<o:p></o:p></span></em></p><p class=MsoNormal><em><span style='font-family:"Calibri",sans-serif;color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'> octree_output = vtk.vtkUnstructuredGrid()<o:p></o:p></span></em></p><p class=MsoNormal><em><span style='font-family:"Calibri",sans-serif;color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'><o:p> </o:p></span></em></p><p class=MsoNormal><em><span style='font-family:"Calibri",sans-serif;color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'> for materialpath, x , y , z , leafsize in octree:<o:p></o:p></span></em></p><p class=MsoNormal><em><span style='font-family:"Calibri",sans-serif;color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'> # create the coordinates for the points<o:p></o:p></span></em></p><p class=MsoNormal><em><span style='font-family:"Calibri",sans-serif;color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'> l = .5*leafsize<o:p></o:p></span></em></p><p class=MsoNormal><em><span style='font-family:"Calibri",sans-serif;color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'> xL = int(x)-l<o:p></o:p></span></em></p><p class=MsoNormal><em><span style='font-family:"Calibri",sans-serif;color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'> xR = int(x)+l <o:p></o:p></span></em></p><p class=MsoNormal><em><span style='font-family:"Calibri",sans-serif;color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'> yL = int(y)-l<o:p></o:p></span></em></p><p class=MsoNormal><em><span style='font-family:"Calibri",sans-serif;color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'> yR = int(y)+l <o:p></o:p></span></em></p><p class=MsoNormal><em><span style='font-family:"Calibri",sans-serif;color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'> zL = int(z)-l<o:p></o:p></span></em></p><p class=MsoNormal><em><span style='font-family:"Calibri",sans-serif;color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'> zR = int(z)+l<o:p></o:p></span></em></p><p class=MsoNormal><em><span style='font-family:"Calibri",sans-serif;color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'> <o:p></o:p></span></em></p><p class=MsoNormal><em><span style='font-family:"Calibri",sans-serif;color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'> # create the points<o:p></o:p></span></em></p><p class=MsoNormal><em><span style='font-family:"Calibri",sans-serif;color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'> points.InsertNextPoint(xL, yL, zL)<o:p></o:p></span></em></p><p class=MsoNormal><em><span style='font-family:"Calibri",sans-serif;color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'> points.InsertNextPoint(xR, yL, zL)<o:p></o:p></span></em></p><p class=MsoNormal><em><span style='font-family:"Calibri",sans-serif;color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'> points.InsertNextPoint(xR, yR, zL)<o:p></o:p></span></em></p><p class=MsoNormal><em><span style='font-family:"Calibri",sans-serif;color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'> points.InsertNextPoint(xL, yR, zL)<o:p></o:p></span></em></p><p class=MsoNormal><em><span style='font-family:"Calibri",sans-serif;color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'> points.InsertNextPoint(xL, yL, zR)<o:p></o:p></span></em></p><p class=MsoNormal><em><span style='font-family:"Calibri",sans-serif;color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'> points.InsertNextPoint(xR, yL, zR)<o:p></o:p></span></em></p><p class=MsoNormal><em><span style='font-family:"Calibri",sans-serif;color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'> points.InsertNextPoint(xR, yR, zR)<o:p></o:p></span></em></p><p class=MsoNormal><em><span style='font-family:"Calibri",sans-serif;color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'> points.InsertNextPoint(xL, yR, zR)<o:p></o:p></span></em></p><p class=MsoNormal><em><span style='font-family:"Calibri",sans-serif;color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'><o:p> </o:p></span></em></p><p class=MsoNormal><em><span style='font-family:"Calibri",sans-serif;color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'> # Create a hexahedron from the points<o:p></o:p></span></em></p><p class=MsoNormal><em><span style='font-family:"Calibri",sans-serif;color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'> octant = vtk.vtkHexahedron()<o:p></o:p></span></em></p><p class=MsoNormal><em><span style='font-family:"Calibri",sans-serif;color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'> for i in range(0, len(octree)):<o:p></o:p></span></em></p><p class=MsoNormal><em><span style='font-family:"Calibri",sans-serif;color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'> octant.GetPointIds().SetId(i, n+i)<o:p></o:p></span></em></p><p class=MsoNormal><em><span style='font-family:"Calibri",sans-serif;color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'><o:p> </o:p></span></em></p><p class=MsoNormal><em><span style='font-family:"Calibri",sans-serif;color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'> NodeLength.InsertNextValue(leafsize)<o:p></o:p></span></em></p><p class=MsoNormal><em><span style='font-family:"Calibri",sans-serif;color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'> # Add the geometry to the unstructured grid<o:p></o:p></span></em></p><p class=MsoNormal><em><span style='font-family:"Calibri",sans-serif;color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'> octree_output.InsertNextCell(octant.GetCellType(), octant.GetPointIds())<o:p></o:p></span></em></p><p class=MsoNormal><em><span style='font-family:"Calibri",sans-serif;color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'> n+=8<o:p></o:p></span></em></p><p class=MsoNormal><em><span style='font-family:"Calibri",sans-serif;color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'><o:p> </o:p></span></em></p><p class=MsoNormal><em><span style='font-family:"Calibri",sans-serif;color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'> # output all data<o:p></o:p></span></em></p><p class=MsoNormal><em><span style='font-family:"Calibri",sans-serif;color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'> output.vtkUnstructuredGrid = octree_output<o:p></o:p></span></em></p><p class=MsoNormal><em><span style='font-family:"Calibri",sans-serif;color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'> output.Allocate(len(octree),1)<o:p></o:p></span></em></p><p class=MsoNormal><em><span style='font-family:"Calibri",sans-serif;color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'> output.Points = points<o:p></o:p></span></em></p><p class=MsoNormal><em><span style='font-family:"Calibri",sans-serif;color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'> output.CellData.SetScalars(NodeLength)<o:p></o:p></span></em></p><p class=MsoNormal><em><span style='font-family:"Calibri",sans-serif;color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'><o:p> </o:p></span></em></p><p class=MsoNormal><em><span style='font-family:"Calibri",sans-serif;color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'>if (__name__ == "__main__"):<o:p></o:p></span></em></p><p class=MsoNormal><em><span style='font-family:"Calibri",sans-serif;color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'> DBMSToGeom(connectDBMS())<o:p></o:p></span></em></p><p class=MsoNormal><o:p> </o:p></p><div style='mso-element:para-border-div;border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0cm 0cm 0cm'><p class=MsoNormal style='border:none;padding:0cm'><b>From: </b><a href="mailto:jfavre@cscs.ch">Favre Jean</a><br><b>Sent: </b>maandag 22 februari 2016 21:49<br><b>To: </b><a href="mailto:orodenberg@gmail.com">Olivier Rodenberg</a>; <a href="mailto:vtkusers@vtk.org">vtkusers@vtk.org</a><br><b>Subject: </b>RE: [vtkusers] programmable source multiple hexahedrons inunstructured grid</p></div><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman",serif'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Tahoma",sans-serif;color:black'>I don't know the details of your app, but you should follow the following schema<br>I'll assume for simplicity, that the hexahedra do not share any vertices with any other hexahedra<br>if they do, then you need to figure out how to avoid replicating points.<br><br># use "output", as the pre-defined vtkUnstructuredGrid created for you<o:p></o:p></span></p><div><div><div><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman",serif;color:black'># create a single vtkPoints and add all vertices to it<br># if you have N hexahedra, you'll add 8xN points<br># create a single vtkDoubleArray of size N<br># offset the indices of each hexahedra by 8</span><span style='font-size:12.0pt;font-family:"Times New Roman",serif;color:black'><o:p></o:p></span></p><p class=MsoNormal><span style='color:black'><o:p> </o:p></span></p><p class=MsoNormal><i><span style='color:#7F7F7F'> points = vtk.vtkPoints()</span></i><span style='color:black'><o:p></o:p></span></p><p class=MsoNormal><span style='color:black'><o:p> </o:p></span></p><p class=MsoNormal><i><span style='color:#7F7F7F'> #Create the attribute</span></i><span style='color:black'><o:p></o:p></span></p><p class=MsoNormal><i><span style='color:#7F7F7F'> NodeLength = vtk.vtkDoubleArray()</span></i><span style='color:black'><o:p></o:p></span></p><p class=MsoNormal><i><span style='color:#7F7F7F'> NodeLength.SetName('Node lenght')</span></i><span style='color:black'><o:p></o:p></span></p><p class=MsoNormal><i><span style='color:#7F7F7F'> I=0</span></i><span style='color:black'><o:p></o:p></span></p><p class=MsoNormal><i><span style='color:#7F7F7F'> for materialpath, x , y , z , leafsize in octree:</span></i><span style='color:black'><o:p></o:p></span></p><p class=MsoNormal><i><span style='color:#7F7F7F'> # create the coordinates for the points</span></i><span style='color:black'><o:p></o:p></span></p><p class=MsoNormal><i><span style='color:#7F7F7F'> l = .5*leafsize</span></i><span style='color:black'><o:p></o:p></span></p><p class=MsoNormal><i><span style='color:#7F7F7F'> xL = int(x)-l</span></i><span style='color:black'><o:p></o:p></span></p><p class=MsoNormal><i><span style='color:#7F7F7F'> xR = int(x)+l </span></i><span style='color:black'><o:p></o:p></span></p><p class=MsoNormal><i><span style='color:#7F7F7F'> yL = int(y)-l</span></i><span style='color:black'><o:p></o:p></span></p><p class=MsoNormal><i><span style='color:#7F7F7F'> yR = int(y)+l </span></i><span style='color:black'><o:p></o:p></span></p><p class=MsoNormal><i><span style='color:#7F7F7F'> zL = int(z)-l</span></i><span style='color:black'><o:p></o:p></span></p><p class=MsoNormal><i><span style='color:#7F7F7F'> zR = int(z)+l</span></i><span style='color:black'><o:p></o:p></span></p><p class=MsoNormal><i><span style='color:#7F7F7F'> </span></i><span style='color:black'><o:p></o:p></span></p><p class=MsoNormal><i><span style='color:#7F7F7F'> points.InsertNextPoint(xL, yL, zL)</span></i><span style='color:black'><o:p></o:p></span></p><p class=MsoNormal><i><span style='color:#7F7F7F'> points.InsertNextPoint(xR, yL, zL)</span></i><span style='color:black'><o:p></o:p></span></p><p class=MsoNormal><i><span style='color:#7F7F7F'> points.InsertNextPoint(xR, yR, zL)</span></i><span style='color:black'><o:p></o:p></span></p><p class=MsoNormal><i><span style='color:#7F7F7F'> points.InsertNextPoint(xL, yR, zL)</span></i><span style='color:black'><o:p></o:p></span></p><p class=MsoNormal><i><span style='color:#7F7F7F'> points.InsertNextPoint(xL, yL, zR)</span></i><span style='color:black'><o:p></o:p></span></p><p class=MsoNormal><i><span style='color:#7F7F7F'> points.InsertNextPoint(xR, yL, zR)</span></i><span style='color:black'><o:p></o:p></span></p><p class=MsoNormal><i><span style='color:#7F7F7F'> points.InsertNextPoint(xR, yR, zR)</span></i><span style='color:black'><o:p></o:p></span></p><p class=MsoNormal><i><span style='color:#7F7F7F'> points.InsertNextPoint(xL, yR, zR)</span></i><span style='color:black'><o:p></o:p></span></p><p class=MsoNormal><i><span style='color:#7F7F7F'> </span></i><span style='color:black'><o:p></o:p></span></p><p class=MsoNormal><i><span style='color:#7F7F7F'> # Create a hexahedron from the points</span></i><span style='color:black'><o:p></o:p></span></p><p class=MsoNormal><i><span style='color:#7F7F7F'> hex_ = vtk.vtkHexahedron()</span></i><span style='color:black'><o:p></o:p></span></p><p class=MsoNormal><i><span style='color:#7F7F7F'> for i in range(0, numberOfVertices):</span></i><span style='color:black'><o:p></o:p></span></p><p class=MsoNormal><i><span style='color:#7F7F7F'> hex_.GetPointIds().SetId(i, 8*I+i)</span></i><span style='color:black'><o:p></o:p></span></p><p class=MsoNormal><i><span style='color:#7F7F7F'> </span></i><span style='color:black'><o:p></o:p></span></p><p class=MsoNormal><i><span style='color:#7F7F7F'> NodeLength.InsertNextValue(leafsize)</span></i><span style='color:black'><o:p></o:p></span></p><p class=MsoNormal><i><span style='color:#7F7F7F'> </span></i><span style='color:black'><o:p></o:p></span></p><p class=MsoNormal><i><span style='color:#7F7F7F'> # Add the geometry to the unstructured grid</span></i><span style='color:black'><o:p></o:p></span></p><p class=MsoNormal><i><span style='color:#7F7F7F'> output.InsertNextCell(hex_.GetCellType(), hex_.GetPointIds())</span></i><span style='color:black'><o:p></o:p></span></p><p class=MsoNormal><i><span style='color:#7F7F7F'> I = I +1</span></i><span style='color:black'><o:p></o:p></span></p><p class=MsoNormal><span style='color:black'><o:p> </o:p></span></p><p class=MsoNormal><i><span style='color:#7F7F7F'> # Add the points and hexahedron to an unstructured grid</span></i><span style='color:black'><o:p></o:p></span></p><p class=MsoNormal><i><span style='color:#7F7F7F'> output.Points = points</span></i><span style='color:black'><o:p></o:p></span></p><p class=MsoNormal><i><span style='color:#7F7F7F'> output.CellData.SetScalars(NodeLength)</span></i><span style='color:black'><o:p></o:p></span></p><p class=MsoNormal><i><span style='color:#7F7F7F'> </span></i><span style='color:black'><o:p></o:p></span></p></div></div></div><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman",serif;color:black'> </span><span style='color:black'><o:p></o:p></span></p><p class=MsoNormal><o:p> </o:p></p></div></body></html>