[Insight-developers] Re: [Vxl-users] Optimizers : CostFunction and
Const-Correctness : ITK + VNL
Luis Ibanez
luis.ibanez at kitware.com
Thu Mar 10 23:50:01 EST 2005
Andrew,
Thanks for your rapid answer.
I agree with your statement regarding the possiblity of
using non-const cost_function methods inside the const
method of a different class.
Following your example I have modified the VNL CostFunction
Adaptors in ITK in such a way that they will provide safe
const-correctness face to ITK Optimizers and still use the
non-const calls of internal vnl_cost_functions.
The ITK wrappers around VNL optimizers have been modified
accordingly.
Regards,
Luis
--------------------------
Andrew Fitzgibbon wrote:
> Quick answer: those were designed pretty early, and predated widespread
> "mutable" support.
>
> Other answer: I'm surprosed you ever find yourself with an optimizer
> object whose constness propagates. If I want to fit an "Ellipse" to
> "Data", there are a variety of cost functions I might implement. One
> might be called "Sampson", and would be implemented thus:
>
> struct Sampson: public vnl_cost_function {
> const Data* thedata;
> CachedStuff thestuff;
>
> double f(vnl_vector<double> const& x) {
> Ellipse e(x);
> double tot(0);
> for k = 0 to data->n
> tot += e.distance(data->point[k]);
> cachedstuff.tot = tot;
> return tot;
> }
> };
>
>
> Then it might be used in a const method on Data:
>
> Ellipse Data::fitellipse() const
> {
> Sampson costfn;
> costfn.data = this;
> return Ellipse(amoeba(costfn));
> }
>
>
> I cannot see where constness will propagate, unless you try to
> multiply inherit Sampson from cost_function and Data, but why would
> one do that?
>
>
>
>
>
More information about the Insight-developers
mailing list