Difference between revisions of "Documentation/Nightly/Developers/Tutorials/MigrationGuide/Slicer"

From Slicer Wiki
Jump to: navigation, search
Tag: 2017 source edit
 
(92 intermediate revisions by 9 users not shown)
Line 1: Line 1:
 +
<noinclude>__TOC__</noinclude>
 +
==Slicer backward incompatible changes==
  
__TOC__
+
===Slicer 5.3: Organization name and domain changed from NA-MIC to slicer.org===
  
== Migration Guide ==
+
To address the [https://discourse.slicer.org/t/inconsistency-between-organization-name-used-for-settings-files-and-for-macos-bundle-identifier/26547 inconsistency between organization name used for settings files and for macOS bundle identifier], the 3D Slicer application has updated the <code>Slicer_ORGANIZATION_NAME</code> from "NA-MIC" to "slicer.org" and <code>Slicer_ORGANIZATION_DOMAIN</code> from <code>www.na-mic.org</code> to <code>slicer.org</code>. At the time of this change, 3D Slicer is developed primarily by the Slicer community rather than the NA-MIC community. Distribution of 3D Slicer is hosted at [https://slicer.org slicer.org] rather than at [https://www.na-mic.org www.na-mic.org].
  
=== Slicer 4.9: Application: isRelease() function not available ===
+
Slicer settings will now be under a Slicer directory location rather than NA-MIC. Please review the [https://slicer.readthedocs.io/en/latest/user_guide/settings.html#settings-file-location Settings File Location documentation] for details about the settings location on various platforms.
 +
 
 +
===Slicer 5.3: Removed Annotation module===
 +
 
 +
Annotations module, which provides `vtkMRMLAnnotationROI` and `vtkMRMLAnnotationRuler` nodes have been deprecated since April 2021 and is to be removed in Slicer-4.3.
 +
 
 +
When a scene is loaded into Slicer that contains annotation nodes, they are converted to markup nodes: `vtkMRMLAnnotationROI` is converted to `vtkMRMLMarkupsROI`; and `vtkMRMLAnnotationRuler` is converted to `vtkMRMLMarkupsLine`. All Slicer core modules that previously used annotation nodes, now use markup nodes instead.
 +
 
 +
All extensions, too, need to be updated to use markup nodes instead of annotation nodes. For backward compatibility (so that the same extension can be used with current Slicer version and Slicer-4.2 and earlier versions), it is useful to keep the modules accept both markup and annotation nodes, but always create markup nodes by default.
 +
 
 +
Tips for updating a module to use markups:
 +
 
 +
* In node selectors, wherever `vtkMRMLAnnotationROINode` is accepted, add `vtkMRMLMarkupsLineNode` _before_ it (so they are both accepted, but markups are preferred)
 +
* In node selectors, wherever `vtkMRMLAnnotationRuler` is accepted, add `vtkMRMLMarkupsLine` _before_ it (so they are both accepted, but markups are preferred)
 +
* For ROIs:
 +
** When only non-rotated ROIs are used: you can still use `GetXYZ()` and `GetRadiusXYZ()` methods work the same way for markups ROI
 +
** When ROIs are rotated, markups ROIs support built-in rotation and scaling, therefore it is recommended to use the `exportRoi.GetObjectToWorldMatrix()` method to get all the transforms (including the transform inside the markup node and any transforms applied using transform nodes) that are applied to the bounding box object (that has its center in the origin and its diameter returned by `GetSize()`).
 +
* For rulers:
 +
** Use `GetNthControlPointPosition(0)` and `GetNthControlPointPosition(1)` methods to get the endpoints of the line.
 +
** Use `GetNumberOfDefinedControlPoints()` method to check if both endpoints of the line are defined.
 +
** Use `GetMeasurement('length').GetValue()` to get the line length (or for the displayed string, with units: `getNode('L').GetMeasurement('length').GetValueWithUnitsAsPrintableString()`)
 +
 
 +
===Slicer 5.0: API changes since 4.10===
 +
 
 +
*Removed protected method <tt>vtkMRMLModelDisplayableManager::FindPickedDisplayNodeFromMesh</tt>
 +
 
 +
==== Supporting only Python 3.6 and above ====
 +
Slicer python code has been updated to support Python 3.6 and above syntax using [https://github.com/asottile/pyupgrade pyupgrade] to automatically update the syntax.
 +
 
 +
Install pyupgrade: <code>PythonSlicer -m pip install pyupgrade</code>
 +
 
 +
* Running:
 +
** On 1 file: <code>PythonSlicer -m pyupgrade --py36-plus MyPythonFile.py</code>
 +
** On multiple files: Here is my pyupgrade-script.py written to automate running pyupgrade across all python files in the Slicer repo. It was run by <code>PythonSlicer pyupgrade-script.py</code>
 +
<syntaxhighlight lang="python">
 +
# pyupgrade-script.py
 +
import os
 +
import subprocess
 +
 
 +
search_directory = "C:/Users/MyUserName/Documents/GitHub/Slicer"
 +
for root, _, files in os.walk(search_directory):
 +
  for file_item in files:
 +
    file_path = os.path.join(root, file_item)
 +
      if os.path.isfile(file_path) and file_path.endswith(".py"):
 +
        subprocess.call(["PythonSlicer", "-m", "pyupgrade", "--py36-plus", file_path])
 +
</syntaxhighlight>
 +
 
 +
====Python 2 to Python 3====
 +
 
 +
Slicer core has been updated to only support Python 3.
 +
 
 +
C++ classes and python scripts have been updated to use idioms and constructs only available in Python 3.
 +
 
 +
Update to python scripts have been done leveraging the CLI provided by https://python-future.org by (1) iteratively applying each one of the associates "fixes", (2) reviewing associated changes and (3) updating as needed.
 +
 
 +
Updates specific to extensions are discussed in [[Documentation/Nightly/Developers/Tutorials/MigrationGuide#Slicer_5.0:_Python2_to_Python3]]
 +
 
 +
====Interactor styles====
 +
 
 +
Limitations of VTK widgets (editable points, lines, curves, etc.) prevented Slicer from having sophisticated user interaction in slice and 3D views. In Slicer5, we replaced VTK widgets with MRML widgets. These widgets are still VTK-based and somewhat similar to VTK widgets, but they operate directly on MRML nodes, they use direct method calls between widgets and their representation, and they use a more efficient and flexible event processing. Instead of hardcoding how viewers behave in response to interaction (mouse move, button click, keyboard, ...) events in an interactor style, all these events are translated to actions and performed in a MRML widget. Most modules are not expected to observe interactor events or styles directly, but if they did, then they may need to be updated accordingly.
 +
 
 +
*vtkSliceViewInteractorStyle renamed to vtkMRMLSliceDViewInteractorStyle to reflect that it uses MRML classes directly.
 +
*vtkThreeDViewInteractorStyle renamed to vtkMRMLThreeDViewInteractorStyle to reflect that it uses MRML classes directly.
 +
 
 +
====slicer.util functions====
 +
 
 +
*slicer.util.loadVolume (and other node load functions) now return the loaded node instead of a True/False flag. In case of an error, a RuntimeError exception is thrown.
 +
**Old way of loading a node and get it in a variable: <code>volumeNode = slicer.util.loadVolume('path/to/volume.nrrd', returnNode=True)[1]</code>
 +
**New way of loading a node and get it in a variable: <code>volumeNode = slicer.util.loadVolume('path/to/volume.nrrd')</code>
 +
 
 +
====Markups====
 +
 
 +
*<tt>vtkCommand::Modified</tt> events are no longer invoked when control points are added/removed/modified to improve performance. Modules that need to know If a point position is modified need to add observers to <tt>vtkMRMLMarkupsNode::PointAddedEvent</tt>, <tt>vtkMRMLMarkupsNode::PointRemovedEvent</tt>, <tt>vtkMRMLMarkupsNode::PointModifiedEvent</tt> events. See example in [https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html#get-a-notification-if-a-markup-point-position-is-modified Script repository].
 +
*<tt>vtkMRMLMarkupsNode::MarkupAddedEvent</tt> is renamed to <tt>PointPositionDefinedEvent</tt>. There is a similar event, <tt>vtkMRMLMarkupsNode::PointAddedEvent</tt>, which is called even when preview point is created.
 +
*<tt>vtkMRMLMarkupsNode::MarkupRemovedEvent</tt> is renamed to <tt>vtkMRMLMarkupsNode::PointPositionUndefinedEvent</tt>. There is a similar event, <tt>vtkMRMLMarkupsNode::PointRemovedEvent</tt>, which is called even when preview point is removed.
 +
*<tt>vtkMRMLMarkupsNode::NthMarkupModifiedEvent</tt> is replaced by <tt>vtkMRMLMarkupsNode::PointModifiedEvent</tt>
 +
*During placement of markups, a preview markup point is created. If number of already placed markup points needs to be determined then <code>GetNumberOfDefinedControlPoints()</code> method can be used.
 +
*<tt>GetDefaultMarkups...()</tt> and <tt>SetDefaultMarkups...()</tt> methods are removed. Instead default display node can be accessed by <tt>GetDefaultMarkupsDisplayNode()</tt> method and default values can be get/set in that class.
 +
*<tt>vtkMRMLMarkupsNode::GetNthMarkupSelected()</tt> is replaced by <tt>GetNthControlPointSelected()</tt>
 +
*<tt>vtkMRMLMarkupsNode::PointPositionDefinedEvent</tt> event is added. This event is invoked whenever position is defined for a new point.
 +
*<tt>vtkMRMLMarkupsNode::PointPositionUndefinedEvent</tt> event is added. This event is invoked whenever point with defined position is removed (point is deleted or its position gets undefined).
 +
*For more details, see [{{doxygen-class-url|vtkMRMLMarkupsNode}} vtkMRMLMarkupsNode]
 +
 
 +
====Segmentations====
 +
 
 +
Binary labelmap segmentations can now be represented as shared labelmaps.
 +
The previous implementation of binary labelmaps was performance intensive as each labelmap was represented using a separate vtkDataObject.
 +
Visualizing and editing segmentations that contained a large number of segments could cause performance issues, due to the large number of vtkActors required, as well as calculating masks and overwriting other segments when editing.
 +
 
 +
By default, newly created segments will now be contained on the same layer.
 +
Segments will only be separated into multiple layers if the user creates an overlapping segment when editing.
 +
 
 +
Segments are now saved as a 4D volume with shared 3D layers.
 +
For a segmentation that only uses one layer, the resulting image is a 3D volume.
 +
Before saving, the labelmaps will be collapsed into as few layers as possible.
 +
 
 +
*seg.nrrd files now contain two additional attributes for each segment: SegmentX_LabelValue and SegmentX_Layer
 +
*The label value of a segment can be found using vtkSegment::GetLabelValue()
 +
*Whether or not a segment is shared can be found using vtkSegmentation::IsSharedBinaryLabelmap()
 +
*The other segments sharing the same labelmap can be found using vtkSegmentation::GetSegmentIDsSharingBinaryLabelmapRepresentation()
 +
*Segment editor effects should generally use modifySelectedSegmentByLabelmap rather than SetBinaryLabelmapToSegment to manage layer separation
 +
*Conversion rules now call PreConvert() and PostConvert() before and after conversion to perform pre and post processing steps on the segmentation as a whole
 +
*The function signature for vtkSegmentationConverterRule::Convert now accepts a vtkSegment rather than two vtkDataObjects
 +
*slicer.util.arrayFromSegment has been deprecated. slicer.util.arrayFromSegmentBinaryLabelmap and slicer.util.arrayFromSegmentInternalBinaryLabelmap can be used instead
 +
 
 +
=====Erase the contents of a single segment=====
 +
 
 +
<pre>
 +
segmentation = segmentationNode.GetSegmentation()
 +
segmentation.ClearSegment(segmentId)
 +
</pre>
 +
 
 +
=====Set labelmap in a segment=====
 +
 
 +
Directly, bypassing masking settings:
 +
 
 +
<pre>
 +
slicer.vtkSlicerSegmentationsModuleLogic.SetBinaryLabelmapToSegment(orientedImageDataToSet, segmentationNode, segmentId)
 +
</pre>
 +
 
 +
=====Move a segment from a shared labelmap to a separate layer=====
 +
 
 +
<pre>
 +
segmentation = segmentationNode.GetSegmentation()
 +
segmentation.SeparateSegmentLabelmap(segmentId)
 +
</pre>
 +
 
 +
=====Combine all binary labelmaps to as few layers as possible=====
 +
 
 +
<pre>
 +
segmentation = segmentationNode.GetSegmentation()
 +
segmentation.CollapseBinaryLabelmaps(forceToSingleLayer=false)
 +
</pre>
 +
 
 +
<b>Get a read-only labelmap for a single segment:</b>
 +
 
 +
<pre>
 +
labelmap = slicer.vtkOrientedImageData()
 +
segmentationNode.GetBinaryLabelmapRepresentation(segmentId, labelmap)
 +
</pre>
 +
 
 +
(similarly, use GetClosedSurfaceRepresentation with an additional vtk.vtkPolyData parameter to get a read-only surface mesh)
 +
 
 +
or
 +
 
 +
<pre>
 +
labelmapNumpyArray = slicer.util.arrayFromSegmentBinaryLabelmap(segmentationNode, segmentId)
 +
</pre>
 +
 
 +
=====Get a modifiable shared labelmap=====
 +
 
 +
<pre>
 +
labelmap = slicer.vtkOrientedImageData()
 +
segmentationNode.GetBinaryLabelmapInternalRepresentation(segmentId, labelmap)
 +
</pre>
 +
 
 +
(similarly, use GetClosedSurfaceInternalRepresentation to get a modifiable surface mesh)
 +
 
 +
or
 +
 
 +
<pre>
 +
labelmapNumpyArray = slicer.util.arrayFromSegmentInternalBinaryLabelmap(segmentationNode, segmentId)
 +
</pre>
 +
 
 +
=====Export segments to models=====
 +
 
 +
Model hierarchies no longer exist in Slicer5, but instead various kinds of hierarchies are now replaced by "subject hierarchy", which can accommodate any node types in a single hierarchy. Accordingly, `ExportSegmentsToModelHierarchy`, `ExportAllSegmentsToModelHierarchy`, etc. are replaced by `ExportSegmentsToModels`, `ExportAllSegmentsToModels`, which take a subject hierarchy folder item ID as input.
 +
Documentation/Nightly
 +
See code example in [https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html#export-model-nodes-from-segmentation-node Script repository].
 +
 
 +
=====Smoothing effect=====
 +
 
 +
In Slicer-4.11 version before October 29, 2020 (and earlier versions), Gaussian smoothing method's Standard deviation parameter ("GaussianStandardDeviationMm") was interpreted in pixels, while on the user interface and code it was claimed to be in physical units (millimeter). The problem was fixed and now the parameter is in millimeter.
 +
 
 +
====Volume rendering====
 +
 
 +
vtkMRMLVolumeRenderingDisplayNode::SetAndObserveVolumeNodeID method was removed, as display node base class already maintains a pointer to the displayed (volume) node. To associate a volume display node with a volume node, call <pre>volumeNode->AddAndObserveDisplayNodeID(volumeRenderingDisplayNode->GetID());</pre> after both nodes are added to the scene.
 +
 
 +
''vtkSlicerVolumeRenderingLogic::CreateDefaultVolumeRenderingNodes'' method unnecessarily polluted the scene with ROI node even though the user did not need cropping. In Slicer-5.x we fixed the issue by not creating the ROI nodes automatically. To create a ROI node, you can call ''vtkSlicerVolumeRenderingLogic::CreateROINode'' method.
 +
 
 +
====Extract skeleton====
 +
 
 +
Command-line arguments of the module have been updated:
 +
- output image is now optional, therefore the output image file name must be specified using "--outputImage" argument
 +
- output image centerline voxel value is set to 255 (instead of 1) to make it easier to apply image processing operations on it (values can be interpolated between 0 and 255, while there are no integer values between 0 and 1)
 +
- "--dontPrune" is renamed to "--fullTree" for clarity
 +
- centerline curve is saved in mrk.json format
 +
 
 +
==== MRML node copy API improvements ====
 +
 
 +
Slicer-4.10 and earlier had a single Copy() method, which had limitations:
 +
- usually implemented deep copy (but sometimes bulk data was just shallow-copied): problem, because for quick browsing of sequences, we need shallow-copy (to avoid copying bulk data, such as vtkImageData)
 +
- copied all node properties (except node ID and scene): this required workarounds, whenever we wanted to copy only the content of nodes (but for example keeping node references or node name intact)
 +
 
 +
In Slicer-4.11, these limitations are addressed, by implementing a ''CopyContent(vtkMRMLNode* node, bool deepCopy=true)'' method which allows choosing between deep/shallow copy (create an independent copy of bulk data or pass bulk data pointer) and does not copy node ID, Scene, Name, SingletonTag, HideFromEditors, AddToScene, UndoEnabled, and node references.
 +
 
 +
To make it easier to introduce this new method into existing classes, helper macros are implemented.
 +
 
 +
If a class implements CopyContent method then the developer must make sure that CopyContent and HasCopyContent methods are implemented in all parent classes by adding vtkMRMLCopyContentMacro(ClassName) or vtkMRMLCopyContentDefaultMacro(ClassName) to the class headers. vtkMRMLCopyContentDefaultMacro should be used when the class does not have any additional properties (only those that parent classes already copy). CopyContent must be implemented by calling CopyContent of the parent class, and then copy node properties added in he class (preferable using shallow copy for large data, if deepCopy argument was set to false).
 +
 
 +
If HasCopyContent macro is not added to a class then it cannot be recorded or replayed in Sequences module.
 +
 
 +
==== Removed classes ====
 +
 
 +
Classes removed due to removing legacy Editor module:
 +
* vtkITKNewOtsuThresholdImageFilter is replaced by vtkITKImageThresholdCalculator
 +
* vtkITKGrowCutSegmentationImageFilter is replaced by vtkImageGrowCutSegment (it will be replaced by the ITK implementation https://github.com/Slicer/Slicer/pull/5807)
 +
* vtkITKTimeSeriesDatabase was removed, it was an incomplete class, not used anywhere
 +
* vtkITKWandImageFilter was removed, vtkImageThresholdConnectivity (in VTK) can be used instead
 +
* vtkImageConnectivity was removed, vtkImageThresholdConnectivity (in VTK) can be used instead
 +
* vtkImageErode was removed, vtkImageDilateErode3D (in VTK) can be used instead
 +
* vtkImageLabelChange was removed, vtkImageThreshold (in VTK) can be used instead
 +
* vtkImageSlicePaint was replaced by logic built into qSlicerSegmentEditorPaintEffect
 +
* vtkImageStash is replaced by vtkSegmentationHistory
 +
* vtkPichonFastMarching moved to SegmentEditorExtraEffects extension (https://github.com/lassoan/SlicerSegmentEditorExtraEffects)
 +
 
 +
Classes removed due to removing Charts and DoubleArrays modules:
 +
* vtkMRMLChartNode is replaced by vtkMRMLPlotNode
 +
* vtkMRMLChartViewNode is replaced by vtkMRMLPlotViewNode
 +
* vtkMRMLDoubleArrayNode is replaced by vtkMRMLTableNode (can store any number of columns, not just two)
 +
* vtkMRMLDoubleArrayStorageNode is replaced by vtkMRMLTableStorageNode
 +
* qMRMLChartView is replaced by qMRMLPlotView
 +
* qMRMLChartViewControllerWidget is replaced by qMRMLPlotViewControllerWidget
 +
* qMRMLChartWidget is replaced by qMRMLPlotWidget
 +
 
 +
===Slicer 5.0: Fiducial List was renamed to Point List===
 +
 
 +
To simplify terms used in Slicer, "Fiducial List" term was renamed to "Point List" on the user interface.
 +
The term in the API has not been changed to preserve backward compatibility.
 +
 
 +
See discussion of the topic [https://discourse.slicer.org/t/delete-control-point-delete-fiducial-pop-up-confirm-box/20430/18 here].
 +
 
 +
===Slicer 5.0: SliceIntersectionVisibility was moved from vtkMRMLSliceCompositeNode to vtkMRMLSliceDisplayNode===
 +
 
 +
SliceIntersectionVisibility property (that controls if intersections of other slices should be displayed in the slice view) was stored in vtkMRMLSliceCompositeNode. This was not a good choice because the composite node stores what image layers should be displayed in the slice view and how (what opacity, what blending method, etc.). The property was kept in that class for a long time to preserve backward compatibility, but when interactive slice intersection feature was added and additional properties had to be added that control appearance and behavior of slice intersections, this property was moved into the new vtkMRMLSliceDisplayNode node type and renamed to IntersectingSlicesVisibility.
 +
 
 +
Scripts that previously used SliceIntersectionVisibility property will now fail with this error:
 +
 
 +
  AttributeError: 'MRMLCore.vtkMRMLSliceCompositeNode' object has no attribute 'SetSliceIntersectionVisibility'
 +
 
 +
Those failing scripts can be updated with this example in the script repository: https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html#turn-on-slice-intersections
 +
 
 +
===Slicer 5.0: SlicerPython was removed. Use PythonSlicer instead===
 +
 
 +
<b>Error message:</b>
 +
 
 +
<pre>
 +
SlicerPython executable is obsolete and will be removed. Use PythonSlicer executable instead.
 +
For more details, see https://github.com/Slicer/Slicer/issues/4843
 +
</pre>
 +
 
 +
<b>Solution:</b>
 +
 
 +
Use <tt>PythonSlicer</tt> instead of <tt>SlicerPython</tt>
 +
 
 +
<b>Background:</b>
 +
 
 +
Python IDEs (specifically PyCharm, but potentially others) only recognize <tt>Python*.exe</tt> files as Python interpreters.
 +
 
 +
To allow using Slicer's Python interpreter in these IDEs, we had to add <tt>PythonSlicer</tt>, but kept <tt>SlicerPython</tt> around for not immediately breaking things.
 +
 
 +
This redundancy is confusing for users that we could resolve by simply removing SlicerPython for Slicer5.
 +
 
 +
<b>References:</b>
 +
 
 +
https://github.com/Slicer/Slicer/issues/4843
 +
 
 +
===Slicer 5.0: Application must be installed in writable location to install extensions===
 +
 
 +
Extensions are now installed in the application home folder because Python packages are installed there anyway, so the application home folder has to be writable (or Slicer has to be run as admin when you install extensions). It also allows making Slicer fully portable - see details [https://discourse.slicer.org/t/slicer-is-now-fully-portable/15410 here].
 +
 
 +
If you want to allow any user to install extensions without admin rights and you only need to use extensions that don’t install Python packages at runtime then you can specify a custom extension install path folder in Slicer-NNN.ini file or revert to the old behavior of Slicer by specifying <code>Slicer_STORE_SETTINGS_IN_APPLICATION_HOME_DIR:BOOL=OFF</code> when configuring your Slicer build.
 +
 
 +
===Slicer 5.0: Models are saved in LPS coordinate system by default===
 +
 
 +
While Slicer uses RAS coordinate system internally, images, transforms, and markups files are stored in LPS coordinate system, because DICOM and all medical image computing software (maybe except a few very old ones) uses LPS coordinate system in files.
 +
 
 +
However, Slicer has been still using its internal RAS coordinate system in mesh files (STL, VTK, VTP, OBJ, PLY), which caused issues when interfacing with third-party software.
 +
 
 +
From Slicer-4.11.0-2020-02-26 (revision 28794) models are saved in LPS coordinate system, and mesh files assumed to be in LPS coordinate system by default (if no other coordinate system specified in the file).
 +
 
 +
Slicer started embedding coordinate system name in mesh files a few years ago (see <code>SPACE=RAS</code> in the file header), so all the files that Slicer saved in recent years will load correctly and any scene files created with any version of Slicer will also load the models with correct orientation, too.
 +
 
 +
Manual setting of coordinate system (in Add data dialog / Options column) is only needed when loading a mesh file without a scene that were created by Slicer-4.6 (2017-09-27) and earlier; and obj files created by Slicer-4.6 and Slicer-4.8 (between 2016-10-11 and 2018-03-26), or files are created by third-party software in RAS coordinate system.
 +
 
 +
If you encounter orientation issues when loading a model file, you have the following options:
 +
 
 +
*Option A: Specify the coordinate system when you open the model file. In “Add data” dialog, click “Show Options” and then choose “RAS” as coordinate system.
 +
*Option B: Update the third-party software that generate the mesh to save coordinates in LPS coordinate system instead of RAS coordinate system. Conversion is simple inverting the sign of the first two coordinates.
 +
*Option C: Write <code>SPACE=RAS</code> in the comment/description field in the mesh file (for STL, OBJ, PLY, VTK file; for VTP files, add in the first value of a vtkStringArray field array named <code>SPACE</code>) to indicate that the values are stored in RAS coordinate system. This option is useful if coordinates have to be stored in RAS coordinate system (for example, for compatibility with other software). See implementation example [https://github.com/Slicer/SlicerGitSVNArchive/blob/c0829f596f0ea661e0c5484056bd1374a3d22958/Libs/MRML/Core/vtkMRMLModelStorageNode.cxx#L421-L647 here].
 +
 
 +
See more information, discussion of this topic on the [https://discourse.slicer.org/t/model-files-are-now-saved-in-lps-coordinate-system/10446 Slicer forum].
 +
 
 +
===Slicer 5.0: CLI module descriptor XML files assume LPS coordinate system by default===
 +
 
 +
If [[Documentation/Nightly/Developers/SlicerExecutionModel|SlicerExecutionModel]] descriptor XML file of a CLI module does not specify coordinate system for a point, pointfile, or region element then the coordinate system is assumed to be "lps". To preserve previous behavior and use "ras" coordinate system instead, add '''coordinateSystem="ras"''' to the element.
 +
 
 +
===Slicer 5.0: Sequences extension has been merged into Slicer core===
 +
 
 +
Sequences extension has been merged into Slicer core, therefore extensions do not need to depend on Sequences extension anymore.
 +
 
 +
SequenceBrowser module has been merged into Sequences module, therefore previous code that used SequenceBrowser module now should use Sequences module instead.
 +
 
 +
===Slicer 5.0: FreeSurfer support has been removed from Slicer core===
 +
The loading of FreeSurfer models and scalar overlays, as well as the FreeSurfer-specific color nodes, have been moved to the new [https://github.com/PerkLab/SlicerFreeSurfer SlicerFreeSurfer] extension. Tutorials on how to use the FreeSurfer Importer module to load multiple files at once can be found on the [https://github.com/PerkLab/SlicerFreeSurfer/wiki/Tutorials SlicerFreeSurfer tutorial page].
 +
 
 +
===Slicer 5.0: Removed Editor module===
 +
 
 +
The legacy Editor module has been deprecated since about 2017 and got removed in November 2021. It is replaced by the much improved Segment Editor module.
 +
 
 +
===Slicer 5.0: Removed Charts and DoubleArrays module===
 +
 
 +
Charts and DoubleArrays module have been deprecated since about 2018 and got removed in November 2021. They are replaced by Plots and Tables modules.
 +
 
 +
'''Example of commits'''
 +
* [https://github.com/SlicerRt/SlicerRT/commit/8f9155f94399be71e747d3d45b1f6c4152caa139 SlicerRT@8f9155f94] ENH: Update DVH module to use plots infrastructure instead of charts
 +
 
 +
===Slicer 5.0 : Avoid typedef of anonymous structure===
 +
 
 +
Due to a recent (but retroactive) C++ rule change, only sufficiently C-compatible classes are permitted to be given a typedef name for linkage purposes. Add an <tt>enabled-by-default</tt> warning for these cases, and rephrase our existing error for the case where we encounter the <tt>typedef</tt> name for linkage after we've already computed and used a wrong linkage in terms of the new rule.
 +
 
 +
<b>To fix warning message similar to:</b>
 +
 
 +
<pre>
 +
Slicer/Libs/MRML/Core/vtkMRMLTableStorageNode.h:95:17:
 +
warning: anonymous non-C-compatible type given name for linkage purposes by typedef declaration; add a tag name here [-Wnon-c-typedef-for-linkage]
 +
  typedef struct
 +
                ^
 +
                ColumnInfo
 +
Slicer/Libs/MRML/Core/vtkMRMLTableStorageNode.h:99:5:
 +
note: type is not C-compatible due to this default member initializer
 +
    int ScalarType = VTK_STRING;
 +
    ^~~~~~~~~~~~~~
 +
Slicer/Libs/MRML/Core/vtkMRMLTableStorageNode.h:102:5:
 +
note: type is given name 'ColumnInfo' for linkage purposes by this typedef declaration
 +
  } ColumnInfo;
 +
    ^
 +
For consistency, Use 'using' to a named structure definintion for all
 +
structures.
 +
</pre>
 +
 
 +
<b>Replace code like this:</b>
 +
 
 +
<pre>
 +
  typedef struct
 +
  {
 +
    std::string ColumnName;
 +
    std::vector<vtkAbstractArray*> RawComponentArrays;
 +
    int ScalarType = VTK_STRING;
 +
    std::vector<std::string> ComponentNames;
 +
    std::string NullValueString;
 +
  } ColumnInfo;
 +
</pre>
 +
 
 +
<b>By this:</b>
 +
 
 +
<pre>
 +
  struct StructColumnInfo
 +
  {
 +
    std::string ColumnName;
 +
    std::vector<vtkAbstractArray*> RawComponentArrays;
 +
    int ScalarType = VTK_STRING;
 +
    std::vector<std::string> ComponentNames;
 +
    std::string NullValueString;
 +
  };
 +
  using ColumnInfo = struct StructColumnInfo;
 +
</pre>
 +
 
 +
 
 +
<b>References:</b>
 +
 
 +
https://reviews.llvm.org/D74103
 +
 
 +
===Slicer 5.0 : Temporary path===
 +
 
 +
Temporary path was stored redundantly application settings (Slicer.ini) in two keys: <code>Modules/TemporaryDirectory</code> and <code>TemporaryPath</code>. <code>Modules/TemporaryDirectory</code> overwrote <code>TemporaryPath</code> at startup, but when temporary path was set via the <code>slicer.app.temporaryPath</code> then it was only written to <code>TemporaryPath</code>.
 +
 
 +
Changed behavior so that only <code>TemporaryPath</code> is used. <code>Modules/TemporaryDirectory</code> is ignored.
 +
 
 +
To ensure that temporary path is always writable, it as checked at startup that a file can be created in temporary path and if this check fails then temporary path is reset to default (<code>QDir::tempPath()</code>).
 +
 
 +
===Slicer 5.0 : Always prefer executable CLIs===
 +
 
 +
Previously, if a CLI module was available both as an executable and a shared library, then PreferExecutableCLI application setting was used to determine which one is used. Now always CLIs are always executed in an external process (if an executable is available). Reasons are described in this issue: https://github.com/Slicer/Slicer/issues/4893. The application setting is no more displayed in the GUI and any setting specified in earlier Slicer versions is ignored.
 +
 
 +
===Slicer 5.0 : SlicerApp-real is a console application on Windows===
 +
 
 +
Previously, the application (SlicerApp-real.exe) was built as a GUI application (without console) on Windows, to avoid displaying a terminal window when starting the application. This had the drawback that the Slicer application did not have standard input/output that could be displayed or redirected (for example, for capturing into a file). SlicerApp-real has always been a console application on Linux and macOS, therefore this change makes the software behavior more consistent across platforms.
 +
 
 +
SlicerApp-real.exe is now built as a console application (see [https://github.com/Slicer/Slicer/issues/2934 #2934]). Displaying of a terminal window is prevented by using a launcher (Slicer.exe) that is built as a GUI application and it starts Slicer with the standard input and outputs redirected.
 +
 
 +
To display console output: https://slicer.readthedocs.io/en/latest/developer_guide/debugging/overview.html#console-output-on-windows
 +
 
 +
To launch a command-line terminal using <code>subprocess.Popen</code> that shows a new terminal, specify <code>creationflags=subprocess.CREATE_NEW_CONSOLE</code> argument.
 +
 
 +
===Slicer 4.11: Variable CMAKE_DEFAULT_BUILD_TYPE renamed to Slicer_DEFAULT_BUILD_TYPE===
 +
 
 +
Setting the default build type for single config generator may be done setting <tt>Slicer_DEFAULT_BUILD_TYPE</tt> instead of <tt>CMAKE_DEFAULT_BUILD_TYPE</tt>.
 +
 
 +
<b>Error message similar to:</b>
 +
 
 +
<pre>
 +
  CMake Error:
 +
    Generator
 +
 
 +
      Visual Studio 15 2017
 +
 
 +
    does not support variable
 +
 
 +
      CMAKE_DEFAULT_BUILD_TYPE
 +
 
 +
    but it has been specified.
 +
</pre>
 +
 
 +
<b>References:</b>
 +
 
 +
https://github.com/Slicer/Slicer/pull/4799
 +
 
 +
===Slicer 4.11: teem python module renamed to vtkTeem, explicit import required===
 +
 
 +
*Since the module provides VTK classes interfacing with "teem", the name is now representative of the class it contains.
 +
*<tt>vtkTeem</tt> classes are expected to be used by explicitly importing the module.
 +
 
 +
<b>Replace code like this:</b>
 +
 
 +
<pre>
 +
import teem
 +
 
 +
class CalculateTensorScalars(object):
 +
  def __init__(self):
 +
    self.dti_math = teem.vtkDiffusionTensorMathematics()
 +
</pre>
 +
 
 +
<b>By this:</b>
 +
 
 +
<pre>
 +
import vtkTeem
 +
 
 +
class CalculateTensorScalars(object):
 +
  def __init__(self):
 +
    self.dti_math = vtkTeem.vtkDiffusionTensorMathematics()
 +
</pre>
 +
 
 +
===Slicer 4.11: Display window/level (brightness/contrast) adjustment===
 +
 
 +
*A new "Window/level" mouse interaction mode was introduced. Volume display window/level can only be changed if this mode is activated by clicking the corresponding button in the toolbar. The new mouse mode prevents accidental modification of volume window/level (when for example the user accidentally clicked too far from a markup) and it also allows more sophisticated window/level adjustments.
 +
*New region-based auto window/level feature added: activate "Window/level" mouse mode and use Ctrl + left-click-and-drag to highlight a region and optimize window/level for that (pressing Escape or right-click cancels the operation).
 +
*Auto window/level reset: activate "Window/level" mouse mode and double-click the left mouse button.
 +
*Improved auto window/level algorithm to prevent too bright display of images. Window/level is set to display values between 0.1th and 99.9th percentile of gray levels. See details here: https://discourse.slicer.org/t/feedback-requested-how-to-improve-mouse-interaction-in-views/6420.
 +
*Removed class <tt>vtkImageBimodalAnalysis</tt>
 +
 
 +
===Slicer 4.10: Registration of runTest function done in ScriptedLoadableModule base class===
 +
 
 +
Following [http://viewvc.slicer.org/viewvc.cgi/Slicer4?view=revision&revision=27617 r27617]:
 +
 
 +
*the <code>ScriptedLoadableModule</code> class takes care of registering the <code>runTest</code> function.
 +
*the <code>runTest</code> function expects <code>msec</code> keyword argument.
 +
 
 +
<b>Error message similar to:</b>
 +
 
 +
<pre>
 +
Traceback (most recent call last):
 +
  File "/path/to/Slicer-SuperBuild/Slicer-build/bin/Python/slicer/ScriptedLoadableModule.py", line 205, in onReloadAndTest
 +
    test(msec=int(slicer.app.userSettings().value("Developer/SelfTestDisplayMessageDelay")), **kwargs)
 +
TypeError: runTest() got an unexpected keyword argument 'msec'
 +
Reload and Test: Exception!
 +
 
 +
runTest() got an unexpected keyword argument 'msec'
 +
</pre>
 +
 
 +
<b>Replace code like this:</b>
 +
 
 +
<pre>
 +
class sceneImport2428(ScriptedLoadableModule):
 +
  [...]
 +
  def __init__(self, parent):
 +
    ScriptedLoadableModule.__init__(self, parent)
 +
    parent.title = "..."
 +
    [...]
 +
    parent.acknowledgementText = "..."
 +
    self.parent = parent
 +
 
 +
    # Add this test to the SelfTest module's list for discovery when the module
 +
    # is created.  Since this module may be discovered before SelfTests itself,
 +
    # create the list if it doesn't already exist.
 +
    try:
 +
      slicer.selfTests
 +
    except AttributeError:
 +
      slicer.selfTests = {}
 +
    slicer.selfTests['sceneImport2428'] = self.runTest
 +
 +
  def runTest(self):
 +
    tester = sceneImport2428Test()
 +
    tester.runTest()
 +
 
 +
  [...]
 +
</pre>
 +
 
 +
<b>By this:</b>
 +
 
 +
<pre>
 +
class sceneImport2428(ScriptedLoadableModule):
 +
  [...]
 +
  def __init__(self, parent):
 +
    ScriptedLoadableModule.__init__(self, parent)
 +
    parent.title = "..."
 +
    [...]
 +
    parent.acknowledgementText = "..."
 +
 
 +
  [...]
 +
</pre>
 +
 
 +
===Slicer 4.9: Update of VTK version from 9.0 to 8.2===
 +
 
 +
Following [https://github.com/Kitware/VTK/commit/b703d78be3ffd8ae69c319afa0230097ff270f26 kitware/VTK@b703d78be], VTK has updated to use version number 8.2 instead of 9.0. This was discussed in on the VTK mailing list in http://vtk.1045678.n5.nabble.com/Discussion-OK-to-change-VTK-s-version-number-from-9-0-to-8-2-tt5748702.html
 +
 
 +
At first, this VTK commit and its companion [https://github.com/Kitware/VTK/commit/8a00b357e84eec695bda049216f30f2b76d80855 kitware/VTK@8a00b357e] were both reverted from the [https://github.com/Slicer/VTK/ Slicer/VTK] fork. Then, since having the corresponding changes reverted in VTK was not possible, it was decided to also update Slicer. This was done in the following commits:
 +
 
 +
*[http://viewvc.slicer.org/viewvc.cgi/Slicer4?view=revision&revision=27472 r27472]: COMP: Update c++ classes to support building against VTK >= 9 and VTK >= 8.2
 +
*[http://viewvc.slicer.org/viewvc.cgi/Slicer4?view=revision&revision=27473 r27473]: COMP: Update VTK to include version change from 9.0 to 8.2. Fixes #4623
 +
 
 +
This means that code depending on VTK must also be updated to include similar fixes.
 +
 
 +
'''Replace this:'''
 +
  #if VTK_MAJOR_VERSION >= 9
 +
 
 +
'''By this:'''
 +
  #if VTK_MAJOR_VERSION >= 9 || (VTK_MAJOR_VERSION >= 8 && VTK_MINOR_VERSION >= 2)
 +
 
 +
and
 +
 
 +
'''Replace this:'''
 +
  #if VTK_MAJOR_VERSION < 9
 +
 
 +
'''By this:'''
 +
  #if VTK_MAJOR_VERSION <= 7 || (VTK_MAJOR_VERSION <= 8 && VTK_MINOR_VERSION <= 1)
 +
 
 +
 
 +
===Slicer 4.9: ITK_LEGACY_REMOVE is now OFF===
 +
In preparation to switch to ITK 5.0, we disable legacy functionality in ITK. This might affect some modules which rely on ITK. Take a look at [https://itk.org/migrationv4 ITK 4 migration guide] before [https://github.com/InsightSoftwareConsortium/ITK/blob/master/Documentation/ITK5MigrationGuide.md ITK 5 migration guide].
 +
 
 +
===Slicer 4.9: vtkMRMLPlotDataNode renamed to vtkMRMLPlotSeriesNode===
 +
Plotting was improved in [https://github.com/Slicer/Slicer/commit/082edc40c this commit]
 +
 
 +
'''Replace this:'''
 +
 
 +
  vtkMRMLPlotDataNode
 +
 
 +
'''By this:'''
 +
  vtkMRMLPlotSeriesNode
 +
 
 +
===Slicer 4.9: CMake: Module MIDAS not available===
 +
 
 +
The test infrastructure of your project should be updated to use [https://cmake.org/cmake/help/latest/module/ExternalData.html ExternalData] built-in CMake module
 +
instead of the specific <tt>MIDAS</tt> module.
 +
 
 +
See EMSegment commit [http://viewvc.slicer.org/viewvc.cgi/Slicer3?view=revision&revision=17150 r17150] for an example of transition.
 +
 
 +
This means that instead of using <tt>midas_add_test</tt> with the <tt>MIDAS{path/to/file.ext.md5}</tt>
 +
syntax for addressing the test data, the function [https://cmake.org/cmake/help/latest/module/ExternalData.html#command:externaldata_add_test ExternalData_add_target] is used by
 +
specifying both <tt>DATA{path/to/file.ext}</tt> and a download target name.
 +
 
 +
'''Replace this:'''
 +
 
 +
  midas_add_test(NAME test1 COMMAND ...)
 +
  midas_add_test(NAME test2 COMMAND ...)
 +
 
 +
'''By this:'''
 +
 
 +
  ExternalData_add_test(EMSegmentData NAME test1 COMMAND ...)
 +
  ExternalData_add_test(EMSegmentData NAME test2 COMMAND ...)
 +
 
 +
  [...]
 +
 
 +
  ExternalData_add_target(EMSegmentData)
 +
 
 +
 
 +
A key difference with the former approaches is that instead of adding two tests (one named
 +
<tt><testName>_fetchData</tt> to downoad the data and one running the test command), only one
 +
test is added but a common download target is added at the end using [https://cmake.org/cmake/help/latest/module/ExternalData.html#command:externaldata_add_target ExternalData_add_target]
 +
function.
 +
 
 +
This means that test data can now be downloaded in parallel (and cached) at build time instead
 +
of testing time.
 +
 
 +
===Slicer 4.9: CMake: Module SlicerMacroCheckExternalProjectDependency not available===
 +
 
 +
Since the module was removed in [http://viewvc.slicer.org/viewvc.cgi/Slicer4?view=revision&revision=26992 r26992], consider updating
 +
your build system to use CMake module <code>ExternalProjectDependency</code>
 +
 
 +
===Slicer 4.9: CMake: Module SlicerMacroEmptyExternalProject not available===
 +
 
 +
Since the module was removed in [http://viewvc.slicer.org/viewvc.cgi/Slicer4?view=revision&revision=26991 r26991]
 +
 
 +
'''Replace this:'''
 +
 
 +
<pre>
 +
include(SlicerMacroEmptyExternalProject)
 +
 
 +
[...]
 +
 
 +
SlicerMacroEmptyExternalProject("${proj}" "${${proj}_DEPENDENCIES}")
 +
</pre>
 +
 
 +
'''By this:'''
 +
 
 +
<pre>
 +
include(ExternalProjectDependency)
 +
 
 +
[...]
 +
 
 +
ExternalProject_Add_Empty(${proj} DEPENDS ${${proj}_DEPENDENCIES})
 +
</pre>
 +
 
 +
===Slicer 4.9: CMake: Module SlicerBlockSetCMakeOSXVariables not available===
 +
 
 +
Since it was renamed to <tt>SlicerInitializeOSXVariables</tt> in [http://viewvc.slicer.org/viewvc.cgi/Slicer4?view=revision&revision=26982 r26982]
 +
 
 +
'''Replace this:'''
 +
 
 +
<pre>
 +
include(SlicerBlockSetCMakeOSXVariables)
 +
</pre>
 +
 
 +
'''By this:'''
 +
 
 +
<pre>
 +
include(SlicerInitializeOSXVariables)
 +
</pre>
 +
 
 +
===Slicer 4.9: Application: isRelease() function not available===
  
 
See [[#Slicer_4.8:_Application:_isRelease.28.29_function_not_available_or_deprecated]]
 
See [[#Slicer_4.8:_Application:_isRelease.28.29_function_not_available_or_deprecated]]
  
=== Slicer 4.9: slicer.util.getNode() raises exception if node not found ===
+
===Slicer 4.9: slicer.util.getNode() raises exception if node not found===
  
 
If slicer.util.getNode() is called and the node is not found then instead of just returning None (Slicer 4.8 behavior), the method now raises a MRMLNodeNotFoundException. This makes code debugging easier (the error is reported when it happens), and in general more consistent with Python conventions.
 
If slicer.util.getNode() is called and the node is not found then instead of just returning None (Slicer 4.8 behavior), the method now raises a MRMLNodeNotFoundException. This makes code debugging easier (the error is reported when it happens), and in general more consistent with Python conventions.
Line 68: Line 700:
  
 
The approach had few issues:
 
The approach had few issues:
* the name of the variable was confusing
+
 
* identifying a "stable release" only from a source tree revision was not enough. Indeed the environment defining a "release" is the one found on the build machines used to generate the installer.
+
*the name of the variable was confusing
* nightly build are also considered as release
+
*identifying a "stable release" only from a source tree revision was not enough. Indeed the environment defining a "release" is the one found on the build machines used to generate the installer.
 +
*nightly build are also considered as release
  
 
To address this, the CMake variable <tt>Slicer_RELEASE_TYPE</tt> was introduced. As of 2017-10-04, it can be set to <tt>Experimental</tt>, <tt>Nightly</tt>
 
To address this, the CMake variable <tt>Slicer_RELEASE_TYPE</tt> was introduced. As of 2017-10-04, it can be set to <tt>Experimental</tt>, <tt>Nightly</tt>
Line 113: Line 746:
  
 
<b>References:</b>
 
<b>References:</b>
* Changed introduced in [http://viewvc.slicer.org/viewvc.cgi/Slicer4?view=revision&revision=24891 r24891]
+
 
 +
*Changed introduced in [http://viewvc.slicer.org/viewvc.cgi/Slicer4?view=revision&revision=24891 r24891]
  
 
<b>Error message similar to:</b>
 
<b>Error message similar to:</b>
Line 131: Line 765:
  
 
Removes lines and/or refactor code
 
Removes lines and/or refactor code
 
  
  
Line 212: Line 845:
  
 
<b>References:</b>
 
<b>References:</b>
* http://www.slicer.org/slicerWiki/index.php/Documentation/Labs/Segmentations#vtkMRMLLabelMapVolumeNode_integration
+
 
* http://viewvc.slicer.org/viewvc.cgi/Slicer4?view=revision&revision=24291
+
*https://www.slicer.org/wiki/Documentation/Labs/Segmentations#vtkMRMLLabelMapVolumeNode_integration* http://viewvc.slicer.org/viewvc.cgi/Slicer4?view=revision&revision=24291
  
  
Line 241: Line 874:
 
<b>References:</b>
 
<b>References:</b>
  
* http://viewvc.slicer.org/viewvc.cgi/Slicer4?view=revision&revision=21592
+
*http://viewvc.slicer.org/viewvc.cgi/Slicer4?view=revision&revision=21592
* https://issues.slicer.org/view.php?id=2813
+
*https://issues.slicer.org/view.php?id=2813

Latest revision as of 14:55, 22 August 2023

Home < Documentation < Nightly < Developers < Tutorials < MigrationGuide < Slicer

Contents

Slicer backward incompatible changes

Slicer 5.3: Organization name and domain changed from NA-MIC to slicer.org

To address the inconsistency between organization name used for settings files and for macOS bundle identifier, the 3D Slicer application has updated the Slicer_ORGANIZATION_NAME from "NA-MIC" to "slicer.org" and Slicer_ORGANIZATION_DOMAIN from www.na-mic.org to slicer.org. At the time of this change, 3D Slicer is developed primarily by the Slicer community rather than the NA-MIC community. Distribution of 3D Slicer is hosted at slicer.org rather than at www.na-mic.org.

Slicer settings will now be under a Slicer directory location rather than NA-MIC. Please review the Settings File Location documentation for details about the settings location on various platforms.

Slicer 5.3: Removed Annotation module

Annotations module, which provides `vtkMRMLAnnotationROI` and `vtkMRMLAnnotationRuler` nodes have been deprecated since April 2021 and is to be removed in Slicer-4.3.

When a scene is loaded into Slicer that contains annotation nodes, they are converted to markup nodes: `vtkMRMLAnnotationROI` is converted to `vtkMRMLMarkupsROI`; and `vtkMRMLAnnotationRuler` is converted to `vtkMRMLMarkupsLine`. All Slicer core modules that previously used annotation nodes, now use markup nodes instead.

All extensions, too, need to be updated to use markup nodes instead of annotation nodes. For backward compatibility (so that the same extension can be used with current Slicer version and Slicer-4.2 and earlier versions), it is useful to keep the modules accept both markup and annotation nodes, but always create markup nodes by default.

Tips for updating a module to use markups:

  • In node selectors, wherever `vtkMRMLAnnotationROINode` is accepted, add `vtkMRMLMarkupsLineNode` _before_ it (so they are both accepted, but markups are preferred)
  • In node selectors, wherever `vtkMRMLAnnotationRuler` is accepted, add `vtkMRMLMarkupsLine` _before_ it (so they are both accepted, but markups are preferred)
  • For ROIs:
    • When only non-rotated ROIs are used: you can still use `GetXYZ()` and `GetRadiusXYZ()` methods work the same way for markups ROI
    • When ROIs are rotated, markups ROIs support built-in rotation and scaling, therefore it is recommended to use the `exportRoi.GetObjectToWorldMatrix()` method to get all the transforms (including the transform inside the markup node and any transforms applied using transform nodes) that are applied to the bounding box object (that has its center in the origin and its diameter returned by `GetSize()`).
  • For rulers:
    • Use `GetNthControlPointPosition(0)` and `GetNthControlPointPosition(1)` methods to get the endpoints of the line.
    • Use `GetNumberOfDefinedControlPoints()` method to check if both endpoints of the line are defined.
    • Use `GetMeasurement('length').GetValue()` to get the line length (or for the displayed string, with units: `getNode('L').GetMeasurement('length').GetValueWithUnitsAsPrintableString()`)

Slicer 5.0: API changes since 4.10

  • Removed protected method vtkMRMLModelDisplayableManager::FindPickedDisplayNodeFromMesh

Supporting only Python 3.6 and above

Slicer python code has been updated to support Python 3.6 and above syntax using pyupgrade to automatically update the syntax.

Install pyupgrade: PythonSlicer -m pip install pyupgrade

  • Running:
    • On 1 file: PythonSlicer -m pyupgrade --py36-plus MyPythonFile.py
    • On multiple files: Here is my pyupgrade-script.py written to automate running pyupgrade across all python files in the Slicer repo. It was run by PythonSlicer pyupgrade-script.py
# pyupgrade-script.py
import os
import subprocess

search_directory = "C:/Users/MyUserName/Documents/GitHub/Slicer"
for root, _, files in os.walk(search_directory):
  for file_item in files:
    file_path = os.path.join(root, file_item)
      if os.path.isfile(file_path) and file_path.endswith(".py"):
        subprocess.call(["PythonSlicer", "-m", "pyupgrade", "--py36-plus", file_path])

Python 2 to Python 3

Slicer core has been updated to only support Python 3.

C++ classes and python scripts have been updated to use idioms and constructs only available in Python 3.

Update to python scripts have been done leveraging the CLI provided by https://python-future.org by (1) iteratively applying each one of the associates "fixes", (2) reviewing associated changes and (3) updating as needed.

Updates specific to extensions are discussed in Documentation/Nightly/Developers/Tutorials/MigrationGuide#Slicer_5.0:_Python2_to_Python3

Interactor styles

Limitations of VTK widgets (editable points, lines, curves, etc.) prevented Slicer from having sophisticated user interaction in slice and 3D views. In Slicer5, we replaced VTK widgets with MRML widgets. These widgets are still VTK-based and somewhat similar to VTK widgets, but they operate directly on MRML nodes, they use direct method calls between widgets and their representation, and they use a more efficient and flexible event processing. Instead of hardcoding how viewers behave in response to interaction (mouse move, button click, keyboard, ...) events in an interactor style, all these events are translated to actions and performed in a MRML widget. Most modules are not expected to observe interactor events or styles directly, but if they did, then they may need to be updated accordingly.

  • vtkSliceViewInteractorStyle renamed to vtkMRMLSliceDViewInteractorStyle to reflect that it uses MRML classes directly.
  • vtkThreeDViewInteractorStyle renamed to vtkMRMLThreeDViewInteractorStyle to reflect that it uses MRML classes directly.

slicer.util functions

  • slicer.util.loadVolume (and other node load functions) now return the loaded node instead of a True/False flag. In case of an error, a RuntimeError exception is thrown.
    • Old way of loading a node and get it in a variable: volumeNode = slicer.util.loadVolume('path/to/volume.nrrd', returnNode=True)[1]
    • New way of loading a node and get it in a variable: volumeNode = slicer.util.loadVolume('path/to/volume.nrrd')

Markups

  • vtkCommand::Modified events are no longer invoked when control points are added/removed/modified to improve performance. Modules that need to know If a point position is modified need to add observers to vtkMRMLMarkupsNode::PointAddedEvent, vtkMRMLMarkupsNode::PointRemovedEvent, vtkMRMLMarkupsNode::PointModifiedEvent events. See example in Script repository.
  • vtkMRMLMarkupsNode::MarkupAddedEvent is renamed to PointPositionDefinedEvent. There is a similar event, vtkMRMLMarkupsNode::PointAddedEvent, which is called even when preview point is created.
  • vtkMRMLMarkupsNode::MarkupRemovedEvent is renamed to vtkMRMLMarkupsNode::PointPositionUndefinedEvent. There is a similar event, vtkMRMLMarkupsNode::PointRemovedEvent, which is called even when preview point is removed.
  • vtkMRMLMarkupsNode::NthMarkupModifiedEvent is replaced by vtkMRMLMarkupsNode::PointModifiedEvent
  • During placement of markups, a preview markup point is created. If number of already placed markup points needs to be determined then GetNumberOfDefinedControlPoints() method can be used.
  • GetDefaultMarkups...() and SetDefaultMarkups...() methods are removed. Instead default display node can be accessed by GetDefaultMarkupsDisplayNode() method and default values can be get/set in that class.
  • vtkMRMLMarkupsNode::GetNthMarkupSelected() is replaced by GetNthControlPointSelected()
  • vtkMRMLMarkupsNode::PointPositionDefinedEvent event is added. This event is invoked whenever position is defined for a new point.
  • vtkMRMLMarkupsNode::PointPositionUndefinedEvent event is added. This event is invoked whenever point with defined position is removed (point is deleted or its position gets undefined).
  • For more details, see vtkMRMLMarkupsNode

Segmentations

Binary labelmap segmentations can now be represented as shared labelmaps. The previous implementation of binary labelmaps was performance intensive as each labelmap was represented using a separate vtkDataObject. Visualizing and editing segmentations that contained a large number of segments could cause performance issues, due to the large number of vtkActors required, as well as calculating masks and overwriting other segments when editing.

By default, newly created segments will now be contained on the same layer. Segments will only be separated into multiple layers if the user creates an overlapping segment when editing.

Segments are now saved as a 4D volume with shared 3D layers. For a segmentation that only uses one layer, the resulting image is a 3D volume. Before saving, the labelmaps will be collapsed into as few layers as possible.

  • seg.nrrd files now contain two additional attributes for each segment: SegmentX_LabelValue and SegmentX_Layer
  • The label value of a segment can be found using vtkSegment::GetLabelValue()
  • Whether or not a segment is shared can be found using vtkSegmentation::IsSharedBinaryLabelmap()
  • The other segments sharing the same labelmap can be found using vtkSegmentation::GetSegmentIDsSharingBinaryLabelmapRepresentation()
  • Segment editor effects should generally use modifySelectedSegmentByLabelmap rather than SetBinaryLabelmapToSegment to manage layer separation
  • Conversion rules now call PreConvert() and PostConvert() before and after conversion to perform pre and post processing steps on the segmentation as a whole
  • The function signature for vtkSegmentationConverterRule::Convert now accepts a vtkSegment rather than two vtkDataObjects
  • slicer.util.arrayFromSegment has been deprecated. slicer.util.arrayFromSegmentBinaryLabelmap and slicer.util.arrayFromSegmentInternalBinaryLabelmap can be used instead
Erase the contents of a single segment
segmentation = segmentationNode.GetSegmentation()
segmentation.ClearSegment(segmentId)
Set labelmap in a segment

Directly, bypassing masking settings:

slicer.vtkSlicerSegmentationsModuleLogic.SetBinaryLabelmapToSegment(orientedImageDataToSet, segmentationNode, segmentId)
Move a segment from a shared labelmap to a separate layer
segmentation = segmentationNode.GetSegmentation()
segmentation.SeparateSegmentLabelmap(segmentId)
Combine all binary labelmaps to as few layers as possible
segmentation = segmentationNode.GetSegmentation()
segmentation.CollapseBinaryLabelmaps(forceToSingleLayer=false)

Get a read-only labelmap for a single segment:

labelmap = slicer.vtkOrientedImageData()
segmentationNode.GetBinaryLabelmapRepresentation(segmentId, labelmap)

(similarly, use GetClosedSurfaceRepresentation with an additional vtk.vtkPolyData parameter to get a read-only surface mesh)

or

labelmapNumpyArray = slicer.util.arrayFromSegmentBinaryLabelmap(segmentationNode, segmentId)
Get a modifiable shared labelmap
labelmap = slicer.vtkOrientedImageData()
segmentationNode.GetBinaryLabelmapInternalRepresentation(segmentId, labelmap)

(similarly, use GetClosedSurfaceInternalRepresentation to get a modifiable surface mesh)

or

labelmapNumpyArray = slicer.util.arrayFromSegmentInternalBinaryLabelmap(segmentationNode, segmentId)
Export segments to models

Model hierarchies no longer exist in Slicer5, but instead various kinds of hierarchies are now replaced by "subject hierarchy", which can accommodate any node types in a single hierarchy. Accordingly, `ExportSegmentsToModelHierarchy`, `ExportAllSegmentsToModelHierarchy`, etc. are replaced by `ExportSegmentsToModels`, `ExportAllSegmentsToModels`, which take a subject hierarchy folder item ID as input. Documentation/Nightly See code example in Script repository.

Smoothing effect

In Slicer-4.11 version before October 29, 2020 (and earlier versions), Gaussian smoothing method's Standard deviation parameter ("GaussianStandardDeviationMm") was interpreted in pixels, while on the user interface and code it was claimed to be in physical units (millimeter). The problem was fixed and now the parameter is in millimeter.

Volume rendering

vtkMRMLVolumeRenderingDisplayNode::SetAndObserveVolumeNodeID method was removed, as display node base class already maintains a pointer to the displayed (volume) node. To associate a volume display node with a volume node, call

volumeNode->AddAndObserveDisplayNodeID(volumeRenderingDisplayNode->GetID());

after both nodes are added to the scene.

vtkSlicerVolumeRenderingLogic::CreateDefaultVolumeRenderingNodes method unnecessarily polluted the scene with ROI node even though the user did not need cropping. In Slicer-5.x we fixed the issue by not creating the ROI nodes automatically. To create a ROI node, you can call vtkSlicerVolumeRenderingLogic::CreateROINode method.

Extract skeleton

Command-line arguments of the module have been updated: - output image is now optional, therefore the output image file name must be specified using "--outputImage" argument - output image centerline voxel value is set to 255 (instead of 1) to make it easier to apply image processing operations on it (values can be interpolated between 0 and 255, while there are no integer values between 0 and 1) - "--dontPrune" is renamed to "--fullTree" for clarity - centerline curve is saved in mrk.json format

MRML node copy API improvements

Slicer-4.10 and earlier had a single Copy() method, which had limitations: - usually implemented deep copy (but sometimes bulk data was just shallow-copied): problem, because for quick browsing of sequences, we need shallow-copy (to avoid copying bulk data, such as vtkImageData) - copied all node properties (except node ID and scene): this required workarounds, whenever we wanted to copy only the content of nodes (but for example keeping node references or node name intact)

In Slicer-4.11, these limitations are addressed, by implementing a CopyContent(vtkMRMLNode* node, bool deepCopy=true) method which allows choosing between deep/shallow copy (create an independent copy of bulk data or pass bulk data pointer) and does not copy node ID, Scene, Name, SingletonTag, HideFromEditors, AddToScene, UndoEnabled, and node references.

To make it easier to introduce this new method into existing classes, helper macros are implemented.

If a class implements CopyContent method then the developer must make sure that CopyContent and HasCopyContent methods are implemented in all parent classes by adding vtkMRMLCopyContentMacro(ClassName) or vtkMRMLCopyContentDefaultMacro(ClassName) to the class headers. vtkMRMLCopyContentDefaultMacro should be used when the class does not have any additional properties (only those that parent classes already copy). CopyContent must be implemented by calling CopyContent of the parent class, and then copy node properties added in he class (preferable using shallow copy for large data, if deepCopy argument was set to false).

If HasCopyContent macro is not added to a class then it cannot be recorded or replayed in Sequences module.

Removed classes

Classes removed due to removing legacy Editor module:

  • vtkITKNewOtsuThresholdImageFilter is replaced by vtkITKImageThresholdCalculator
  • vtkITKGrowCutSegmentationImageFilter is replaced by vtkImageGrowCutSegment (it will be replaced by the ITK implementation https://github.com/Slicer/Slicer/pull/5807)
  • vtkITKTimeSeriesDatabase was removed, it was an incomplete class, not used anywhere
  • vtkITKWandImageFilter was removed, vtkImageThresholdConnectivity (in VTK) can be used instead
  • vtkImageConnectivity was removed, vtkImageThresholdConnectivity (in VTK) can be used instead
  • vtkImageErode was removed, vtkImageDilateErode3D (in VTK) can be used instead
  • vtkImageLabelChange was removed, vtkImageThreshold (in VTK) can be used instead
  • vtkImageSlicePaint was replaced by logic built into qSlicerSegmentEditorPaintEffect
  • vtkImageStash is replaced by vtkSegmentationHistory
  • vtkPichonFastMarching moved to SegmentEditorExtraEffects extension (https://github.com/lassoan/SlicerSegmentEditorExtraEffects)

Classes removed due to removing Charts and DoubleArrays modules:

  • vtkMRMLChartNode is replaced by vtkMRMLPlotNode
  • vtkMRMLChartViewNode is replaced by vtkMRMLPlotViewNode
  • vtkMRMLDoubleArrayNode is replaced by vtkMRMLTableNode (can store any number of columns, not just two)
  • vtkMRMLDoubleArrayStorageNode is replaced by vtkMRMLTableStorageNode
  • qMRMLChartView is replaced by qMRMLPlotView
  • qMRMLChartViewControllerWidget is replaced by qMRMLPlotViewControllerWidget
  • qMRMLChartWidget is replaced by qMRMLPlotWidget

Slicer 5.0: Fiducial List was renamed to Point List

To simplify terms used in Slicer, "Fiducial List" term was renamed to "Point List" on the user interface. The term in the API has not been changed to preserve backward compatibility.

See discussion of the topic here.

Slicer 5.0: SliceIntersectionVisibility was moved from vtkMRMLSliceCompositeNode to vtkMRMLSliceDisplayNode

SliceIntersectionVisibility property (that controls if intersections of other slices should be displayed in the slice view) was stored in vtkMRMLSliceCompositeNode. This was not a good choice because the composite node stores what image layers should be displayed in the slice view and how (what opacity, what blending method, etc.). The property was kept in that class for a long time to preserve backward compatibility, but when interactive slice intersection feature was added and additional properties had to be added that control appearance and behavior of slice intersections, this property was moved into the new vtkMRMLSliceDisplayNode node type and renamed to IntersectingSlicesVisibility.

Scripts that previously used SliceIntersectionVisibility property will now fail with this error:

  AttributeError: 'MRMLCore.vtkMRMLSliceCompositeNode' object has no attribute 'SetSliceIntersectionVisibility'

Those failing scripts can be updated with this example in the script repository: https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html#turn-on-slice-intersections

Slicer 5.0: SlicerPython was removed. Use PythonSlicer instead

Error message:

SlicerPython executable is obsolete and will be removed. Use PythonSlicer executable instead.
For more details, see https://github.com/Slicer/Slicer/issues/4843

Solution:

Use PythonSlicer instead of SlicerPython

Background:

Python IDEs (specifically PyCharm, but potentially others) only recognize Python*.exe files as Python interpreters.

To allow using Slicer's Python interpreter in these IDEs, we had to add PythonSlicer, but kept SlicerPython around for not immediately breaking things.

This redundancy is confusing for users that we could resolve by simply removing SlicerPython for Slicer5.

References:

https://github.com/Slicer/Slicer/issues/4843

Slicer 5.0: Application must be installed in writable location to install extensions

Extensions are now installed in the application home folder because Python packages are installed there anyway, so the application home folder has to be writable (or Slicer has to be run as admin when you install extensions). It also allows making Slicer fully portable - see details here.

If you want to allow any user to install extensions without admin rights and you only need to use extensions that don’t install Python packages at runtime then you can specify a custom extension install path folder in Slicer-NNN.ini file or revert to the old behavior of Slicer by specifying Slicer_STORE_SETTINGS_IN_APPLICATION_HOME_DIR:BOOL=OFF when configuring your Slicer build.

Slicer 5.0: Models are saved in LPS coordinate system by default

While Slicer uses RAS coordinate system internally, images, transforms, and markups files are stored in LPS coordinate system, because DICOM and all medical image computing software (maybe except a few very old ones) uses LPS coordinate system in files.

However, Slicer has been still using its internal RAS coordinate system in mesh files (STL, VTK, VTP, OBJ, PLY), which caused issues when interfacing with third-party software.

From Slicer-4.11.0-2020-02-26 (revision 28794) models are saved in LPS coordinate system, and mesh files assumed to be in LPS coordinate system by default (if no other coordinate system specified in the file).

Slicer started embedding coordinate system name in mesh files a few years ago (see SPACE=RAS in the file header), so all the files that Slicer saved in recent years will load correctly and any scene files created with any version of Slicer will also load the models with correct orientation, too.

Manual setting of coordinate system (in Add data dialog / Options column) is only needed when loading a mesh file without a scene that were created by Slicer-4.6 (2017-09-27) and earlier; and obj files created by Slicer-4.6 and Slicer-4.8 (between 2016-10-11 and 2018-03-26), or files are created by third-party software in RAS coordinate system.

If you encounter orientation issues when loading a model file, you have the following options:

  • Option A: Specify the coordinate system when you open the model file. In “Add data” dialog, click “Show Options” and then choose “RAS” as coordinate system.
  • Option B: Update the third-party software that generate the mesh to save coordinates in LPS coordinate system instead of RAS coordinate system. Conversion is simple inverting the sign of the first two coordinates.
  • Option C: Write SPACE=RAS in the comment/description field in the mesh file (for STL, OBJ, PLY, VTK file; for VTP files, add in the first value of a vtkStringArray field array named SPACE) to indicate that the values are stored in RAS coordinate system. This option is useful if coordinates have to be stored in RAS coordinate system (for example, for compatibility with other software). See implementation example here.

See more information, discussion of this topic on the Slicer forum.

Slicer 5.0: CLI module descriptor XML files assume LPS coordinate system by default

If SlicerExecutionModel descriptor XML file of a CLI module does not specify coordinate system for a point, pointfile, or region element then the coordinate system is assumed to be "lps". To preserve previous behavior and use "ras" coordinate system instead, add coordinateSystem="ras" to the element.

Slicer 5.0: Sequences extension has been merged into Slicer core

Sequences extension has been merged into Slicer core, therefore extensions do not need to depend on Sequences extension anymore.

SequenceBrowser module has been merged into Sequences module, therefore previous code that used SequenceBrowser module now should use Sequences module instead.

Slicer 5.0: FreeSurfer support has been removed from Slicer core

The loading of FreeSurfer models and scalar overlays, as well as the FreeSurfer-specific color nodes, have been moved to the new SlicerFreeSurfer extension. Tutorials on how to use the FreeSurfer Importer module to load multiple files at once can be found on the SlicerFreeSurfer tutorial page.

Slicer 5.0: Removed Editor module

The legacy Editor module has been deprecated since about 2017 and got removed in November 2021. It is replaced by the much improved Segment Editor module.

Slicer 5.0: Removed Charts and DoubleArrays module

Charts and DoubleArrays module have been deprecated since about 2018 and got removed in November 2021. They are replaced by Plots and Tables modules.

Example of commits

Slicer 5.0 : Avoid typedef of anonymous structure

Due to a recent (but retroactive) C++ rule change, only sufficiently C-compatible classes are permitted to be given a typedef name for linkage purposes. Add an enabled-by-default warning for these cases, and rephrase our existing error for the case where we encounter the typedef name for linkage after we've already computed and used a wrong linkage in terms of the new rule.

To fix warning message similar to:

Slicer/Libs/MRML/Core/vtkMRMLTableStorageNode.h:95:17:
warning: anonymous non-C-compatible type given name for linkage purposes by typedef declaration; add a tag name here [-Wnon-c-typedef-for-linkage]
  typedef struct
                ^
                ColumnInfo
Slicer/Libs/MRML/Core/vtkMRMLTableStorageNode.h:99:5:
note: type is not C-compatible due to this default member initializer
    int ScalarType = VTK_STRING;
    ^~~~~~~~~~~~~~
Slicer/Libs/MRML/Core/vtkMRMLTableStorageNode.h:102:5:
note: type is given name 'ColumnInfo' for linkage purposes by this typedef declaration
  } ColumnInfo;
    ^
For consistency, Use 'using' to a named structure definintion for all 
structures.

Replace code like this:

  typedef struct
  {
    std::string ColumnName;
    std::vector<vtkAbstractArray*> RawComponentArrays;
    int ScalarType = VTK_STRING;
    std::vector<std::string> ComponentNames;
    std::string NullValueString;
  } ColumnInfo;

By this:

  struct StructColumnInfo
  {
    std::string ColumnName;
    std::vector<vtkAbstractArray*> RawComponentArrays;
    int ScalarType = VTK_STRING;
    std::vector<std::string> ComponentNames;
    std::string NullValueString;
  };
  using ColumnInfo = struct StructColumnInfo;


References:

https://reviews.llvm.org/D74103

Slicer 5.0 : Temporary path

Temporary path was stored redundantly application settings (Slicer.ini) in two keys: Modules/TemporaryDirectory and TemporaryPath. Modules/TemporaryDirectory overwrote TemporaryPath at startup, but when temporary path was set via the slicer.app.temporaryPath then it was only written to TemporaryPath.

Changed behavior so that only TemporaryPath is used. Modules/TemporaryDirectory is ignored.

To ensure that temporary path is always writable, it as checked at startup that a file can be created in temporary path and if this check fails then temporary path is reset to default (QDir::tempPath()).

Slicer 5.0 : Always prefer executable CLIs

Previously, if a CLI module was available both as an executable and a shared library, then PreferExecutableCLI application setting was used to determine which one is used. Now always CLIs are always executed in an external process (if an executable is available). Reasons are described in this issue: https://github.com/Slicer/Slicer/issues/4893. The application setting is no more displayed in the GUI and any setting specified in earlier Slicer versions is ignored.

Slicer 5.0 : SlicerApp-real is a console application on Windows

Previously, the application (SlicerApp-real.exe) was built as a GUI application (without console) on Windows, to avoid displaying a terminal window when starting the application. This had the drawback that the Slicer application did not have standard input/output that could be displayed or redirected (for example, for capturing into a file). SlicerApp-real has always been a console application on Linux and macOS, therefore this change makes the software behavior more consistent across platforms.

SlicerApp-real.exe is now built as a console application (see #2934). Displaying of a terminal window is prevented by using a launcher (Slicer.exe) that is built as a GUI application and it starts Slicer with the standard input and outputs redirected.

To display console output: https://slicer.readthedocs.io/en/latest/developer_guide/debugging/overview.html#console-output-on-windows

To launch a command-line terminal using subprocess.Popen that shows a new terminal, specify creationflags=subprocess.CREATE_NEW_CONSOLE argument.

Slicer 4.11: Variable CMAKE_DEFAULT_BUILD_TYPE renamed to Slicer_DEFAULT_BUILD_TYPE

Setting the default build type for single config generator may be done setting Slicer_DEFAULT_BUILD_TYPE instead of CMAKE_DEFAULT_BUILD_TYPE.

Error message similar to:

  CMake Error:
     Generator

       Visual Studio 15 2017

     does not support variable

       CMAKE_DEFAULT_BUILD_TYPE

     but it has been specified.

References:

https://github.com/Slicer/Slicer/pull/4799

Slicer 4.11: teem python module renamed to vtkTeem, explicit import required

  • Since the module provides VTK classes interfacing with "teem", the name is now representative of the class it contains.
  • vtkTeem classes are expected to be used by explicitly importing the module.

Replace code like this:

import teem

class CalculateTensorScalars(object):
  def __init__(self):
    self.dti_math = teem.vtkDiffusionTensorMathematics()

By this:

import vtkTeem

class CalculateTensorScalars(object):
  def __init__(self):
    self.dti_math = vtkTeem.vtkDiffusionTensorMathematics()

Slicer 4.11: Display window/level (brightness/contrast) adjustment

  • A new "Window/level" mouse interaction mode was introduced. Volume display window/level can only be changed if this mode is activated by clicking the corresponding button in the toolbar. The new mouse mode prevents accidental modification of volume window/level (when for example the user accidentally clicked too far from a markup) and it also allows more sophisticated window/level adjustments.
  • New region-based auto window/level feature added: activate "Window/level" mouse mode and use Ctrl + left-click-and-drag to highlight a region and optimize window/level for that (pressing Escape or right-click cancels the operation).
  • Auto window/level reset: activate "Window/level" mouse mode and double-click the left mouse button.
  • Improved auto window/level algorithm to prevent too bright display of images. Window/level is set to display values between 0.1th and 99.9th percentile of gray levels. See details here: https://discourse.slicer.org/t/feedback-requested-how-to-improve-mouse-interaction-in-views/6420.
  • Removed class vtkImageBimodalAnalysis

Slicer 4.10: Registration of runTest function done in ScriptedLoadableModule base class

Following r27617:

  • the ScriptedLoadableModule class takes care of registering the runTest function.
  • the runTest function expects msec keyword argument.

Error message similar to:

Traceback (most recent call last):
  File "/path/to/Slicer-SuperBuild/Slicer-build/bin/Python/slicer/ScriptedLoadableModule.py", line 205, in onReloadAndTest
    test(msec=int(slicer.app.userSettings().value("Developer/SelfTestDisplayMessageDelay")), **kwargs)
TypeError: runTest() got an unexpected keyword argument 'msec'
Reload and Test: Exception!

runTest() got an unexpected keyword argument 'msec'

Replace code like this:

class sceneImport2428(ScriptedLoadableModule):
  [...]
  def __init__(self, parent):
    ScriptedLoadableModule.__init__(self, parent)
    parent.title = "..."
    [...]
    parent.acknowledgementText = "..."
    self.parent = parent 	 
	  	 
    # Add this test to the SelfTest module's list for discovery when the module 	 
    # is created.  Since this module may be discovered before SelfTests itself, 	 
    # create the list if it doesn't already exist. 	 
    try: 	 
      slicer.selfTests 	 
    except AttributeError: 	 
      slicer.selfTests = {} 	 
    slicer.selfTests['sceneImport2428'] = self.runTest 	 
 
  def runTest(self): 	 
    tester = sceneImport2428Test() 	 
    tester.runTest()

  [...]

By this:

class sceneImport2428(ScriptedLoadableModule):
  [...]
  def __init__(self, parent):
    ScriptedLoadableModule.__init__(self, parent)
    parent.title = "..."
    [...]
    parent.acknowledgementText = "..."

  [...]

Slicer 4.9: Update of VTK version from 9.0 to 8.2

Following kitware/VTK@b703d78be, VTK has updated to use version number 8.2 instead of 9.0. This was discussed in on the VTK mailing list in http://vtk.1045678.n5.nabble.com/Discussion-OK-to-change-VTK-s-version-number-from-9-0-to-8-2-tt5748702.html

At first, this VTK commit and its companion kitware/VTK@8a00b357e were both reverted from the Slicer/VTK fork. Then, since having the corresponding changes reverted in VTK was not possible, it was decided to also update Slicer. This was done in the following commits:

  • r27472: COMP: Update c++ classes to support building against VTK >= 9 and VTK >= 8.2
  • r27473: COMP: Update VTK to include version change from 9.0 to 8.2. Fixes #4623

This means that code depending on VTK must also be updated to include similar fixes.

Replace this:

 #if VTK_MAJOR_VERSION >= 9

By this:

 #if VTK_MAJOR_VERSION >= 9 || (VTK_MAJOR_VERSION >= 8 && VTK_MINOR_VERSION >= 2)

and

Replace this:

 #if VTK_MAJOR_VERSION < 9

By this:

 #if VTK_MAJOR_VERSION <= 7 || (VTK_MAJOR_VERSION <= 8 && VTK_MINOR_VERSION <= 1)


Slicer 4.9: ITK_LEGACY_REMOVE is now OFF

In preparation to switch to ITK 5.0, we disable legacy functionality in ITK. This might affect some modules which rely on ITK. Take a look at ITK 4 migration guide before ITK 5 migration guide.

Slicer 4.9: vtkMRMLPlotDataNode renamed to vtkMRMLPlotSeriesNode

Plotting was improved in this commit

Replace this:

 vtkMRMLPlotDataNode

By this:

 vtkMRMLPlotSeriesNode

Slicer 4.9: CMake: Module MIDAS not available

The test infrastructure of your project should be updated to use ExternalData built-in CMake module instead of the specific MIDAS module.

See EMSegment commit r17150 for an example of transition.

This means that instead of using midas_add_test with the MIDAS{path/to/file.ext.md5} syntax for addressing the test data, the function ExternalData_add_target is used by specifying both DATA{path/to/file.ext} and a download target name.

Replace this:

 midas_add_test(NAME test1 COMMAND ...)
 midas_add_test(NAME test2 COMMAND ...)

By this:

 ExternalData_add_test(EMSegmentData NAME test1 COMMAND ...)
 ExternalData_add_test(EMSegmentData NAME test2 COMMAND ...)
 
 [...]
 
 ExternalData_add_target(EMSegmentData)


A key difference with the former approaches is that instead of adding two tests (one named <testName>_fetchData to downoad the data and one running the test command), only one test is added but a common download target is added at the end using ExternalData_add_target function.

This means that test data can now be downloaded in parallel (and cached) at build time instead of testing time.

Slicer 4.9: CMake: Module SlicerMacroCheckExternalProjectDependency not available

Since the module was removed in r26992, consider updating your build system to use CMake module ExternalProjectDependency

Slicer 4.9: CMake: Module SlicerMacroEmptyExternalProject not available

Since the module was removed in r26991

Replace this:

include(SlicerMacroEmptyExternalProject)

[...]

SlicerMacroEmptyExternalProject("${proj}" "${${proj}_DEPENDENCIES}")

By this:

include(ExternalProjectDependency)

[...]

ExternalProject_Add_Empty(${proj} DEPENDS ${${proj}_DEPENDENCIES})

Slicer 4.9: CMake: Module SlicerBlockSetCMakeOSXVariables not available

Since it was renamed to SlicerInitializeOSXVariables in r26982

Replace this:

include(SlicerBlockSetCMakeOSXVariables)

By this:

include(SlicerInitializeOSXVariables)

Slicer 4.9: Application: isRelease() function not available

See #Slicer_4.8:_Application:_isRelease.28.29_function_not_available_or_deprecated

Slicer 4.9: slicer.util.getNode() raises exception if node not found

If slicer.util.getNode() is called and the node is not found then instead of just returning None (Slicer 4.8 behavior), the method now raises a MRMLNodeNotFoundException. This makes code debugging easier (the error is reported when it happens), and in general more consistent with Python conventions.

How to update existing code:

It is advisable to only use slicer.util.getNode in tests, or interactively in the Python console, as its behavior is somewhat unpredictable (it may either found a node by name or ID, and result of wildcard search is even less deterministic). In general, it is recommended to use the MRML scene's GetFirstNodeByName and GetNodeByID methods instead.

Replace this:

n = slicer.util.getNode(nodeNameOrID)

By one of these:

If node is to be found by name:

  n = slicer.mrmlScene.GetFirstNodeByName(nodeName)

If node is to be found by ID:

  n = slicer.mrmlScene.GetNodeByID(nodeID)

If node is to be found by name or ID (slower, less predictable, recommended for testing only):

try:
  n = slicer.util.getNode(nodeNameOrID)
except slicer.util.MRMLNodeNotFoundException:
  n = None

More information: https://github.com/Slicer/Slicer/commit/b63484af1b1b413f35396f8f7efb73e870448bd4

Slicer 4.8: Application: isRelease() function not available or deprecated

Error message similar to:

   Missing/deprecated qSlicerCoreApplication::isRelease()

or

   Missing/deprecated slicer.app.isRelease()


Solution:

Use qSlicerCoreApplication::releaseType() == "Stable"

Summary:

Prior to r26420, the variable Slicer_VERSION_TWEAK was used to check if a "stable release" was built. The variable value was set by updating the sources and defining the variable to an integer greater or equal to 0. In other word, if the variable evaluated to an empty string, a nighty or experimental build was being done, if it evaluated to an integer, a stable release build was being done.

The approach had few issues:

  • the name of the variable was confusing
  • identifying a "stable release" only from a source tree revision was not enough. Indeed the environment defining a "release" is the one found on the build machines used to generate the installer.
  • nightly build are also considered as release

To address this, the CMake variable Slicer_RELEASE_TYPE was introduced. As of 2017-10-04, it can be set to Experimental, Nightly or Stable with Experimental being the value hard-coded in the source.

Identifying a build as "stable" is now explicitly done by setting Slicer_RELEASE_TYPE to Stable at configure time.

Also, since the concept of release types was introduced, the function isRelease() has been removed in favor of releaseType().

References:

https://github.com/Slicer/Slicer/pull/354

Slicer Python Module: modulewidget and others removed.

Summary Python classes formerly in "slicer.moduledm", "slicer.modulelogic", "slicer.modulemrml" and "slicer.modulewidget" are now directly available in the slicer module.

See example of change here.

Rational:

See comments in commit messages referenced blow.

References:

https://github.com/Slicer/Slicer/commit/628f83fe7a6f4e0710e306bcaf7c04b9e3e5e6bd

https://github.com/Slicer/Slicer/commit/9cb5668fde1abc8f0430a91ca37fc29277ceeb4e

MRML: Slicer 4.6: Moved up vtkMRMLStorableNode in the MRML node hierarchy.

Rational:

vtkMRMLStorableNode is not a children of vtkMRMLTransformable node anymore, but directly a children of vtkMRMLNode.

This allows making a node storable without requiring it to be also transformable. It is important for several node types (color maps, tables, etc), which require separate storage node but are not transformable.

References:

Error message similar to:

   /tmp/LongitudinalPETCT/MRML/vtkMRMLLongitudinalPETCTStudyNode.cxx: In member function ‘void vtkMRMLLongitudinalPETCTStudyNode::ObserveRegistrationTransform(bool)’:
   /tmp/LongitudinalPETCT/MRML/vtkMRMLLongitudinalPETCTStudyNode.cxx:478:28: error: ‘class vtkMRMLVolumePropertyNode’ has no member named ‘GetParentTransformNode’
                  && propNode->GetParentTransformNode()
                               ^
   /tmp/LongitudinalPETCT/MRML/vtkMRMLLongitudinalPETCTStudyNode.cxx:480:23: error: ‘class vtkMRMLVolumePropertyNode’ has no member named ‘SetAndObserveTransformNodeID’
                propNode->SetAndObserveTransformNodeID(
                          ^
   /tmp/LongitudinalPETCT/MRML/vtkMRMLLongitudinalPETCTStudyNode.cxx:503:23: error: ‘class vtkMRMLVolumePropertyNode’ has no member named ‘SetAndObserveTransformNodeID’
                propNode->SetAndObserveTransformNodeID(NULL);
                          ^

Solution:

Removes lines and/or refactor code


MRML: Slicer 4.5: Introduction of vtkMRMLLabelMapVolumeNode

Rational:

Before vtkMRMLScalarVolumeNode was used for both scalar and label map volumes and the LabelMap custom MRML node attribute was used for distinguishing between them (0=scalar; 1=label map volume).

This made conversion between labelmap/scalar volumes very easy but made it difficult to customize behavior, display, processing of segmentation information.

Now a new vtkMRMLLabelMapVolumeNode class is used for storing segmentation information (still using vtkMRMLScalarVolume used as base class for backward compatibility; but in the future the base class may be changed to reflect that segmentation can be represented in various ways, not just as volumes).

Error message similar to:

 error: ‘class vtkMRMLScalarVolumeNode’ has no member named ‘SetLabelMap’
    outputVolumeNode->SetLabelMap(1);
                      ^

Solution (part1: down cast to vtkMRMLLabelMapVolumeNode, remove call to SetLabelMap)

Replace lines like:

    vtkMRMLNode* outputNode = d->OutputLabelVolumeMRMLNodeComboBox->currentNode();
    vtkMRMLScalarVolumeNode* outputVolumeNode = vtkMRMLScalarVolumeNode::SafeDownCast(outputNode);
    [...]
    outputVolumeNode->SetLabelMap(1);


with:

    vtkMRMLLabelMapVolumeNode* outputVolumeNode =
      vtkMRMLLabelMapVolumeNode::SafeDownCast(d->OutputLabelVolumeMRMLNodeComboBox->currentNode());
    [...]


Solution (part2: Update UI file):

Replace lines like:

 <widget class="qMRMLNodeComboBox" name="InputLabelVolumeMRMLNodeComboBox">
  <property name="nodeTypes">
   <stringlist>
    <string>vtkMRMLScalarVolumeNode</string>
   </stringlist>
  </property>
  [...]
 </widget>

with:

 <widget class="qMRMLNodeComboBox" name="InputLabelVolumeMRMLNodeComboBox">
  <property name="nodeTypes">
   <stringlist>
    <string>vtkMRMLLabelMapVolumeNode</string>      <------------- Update Here
   </stringlist>
  </property>
  [...]
 </widget>


Solution (part3: Update node selector configuration):

Replace lines like:

 nodeSelector.setNodeTypes(QStringList("vtkMRMLScalarVolumeNode"));
 nodeSelector.addAttribute("vtkMRMLScalarVolumeNode", "LabelMap", "1");

with:

 nodeSelector.setNodeTypes(QStringList("vtkMRMLLabelMapVolumeNode"));


References:


CLI: Slicer 4.3: Add ITKFactoryRegistration library centralizing ITK IO factory registration

Rational:

 Linking against ITKFactoryRegistration ensures that ITK IO factory are properly registered on all supported platforms.

Error message similar to:

 Undefined symbols for architecture x86_64:
 "itk::itkFactoryRegistration()", referenced from:
 _main in ImageMakerTest.cxx.o
 ld: symbol(s) not found for architecture x86_64

Solution:

Replace lines like:

 target_link_libraries(${CLP}Test ${CLP}Lib)

with:

 target_link_libraries(${CLP}Test ${CLP}Lib ${SlicerExecutionModel_EXTRA_EXECUTABLE_TARGET_LIBRARIES})

References: