How to convert a .vtk mesh from LPS to RAS coordinates for proper alignment with NIfTI volumes in NiiVue?


Question:
I’m working with a .vtk surface mesh that was saved in LPS (Left-Posterior-Superior) coordinate space, and I want to overlay it correctly on a .nii.gz volume image in NiiVue, which uses RAS (Right-Anterior-Superior) coordinates.

Currently, when I try to display both in NiiVue, the mesh appears completely misaligned—likely due to the coordinate system mismatch.

My questions are:

  1. Is there a recommended way (in VTK or otherwise) to convert the .vtk mesh from LPS to RAS?
  2. Should this be handled manually with a transformation matrix, or is there a VTK-native method for this conversion?
  3. Alternatively, would it be more appropriate to preprocess the mesh in another tool like 3D Slicer, and if so, how?

Any guidance or best practices for handling this kind of coordinate transformation in VTK would be greatly appreciated!

Thanks!

It should be possible with vtkTransform and vtkTransformPolyDataFilter.

transform = vtkTransform()
transform.Scale(-1.0, -1.0, 1.0)

filter = vtkTransformPolyDataFilter()
filter.SetTransform(transform)
filter.SetInputData(...)

The LPS → RAS transform just reverses the L-R and A-P directions.