Skip to content

Commit

Permalink
Adding support for named inputs in the json files
Browse files Browse the repository at this point in the history
  • Loading branch information
blowekamp committed Mar 3, 2015
1 parent eadd52e commit 625d941
Showing 1 changed file with 54 additions and 12 deletions.
66 changes: 54 additions & 12 deletions SimpleFilters/SimpleFilters.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,18 @@ def onApplyButton(self):

except:
self.currentStatusLabel.text = "Exception"

import sys
msg = sys.exc_info()[0]

# if there was an exception during start-up make sure to finish
self.onLogicRunStop()
# todo print exception
pass


qt.QMessageBox.critical(slicer.util.mainWindow(),
"Exception before execution of {0}".format(self.filterParameters.filter.GetName()),
msg)



def onCancelButton(self):
Expand Down Expand Up @@ -488,7 +496,11 @@ def run(self, filter, outputMRMLNode, outputLabelMap, *inputs):
inputImages = []

for i in inputs:
if i is None:
break

imgNodeName = i.GetName()

img = sitk.ReadImage(sitkUtils.GetSlicerITKReadWriteAddress(imgNodeName) )
inputImages.append(img)

Expand Down Expand Up @@ -550,19 +562,49 @@ def create(self, json):
#
# input volume selectors
#
for n in range(json["number_of_inputs"]):
if "inputs" in json:

w = self.createInputWidget(n)
# have named inputs
n=0
for input in json["inputs"]:

inputSelectorLabel = qt.QLabel("Input Volume: ")
self.widgets.append(inputSelectorLabel)
w = self.createInputWidget(n, noneEnabled=("optional" in input and input["optional"]))

# add to layout after connection
parametersFormLayout.addRow(inputSelectorLabel, w)
name = "Input Volume: "
if "name" in input:
name = "Input {0}: ".format(input["name"])
name = name.replace("Image", "Volume")

print "adding {1}: {0}".format(name,n)
inputSelectorLabel = qt.QLabel(name)
self.widgets.append(inputSelectorLabel)

# add to layout after connection
parametersFormLayout.addRow(inputSelectorLabel, w)

self.inputs.append(w.currentNode())

n+=1

if "number_of_inputs" in json and json["number_of_inputs"] != 0:
import sys
sys.stderr.write("Expected \"number_of_inputs\" to be 0 not {0}!".format(json["number_of_inputs"]))

else:

for n in range(json["number_of_inputs"]):

w = self.createInputWidget(n)

inputSelectorLabel = qt.QLabel("Input Volume: ")
self.widgets.append(inputSelectorLabel)

# add to layout after connection
parametersFormLayout.addRow(inputSelectorLabel, w)

self.inputs.append(w.currentNode())
self.inputs.append(w.currentNode())

#end for each input
#end for each input

if json["template_code_filename"] == "KernelImageFilter":
w = self.createVectorWidget("KernelRadius","std::vector<uint32_t>")
Expand Down Expand Up @@ -808,14 +850,14 @@ def create(self, json):
parametersFormLayout.addRow(outputLabelMapLabel, self.outputLabelMapBox)


def createInputWidget(self,n):
def createInputWidget(self,n, noneEnabled=False):
inputSelector = slicer.qMRMLNodeComboBox()
self.widgets.append(inputSelector)
inputSelector.nodeTypes = ( ("vtkMRMLScalarVolumeNode"), "" )
inputSelector.selectNodeUponCreation = True
inputSelector.addEnabled = False
inputSelector.removeEnabled = False
inputSelector.noneEnabled = False
inputSelector.noneEnabled = noneEnabled
inputSelector.showHidden = False
inputSelector.showChildNodeTypes = False
inputSelector.setMRMLScene( slicer.mrmlScene )
Expand Down

0 comments on commit 625d941

Please sign in to comment.