[vtkusers] programmable source multiple hexahedrons in unstructured grid - cell data not stored in paraview
Olivier Rodenberg
orodenberg at gmail.com
Tue Feb 23 03:52:26 EST 2016
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 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.
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?
Thanks in advance.
def DBMSToGeom(octree):
n=0
#Create the attribute
NodeLength = vtk.vtkDoubleArray()
NodeLength.SetName('Node length')
#create vtkpoints and vtkUnstructuredGrid()
points = vtk.vtkPoints()
octree_output = vtk.vtkUnstructuredGrid()
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.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
octant = vtk.vtkHexahedron()
for i in range(0, len(octree)):
octant.GetPointIds().SetId(i, n+i)
NodeLength.InsertNextValue(leafsize)
# Add the geometry to the unstructured grid
octree_output.InsertNextCell(octant.GetCellType(), octant.GetPointIds())
n+=8
# output all data
output.vtkUnstructuredGrid = octree_output
output.Allocate(len(octree),1)
output.Points = points
output.CellData.SetScalars(NodeLength)
if (__name__ == "__main__"):
DBMSToGeom(connectDBMS())
From: Favre Jean
Sent: maandag 22 februari 2016 21:49
To: Olivier Rodenberg; vtkusers at vtk.org
Subject: RE: [vtkusers] programmable source multiple hexahedrons inunstructured grid
I don't know the details of your app, but you should follow the following schema
I'll assume for simplicity, that the hexahedra do not share any vertices with any other hexahedra
if they do, then you need to figure out how to avoid replicating points.
# use "output", as the pre-defined vtkUnstructuredGrid created for you
# create a single vtkPoints and add all vertices to it
# if you have N hexahedra, you'll add 8xN points
# create a single vtkDoubleArray of size N
# offset the indices of each hexahedra by 8
points = vtk.vtkPoints()
#Create the attribute
NodeLength = vtk.vtkDoubleArray()
NodeLength.SetName('Node lenght')
I=0
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
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, 8*I+i)
NodeLength.InsertNextValue(leafsize)
# Add the geometry to the unstructured grid
output.InsertNextCell(hex_.GetCellType(), hex_.GetPointIds())
I = I +1
# Add the points and hexahedron to an unstructured grid
output.Points = points
output.CellData.SetScalars(NodeLength)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160223/decbb2d9/attachment-0001.html>
More information about the vtkusers
mailing list