X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=itk%2FclitkInvertVFFilter.txx;h=6c91dbb9ebf4fa14d72a411b5bf0fad28ef42986;hb=69dacfe0651ee24bef0f9e6b41171b9eec96fd2e;hp=e26fed7c77c6b7cac148e970adce1491587742bd;hpb=f3457815210ffe8646f3288be3362d34fcc7c3af;p=clitk.git diff --git a/itk/clitkInvertVFFilter.txx b/itk/clitkInvertVFFilter.txx index e26fed7..6c91dbb 100644 --- a/itk/clitkInvertVFFilter.txx +++ b/itk/clitkInvertVFFilter.txx @@ -47,7 +47,9 @@ public: //Typedefs typedef typename OutputImageType::PixelType PixelType; typedef itk::Image WeightsImageType; - typedef itk::Image MutexImageType; +#if ITK_VERSION_MAJOR <= 4 + typedef itk::Image 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::BeforeThreadedGenerateData() //========================================================================================================================= //update the output for the outputRegionForThread template -#if ITK_VERSION_MAJOR >= 4 void HelperClass1::ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, itk::ThreadIdType threadId ) -#else -void HelperClass1::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::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::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 HelperClass2= 4 template void HelperClass2::ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, itk::ThreadIdType threadId ) -#else -template void HelperClass2::ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, int threadId ) -#endif { // std::cout << "HelperClass2::ThreadedGenerateData - IN " << threadId << std::endl; @@ -454,18 +459,28 @@ template void InvertVFFilterSetNumberOfThreads(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" < void InvertVFFilterSetNumberOfThreads(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);