Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

STYLE: Use std::unique_ptr for GradientImageFilter::m_BoundaryCondition #4512

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#include "itkImageToImageFilter.h"
#include "itkCovariantVector.h"
#include "itkImageRegionIterator.h"
#include "itkZeroFluxNeumannBoundaryCondition.h"
#include <memory> // For unique_ptr.

namespace itk
{
Expand Down Expand Up @@ -163,7 +165,7 @@ class ITK_TEMPLATE_EXPORT GradientImageFilter : public ImageToImageFilter<TInput

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

Expand Down Expand Up @@ -226,7 +228,9 @@ class ITK_TEMPLATE_EXPORT GradientImageFilter : public ImageToImageFilter<TInput
bool m_UseImageDirection{ true };

// allow setting the the m_BoundaryCondition
ImageBoundaryCondition<TInputImage, TInputImage> * m_BoundaryCondition{};
std::unique_ptr<ImageBoundaryCondition<TInputImage, TInputImage>> m_BoundaryCondition{
std::make_unique<ZeroFluxNeumannBoundaryCondition<TInputImage>>()
};
};
} // end namespace itk

Expand Down
15 changes: 3 additions & 12 deletions Modules/Filtering/ImageGradient/include/itkGradientImageFilter.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,16 @@ namespace itk
template <typename TInputImage, typename TOperatorValueType, typename TOutputValueType, typename TOutputImageType>
GradientImageFilter<TInputImage, TOperatorValueType, TOutputValueType, TOutputImageType>::GradientImageFilter()
{
// default boundary condition
m_BoundaryCondition = new ZeroFluxNeumannBoundaryCondition<TInputImage>();
this->DynamicMultiThreadingOn();
this->ThreaderUpdateProgressOff();
}

template <typename TInputImage, typename TOperatorValueType, typename TOutputValueType, typename TOutputImageType>
GradientImageFilter<TInputImage, TOperatorValueType, TOutputValueType, TOutputImageType>::~GradientImageFilter()
{
delete m_BoundaryCondition;
}

template <typename TInputImage, typename TOperatorValueType, typename TOutputValue, typename TOutputImage>
void
GradientImageFilter<TInputImage, TOperatorValueType, TOutputValue, TOutputImage>::OverrideBoundaryCondition(
ImageBoundaryCondition<TInputImage> * boundaryCondition)
{
delete m_BoundaryCondition;
m_BoundaryCondition = boundaryCondition;
m_BoundaryCondition.reset(boundaryCondition);
}

template <typename TInputImage, typename TOperatorValueType, typename TOutputValueType, typename TOutputImageType>
Expand Down Expand Up @@ -165,7 +156,7 @@ GradientImageFilter<TInputImage, TOperatorValueType, TOutputValueType, TOutputIm
{
nit = ConstNeighborhoodIterator<InputImageType>(radius, inputImage, face);
ImageRegionIterator<OutputImageType> it(outputImage, face);
nit.OverrideBoundaryCondition(m_BoundaryCondition);
nit.OverrideBoundaryCondition(m_BoundaryCondition.get());
nit.GoToBegin();

while (!nit.IsAtEnd())
Expand Down Expand Up @@ -220,7 +211,7 @@ GradientImageFilter<TInputImage, TOperatorValueType, TOutputValueType, TOutputIm
os << indent << "BoundaryCondition: ";
if (m_BoundaryCondition != nullptr)
{
os << m_BoundaryCondition << std::endl;
os << m_BoundaryCondition.get() << std::endl;
}
else
{
Expand Down
Loading