<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:Courier;
        panose-1:2 7 4 9 2 2 5 2 4 4;}
@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;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri",sans-serif;}
@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><div class=WordSection1><p class=MsoNormal>Hi all,</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. </p><p class=MsoNormal>Each of the cubes has an own attribute value which will be used for colouring. </p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>The centre points, the edge lenth and the attribute value of the cubes are extracted from a PostgreSQL database via the python extension psycopg2. I am able to create a single hexahedron. However I am not able to add more geometries to an unstructured grid. The code that I am using is described bellow.  When running  the code I get the error “<span style='font-size:8.5pt;font-family:Courier;color:maroon'>TypeError: 'vtkCommonDataModelPython.vtkUnstructuredGrid' object is not iterable”. </span> I am not sure how to proceed. Is it even possible to create a unstructured grid? And does anyone know how I could store multiple geometries in an unstructured grid?</p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><i><span style='color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'>import psycopg2<o:p></o:p></span></i></p><p class=MsoNormal><i><span style='color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'><o:p> </o:p></span></i></p><p class=MsoNormal><i><span style='color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'>def connectDBMS():<o:p></o:p></span></i></p><p class=MsoNormal><i><span style='color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'>    conn = psycopg2.connect("host='localhost' dbname='thesis' user='postgres' password='Supermen1'")<o:p></o:p></span></i></p><p class=MsoNormal><i><span style='color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'>    cur = conn.cursor() <o:p></o:p></span></i></p><p class=MsoNormal><i><span style='color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'>    cur.execute('SELECT * FROM emptyspace limit 10;')                                                    <o:p></o:p></span></i></p><p class=MsoNormal><i><span style='color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'>    return  cur.fetchall()<o:p></o:p></span></i></p><p class=MsoNormal><i><span style='color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'><o:p> </o:p></span></i></p><p class=MsoNormal><i><span style='color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'>def DBMSToGeom(octree):<o:p></o:p></span></i></p><p class=MsoNormal><i><span style='color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'>    numberOfVertices = 8<o:p></o:p></span></i></p><p class=MsoNormal><i><span style='color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'><o:p> </o:p></span></i></p><p class=MsoNormal><i><span style='color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'>    # create the unstructured grid<o:p></o:p></span></i></p><p class=MsoNormal><i><span style='color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'>    octree = vtk.vtkUnstructuredGrid()<o:p></o:p></span></i></p><p class=MsoNormal><i><span style='color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'><o:p> </o:p></span></i></p><p class=MsoNormal><i><span style='color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'>    # Create the points<o:p></o:p></span></i></p><p class=MsoNormal><i><span style='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></i></p><p class=MsoNormal><i><span style='color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'><o:p> </o:p></span></i></p><p class=MsoNormal><i><span style='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></i></p><p class=MsoNormal><i><span style='color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'>        l = .5*leafsize<o:p></o:p></span></i></p><p class=MsoNormal><i><span style='color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'>        xL = int(x)-l<o:p></o:p></span></i></p><p class=MsoNormal><i><span style='color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'>        xR = int(x)+l        <o:p></o:p></span></i></p><p class=MsoNormal><i><span style='color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'>        yL = int(y)-l<o:p></o:p></span></i></p><p class=MsoNormal><i><span style='color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'>        yR = int(y)+l        <o:p></o:p></span></i></p><p class=MsoNormal><i><span style='color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'>        zL = int(z)-l<o:p></o:p></span></i></p><p class=MsoNormal><i><span style='color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'>        zR = int(z)+l<o:p></o:p></span></i></p><p class=MsoNormal><i><span style='color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'><o:p> </o:p></span></i></p><p class=MsoNormal><i><span style='color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'>        # create the points<o:p></o:p></span></i></p><p class=MsoNormal><i><span style='color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'>        points = vtk.vtkPoints()<o:p></o:p></span></i></p><p class=MsoNormal><i><span style='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></i></p><p class=MsoNormal><i><span style='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></i></p><p class=MsoNormal><i><span style='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></i></p><p class=MsoNormal><i><span style='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></i></p><p class=MsoNormal><i><span style='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></i></p><p class=MsoNormal><i><span style='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></i></p><p class=MsoNormal><i><span style='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></i></p><p class=MsoNormal><i><span style='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></i></p><p class=MsoNormal><i><span style='color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'><o:p> </o:p></span></i></p><p class=MsoNormal><i><span style='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></i></p><p class=MsoNormal><i><span style='color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'>        hex_ = vtk.vtkHexahedron()<o:p></o:p></span></i></p><p class=MsoNormal><i><span style='color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'>        for i in range(0, numberOfVertices):<o:p></o:p></span></i></p><p class=MsoNormal><i><span style='color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'>            hex_.GetPointIds().SetId(i, i)<o:p></o:p></span></i></p><p class=MsoNormal><i><span style='color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'><o:p> </o:p></span></i></p><p class=MsoNormal><i><span style='color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'>        #Create the attribute<o:p></o:p></span></i></p><p class=MsoNormal><i><span style='color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'>        NodeLength = vtk.vtkDoubleArray()<o:p></o:p></span></i></p><p class=MsoNormal><i><span style='color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'>        NodeLength.SetName('Node lenght')<o:p></o:p></span></i></p><p class=MsoNormal><i><span style='color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'>        NodeLength.InsertNextValue(leafsize)<o:p></o:p></span></i></p><p class=MsoNormal><i><span style='color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'><o:p> </o:p></span></i></p><p class=MsoNormal><i><span style='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></i></p><p class=MsoNormal><i><span style='color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'>        octree.InsertNextCell(hex_.GetCellType(), hex_.GetPointIds())<o:p></o:p></span></i></p><p class=MsoNormal><i><span style='color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'><o:p> </o:p></span></i></p><p class=MsoNormal><i><span style='color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'>    # Add the points and hexahedron to an unstructured grid<o:p></o:p></span></i></p><p class=MsoNormal><i><span style='color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'>    output.Allocate(1,1)<o:p></o:p></span></i></p><p class=MsoNormal><i><span style='color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'>    output.octree<o:p></o:p></span></i></p><p class=MsoNormal><i><span style='color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'>    output.Points = points<o:p></o:p></span></i></p><p class=MsoNormal><i><span style='color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'>    output.CellData.SetScalars(NodeLength)<o:p></o:p></span></i></p><p class=MsoNormal><i><span style='color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'><o:p> </o:p></span></i></p><p class=MsoNormal><i><span style='color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'>if (__name__ == "__main__"):<o:p></o:p></span></i></p><p class=MsoNormal><i><span style='color:#7F7F7F;mso-style-textfill-fill-color:#7F7F7F;mso-style-textfill-fill-alpha:100.0%'>    DBMSToGeom(connectDBMS())<o:p></o:p></span></i></p><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman",serif'><o:p> </o:p></span></p></div></body></html>