]> Creatis software - clitk.git/commitdiff
Change itkSimpleFastMutexLock to std::mutex
authortbaudier <thomas.baudier@creatis.insa-lyon.fr>
Fri, 15 Feb 2019 15:43:37 +0000 (16:43 +0100)
committertbaudier <thomas.baudier@creatis.insa-lyon.fr>
Fri, 15 Feb 2019 15:54:53 +0000 (16:54 +0100)
This is mandatory with ITK5 and c++11

The filters created an itk::Image<itk::SimpleFastMutexLock, dim> but this procedure is not possible with itk::Image<std::mutex, dim>
(cannot copy a mutex)
So I created a mutex alone and lock/unlock it when it is necessary

itk/clitkForwardWarpImageFilter.h
itk/clitkForwardWarpImageFilter.txx
itk/clitkInvertVFFilter.h
itk/clitkInvertVFFilter.txx
registration/clitkDeformationListStatisticsFilter.h

index 7efac8fc8268291bd3564fb0a1a03045a9744cbb..ec46f0ca8fa97a11590c8a0a0c750b5d4e7a809a 100644 (file)
 #include "itkImageRegionIterator.h"
 #include "itkImageRegionIteratorWithIndex.h"
 #include "itkNumericTraits.h"
+#if ITK_VERSION_MAJOR <= 4
 #include "itkSimpleFastMutexLock.h"
+#else
+#include <mutex>
+#endif
 
 namespace clitk
 {
@@ -56,7 +60,9 @@ namespace clitk
     //Some other typedefs
     typedef double CoordRepType;
     typedef itk::Image<double, ImageDimension> WeightsImageType;
+#if ITK_VERSION_MAJOR <= 4
     typedef itk::Image<itk::SimpleFastMutexLock, ImageDimension> MutexImageType;
+#endif
 
     /** Point type */
     typedef itk::Point<CoordRepType,itkGetStaticConstMacro(ImageDimension)> PointType;
index 88804f5248175517f578612382685981deb88277..4c38b5a5e3d5a627668de493c6cefccb6e2d5021 100644 (file)
@@ -53,7 +53,9 @@ public:
   //Typedefs
   typedef typename OutputImageType::PixelType        OutputPixelType;
   typedef itk::Image<double, ImageDimension > WeightsImageType;
-  typedef itk::Image<itk::SimpleFastMutexLock, ImageDimension > MutexImageType;
+#if ITK_VERSION_MAJOR <= 4
+    typedef itk::Image<itk::SimpleFastMutexLock, ImageDimension> MutexImageType;
+#endif
   //===================================================================================
   //Set methods
   void SetWeights(const typename WeightsImageType::Pointer input) {
@@ -64,11 +66,18 @@ public:
     m_DeformationField=input;
     this->Modified();
   }
+#if ITK_VERSION_MAJOR <= 4
   void SetMutexImage(const typename MutexImageType::Pointer input) {
     m_MutexImage=input;
     this->Modified();
     m_ThreadSafe=true;
   }
+#else
+  void SetMutexImage() {
+    this->Modified();
+    m_ThreadSafe=true;
+  }
+#endif
 
   //Get methods
   typename WeightsImageType::Pointer GetWeights() {
@@ -89,7 +98,11 @@ protected:
   //member data
   typename  itk::Image< double, ImageDimension>::Pointer m_Weights;
   typename DeformationFieldType::Pointer m_DeformationField;
+#if ITK_VERSION_MAJOR <= 4
   typename MutexImageType::Pointer m_MutexImage;
+#else
+  std::mutex m_Mutex;
+#endif
   bool m_ThreadSafe;
 
 };
@@ -224,14 +237,22 @@ void HelperClass1<InputImageType, OutputImageType, DeformationFieldType>::Thread
 
           } else {
             //Entering critilal section: shared memory
+#if ITK_VERSION_MAJOR <= 4
             m_MutexImage->GetPixel(neighIndex).Lock();
+#else
+            m_Mutex.lock();
+#endif
 
             //Set the pixel and weight at neighIndex
             outputPtr->SetPixel(neighIndex, outputPtr->GetPixel(neighIndex) + overlap * static_cast<OutputPixelType>(inputIt.Get()));
             m_Weights->SetPixel(neighIndex, m_Weights->GetPixel(neighIndex) + overlap);
 
             //Unlock
+#if ITK_VERSION_MAJOR <= 4
             m_MutexImage->GetPixel(neighIndex).Unlock();
+#else
+            m_Mutex.unlock();
+#endif
 
           }
           //Add to total overlap
