[vtkusers] setting scalars on a vtkStructuredGrid

John Hunter jdhunter at ace.bsd.uchicago.edu
Thu Jan 15 14:04:34 EST 2004


I have a vtkStructuredGrid on which I am displaying scalar data with a
surface using vtkDataSetSurfaceFilter.  

For an MxN grid, I set the scalar data with 

   grid.GetPointData().SetScalars(scalars)

where scalars is a vtkScalars instance with MxN data points.

However, I have datasets where I am missing scalar data from some of
the points in the MxN grid, and so I want to set the scalar data on
the points where I have them and interpolate otherwise.

I've been reading the vtkDataSetAttributes documentation which
provides methods like InterpolatePoint that look helpful.  What I am
bumping up against right now is how to properly set the scalar data
for the known points on the grid.  The parent class vtkFieldData
provides SetComponent which looks relevant, but the docs say

  This method should not be used if the instance is from a subclass of
  vtkFieldData (vtkPointData or vtkCellData)

I don't believe and of the SetTuple methods are available to me in the
python wrapper.  Should I just go with SetComponent?

Below is some example code I have been using for the case where all
M*N scalar values are known.

Thanks!
John Hunter


    grid = vtk.vtkStructuredGrid()
    grid.SetDimensions(numrows, numcols, 1)
    points = vtk.vtkPoints()

    for xyz in locations:
        points.InsertNextPoint(*xyz)
    grid.SetPoints(points)

    scalars = vtk.vtkFloatArray()
    for val in values:
        scalars.InsertNextValue(val)            
    grid.GetPointData().SetScalars(scalars)


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

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





More information about the vtkusers mailing list