Convert .vtk file into nifti format

I have first created a vtkParametricEllipsoid (i.e. a surface mesh). I here used trimesh library since it contains a functionality to generate a 3D volume mesh by passing a surface mesh (for that they used gmsh library). And then used meshio library to convert back it into .vtk file. Now I want to convert this volumetric mesh into nifti format. How can I do that ? I here attached the generated volumetric mesh for your further reference.ref_volumetric_ellipsoid.vtk (3.9 MB)

For this, there is no need to go through all the trouble of volumetric mesh generation. You can directly fill a region specified by a polydata using vtkPolyDataToImageStencil.

For trivial shapes like an elliosoid you can also easily fill voxels of an image array directly, using an implicit modeling function. You don’t even need VTK, just numpy.

The reason I want to do this is to pass the output to a Finite Element tool as a solid ellipsoid and take the deformations by applying different boundary conditions and loads. Is there a way to convert this volumetric mesh into nifty since vtkPolyDataToImageStencil needs first converting the unstructured grid to a polydata ?

You can either extract the surface mesh using vtkGeometryFilter and use vtkPolyDataToImageStencil to that; or if you have different scalars in the FE mesh and want to have those values in the image then you can convert the mesh to image directly using vtkProbeFilter.

Note that Nifti image is only for brain MRI images. For general-purpose 3D image storage, I would recommend using Nrrd or MetaImage format.