@@ -459,11 +480,15 @@ void ForwardWarpImageFilter<InputImageType, OutputImageType, DeformationFieldTyp
   //Threadsafe?
   if(m_ThreadSafe) {
     //Allocate the mutex image
+#if ITK_VERSION_MAJOR <= 4
     typename MutexImageType::Pointer mutex=ForwardWarpImageFilter::MutexImageType::New();
     mutex->SetRegions(region);
     mutex->Allocate();
     mutex->SetSpacing(inputPtr->GetSpacing());
     helper1->SetMutexImage(mutex);
+#else
+    helper1->SetMutexImage();
+#endif
     if (m_Verbose) std::cout <<"Forwarp warping using a thread-safe algorithm" <<std::endl;
   } else  if(m_Verbose)std::cout <<"Forwarp warping using a thread-unsafe algorithm" <<std::endl;
 
index 8ad84a2e969c6ba75ed7da41dbe50676b4ab6a0b..b3167450dd810d2fe6b30b13dea74cdfc50cdec1 100644 (file)
@@ -51,7 +51,9 @@ namespace clitk
     //Some other typedefs
     typedef double CoordRepType;
     typedef itk::Image<double, ImageDimension> WeightsImageType;
+#if ITK_VERSION_MAJOR <= 4
     typedef itk::Image<itk::SimpleFastMutexLock, ImageDimension> MutexImageType;
+#endif
 
     /** Point type */
     typedef itk::Point<CoordRepType,itkGetStaticConstMacro(ImageDimension)> PointType;
index ec3c90fe31b8e4532ec81f02632daf9621ad3214..6c91dbb9ebf4fa14d72a411b5bf0fad28ef42986 100644 (file)
@@ -47,7 +47,9 @@ public:
   //Typedefs
   typedef typename OutputImageType::PixelType        PixelType;
   typedef itk::Image<double, ImageDimension > WeightsImageType;
-  typedef itk::Image<itk::SimpleFastMutexLock, ImageDimension > MutexImageType;
+#if ITK_VERSION_MAJOR <= 4
+  typedef itk::Image<itk::SimpleFastMutexLock, ImageDimension> MutexImageType;
+#endif
 
   //===================================================================================
   //Set methods
@@ -55,11 +57,18 @@ public:
     m_Weights = input;
     this->Modified();
   }
+#if ITK_VERSION_MAJOR <= 4
   void SetMutexImage(const typename MutexImageType::Pointer input) {
     m_MutexImage=input;
     this->Modified();
     m_ThreadSafe=true;
   }
+#else
+  void SetMutexImage() {
+    this->Modified();
+    m_ThreadSafe=true;
+  }
+#endif
 
   //Get methods
   typename  WeightsImageType::Pointer GetWeights() {
@@ -79,7 +88,11 @@ protected:
 
   //member data
   typename  WeightsImageType::Pointer m_Weights;
+#if ITK_VERSION_MAJOR <= 4
   typename MutexImageType::Pointer m_MutexImage;
+#else
+  std::mutex m_Mutex;
+#endif
   bool m_ThreadSafe;
 
 };
@@ -215,14 +228,22 @@ void HelperClass1<InputImageType, OutputImageType>::ThreadedGenerateData(const O
 
           else {
             //Entering critilal section: shared memory
+#if ITK_VERSION_MAJOR <= 4
             m_MutexImage->GetPixel(neighIndex).Lock();
+#else
+            m_Mutex.lock();
+#endif
 
             //Set the pixel and weight at neighIndex
             outputPtr->SetPixel(neighIndex, outputPtr->GetPixel(neighIndex) - (displacement*overlap));
             m_Weights->SetPixel(neighIndex, m_Weights->GetPixel(neighIndex) + overlap);
 
             //Unlock
+#if ITK_VERSION_MAJOR <= 4
             m_MutexImage->GetPixel(neighIndex).Unlock();
+#else
+            m_Mutex.unlock();
+#endif
 
           }
           //Add to total overlap
@@ -451,11 +472,15 @@ template <class InputImageType, class OutputImageType> void InvertVFFilter<Input
   //Threadsafe?
   if(m_ThreadSafe) {
     //Allocate the mutex image
+#if ITK_VERSION_MAJOR <= 4
     typename MutexImageType::Pointer mutex=InvertVFFilter::MutexImageType::New();
     mutex->SetRegions(region);
     mutex->Allocate();
     mutex->SetSpacing(inputPtr->GetSpacing());
     helper1->SetMutexImage(mutex);
+#else
+    helper1->SetMutexImage();
+#endif
     if (m_Verbose) std::cout <<"Inverting using a thread-safe algorithm" <<std::endl;
   } else  if(m_Verbose)std::cout <<"Inverting using a thread-unsafe algorithm" <<std::endl;
 
index 1a224ec497989fa92b34529d1e915c9a089508d5..1651094e74937e06507ba42df18001e9e0921d00 100644 (file)
 #include "itkImageRegionIterator.h"
 #include "itkImageRegionIteratorWithIndex.h"
 #include "itkNumericTraits.h"
+#if ITK_VERSION_MAJOR <= 4
 #include "itkSimpleFastMutexLock.h"
+#else
+#include <mutex>
+#endif
 #include "itkImageMaskSpatialObject.h"
 
 namespace clitk