X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=itk%2FclitkInvertVFFilter.txx;h=b2485e0e51a5f6c260c3aeed26cfc5575c396543;hb=f05cc2cf37d7ec960b73fa9d2393d5a888e1f87a;hp=3df8aca45b7fa55508389cf04a0ceb05a648aba0;hpb=1e034c70105f0926939acaaa27ddb46e904ae8bf;p=clitk.git diff --git a/itk/clitkInvertVFFilter.txx b/itk/clitkInvertVFFilter.txx index 3df8aca..b2485e0 100644 --- a/itk/clitkInvertVFFilter.txx +++ b/itk/clitkInvertVFFilter.txx @@ -3,7 +3,7 @@ Authors belong to: - University of LYON http://www.universite-lyon.fr/ - - Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr + - Léon Bérard cancer center http://www.centreleonberard.fr - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr This software is distributed WITHOUT ANY WARRANTY; without even @@ -14,9 +14,10 @@ - BSD See included LICENSE.txt file - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html -======================================================================-====*/ +===========================================================================**/ #ifndef __clitkInvertVFFilter_txx #define __clitkInvertVFFilter_txx + namespace { @@ -73,8 +74,8 @@ protected: ~HelperClass1() {}; //the actual processing - void BeforeThreadedGenerateData(); - void ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, int threadId ); + void BeforeThreadedGenerateData() ITK_OVERRIDE; + void ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, itk::ThreadIdType threadId ) ITK_OVERRIDE; //member data typename WeightsImageType::Pointer m_Weights; @@ -103,6 +104,7 @@ HelperClass1::HelperClass1() template void HelperClass1::BeforeThreadedGenerateData() { + //std::cout << "HelperClass1::BeforeThreadedGenerateData - IN" << std::endl; //Since we will add, put to zero! this->GetOutput()->FillBuffer(itk::NumericTraits::Zero); this->GetWeights()->FillBuffer(itk::NumericTraits::Zero); @@ -111,15 +113,15 @@ void HelperClass1::BeforeThreadedGenerateData() //========================================================================================================================= //update the output for the outputRegionForThread template -void HelperClass1::ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, int threadId ) +void HelperClass1::ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, itk::ThreadIdType threadId ) { - +// std::cout << "HelperClass1::ThreadedGenerateData - IN " << threadId << std::endl; //Get pointer to the input typename InputImageType::ConstPointer inputPtr = this->GetInput(); //Get pointer to the output typename OutputImageType::Pointer outputPtr = this->GetOutput(); - typename OutputImageType::SizeType size=outputPtr->GetLargestPossibleRegion().GetSize(); + //typename OutputImageType::SizeType size=outputPtr->GetLargestPossibleRegion().GetSize(); //Iterator over input typedef itk::ImageRegionConstIteratorWithIndex InputImageIteratorType; @@ -129,13 +131,15 @@ void HelperClass1::ThreadedGenerateData(const O //Initialize typename InputImageType::IndexType index; - itk::ContinuousIndex contIndex; + itk::ContinuousIndex contIndex, inContIndex; typename InputImageType::PointType ipoint; typename OutputImageType::PointType opoint; typedef typename OutputImageType::PixelType DisplacementType; DisplacementType displacement; inputIt.GoToBegin(); + typename OutputImageType::SizeType size = outputPtr->GetLargestPossibleRegion().GetSize(); + //define some temp variables signed long baseIndex[ImageDimension]; double distance[ImageDimension]; @@ -147,7 +151,7 @@ void HelperClass1::ThreadedGenerateData(const O unsigned int neighbors = 1 << ImageDimension; //================================================================================================== - //Loop over the region and add the intensities to the output and the weight to the weights + //Loop over the output region and add the intensities from the input to the output and the weight to the weights //================================================================================================== while( !inputIt.IsAtEnd() ) { // get the input image index @@ -178,7 +182,7 @@ void HelperClass1::ThreadedGenerateData(const O upper = counter; // each bit indicates upper/lower neighbour // get neighbor index and overlap fraction - for( dim = 0; dim < 3; dim++ ) { + for( dim = 0; dim < ImageDimension; dim++ ) { if ( upper & 1 ) { neighIndex[dim] = baseIndex[dim] + 1; overlap *= distance[dim]; @@ -187,8 +191,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 @@ -233,6 +239,7 @@ void HelperClass1::ThreadedGenerateData(const O ++inputIt; } +// std::cout << "HelperClass1::ThreadedGenerateData - OUT " << threadId << std::endl; } @@ -282,8 +289,7 @@ protected: //the actual processing - void ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, int threadId ); - + void ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, itk::ThreadIdType threadId ) ITK_OVERRIDE; //member data typename WeightsImageType::Pointer m_Weights; @@ -302,14 +308,18 @@ 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 -template void HelperClass2::ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, int threadId ) +template void HelperClass2::ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, itk::ThreadIdType threadId ) { +// std::cout << "HelperClass2::ThreadedGenerateData - IN " << threadId << std::endl; //Get pointer to the input typename InputImageType::ConstPointer inputPtr = this->GetInput(); @@ -360,6 +370,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 InvertVFFilter::GenerateData() { + // std::cout << "InvertVFFilter::GenerateData - IN" << std::endl; //Get the properties of the input typename InputImageType::ConstPointer inputPtr=this->GetInput(); - typename WeightsImageType::RegionType region; - typename WeightsImageType::RegionType::SizeType size=inputPtr->GetLargestPossibleRegion().GetSize(); - region.SetSize(size); - typename OutputImageType::IndexType start; - for (unsigned int i=0; i< ImageDimension; i++) start[i]=0; - region.SetIndex(start); - PixelType zero = itk::NumericTraits::Zero; - + typename WeightsImageType::RegionType region = inputPtr->GetLargestPossibleRegion(); //Allocate the weights typename WeightsImageType::Pointer weights=WeightsImageType::New(); + weights->SetOrigin(inputPtr->GetOrigin()); weights->SetRegions(region); weights->Allocate(); weights->SetSpacing(inputPtr->GetSpacing()); @@ -426,7 +438,13 @@ 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); @@ -456,6 +474,13 @@ template void InvertVFFilterSetNumberOfThreads(m_NumberOfThreads); +#else + helper2->SetNumberOfWorkUnits(m_NumberOfWorkUnits); +#endif + } helper2->SetInput(temp); helper2->SetWeights(weights); helper2->SetEdgePaddingValue(m_EdgePaddingValue); @@ -466,6 +491,8 @@ template void InvertVFFilterSetNthOutput(0, helper2->GetOutput()); + + //std::cout << "InvertVFFilter::GenerateData - OUT" << std::endl; }