Skip to content

Commit

Permalink
STYLE: Declare ImageGaussianModelEstimator::m_Covariance as unique_ptr
Browse files Browse the repository at this point in the history
Also defaulted the destructor of `ImageGaussianModelEstimator`.
  • Loading branch information
N-Dekker authored and dzenanz committed Sep 14, 2022
1 parent 8992dcf commit b03347b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include <cmath>
#include <cfloat>
#include <memory> // For unique_ptr.

#include "vnl/vnl_vector.h"
#include "vnl/vnl_matrix.h"
Expand Down Expand Up @@ -124,7 +125,7 @@ class ITK_TEMPLATE_EXPORT ImageGaussianModelEstimator : public ImageModelEstimat

protected:
ImageGaussianModelEstimator() = default;
~ImageGaussianModelEstimator() override;
~ImageGaussianModelEstimator() override = default;
void
PrintSelf(std::ostream & os, Indent indent) const override;

Expand All @@ -151,9 +152,9 @@ class ITK_TEMPLATE_EXPORT ImageGaussianModelEstimator : public ImageModelEstimat
void
EstimateGaussianModelParameters();

MatrixType m_NumberOfSamples;
MatrixType m_Means;
MatrixType * m_Covariance{ nullptr };
MatrixType m_NumberOfSamples;
MatrixType m_Means;
std::unique_ptr<MatrixType[]> m_Covariance{ nullptr };

TrainingImagePointer m_TrainingImage;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,11 @@

#include "itkMath.h"
#include "itkNumericTraits.h"
#include "itkMakeUniqueForOverwrite.h"

namespace itk
{

template <typename TInputImage, typename TMembershipFunction, typename TTrainingImage>
ImageGaussianModelEstimator<TInputImage, TMembershipFunction, TTrainingImage>::~ImageGaussianModelEstimator()
{
delete[] m_Covariance;
}


template <typename TInputImage, typename TMembershipFunction, typename TTrainingImage>
void
ImageGaussianModelEstimator<TInputImage, TMembershipFunction, TTrainingImage>::PrintSelf(std::ostream & os,
Expand All @@ -40,7 +34,7 @@ ImageGaussianModelEstimator<TInputImage, TMembershipFunction, TTrainingImage>::P

os << indent << "NumberOfSamples: " << m_NumberOfSamples << std::endl;
os << indent << "Means: " << m_Means << std::endl;
os << indent << "Covariance: " << m_Covariance << std::endl;
os << indent << "Covariance: " << m_Covariance.get() << std::endl;

itkPrintSelfObjectMacro(TrainingImage);
}
Expand Down Expand Up @@ -139,10 +133,8 @@ ImageGaussianModelEstimator<TInputImage, TMembershipFunction, TTrainingImage>::E
m_NumberOfSamples.set_size(numberOfModels, 1);
m_NumberOfSamples.fill(0);

// Delete previous allocation first
delete[] m_Covariance;
// Number of covariance matrices are equal to the number of classes
m_Covariance = (MatrixType *)new MatrixType[numberOfModels];
m_Covariance = make_unique_for_overwrite<MatrixType[]>(numberOfModels);

for (unsigned int i = 0; i < numberOfModels; ++i)
{
Expand Down

0 comments on commit b03347b

Please sign in to comment.