Difference between revisions of "Documentation/Nightly/Developers/Tutorials/MigrationGuide/ITK4-to-ITK5"

From Slicer Wiki
Jump to: navigation, search
 
(6 intermediate revisions by 2 users not shown)
Line 2: Line 2:
 
This section lists categories of code changes necessary to build Slicer with ITK 5. Each category has a short description, an example error message, a suggested upgrade path, and references to relevant commits.
 
This section lists categories of code changes necessary to build Slicer with ITK 5. Each category has a short description, an example error message, a suggested upgrade path, and references to relevant commits.
  
Referencing this list might be helpful if Slicer extensions require updates to be compatible with ITK 5.
+
Referencing this list might be helpful if Slicer extensions requiring updates to be compatible with ITK 5.
  
Also check the ITK migration guide if more info is needed:
+
Make also sure to read through the [https://github.com/InsightSoftwareConsortium/ITK/blob/master/Documentation/ITK5MigrationGuide.md ITK 5 migration guide].
* https://github.com/InsightSoftwareConsortium/ITK/blob/master/Documentation/ITK5MigrationGuide.md (ITKv5 Migration Guide)
+
 
 +
[https://github.com/InsightSoftwareConsortium/ITK/tree/master/Utilities/ITKv5Preparation Utilities/ITKv5Preparation] directory contains bash scripts which have been used to update ITK to version 5. These scripts can assist with updating external code bases to ITK 5 content and style.
 +
 
 +
===Upgrading to ITKv5 or keep using ITKv4 GenerateThreadedData===
 +
If the ThreadedGenerateData does not use threadId, change the name of the function to DynamicThreadedGenerateData
 +
Replace:
 +
<pre>
 +
  void ThreadedGenerateData( const OutputRegionType& threadRegion, ThreadIdType threadId )
 +
</pre>
 +
with:
 +
<pre>
 +
  void DynamicThreadedGenerateData( const OutputRegionType& threadRegion )
 +
</pre>
 +
 
 +
If you want to keep using the ITKv4 thread system (with ThreadedGenerateData), add to the constructor of your ITK class:
 +
<pre>
 +
  this->DynamicMultiThreadingOff();
 +
</pre>
  
 
===itkMultiThreader refactor===
 
===itkMultiThreader refactor===
  
 
Replace lines like:
 
Replace lines like:
 +
<pre>
 
   #include <itkMultiThreader.h>
 
   #include <itkMultiThreader.h>
 +
 
   itk::MultiThreader::Pointer ProcessingThreader;
 
   itk::MultiThreader::Pointer ProcessingThreader;
 +
 +
  ITK_THREAD_RETURN_TYPE
 +
 +
  ITK_THREAD_RETURN_VALUE
 +
 +
  SetNumberOfThreads()
 +
</pre>
  
 
with:
 
with:
 +
<pre>
 
   #include <itkPlatformMultiThreader.h>
 
   #include <itkPlatformMultiThreader.h>
 +
 
   itk::PlatformMultiThreader::Pointer ProcessingThreader;
 
   itk::PlatformMultiThreader::Pointer ProcessingThreader;
 +
 +
  itk::ITK_THREAD_RETURN_TYPE
 +
 +
  itk::ITK_THREAD_RETURN_DEFAULT_VALUE
 +
 +
  SetNumberOfWorkUnits()
 +
</pre>
  
 
===SimpleFastMutexLock, FastMutexLock and MutexLock are deprecated===
 
===SimpleFastMutexLock, FastMutexLock and MutexLock are deprecated===
Line 22: Line 57:
  
 
Replace:
 
Replace:
 +
<pre>
 
   #include "itkSimpleFastMutexLock.h"
 
   #include "itkSimpleFastMutexLock.h"
 
   #include "itkFastMutexLock.h"
 
   #include "itkFastMutexLock.h"
 
   #include "itkMutexLock.h"
 
   #include "itkMutexLock.h"
 +
 
   SimpleFastMutexLock
 
   SimpleFastMutexLock
 
   FastMutexLock
 
   FastMutexLock
 
   MutexLock
 
   MutexLock
  
with:
+
   m_Lock->Lock();
   #include <mutex>
+
   m_Lock->Unlock();
  std::mutex
 
 
 
===Dead code after update to Qt >= 5.6.0===
 
 
 
Remove any branch checking of QT_VERSION lesser than 5.6.0
 
<pre>
 
  #include <QtGlobal>
 
  #if(QT_VERSION < QT_VERSION_CHECKS(5, 6, 0))
 
   // Obsolete Qt4 code
 
  #include <QDesignerCustomWidgetInterface>
 
  #else
 
  // Qt5 code
 
  #include <QtUiPlugin/QDesignerCustomWidgetInterface>
 
  #endif
 
 
 
  [...]
 
 
 
  class Q_SLICER_MODULE_SEGMENTATIONS_WIDGETS_PLUGINS_EXPORT qSlicerSegmentationsModuleWidgetsAbstractPlugin
 
      : public QDesignerCustomWidgetInterface
 
  {
 
  #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
 
    Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QDesignerCustomWidgetInterface")
 
  #endif
 
    Q_INTERFACES(QDesignerCustomWidgetInterface);
 
  }
 
 
</pre>
 
</pre>
  
After cleaning:
+
with:
 
 
 
<pre>
 
<pre>
   #include <QtUiPlugin/QDesignerCustomWidgetInterface>
+
   #include <mutex>
  
   [...]
+
   std::mutex
  
   class Q_SLICER_MODULE_SEGMENTATIONS_WIDGETS_PLUGINS_EXPORT qSlicerSegmentationsModuleWidgetsAbstractPlugin
+
   m_Lock.lock();
      : public QDesignerCustomWidgetInterface
+
   m_Lock.unlock();
   {
 
    Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QDesignerCustomWidgetInterface")
 
    Q_INTERFACES(QDesignerCustomWidgetInterface);
 
  }
 
 
</pre>
 
</pre>
 
====Python====
 
 
This migration guide points becomes obsolete:
 
[[Documentation/Nightly/Developers/Tutorials/MigrationGuide#Qt5:_Fix_error:_.E2.80.98class_QHeaderView.E2.80.99_has_no_member_named_.E2.80.98setResizeMode.E2.80.99]]
 
 
Only Qt5 needs to be supported, so the following code can be simplified:
 
 
Before:
 
  _setSectionResizeMode(self.horizontalHeader(), 0, qt.QHeaderView.Stretch)
 
  def _setSectionResizeMode(header, *args, **kwargs):
 
    if version.parse(qt.Qt.qVersion()) < version.parse("5.0.0"):
 
      header.setResizeMode(*args, **kwargs)
 
    else:
 
      header.setSectionResizeMode(*args, **kwargs)
 
 
After:
 
  self.horizontalHeader(0, qt.QHeaderView.Stretch)
 

Latest revision as of 06:30, 1 May 2019

Home < Documentation < Nightly < Developers < Tutorials < MigrationGuide < ITK4-to-ITK5

Transition from ITK4 to ITK5

This section lists categories of code changes necessary to build Slicer with ITK 5. Each category has a short description, an example error message, a suggested upgrade path, and references to relevant commits.

Referencing this list might be helpful if Slicer extensions requiring updates to be compatible with ITK 5.

Make also sure to read through the ITK 5 migration guide.

Utilities/ITKv5Preparation directory contains bash scripts which have been used to update ITK to version 5. These scripts can assist with updating external code bases to ITK 5 content and style.

Upgrading to ITKv5 or keep using ITKv4 GenerateThreadedData

If the ThreadedGenerateData does not use threadId, change the name of the function to DynamicThreadedGenerateData Replace:

  void ThreadedGenerateData( const OutputRegionType& threadRegion, ThreadIdType threadId )

with:

  void DynamicThreadedGenerateData( const OutputRegionType& threadRegion )

If you want to keep using the ITKv4 thread system (with ThreadedGenerateData), add to the constructor of your ITK class:

  this->DynamicMultiThreadingOff();

itkMultiThreader refactor

Replace lines like:

  #include <itkMultiThreader.h>

  itk::MultiThreader::Pointer ProcessingThreader;

  ITK_THREAD_RETURN_TYPE

  ITK_THREAD_RETURN_VALUE

  SetNumberOfThreads()

with:

  #include <itkPlatformMultiThreader.h>

  itk::PlatformMultiThreader::Pointer ProcessingThreader;

  itk::ITK_THREAD_RETURN_TYPE

  itk::ITK_THREAD_RETURN_DEFAULT_VALUE

  SetNumberOfWorkUnits()

SimpleFastMutexLock, FastMutexLock and MutexLock are deprecated

Instead use std::mutex available in C++11

Replace:

  #include "itkSimpleFastMutexLock.h"
  #include "itkFastMutexLock.h"
  #include "itkMutexLock.h"

  SimpleFastMutexLock
  FastMutexLock
  MutexLock

  m_Lock->Lock();
  m_Lock->Unlock();

with:

  #include <mutex>

  std::mutex

  m_Lock.lock();
  m_Lock.unlock();