]> Creatis software - clitk.git/blobdiff - itk/clitkForwardWarpImageFilter.txx
Change itkSimpleFastMutexLock to std::mutex
[clitk.git] / itk / clitkForwardWarpImageFilter.txx
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;