VTK and Image Node

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

VTK and Image Node

manlio99
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)



--
View this message in context: http://slicer-devel.65872.n3.nabble.com/VTK-and-Image-Node-tp4038421.html
Sent from the slicer-devel mailing list archive at Nabble.com.
_______________________________________________
slicer-devel mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-devel
To unsubscribe: send email to [hidden email] with unsubscribe as the subject
http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/FAQ
Reply | Threaded
Open this post in threaded view
|

Re: VTK and Image Node

lasso2

You need to create a display node for your output volume node.

 

Andras

 

From: [hidden email]
Sent: Tuesday, April 4, 2017 3:26 PM
To: [hidden email]
Subject: [slicer-devel] VTK and Image Node

 

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)



--
View this message in context: http://slicer-devel.65872.n3.nabble.com/VTK-and-Image-Node-tp4038421.html
Sent from the slicer-devel mailing list archive at Nabble.com.
_______________________________________________
slicer-devel mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-devel
To unsubscribe: send email to [hidden email] with unsubscribe as the subject
http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/FAQ

_______________________________________________
slicer-devel mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-devel
To unsubscribe: send email to [hidden email] with unsubscribe as the subject
http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/FAQ