X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=registration%2FitkOptMattesMutualInformationImageToImageMetricFor3DBLUTFFD.txx;h=9f717668e4d79e068e67099dc7a432aa68847953;hb=HEAD;hp=f55b19a5556d1d76c343babb15e80f610b6ec117;hpb=1eaa43a8aa678f784fd0f4b587d45c1435285214;p=clitk.git diff --git a/registration/itkOptMattesMutualInformationImageToImageMetricFor3DBLUTFFD.txx b/registration/itkOptMattesMutualInformationImageToImageMetricFor3DBLUTFFD.txx index f55b19a..9f71766 100644 --- a/registration/itkOptMattesMutualInformationImageToImageMetricFor3DBLUTFFD.txx +++ b/registration/itkOptMattesMutualInformationImageToImageMetricFor3DBLUTFFD.txx @@ -44,8 +44,8 @@ PURPOSE. See the above copyright notices for more information. #include "vnl/vnl_math.h" #include "itkStatisticsImageFilter.h" -#include "vnl/vnl_vector.txx" -#include "vnl/vnl_c_vector.txx" +#include "vnl/vnl_vector.h" +#include "vnl/vnl_c_vector.h" namespace itk { @@ -183,7 +183,11 @@ MattesMutualInformationImageToImageMetricFor3DBLUTFFD template void MattesMutualInformationImageToImageMetricFor3DBLUTFFD +#if ( ( ITK_VERSION_MAJOR == 4 ) && ( ITK_VERSION_MINOR > 12 ) || ( ITK_VERSION_MAJOR > 4 )) +::Initialize(void) +#else ::Initialize(void) throw ( ExceptionObject ) +#endif { this->Superclass::Initialize(); this->Superclass::MultiThreadingInitialize(); @@ -192,7 +196,11 @@ MattesMutualInformationImageToImageMetricFor3DBLUTFFD typename FixedImageStatisticsFilterType::Pointer fixedImageStats = FixedImageStatisticsFilterType::New(); fixedImageStats->SetInput( this->m_FixedImage ); +#if ITK_VERSION_MAJOR <= 4 fixedImageStats->SetNumberOfThreads( this->m_NumberOfThreads ); +#else + fixedImageStats->SetNumberOfWorkUnits( this->m_NumberOfWorkUnits ); +#endif fixedImageStats->Update(); m_FixedImageTrueMin = fixedImageStats->GetMinimum(); @@ -205,7 +213,11 @@ MattesMutualInformationImageToImageMetricFor3DBLUTFFD typename MovingImageStatisticsFilterType::Pointer movingImageStats = MovingImageStatisticsFilterType::New(); movingImageStats->SetInput( this->m_MovingImage ); +#if ITK_VERSION_MAJOR <= 4 movingImageStats->SetNumberOfThreads( this->m_NumberOfThreads ); +#else + movingImageStats->SetNumberOfWorkUnits( this->m_NumberOfWorkUnits ); +#endif movingImageStats->Update(); m_MovingImageTrueMin = movingImageStats->GetMinimum(); @@ -362,35 +374,62 @@ MattesMutualInformationImageToImageMetricFor3DBLUTFFD } // Assumes number of threads doesn't change between calls to Initialize m_ThreaderFixedImageMarginalPDF = new - PDFValueType[(this->m_NumberOfThreads-1) - * m_NumberOfHistogramBins]; +#if ITK_VERSION_MAJOR <= 4 + PDFValueType[(this->m_NumberOfThreads-1) * m_NumberOfHistogramBins]; +#else + PDFValueType[(this->m_NumberOfWorkUnits-1) * m_NumberOfHistogramBins]; +#endif if(m_ThreaderJointPDF != NULL) { delete [] m_ThreaderJointPDF; } m_ThreaderJointPDF = new typename +#if ITK_VERSION_MAJOR <= 4 JointPDFType::Pointer[this->m_NumberOfThreads-1]; +#else + JointPDFType::Pointer[this->m_NumberOfWorkUnits-1]; +#endif if(m_ThreaderJointPDFStartBin != NULL) { delete [] m_ThreaderJointPDFStartBin; } +#if ITK_VERSION_MAJOR <= 4 m_ThreaderJointPDFStartBin = new int[this->m_NumberOfThreads]; +#else + m_ThreaderJointPDFStartBin = new int[this->m_NumberOfWorkUnits]; +#endif if(m_ThreaderJointPDFEndBin != NULL) { delete [] m_ThreaderJointPDFEndBin; } +#if ITK_VERSION_MAJOR <= 4 m_ThreaderJointPDFEndBin = new int[this->m_NumberOfThreads]; +#else + m_ThreaderJointPDFEndBin = new int[this->m_NumberOfWorkUnits]; +#endif if(m_ThreaderJointPDFSum != NULL) { delete [] m_ThreaderJointPDFSum; } +#if ITK_VERSION_MAJOR <= 4 m_ThreaderJointPDFSum = new double[this->m_NumberOfThreads]; +#else + m_ThreaderJointPDFSum = new double[this->m_NumberOfWorkUnits]; +#endif unsigned int threadID; +#if ITK_VERSION_MAJOR <= 4 int binRange = m_NumberOfHistogramBins / this->m_NumberOfThreads; +#else + int binRange = m_NumberOfHistogramBins / this->m_NumberOfWorkUnits; +#endif +#if ITK_VERSION_MAJOR <= 4 for(threadID = 0; threadID < this->m_NumberOfThreads-1; threadID++) { +#else + for(threadID = 0; threadID < this->m_NumberOfWorkUnits-1; threadID++) { +#endif m_ThreaderJointPDF[threadID] = JointPDFType::New(); m_ThreaderJointPDF[threadID]->SetRegions( jointPDFRegion ); m_ThreaderJointPDF[threadID]->Allocate(); @@ -399,10 +438,13 @@ MattesMutualInformationImageToImageMetricFor3DBLUTFFD m_ThreaderJointPDFEndBin[threadID] = (threadID + 1) * binRange - 1; } - m_ThreaderJointPDFStartBin[this->m_NumberOfThreads-1] = - (this->m_NumberOfThreads - 1 ) * binRange; - +#if ITK_VERSION_MAJOR <= 4 + m_ThreaderJointPDFStartBin[this->m_NumberOfThreads-1] = (this->m_NumberOfThreads - 1 ) * binRange; m_ThreaderJointPDFEndBin[this->m_NumberOfThreads-1] = m_NumberOfHistogramBins - 1; +#else + m_ThreaderJointPDFStartBin[this->m_NumberOfWorkUnits-1] = (this->m_NumberOfWorkUnits - 1 ) * binRange; + m_ThreaderJointPDFEndBin[this->m_NumberOfWorkUnits-1] = m_NumberOfHistogramBins - 1; +#endif // Release memory of arrays that may have been used for // previous executions of this metric with different settings @@ -420,18 +462,34 @@ MattesMutualInformationImageToImageMetricFor3DBLUTFFD if( this->m_UseExplicitPDFDerivatives ) { m_ThreaderJointPDFDerivatives = new typename +#if ITK_VERSION_MAJOR <= 4 JointPDFDerivativesType::Pointer[this->m_NumberOfThreads-1]; +#else + JointPDFDerivativesType::Pointer[this->m_NumberOfWorkUnits-1]; +#endif +#if ITK_VERSION_MAJOR <= 4 for(threadID = 0; threadID < this->m_NumberOfThreads-1; threadID++) { +#else + for(threadID = 0; threadID < this->m_NumberOfWorkUnits-1; threadID++) { +#endif m_ThreaderJointPDFDerivatives[threadID] = JointPDFDerivativesType::New(); m_ThreaderJointPDFDerivatives[threadID]->SetRegions( jointPDFDerivativesRegion ); m_ThreaderJointPDFDerivatives[threadID]->Allocate(); } } else { +#if ITK_VERSION_MAJOR <= 4 m_ThreaderMetricDerivative = new DerivativeType[this->m_NumberOfThreads-1]; +#else + m_ThreaderMetricDerivative = new DerivativeType[this->m_NumberOfWorkUnits-1]; +#endif +#if ITK_VERSION_MAJOR <= 4 for(threadID = 0; threadID < this->m_NumberOfThreads-1; threadID++) { +#else + for(threadID = 0; threadID < this->m_NumberOfWorkUnits-1; threadID++) { +#endif this->m_ThreaderMetricDerivative[threadID] = DerivativeType( this->GetNumberOfParameters() ); } } @@ -595,7 +653,11 @@ MattesMutualInformationImageToImageMetricFor3DBLUTFFD unsigned int tPdfPtrOffset; tPdfPtrOffset = ( m_ThreaderJointPDFStartBin[threadID] * m_JointPDF->GetOffsetTable()[1] ); +#if ITK_VERSION_MAJOR <= 4 for(t=0; tm_NumberOfThreads-1; t++) { +#else + for(t=0; tm_NumberOfWorkUnits-1; t++) { +#endif pdfPtr = pdfPtrStart; tPdfPtr = m_ThreaderJointPDF[t]->GetBufferPointer() + tPdfPtrOffset; tPdfPtrEnd = tPdfPtr + maxI; @@ -630,9 +692,6 @@ MattesMutualInformationImageToImageMetricFor3DBLUTFFD { // Set up the parameters in the transform this->m_Transform->SetParameters( parameters ); -#if ITK_VERSION_MAJOR < 4 - this->m_Parameters = parameters; -#endif // MUST BE CALLED TO INITIATE PROCESSING this->GetValueMultiThreadedInitiate(); @@ -640,7 +699,11 @@ MattesMutualInformationImageToImageMetricFor3DBLUTFFD // MUST BE CALLED TO INITIATE PROCESSING this->GetValueMultiThreadedPostProcessInitiate(); +#if ITK_VERSION_MAJOR <= 4 for(unsigned int threadID = 0; threadIDm_NumberOfThreads-1; threadID++) { +#else + for(unsigned int threadID = 0; threadIDm_NumberOfWorkUnits-1; threadID++) { +#endif m_JointPDFSum += m_ThreaderJointPDFSum[threadID]; } if ( m_JointPDFSum == 0.0 ) { @@ -705,9 +768,9 @@ MattesMutualInformationImageToImageMetricFor3DBLUTFFD // check for non-zero bin contribution if( jointPDFValue > 1e-16 && movingImagePDFValue > 1e-16 ) { - double pRatio = vcl_log(jointPDFValue / movingImagePDFValue ); + double pRatio = std::log(jointPDFValue / movingImagePDFValue ); if( fixedImagePDFValue > 1e-16) { - sum += jointPDFValue * ( pRatio - vcl_log(fixedImagePDFValue ) ); + sum += jointPDFValue * ( pRatio - std::log(fixedImagePDFValue ) ); } } // end if-block to check non-zero bin contribution @@ -886,7 +949,11 @@ MattesMutualInformationImageToImageMetricFor3DBLUTFFD JointPDFDerivativesValueType *tPdfDPtrEnd; unsigned int tPdfDPtrOffset; tPdfDPtrOffset = m_ThreaderJointPDFStartBin[threadID] * rowSize; +#if ITK_VERSION_MAJOR <= 4 for(unsigned int t=0; tm_NumberOfThreads-1; t++) { +#else + for(unsigned int t=0; tm_NumberOfWorkUnits-1; t++) { +#endif pdfDPtr = pdfDPtrStart; tPdfDPtr = m_ThreaderJointPDFDerivatives[t]->GetBufferPointer() + tPdfDPtrOffset; @@ -933,7 +1000,11 @@ MattesMutualInformationImageToImageMetricFor3DBLUTFFD } else { this->m_PRatioArray.Fill( 0.0 ); this->m_MetricDerivative.Fill( NumericTraits< MeasureType >::Zero ); +#if ITK_VERSION_MAJOR <= 4 for(unsigned int threadID = 0; threadID < this->m_NumberOfThreads-1; threadID++ ) { +#else + for(unsigned int threadID = 0; threadID < this->m_NumberOfWorkUnits-1; threadID++ ) { +#endif this->m_ThreaderMetricDerivative[threadID].Fill( NumericTraits< MeasureType >::Zero ); } this->m_ImplicitDerivativesSecondPass = false; @@ -941,9 +1012,6 @@ MattesMutualInformationImageToImageMetricFor3DBLUTFFD // Set up the parameters in the transform this->m_Transform->SetParameters( parameters ); -#if ITK_VERSION_MAJOR < 4 - this->m_Parameters = parameters; -#endif // MUST BE CALLED TO INITIATE PROCESSING ON SAMPLES this->GetValueAndDerivativeMultiThreadedInitiate(); @@ -951,7 +1019,11 @@ MattesMutualInformationImageToImageMetricFor3DBLUTFFD // CALL IF DOING THREADED POST PROCESSING this->GetValueAndDerivativeMultiThreadedPostProcessInitiate(); +#if ITK_VERSION_MAJOR <= 4 for(unsigned int threadID = 0; threadIDm_NumberOfThreads-1; threadID++) { +#else + for(unsigned int threadID = 0; threadIDm_NumberOfWorkUnits-1; threadID++) { +#endif m_JointPDFSum += m_ThreaderJointPDFSum[threadID]; } if ( m_JointPDFSum == 0.0 ) { @@ -1021,10 +1093,10 @@ MattesMutualInformationImageToImageMetricFor3DBLUTFFD // check for non-zero bin contribution if( jointPDFValue > 1e-16 && movingImagePDFValue > 1e-16 ) { - double pRatio = vcl_log(jointPDFValue / movingImagePDFValue ); + double pRatio = std::log(jointPDFValue / movingImagePDFValue ); if( fixedImagePDFValue > 1e-16) { - sum += jointPDFValue * ( pRatio - vcl_log(fixedImagePDFValue ) ); + sum += jointPDFValue * ( pRatio - std::log(fixedImagePDFValue ) ); } if( this->m_UseExplicitPDFDerivatives ) { @@ -1060,7 +1132,11 @@ MattesMutualInformationImageToImageMetricFor3DBLUTFFD // Consolidate the contributions from each one of the threads to the total // derivative. +#if ITK_VERSION_MAJOR <= 4 for(unsigned int t = 0; t < this->m_NumberOfThreads-1; t++ ) { +#else + for(unsigned int t = 0; t < this->m_NumberOfWorkUnits-1; t++ ) { +#endif DerivativeType * source = &(this->m_ThreaderMetricDerivative[t]); for(unsigned int pp=0; pp < this->m_NumberOfParameters; pp++ ) { this->m_MetricDerivative[pp] += (*source)[pp]; @@ -1156,13 +1232,8 @@ MattesMutualInformationImageToImageMetricFor3DBLUTFFD transform = this->m_Transform; } -#if ITK_VERSION_MAJOR >= 4 JacobianType jacobian; transform->ComputeJacobianWithRespectToParameters(this->m_FixedImageSamples[sampleNumber].point, jacobian); -#else - const JacobianType& jacobian = - transform->GetJacobian( this->m_FixedImageSamples[sampleNumber].point ); -#endif // for ( unsigned int mu = 0; mu < this->m_NumberOfParameters; mu++ ) // { @@ -1230,15 +1301,9 @@ MattesMutualInformationImageToImageMetricFor3DBLUTFFD indicesHelper = &(this->m_BSplineTransformIndices); } -#if ITK_VERSION_MAJOR >= 4 this->m_BSplineTransform->ComputeJacobianFromBSplineWeightsWithRespectToPosition( this->m_FixedImageSamples[sampleNumber].point, *weightsHelper, *indicesHelper ); -#else - this->m_BSplineTransform->GetJacobian( - this->m_FixedImageSamples[sampleNumber].point, - *weightsHelper, *indicesHelper ); -#endif } for( unsigned int dim = 0; dim < Superclass::FixedImageDimension; dim++ ) {