title: plot vtk vector component as color map
body: <p>I would like to generate a plot of a vtkUnstructuredGrid colored by a component of a vector. I can do this by reading the vtu-file produced by the code below in paraview, where I can select e.g. the y-component of the displacement vector. However, I can't figure out how to do this directly in the python script. By setting the variable 'component' equal to 0 I get the x-component, as expected. I can't seem to be able to select any other component for display.</p>
  
  <p>One possibility is probably by using a calculation filter and creating a new scalar array, but I'm sure there is a more straightforward way. Any help is greatly appreciated.</p>
  
  <pre><code>import vtk
  
  grid = vtk.vtkUnstructuredGrid()
  points = vtk.vtkPoints()
  cells = vtk.vtkCellArray()
  disp = vtk.vtkFloatArray()
  disp.SetNumberOfComponents(3)
  disp.SetName('displacement')
  
  N = 11
  delta = 10./(N-1)
  for kz in range(N):
      for ky in range(N):
          for kx in range(N):
              points.InsertNextPoint(kx*delta,ky*delta,kz*delta)
              disp.InsertNextTuple3(kx,kx*ky,ky**2+kz**2)
  grid.SetPoints(points)
  pdata = grid.GetPointData()
  pdata.AddArray(disp)
  
  inel = [0,1,N+1,N,N**2,N**2+1,N**2+N+1,N**2+N]
  for kz in range(N-1):
      for ky in range(N-1):
          for kx in range(N-1):
              anEle = vtk.vtkHexahedron()
              for kk in range(8):
                  anEle.GetPointIds().SetId(kk,inel[kk]+kx+N*ky+N**2*kz)
              cells.InsertNextCell(anEle)
  grid.SetCells(vtk.VTK_HEXAHEDRON,cells)
  
  if 1==11:
      writer = vtk.vtkXMLUnstructuredGridWriter();
      writer.SetDataModeToAscii()
      writer.SetFileName('bricks.vtu')
      writer.SetInput(grid)
      writer.Write()
  
  else:
      grid.GetPointData().SetActiveScalars('displacement')
  
      # create a rendering window and renderer
      ren = vtk.vtkRenderer()
      renWin = vtk.vtkRenderWindow()
      renWin.AddRenderer(ren)
  
      # create a renderwindowinteractor
      iren = vtk.vtkRenderWindowInteractor()
      iren.SetRenderWindow(renWin)
  
      # mapper
      mapper = vtk.vtkDataSetMapper()
      mapper.SetInput(grid)
      component = 1
      vrange = grid.GetPointData().GetArray(0).GetRange(component)
      mapper.SetScalarRange(vrange)
  
      # actor
      actor = vtk.vtkActor()
      actor.SetMapper(mapper)
      p=actor.GetProperty()
      p.SetEdgeVisibility(True)
  
      # assign actor to the renderer
      ren.AddActor(actor)
  
      #########################################################################
      #             Define view
      #########################################################################
      ViewSize = [1253, 817]
      CenterOfRotation = [5.0, 5.0, 5.0]
      CameraPosition = [23, 20, 30]
      CameraFocalPoint = [5,5,5]
      CameraViewUp = [0,1,0]
      CameraParallelScale = 9
      Background = [0.9,0.9,0.9]
  
      renWin.SetSize(ViewSize)
      camera = ren.GetActiveCamera()
      camera.SetFocalPoint(CenterOfRotation)
      camera.SetPosition(CameraPosition)
      camera.SetFocalPoint(CameraFocalPoint)
      camera.SetViewUp(CameraViewUp)
      camera.SetParallelScale(CameraParallelScale)
      ren.SetBackground(Background)
  
      #########################################################################
      #             Add color bar
      #########################################################################
      cmap = vtk.vtkDiscretizableColorTransferFunction()
      cmap.AddRGBPoint(vrange[0],1,0,0)
      cmap.AddRGBPoint(vrange[1],1,1,1)
      cmap.SetNumberOfValues(20)
      cmap.SetDiscretize(True)
      cmap.SetVectorModeToComponent()
      cmap.SetVectorComponent(component)
  
      mapper.SetLookupTable(cmap)
      scalarBar = vtk.vtkScalarBarActor()
      scalarBar.SetLookupTable(cmap)
      scalarBar.SetTitle('displacement')
      ren.AddActor2D(scalarBar)
  
  
      renderLarge = vtk.vtkWindowToImageFilter()
      renderLarge.SetInput(renWin)
      renderLarge.SetMagnification(4)
  
      writer = vtk.vtkPNGWriter()
      writer.SetInputConnection(renderLarge.GetOutputPort())
      writer.SetFileName('bricks.png')
      renWin.SetOffScreenRendering(True)
      renWin.Render()
      writer.Write()
  </code></pre>