Difference between revisions of "Documentation/Nightly/Developers/Logics"
(4.1 -> Nightly) |
|||
(3 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
+ | <noinclude>{{documentation/versioncheck}}</noinclude> | ||
+ | |||
+ | == Overview == | ||
+ | |||
A logic is a collection of "algorithms" that mainly process MRML nodes within a scene. | A logic is a collection of "algorithms" that mainly process MRML nodes within a scene. | ||
Line 5: | Line 9: | ||
* ''passive'' (helper): collection of utility functions to simplify the handling of nodes (e.g. <code>AddArchetypeVolume</code> in Volumes logic, Application logic.) | * ''passive'' (helper): collection of utility functions to simplify the handling of nodes (e.g. <code>AddArchetypeVolume</code> in Volumes logic, Application logic.) | ||
* a mix of both: not ideal. | * a mix of both: not ideal. | ||
+ | |||
+ | == Types of logics == | ||
There are 5 types of logics within Slicer. Their role is usually dictated by their dependencies. The [http://slicer.org/doc/html/classvtkMRMLAbstractLogic__inherit__graph.png inheritance graph] can be useful to understand the relationship between each logic types. | There are 5 types of logics within Slicer. Their role is usually dictated by their dependencies. The [http://slicer.org/doc/html/classvtkMRMLAbstractLogic__inherit__graph.png inheritance graph] can be useful to understand the relationship between each logic types. | ||
Line 56: | Line 62: | ||
#: Role | #: Role | ||
#:: They are logics that focus on representing nodes in a VTK renderer and handling user interaction within the view. | #:: They are logics that focus on representing nodes in a VTK renderer and handling user interaction within the view. | ||
− | + | ||
− | + | == Remarks == | |
− | |||
− | |||
A class (logic, widget...) should explicitly expose in its API the required logic(s) (e.g. <code>qMRMLColorPickerwidget::setColorLogic(vtkMRMLColorLogic*)</code>) instead of hiding the requirements by directly using the application logic (e.g. <code>this->GetApplicationLogic()->GetModelHierarchyLogic()</code> ). | A class (logic, widget...) should explicitly expose in its API the required logic(s) (e.g. <code>qMRMLColorPickerwidget::setColorLogic(vtkMRMLColorLogic*)</code>) instead of hiding the requirements by directly using the application logic (e.g. <code>this->GetApplicationLogic()->GetModelHierarchyLogic()</code> ). |
Latest revision as of 15:45, 8 June 2016
Home < Documentation < Nightly < Developers < Logics
For the latest Slicer documentation, visit the read-the-docs. |
Overview
A logic is a collection of "algorithms" that mainly process MRML nodes within a scene.
Logics can be:
- active: observe the scene and nodes to react when receiving events are fired
- passive (helper): collection of utility functions to simplify the handling of nodes (e.g.
AddArchetypeVolume
in Volumes logic, Application logic.) - a mix of both: not ideal.
Types of logics
There are 5 types of logics within Slicer. Their role is usually dictated by their dependencies. The inheritance graph can be useful to understand the relationship between each logic types.
- MRML logics
- Location
- Slicer/Libs/MRML/Logics
- Dependencies
- MRMLCore
- no graphical dependency
- no Slicer dendendency (can by used by other projects)
- Role
- Contain the base classes for logics (
vtkMRMLAbstractLogic
,vtkMRMLApplicationLogic
) and helper classes - MRML logics don't have access to the application, and so shouldn't contain any Slicer specific code.
- Contain the base classes for logics (
- Examples:
- factories: for MRML nodes (
vtkMRMLColorLogic
creates defaultvtkMRMLColor*Nodes
) - helpers:
vtkMRMLModelHierarchyLogic
- factories: for MRML nodes (
- Location
- Slicer logics
- Location
- Slicer/Base/Logics
- Dependencies
- MRMLLogic
- Role
- Specialization of MRML Logics for the Slicer application.
- Examples:
vtkSlicerColorLogic
: knows about the "application" default LUT IDs and custom application lut files.
- Location
- Application logics
- Location
- Slicer/Libs/MRML/Logics/vtkMRMLApplicationLogic.[h|cxx] and Slicer/Base/Logics/vtkSlicerApplicationLogic.[h|cxx]
- Dependencies
vtkMRMLApplicationLogic
doesn't depend on Slicer howevervtkSlicerApplicationLogic
does.
- Role
- Contains application specific information.
vtkMRMLApplicationLogic
is an abstract class that is specialized for the application using MRML (vtkSlicerApplicationLogic
for Slicer) vtk[MRML/Slicer]ApplicationLogic
is NOT a singleton, however, it can be accessed by any logics (seevtkMRMLAbstractLogic::SetApplicationLogic
) so it can be considered as such. It currently contains a list of nodes/logics, unique in the application. It is here for historic reasons (Slicer3), but it should not be seen as a placeholder for everything. Querying a module to get its logic should be preferred to access logics.
- Contains application specific information.
- Location
- Module logics
- Location
- Slicer/Modules/Loadable/XYZ/Logic/vtkSlicerXXXLogic
- Dependencies
- Slicer logics, XYZ nodes and optionally other module logics
- Role
- A module logic is the module public API. While a module has typically (not necessarily) an associated widget/panel, no processing should be done within the widget, the widget is just the interface between the user and the logic/nodes. Modules can access other module logics (i.e.
qSlicerCoreApplication::moduleManager()->module("Volumes")->logic()
) if needed. There is maximum 1 module logic per module, however, it doesn't prevent the module logic to use helper logics (vtkSlicerModelsLogic
can instantiate/usevtkMRMLModelHierarchyLogic
).
- A module logic is the module public API. While a module has typically (not necessarily) an associated widget/panel, no processing should be done within the widget, the widget is just the interface between the user and the logic/nodes. Modules can access other module logics (i.e.
- Location
- Displayable managers
- Location
- Slicer/Libs/MRML/DisplayableManager
- Dependencies
- MRMLLogic and vtkRendering
- Role
- They are logics that focus on representing nodes in a VTK renderer and handling user interaction within the view.
- Location
Remarks
A class (logic, widget...) should explicitly expose in its API the required logic(s) (e.g. qMRMLColorPickerwidget::setColorLogic(vtkMRMLColorLogic*)
) instead of hiding the requirements by directly using the application logic (e.g. this->GetApplicationLogic()->GetModelHierarchyLogic()
).
It is the role of the class instantiator to pass the required logics to the created class (e.g. the module plugin sets the module logic to the module widget). For module logics depending on other module logics, it is resolved in the qSlicer*Module::setup()
function, qSlicer*Modules
have access to all modules and their logics that way (i.e. qSlicerCoreApplication::moduleManager()->module("Volumes")->logic()
).
Exposing the requirements in the API instead of using singleton has the advantage of having a scope well defined and contained, the code becomes more modular and easier to unit test.