Skip to content

Commit 8fa2e4f

Browse files
N-Dekkerdzenanz
authored andcommitted
STYLE: Declare Ellipsoid SpatialFunction orientations as a fixed matrix
Declared the private (internal) EllipsoidInteriorExteriorSpatialFunction data member `m_Orientations` as a `vnl_matrix_fixed`, instead of a raw pointer to dynamically allocated memory. Defaulted the `EllipsoidInteriorExteriorSpatialFunction` destructor, as it now no longer needs to `delete` internal data pointers anymore. Following C++ Core Guidelines, April 10, 2022, "Prefer scoped objects, don’t heap-allocate unnecessarily", https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#r5-prefer-scoped-objects-dont-heap-allocate-unnecessarily
1 parent d7bb212 commit 8fa2e4f

2 files changed

Lines changed: 8 additions & 50 deletions

File tree

Modules/Core/Common/include/itkEllipsoidInteriorExteriorSpatialFunction.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class ITK_TEMPLATE_EXPORT EllipsoidInteriorExteriorSpatialFunction
8282

8383
protected:
8484
EllipsoidInteriorExteriorSpatialFunction();
85-
~EllipsoidInteriorExteriorSpatialFunction() override;
85+
~EllipsoidInteriorExteriorSpatialFunction() override = default;
8686

8787
void
8888
PrintSelf(std::ostream & os, Indent indent) const override;
@@ -95,7 +95,7 @@ class ITK_TEMPLATE_EXPORT EllipsoidInteriorExteriorSpatialFunction
9595
InputType m_Axes;
9696

9797
/** The orientation vectors (must be orthogonal) of the ellipsoid axes. */
98-
double ** m_Orientations;
98+
OrientationType m_Orientations{};
9999
};
100100
} // end namespace itk
101101

Modules/Core/Common/include/itkEllipsoidInteriorExteriorSpatialFunction.hxx

Lines changed: 6 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,10 @@ namespace itk
2525
template <unsigned int VDimension, typename TInput>
2626
EllipsoidInteriorExteriorSpatialFunction<VDimension, TInput>::EllipsoidInteriorExteriorSpatialFunction()
2727
{
28-
m_Orientations = nullptr;
2928
m_Axes.Fill(1.0f); // Lengths of ellipsoid axes.
3029
m_Center.Fill(0.0f); // Origin of ellipsoid
3130
}
3231

33-
template <unsigned int VDimension, typename TInput>
34-
EllipsoidInteriorExteriorSpatialFunction<VDimension, TInput>::~EllipsoidInteriorExteriorSpatialFunction()
35-
{
36-
unsigned int i;
37-
38-
if (m_Orientations)
39-
{
40-
for (i = 0; i < VDimension; ++i)
41-
{
42-
delete[] m_Orientations[i];
43-
}
44-
delete[] m_Orientations;
45-
}
46-
}
47-
4832
template <unsigned int VDimension, typename TInput>
4933
auto
5034
EllipsoidInteriorExteriorSpatialFunction<VDimension, TInput>::Evaluate(const InputType & position) const -> OutputType
@@ -84,31 +68,8 @@ template <unsigned int VDimension, typename TInput>
8468
void
8569
EllipsoidInteriorExteriorSpatialFunction<VDimension, TInput>::SetOrientations(const OrientationType & orientations)
8670
{
87-
unsigned int i, j;
88-
89-
// Initialize orientation vectors.
90-
if (m_Orientations)
91-
{
92-
for (i = 0; i < VDimension; ++i)
93-
{
94-
delete[] m_Orientations[i];
95-
}
96-
delete[] m_Orientations;
97-
}
98-
m_Orientations = new double *[VDimension];
99-
for (i = 0; i < VDimension; ++i)
100-
{
101-
m_Orientations[i] = new double[VDimension];
102-
}
103-
10471
// Set orientation vectors (must be orthogonal).
105-
for (i = 0; i < VDimension; ++i)
106-
{
107-
for (j = 0; j < VDimension; ++j)
108-
{
109-
m_Orientations[i][j] = orientations[i][j];
110-
}
111-
}
72+
m_Orientations = orientations;
11273
}
11374

11475
template <unsigned int VDimension, typename TInput>
@@ -121,17 +82,14 @@ EllipsoidInteriorExteriorSpatialFunction<VDimension, TInput>::PrintSelf(std::ost
12182

12283
os << indent << "Lengths of Ellipsoid Axes: " << m_Axes << std::endl;
12384
os << indent << "Origin of Ellipsoid: " << m_Center << std::endl;
124-
if (m_Orientations)
85+
os << indent << "Orientations: " << std::endl;
86+
for (i = 0; i < VDimension; ++i)
12587
{
126-
os << indent << "Orientations: " << std::endl;
127-
for (i = 0; i < VDimension; ++i)
88+
for (j = 0; j < VDimension; ++j)
12889
{
129-
for (j = 0; j < VDimension; ++j)
130-
{
131-
os << indent << indent << m_Orientations[i][j] << " ";
132-
}
133-
os << std::endl;
90+
os << indent << indent << m_Orientations[i][j] << " ";
13491
}
92+
os << std::endl;
13593
}
13694
}
13795
} // end namespace itk

0 commit comments

Comments
 (0)