[vtkusers] programmable source multiple hexahedrons in unstructured grid

Nishad Sohoni ns451 at srcf.net
Mon Feb 22 16:04:35 EST 2016


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:

def DBMSToGeom(octree_in):
     numberOfVertices = 8

     # create the unstructured grid
     octree_out = vtk.vtkUnstructuredGrid()

     # Create the points
     for  materialpath, x , y , z , leafsize in octree_in:

         # Rest of loop #

     # Rest of function #


On 22/02/16 18:18, Olivier Rodenberg wrote:
>
> Hi all,
>
> I am trying to create a programmable filter where multiple(>1000) 
> cubes(hexahedrons) are stored in an unstructured grid.
>
> Each of the cubes has an own attribute value which will be used for 
> colouring.
>
> 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 
> “TypeError: 'vtkCommonDataModelPython.vtkUnstructuredGrid' object is 
> not iterable”.  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?
>
> /import psycopg2/
>
> //
>
> /def connectDBMS():/
>
> /conn = psycopg2.connect("host='localhost' dbname='thesis' 
> user='postgres' password='Supermen1'")/
>
> /cur = conn.cursor() /
>
> /    cur.execute('SELECT * FROM emptyspace limit 10;') /
>
> /    return  cur.fetchall()/
>
> //
>
> /def DBMSToGeom(octree):/
>
> /numberOfVertices = 8/
>
> //
>
> /# create the unstructured grid/
>
> /octree = vtk.vtkUnstructuredGrid()/
>
> //
>
> /# Create the points/
>
> /for  materialpath, x , y , z , leafsize in octree:/
>
> //
>
> /# create the coordinates for the points/
>
> /l = .5*leafsize/
>
> /xL = int(x)-l/
>
> /xR = int(x)+l /
>
> /        yL = int(y)-l/
>
> /yR = int(y)+l /
>
> /        zL = int(z)-l/
>
> /zR = int(z)+l/
>
> //
>
> /# create the points/
>
> / points = vtk.vtkPoints()/
>
> /points.InsertNextPoint(xL, yL, zL)/
>
> /points.InsertNextPoint(xR, yL, zL)/
>
> /points.InsertNextPoint(xR, yR, zL)/
>
> /points.InsertNextPoint(xL, yR, zL)/
>
> /points.InsertNextPoint(xL, yL, zR)/
>
> /points.InsertNextPoint(xR, yL, zR)/
>
> /points.InsertNextPoint(xR, yR, zR)/
>
> /points.InsertNextPoint(xL, yR, zR)/
>
> //
>
> /# Create a hexahedron from the points/
>
> /hex_ = vtk.vtkHexahedron()/
>
> /for i in range(0, numberOfVertices):/
>
> /hex_.GetPointIds().SetId(i, i)/
>
> //
>
> /#Create the attribute/
>
> /NodeLength = vtk.vtkDoubleArray()/
>
> /NodeLength.SetName('Node lenght')/
>
> /NodeLength.InsertNextValue(leafsize)/
>
> //
>
> /# Add the geometry to the unstructured grid/
>
> /octree.InsertNextCell(hex_.GetCellType(), hex_.GetPointIds())/
>
> //
>
> /# Add the points and hexahedron to an unstructured grid/
>
> /output.Allocate(1,1)/
>
> /output.octree/
>
> /output.Points = points/
>
> /output.CellData.SetScalars(NodeLength)/
>
> //
>
> /if (__name__ == "__main__"):/
>
> /DBMSToGeom(connectDBMS())/
>
>
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/vtkusers

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160222/f8947afd/attachment.html>


More information about the vtkusers mailing list