X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=itk%2FclitkInvertVFFilter.txx;h=6c91dbb9ebf4fa14d72a411b5bf0fad28ef42986;hb=69dacfe0651ee24bef0f9e6b41171b9eec96fd2e;hp=34500a3897e058db1247afc3f1a174526cb5862e;hpb=83929af8ebcf2b66482a42e4d41091aa3830c710;p=clitk.git diff --git a/itk/clitkInvertVFFilter.txx b/itk/clitkInvertVFFilter.txx index 34500a3..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 @@ -145,7 +150,7 @@ void HelperClass1::ThreadedGenerateData(const O typedef typename OutputImageType::PixelType DisplacementType; DisplacementType displacement; inputIt.GoToBegin(); - + typename OutputImageType::SizeType size = outputPtr->GetLargestPossibleRegion().GetSize(); //define some temp variables @@ -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] ); @@ -199,7 +204,7 @@ void HelperClass1::ThreadedGenerateData(const O overlap *= 1.0 - distance[dim]; } upper >>= 1; - + if (neighIndex[dim] >= size[dim]) neighIndex[dim] = size[dim] - 1; } @@ -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; @@ -320,20 +329,19 @@ protected: //Empty constructor template HelperClass2::HelperClass2() { - m_EdgePaddingValue=itk::NumericTraits::Zero; + PixelType zero; + for(unsigned int i=0;i ::Zero; } //========================================================================================================================= //update the output for the outputRegionForThread -#if ITK_VERSION_MAJOR >= 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; - + //Get pointer to the input typename InputImageType::ConstPointer inputPtr = this->GetInput(); @@ -383,9 +391,9 @@ template void HelperClass2 InvertVFFilter::InvertVFFilter() { - m_EdgePaddingValue=itk::NumericTraits::Zero; //no other reasonable value? + + //m_EdgePaddingValue=itk::NumericTraits::Zero; //no other reasonable value? + PixelType zero; + for(unsigned int i=0;i 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); @@ -487,7 +516,7 @@ template void InvertVFFilterSetNthOutput(0, helper2->GetOutput()); - + //std::cout << "InvertVFFilter::GenerateData - OUT" << std::endl; }