<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;">Hi,<br><br>I am still trying to view my EM fields and I found it can be possible done with a vtkStructuredGrid.<br><br>The problem is that when I enter the points in the grid the resulting wireframe isn't correct.<br><br>Here is what I want to get :<br><br><a href="http://utopia.duth.gr/%7Eak2432/what%20I%20want.png">http://utopia.duth.gr/~ak2432/what%20I%20want.png</a><br><br>and here is what I got :<br><br><a href="http://utopia.duth.gr/%7Eak2432/what%20I%20got.png">http://utopia.duth.gr/~ak2432/what%20I%20got.png</a><br><br>The 1st pic is from an example where the user takes the x,y,z values from a file. The code is the following :<br><br><br><br>import vtk<br><br>renderer = vtk.vtkRenderer()<br>renWin = vtk.vtkRenderWindow()<br>renWin.AddRenderer(renderer)<br>interactor =
vtk.vtkRenderWindowInteractor()<br>interactor.SetRenderWindow(renWin)<br><br>renWin.SetSize(600, 600) <br>renderer.SetBackground(1,1,1) <br><br>grid = vtk.vtkStructuredGrid()<br>grid.SetDimensions(8,8,1)<br><br><br>points = vtk.vtkPoints()<br>scalars = vtk.vtkFloatArray()<br>i = 0<br>for line in file('xyz.dat'):<br> x, y, z = [float(val) for val in line.split()]<br> scalars.InsertNextValue(float(i))<br> points.InsertNextPoint(x,y,z)<br><br> if i==0:<br> # add a label for point 0<br> text = vtk.vtkVectorText()<br> text.SetText('0')<br> textMapper = vtk.vtkPolyDataMapper()<br>
textMapper.SetInput(text.GetOutput())<br><br> textActor = vtk.vtkFollower()<br> textActor.SetMapper(textMapper)<br> textActor.SetPosition(x, y, z)<br> renderer.AddActor(textActor)<br><br><br> i+=1<br> <br>grid.SetPoints(points)<br>grid.GetPointData().SetScalars(scalars)<br><br>filter = vtk.vtkDataSetSurfaceFilter()<br>filter.SetInput(grid)<br><br>mapper = vtk.vtkPolyDataMapper()<br>mapper.SetInput(filter.GetOutput())<br><br>lut = vtk.vtkLookupTable()<br>lut.SetHueRange(0.667, 0.0)<br>mapper.SetLookupTable(lut)<br><br><br><br>surfActor = vtk.vtkActor()<br>surfActor.SetMapper(mapper)<br><br><br>property =
surfActor.GetProperty()<br>property.SetRepresentationToSurface()<br>property.SetInterpolationToGouraud()<br><br>renderer.AddActor(surfActor)<br>mapper.SetScalarRange(0, 64)<br><br>interactor.Initialize()<br>interactor.Start()<br><br><br>What I want to do is have a 2D array of values and use those. Here is my code : <br><br>import vtk<br><br>aa=Ex[:,:,2]<br>print aa<br>print aa.min(),aa.max()<br><br>renderer = vtk.vtkRenderer()<br>renWin = vtk.vtkRenderWindow()<br>renWin.AddRenderer(renderer)<br>interactor = vtk.vtkRenderWindowInteractor()<br>interactor.SetRenderWindow(renWin)<br>renWin.SetSize(600, 600) <br>renderer.SetBackground(1,1,1) <br><br>grid = vtk.vtkStructuredGrid()<br>grid.SetDimensions(Ex.shape[0],Ex.shape[1],1)<br><br>points = vtk.vtkPoints()<br>scalars = vtk.vtkFloatArray()<br><br>#HERE I ADD THE VALUES<br>for i in xrange(Ex.shape[0]):<br> for j in
xrange(Ex.shape[1]):<br> points.InsertNextPoint(i,j,Ex[i,j,2])<br> scalars.InsertNextValue(Ex[i,j,2])<br> <br><br><br>grid.SetPoints(points)<br>grid.GetPointData().SetScalars(scalars)<br>filter = vtk.vtkDataSetSurfaceFilter()<br>filter.SetInput(grid)<br>mapper = vtk.vtkPolyDataMapper()<br>mapper.SetInput(filter.GetOutput())<br>surfActor = vtk.vtkActor()<br>surfActor.SetMapper(mapper)<br><br><br><br>property = surfActor.GetProperty()<br>property.SetRepresentationToSurface()<br>property.SetInterpolationToPhong()<br>renderer.AddActor(surfActor)<br>mapper.SetScalarRange(aa.min(),aa.max())<br>interactor.Initialize()<br>interactor.Start()<br><br><br>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...<br><br>Can anyone help me out here? Thank you very much.<br><br>Adam<br></td></tr></table><br>
<hr size=1><font size=-1 face=Arial>
Χρησιμοποιείτε Yahoo!<br>
Βαρεθήκατε τα ενοχλητικά μηνύ ματα (spam); Το Yahoo! Mail διαθέτει την καλύτερη δυνατή προστασία κατά των ενοχλητικών μηνυμάτων <br>
<a href="http://login.yahoo.com/config/mail?.intl=gr">http://login.yahoo.com/config/mail?.intl=gr</a> </font>