How to import STL as RAS coordinate system?

When I export a CT as STL and then re-import, the X and Y end up inverted.
This issue is fixed when I select the coordinate system as RAS:
image
But I’m looking to import this STL using a script.
I want to prevent the user to do it by itself, since it will always have to select RAS.
Is there a way to import STL as RAS only using script?
If I use loadModel, it imports as LPS by default.

How this mentioned header works?

  • STereoLithography (.stl): Format most commonly used for 3D printing. Default coordinate system: LPS. Coordinate system (LPS/RAS) can be specified in header.

I would not recommend using RAS coordinate system in any files. Slicer used to do this and it led to many compatibility issues, because the medical imaging community has pretty much agreed on using LPS coordinate system and millimeters as units (probably due to DICOM standard). Instead, you can invert the sign of the first two coordinates before writing to STL to have all the coordinates in LPS.

If you decide to stick to RAS coordinate system anyway, then make sure to include SPACE=RAS in the STL file header, in the comment field. Slicer recognizes this text and will interpret the coordinates as RAS.

You can specify coordinate system in the model file reader or in the Models module logic AddModel method, but the two other solutions that I described above are better, as they avoid hardcoding uncommon data conventions in your processing workflow.

1 Like

Thanks a lot, Andras!
To my case, it worked well to update the header, but I duly noted your recommendation.

1 Like