Skip to content

Instantly share code, notes, and snippets.

Created September 21, 2017 13:17
What would you like to do?
Compute the total length between all the points of a markup list in 3D Slicer
from __main__ import qt, slicer
# MarkupsInfo module
class MarkupsInfo:
def __init__(self, parent):
import string
parent.title = "Markups info"
parent.categories = ["Informatics"]
parent.contributors = ["Andras Lasso (PerkLab)"]
parent.helpText = string.Template("""
Use this module to get information about markups. The only metric it computes now is the total distance between the markup points in the selected list.
""").substitute({ 'a':parent.slicerWikiUrl, 'b', 'c' })
parent.acknowledgementText = """
Supported by SparKit and the Slicer Community. See for details.
self.parent = parent
# Widget
class MarkupsInfoWidget:
def __init__(self, parent=None):
self.parent = parent
self.logic = None
def setup(self):
frame = qt.QFrame()
layout = qt.QFormLayout()
frame.setLayout( layout )
self.parent.layout().addWidget( frame )
# Markup selector
self.markupSelectorLabel = qt.QLabel()
self.markupSelectorLabel.setText( "Markup list: " )
self.markupSelector = slicer.qMRMLNodeComboBox()
self.markupSelector.nodeTypes = ( "vtkMRMLMarkupsFiducialNode", "" )
self.markupSelector.noneEnabled = False
self.markupSelector.selectNodeUponCreation = True
self.markupSelector.setMRMLScene( slicer.mrmlScene )
self.markupSelector.setToolTip( "Pick the markup list to be filled" )
layout.addRow(self.markupSelectorLabel, self.markupSelector)
# Apply button
self.computeButton = qt.QPushButton("Compute")
self.computeButton.toolTip = "Compute information for the selected markup"
# Results
self.totalDistanceLabel = qt.QLabel()
self.totalDistanceLabel.setText( "Total distance between fiducials (mm): " )
self.totalDistanceValue = qt.QLabel()
layout.addRow(self.totalDistanceLabel, self.totalDistanceValue)
# connections
self.computeButton.connect('clicked()', self.onCompute)
self.markupSelector.connect('currentNodeChanged(vtkMRMLNode*)', self.onMarkupSelect)
def UpdatecomputeButtonState(self):
if not self.markupSelector.currentNode() :
self.computeButton.enabled = False
self.computeButton.enabled = True
def onMarkupSelect(self, node):
def onCompute(self):
self.logic = MarkupsInfoLogic(self.markupSelector.currentNode())
# Logic
class MarkupsInfoLogic:
"""Implement the logic to compute markup info
Nodes are passed in as arguments.
Results are stored as 'info' instance variable.
def __init__(self, markupNode):{}
# Compute total distance between fiducials
startPtCoords = [0.0, 0.0, 0.0]
endPtCoords = [0.0, 0.0, 0.0]
for fidIndex in xrange(markupNode.GetNumberOfFiducials()-1):
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment