0

Some example how to do the task in the subject? Preferable in Python.

I suppose that .stl is 3D surface image and .mha are a 3D Volume (3 dimension array of pixels (compressed?)). Some processing must be done in the middle (fill inside the surface).

Thanks,

Luis Gonçalves

2 Answers2

1

You can check this example in vedo:

enter image description here

to save the volume add: write(v, 'vol.mhd')

mmusy
  • 1,292
  • 9
  • 10
  • How to convert a variable of the class vtkplotter.volume.Volume to a volume in VTK and also how to convert vtkplotter.mesh.Mesh to a mesh in VTK? Thanks. – Luis Gonçalves Mar 12 '20 at 15:33
  • They already are! try e.g. isinstance(vtkplotter.volume.Volume, vtk.vtkVolume) should give True Mesh is a vtkActor. You can get the vtk.vtkPolydata object with mesh.polydata() – mmusy Mar 12 '20 at 19:23
  • And if I want to convert the .stl to .mhd without volume fill? Only with the points of the surface. Are there some example? – Luis Gonçalves Mar 16 '20 at 15:07
  • MetaImage is only for volumetric data not polygonal data afaik. – mmusy Mar 16 '20 at 19:59
1

Also you could try using VTK's PolyDataToImageDataStencil filter. That's presumably what vtkplotter is using underneath.

Here's a Python example using vtkPolyDataToImageStencil: https://lorensen.github.io/VTKExamples/site/Python/PolyData/PolyDataToImageDataStencil/

And here is the documentation for the class: https://vtk.org/doc/nightly/html/classvtkPolyDataToImageStencil.html

Dave Chen
  • 1,905
  • 1
  • 12
  • 18