[Insight-developers] Better Point Casting
Luis Ibanez
luis.ibanez@kitware.com
Wed, 20 Feb 2002 12:05:58 -0500
Miller, James V (CRD) wrote:
>It would be a little more convenient to have the Cast...() method return
>the casted values rather than have to pass an appropriate one in. But since
>we can't have an overloaded function with the same input parameters and only
>differ in return type, then we are probably stuck.
>
That's right,
we also may not want to pay for the overload of copying Vectors and
Points through
the return and operator=().
>
>
>As for the "confusion" associated with these casts: I think as long as they are
>not implicit casts then we are okay. If the developer needs to do an explicit cast
>we should not stand in their way.
>
It sounds reasonable, anyway we cannot stop the users for doing their
own for() loops
if they want to convert the types...
Would be nice to put all this casting functions in an independent file.
How : itkCasting.h sound ?
In fact, if we do not care about restricting the types of the array-like
objects to be
converted we could just create one templated function. That also raise
the question
if these classes should return their dimension by using a generic method :
unsigned int GetDimension( void ) const
instead of:
GetVectorDimension()
GetPointDimension()
GetCovariantVectorDimension();
>
>The bottom line was that I knew what I was doing and was aware that the coordinates
>I wanted to specify for my spatial function matched the "radius size" of my
>Neighborhood. But since there was not "converter" function, I had to write
>a series of small loops. These small loops can confuse the reader of the code because
>unless they are commented well, there is nothing to indicate why the "copy" is being
>done.
>
Ok, we can follow the C approach : "The programmer knows what he is doing"
given that the casts are explicit they should be aware of the implications.
That will save us from writing a lot of code too :-)
Luis