Image Utilities (IU)
 All Data Structures Namespaces Functions Variables Typedefs Enumerations Friends Groups Pages
typetraits.h
1 #pragma once
2 
3 #include "../iuhelpermath.h"
4 #include "iumathapi.h"
5 
6 namespace iu {
10 template<typename PixelType>
11 struct IUMATH_DLLAPI type_trait {};
12 
14 template<> struct IUMATH_DLLAPI type_trait<float2>
15 {
17  static inline __host__ __device__ float2 make_complex(float x)
18  {
19  return make_float2(x, x);
20  }
22  static inline __host__ __device__ float2 make_complex(float x, float y)
23  {
24  return make_float2(x, y);
25  }
26 
28  static inline __host__ __device__ float2 make(float x)
29  {
30  return make_float2(x, x);
31  }
32 
34  static inline __host__ __device__ float abs(float2 x)
35  {
36  return length(x);
37  }
38 
40  typedef float real_type;
41 
43  typedef float2 complex_type;
44 
46  struct is_complex { static const bool value = true; };
47 
49  static const char* name()
50  {
51  return "float2";
52  }
53 };
54 
56 template<> struct IUMATH_DLLAPI type_trait<double2>
57 {
59  static inline __host__ __device__ double2 make_complex(double x)
60  {
61  return make_double2(x, x);
62  }
64  static inline __host__ __device__ double2 make_complex(double x, double y)
65  {
66  return make_double2(x, y);
67  }
68 
70  static inline __host__ __device__ double2 make(double x)
71  {
72  return make_double2(x, x);
73  }
74 
76  static inline __host__ __device__ double abs(double2 x)
77  {
78  return length(x);
79  }
80 
82  typedef double real_type;
83 
85  typedef double2 complex_type;
86 
88  struct is_complex { static const bool value = true; };
89 
91  static inline const char* name()
92  {
93  return "double2";
94  }
95 };
96 
98 template<> struct IUMATH_DLLAPI type_trait<float>
99 {
101  static inline __host__ __device__ float2 make_complex(float x)
102  {
103  return make_float2(x, x);
104  }
106  static inline __host__ __device__ float2 make_complex(float x, float y)
107  {
108  return make_float2(x, y);
109  }
110 
112  static inline __host__ __device__ float make(float x)
113  {
114  return x;
115  }
116 
118  static inline __host__ __device__ float abs(float x)
119  {
120  return fabs(x);
121  }
122 
124  static inline __host__ __device__ float max(float x, float y)
125  {
126  return fmaxf(x, y);
127  }
128 
130  typedef float real_type;
131 
133  typedef float2 complex_type;
134 
136  struct is_complex { static const bool value = false; };
137 
139  static const char* name()
140  {
141  return "float";
142  }
143 };
144 
146 template<> struct IUMATH_DLLAPI type_trait<double>
147 {
149  static inline __host__ __device__ double2 make_complex(double x)
150  {
151  return make_double2(x, x);
152  }
153 
155  static inline __host__ __device__ double2 make_complex(double x, double y)
156  {
157  return make_double2(x, y);
158  }
159 
161  static inline __host__ __device__ double make(double x)
162  {
163  return x;
164  }
165 
167  static inline __host__ __device__ double abs(double x)
168  {
169  return fabs(x);
170  }
171 
173  static inline __host__ __device__ double max(double x, double y)
174  {
175  return fmax(x, y);
176  }
177 
179  typedef double real_type;
180 
182  typedef double2 complex_type;
183 
185  struct is_complex { static const bool value = true; };
186 
188  static const char* name()
189  {
190  return "double";
191  }
192 };
193 
194 }
195 
197 template<typename PixelType>
198 IUMATH_DLLAPI inline __host__ __device__ typename iu::type_trait<PixelType>::complex_type complex_multiply(
199  const typename iu::type_trait<PixelType>::complex_type& src1,
200  const typename iu::type_trait<PixelType>::complex_type& src2)
201 {
203  dst.x = src1.x * src2.x - src1.y * src2.y;
204  dst.y = src1.x * src2.y + src1.y * src2.x;
205  return dst;
206 }
207 
209 template<typename PixelType>
210 IUMATH_DLLAPI inline __host__ __device__ typename iu::type_trait<PixelType>::complex_type complex_multiply_conjugate(
211  const typename iu::type_trait<PixelType>::complex_type& src1,
212  const typename iu::type_trait<PixelType>::complex_type& src2)
213 {
215  dst.x = src1.x * src2.x + src1.y * src2.y;
216  dst.y = -src1.x * src2.y + src1.y * src2.x;
217  return dst;
218 }
219 
221 template<typename PixelType>
222 IUMATH_DLLAPI inline __host__ __device__ typename iu::type_trait<PixelType>::complex_type complex_conjugate(
223  const typename iu::type_trait<PixelType>::complex_type& src)
224 {
226  dst.x = src.x;
227  dst.y = -src.y;
228  return dst;
229 }
static __host__ __device__ float abs(float x)
Definition: typetraits.h:118
static __host__ __device__ double abs(double2 x)
Definition: typetraits.h:76
static const char * name()
Definition: typetraits.h:49
static __host__ __device__ float2 make_complex(float x, float y)
Definition: typetraits.h:106
float real_type
Definition: typetraits.h:40
static __host__ __device__ float2 make_complex(float x)
Definition: typetraits.h:101
static const char * name()
Definition: typetraits.h:139
static __host__ __device__ double make(double x)
Definition: typetraits.h:161
static const char * name()
Definition: typetraits.h:91
static __host__ __device__ float abs(float2 x)
Definition: typetraits.h:34
float real_type
Definition: typetraits.h:130
static __host__ __device__ double2 make_complex(double x)
Definition: typetraits.h:59
static __host__ __device__ float2 make_complex(float x)
Definition: typetraits.h:17
float2 complex_type
Definition: typetraits.h:43
static __host__ __device__ double2 make_complex(double x)
Definition: typetraits.h:149
double real_type
Definition: typetraits.h:179
static const char * name()
Definition: typetraits.h:188
static __host__ __device__ float2 make_complex(float x, float y)
Definition: typetraits.h:22
static __host__ __device__ double abs(double x)
Definition: typetraits.h:167
double real_type
Definition: typetraits.h:82
static __host__ __device__ double max(double x, double y)
Definition: typetraits.h:173
static __host__ __device__ float max(float x, float y)
Definition: typetraits.h:124
static __host__ __device__ double2 make(double x)
Definition: typetraits.h:70
double2 complex_type
Definition: typetraits.h:182
Definition: typetraits.h:11
double2 complex_type
Definition: typetraits.h:85
static __host__ __device__ float make(float x)
Definition: typetraits.h:112
static __host__ __device__ float2 make(float x)
Definition: typetraits.h:28
static __host__ __device__ double2 make_complex(double x, double y)
Definition: typetraits.h:155
static __host__ __device__ double2 make_complex(double x, double y)
Definition: typetraits.h:64
float2 complex_type
Definition: typetraits.h:133