]> Creatis software - clitk.git/blobdiff - registration/itkOptMattesMutualInformationImageToImageMetricFor3DBLUTFFD.txx
Ensure compatibility with ITK < 4.12 for throw exception
[clitk.git] / registration / itkOptMattesMutualInformationImageToImageMetricFor3DBLUTFFD.txx
index efe9cba383476068a521e6f0edaa8e8c4bc81064..ef4257e6c66f0525a8c15806923a0aaead195ae2 100644 (file)
@@ -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<TFixedImage,TMovingImage>
 template <class TFixedImage, class TMovingImage>
 void
 MattesMutualInformationImageToImageMetricFor3DBLUTFFD<TFixedImage,TMovingImage>
+#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<TFixedImage,TMovingImage>
   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<TFixedImage,TMovingImage>
   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<TFixedImage,TMovingImage>
   }
   // 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
 
-  ThreadIdType threadID;
+  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<TFixedImage,TMovingImage>
     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<TFixedImage,TMovingImage>
 
   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() );
     }
   }
@@ -473,7 +531,7 @@ MattesMutualInformationImageToImageMetricFor3DBLUTFFD<TFixedImage,TMovingImage>
 template < class TFixedImage, class TMovingImage  >
 inline void
 MattesMutualInformationImageToImageMetricFor3DBLUTFFD<TFixedImage,TMovingImage>
