00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef CVD_PIXEL_TRAITS_H_
00022 #define CVD_PIXEL_TRAITS_H_
00023
00024 #include <limits>
00025
00026 #if defined (CVD_HAVE_TOON)
00027 #include <TooN/TooN.h>
00028 #endif
00029
00030 namespace CVD {
00031 namespace Pixel {
00032
00033
00034
00035 template<class T> struct traits_error
00036 {
00037 };
00038
00039
00040
00041
00042 template<class T, int LIFT=0> struct traits: public traits_error<T>
00043 {
00044 static const bool integral=traits_error<T>::Error_trait_not_defined_for_this_class;
00045 };
00046
00047 template<int LIFT> struct traits<unsigned char, LIFT>
00048 {
00049 typedef int wider_type;
00050 typedef float float_type;
00051 static const bool integral = true;
00052 static const bool is_signed = false;
00053 static const int bits_used = 8;
00054 static const unsigned char max_intensity=(1 << bits_used) - 1;
00055 };
00056
00057 template<int LIFT> struct traits<char, LIFT>
00058 {
00059 typedef int wider_type;
00060 typedef float float_type;
00061 static const bool integral = true;
00062 static const bool is_signed = std::numeric_limits<char>::is_signed;
00063 static const int bits_used = std::numeric_limits<char>::digits;
00064 static const char max_intensity=(1 << bits_used) - 1;
00065 };
00066
00067 template<int LIFT> struct traits<signed char, LIFT>
00068 {
00069 typedef int wider_type;
00070 typedef float float_type;
00071 static const bool integral = true;
00072 static const bool is_signed = false;
00073 static const int bits_used = 7;
00074 static const signed char max_intensity=(1 << bits_used) - 1;
00075 };
00076
00077 template<int LIFT> struct traits<short, LIFT>
00078 {
00079 typedef int wider_type;
00080 typedef float float_type;
00081 static const bool integral = true;
00082 static const bool is_signed = true;
00083 static const int bits_used = 15;
00084 static const short max_intensity=(1 << bits_used) - 1;
00085 };
00086
00087 template<int LIFT> struct traits<unsigned short, LIFT>
00088 {
00089 typedef int wider_type;
00090 typedef float float_type;
00091 static const bool integral = true;
00092 static const bool is_signed = false;
00093 static const int bits_used = 16;
00094 static const unsigned short max_intensity=(1 << bits_used) - 1;
00095 };
00096
00097 template<int LIFT> struct traits<int, LIFT>
00098 {
00099 typedef int wider_type;
00100 typedef float float_type;
00101 static const bool integral = true;
00102 static const bool is_signed = true;
00103 static const int bits_used = 16;
00104 static const int max_intensity=(1 << bits_used) - 1;
00105 };
00106
00107 template<int LIFT> struct traits<unsigned int, LIFT>
00108 {
00109 typedef unsigned int wider_type;
00110 typedef float float_type;
00111 static const bool integral = true;
00112 static const bool is_signed = false;
00113 static const int bits_used = 16;
00114 static const unsigned int max_intensity=(1 << bits_used) - 1;
00115 };
00116
00117 template<int LIFT> struct traits<long, LIFT>
00118 {
00119 typedef int wider_type;
00120 typedef float float_type;
00121 static const bool integral = true;
00122 static const bool is_signed = true;
00123 static const int bits_used = 16;
00124 static const long max_intensity=(1 << bits_used) - 1;
00125 };
00126
00127 template<int LIFT> struct traits<long long, LIFT>
00128 {
00129 typedef long long wider_type;
00130 typedef double float_type;
00131 static const bool integral = true;
00132 static const bool is_signed = true;
00133 static const int bits_used = 31;
00134 static const long long max_intensity=(1ll << bits_used) - 1ll;
00135 };
00136
00137 template<int LIFT> struct traits<unsigned long long, LIFT>
00138 {
00139 typedef unsigned long long wider_type;
00140 typedef double float_type;
00141 static const bool integral = true;
00142 static const bool is_signed = false;
00143 static const int bits_used = 31;
00144 static const unsigned long long max_intensity=(1ull << bits_used) - 1ull;
00145 };
00146
00147 template<int LIFT> struct traits<unsigned long, LIFT>
00148 {
00149 typedef unsigned int wider_type;
00150 typedef float float_type;
00151 static const bool integral = true;
00152 static const bool is_signed = false;
00153 static const int bits_used = 16;
00154 static const long max_intensity=(1 << bits_used) - 1;
00155 };
00156
00157 template<int LIFT> struct traits<float, LIFT>
00158 {
00159 typedef float wider_type;
00160 typedef float float_type;
00161 static const bool integral = false;
00162 static const bool is_signed = true;
00163 static const float max_intensity;
00164 };
00165
00166 template<int LIFT> const float traits<float, LIFT>::max_intensity = 1.0f;
00167
00168 template<int LIFT> struct traits<double, LIFT>
00169 {
00170 typedef double wider_type;
00171 typedef double float_type;
00172 static const bool integral = false;
00173 static const bool is_signed = true;
00174 static const double max_intensity;
00175 };
00176
00177 template<int LIFT> const double traits<double, LIFT>::max_intensity = 1.0;
00178
00179 template<int LIFT> struct traits<long double, LIFT>
00180 {
00181 typedef long double wider_type;
00182 typedef long double float_type;
00183 static const bool integral = false;
00184 static const bool is_signed = true;
00185 static const long double max_intensity;
00186 };
00187
00188 template<int LIFT> struct traits<bool, LIFT>
00189 {
00190 typedef int wider_type;
00191 typedef float float_type;
00192 static const bool integral = true;
00193 static const bool is_signed = false;
00194 static const int bits_used = 1;
00195 static const bool max_intensity= true;
00196 };
00197
00198
00199 #if defined (CVD_HAVE_TOON)
00200 template<int N> struct traits<TooN::Vector<N> >
00201 {
00202 typedef TooN::Vector<N> wider_type;
00203 typedef TooN::Vector<N> float_type;
00204 static const bool integral = false;
00205 static const bool is_signed = true;
00206 static const TooN::Vector<N> max_intensity;
00207 };
00208 template <int N> const TooN::Vector<N> traits<TooN::Vector<N> >::max_intensity = TooN::Vector<N>(1.0);
00209
00210 template<int N, int M> struct traits<TooN::Matrix<N,M> >
00211 {
00212 typedef TooN::Matrix<N,M> wider_type;
00213 typedef TooN::Matrix<N,M> float_type;
00214 static const bool integral = false;
00215 static const bool is_signed = true;
00216 };
00217
00218 #endif
00219
00220
00221 template<int LIFT> const long double traits<long double, LIFT>::max_intensity = 1.0;
00222
00223 template<class C> struct indirect_type
00224 {
00225 typedef C type;
00226 };
00227
00228 template<class C, int N, int LIFT> struct traits<C[N], LIFT>
00229 {
00230 typedef typename indirect_type<typename traits<C>::wider_type[N]>::type wider_type;
00231 typedef typename indirect_type<typename traits<C>::float_type[N]>::type float_type;
00232 };
00233 }
00234 }
00235
00236 #endif