[Insight-developers] Re: traits and numeric_limits

Brad King brad.king at kitware.com
Thu Jun 8 12:33:16 EDT 2000


Josh,

I started working at Kitware a few days ago, and have been reading
through the existing ITK source.  I think this will answer your question:

The idea of the itkScalarTraits and itkVectorTraits is to allow special
information not necessarily included in a type to be known.  If you look
at itkPixelTraits.h, you will see the definitions of the scalar and vector
trait sets.  Note that below the main definitions, there are
specializations for many of the basic types.  You need to add such
specializations for any type you wish to use in a class that needs the
trait information.

You probably want to add something like:

template <class FloatType>
class itkScalarTraits< complex<FloatType> > {
public:
  typedef complex<FloatType> ValueType;
  typedef complex<FloatType> ScalarType;
  static ScalarType& GetScalar(complex<FloatType>& v) {return v;}
  static void SetScalar(complex<FloatType>& data, ScalarType const& v)
    {data = v;}
};

A similar specialization will be needed for itkVectorTraits as well.
Modify this for however you wish to treat the complex numbers
(adjust the Get/Set Scalar and the Get/Set Vector methods).  The same
type of thing would be put in with the "myClass" definition as well.  If
myClass is not a template class, then just leave the
"template" declaration above the specialization empty:

template <>
class itkScalarTraits< myClass > {
/*......*/
};

-Brad

On Thu, 8 Jun 2000, Josh Cates wrote:

> Hello Will,
> 
> With the addition of the numeric traits code, I cannot compile such things
> as:
> 
>  itkImage< complex<float> >::Pointer = itkImage< complex<float> >
>  
> or in general: 
> 
>  itkImage< myClass >::Pointer = itkImage< myClass >
> 
> because itkScalarTraits<myClass> and itkVectorTraits<myClass> expect a
> type named "ValueType" in class myClass.
> 
> How do I get around the requirement for defining a ValueType for
> complex<> and myClass?
> 
> Thanks,
> 
> Josh.
> +--+--+--+--+--+--+--+--+--+--+--+--
>  Josh Cates			
>  Dept. of Electrical Engineering	
>  University of Tennessee, Knoxville
>  Email: jecates at utk.edu
>  Phone: (865) 974-0694
>  URL:   www.cs.utk.edu/~cates
> --+--+--+--+--+--+--+--+--+--+--+---
> 
> On Mon, 22 May 2000, Will Schroeder wrote:
> 
> > Hi Luis, Jim -
> > 
> > I modified itkNumericTraits.h to include <limits> on the PC, and
> > ../Insight3DParty/vxl/vnl/vnl_numeric_limits.h on everything else,
> > plus created a #define ITK_NUMERIC_LIMITS. Could you (and anyone with
> > a Unix system) please check this out...the #ifdef is probably not
> > right for Unix systems because some do have a <limits> file.
> > 
> > Will
> > 
> 
> 
> _______________________________________________
> Insight-developers mailing list
> Insight-developers at public.kitware.com
> http://public.kitware.com/mailman/listinfo/insight-developers
> 





More information about the Insight-developers mailing list