core/vnl/vnl_complex_traits.h

Go to the documentation of this file.
00001 // This is core/vnl/vnl_complex_traits.h
00002 #ifndef vnl_complex_traits_h_
00003 #define vnl_complex_traits_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 //:
00008 // \file
00009 // \brief To allow templated algorithms to determine appropriate actions of conjugation, complexification etc.
00010 // \author fsm, Oxford RRG, 26 Mar 1999
00011 //
00012 // \verbatim
00013 //  Modifications
00014 //   LSB (Manchester) 26/3/01 Documentation tidied
00015 // \endverbatim
00016 //-----------------------------------------------------------------------------
00017 
00018 #include <vcl_complex.h>
00019 
00020 #if 0 // The old implementation
00021   //: Whether complex or not
00022   enum { isreal = true };
00023 
00024   //: Complex conjugation.
00025   static T conjugate(T x);
00026 
00027   //: Complexification.
00028   static vcl_complex<T> complexify(T x);
00029 #endif
00030 
00031 template <class T> // the primary template is empty, by design.
00032 struct vnl_complex_traits;
00033 
00034 #define macro(T) \
00035 VCL_DEFINE_SPECIALIZATION struct vnl_complex_traits<T > \
00036 { \
00037   enum { isreal = true }; \
00038   static T conjugate(T x) { return x; } \
00039   static vcl_complex<T> complexify(T x) { return vcl_complex<T >(x, (T)0); } \
00040 }
00041 #define makro(T) \
00042 macro(signed T); \
00043 macro(unsigned T)
00044 makro(char);
00045 makro(short);
00046 makro(int);
00047 makro(long);
00048 #undef makro
00049 #undef macro
00050 
00051 
00052 VCL_DEFINE_SPECIALIZATION struct vnl_complex_traits<float>
00053 {
00054   enum { isreal = true };
00055   static float conjugate(float x) { return x; }
00056   static vcl_complex<float> complexify(float x) { return vcl_complex<float>(x, 0.0f); }
00057 };
00058 
00059 VCL_DEFINE_SPECIALIZATION struct vnl_complex_traits<double>
00060 {
00061   enum { isreal = true };
00062   static double conjugate(double x) { return x; }
00063   static vcl_complex<double> complexify(double x) { return vcl_complex<double>(x, 0.0); }
00064 };
00065 
00066 VCL_DEFINE_SPECIALIZATION struct vnl_complex_traits<long double>
00067 {
00068   enum { isreal = true };
00069   static long double conjugate(long double x) { return x; }
00070   static vcl_complex<long double> complexify(long double x) { return vcl_complex<long double>(x, 0.0); }
00071 };
00072 
00073 VCL_DEFINE_SPECIALIZATION struct vnl_complex_traits<vcl_complex<float> >
00074 {
00075   enum { isreal = false };
00076   static vcl_complex<float> conjugate(vcl_complex<float> x) { return vcl_conj(x); }
00077   static vcl_complex<float> complexify(float x) { return x; }
00078 };
00079 
00080 VCL_DEFINE_SPECIALIZATION struct vnl_complex_traits<vcl_complex<double> >
00081 {
00082   enum { isreal = false };
00083   static vcl_complex<double> conjugate(vcl_complex<double> x) { return vcl_conj(x); }
00084   static vcl_complex<double> complexify(double x) { return x; }
00085 };
00086 
00087 VCL_DEFINE_SPECIALIZATION struct vnl_complex_traits<vcl_complex<long double> >
00088 {
00089   enum { isreal = false };
00090   static vcl_complex<long double> conjugate(vcl_complex<long double> x) { return vcl_conj(x); }
00091   static vcl_complex<long double> complexify(long double x) { return x; }
00092 };
00093 
00094 #include <vnl/vnl_bignum.h>
00095 
00096 VCL_DEFINE_SPECIALIZATION struct vnl_complex_traits<vnl_bignum>
00097 {
00098   enum { isreal = true };
00099   static vnl_bignum conjugate(vnl_bignum x) { return x; }
00100   static vcl_complex<vnl_bignum> complexify(vnl_bignum x) { return vcl_complex<vnl_bignum>(x,vnl_bignum(0L)); }
00101 };
00102 
00103 VCL_DEFINE_SPECIALIZATION struct vnl_complex_traits<vcl_complex<vnl_bignum> >
00104 {
00105   enum { isreal = false };
00106   static vcl_complex<vnl_bignum> conjugate(vcl_complex<vnl_bignum> x) { return vcl_complex<vnl_bignum>(x.real(),-x.imag()); }
00107   static vcl_complex<vnl_bignum> complexify(vcl_complex<vnl_bignum> x) { return x; }
00108 };
00109 
00110 #include <vnl/vnl_rational.h>
00111 
00112 VCL_DEFINE_SPECIALIZATION struct vnl_complex_traits<vnl_rational>
00113 {
00114   enum { isreal = true };
00115   static vnl_rational conjugate(vnl_rational x) { return x; }
00116   static vcl_complex<vnl_rational> complexify(vnl_rational x) { return vcl_complex<vnl_rational>(x, vnl_rational(0,1)); }
00117 };
00118 
00119 VCL_DEFINE_SPECIALIZATION struct vnl_complex_traits<vcl_complex<vnl_rational> >
00120 {
00121   enum { isreal = false };
00122   static vcl_complex<vnl_rational> conjugate(vcl_complex<vnl_rational> x) {return vcl_complex<vnl_rational>(x.real(),-x.imag());}
00123   static vcl_complex<vnl_rational> complexify(vcl_complex<vnl_rational> x) { return x; }
00124 };
00125 
00126 #endif // vnl_complex_traits_h_

Generated on Fri Nov 21 05:06:13 2008 for core/vnl by  doxygen 1.5.1