marcomusy / vedo

A python module for scientific analysis of 3D data based on VTK and Numpy
https://vedo.embl.es
MIT License
2.05k stars 266 forks source link

Create a mesh from a volume object ? #330

Closed Benjamin-Fouquet closed 3 years ago

Benjamin-Fouquet commented 3 years ago

Hello there,

I am looking to create a mesh from a 3D MRI dataset in Nifti format. The dataset loads and is displayable without issue, but when I try to extract the mesh using getMeshes (), it returns an empty list. How could I create a mesh from the current Plotter object.

Sample code below if needed: from vedo import * import numpy as np

image = load ('path/of/my/file.nii')

cam = dict(pos=(113, -189, 62.1), focalPoint=(18.3, 4.39, 2.41), viewup=(-0.0708, 0.263, 0.962), distance=223, clippingRange=(74.3, 382))

plot = show (image, doc, bg='k', bg2='lg', axes=11, camera=cam)

mesh = plot.getMeshes ()

It's probably a silly thing from my side, so thanks in advance for any guidance provided.

marcomusy commented 3 years ago

Uhm what is s1 in your example? If you load a Volume then there are no meshes to get... unless you make some isosurface ...

Benjamin-Fouquet commented 3 years ago

edit: corrected the show to correctly take image argument.

The image is a Volume object from the nii file. Would the correct process be to first create isosurface from the volume, then get the mesh ? Would it be an option to retrieve a volume mesh as well ?

marcomusy commented 3 years ago

I'm not sure why you are trying to retrieve something that you already have in your hands :) What you call image is already a vedo.Volume object. Mesh are polygonal objects (made of vertices and triangle faces) - there is no "volume mesh". You can create a mesh from the Volume with e.g. mymesh = vol.isosurface() then you can visualize this mesh or save it check out the examples in https://vedo.embl.es/ (volumetric)

Let me know if you have more doubts

Benjamin-Fouquet commented 3 years ago

All good, thank you for your swift answer.