Skip to content

Instantly share code, notes, and snippets.

@jbvimort
Last active March 28, 2016 20:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbvimort/14abff80e87dd4c188aa to your computer and use it in GitHub Desktop.
Save jbvimort/14abff80e87dd4c188aa to your computer and use it in GitHub Desktop.
from __main__ import vtk, qt, ctk, slicer
from slicer.ScriptedLoadableModule import *
class dumyExtenction(ScriptedLoadableModule):
"""Uses ScriptedLoadableModule base class, available at:
https://github.com/Slicer/Slicer/blob/master/Base/Python/slicer/ScriptedLoadableModule.py
"""
def __init__(self, parent):
ScriptedLoadableModule.__init__(self, parent)
self.parent.title = "dumyExtenction" # TODO make this more human readable by adding spaces
self.parent.categories = ["Examples"]
self.parent.dependencies = []
self.parent.contributors = ["John Doe (AnyWare Corp.)"]
self.parent.helpText = """
This is an example of scripted loadable module bundled in an extension.
"""
self.parent.acknowledgementText = """
This file was originally developed by Jean-Christophe Fillion-Robin, Kitware Inc.
and Steve Pieper, Isomics, Inc. and was partially funded by NIH grant 3P41RR013218-12S1.
"""
class dumyExtenctionWidget(ScriptedLoadableModuleWidget):
def setup(self):
self.logic = dumyExtenctionLogic()
ScriptedLoadableModuleWidget.setup(self)
self.interactionNode = slicer.mrmlScene.GetNodeByID("vtkMRMLInteractionNodeSingleton")
self.currentFidList = None
self.currentTag = None
#
# Parameters Area
#
parametersCollapsibleButton = ctk.ctkCollapsibleButton()
parametersCollapsibleButton.text = "Parameters"
self.layout.addWidget(parametersCollapsibleButton)
parametersFormLayout = qt.QFormLayout(parametersCollapsibleButton)
inputMovingdLabel = qt.QLabel("FidList")
parametersFormLayout.addRow(inputMovingdLabel)
self.inputFidListSelector = slicer.qMRMLNodeComboBox()
self.inputFidListSelector.objectName = 'inputFidListSelector'
self.inputFidListSelector.nodeTypes = ['vtkMRMLMarkupsFiducialNode']
self.inputFidListSelector.selectNodeUponCreation = False
self.inputFidListSelector.addEnabled = True
self.inputFidListSelector.removeEnabled = False
self.inputFidListSelector.noneEnabled = True
self.inputFidListSelector.showHidden = False
self.inputFidListSelector.showChildNodeTypes = False
self.inputFidListSelector.setMRMLScene(slicer.mrmlScene)
parametersFormLayout.addRow(self.inputFidListSelector)
self.inputFidListSelector.connect('currentNodeChanged(vtkMRMLNode*)', self.onFidListChanged)
self.createMarkup = qt.QPushButton("Add markup")
self.createMarkup.enabled = True
parametersFormLayout.addRow(self.createMarkup)
self.createMarkup.connect('clicked(bool)', self.onAddMarkups)
self.replaceMarkups = qt.QPushButton("replace markups")
self.replaceMarkups.enabled = True
parametersFormLayout.addRow(self.replaceMarkups)
self.replaceMarkups.connect('clicked(bool)', self.onReplaceMarkups)
# Add vertical spacer
self.layout.addStretch(1)
def onFidListChanged(self):
fidList = self.inputFidListSelector.currentNode()
if self.currentFidList:
self.currentFidListlandmarks.RemoveObserver(self.currentTag)
self.currentFidListlandmarks = None
if fidList:
self.currentFidListlandmarks = fidList
self.currentTag = fidList.AddObserver(fidList.MarkupAddedEvent, self.onMarkupAddedEvent)
def onMarkupAddedEvent(self, obj, event):
numOfMarkups = obj.GetNumberOfMarkups()
landmarkCoord = [-1, -1, -1]
obj.GetNthFiducialPosition(numOfMarkups - 1, landmarkCoord)
print landmarkCoord
landmarkCoord = [numOfMarkups, numOfMarkups, numOfMarkups]
#obj.SetNthFiducialPositionFromArray(numOfMarkups - 1,landmarkCoord)
def onReplaceMarkups(self):
fidlist = self.inputFidListSelector.currentNode()
for i in range(0, fidlist.GetNumberOfMarkups()):
landmarkCoord = [-1, -1, -1]
fidlist.GetNthFiducialPosition(i, landmarkCoord)
print landmarkCoord
landmarkCoord = [i, i, i]
fidlist.SetNthFiducialPositionFromArray(i,landmarkCoord)
def onAddMarkups(self, signal):
# Add fiducial on the scene.
# If no input model selected, the addition of fiducial shouldn't be possible.
selectionNode = slicer.mrmlScene.GetNodeByID("vtkMRMLSelectionNodeSingleton")
selectionNode.SetReferenceActivePlaceNodeClassName("vtkMRMLMarkupsFiducialNode")
fidList = self.inputFidListSelector.currentNode()
if fidList:
selectionNode.SetActivePlaceNodeID(fidList.GetID())
self.interactionNode.SetCurrentInteractionMode(1)
else:
self.logic.warningMessage("Please select a fiducial list")
class dumyExtenctionLogic(ScriptedLoadableModuleLogic):
pass
class dumyExtenctionTest(ScriptedLoadableModuleTest):
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment