[Insight-developers] Better Point Casting

Luis Ibanez luis.ibanez@kitware.com
Wed, 20 Feb 2002 10:02:02 -0500


Miller, James V (CRD) wrote:

> I was thinking it might be nice to have CastFrom() on other objects as 
> well.
> In particular: Index, Offset, Size, ContinuousIndex, ...


Totally agree with that, we have a lot of for() loops here
and there for doing this (as you already noted).

Should we restrict the number of combination to those that
make sense ?  

We could just add a limited liability function:

     template < arraytype A, arraytype B >
     void
     CastAtYourOwnRisk( const arraytype & A, arraytype & B );

templated function (not belonging to any class) relying on the
types to have defined: { ValueType, Dimension and operator[] }.
...trust the users and hope for the best....!


I would rather not allow casting Points to Vectors because
that blurrs the distintion between both concepts and removes
all the interest in having both classes we could just have
itkArrays in that case. Same thing goes for the distinction
between Index and Size for example.

>
> Should this be a class member or a separate function?

It looks like separate functions will provide more flexibility.
Maybe putting all of then in an    itkCasting.h      file ?

>
> When I want to use the Radius of a Neighborhood as the
> Center of an EllipsoidSpatialFunction, I need to create a
> Point and copy the radius:

Isn't this a missuse of the concepts ?
Why would you like to use a radius as a center ?
I can see the need for using an Index as a Point and vice-versa;
the same relation seems to work for Size and Vector.
In general trying to cast:  Index to Size or Point to Vector
should be an indication that something wrong is going on.

>
> If we use functions outside of the class, we could avoid
> templated member functions.

This seems to be the best option.
It will be a matter of selecting what combinations of casting
should be allowed.


I'm having trouble finding  a good differenciation between
an itkPoint and an itkContinuousIndex. It looks like a Point
could be used everywhere a ContinuousIndex is being used.

It is just a distinction of the reference system ?


Luis