Difference between revisions of "Documentation/Nightly/Developers/Modules"

From Slicer Wiki
Jump to: navigation, search
m (Clean up scripted modules/Python links)
Tag: 2017 source edit
 
(10 intermediate revisions by 3 users not shown)
Line 1: Line 1:
<noinclude>{{documentation/versioncheck}}</noinclude>
+
<noinclude>{{documentation/versioncheck}}</noinclude><noinclude>
Slicer supports three types of modules. While the developer has to choose between one of the three types to implement its module, the end user won't notice the difference as they all share the same look & feel. The choice for a given type of module is usually based on the type of inputs/parameters for a given module.
 
  
= Command Line Interface (CLI) =
+
{{TOC left}}
CLIs are standalone executables with a limited input/output arguments complexity (simple argument types, no user interactions...). They are typically implemented using [http://www.itk.org ITK].
 
* Shared lib or executable
 
* UI automatically generated
 
* Where to start ?
 
# Create initial skeleton using the [[Documentation/{{documentation/version}}/Developers/ExtensionWizard|Extension Wizard]]
 
# Read [[Documentation/{{documentation/version}}/Developers/Build_Module|Compiling slicer modules outside of the slicer source tree.]]
 
# Learn from [http://viewvc.slicer.org/viewvc.cgi/Slicer4/trunk/Modules/CLI/ existing modules]
 
* Links:
 
** [[Documentation/{{documentation/version}}/Developers/SlicerExecutionModel|Slicer execution model]]
 
** [http://www.na-mic.org/Wiki/index.php/File:Slicer4_CLI.ppt CLI in Slicer4] (presentation of 2012 NAMIC AHM)
 
  
= Loadable Modules =
+
</noinclude>Slicer supports three types of modules: [[Documentation/{{documentation/version}}/Developers/Modules#Command_Line_Interface_.28CLI.29|Command Line Interface (CLI)]], [[Documentation/{{documentation/version}}/Developers/Modules#Loadable_Modules|Loadable Modules]] and [[Documentation/{{documentation/version}}/Developers/Modules#Scripted_Modules|Scripted Modules]].
 +
 
 +
While the developer has to choose between one of the three types to implement its module, the end user will <b>NOT</b> notice the difference as they all share the same look & feel.
 +
 
 +
The choice for a given type of module is usually based on the type of inputs/parameters for a given module.
 +
 
 +
<noinclude>{{Clear|left}}
 +
 
 +
=Command Line Interface (CLI)=
 +
CLIs are standalone executables with a limited input/output arguments complexity (simple argument types, no user interactions...). They are typically implemented in C++ (using [http://www.itk.org ITK]). Recent Slicer versions allow running (almost) any Python script as a CLI module by providing an interface description .xml file.
 +
 
 +
*Shared lib, executable, or Python script
 +
*UI automatically generated
 +
*Where to start ?
 +
 
 +
#Create initial skeleton using the [[Documentation/{{documentation/version}}/Developers/ExtensionWizard|Extension Wizard]]
 +
#Read [[Documentation/{{documentation/version}}/Developers/Build_Module|Compiling slicer modules outside of the slicer source tree.]]
 +
#Learn from [http://viewvc.slicer.org/viewvc.cgi/Slicer4/trunk/Modules/CLI/ existing modules]
 +
 
 +
*Links:
 +
**[[Documentation/{{documentation/version}}/Training#Developing_and_contributing_extensions_for_3D_Slicer|Developing and contributing extensions for 3D Slicer]]
 +
**[[Documentation/{{documentation/version}}/Developers/SlicerExecutionModel|Slicer execution model]]
 +
**[http://www.na-mic.org/Wiki/index.php/File:Slicer4_CLI.ppt CLI in Slicer4] (presentation of 2012 NAMIC AHM)
 +
**Example of [https://github.com/lassoan/SlicerPythonCLIExample CLI module implemented in Python]
 +
 
 +
=Loadable Modules=
 
Loadable modules are [http://en.wikipedia.org/wiki/C%2B%2B C++] plugins that are built against Slicer. They define custom GUIs for their specific behavior as they have full control over the application.
 
Loadable modules are [http://en.wikipedia.org/wiki/C%2B%2B C++] plugins that are built against Slicer. They define custom GUIs for their specific behavior as they have full control over the application.
* C++ shared library
+
 
* Full control over the UI (based on [http://qt.nokia.com/products/ Qt]) and Slicer internals (MRML, logics, display managers...)
+
*C++ shared library
* Optimized for heavy computations
+
*Full control over the UI (based on [http://qt.nokia.com/products/ Qt]) and Slicer internals (MRML, logics, display managers...)
* Where to start ?
+
*Optimized for heavy computations
# Create initial skeleton using the [[Documentation/{{documentation/version}}/Developers/ExtensionWizard|Extension Wizard]]
+
*Where to start ?
# Read [[Documentation/{{documentation/version}}/Developers/Build_Module|Compiling slicer modules outside of the slicer source tree.]]
+
 
# Learn from [http://viewvc.slicer.org/viewvc.cgi/Slicer4/trunk/Modules/Loadable/ existing modules]
+
#Create initial skeleton using the [[Documentation/{{documentation/version}}/Developers/ExtensionWizard|Extension Wizard]]
* Links:
+
#Read [[Documentation/{{documentation/version}}/Developers/Build_Module|Compiling slicer modules outside of the slicer source tree.]]
 +
#Learn from [http://viewvc.slicer.org/viewvc.cgi/Slicer4/trunk/Modules/Loadable/ existing modules]
 +
 
 +
*Links:
 +
**[[Documentation/{{documentation/version}}/Training#Developing_and_contributing_extensions_for_3D_Slicer|Developing and contributing extensions for 3D Slicer]]
 
**[http://www.na-mic.org/Wiki/index.php/File:LoadableModules.pptx Loadable modules] (presentation of 2012 NAMIC AHM)
 
**[http://www.na-mic.org/Wiki/index.php/File:LoadableModules.pptx Loadable modules] (presentation of 2012 NAMIC AHM)
 
**[[Documentation/{{documentation/version}}/Developers/Tutorials/CreateLoadableModule|How to write a loadable module]]
 
**[[Documentation/{{documentation/version}}/Developers/Tutorials/CreateLoadableModule|How to write a loadable module]]
  
= Scripted Modules =
+
=Scripted Modules=
 
Scripted modules are written in [http://www.python.org/ Python].  
 
Scripted modules are written in [http://www.python.org/ Python].  
  
 
An extensive tutorial and reference page was created [http://www.na-mic.org/Wiki/index.php/2013_Project_Week_Breakout_Session:Slicer4Python for the Slicer/Python breakout session at the NA-MIC 2014 Summer Project Week].  Please read through this and many of your questions will be answered.
 
An extensive tutorial and reference page was created [http://www.na-mic.org/Wiki/index.php/2013_Project_Week_Breakout_Session:Slicer4Python for the Slicer/Python breakout session at the NA-MIC 2014 Summer Project Week].  Please read through this and many of your questions will be answered.
  
Several tutorials for developers are available from the Slicer Training page: http://wiki.slicer.org/slicerWiki/index.php/Documentation/Nightly/Training#Tutorials_for_software_developers
+
Several tutorials for developers are available from the Slicer Training page: https://www.slicer.org/wiki/Documentation/Nightly/Training#Tutorials_for_software_developers
 
+
 
* Python Console
+
*Python Console
* Full access to the API: [http://www.vtk.org VTK], [http://qt.nokia.com/products/ Qt], [http://slicer.org/doc/html/annotated.html MRML and Slicer],[http://www.itk.org/SimpleITKDoxygen/html/classes.html SimpleITK] are fully wrapped
+
*Full access to the API: [http://www.vtk.org VTK], [http://qt.nokia.com/products/ Qt], [http://slicer.org/doc/html/annotated.html MRML and Slicer],[http://www.itk.org/SimpleITKDoxygen/html/classes.html SimpleITK] are fully wrapped
* Recommended for fast prototyping and custom workflow development
+
*Recommended for fast prototyping and custom workflow development
* Where to start?
+
*Where to start?
# Read the [http://www.na-mic.org/Wiki/index.php/2013_Project_Week_Breakout_Session:Slicer4Python Slicer/Python breakout session at the NA-MIC 2014 Summer Project Week] tutorial.
+
 
# Create initial skeleton using the [[Documentation/{{documentation/version}}/Developers/ExtensionWizard|Extension Wizard]]
+
#Read the [http://www.na-mic.org/Wiki/index.php/2013_Project_Week_Breakout_Session:Slicer4Python Slicer/Python breakout session at the NA-MIC 2014 Summer Project Week] tutorial.
# [http://1drv.ms/12dQ5vV Python scripted module design - beyond basics (role of widget, logic, MRML classes, using MRML node for storing module parameters, etc.)]
+
#Create initial skeleton using the [[Documentation/{{documentation/version}}/Developers/ExtensionWizard|Extension Wizard]]
# Learn from [http://viewvc.slicer.org/viewvc.cgi/Slicer4/trunk/Modules/Scripted/ existing modules]
+
#[[Media:SlicerModulesProgrammingBeyondBasics.pdf|Python scripted module design - beyond basics]]: role of widget, logic, MRML classes, using MRML node for storing module parameters, etc. (editable version: [[File:SlicerModulesProgrammingBeyondBasics.pptx]])
* More information:
+
#Learn from [http://viewvc.slicer.org/viewvc.cgi/Slicer4/trunk/Modules/Scripted/ existing modules]
** [[Documentation/{{documentation/version}}/Developers/Python_scripting|Python Scripting]]
+
 
** [[Documentation/{{documentation/version}}/Training#Slicer4_Programming_Tutorial|Python Scripting Tutorial]]
+
*More information:
** [[Documentation/{{documentation/version}}/ScriptRepository|Community contributed examples]]
+
**[[Documentation/{{documentation/version}}/Training#Developing_and_contributing_extensions_for_3D_Slicer|Developing and contributing extensions for 3D Slicer]]
** [[Documentation/{{documentation/version}}/Developers/Slicelets|Developing slicelets: standalone applications with simplified, fully customized user interface]]
+
**[[Documentation/{{documentation/version}}/Developers/Python_scripting|Python Scripting]]
 +
**[[Documentation/{{documentation/version}}/Training#Slicer4_Programming_Tutorial|Python Scripting Tutorial]]
 +
**[https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html Script repository]
 +
**[[Documentation/{{documentation/version}}/Developers/Slicelets|Developing slicelets: standalone applications with simplified, fully customized user interface]]
  
 
=Module Factory=
 
=Module Factory=
 
Loading modules into slicer happens in multiple steps:
 
Loading modules into slicer happens in multiple steps:
 +
 
*module factories must be registered into the factory manager
 
*module factories must be registered into the factory manager
* directories where the modules to load are located must be passed to the factory manager
+
*directories where the modules to load are located must be passed to the factory manager
* Optionally specify module names to ignore
+
*Optionally specify module names to ignore
* scan the directories and test which file is a module and register it (not instantiated yet)  
+
*scan the directories and test which file is a module and register it (not instantiated yet)
* Instantiate all the register modules
+
*Instantiate all the register modules
* Connect each module with the scene and the application
+
*Connect each module with the scene and the application
 +
 
 
More details can be found in the [http://slicer.org/doc/html/classqSlicerAbstractModuleFactoryManager.html online doc]
 
More details can be found in the [http://slicer.org/doc/html/classqSlicerAbstractModuleFactoryManager.html online doc]
  
==ToDo==
+
=Association of MRML nodes to modules=
* Transform all core modules into Loadable modules.
+
 
** the factory manager only support file based modules, core modules are not file based (linked into the core factory itself)
+
Modules can be associated with MRML nodes, which for example allows determining what module can be used to edit a certain MRML node. A module can either specify the list of node types that it supports by overriding [https://www.slicer.org/doc/html/classqSlicerAbstractCoreModule.html#a932cfab8cb00c2e770b95a97fce92670 qSlicerAbstractCoreModule::associatedNodeTypes()] method or a module can call [https://www.slicer.org/doc/html/classqSlicerCoreApplication.html#a748d8b0ab3914bded820337534a1aa76 qSlicerCoreApplication::addModuleAssociatedNodeTypes()] to associate any node type with any module.
* Move factory registration in qSlicerApplication (or a general application library) to support module discovery/loading without needing to instantiate Slicer.
+
 
** Currently can't be moved into qSlicerApplication as the CLI factories that are in QTCLI depend on QTGUI
+
Multiple modules can be associated with the same MRML node type. The best module for editing a specific node instance is determined run-time. The application framework calls [https://www.slicer.org/doc/html/classqSlicerAbstractModuleWidget.html#a8e1bdbc248688677af5cd91f0849d44e qSlicerAbstractModuleWidget::nodeEditable()] for each associated module candidate and will activate the one that has the highest confidence in handling the node.
** QtTesting is also limited with the QTCLI dependency on QtGUI (->qSlicerApplication would need to access QtTesting code from QtCli)
+
 
** Proposed architecture
+
To select a MRML node as the "active" or "edited" node in a module the module widget's [https://www.slicer.org/doc/html/classqSlicerAbstractModuleRepresentation.html#adfd05c2484d8cab8e3e9cda09e45d227 qSlicerAbstractModuleWidget::setEditedNode()] method is called.
 +
 
 +
=ToDo - Planned developments=
 +
 
 +
*Transform all core modules into Loadable modules.
 +
**the factory manager only support file based modules, core modules are not file based (linked into the core factory itself)
 +
*Move factory registration in qSlicerApplication (or a general application library) to support module discovery/loading without needing to instantiate Slicer.
 +
**Currently can't be moved into qSlicerApplication as the CLI factories that are in QTCLI depend on QTGUI
 +
**QtTesting is also limited with the QTCLI dependency on QtGUI (->qSlicerApplication would need to access QtTesting code from QtCli)
 +
**Proposed architecture
 +
 
 
  Base
 
  Base
 
   Application -> classes that are useful to build an application (mix of qSlicerCoreApplication, qSlicerApplication, Main.cxx...)
 
   Application -> classes that are useful to build an application (mix of qSlicerCoreApplication, qSlicerApplication, Main.cxx...)
Line 76: Line 109:
 
       Python
 
       Python
 
   Widgets -> formally QtGUI
 
   Widgets -> formally QtGUI
* Add category hierarchy in the Settings module panel
+
 
* Register factory settings/command-options(e.g. disable-loadable-modules) when registering module factories
+
*Add category hierarchy in the Settings module panel
** To have the settings panel be generic but have the code proper of each registered factory somewhere else
+
*Register factory settings/command-options(e.g. disable-loadable-modules) when registering module factories
* Add mechanism for modules to register dialogs (toolbars that open dialogs),  e.g. the sceneview module needs to register the sceneView dialog into an icon.
+
**To have the settings panel be generic but have the code proper of each registered factory somewhere else
* Ignore modules from the launcher command line.
+
*Add mechanism for modules to register dialogs (toolbars that open dialogs),  e.g. the sceneview module needs to register the sceneView dialog into an icon.
* cloning" of module panels at run time. See [http://massmail.spl.harvard.edu/public-archives/slicer-devel/2012/008965.html "here] and [http://massmail.spl.harvard.edu/public-archives/slicer-devel/2012/008039.html here]
+
*<s>Ignore modules from the launcher command line.</s> {{done}}
 +
*cloning" of module panels at run time. See [http://massmail.spl.harvard.edu/public-archives/slicer-devel/2012/008965.html "here] and [http://massmail.spl.harvard.edu/public-archives/slicer-devel/2012/008039.html here]
 +
</noinclude>

Latest revision as of 04:09, 24 April 2021

Home < Documentation < Nightly < Developers < Modules


For the latest Slicer documentation, visit the read-the-docs.


Slicer supports three types of modules: Command Line Interface (CLI), Loadable Modules and Scripted Modules.

While the developer has to choose between one of the three types to implement its module, the end user will NOT notice the difference as they all share the same look & feel.

The choice for a given type of module is usually based on the type of inputs/parameters for a given module.

Command Line Interface (CLI)

CLIs are standalone executables with a limited input/output arguments complexity (simple argument types, no user interactions...). They are typically implemented in C++ (using ITK). Recent Slicer versions allow running (almost) any Python script as a CLI module by providing an interface description .xml file.

  • Shared lib, executable, or Python script
  • UI automatically generated
  • Where to start ?
  1. Create initial skeleton using the Extension Wizard
  2. Read Compiling slicer modules outside of the slicer source tree.
  3. Learn from existing modules

Loadable Modules

Loadable modules are C++ plugins that are built against Slicer. They define custom GUIs for their specific behavior as they have full control over the application.

  • C++ shared library
  • Full control over the UI (based on Qt) and Slicer internals (MRML, logics, display managers...)
  • Optimized for heavy computations
  • Where to start ?
  1. Create initial skeleton using the Extension Wizard
  2. Read Compiling slicer modules outside of the slicer source tree.
  3. Learn from existing modules

Scripted Modules

Scripted modules are written in Python.

An extensive tutorial and reference page was created for the Slicer/Python breakout session at the NA-MIC 2014 Summer Project Week. Please read through this and many of your questions will be answered.

Several tutorials for developers are available from the Slicer Training page: https://www.slicer.org/wiki/Documentation/Nightly/Training#Tutorials_for_software_developers

  • Python Console
  • Full access to the API: VTK, Qt, MRML and Slicer,SimpleITK are fully wrapped
  • Recommended for fast prototyping and custom workflow development
  • Where to start?
  1. Read the Slicer/Python breakout session at the NA-MIC 2014 Summer Project Week tutorial.
  2. Create initial skeleton using the Extension Wizard
  3. Python scripted module design - beyond basics: role of widget, logic, MRML classes, using MRML node for storing module parameters, etc. (editable version: File:SlicerModulesProgrammingBeyondBasics.pptx)
  4. Learn from existing modules

Module Factory

Loading modules into slicer happens in multiple steps:

  • module factories must be registered into the factory manager
  • directories where the modules to load are located must be passed to the factory manager
  • Optionally specify module names to ignore
  • scan the directories and test which file is a module and register it (not instantiated yet)
  • Instantiate all the register modules
  • Connect each module with the scene and the application

More details can be found in the online doc

Association of MRML nodes to modules

Modules can be associated with MRML nodes, which for example allows determining what module can be used to edit a certain MRML node. A module can either specify the list of node types that it supports by overriding qSlicerAbstractCoreModule::associatedNodeTypes() method or a module can call qSlicerCoreApplication::addModuleAssociatedNodeTypes() to associate any node type with any module.

Multiple modules can be associated with the same MRML node type. The best module for editing a specific node instance is determined run-time. The application framework calls qSlicerAbstractModuleWidget::nodeEditable() for each associated module candidate and will activate the one that has the highest confidence in handling the node.

To select a MRML node as the "active" or "edited" node in a module the module widget's qSlicerAbstractModuleWidget::setEditedNode() method is called.

ToDo - Planned developments

  • Transform all core modules into Loadable modules.
    • the factory manager only support file based modules, core modules are not file based (linked into the core factory itself)
  • Move factory registration in qSlicerApplication (or a general application library) to support module discovery/loading without needing to instantiate Slicer.
    • Currently can't be moved into qSlicerApplication as the CLI factories that are in QTCLI depend on QTGUI
    • QtTesting is also limited with the QTCLI dependency on QtGUI (->qSlicerApplication would need to access QtTesting code from QtCli)
    • Proposed architecture
Base
  Application -> classes that are useful to build an application (mix of qSlicerCoreApplication, qSlicerApplication, Main.cxx...)
  Core -> formally QtCore
  Modules -> contains the factories and module specific code
     Loadable
     CLI
     Scripted
  Scripted -> all that is python specific
     Cxx
     Python
  Widgets -> formally QtGUI
  • Add category hierarchy in the Settings module panel
  • Register factory settings/command-options(e.g. disable-loadable-modules) when registering module factories
    • To have the settings panel be generic but have the code proper of each registered factory somewhere else
  • Add mechanism for modules to register dialogs (toolbars that open dialogs), e.g. the sceneview module needs to register the sceneView dialog into an icon.
  • Ignore modules from the launcher command line. Check.svg
  • cloning" of module panels at run time. See "here and here