Nrrd vs vtp model coordinate systems in Python

Hello,

My model (.vtp) and image (.nrrd) align in slicer correctly. I am trying to use the model and image information in Python, but they do not visually align when plotted; they are in different coordinate systems (world vs physical)? Is there an easy way to convert the vtp mesh to align with the nrrd CT image in Python?

TLDR: what is the conversion that slicer does internally to a model to align it with a given reference image?

Thanks!

As an update - I was able to get it aligned by the following steps:

- mesh points are world coordinates in LPS

- NRRD image are in voxels

- slicer applies image origin and direction to mesh → converts mesh coordinates to voxel space?

- world → voxel: voxel=(mesh_points−origin)*inv(direction)/spacing

- shift mesh so image origin is (0,0,0)

- apply inverse of image direction

- convert physical to voxel indices (divide by spacing)

If I am using the mesh information inside a registration algorithm, should I do this conversion within Python?