[Insight-developers] Code Headscratcher for the day: GetValueAndDerivative
Ziv Yaniv
zivy at isis.georgetown.edu
Fri Dec 3 10:25:08 EST 2010
Hi Kent,
The redefinition of GetValueAndDerivative as a pure virtual method in
ImageToSpatialObjectMetric hiding the implementation from
SingleValuedCostFunction is indeed strange.
I believe it can be removed along with its (re)implementations in most
of the subclasses . Subclasses that want to do something smart, using
common sub-computations for both derivative and value can simply
override the GetValueAndDerivative method (most likely this was the
intention when it was defined as a virtual function in
SingleValuedCostFunction).
Also, I am of the opinion that SingleValuedCostFunction should not
define the GetDerivative/GetValueAndDerivative methods. This has to do
with my push to modify the optimization hierarchy [see
http://www.itk.org/Wiki/Proposals:Refactoring_of_optimization_framework ].
regards
Ziv
On 5:59 PM, kent williams wrote:
> 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?
>
>
>
--
Ziv Yaniv, PhD., Research Assistant Professor
Imaging Science and Information Systems (ISIS) Center
Department of Radiology
Georgetown University Medical Center
2115 Wisconsin Avenue, Suite 603
Washington, DC, 20007,
Phone: +1-202-6877286
Fax: +1-202-784-3479
email: zivy at isis.georgetown.edu
web: http://isiswiki.georgetown.edu/zivy/
More information about the Insight-developers
mailing list