X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=itk%2FclitkForwardWarpImageFilter.txx;h=4c38b5a5e3d5a627668de493c6cefccb6e2d5021;hb=a523f5be1e221995c0d4d29a0077b5e8b984c96d;hp=283abe61c8c52fb3531e98d019a920a46734fe75;hpb=7f7c290c75d4917446f8751856ae7d450f58a6f0;p=clitk.git diff --git a/itk/clitkForwardWarpImageFilter.txx b/itk/clitkForwardWarpImageFilter.txx index 283abe6..4c38b5a 100644 --- a/itk/clitkForwardWarpImageFilter.txx +++ b/itk/clitkForwardWarpImageFilter.txx @@ -53,7 +53,9 @@ public: //Typedefs typedef typename OutputImageType::PixelType OutputPixelType; typedef itk::Image WeightsImageType; - typedef itk::Image MutexImageType; +#if ITK_VERSION_MAJOR <= 4 + typedef itk::Image 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() { @@ -84,12 +93,16 @@ protected: //the actual processing void BeforeThreadedGenerateData(); - void ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, itk::ThreadIdType threadId ); + void ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, int threadId ); //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; }; @@ -124,7 +137,7 @@ void HelperClass1::Before //========================================================================================================================= //update the output for the outputRegionForThread template -void HelperClass1::ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, itk::ThreadIdType threadId ) +void HelperClass1::ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, int threadId ) { //Get pointer to the input @@ -184,7 +197,7 @@ void HelperClass1::Thread for(dim = 0; dim < ImageDimension; dim++) { // The following block is equivalent to the following line without // having to call floor. For positive inputs!!! - // 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] ); } @@ -224,14 +237,22 @@ void HelperClass1::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(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 @@ -303,7 +324,7 @@ protected: //the actual processing - void ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, itk::ThreadIdType threadId ); + void ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, int threadId ); //member data @@ -330,7 +351,7 @@ HelperClass2::HelperClass2() //========================================================================================================================= //update the output for the outputRegionForThread template void -HelperClass2::ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, itk::ThreadIdType threadId ) +HelperClass2::ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, int threadId ) { //Get pointer to the input @@ -445,7 +466,13 @@ void ForwardWarpImageFilterSetNumberOfThreads(m_NumberOfThreads); + if(m_NumberOfThreadsIsGiven) { +#if ITK_VERSION_MAJOR <= 4 + helper1->SetNumberOfThreads(m_NumberOfThreads); +#else + helper1->SetNumberOfWorkUnits(m_NumberOfWorkUnits); +#endif + } helper1->SetInput(inputPtr); helper1->SetDeformationField(m_DeformationField); helper1->SetWeights(weights); @@ -453,11 +480,15 @@ void ForwardWarpImageFilterSetRegions(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" <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);