diff --git a/Common/Transforms/itkAdvancedImageMomentsCalculator.h b/Common/Transforms/itkAdvancedImageMomentsCalculator.h index 88c50e717..6a8631e5d 100644 --- a/Common/Transforms/itkAdvancedImageMomentsCalculator.h +++ b/Common/Transforms/itkAdvancedImageMomentsCalculator.h @@ -32,6 +32,8 @@ #include "itkMultiThreader.h" +#include + namespace itk { /** \class AdvancedImageMomentsCalculator @@ -285,8 +287,7 @@ class AdvancedImageMomentsCalculator : public Object mutable MultiThreaderParameterType m_ThreaderParameters; - mutable AlignedComputePerThreadStruct * m_ComputePerThreadVariables; - mutable ThreadIdType m_ComputePerThreadVariablesSize; + mutable std::vector m_ComputePerThreadVariables; bool m_UseMultiThread; SizeValueType m_NumberOfPixelsCounted; diff --git a/Common/Transforms/itkAdvancedImageMomentsCalculator.hxx b/Common/Transforms/itkAdvancedImageMomentsCalculator.hxx index c88d60e87..c89fdc1cc 100644 --- a/Common/Transforms/itkAdvancedImageMomentsCalculator.hxx +++ b/Common/Transforms/itkAdvancedImageMomentsCalculator.hxx @@ -78,8 +78,6 @@ AdvancedImageMomentsCalculator< TImage >::AdvancedImageMomentsCalculator(void) this->m_ThreaderParameters.st_Self = this; // Multi-threading structs - this->m_ComputePerThreadVariables = NULL; - this->m_ComputePerThreadVariablesSize = 0; this->m_CenterOfGravityUsesLowerThreshold = false; this->m_NumberOfSamplesForCenteredTransformInitialization = 10000; this->m_LowerThresholdForCenterGravity = 500; @@ -91,7 +89,6 @@ template< typename TImage > AdvancedImageMomentsCalculator< TImage >:: ~AdvancedImageMomentsCalculator() { - delete[] this->m_ComputePerThreadVariables; } /** @@ -114,24 +111,9 @@ AdvancedImageMomentsCalculator< TImage > */ const ThreadIdType numberOfThreads = this->m_Threader->GetNumberOfThreads(); - /** Only resize the array of structs when needed. */ - if (this->m_ComputePerThreadVariablesSize != numberOfThreads) - { - delete[] this->m_ComputePerThreadVariables; - this->m_ComputePerThreadVariables = new AlignedComputePerThreadStruct[numberOfThreads]; - this->m_ComputePerThreadVariablesSize = numberOfThreads; - } - - /** Some initialization. */ - for (ThreadIdType i = 0; i < numberOfThreads; ++i) - { - this->m_ComputePerThreadVariables[i].st_M0 = NumericTraits< ScalarType >::Zero; - this->m_ComputePerThreadVariables[i].st_M1 = NumericTraits< typename VectorType::ValueType >::Zero; - this->m_ComputePerThreadVariables[i].st_M2.Fill(NumericTraits< typename MatrixType::ValueType >::ZeroValue()); - this->m_ComputePerThreadVariables[i].st_Cg = NumericTraits< typename VectorType::ValueType >::Zero; - this->m_ComputePerThreadVariables[i].st_Cm.Fill(NumericTraits< typename MatrixType::ValueType >::ZeroValue()); - this->m_ComputePerThreadVariables[i].st_NumberOfPixelsCounted = NumericTraits< SizeValueType >::Zero; - } + /** Resize (if necessary) and assign structs of zero-initialized values */ + this->m_ComputePerThreadVariables.resize(numberOfThreads); + this->m_ComputePerThreadVariables.assign(numberOfThreads, AlignedComputePerThreadStruct{}); } // end InitializeThreadingParameters() diff --git a/Common/itkComputeDisplacementDistribution.h b/Common/itkComputeDisplacementDistribution.h index 1ae5b3cb0..2773fe03a 100644 --- a/Common/itkComputeDisplacementDistribution.h +++ b/Common/itkComputeDisplacementDistribution.h @@ -26,6 +26,8 @@ #include "itkImageFullSampler.h" #include "itkMultiThreader.h" +#include + namespace itk { /**\class ComputeDisplacementDistribution @@ -216,8 +218,7 @@ class ComputeDisplacementDistribution : mutable MultiThreaderParameterType m_ThreaderParameters; - mutable AlignedComputePerThreadStruct * m_ComputePerThreadVariables; - mutable ThreadIdType m_ComputePerThreadVariablesSize; + mutable std::vector m_ComputePerThreadVariables; SizeValueType m_NumberOfPixelsCounted; bool m_UseMultiThread; diff --git a/Common/itkComputeDisplacementDistribution.hxx b/Common/itkComputeDisplacementDistribution.hxx index e358cff21..baae73396 100644 --- a/Common/itkComputeDisplacementDistribution.hxx +++ b/Common/itkComputeDisplacementDistribution.hxx @@ -63,10 +63,6 @@ ComputeDisplacementDistribution< TFixedImage, TTransform > /** Initialize the m_ThreaderParameters. */ this->m_ThreaderParameters.st_Self = this; - // Multi-threading structs - this->m_ComputePerThreadVariables = NULL; - this->m_ComputePerThreadVariablesSize = 0; - } // end Constructor @@ -78,7 +74,6 @@ template< class TFixedImage, class TTransform > ComputeDisplacementDistribution< TFixedImage, TTransform > ::~ComputeDisplacementDistribution() { - delete[] this->m_ComputePerThreadVariables; } // end Destructor @@ -102,22 +97,9 @@ ComputeDisplacementDistribution< TFixedImage, TTransform > */ const ThreadIdType numberOfThreads = this->m_Threader->GetNumberOfThreads(); - /** Only resize the array of structs when needed. */ - if( this->m_ComputePerThreadVariablesSize != numberOfThreads ) - { - delete[] this->m_ComputePerThreadVariables; - this->m_ComputePerThreadVariables = new AlignedComputePerThreadStruct[ numberOfThreads ]; - this->m_ComputePerThreadVariablesSize = numberOfThreads; - } - - /** Some initialization. */ - for( ThreadIdType i = 0; i < numberOfThreads; ++i ) - { - this->m_ComputePerThreadVariables[ i ].st_MaxJJ = NumericTraits< double >::Zero; - this->m_ComputePerThreadVariables[ i ].st_Displacement = NumericTraits< double >::Zero; - this->m_ComputePerThreadVariables[ i ].st_DisplacementSquared = NumericTraits< double >::Zero; - this->m_ComputePerThreadVariables[ i ].st_NumberOfPixelsCounted = NumericTraits< SizeValueType >::Zero; - } + /** Resize (if necessary) and assign structs of zero-initialized values */ + this->m_ComputePerThreadVariables.resize(numberOfThreads); + this->m_ComputePerThreadVariables.assign(numberOfThreads, AlignedComputePerThreadStruct{}); } // end InitializeThreadingParameters()