本文整理汇总了Python中SegmentStatistics.SegmentStatisticsLogic.setParameterNode方法的典型用法代码示例。如果您正苦于以下问题:Python SegmentStatisticsLogic.setParameterNode方法的具体用法?Python SegmentStatisticsLogic.setParameterNode怎么用?Python SegmentStatisticsLogic.setParameterNode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SegmentStatistics.SegmentStatisticsLogic
的用法示例。
在下文中一共展示了SegmentStatisticsLogic.setParameterNode方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SegmentStatisticsWidget
# 需要导入模块: from SegmentStatistics import SegmentStatisticsLogic [as 别名]
# 或者: from SegmentStatistics.SegmentStatisticsLogic import setParameterNode [as 别名]
#.........这里部分代码省略.........
self.segmentationSelector.setCurrentNode(segmentationNode)
def cleanup(self):
if self.parameterNode and self.parameterNodeObserver:
self.parameterNode.RemoveObserver(self.parameterNodeObserver)
def onNodeSelectionChanged(self):
self.applyButton.enabled = (self.segmentationSelector.currentNode() is not None and
self.parameterNodeSelector.currentNode() is not None)
if self.segmentationSelector.currentNode():
self.outputTableSelector.baseName = self.segmentationSelector.currentNode().GetName() + ' statistics'
def onApply(self):
"""Calculate the label statistics
"""
if not self.outputTableSelector.currentNode():
newTable = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLTableNode")
self.outputTableSelector.setCurrentNode(newTable)
# Lock GUI
self.applyButton.text = "Working..."
self.applyButton.setEnabled(False)
slicer.app.processEvents()
# set up parameters for computation
self.logic.getParameterNode().SetParameter("Segmentation", self.segmentationSelector.currentNode().GetID())
if self.scalarSelector.currentNode():
self.logic.getParameterNode().SetParameter("ScalarVolume", self.scalarSelector.currentNode().GetID())
else:
self.logic.getParameterNode().UnsetParameter("ScalarVolume")
self.logic.getParameterNode().SetParameter("MeasurementsTable", self.outputTableSelector.currentNode().GetID())
# Compute statistics
self.logic.computeStatistics()
self.logic.exportToTable(self.outputTableSelector.currentNode())
# Unlock GUI
self.applyButton.setEnabled(True)
self.applyButton.text = "Apply"
self.logic.showTable(self.outputTableSelector.currentNode())
def onEditParameters(self, pluginName=None):
"""Open dialog box to edit plugin's parameters"""
if self.parameterNodeSelector.currentNode():
SegmentStatisticsParameterEditorDialog.editParameters(self.parameterNodeSelector.currentNode(),pluginName)
def addPluginOptionWidgets(self):
self.pluginEnabledCheckboxes = {}
self.parametersLayout.addRow(qt.QLabel("Enabled segment statistics plugins:"))
for plugin in self.logic.plugins:
checkbox = qt.QCheckBox(plugin.name+" Statistics")
checkbox.checked = True
checkbox.connect('stateChanged(int)', self.updateParameterNodeFromGui)
optionButton = qt.QPushButton("Options")
from functools import partial
optionButton.connect('clicked()',partial(self.onEditParameters, plugin.name))
editWidget = qt.QWidget()
editWidget.setLayout(qt.QHBoxLayout())
editWidget.layout().margin = 0
editWidget.layout().addWidget(checkbox, 0)
editWidget.layout().addStretch(1)
editWidget.layout().addWidget(optionButton, 0)
self.pluginEnabledCheckboxes[plugin.name] = checkbox
self.parametersLayout.addRow(editWidget)
# embed widgets for editing plugin' parameters
#for plugin in self.logic.plugins:
# pluginOptionsCollapsibleButton = ctk.ctkCollapsibleGroupBox()
# pluginOptionsCollapsibleButton.setTitle( plugin.name )
# pluginOptionsFormLayout = qt.QFormLayout(pluginOptionsCollapsibleButton)
# pluginOptionsFormLayout.addRow(plugin.optionsWidget)
# self.parametersLayout.addRow(pluginOptionsCollapsibleButton)
def onParameterSetSelected(self):
if self.parameterNode and self.parameterNodeObserver:
self.parameterNode.RemoveObserver(self.parameterNodeObserver)
self.parameterNode = self.parameterNodeSelector.currentNode()
if self.parameterNode:
self.logic.setParameterNode(self.parameterNode)
self.parameterNodeObserver = self.parameterNode.AddObserver(vtk.vtkCommand.ModifiedEvent,
self.updateGuiFromParameterNode)
self.updateGuiFromParameterNode()
def updateGuiFromParameterNode(self, caller=None, event=None):
if not self.parameterNode:
return
for plugin in self.logic.plugins:
pluginName = plugin.__class__.__name__
parameter = pluginName+'.enabled'
checkbox = self.pluginEnabledCheckboxes[plugin.name]
value = self.parameterNode.GetParameter(parameter)=='True'
if checkbox.checked!=value:
previousState = checkbox.blockSignals(True)
checkbox.checked = value
checkbox.blockSignals(previousState)
def updateParameterNodeFromGui(self):
if not self.parameterNode:
return
for plugin in self.logic.plugins:
pluginName = plugin.__class__.__name__
parameter = pluginName+'.enabled'
checkbox = self.pluginEnabledCheckboxes[plugin.name]
self.parameterNode.SetParameter(parameter, str(checkbox.checked))
示例2: SegmentStatisticsParameterEditorDialog
# 需要导入模块: from SegmentStatistics import SegmentStatisticsLogic [as 别名]
# 或者: from SegmentStatistics.SegmentStatisticsLogic import setParameterNode [as 别名]
class SegmentStatisticsParameterEditorDialog(qt.QDialog):
"""Dialog to edit parameters of segment statistics plugins.
Most users will only need to call the static method editParameters(...)
"""
@staticmethod
def editParameters(parameterNode, pluginName=None):
"""Executes a modal dialog to edit a segment statistics parameter node if a pluginName is specified, only
options for this plugin are displayed"
"""
dialog = SegmentStatisticsParameterEditorDialog(parent=None, parameterNode=parameterNode,
pluginName=pluginName)
return dialog.exec_()
def __init__(self,parent=None, parameterNode=None, pluginName=None):
super(qt.QDialog,self).__init__(parent)
self.title = "Edit Segment Statistics Parameters"
self.parameterNode = parameterNode
self.pluginName = pluginName
self.logic = SegmentStatisticsLogic() # for access to plugins and editor widgets
self.logic.setParameterNode(self.parameterNode)
self.setup()
def setParameterNode(self, parameterNode):
"""Set the parameter node the dialog will operate on"""
if parameterNode==self.parameterNode:
return
self.parameterNode = parameterNode
self.logic.setParameterNode(self.parameterNode)
def setup(self):
self.setLayout(qt.QVBoxLayout())
self.descriptionLabel = qt.QLabel("Edit segment statistics plugin parameters:",0)
self.doneButton = qt.QPushButton("Done")
self.doneButton.toolTip = "Finish editing."
doneWidget = qt.QWidget(self)
doneWidget.setLayout(qt.QHBoxLayout())
doneWidget.layout().addStretch(1)
doneWidget.layout().addWidget(self.doneButton, 0)
parametersScrollArea = qt.QScrollArea(self)
self.parametersWidget = qt.QWidget(parametersScrollArea)
self.parametersLayout = qt.QFormLayout(self.parametersWidget)
self._addPluginOptionWidgets()
parametersScrollArea.setWidget(self.parametersWidget)
parametersScrollArea.widgetResizable = True
parametersScrollArea.setVerticalScrollBarPolicy(qt.Qt.ScrollBarAsNeeded )
parametersScrollArea.setHorizontalScrollBarPolicy(qt.Qt.ScrollBarAsNeeded)
self.layout().addWidget(self.descriptionLabel,0)
self.layout().addWidget(parametersScrollArea, 1)
self.layout().addWidget(doneWidget, 0)
self.doneButton.connect('clicked()', lambda: self.done(1))
def _addPluginOptionWidgets(self):
description = "Edit segment statistics plugin parameters:"
if self.pluginName:
description = "Edit "+self.pluginName+" plugin parameters:"
self.descriptionLabel.text = description
if self.pluginName:
for plugin in self.logic.plugins:
if plugin.name==self.pluginName:
self.parametersLayout.addRow(plugin.optionsWidget)
else:
for plugin in self.logic.plugins:
pluginOptionsCollapsibleButton = ctk.ctkCollapsibleGroupBox(self.parametersWidget)
pluginOptionsCollapsibleButton.setTitle( plugin.name )
pluginOptionsFormLayout = qt.QFormLayout(pluginOptionsCollapsibleButton)
pluginOptionsFormLayout.addRow(plugin.optionsWidget)
self.parametersLayout.addRow(pluginOptionsCollapsibleButton)