I am curious about how the UI for existing plugins in Slicer is designed, specifically how the UI in the Segment Editor plugin is structured. For example, how is the thresholding interface (or similar new sub-interfaces) designed and implemented? Also, where exactly are these UI files stored in the source code?
I would like to review the source code for these UI interfaces in order to help me design the UI for my own plugin. Could you kindly guide me to the specific locations of these UI files within the Slicer source code?
thanks for your kind help!
I want to understand more about how the UI in 3D Slicer works in detail. Specifically, I’d like to know how the “apply” button functions, how sample data import is implemented in Python code, and how these components are connected. Are there efficient ways to help me better understand the purpose and usage of these functions?
My supervisor has asked me to implement a very simple plugin. The UI consists of a button to import sample data, a label to display the threshold value, a slider to adjust the threshold, and an “apply” button. Once the sample data is imported, it should automatically set a threshold suitable for the skull (using the first CT scan of the brain as an example). Clicking the “apply” button should display the corresponding model in the four-pane view.
My current idea is to extract the threshold processing code from the Segment Editor module and integrate it into my new plugin. However, this seems challenging since the Segment Editor is a complete and complex module. I’m having trouble identifying which parts of the code I can reuse and how to integrate them into a new plugin generated with Extension Wizard. My plugin is written in Python.
If anyone could provide some guidance, I would greatly appreciate it. I’m new to Slicer and want to understand its functionality better by creating my own plugin. I’d be thankful for any help or insights you can share.
I suggest you start by going through the developer tutorials, and use the Extension Wizard to make a sample module. It will give you a template with an Apply button and a place where you can put in custom image processing logic.
First, thank you for providing such a detailed and helpful tutorial on creating a custom 3D Slicer plugin. The step-by-step instructions have given me a good understanding of the relationships between different Slicer modules, and I appreciate your effort in putting this guide together.
However, while following the tutorial to create my first plugin using Python, I encountered some issues. I would be grateful for your insights on how to address them:
Missing updateGUIFromParameterNode Method
In the code generated by the Extension Wizard, the MASSWidget class (class MASSWidget(ScriptedLoadableModuleWidget, VTKObservationMixin)) does not contain the updateGUIFromParameterNode(self, caller=None, event=None) method referenced in the tutorial. Since the tutorial instructs replacing the body of this function, but it was missing entirely, I manually added the function.
Is this function still necessary in recent versions of 3D Slicer?
If it has been replaced by a different method, could you point me to an example or documentation for the current recommended approach?
AttributeError with getCenterOfMass Method
I added a markupsFiducialsNode according to the tutorial, but when running Reload & Test, I encountered the following error:
Traceback (most recent call last):
File "D:\Application\Slicer 5.6.2\bin\Python\slicer\util.py", line 3255, in tryWithErrorDisplay
yield
File "D:\Application\Slicer 5.6.2\bin\Python\slicer\ScriptedLoadableModule.py", line 265, in onReloadAndTest
test(msec=int(slicer.app.userSettings().value("Developer/SelfTestDisplayMessageDelay")), **kwargs)
File "D:\Application\Slicer 5.6.2\bin\Python\slicer\ScriptedLoadableModule.py", line 83, in runTest
testCase.runTest(**kwargs)
File "H:/SLICER_MODULE/MASS/MASS/MASS.py", line 363, in runTest
self.test_MASS1()
File "H:/SLICER_MODULE/MASS/MASS/MASS.py", line 399, in test_MASS1
logic.process(inputVolume, outputVolume, threshold, True)
File "H:/SLICER_MODULE/MASS/MASS/MASS.py", line 318, in process
self.centerOfMass = self.getCenterOfMass(inputMarkups)
File "H:/SLICER_MODULE/MASS/MASS/MASS.py", line 293, in getCenterOfMass
for i in range(markupsNode.GetNumberOfControlPoints()):
AttributeError: 'MRMLCorePython.vtkMRMLScalarVolumeNode' object has no attribute 'GetNumberOfControlPoints'
I understand this error indicates that markupsNode is treated as a vtkMRMLScalarVolumeNode rather than a vtkMRMLMarkupsFiducialNode. Could you help me understand what might cause this, and how I can ensure that markupsNode is correctly initialized as a vtkMRMLMarkupsFiducialNode?
3. Additional Questions
Are there significant changes in the newer versions of 3D Slicer that affect the tutorial code?
Is there an updated version of this tutorial or a similar guide compatible with 3D Slicer 5.6.2?
Thank you again for your guidance and the tutorial—it has been a great learning experience!
Good questions - this tutorial was created by the team at Queens, so I suspect they can reply. @lassoan@Sunderlandkyl probably know. It says it was created for version 5.6 so I’m sure it’s mostly correct, but there were some tweaks to parameter nodes and maybe the that changed the API used by the tutorial.
Fortunately they put the tutorial in a github repo, so you can report changes there and maybe even offer a pull request with an updated powerpoint.
Another issue I noticed is that the ppt didn’t get exported quite right to pdf.
The tutorial has not been fully updated after the parameter node wrapper updates. I’ve removed the obsolete parts now. Let us know if something does not work or unclear. I’ve also fixed the uploaded pdf.