Exporting markups to LPS table and saving to text file?

Hello,

Is there a simple way to

  1. export a markups point list to a table in LPS in Python (rather than the GUI) and then
  2. saving that table as a .txt file?

I have another program that reads the lps text file and everything works well from the GUI but I would like to automate this step.

For step 1, I saw in the Slicer logic this function:

static bool ExportControlPointsToTable(vtkMRMLMarkupsNode* markupsNode, vtkMRMLTableNode* tableNode,
int coordinateSystem = vtkMRMLStorageNode::CoordinateSystemRAS);

I assume I first need to make a new table node, then run the above, but how do I change the coordinate system to LPS?

I saw a post for how to save markups to csv with

slicer.modules.markups.logic().ExportControlPointsToCSV(markupsNode, “/path/to/MyControlPoints.csv”)

but I prefer the txt export since I have my pipeline set up to read that.

Thank you,
Eva

@evaherbst
All of these should be doable, the question is what is the benefit you will be gaining by exporting the data in yet another format? Did you consider reading the JSON file directly (which already saves the coordinates in LPS)? Going forward you might find your workflow to be more robust if you avoid using these customs codes and outputs and go straight from JSON.

Did you try

int coordinateSystem = vtkMRMLStorageNode::CoordinateSystemLPS);

If this doesn’t work, and since you are building custom code, you can simply multiply the first to coordinates by -1 to convert RAS to LPS (or vice versa).

Thanks @muratmaga!

Solved.
I used:

markupsNode = slicer.util.getNode(“myNode”)

if not markupsNode:

raise ValueError(“Markups node not found”)

tableNode = slicer.mrmlScene.AddNewNodeByClass(“vtkMRMLTableNode”)

tableNode.SetName(markupsNode.GetName())

slicer.modules.markups.logic().ExportControlPointsToTable(markupsNode, tableNode, slicer.vtkMRMLStorageNode.CoordinateSystemLPS)

And then simply saved that table with the .txt extension

I did not want to use .mrk.json extension because my biomechanical model is in Java and I have a reader method that reads the .txt files.

1 Like

That is fine, but I highly recommend to develop your json reader instead. That will help you in the long-run both from data management perspective (what if you decide to add/revise new markups?) and data flow (you will have to re-export everything if you modify your dataset).

I have been in a similar situation, and did what you are doing right now which eventually became a burden.

Thanks @muratmaga for the advice, that is a good point.