I have a segmentation, in a 3D numpy.ndarray, which I would like to render into VTK. [See here similar process here: https://pyscience.wordpress.com/2014/11/16/volume-rendering-with-python-and-vtk/ by@somada141]
My current (ad-hoc) solution includes: (1) Save the NumPy array to a Nifiti file with nib. Nifti1Image (2) Load the Nifiti file into vtk with (vtkNIFTIImageReader()) (3) Render the surface with vtkDiscreteMarchingCubes()
My question: How can I convert this 3D NumPy array directly into VTK without the intermediate file.
You can use the module numpy_support( https://github.com/Kitware/VTK/blob/master/Wrapping/Python/vtk/util/numpy_support.py) or the new vtk datasetadapter http://www.paraview.org/ParaView3/Doc/Nightly/www/py-doc/paraview.vtk.numpy_interface.dataset_adapter.html , http://kitware.com/blog/home/post/709
For an example of the first solution see https://pyscience.wordpress.com/2014/09/06/numpy-to-vtk-converting-your-numpy-arrays-to-vtk-arrays-and-files/
Actually while I was looking for an example I found also http://www.vtk.org/Wiki/VTK/Examples/Python/vtkWithNumpy, which I never tried before!