[vtkusers] Proper Usage of the vtkStructuredGrid

Ada Som somada141 at yahoo.gr
Tue Oct 21 08:55:19 EDT 2008


Hi,

I am still trying to view my EM fields and I found it can be possible done with a vtkStructuredGrid.

The problem is that when I enter the points in the grid the resulting wireframe isn't correct.

Here is what I want to get :

http://utopia.duth.gr/~ak2432/what%20I%20want.png

and here is what I got :

http://utopia.duth.gr/~ak2432/what%20I%20got.png

The 1st pic is from an example where the user takes the x,y,z values from a file. The code is the following :



import vtk

renderer = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(renderer)
interactor = vtk.vtkRenderWindowInteractor()
interactor.SetRenderWindow(renWin)

renWin.SetSize(600, 600) 
renderer.SetBackground(1,1,1)   

grid = vtk.vtkStructuredGrid()
grid.SetDimensions(8,8,1)


points = vtk.vtkPoints()
scalars = vtk.vtkFloatArray()
i = 0
for line in file('xyz.dat'):
    x, y, z =  [float(val) for val in line.split()]
    scalars.InsertNextValue(float(i))
    points.InsertNextPoint(x,y,z)

    if i==0:
        # add a label for point 0
        text = vtk.vtkVectorText()
        text.SetText('0')
        textMapper = vtk.vtkPolyDataMapper()
        textMapper.SetInput(text.GetOutput())

        textActor = vtk.vtkFollower()
        textActor.SetMapper(textMapper)
        textActor.SetPosition(x, y, z)
        renderer.AddActor(textActor)


    i+=1
    
grid.SetPoints(points)
grid.GetPointData().SetScalars(scalars)

filter = vtk.vtkDataSetSurfaceFilter()
filter.SetInput(grid)

mapper = vtk.vtkPolyDataMapper()
mapper.SetInput(filter.GetOutput())

lut = vtk.vtkLookupTable()
lut.SetHueRange(0.667, 0.0)
mapper.SetLookupTable(lut)



surfActor = vtk.vtkActor()
surfActor.SetMapper(mapper)


property = surfActor.GetProperty()
property.SetRepresentationToSurface()
property.SetInterpolationToGouraud()

renderer.AddActor(surfActor)
mapper.SetScalarRange(0, 64)

interactor.Initialize()
interactor.Start()


What I want to do is have a 2D array of values and use those. Here is my code : 

import vtk

aa=Ex[:,:,2]
print aa
print aa.min(),aa.max()

renderer = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(renderer)
interactor = vtk.vtkRenderWindowInteractor()
interactor.SetRenderWindow(renWin)
renWin.SetSize(600, 600) 
renderer.SetBackground(1,1,1)   

grid = vtk.vtkStructuredGrid()
grid.SetDimensions(Ex.shape[0],Ex.shape[1],1)

points = vtk.vtkPoints()
scalars = vtk.vtkFloatArray()

#HERE I ADD THE VALUES
for i in xrange(Ex.shape[0]):
    for j in xrange(Ex.shape[1]):
        points.InsertNextPoint(i,j,Ex[i,j,2])
        scalars.InsertNextValue(Ex[i,j,2])
        


grid.SetPoints(points)
grid.GetPointData().SetScalars(scalars)
filter = vtk.vtkDataSetSurfaceFilter()
filter.SetInput(grid)
mapper = vtk.vtkPolyDataMapper()
mapper.SetInput(filter.GetOutput())
surfActor = vtk.vtkActor()
surfActor.SetMapper(mapper)



property = surfActor.GetProperty()
property.SetRepresentationToSurface()
property.SetInterpolationToPhong()
renderer.AddActor(surfActor)
mapper.SetScalarRange(aa.min(),aa.max())
interactor.Initialize()
interactor.Start()


As you can see I add the values by looping over the numpy array I have and add the value of z both as a scalar and a point coordinate so I will have sth like an surface and color mapping...

Can anyone help me out here? Thank you very much.

Adam



      
___________________________________________________________ 
Χρησιμοποιείτε Yahoo!; 
Βαρεθήκατε τα ενοχλητικά μηνύματα (spam); Το Yahoo! Mail 
διαθέτει την καλύτερη δυνατή προστασία κατά των ενοχλητικών 
μηνυμάτων http://login.yahoo.com/config/mail?.intl=gr 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20081021/94bf55a0/attachment.htm>


More information about the vtkusers mailing list