[Insight-developers] Code Headscratcher for the day: GetValueAndDerivative
kent williams
norman-k-williams at uiowa.edu
Thu Dec 2 16:35:42 EST 2010
This came up in addressing this bug report:
http://public.kitware.com/Bug/view.php?id=11379
itk::ImageToSpatialObjectMetric is derived from
itk::SingleValuedCostFunction.
SingleValuedCostFunction has a virtual method GetValueAndDerivative.
ImageToSpatialObjectMetric has a pure virtual method GetValueAndDerivative
with the same function signature.
The bug report says that the pure virtual declarations for GetValue and
GetDerivative in ImageToSpatialObjectMetric are redundant and need removing.
But this is the first time I've seen a class redefine an implemented virtual
function in the parent as pure virtual.
And in this case, I don't know why it does so. How many ways are there to
implement GetValueAndDerivative? In fact it is defined exactly the same ways
as it is in itk::SingleValuedCostFunction in
itk::EuclideanDistancePointMetric
itk::GradientDifferenceImageToImageMetric
itk::HistogramImageToImageMetric
itk::MeanReciprocalSquareDifferencePointSetToImageMetric gets a gold star
for breaking the pattern, but it does so by implementing GetValue and
GetDerivative, but then implementing GetValueAndDerivative by block-copying
the text of the two simpler functions into one method.
And while I'm on the subject of headscratchers -- why does
itk::ImageToImageMetric define some methods as virtual inline? In-line
means expand the function body in-line where its called, and virtual means
call the function via a pointer in the object's VTable. How do you do both?
More information about the Insight-developers
mailing list