-::GetValueThreadPreProcess( ThreadIdType threadID,
+::GetValueThreadPreProcess( unsigned int threadID,
                             bool withinSampleThread ) const
 {
 
@@ -501,7 +559,7 @@ MattesMutualInformationImageToImageMetricFor3DBLUTFFD<TFixedImage,TMovingImage>
 template < class TFixedImage, class TMovingImage  >
 inline bool
 MattesMutualInformationImageToImageMetricFor3DBLUTFFD<TFixedImage,TMovingImage>
-::GetValueThreadProcessSample( ThreadIdType threadID,
+::GetValueThreadProcessSample( unsigned int threadID,
                                unsigned long fixedImageSample,
                                const MovingImagePointType & itkNotUsed(mappedPoint),
                                double movingImageValue) const
@@ -576,7 +634,7 @@ MattesMutualInformationImageToImageMetricFor3DBLUTFFD<TFixedImage,TMovingImage>
 template < class TFixedImage, class TMovingImage  >
 inline void
 MattesMutualInformationImageToImageMetricFor3DBLUTFFD<TFixedImage,TMovingImage>
-::GetValueThreadPostProcess( ThreadIdType threadID,
+::GetValueThreadPostProcess( unsigned int threadID,
                              bool itkNotUsed(withinSampleThread) ) const
 {
   unsigned int t;
@@ -595,7 +653,11 @@ MattesMutualInformationImageToImageMetricFor3DBLUTFFD<TFixedImage,TMovingImage>
   unsigned int       tPdfPtrOffset;
   tPdfPtrOffset = ( m_ThreaderJointPDFStartBin[threadID]
                     * m_JointPDF->GetOffsetTable()[1] );
+#if ITK_VERSION_MAJOR <= 4
   for(t=0; t<this->m_NumberOfThreads-1; t++) {
+#else
+  for(t=0; t<this->m_NumberOfWorkUnits-1; t++) {
+#endif
     pdfPtr = pdfPtrStart;
     tPdfPtr = m_ThreaderJointPDF[t]->GetBufferPointer() + tPdfPtrOffset;
     tPdfPtrEnd = tPdfPtr + maxI;
@@ -630,7 +692,6 @@ MattesMutualInformationImageToImageMetricFor3DBLUTFFD<TFixedImage,TMovingImage>
 {
   // Set up the parameters in the transform
   this->m_Transform->SetParameters( parameters );
-  this->m_Parameters = parameters;
 
   // MUST BE CALLED TO INITIATE PROCESSING
   this->GetValueMultiThreadedInitiate();
@@ -638,7 +699,11 @@ MattesMutualInformationImageToImageMetricFor3DBLUTFFD<TFixedImage,TMovingImage>
   // MUST BE CALLED TO INITIATE PROCESSING
   this->GetValueMultiThreadedPostProcessInitiate();
 
-  for(ThreadIdType threadID = 0; threadID<this->m_NumberOfThreads-1; threadID++) {
+#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
     m_JointPDFSum += m_ThreaderJointPDFSum[threadID];
   }
   if ( m_JointPDFSum == 0.0 ) {
@@ -720,7 +785,7 @@ MattesMutualInformationImageToImageMetricFor3DBLUTFFD<TFixedImage,TMovingImage>
 template < class TFixedImage, class TMovingImage  >
 inline void
 MattesMutualInformationImageToImageMetricFor3DBLUTFFD<TFixedImage,TMovingImage>
-::GetValueAndDerivativeThreadPreProcess( ThreadIdType threadID,
+::GetValueAndDerivativeThreadPreProcess( unsigned int threadID,
     bool itkNotUsed(withinSampleThread) ) const
 {
   if(threadID > 0) {
@@ -757,7 +822,7 @@ MattesMutualInformationImageToImageMetricFor3DBLUTFFD<TFixedImage,TMovingImage>
 template < class TFixedImage, class TMovingImage  >
 inline bool
 MattesMutualInformationImageToImageMetricFor3DBLUTFFD<TFixedImage,TMovingImage>
-::GetValueAndDerivativeThreadProcessSample( ThreadIdType threadID,
+::GetValueAndDerivativeThreadProcessSample( unsigned int threadID,
     unsigned long fixedImageSample,
     const MovingImagePointType & itkNotUsed(mappedPoint),
     double movingImageValue,
@@ -864,7 +929,7 @@ MattesMutualInformationImageToImageMetricFor3DBLUTFFD<TFixedImage,TMovingImage>
 template < class TFixedImage, class TMovingImage  >
 inline void
 MattesMutualInformationImageToImageMetricFor3DBLUTFFD<TFixedImage,TMovingImage>
-::GetValueAndDerivativeThreadPostProcess( ThreadIdType threadID,
+::GetValueAndDerivativeThreadPostProcess( unsigned int threadID,
     bool withinSampleThread ) const
 {
   this->GetValueThreadPostProcess( threadID, withinSampleThread );
@@ -884,7 +949,11 @@ MattesMutualInformationImageToImageMetricFor3DBLUTFFD<TFixedImage,TMovingImage>
     JointPDFDerivativesValueType *tPdfDPtrEnd;
     unsigned int tPdfDPtrOffset;
     tPdfDPtrOffset = m_ThreaderJointPDFStartBin[threadID] *  rowSize;
+#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
       pdfDPtr = pdfDPtrStart;
       tPdfDPtr = m_ThreaderJointPDFDerivatives[t]->GetBufferPointer()
                  + tPdfDPtrOffset;
@@ -931,7 +1000,11 @@ MattesMutualInformationImageToImageMetricFor3DBLUTFFD<TFixedImage,TMovingImage>
   } else {
     this->m_PRatioArray.Fill( 0.0 );
     this->m_MetricDerivative.Fill( NumericTraits< MeasureType >::Zero );
-    for(ThreadIdType threadID = 0; threadID < this->m_NumberOfThreads-1; threadID++ ) {
+#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;
@@ -939,7 +1012,6 @@ MattesMutualInformationImageToImageMetricFor3DBLUTFFD<TFixedImage,TMovingImage>
 
   // Set up the parameters in the transform
   this->m_Transform->SetParameters( parameters );
-  this->m_Parameters = parameters;
 
   // MUST BE CALLED TO INITIATE PROCESSING ON SAMPLES
   this->GetValueAndDerivativeMultiThreadedInitiate();
@@ -947,7 +1019,11 @@ MattesMutualInformationImageToImageMetricFor3DBLUTFFD<TFixedImage,TMovingImage>
   // CALL IF DOING THREADED POST PROCESSING
   this->GetValueAndDerivativeMultiThreadedPostProcessInitiate();
 
-  for(ThreadIdType threadID = 0; threadID<this->m_NumberOfThreads-1; threadID++) {
+#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
     m_JointPDFSum += m_ThreaderJointPDFSum[threadID];
   }
   if ( m_JointPDFSum == 0.0 ) {
@@ -1056,7 +1132,11 @@ MattesMutualInformationImageToImageMetricFor3DBLUTFFD<TFixedImage,TMovingImage>
 
     // 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];
@@ -1091,7 +1171,7 @@ MattesMutualInformationImageToImageMetricFor3DBLUTFFD<TFixedImage,TMovingImage>
 template < class TFixedImage, class TMovingImage >
 void
 MattesMutualInformationImageToImageMetricFor3DBLUTFFD<TFixedImage,TMovingImage>
-::ComputePDFDerivatives( ThreadIdType threadID,
+::ComputePDFDerivatives( unsigned int threadID,
                          unsigned int sampleNumber,
                          int pdfMovingIndex,
                          const ImageDerivativesType & movingImageGradientValue,
@@ -1152,13 +1232,8 @@ MattesMutualInformationImageToImageMetricFor3DBLUTFFD<TFixedImage,TMovingImage>
       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++ )
     //       {
@@ -1226,15 +1301,9 @@ MattesMutualInformationImageToImageMetricFor3DBLUTFFD<TFixedImage,TMovingImage>
         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++ ) {