Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a parameter set controller #132

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

chir-set
Copy link
Collaborator

GuidedVeinSegmentation

Using a single wrapped parameter node and multiple vtkMRMLScriptedModuleNode instances, each defining a parameter set.

At the same time, use the wrapped parameter node in logic.

@chir-set
Copy link
Collaborator Author

chir-set commented Oct 25, 2024

Hello @lassoan,

I request you opinion about this patch.

The goal is to add a parameter set node to most modules in SlicerVMTK where the
parameter node wrapper is being used.

The chosen method is as follows:

  • generate a single wrapped parameter node from the logic class
  • connect it once only
  • never replace this parameter node
  • reset it to default values when the scene is closed
  • generate vtkMRMLScriptedModuleNode instances from an MRML combobox
  • initialise the MRML parameter node with default values
  • when an MRML parameter node becomes active, update the wrapped parameter node accordingly (this updates the UI widgets)
  • when a UI widget is modified, update the active MRML parameter node.

This is not a formal pull request yet, I wish to read your thoughts about this.
It's the simplest effective approach I have found when the parameter node
wrapper is used in a module. The other solution would be to drop the wrapper,
but it's not where Slicer is going as I understand.

Thanks and regards.

@chir-set chir-set requested a review from lassoan October 25, 2024 13:37
@lassoan
Copy link
Contributor

lassoan commented Oct 25, 2024

Thanks for working on this! It would be greate to use parameter node in VMTK modules.

I would recommend to start from the latest version of the scripted module template: create a module by the same name as the existing module and copy over all the relevant code from the old version of the module. If you find anything wrong with the template we should fix the template.

@chir-set
Copy link
Collaborator Author

Thank you for your suggestion. After comparing the current module template (created a new module) and the GuidedVeinSegmentation module (which was created using that template at that time, i.e, with the parameter node wrapper), I consider that the module is conform to the current template.

The problem seems to be that a wrapped parameter node is never disconnected from the UI. As we add more wrapped parameter nodes, any UI interaction is propagated to all of them.

This code snippet illustrates this.

import GuidedVeinSegmentation
mainWindow().moduleSelector().selectModule('GuidedVeinSegmentation')

logic = getModuleLogic("GuidedVeinSegmentation")
widget = getModuleWidget("GuidedVeinSegmentation")

parameterNode = logic.getParameterNode() # A wrapped parameter node.

print("Logic generated parameter node:", parameterNode.shellMargin) # 18.0

scriptedModuleNode = slicer.vtkMRMLScriptedModuleNode()
additionalParameterNode = GuidedVeinSegmentation.GuidedVeinSegmentationParameterNode(scriptedModuleNode) # A wrapped parameter node.
widget.setParameterNode(additionalParameterNode)

print("Additional parameter node:", additionalParameterNode.shellMargin) # 18.0

print("---------", "Additional parameter node is current", "---------")
print("Setting value in additionalParameterNode")
additionalParameterNode.shellMargin = 16.5 # Or UI interaction
print("Logic generated parameter node:", parameterNode.shellMargin) # 16.5
print("Additional parameter node:", additionalParameterNode.shellMargin) # 16.5
print("         ---")
print("Setting value in parameterNode")
parameterNode.shellMargin = 10.2 # Or UI interaction
print("Logic generated parameter node:", parameterNode.shellMargin) # 10.2
print("Additional parameter node:", additionalParameterNode.shellMargin) # 10.2

print("---------", "Logic generated parameter node is current", "---------")
widget.setParameterNode(parameterNode)

print("Setting value in additionalParameterNode")
additionalParameterNode.shellMargin = 22.8 # Or UI interaction
print("Logic generated parameter node:", parameterNode.shellMargin) # 22.8
print("Additional parameter node:", additionalParameterNode.shellMargin) # 22.8
print("         ---")
print("Setting value in parameterNode")
parameterNode.shellMargin = 19.7 # Or UI interaction
print("Logic generated parameter node:", parameterNode.shellMargin) # 19.7
print("Additional parameter node:", additionalParameterNode.shellMargin) # 19.7

@lassoan
Copy link
Contributor

lassoan commented Oct 25, 2024

Please report this to the Slicer Forum - Development category, @mention Sam Horvath and Kyle Sunderland. We need to follow the template and if there are any issues or concerns then the template should be fixed.

GuidedVeinSegmentation

Using a single wrapped parameter node and multiple vtkMRMLScriptedModuleNode
instances, each defining a parameter set.

At the same time, use the wrapped parameter node in logic.
GuidedVeinSegmentation

Using a single wrapped parameter node and multiple vtkMRMLScriptedModuleNode
instances, each defining a parameter set.

At the same time, use the wrapped parameter node in logic.

This patch acknowledges the change in paradigm:
 - do not generate a vtkMRMLScriptedModuleNode parameter node from logic
 - do not generate a parameter node wrapper from logic
 - generate vtkMRMLScriptedModuleNode instances from the parameter set selector
 - wrap each instance
 - do not create a default parameter node in the selector
 - drop initializeParameterNode()
 - rely on a new parameterSetChanged() function rather
 - optionally use accessor get/set methods in logic
 - add a return statement in wrapper.py::_connectGui().
@chir-set chir-set force-pushed the ParameterSetSample branch from 327bee0 to 0d11f5a Compare January 6, 2025 19:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants