[Insight-developers] CastImageFilter

Miller, James V (CRD) millerjv@crd.ge.com
Fri, 22 Mar 2002 10:05:16 -0500


Luis,

Why doesn't SetFunctor() work?

I think this should work for the same reason that you can set the comparitor used in
std::priority_queue

Jim


-----Original Message-----
From: Luis Ibanez [mailto:luis.ibanez@kitware.com]
Sent: Friday, March 22, 2002 9:54 AM
To: Miller, James V (CRD)
Cc: 'Joshua Cates'; Insight-Developers
Subject: Re: [Insight-developers] CastImageFilter



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