VTK and Image Node

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

VTK and Image Node

manlio99
This post has NOT been accepted by the mailing list yet.
Hi, I´m new to Slicer and I´m currently having some troubles when trying to render a VTK Image.
I have a VTK array, which I convert it to numpy, so i process it to obtain some parameters, and them convert it back to VTK. After that i want to show (render) the output VTK in Slicer. The problem is that I get empty images.

Could someone please help me? I don´t know where I have made a mistake.

My code goes as follows:


      input=self1.inputSelector.currentNode()
      output=self1.outputSelector.currentNode()
      SlicerInputData = input.GetImageData()
      vtk_data = SlicerInputData.GetPointData().GetScalars()
      numpy_data = numpy_support.vtk_to_numpy(vtk_data)
      dims = SlicerInputData.GetDimensions()
      numpy_data = numpy_data.reshape(dims[2], dims[1], dims[0])

      resultLLO0 = numpy_data
      vtk_data_array = numpy_support.numpy_to_vtk(num_array=resultLLO0.ravel(), deep=True)
     

      imgvtk = vtk.vtkImageData()
      imgvtk.AllocateScalars(vtk.VTK_UNSIGNED_CHAR, 1)
      imgvtk.SetDimensions(resultLLO0.shape)
      imgvtk.GetPointData().SetScalars(vtk_data_array)

      ijkToRAS = vtk.vtkMatrix4x4()
      ras2ijk = vtk.vtkMatrix4x4()

      input.GetIJKToRASMatrix(ijkToRAS)
      input.GetRASToIJKMatrix(ras2ijk)
      output.SetIJKToRASMatrix(ijkToRAS)
      output.SetRASToIJKMatrix(ras2ijk)
      output.SetAndObserveImageData(imgvtk)

      selectionNode = slicer.app.applicationLogic().GetSelectionNode()
      selectionNode.SetReferenceActiveVolumeID(output.GetID())
      slicer.app.applicationLogic().PropagateVolumeSelection(0)