From 612401461fe73252d01515c7b483848cd3a4e87d Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Fri, 10 May 2024 14:57:17 +0200 Subject: [PATCH] STYLE: Remove `this->MakeOutput(0)` calls from constructors in Core MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In those cases, `MakeOutput(0)` just did `OutputType::New()` anyway. This commit avoids unnecessary casts and calls to virtual functions. Following C++ Core Guidelines, February 15, 2024, "Don’t call virtual functions in constructors and destructors", https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rc-ctor-virtual --- Modules/Core/Common/include/itkImageSource.hxx | 5 +---- Modules/Core/Mesh/include/itkImageToMeshFilter.hxx | 5 +---- Modules/Core/Mesh/include/itkMeshSource.hxx | 6 +----- 3 files changed, 3 insertions(+), 13 deletions(-) diff --git a/Modules/Core/Common/include/itkImageSource.hxx b/Modules/Core/Common/include/itkImageSource.hxx index 3103e4256eb5..e070c9aff184 100644 --- a/Modules/Core/Common/include/itkImageSource.hxx +++ b/Modules/Core/Common/include/itkImageSource.hxx @@ -39,11 +39,8 @@ namespace itk template ImageSource::ImageSource() { - // Create the output. We use static_cast<> here because we know the default - // output must be of type TOutputImage - typename TOutputImage::Pointer output = static_cast(this->MakeOutput(0).GetPointer()); this->ProcessObject::SetNumberOfRequiredOutputs(1); - this->ProcessObject::SetNthOutput(0, output.GetPointer()); + this->ProcessObject::SetNthOutput(0, TOutputImage::New().GetPointer()); #if defined(ITKV4_COMPATIBILITY) m_DynamicMultiThreading = false; diff --git a/Modules/Core/Mesh/include/itkImageToMeshFilter.hxx b/Modules/Core/Mesh/include/itkImageToMeshFilter.hxx index dd52325c777d..f2c43ad889ed 100644 --- a/Modules/Core/Mesh/include/itkImageToMeshFilter.hxx +++ b/Modules/Core/Mesh/include/itkImageToMeshFilter.hxx @@ -27,11 +27,8 @@ template ImageToMeshFilter::ImageToMeshFilter() { this->ProcessObject::SetNumberOfRequiredInputs(1); - - OutputMeshPointer output = dynamic_cast(this->MakeOutput(0).GetPointer()); - this->ProcessObject::SetNumberOfRequiredOutputs(1); - this->ProcessObject::SetNthOutput(0, output.GetPointer()); + this->ProcessObject::SetNthOutput(0, OutputMeshType::New().GetPointer()); } /** diff --git a/Modules/Core/Mesh/include/itkMeshSource.hxx b/Modules/Core/Mesh/include/itkMeshSource.hxx index b19e4e53ff26..f9727cb7fbe8 100644 --- a/Modules/Core/Mesh/include/itkMeshSource.hxx +++ b/Modules/Core/Mesh/include/itkMeshSource.hxx @@ -25,12 +25,8 @@ namespace itk template MeshSource::MeshSource() { - // Create the output. We use static_cast<> here because we know the default - // output must be of type TOutputMesh - OutputMeshPointer output = static_cast(this->MakeOutput(0).GetPointer()); - this->ProcessObject::SetNumberOfRequiredOutputs(1); - this->ProcessObject::SetNthOutput(0, output.GetPointer()); + this->ProcessObject::SetNthOutput(0, TOutputMesh::New().GetPointer()); m_GenerateDataRegion = 0; m_GenerateDataNumberOfRegions = 0;