<html>
<head>
<meta content="text/html; charset=windows-1252"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
The TypeError seems to be because you use 'octree' as the input to
DBMSToGeom, but also as the new unstructured grid. Perhaps you
should do:<br>
<br>
<tt>def DBMSToGeom(octree_i</tt><tt>n</tt><tt>):</tt><tt><o:p></o:p></tt><tt><br>
</tt><tt> numberOfVertices = 8</tt><tt><br>
</tt><tt><o:p></o:p></tt><tt><br>
</tt><tt> # create the unstructured grid</tt><tt><o:p></o:p></tt><tt><br>
</tt><tt> octree_out = vtk.vtkUnstructuredGrid()</tt><tt><br>
</tt><tt><o:p></o:p></tt><tt><br>
</tt><tt> # Create the points</tt><tt><o:p></o:p></tt><tt><br>
</tt><tt> for materialpath, x , y , z , leafsize in octree_in:<br>
<br>
# Rest of loop #<br>
<br>
# Rest of function #<br>
</tt><br>
<br>
<div class="moz-cite-prefix">On 22/02/16 18:18, Olivier Rodenberg
wrote:<br>
</div>
<blockquote cite="mid:56cb50fd.016b1c0a.b4558.507f@mx.google.com"
type="cite">
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
<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>
<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>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
Powered by <a class="moz-txt-link-abbreviated" href="http://www.kitware.com">www.kitware.com</a>
Visit other Kitware open-source projects at <a class="moz-txt-link-freetext" href="http://www.kitware.com/opensource/opensource.html">http://www.kitware.com/opensource/opensource.html</a>
Please keep messages on-topic and check the VTK FAQ at: <a class="moz-txt-link-freetext" href="http://www.vtk.org/Wiki/VTK_FAQ">http://www.vtk.org/Wiki/VTK_FAQ</a>
Search the list archives at: <a class="moz-txt-link-freetext" href="http://markmail.org/search/?q=vtkusers">http://markmail.org/search/?q=vtkusers</a>
Follow this link to subscribe/unsubscribe:
<a class="moz-txt-link-freetext" href="http://public.kitware.com/mailman/listinfo/vtkusers">http://public.kitware.com/mailman/listinfo/vtkusers</a>
</pre>
</blockquote>
<br>
</body>
</html>