core/vil/vil_pixel_traits.h

Go to the documentation of this file.
00001 // This is core/vil/vil_pixel_traits.h
00002 #ifndef vil_pixel_traits_h_
00003 #define vil_pixel_traits_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 //:
00008 // \file
00009 // \brief Templated component number/type/size
00010 //
00011 // To allow templated image processing algorithms to determine appropriate types, and sizes
00012 // The basic framework was copied from AWF's vnl_numeric_traits class.
00013 //
00014 // In most cases it is probably better to use vil_pixel_format.
00015 // \author Ian Scott
00016 // \date   27 Nov 2002
00017 // \verbatim
00018 //  Modifications
00019 //   J.L. Mundy Dec. 2004, Added traits to support range mapping.
00020 //
00021 //  - is_signed         -  does the type have negative values
00022 //  - num_bits          -  number of bits required to encode the value range
00023 //  - minval            -  the minimum value of the type (possibly negative).
00024 //  - maxval            -  the maximum value of the type
00025 //  - real_number_field - is the type an approximation to the field of reals
00026 //
00027 //  (Note, functions used rather than static constants for minimal linking issues)
00028 // \endverbatim
00029 //-----------------------------------------------------------------------------
00030 #include <vcl_climits.h> // for UCHAR_MAX
00031 #include <vcl_cfloat.h>
00032 
00033 //: Pixel properties for templates.
00034 template <class T>
00035 class vil_pixel_traits;
00036 
00037 
00038 VCL_DEFINE_SPECIALIZATION
00039 class vil_pixel_traits<bool>
00040 {
00041  public:
00042   //: Type of individual components
00043   typedef bool component_type;
00044 
00045   //: Is signed
00046   static bool is_signed() {return false;}
00047 
00048   //: Size in bits
00049   static unsigned num_bits() {return 1;}
00050 
00051   //: Minimum value
00052   static bool minval() {return false;}
00053 
00054   //: Maximum value
00055   static bool maxval() {return true;}
00056 
00057   //: Real number field
00058   static bool real_number_field() {return false;}
00059 };
00060 
00061 #if !VCL_CANNOT_SPECIALIZE_CV
00062 VCL_DEFINE_SPECIALIZATION
00063 class vil_pixel_traits<bool const> : public vil_pixel_traits<bool> {};
00064 #endif
00065 
00066 VCL_DEFINE_SPECIALIZATION
00067 class vil_pixel_traits<char>
00068 {
00069  public:
00070   //: Type of individual components
00071   typedef char component_type;
00072 
00073   //: Is signed (char is not guaranteed to be unsigned)
00074   static bool is_signed() {return (char)255<0;}
00075 
00076   //: Size in bits
00077   static unsigned num_bits() {return 8;}
00078 
00079   //: Minimum value
00080   static char minval() {return char(255)<0?-128:0;}
00081 
00082   //: Maximum value
00083   static char maxval() {return char(255)<0?127:255;}
00084 
00085   //: Real number field
00086   static bool real_number_field() {return false;}
00087 };
00088 
00089 #if !VCL_CANNOT_SPECIALIZE_CV
00090 VCL_DEFINE_SPECIALIZATION
00091 class vil_pixel_traits<char const> : public vil_pixel_traits<char> {};
00092 #endif
00093 
00094 VCL_DEFINE_SPECIALIZATION
00095 class vil_pixel_traits<unsigned char>
00096 {
00097  public:
00098   //: Type of individual components
00099   typedef unsigned char component_type;
00100 
00101   //: Is signed
00102   static bool is_signed() {return false;}
00103 
00104   //: Size in bits
00105   static unsigned num_bits() {return 8;}
00106 
00107   //: Minimum value
00108   static unsigned char minval() {return 0;}
00109 
00110   //: Maximum value
00111   static unsigned char maxval() {return UCHAR_MAX;}
00112 
00113   //: Real number field
00114   static bool real_number_field() {return false;}
00115 };
00116 
00117 #if !VCL_CANNOT_SPECIALIZE_CV
00118 VCL_DEFINE_SPECIALIZATION
00119 class vil_pixel_traits<unsigned char const> : public vil_pixel_traits<unsigned char> {};
00120 #endif
00121 
00122 VCL_DEFINE_SPECIALIZATION
00123 class vil_pixel_traits<signed char>
00124 {
00125  public:
00126   //: Type of individual components
00127   typedef signed char component_type;
00128 
00129   //: Is signed
00130   static bool is_signed() {return true;}
00131 
00132   //: Size in bits
00133   static unsigned num_bits() {return 8;}
00134 
00135   //: Minimum value
00136   static signed char minval() {return SCHAR_MIN;}
00137 
00138   //: Maximum value
00139   static signed char maxval() {return SCHAR_MAX;}
00140 
00141   //: Real number field
00142   static bool real_number_field() {return false;}
00143 };
00144 
00145 #if !VCL_CANNOT_SPECIALIZE_CV
00146 VCL_DEFINE_SPECIALIZATION
00147 class vil_pixel_traits<signed char const> : public vil_pixel_traits<signed char> {};
00148 #endif
00149 
00150 VCL_DEFINE_SPECIALIZATION
00151 class vil_pixel_traits<short>
00152 {
00153  public:
00154   //: Type of individual components
00155   typedef short component_type;
00156 
00157   //: Is signed
00158   static bool is_signed() {return true;}
00159 
00160   //: Size in bits
00161   static unsigned num_bits() {return 8*sizeof(short);}
00162 
00163   //: Minimum value
00164   static short minval() {return SHRT_MIN;}
00165 
00166   //: Maximum value
00167   static short maxval() {return SHRT_MAX;}
00168 
00169   //: Real number field
00170   static bool real_number_field() {return false;}
00171 };
00172 
00173 #if !VCL_CANNOT_SPECIALIZE_CV
00174 VCL_DEFINE_SPECIALIZATION
00175 class vil_pixel_traits<short const> : public vil_pixel_traits<short> {};
00176 #endif
00177 
00178 VCL_DEFINE_SPECIALIZATION
00179 class vil_pixel_traits<unsigned short>
00180 {
00181  public:
00182   //: Type of individual components
00183   typedef unsigned short component_type;
00184 
00185   //: Is signed
00186   static bool is_signed() {return false;}
00187 
00188   //: Size in bits
00189   static unsigned num_bits() {return 16;}
00190 
00191   //: Minimum value
00192   static unsigned short minval() {return 0;}
00193 
00194   //: Maximum value
00195   static unsigned short maxval() {return USHRT_MAX;}
00196 
00197   //: Real number field
00198   static bool real_number_field() {return false;}
00199 };
00200 
00201 #if !VCL_CANNOT_SPECIALIZE_CV
00202 VCL_DEFINE_SPECIALIZATION
00203 class vil_pixel_traits<unsigned short const> : public vil_pixel_traits<unsigned short> {};
00204 #endif
00205 
00206 VCL_DEFINE_SPECIALIZATION
00207 class vil_pixel_traits<int>
00208 {
00209  public:
00210   //: Type of individual components
00211   typedef int component_type;
00212 
00213   //: Is signed
00214   static bool is_signed() {return true;}
00215 
00216   //: Size in bits
00217   static unsigned num_bits() {return 8*sizeof(int);}
00218 
00219   //: Minimum value
00220   static int minval() {return INT_MIN;}
00221 
00222   //: Maximum value
00223   static int maxval() {return INT_MAX;}
00224 
00225   //: Real number field
00226   static bool real_number_field() {return false;}
00227 };
00228 
00229 #if !VCL_CANNOT_SPECIALIZE_CV
00230 VCL_DEFINE_SPECIALIZATION
00231 class vil_pixel_traits<int const> : public vil_pixel_traits<int> {};
00232 #endif
00233 
00234 VCL_DEFINE_SPECIALIZATION
00235 class vil_pixel_traits<unsigned int>
00236 {
00237  public:
00238   //: Type of individual components
00239   typedef unsigned int component_type;
00240 
00241   //: Is signed
00242   static bool is_signed() {return false;}
00243 
00244   //: Size in bits
00245   static unsigned num_bits() {return 8*sizeof(unsigned int);}
00246 
00247   //: Minimum value
00248   static unsigned int minval() {return 0;}
00249 
00250   //: Maximum value
00251   static unsigned int maxval() {return UINT_MAX;}
00252 
00253   //: Real number field
00254   static bool real_number_field() {return false;}
00255 };
00256 
00257 #if !VCL_CANNOT_SPECIALIZE_CV
00258 VCL_DEFINE_SPECIALIZATION
00259 class vil_pixel_traits<unsigned int const> : public vil_pixel_traits<unsigned int> {};
00260 #endif
00261 
00262 VCL_DEFINE_SPECIALIZATION
00263 class vil_pixel_traits<long>
00264 {
00265  public:
00266   //: Type of individual components
00267   typedef long component_type;
00268 
00269   //: Is signed
00270   static bool is_signed() {return true;}
00271 
00272   //: Size in bits
00273   static unsigned num_bits() {return 8*sizeof(long);}
00274 
00275   //: Minimum value
00276   static long minval() {return LONG_MIN;}
00277 
00278   //: Maximum value
00279   static long maxval() {return LONG_MAX;}
00280 
00281   //: Real number field
00282   static bool real_number_field() {return false;}
00283 };
00284 
00285 #if !VCL_CANNOT_SPECIALIZE_CV
00286 VCL_DEFINE_SPECIALIZATION
00287 class vil_pixel_traits<long const> : public vil_pixel_traits<long > {};
00288 #endif
00289 
00290 VCL_DEFINE_SPECIALIZATION
00291 class vil_pixel_traits<unsigned long>
00292 {
00293  public:
00294   //: Type of individual components
00295   typedef unsigned long component_type;
00296 
00297   //: Is signed
00298   static bool is_signed() {return false;}
00299 
00300   //: Size in bits
00301   static unsigned num_bits() {return 8*sizeof(unsigned long);}
00302 
00303   //: Minimum value
00304   static unsigned long minval() {return 0;}
00305 
00306   //: Maximum value
00307   static unsigned long maxval() {return ULONG_MAX;}
00308 
00309   //: Real number field
00310   static bool real_number_field() {return false;}
00311 };
00312 
00313 #if !VCL_CANNOT_SPECIALIZE_CV
00314 VCL_DEFINE_SPECIALIZATION
00315 class vil_pixel_traits<unsigned long const> : public vil_pixel_traits<unsigned long> {};
00316 #endif
00317 
00318 VCL_DEFINE_SPECIALIZATION
00319 class vil_pixel_traits<float>
00320 {
00321  public:
00322   //: Type of individual components
00323   typedef float component_type;
00324 
00325   //: Is signed
00326   static bool is_signed() {return true;}
00327 
00328   //: Size in bits
00329   static unsigned num_bits() {return 8*sizeof(float);}
00330 
00331   //: Minimum value
00332   static float minval() {return -FLT_MAX;}
00333 
00334   //: Maximum value
00335   static float maxval() {return FLT_MAX;}
00336 
00337   //: Real number field
00338   static bool real_number_field() {return true;}
00339 };
00340 
00341 #if !VCL_CANNOT_SPECIALIZE_CV
00342 VCL_DEFINE_SPECIALIZATION
00343 class vil_pixel_traits<float const> : public vil_pixel_traits<float> {};
00344 #endif
00345 
00346 VCL_DEFINE_SPECIALIZATION
00347 class vil_pixel_traits<double>
00348 {
00349  public:
00350   //: Type of individual components
00351   typedef double component_type;
00352 
00353   //: Is signed
00354   static bool is_signed() {return true;}
00355 
00356   //: Size in bits
00357   static unsigned num_bits() {return 8*sizeof(double);}
00358 
00359   //: Minimum value
00360   static double minval() {return -DBL_MAX;}
00361 
00362   //: Maximum value
00363   static double maxval() {return DBL_MAX;}
00364 
00365   //: Real number field
00366   static bool real_number_field() {return true;}
00367 };
00368 
00369 #if !VCL_CANNOT_SPECIALIZE_CV
00370 VCL_DEFINE_SPECIALIZATION
00371 class vil_pixel_traits<double const> : public vil_pixel_traits<double> {};
00372 #endif
00373 
00374 VCL_DEFINE_SPECIALIZATION
00375 class vil_pixel_traits<long double>
00376 {
00377  public:
00378   //: Type of individual components
00379   typedef long double component_type;
00380 
00381   //: Is signed
00382   static bool is_signed() {return true;}
00383 
00384   //: Size in bits
00385   static unsigned num_bits() {return 8*sizeof(long double);}
00386 
00387   //: Minimum value
00388   static long double minval() {return -LDBL_MAX;}
00389 
00390   //: Maximum value
00391   static long double maxval() {return LDBL_MAX;}
00392 
00393   //: Real number field
00394   static bool real_number_field() {return true;}
00395 };
00396 
00397 #if !VCL_CANNOT_SPECIALIZE_CV
00398 VCL_DEFINE_SPECIALIZATION
00399 class vil_pixel_traits<long double const> : public vil_pixel_traits<long double> {};
00400 #endif
00401 
00402 // Define default implementation which assumes that T is compound type which
00403 // declares the STL-like value_type typedef.
00404 template <class T>
00405 class vil_pixel_traits
00406 {
00407  public:
00408   //: Type of individual components
00409   typedef typename vil_pixel_traits<VCL_DISAPPEARING_TYPENAME T::value_type>::
00410     component_type component_type;
00411 };
00412 
00413 #endif // vil_pixel_traits_h_

Generated on Sat Nov 22 05:07:54 2008 for core/vil by  doxygen 1.5.1