[vtkusers] VTK 3D Structured Grid Problem
Andrea Gavana
andrea.gavana at polymtl.ca
Wed Jul 7 12:48:37 EDT 2004
Hello NG,
I'm working with a 3D structured grid in VTK, using Python and the
wrapping vtkpython. What I do is as follows:
1) Using Fortran, via a Python-Fortran interface, I read a 3D grid coming from
another application. This 3D grid is now on a matrix with shape (8,nx*ny*nz),
every cell is identified by 8 coordinates (first index of the matrix) and I
have globally nx*ny*nz cells (second index of the matrix);
2) Using the pyvtk module, I write this matrix on a binary file;
3) I load the file using vtkStructuredGridReader().
So, my process is as follows:
# CODE BEGIN
vtks = VtkData(StructuredGrid([2*nx,2*ny,2*nz],MYMATRIX)
vtks.tofile('myfile','binary')
filename = 'myfile.vtk'
reader = vtkpython.vtkStructuredGridReader()
reader.SetFileName(filename)
mapsurface = vtkpython.vtkDataSetMapper()
mapsurface.SetInput(reader.GetOutput())
mapedge = vtkpython.vtkDataSetMapper()
mapedge.SetInput(reader.GetOutput())
# CODE END
Next I use the usual rendering/interacting command in order to display the 3D
grid. The problem is that I have A LOT of cells in my grid, so this process is
fairly slow...
Is there a way to create a VTKStructuredGrid object directly from a matrix
(without passing through a file)?
I've tried also this way:
# CODE BEGIN
pts = vtk.vtkPoints()
pts.SetNumberOfPoints(8*nx*ny*nz)
a = vtk.vtkStructuredGrid()
a.SetDimensions(2*nx,2*ny,2*nz)
idx = 0
for i in range(0,2*nz):
for j in range(0,2*ny):
for i in range(0,2*nx):
pts.SetPoint(idx, nanna[0,idx], nanna[1,idx], nanna[2,idx])
idx = idx + 1
a.SetPoints(pts)
mapsurface = vtk.vtkDataSetMapper()
meshGeom = vtk.vtkStructuredGridGeometryFilter()
meshGeom.SetInput(a)
meshGeom.SetExtent(0, nx-1, 0, ny-1, 0, nz-1)
mapsurface.SetInput(meshGeom.GetOutput())
actsurface = vtkpython.vtkActor()
actsurface.SetMapper(mapsurface)
# CODE END
But I get 2 problems:
1) Doing 3 for loops with a lot of cells is also slow (I can have also a
million cells)
2) The only thing I get is a 3D plot of the points, not a surface or a
wireframe, and I do not know why...
Is there anyone that can provide me a small piece of code to do it in Python?
I'm not really an expert on VTK/Python, I just started learning...
Thanks for every suggestion.
Andrea.
More information about the vtkusers
mailing list