Skip to content

Commit

Permalink
PERF: Remove BSplineInterpolationWeightFunction Kernel, use FastEvaluate
Browse files Browse the repository at this point in the history
Removed the dynamically allocated `m_Kernel` data member from
`BSplineInterpolationWeightFunction` and replaced the virtual function
call `m_Kernel->Evaluate(x)` by a faster static member function call, to
the newly added `BSplineKernelFunction::FastEvaluate` member function.

May significantly improve the performance of
`BSplineInterpolationWeightFunction`.
  • Loading branch information
N-Dekker committed Sep 5, 2021
1 parent 99f04d7 commit c23944b
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

#include "itkFunctionBase.h"
#include "itkContinuousIndex.h"
#include "itkBSplineKernelFunction.h"
#include "itkArray.h"
#include "itkArray2D.h"
#include "itkMath.h"
Expand Down Expand Up @@ -122,12 +121,6 @@ class ITK_TEMPLATE_EXPORT BSplineInterpolationWeightFunction

/** Table mapping linear offset to indices. */
TableType m_OffsetToIndexTable;

/** Interpolation kernel type. */
using KernelType = BSplineKernelFunction<Self::SplineOrder>;

/** Interpolation kernel. */
typename KernelType::Pointer m_Kernel;
};
} // end namespace itk

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#define itkBSplineInterpolationWeightFunction_hxx

#include "itkBSplineInterpolationWeightFunction.h"
#include "itkBSplineKernelFunction.h"
#include "itkImage.h"
#include "itkMatrix.h"
#include "itkMath.h"
Expand All @@ -44,10 +45,6 @@ BSplineInterpolationWeightFunction<TCoordRep, VSpaceDimension, VSplineOrder>::BS
}
++counter;
}


// Initialize the interpolation kernel
m_Kernel = KernelType::New();
}

/**
Expand Down Expand Up @@ -104,7 +101,7 @@ BSplineInterpolationWeightFunction<TCoordRep, VSpaceDimension, VSplineOrder>::Ev

for (k = 0; k <= SplineOrder; ++k)
{
weights1D[j][k] = m_Kernel->Evaluate(x);
weights1D[j][k] = BSplineKernelFunction<SplineOrder>::FastEvaluate(x);
x -= 1.0;
}
}
Expand Down

0 comments on commit c23944b

Please sign in to comment.