diff --git a/Common/itkComputeDisplacementDistribution.h b/Common/itkComputeDisplacementDistribution.h index 73ce341f7..69059f8d5 100644 --- a/Common/itkComputeDisplacementDistribution.h +++ b/Common/itkComputeDisplacementDistribution.h @@ -99,9 +99,9 @@ class ITK_TEMPLATE_EXPORT ComputeDisplacementDistribution : public ScaledSingleV void SetFixedImageRegion(const FixedImageRegionType & region) { - if (region != this->m_FixedImageRegion) + if (region != m_FixedImageRegion) { - this->m_FixedImageRegion = region; + m_FixedImageRegion = region; } } @@ -124,7 +124,7 @@ class ITK_TEMPLATE_EXPORT ComputeDisplacementDistribution : public ScaledSingleV void SetNumberOfWorkUnits(ThreadIdType numberOfThreads) { - this->m_Threader->SetNumberOfWorkUnits(numberOfThreads); + m_Threader->SetNumberOfWorkUnits(numberOfThreads); } diff --git a/Common/itkComputeDisplacementDistribution.hxx b/Common/itkComputeDisplacementDistribution.hxx index b3f0dd63c..19c2c7ffa 100644 --- a/Common/itkComputeDisplacementDistribution.hxx +++ b/Common/itkComputeDisplacementDistribution.hxx @@ -45,7 +45,7 @@ template ComputeDisplacementDistribution::ComputeDisplacementDistribution() { /** Initialize the m_ThreaderParameters. */ - this->m_ThreaderParameters.st_Self = this; + m_ThreaderParameters.st_Self = this; } // end Constructor @@ -67,7 +67,7 @@ ComputeDisplacementDistribution::InitializeThreadingPar * each iteration, in the accumulate functions, in a multi-threaded fashion. * This has performance benefits for larger vector sizes. */ - const ThreadIdType numberOfThreads = this->m_Threader->GetNumberOfWorkUnits(); + const ThreadIdType numberOfThreads = m_Threader->GetNumberOfWorkUnits(); // For each thread, assign a struct of zero-initialized values. m_ComputePerThreadVariables.assign(numberOfThreads, AlignedComputePerThreadStruct()); @@ -100,24 +100,24 @@ ComputeDisplacementDistribution::ComputeSingleThreaded( const SizeValueType nrofsamples = sampleContainer->Size(); /** Get the number of parameters. */ - const auto numberOfParameters = static_cast(this->m_Transform->GetNumberOfParameters()); + const auto numberOfParameters = static_cast(m_Transform->GetNumberOfParameters()); /** Get scales vector */ const ScalesType & scales = this->GetScales(); - this->m_ScaledCostFunction->SetScales(scales); + Superclass::m_ScaledCostFunction->SetScales(scales); /** Get the exact gradient. */ - this->m_ExactGradient.set_size(numberOfParameters); - this->m_ExactGradient.Fill(0.0); - this->GetScaledDerivative(mu, this->m_ExactGradient); + m_ExactGradient.set_size(numberOfParameters); + m_ExactGradient.Fill(0.0); + this->GetScaledDerivative(mu, m_ExactGradient); /** Get transform and set current position. */ - const unsigned int outdim = this->m_Transform->GetOutputSpaceDimension(); + const unsigned int outdim = m_Transform->GetOutputSpaceDimension(); unsigned int samplenr = 0; /** Variables for nonzerojacobian indices and the Jacobian. */ - const SizeValueType sizejacind = this->m_Transform->GetNumberOfNonZeroJacobianIndices(); + const SizeValueType sizejacind = m_Transform->GetNumberOfNonZeroJacobianIndices(); JacobianType jacj(outdim, sizejacind, 0.0); NonZeroJacobianIndicesType jacind(sizejacind); jacind[0] = 0; @@ -143,7 +143,7 @@ ComputeDisplacementDistribution::ComputeSingleThreaded( { /** Read fixed coordinates and get Jacobian. */ const FixedImagePointType & point = sample.m_ImageCoordinates; - this->m_Transform->GetJacobian(point, jacj, jacind); + m_Transform->GetJacobian(point, jacj, jacind); /** Apply scales, if necessary. */ if (this->GetUseScales()) @@ -172,7 +172,7 @@ ComputeDisplacementDistribution::ComputeSingleThreaded( for (unsigned int j = 0; j < sizejacind; ++j) { int pj = jacind[j]; - temp += jacj(i, j) * this->m_ExactGradient(pj); + temp += jacj(i, j) * m_ExactGradient(pj); } Jgg(i) = temp; } @@ -218,7 +218,7 @@ ComputeDisplacementDistribution::Compute(const Paramete std::string methods) { /** Option for now to still use the single threaded code. */ - if (!this->m_UseMultiThread) + if (!m_UseMultiThread) { return this->ComputeSingleThreaded(mu, jacg, maxJJ, methods); } @@ -248,20 +248,20 @@ void ComputeDisplacementDistribution::BeforeThreadedCompute(const ParametersType & mu) { /** Get the number of parameters. */ - this->m_NumberOfParameters = - static_cast(this->m_Transform->GetNumberOfParameters()); // why is this parameter needed? + m_NumberOfParameters = + static_cast(m_Transform->GetNumberOfParameters()); // why is this parameter needed? /** Get scales vector */ const ScalesType & scales = this->GetScales(); - this->m_ScaledCostFunction->SetScales(scales); + Superclass::m_ScaledCostFunction->SetScales(scales); /** Get the exact gradient. */ - this->m_ExactGradient.set_size(this->m_NumberOfParameters); - this->m_ExactGradient.Fill(0.0); - this->GetScaledDerivative(mu, this->m_ExactGradient); + m_ExactGradient.set_size(m_NumberOfParameters); + m_ExactGradient.Fill(0.0); + this->GetScaledDerivative(mu, m_ExactGradient); /** Get samples. */ - this->m_SampleContainer = this->SampleFixedImageForJacobianTerms(); + m_SampleContainer = this->SampleFixedImageForJacobianTerms(); } // end BeforeThreadedCompute() @@ -275,7 +275,7 @@ void ComputeDisplacementDistribution::LaunchComputeThreaderCallback() const { /** Setup threader and launch. */ - this->m_Threader->SetSingleMethodAndExecute(this->ComputeThreaderCallback, &m_ThreaderParameters); + m_Threader->SetSingleMethodAndExecute(this->ComputeThreaderCallback, &m_ThreaderParameters); } // end LaunchComputeThreaderCallback() @@ -313,9 +313,9 @@ void ComputeDisplacementDistribution::ThreadedCompute(ThreadIdType threadId) { /** Get sample container size, number of threads, and output space dimension. */ - const SizeValueType sampleContainerSize = this->m_SampleContainer->Size(); - const ThreadIdType numberOfThreads = this->m_Threader->GetNumberOfWorkUnits(); - const unsigned int outdim = this->m_Transform->GetOutputSpaceDimension(); + const SizeValueType sampleContainerSize = m_SampleContainer->Size(); + const ThreadIdType numberOfThreads = m_Threader->GetNumberOfWorkUnits(); + const unsigned int outdim = m_Transform->GetOutputSpaceDimension(); /** Get a handle to the scales vector */ const ScalesType & scales = this->GetScales(); @@ -328,7 +328,7 @@ ComputeDisplacementDistribution::ThreadedCompute(Thread const auto pos_end = std::min(nrOfSamplesPerThreads * (threadId + 1), sampleContainerSize); /** Variables for nonzerojacobian indices and the Jacobian. */ - const SizeValueType sizejacind = this->m_Transform->GetNumberOfNonZeroJacobianIndices(); + const SizeValueType sizejacind = m_Transform->GetNumberOfNonZeroJacobianIndices(); JacobianType jacj(outdim, sizejacind, 0.0); NonZeroJacobianIndicesType jacind(sizejacind); jacind[0] = 0; @@ -349,7 +349,7 @@ ComputeDisplacementDistribution::ThreadedCompute(Thread unsigned long numberOfPixelsCounted = 0; /** Create iterator over the sample container. */ - const auto beginOfSampleContainer = this->m_SampleContainer->cbegin(); + const auto beginOfSampleContainer = m_SampleContainer->cbegin(); const auto threader_fbegin = beginOfSampleContainer + pos_begin; const auto threader_fend = beginOfSampleContainer + pos_end; @@ -358,7 +358,7 @@ ComputeDisplacementDistribution::ThreadedCompute(Thread { /** Read fixed coordinates and get Jacobian. */ const FixedImagePointType & point = threader_fiter->m_ImageCoordinates; - this->m_Transform->GetJacobian(point, jacj, jacind); + m_Transform->GetJacobian(point, jacj, jacind); /** Apply scales, if necessary. */ if (this->GetUseScales()) @@ -387,7 +387,7 @@ ComputeDisplacementDistribution::ThreadedCompute(Thread for (unsigned int j = 0; j < sizejacind; ++j) { int pj = jacind[j]; - temp += jacj(i, j) * this->m_ExactGradient(pj); + temp += jacj(i, j) * m_ExactGradient(pj); } Jgg(i) = temp; } @@ -421,7 +421,7 @@ ComputeDisplacementDistribution::AfterThreadedCompute(d maxJJ = 0.0; double displacement = 0.0; double displacementSquared = 0.0; - this->m_NumberOfPixelsCounted = 0.0; + m_NumberOfPixelsCounted = 0.0; /** Accumulate thread results. */ for (const auto & computePerThreadStruct : m_ComputePerThreadVariables) @@ -429,14 +429,14 @@ ComputeDisplacementDistribution::AfterThreadedCompute(d maxJJ = std::max(maxJJ, computePerThreadStruct.st_MaxJJ); displacement += computePerThreadStruct.st_Displacement; displacementSquared += computePerThreadStruct.st_DisplacementSquared; - this->m_NumberOfPixelsCounted += computePerThreadStruct.st_NumberOfPixelsCounted; + m_NumberOfPixelsCounted += computePerThreadStruct.st_NumberOfPixelsCounted; } // Reset all variables for the next resolution. std::fill_n(m_ComputePerThreadVariables.begin(), m_ComputePerThreadVariables.size(), AlignedComputePerThreadStruct()); /** Compute the sigma of the distribution of the displacements. */ - const double meanDisplacement = displacement / this->m_NumberOfPixelsCounted; - const double sigma = displacementSquared / this->m_NumberOfPixelsCounted - vnl_math::sqr(meanDisplacement); + const double meanDisplacement = displacement / m_NumberOfPixelsCounted; + const double sigma = displacementSquared / m_NumberOfPixelsCounted - vnl_math::sqr(meanDisplacement); jacg = meanDisplacement + 2.0 * std::sqrt(sigma); @@ -468,24 +468,24 @@ ComputeDisplacementDistribution::ComputeUsingSearchDire const SizeValueType nrofsamples = sampleContainer->Size(); /** Get the number of parameters. */ - const auto numberOfParameters = static_cast(this->m_Transform->GetNumberOfParameters()); + const auto numberOfParameters = static_cast(m_Transform->GetNumberOfParameters()); /** Get scales vector */ const ScalesType & scales = this->GetScales(); - this->m_ScaledCostFunction->SetScales(scales); + Superclass::m_ScaledCostFunction->SetScales(scales); /** Get the exact gradient. */ DerivativeType exactgradient(numberOfParameters); exactgradient = mu; /** Get transform and set current position. */ - typename TransformType::Pointer transform = this->m_Transform; - const unsigned int outdim = this->m_Transform->GetOutputSpaceDimension(); + typename TransformType::Pointer transform = m_Transform; + const unsigned int outdim = m_Transform->GetOutputSpaceDimension(); unsigned int samplenr = 0; /** Variables for nonzerojacobian indices and the Jacobian. */ - const SizeValueType sizejacind = this->m_Transform->GetNumberOfNonZeroJacobianIndices(); + const SizeValueType sizejacind = m_Transform->GetNumberOfNonZeroJacobianIndices(); JacobianType jacj(outdim, sizejacind, 0.0); NonZeroJacobianIndicesType jacind(sizejacind); jacind[0] = 0; @@ -509,7 +509,7 @@ ComputeDisplacementDistribution::ComputeUsingSearchDire { /** Read fixed coordinates and get Jacobian. */ const FixedImagePointType & point = sample.m_ImageCoordinates; - this->m_Transform->GetJacobian(point, jacj, jacind); + m_Transform->GetJacobian(point, jacj, jacind); /** Apply scales, if necessary. */ if (this->GetUseScales()) @@ -573,16 +573,16 @@ ComputeDisplacementDistribution::SampleFixedImageForJac /** Set up grid sampler. */ ImageGridSamplerPointer sampler = ImageGridSamplerType::New(); // ImageFullSamplerPointer sampler = ImageFullSamplerType::New(); - sampler->SetInput(this->m_FixedImage); + sampler->SetInput(m_FixedImage); sampler->SetInputImageRegion(this->GetFixedImageRegion()); - sampler->SetMask(this->m_FixedImageMask); + sampler->SetMask(m_FixedImageMask); /** Determine grid spacing of sampler such that the desired * NumberOfJacobianMeasurements is achieved approximately. * Note that the actually obtained number of samples may be lower, due to masks. * This is taken into account at the end of this function. */ - SizeValueType nrofsamples = this->m_NumberOfJacobianMeasurements; + SizeValueType nrofsamples = m_NumberOfJacobianMeasurements; sampler->SetNumberOfSamples(nrofsamples); /** Get samples and check the actually obtained number of samples. */ @@ -592,7 +592,7 @@ ComputeDisplacementDistribution::SampleFixedImageForJac if (nrofsamples == 0) { - itkExceptionMacro("No valid voxels (0/" << this->m_NumberOfJacobianMeasurements + itkExceptionMacro("No valid voxels (0/" << m_NumberOfJacobianMeasurements << ") found to estimate the AdaptiveStochasticGradientDescent parameters."); } return sampleContainer;