Skip to content

Commit

Permalink
STYLE: Simplify code by calling ProcessObject::SetRequiredOutputs
Browse files Browse the repository at this point in the history
Reduced amount of duplicate code.
  • Loading branch information
N-Dekker committed May 22, 2024
1 parent 044fc44 commit 5d3c7ca
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,8 @@ namespace itk
template <typename TInputImage, typename TOutputImage, typename TVoronoiImage>
DanielssonDistanceMapImageFilter<TInputImage, TOutputImage, TVoronoiImage>::DanielssonDistanceMapImageFilter()
{
this->SetNumberOfRequiredOutputs(3);

// distance map
this->SetNthOutput(0, this->MakeOutput(0));

// voronoi map
this->SetNthOutput(1, this->MakeOutput(1));

// distance vectors
this->SetNthOutput(2, this->MakeOutput(2));
// distance map, voronoi map, distance vectors
ProcessObject::SetRequiredOutputs(*this, 3);

m_SquaredDistance = false;
m_InputIsBinary = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,8 @@ template <typename TInputImage, typename TOutputImage, typename TVoronoiImage>
SignedDanielssonDistanceMapImageFilter<TInputImage, TOutputImage, TVoronoiImage>::
SignedDanielssonDistanceMapImageFilter()
{
this->SetNumberOfRequiredOutputs(3);

// distance map
this->SetNthOutput(0, static_cast<OutputImageType *>(this->MakeOutput(0).GetPointer()));

// voronoi map
this->SetNthOutput(1, static_cast<VoronoiImageType *>(this->MakeOutput(1).GetPointer()));

// distance vectors
this->SetNthOutput(2, static_cast<VectorImageType *>(this->MakeOutput(2).GetPointer()));
// distance map, voronoi map, distance vectors
ProcessObject::SetRequiredOutputs(*this, 3);

// Default values
this->m_SquaredDistance = false; // Should we remove this ?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ template <typename TInputImage, typename TEigenValueImage, typename TEigenVector
EigenAnalysis2DImageFilter<TInputImage, TEigenValueImage, TEigenVectorImage>::EigenAnalysis2DImageFilter()
{
this->SetNumberOfRequiredInputs(3);
this->SetNumberOfRequiredOutputs(3);
this->SetNthOutput(0, this->MakeOutput(0));
this->SetNthOutput(1, this->MakeOutput(1));
this->SetNthOutput(2, this->MakeOutput(2));
ProcessObject::SetRequiredOutputs(*this, 3);
static_assert(EigenVectorType::Dimension == 2, "Error: PixelType of EigenVector Image must have exactly 2 elements!");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ template <typename TSample>
CovarianceSampleFilter<TSample>::CovarianceSampleFilter()
{
this->ProcessObject::SetNumberOfRequiredInputs(1);
this->ProcessObject::SetNumberOfRequiredOutputs(2);

this->ProcessObject::SetNthOutput(0, this->MakeOutput(0));
this->ProcessObject::SetNthOutput(1, this->MakeOutput(1));
ProcessObject::SetRequiredOutputs(*this, 2);
}

template <typename TSample>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ template <typename TSample>
StandardDeviationPerComponentSampleFilter<TSample>::StandardDeviationPerComponentSampleFilter()
{
this->ProcessObject::SetNumberOfRequiredInputs(1);
this->ProcessObject::SetNumberOfRequiredOutputs(2);

this->ProcessObject::SetNthOutput(0, this->MakeOutput(0));
this->ProcessObject::SetNthOutput(1, this->MakeOutput(1));
ProcessObject::SetRequiredOutputs(*this, 2);
}

template <typename TSample>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,8 @@ BlockMatchingImageFilter<TFixedImage, TMovingImage, TFeatures, TDisplacements, T
this->m_BlockRadius.Fill(2);
this->m_SearchRadius.Fill(3);

// make the outputs
this->ProcessObject::SetNumberOfRequiredOutputs(2);
typename DisplacementsType::Pointer displacements =
static_cast<DisplacementsType *>(this->MakeOutput(0).GetPointer());
this->SetNthOutput(0, displacements.GetPointer());
typename SimilaritiesType::Pointer similarities = static_cast<SimilaritiesType *>(this->MakeOutput(1).GetPointer());
this->SetNthOutput(1, similarities.GetPointer());
// make the outputs (Displacements, Similarities)
ProcessObject::SetRequiredOutputs(*this, 2);

// all inputs are required
this->SetPrimaryInputName("FeaturePoints");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1354,13 +1354,9 @@ Segmenter<TInputImage>::Segmenter()
m_SortEdgeLists = true;
m_Connectivity.direction = nullptr;
m_Connectivity.index = nullptr;
typename OutputImageType::Pointer img = static_cast<OutputImageType *>(this->MakeOutput(0).GetPointer());
typename SegmentTableType::Pointer st = static_cast<SegmentTableType *>(this->MakeOutput(1).GetPointer());
typename BoundaryType::Pointer bd = static_cast<BoundaryType *>(this->MakeOutput(2).GetPointer());
this->SetNumberOfRequiredOutputs(3);
this->ProcessObject::SetNthOutput(0, img.GetPointer());
this->ProcessObject::SetNthOutput(1, st.GetPointer());
this->ProcessObject::SetNthOutput(2, bd.GetPointer());

// OutputImage, SegmentTable, Boundary
ProcessObject::SetRequiredOutputs(*this, 3);

// Allocate memory for connectivity
m_Connectivity.size = 2 * ImageDimension;
Expand Down

0 comments on commit 5d3c7ca

Please sign in to comment.