How to get line markup in real time?

I want to mark a certain section of blood vessels with some attribute. I thought I could draw line by Markup line widget to get the position of vessels. And read some value of attribues from ComboBox. Finally show the result to table viewer and can save the table with csv format. Some questions occured to me:

  1. How can I get Line Markup in real time? That’s means, if I draw a line in current data view, the coordinates of line’s two points can send to table viewer in time.
  2. How can I save the table data with csv format from table viewer ?

Many thanks.

  1. Add an observer to the markup node
    Example: https://www.slicer.org/wiki/Documentation/Nightly/Developers/Python_scripting#How_can_I_access_callData_argument_in_a_VTK_object_observer_callback_function
    Markup node events:
    https://apidocs.slicer.org/master/classvtkMRMLMarkupsNode.html#a14f8e398ba642299e120de065c0c7dd6a3f3703f43e61e8a3e411cc18278dfda1
  2. Get table model:
lm = slicer.app.layoutManager()
tw = lm.tableWidget(0)
tv = tw.tableView()
model = tv.tableModel()

Output to csv:

2 Likes

Thank you. @adamrankin
Follow your first advice, I add an observer(slicer.vtkMRMLMarkupsNode.PointModifiedEvent) to a vtkMRMLMarkupsLineNode. This can get Line’s two points position when draw a new line in the viewer. But this seem to only can get one line, and I want to get the newly drawn line continuously. Can I add an observer to a volume node that observe whether new vtkMRMLMarkupsLineNode is creating, and this will create a markup folder that contain all markup line node? And also all new LineNode is belong to the volume data, When I switch to another volume node, the observer will switch to a new markup folder.

About table, I found that 3D Slicer supports vtkMRMLTableNode. I realize that can solve my problem. Table can show in the viewer, and I can utilize the data node management in Slicer. There are new problems. How can I bind the table node to the markup folder mentioned above? This means that the table node will be updated when the makup folder changes.

Do you have any suggestions on these questions? Looking forward to your reply.