How to set data values on a vtkStructuredGrid

后端 未结 1 1455
日久生厌
日久生厌 2021-01-03 02:53

I\'m trying to fill in a structured grid with an analytical field, but despite reading the vtk docs, I haven\'t found out how to actually set scalar values at the grid point

相关标签:
1条回答
  • 2021-01-03 03:38

    In VTK there are 3 types of "structured" grids, vtkImageData (vtkUniformGrid derives from this), vtkRectilinearGrid, and vtkStructuredGrid. They are all structured in the sense that the topology is set. vtkImageData has constant spacing between points and is axis aligned, vtkRectilinearGrid is axis aligned but can vary the spacing in each axis direction, and vtkStructuredGrid has arbitrarily located points (cells may not be valid though).

    For what you want to do you should do:

    from vtk import *
    dx = 2.0
    grid = vtkImageData()
    grid.SetOrigin(0, 0, 0) # default values
    grid.SetSpacing(dx, dx, dx)
    grid.SetDimensions(5, 8, 10) # number of points in each direction
    # print grid.GetNumberOfPoints()
    # print grid.GetNumberOfCells()
    array = vtkDoubleArray()
    array.SetNumberOfComponents(1) # this is 3 for a vector
    array.SetNumberOfTuples(grid.GetNumberOfPoints())
    for i in range(grid.GetNumberOfPoints()):
        array.SetValue(i, 1)
    
    grid.GetPointData().AddArray(array)
    # print grid.GetPointData().GetNumberOfArrays()
    array.SetName("unit array")
    
    0 讨论(0)
提交回复
热议问题