Skip to content

Commit b03347b

Browse files
N-Dekkerdzenanz
authored andcommitted
STYLE: Declare ImageGaussianModelEstimator::m_Covariance as unique_ptr
Also defaulted the destructor of `ImageGaussianModelEstimator`.
1 parent 8992dcf commit b03347b

2 files changed

Lines changed: 8 additions & 15 deletions

File tree

Modules/Segmentation/Classifiers/include/itkImageGaussianModelEstimator.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include <cmath>
2222
#include <cfloat>
23+
#include <memory> // For unique_ptr.
2324

2425
#include "vnl/vnl_vector.h"
2526
#include "vnl/vnl_matrix.h"
@@ -124,7 +125,7 @@ class ITK_TEMPLATE_EXPORT ImageGaussianModelEstimator : public ImageModelEstimat
124125

125126
protected:
126127
ImageGaussianModelEstimator() = default;
127-
~ImageGaussianModelEstimator() override;
128+
~ImageGaussianModelEstimator() override = default;
128129
void
129130
PrintSelf(std::ostream & os, Indent indent) const override;
130131

@@ -151,9 +152,9 @@ class ITK_TEMPLATE_EXPORT ImageGaussianModelEstimator : public ImageModelEstimat
151152
void
152153
EstimateGaussianModelParameters();
153154

154-
MatrixType m_NumberOfSamples;
155-
MatrixType m_Means;
156-
MatrixType * m_Covariance{ nullptr };
155+
MatrixType m_NumberOfSamples;
156+
MatrixType m_Means;
157+
std::unique_ptr<MatrixType[]> m_Covariance{ nullptr };
157158

158159
TrainingImagePointer m_TrainingImage;
159160
};

Modules/Segmentation/Classifiers/include/itkImageGaussianModelEstimator.hxx

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,11 @@
2020

2121
#include "itkMath.h"
2222
#include "itkNumericTraits.h"
23+
#include "itkMakeUniqueForOverwrite.h"
2324

2425
namespace itk
2526
{
2627

27-
template <typename TInputImage, typename TMembershipFunction, typename TTrainingImage>
28-
ImageGaussianModelEstimator<TInputImage, TMembershipFunction, TTrainingImage>::~ImageGaussianModelEstimator()
29-
{
30-
delete[] m_Covariance;
31-
}
32-
33-
3428
template <typename TInputImage, typename TMembershipFunction, typename TTrainingImage>
3529
void
3630
ImageGaussianModelEstimator<TInputImage, TMembershipFunction, TTrainingImage>::PrintSelf(std::ostream & os,
@@ -40,7 +34,7 @@ ImageGaussianModelEstimator<TInputImage, TMembershipFunction, TTrainingImage>::P
4034

4135
os << indent << "NumberOfSamples: " << m_NumberOfSamples << std::endl;
4236
os << indent << "Means: " << m_Means << std::endl;
43-
os << indent << "Covariance: " << m_Covariance << std::endl;
37+
os << indent << "Covariance: " << m_Covariance.get() << std::endl;
4438

4539
itkPrintSelfObjectMacro(TrainingImage);
4640
}
@@ -139,10 +133,8 @@ ImageGaussianModelEstimator<TInputImage, TMembershipFunction, TTrainingImage>::E
139133
m_NumberOfSamples.set_size(numberOfModels, 1);
140134
m_NumberOfSamples.fill(0);
141135

142-
// Delete previous allocation first
143-
delete[] m_Covariance;
144136
// Number of covariance matrices are equal to the number of classes
145-
m_Covariance = (MatrixType *)new MatrixType[numberOfModels];
137+
m_Covariance = make_unique_for_overwrite<MatrixType[]>(numberOfModels);
146138

147139
for (unsigned int i = 0; i < numberOfModels; ++i)
148140
{

0 commit comments

Comments
 (0)