[Insight-developers] CastImageFilter

Luis Ibanez luis.ibanez@kitware.com
Fri, 22 Mar 2002 09:53:57 -0500


Josh, Jim,


Miller, James V (CRD) wrote:

>I think you can use the CastImageFilter as it is:
>
>1) As long as a cast operator is defined for converting RGB to itk::Vector, it
>should work out of the box.
>

That's right, the basic castings are all covered by this filter.
That is: 
all the C/C++ normal castings and, as Jim already said, all those involving
classes for which the cast operator to the output class is defined.

>
>2) You can call SetFunctor() on the CastImageFilter (defined in UnaryFunctorImageFilter) to set the
>functor to anyone you would like.
>
There is no "SetFunctor()" in this case.
The Functor has to be defined as a type at compile time.
It is not set at run time.

>
>There is no real problem adding the template parameter. Just not sure whether 
>it is really needed to accomplish what you want.
>

Adding another template parameter to CastFilter will make it equal to 
the UnaryFilter.  

If some fancy casting is needed the easiest way to obtain it is to copy 
the file itkCastingFilter.h
into  "myCastingFilter" and redefine the "Functor" that is already 
inside. That will require to
modify only one line of code: Line 46 where the current conversion is 
defined as:

   return  static_cast< TOutput >( A );

Let's say casting from RGB to float by extracting only the Red component 
will be done
with:

    return static_cast< float >( A[0] );         or
    return static_cast< float >( A.GetRed() );


The whole file is 87 lines  so it is almost to the point were in can be 
managed by a macro
that creates the whole filter is we provide : (1) Filter name  (2) code 
for line 46


Luis