[Insight-developers] Better Point Casting

Miller, James V (CRD) millerjv@crd.ge.com
Wed, 20 Feb 2002 09:30:38 -0500


Luis,

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

But in these cases, I would be looking for a
size.CastFrom(index)
index.CastFrom(size)
point.CastFrom(size)

etc.

Like your original CastFrom() method, it would enforce the 
matching of Dimension.

Currently, there is a good bit of code (short loops) to copy
an index to a size, size to a point, etc.


Should this be a class member or a separate function?

If it were a separate function, it might be simplier to have a 
CastTo() function.

Example:

Spatial functions default to taking a Point as input.
Neighborhoods use a Size to represent the radius of the kernel.

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:

  EllipsoidType::InputType center;
  for (i=0; i < VDimension; i++)
    {
    center[i] = this->GetRadius(i);
    }
  spatialFunction->SetCenter( center );

With CastFrom(), I'll be able to say

  EllipsoidType::InputType center;
  center.CastFrom( this->GetRadius() );
  spatialFunction->SetCenter( center );

With a CastTo(), I'd be able to say

  spatialFunction->SetCenter( this->GetRadius().CastToPoint() );

'Course, this may get us deep into templated member functions
(to be able to cast to different Point types: float, double).

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

Jim

-----Original Message-----
From: Luis Ibanez [mailto:luis.ibanez@kitware.com]
Sent: Wednesday, February 20, 2002 7:49 AM
To: Lydia Ng
Cc: insight-developers@public.kitware.com
Subject: [Insight-developers] Better Point Casting


Hi,

A better Casting function has been added to the itk::Point class.

This one is a templated member of the Point class. It is templated
over the representation type of the source Point (to be cast).

It looks like


template < typename TB>
void CastFrom( const Point< TB, PointDimension > & pa ) {
for(unsigned int i=0; i<PointDimension; i++)
  {
  (*this)[i] = static_cast< TCoordRep >( pa[i] );
  }
}


It has the advantage of enforcing Dimension matching on the source point
and restricting the cast only to Point types.

The use is like:

itk::Point< double, 3 >   pd;
itk::Point< float, 3 >   pf;

pf.CastFrom( pd );  


         Luis




_______________________________________________
Insight-developers mailing list
Insight-developers@public.kitware.com
http://public.kitware.com/mailman/listinfo/insight-developers