Loaded models are sometimes in different coordinate system, and sometimes not. What exactly is going on?

Operating system: Windows
Slicer version: 4.11.20210226
Expected behavior: A model should be loaded into a consistent coordinate system
Actual behavior: When I load some models, it appears to interpret the vertices as being in the RAS coordinate system. And for other models, it appears to use the world coordinates.

For example,

I have .vtu file. I load it up into 3d slicer. The x and y coordinates of all the vertices are flipped. I assume this is because the application is interpretting the vertex values to be in the RAS coordinates. No problem, I just apply a transformation [[-1,0,0,0, 0,-1,0,0, 0,0,1,0, 0,0,0,1]] and all is fine!

However, i have a .ply model too. When I load this model the application uses the actual coordinates of the vertices and it does not appear to be loaded in the RAS coordinate system, so I dont have to apply the transformation above to this model.

Why is there an inconsistency here?

How can I control which coordinate system a model’s vertices are interpreted to be in?

Thanks!

1 Like

If you know the model’s coordinate system, when loading expand the dialog box and specify whether it is LPS or RAS and your model should be imported correctly.

image

Inconsistency comes from the lack of standardization in those formats.

Thank you for the reply. I noticed this dialogue box, and I tested it by importing the same model twice but with the different options (LPS and RAS) chosen. There was no difference (and my model is definitely not symmetric about the x and y axes!)

1 Like

For VTU files, it actually works. I see a difference depending on the LPS / RAS option chosen in that dialogue box.

For my .ply file it does not work. There is no difference between RAS and LPS option

Ok, update:

It must be something weird with this specific .ply file. I just tried another .ply file and it worked…

Confirmed. The file must have been corrupted somehow. I loaded it up in paraview, and exported it to a new .ply file, and then tried it in slicer, and it works!

My last question on this topic, is how do I do this programtically in python when i load a model?

i’m using slicer.util.loadModel(…) function

You will need to use the slicer.util.loadNodeFromFile() function and specify this somehow in the properties.

slicer package — 3D Slicer documentation

slicer.util.loadModel() is a simplified wrapper for loadNodeFromFile() but lacks the ability to pass in properties. I couldn’t quickly find an example, but perhaps you can follow the code a bit deeper to find out what the property you want is and how to specify it: https://github.com/Slicer/Slicer/blob/10fc1df859fa094691e2358d6c0b420bce477700/Base/Python/slicer/util.py#L619

I cannot seem to locate it by following the python code.
I’m wondering if it is even possible.

I noticed this noted in one of the files:


  /// Coordinate system options
  /// LPS coordinate system is used the most commonly in medical image computing.
  ///   Slicer is moving towards using this coordinate system in all files by default
  ///   (while keep using RAS coordinate system internally).
  /// RAS coordinate system is used in Slicer internally. For many years, Slicer used
  ///   this coordinate system in files that it created, too.
  enum
  {
    CoordinateSystemRAS = 0,
    RAS = 0, ///< for backward compatibility
    CoordinateSystemLPS = 1,
    LPS = 1, ///< for backward compatibility
    CoordinateSystemType_Last
  };

from:

Found it! Check out here: https://github.com/Slicer/Slicer/blob/49320e0294eee6b0a471d97664f32aaaf31e5a17/Modules/Loadable/Models/qSlicerModelsReader.cxx#L118

The property is called “coordinateSystem” and the correct value is the integer 0 (for RAS) or 1 (for LPS). For these you could also use a more descriptively named enum.

An example of using properties for a different kind of node can be found here: Script repository — 3D Slicer documentation

So, properties are given as python dictionaries, where the key is the property name and the value is the property value.

1 Like