X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=itk%2FclitkInvertVFFilter.txx;h=6c91dbb9ebf4fa14d72a411b5bf0fad28ef42986;hb=69dacfe0651ee24bef0f9e6b41171b9eec96fd2e;hp=b74958fb597a83dc9b3f559936973b340ee6874d;hpb=5c614f89dec012c7e8fee33c09fe7c1b955f5640;p=clitk.git diff --git a/itk/clitkInvertVFFilter.txx b/itk/clitkInvertVFFilter.txx index b74958f..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,13 +126,9 @@ 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" << std::endl; +// std::cout << "HelperClass1::ThreadedGenerateData - IN " << threadId << std::endl; //Get pointer to the input typename InputImageType::ConstPointer inputPtr = this->GetInput(); @@ -146,6 +151,8 @@ void HelperClass1::ThreadedGenerateData(const O DisplacementType displacement; inputIt.GoToBegin(); + typename OutputImageType::SizeType size = outputPtr->GetLargestPossibleRegion().GetSize(); + //define some temp variables signed long baseIndex[ImageDimension]; double distance[ImageDimension]; @@ -175,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] ); @@ -197,8 +204,10 @@ void HelperClass1::ThreadedGenerateData(const O overlap *= 1.0 - distance[dim]; } upper >>= 1; - } + if (neighIndex[dim] >= size[dim]) + neighIndex[dim] = size[dim] - 1; + } //Set neighbor value only if overlap is not zero @@ -219,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 @@ -243,7 +260,7 @@ void HelperClass1::ThreadedGenerateData(const O ++inputIt; } - //std::cout << "HelperClass1::ThreadedGenerateData - OUT" << std::endl; +// std::cout << "HelperClass1::ThreadedGenerateData - OUT " << threadId << std::endl; } @@ -293,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; @@ -316,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" << std::endl; - +// std::cout << "HelperClass2::ThreadedGenerateData - IN " << threadId << std::endl; + //Get pointer to the input typename InputImageType::ConstPointer inputPtr = this->GetInput(); @@ -379,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 ::InvertVFFilter() //Update template void InvertVFFilter::GenerateData() { - //std::cout << "InvertVFFilter::GenerateData - IN" << std::endl; + // std::cout << "InvertVFFilter::GenerateData - IN" << std::endl; //Get the properties of the input typename InputImageType::ConstPointer inputPtr=this->GetInput(); @@ -442,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); +#else + helper2->SetNumberOfWorkUnits(m_NumberOfWorkUnits); +#endif + } helper2->SetInput(temp); helper2->SetWeights(weights); helper2->SetEdgePaddingValue(m_EdgePaddingValue); @@ -482,6 +516,8 @@ template void InvertVFFilterSetNthOutput(0, helper2->GetOutput()); + + //std::cout << "InvertVFFilter::GenerateData - OUT" << std::endl; }