[vtkusers] How to use vtkStructuredGridGeometryFilter instead of a bunch of cubes

Somada141 somada141 at yahoo.gr
Sun Oct 26 03:50:49 EDT 2008


Hi all,

I am making an FDTD simulation program and at some point I want to plot the
mesh as created by the method. SInce it is an FDTD mesh it is a whole bunch
of cubes in space...

I am attaching a picture of it here :

http://utopia.duth.gr/~ak2432/L2%20-%2013Cuboids-FDTD-4203125.png
http://utopia.duth.gr/~ak2432/L2%20-%2013Cuboids-FDTD-4203125.png 

The problem is that when I do this I create a whole bunch of cube actors one
for each cube showing....However this can get really slow when it comes to
huge meshes....

I later found out that this can be done with a vtkStructuredGrid and
vtkStructuredGridGeometryFilter where I create a huge array of cubes and
blank out the ones I dont want shown...

However I cannot understand how to do this...here is an attempt which only
yields points instead of cube wireframes : 


from vtk import *

#Creating renderer,window,interactor - See the CMFViewer.py for comments on
how this is done properly. The code here is stuffed in order to save space.
renderer = vtkRenderer();renderer_window =
vtkRenderWindow();renderer_window.AddRenderer(renderer)
renderer_interactor =
vtkRenderWindowInteractor();renderer_interactor.SetRenderWindow(renderer_window)
renderer_window.SetSize(1024, 768);renderer.SetBackground(1,1,1)
interactor_style =
vtkInteractorStyleSwitch();renderer_interactor.SetInteractorStyle(interactor_style);interactor_style.SetCurrentStyleToTrackballCamera()

structured_grid = vtkStructuredGrid()
structured_grid.SetDimensions(3,3,3)

mesh_points = vtkPoints()
mesh_scalars = vtkFloatArray()

for i in range(3):
    for j in range(3):
        for k in range(3):
            mesh_points.InsertNextPoint(i,j,k)
            mesh_scalars.InsertNextValue(10*k)

structured_grid.SetPoints(mesh_points)
structured_grid.GetPointData().SetScalars(mesh_scalars)

#structured_grid.GetPointData().SetScalars(mesh_scalars)
surface_filter = vtkStructuredGridGeometryFilter()
surface_filter.SetInput(structured_grid)

polydata_mapper = vtkPolyDataMapper()
polydata_mapper.SetInput(surface_filter.GetOutput())

surfActor = vtkActor()
surfActor.SetMapper(polydata_mapper)

renderer.AddActor(surfActor)

renderer_interactor.Initialize()
renderer_window.Render()
renderer_interactor.Start()


Does anyone know where can I find a decent example of this filter or propose
a better way to do it? 

Thanks,
Adam
-- 
View this message in context: http://www.nabble.com/How-to-use-vtkStructuredGridGeometryFilter-instead-of-a-bunch-of-cubes-tp20171091p20171091.html
Sent from the VTK - Users mailing list archive at Nabble.com.




More information about the vtkusers mailing list