]> Creatis software - clitk.git/blobdiff - itk/clitkInvertVFFilter.txx
Change itkSimpleFastMutexLock to std::mutex
[clitk.git] / itk / clitkInvertVFFilter.txx
index e26fed7c77c6b7cac148e970adce1491587742bd..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() {
@@ -74,16 +83,16 @@ protected:
   ~HelperClass1() {};
 
   //the actual processing
-  void BeforeThreadedGenerateData();
-#if ITK_VERSION_MAJOR >= 4
-  void ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, itk::ThreadIdType threadId );
-#else
-  void ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, int threadId );
-#endif
+  void BeforeThreadedGenerateData() ITK_OVERRIDE;
+  void ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, itk::ThreadIdType threadId ) ITK_OVERRIDE;
 
   //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;
 
 };
@@ -117,11 +126,7 @@ void HelperClass1<InputImageType, OutputImageType>::BeforeThreadedGenerateData()
 //=========================================================================================================================
 //update the output for the outputRegionForThread
 template<class InputImageType, class OutputImageType>
-#if ITK_VERSION_MAJOR >= 4
 void HelperClass1<InputImageType, OutputImageType>::ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, itk::ThreadIdType threadId )
-#else
-void HelperClass1<InputImageType, OutputImageType>::ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, int threadId )
-#endif
 {
 //   std::cout << "HelperClass1::ThreadedGenerateData - IN " << threadId << std::endl;
   //Get pointer to the input
@@ -177,7 +182,7 @@ void HelperClass1<InputImageType, OutputImageType>::ThreadedGenerateData(const O
       for(dim = 0; dim < ImageDimension; dim++) {
         // The following  block is equivalent to the following line without
         // having to call floor. (Only for positive inputs, we already now that is in the image)
-        // baseIndex[dim] = (long) vcl_floor(contIndex[dim] );
+        // baseIndex[dim] = (long) std::floor(contIndex[dim] );
 
         baseIndex[dim] = (long) contIndex[dim];
         distance[dim] = contIndex[dim] - double( baseIndex[dim] );
@@ -223,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
@@ -297,11 +310,7 @@ protected:
 
 
   //the actual processing
-#if ITK_VERSION_MAJOR >= 4
-  void ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, itk::ThreadIdType threadId );
-#else
-  void ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, int threadId );
-#endif
+  void ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, itk::ThreadIdType threadId ) ITK_OVERRIDE;
 
   //member data
   typename     WeightsImageType::Pointer m_Weights;
@@ -329,11 +338,7 @@ template<class InputImageType, class OutputImageType > HelperClass2<InputImageTy
 
 //=========================================================================================================================
 //update the output for the outputRegionForThread
-#if ITK_VERSION_MAJOR >= 4
 template<class InputImageType, class OutputImageType > void HelperClass2<InputImageType, OutputImageType>::ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, itk::ThreadIdType threadId )
-#else
-template<class InputImageType, class OutputImageType > void HelperClass2<InputImageType, OutputImageType>::ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, int threadId )
-#endif
 {
 //   std::cout << "HelperClass2::ThreadedGenerateData - IN " << threadId << std::endl;
 
@@ -454,18 +459,28 @@ template <class InputImageType, class OutputImageType> void InvertVFFilter<Input
   typename HelperClass1Type::Pointer helper1=HelperClass1Type::New();
 
   //Set input
-  if(m_NumberOfThreadsIsGiven)helper1->SetNumberOfThreads(m_NumberOfThreads);
+  if(m_NumberOfThreadsIsGiven) {
+#if ITK_VERSION_MAJOR <= 4
+    helper1->SetNumberOfThreads(m_NumberOfThreads);
+#else
+    helper1->SetNumberOfWorkUnits(m_NumberOfWorkUnits);
+#endif
+  }
   helper1->SetInput(inputPtr);
   helper1->SetWeights(weights);
 
   //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;
 
@@ -484,7 +499,13 @@ template <class InputImageType, class OutputImageType> void InvertVFFilter<Input
   typename HelperClass2Type::Pointer helper2=HelperClass2Type::New();
 
   //Set temporary output as input
-  if(m_NumberOfThreadsIsGiven)helper2->SetNumberOfThreads(m_NumberOfThreads);
+  if(m_NumberOfThreadsIsGiven) {
+#if ITK_VERSION_MAJOR <= 4
+    helper2->SetNumberOfThreads(m_NumberOfThreads);
+#else
+    helper2->SetNumberOfWorkUnits(m_NumberOfWorkUnits);
+#endif
+  }
   helper2->SetInput(temp);
   helper2->SetWeights(weights);
   helper2->SetEdgePaddingValue(m_EdgePaddingValue);