NPL
Neurological Programs and Libraries
npltypes.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2014 Micah C Chambers (micahc.vt@gmail.com)
3  *
4  * NPL is free software: you can redistribute it and/or modify it under the
5  * terms of the BSD 2-Clause License available in LICENSE or at
6  * http://opensource.org/licenses/BSD-2-Clause
7  *
8  * @file npltypes.h
9  *
10  *****************************************************************************/
11 
12 #ifndef NPLTYPES_H
13 #define NPLTYPES_H
14 
15 #include <string>
16 #include <Eigen/Dense>
17 #include <complex>
18 #include <memory>
19 
20 namespace npl {
21 
22 using Eigen::Ref;
23 using Eigen::MatrixXd;
24 using Eigen::VectorXd;
25 using Eigen::VectorXi;
26 using Eigen::Matrix3d;
27 using Eigen::Vector3d;
28 using Eigen::Matrix;
29 
35 
41 template <typename T>
42 using ptr = std::shared_ptr<T>;
43 
53 template <typename T, typename F>
55 {
56  return std::dynamic_pointer_cast<T>(in);
57 }
58 
59 struct rgba_t;
60 struct rgb_t;
61 
62 struct cdouble_t;
63 struct cfloat_t ;
64 struct cquad_t ;
65 
66 struct cdouble_t: public std::complex<double>
67 {
68  explicit operator float() const;
69  explicit operator double() const;
70  explicit operator long double() const;
71  explicit operator int64_t() const;
72  explicit operator uint64_t() const;
73  explicit operator int32_t() const;
74  explicit operator uint32_t() const;
75  explicit operator int16_t() const;
76  explicit operator uint16_t() const;
77  explicit operator int8_t() const;
78  explicit operator uint8_t() const;
79 // explicit operator cfloat_t() const;
80 // explicit operator cquad_t() const;
81 // explicit operator std::complex<float>();
82 // explicit operator std::complex<long double>();
83 //
84  cdouble_t(double re = 0, double im = 0) : std::complex<double>(re, im) {} ;
85  explicit cdouble_t(const cfloat_t&);
86  explicit cdouble_t(const cquad_t&);
87  explicit cdouble_t(const std::complex<float>& );
88  explicit cdouble_t(const std::complex<long double>&);
89  cdouble_t(const std::complex<double>&);
90 // explicit cdouble_t(rgba_t);
91 // explicit cdouble_t(rgb_t);
92 // explicit cdouble_t(const unsigned char& c) : std::complex<double>((double)c) {};
93 // explicit cdouble_t(const char& c) : std::complex<double>((double)c) {};
94 
95  cdouble_t& operator=(const std::complex<double>& v);
96  cdouble_t& operator=(const std::complex<float>& v);
97  cdouble_t& operator=(const std::complex<long double>& v);
98  cdouble_t& operator=(const cfloat_t& v);
99  cdouble_t& operator=(const cquad_t& v);
100 };
101 
102 
103 struct cfloat_t : public std::complex<float>
104 {
105  explicit operator float() const;
106  explicit operator double() const;
107  explicit operator long double() const;
108  explicit operator int64_t() const;
109  explicit operator uint64_t() const;
110  explicit operator int32_t() const;
111  explicit operator uint32_t() const;
112  explicit operator int16_t() const;
113  explicit operator uint16_t() const;
114  explicit operator int8_t() const;
115  explicit operator uint8_t() const;
116 // explicit operator std::complex<double>();
117 // explicit operator std::complex<long double>();
118 //
119  cfloat_t(double re = 0, double im = 0) : std::complex<float>(re, im) {} ;
120  explicit cfloat_t(const cdouble_t&);
121  explicit cfloat_t(const cquad_t&);
122  explicit cfloat_t(const std::complex<double>&);
123  explicit cfloat_t(const std::complex<long double>&);
124  cfloat_t(const std::complex<float>&);
125 // explicit cfloat_t(rgba_t);
126 // explicit cfloat_t(rgb_t);
127 // explicit cfloat_t(const unsigned char& c) : std::complex<float>((float)c) {};
128 // explicit cfloat_t(const char& c) : std::complex<float>((float)c) {};
129 
130  cfloat_t& operator=(const std::complex<double>& v);
131  cfloat_t& operator=(const std::complex<float>& v);
132  cfloat_t& operator=(const std::complex<long double>& v);
133  cfloat_t& operator=(const cdouble_t& v);
134  cfloat_t& operator=(const cquad_t& v);
135 
136 };
137 
138 struct cquad_t : public std::complex<long double>
139 {
140  explicit operator float() const;
141  explicit operator double() const;
142  explicit operator long double() const;
143  explicit operator int64_t() const;
144  explicit operator uint64_t() const;
145  explicit operator int32_t() const;
146  explicit operator uint32_t() const;
147  explicit operator int16_t() const;
148  explicit operator uint16_t() const;
149  explicit operator int8_t() const;
150  explicit operator uint8_t() const;
151 // explicit operator std::complex<float>();
152 // explicit operator std::complex<double>();
153 //
154  cquad_t(double re = 0, double im = 0) : std::complex<long double>(re, im) {} ;
155  explicit cquad_t(const cdouble_t&);
156  explicit cquad_t(const cfloat_t&);
157  explicit cquad_t(const std::complex<float>&);
158  explicit cquad_t(const std::complex<double>&);
159  cquad_t(const std::complex<long double>&);
160 // explicit cquad_t(rgba_t);
161 // explicit cquad_t(rgb_t);
162 //
163 // explicit cquad_t(const unsigned char& c) : std::complex<long double>((long double)c) {};
164 // explicit cquad_t(const char& c) : std::complex<long double>((long double)c) {};
165 
166  cquad_t& operator=(const std::complex<double>& v);
167  cquad_t& operator=(const std::complex<float>& v);
168  cquad_t& operator=(const std::complex<long double>& v);
169  cquad_t& operator=(const cdouble_t& v);
170  cquad_t& operator=(const cfloat_t& v);
171 };
172 
173 struct rgb_t
174 {
175  char red;
176  char green;
177  char blue;
178 
179  explicit operator float() const;
180  explicit operator double() const;
181  explicit operator long double() const;
182  explicit operator int64_t() const;
183  explicit operator uint64_t() const;
184  explicit operator int32_t() const;
185  explicit operator uint32_t() const;
186  explicit operator int16_t() const;
187  explicit operator uint16_t() const;
188  explicit operator int8_t() const;
189  explicit operator uint8_t() const;
190  explicit operator cquad_t() const;
191  explicit operator cdouble_t() const;
192  explicit operator cfloat_t() const;
193 
194  // math operators
195  rgb_t& operator=(float v);
196  rgb_t& operator=(double v);
197  rgb_t& operator=(long double v);
198  rgb_t& operator=(int64_t v);
199  rgb_t& operator=(uint64_t v);
200  rgb_t& operator=(int32_t v);
201  rgb_t& operator=(uint32_t v);
202  rgb_t& operator=(int16_t v);
203  rgb_t& operator=(uint16_t v);
204  rgb_t& operator=(int8_t v);
205  rgb_t& operator=(uint8_t v);
206 
207  rgb_t() : red(0), green(0), blue(0) {} ;
208  rgb_t(char r, char g, char b) :
209  red(r), green(g), blue(b) {} ;
210  explicit rgb_t(float);
211  explicit rgb_t(double);
212  explicit rgb_t(long double);
213  explicit rgb_t(int64_t);
214  explicit rgb_t(uint64_t);
215  explicit rgb_t(int32_t);
216  explicit rgb_t(uint32_t);
217  explicit rgb_t(int16_t);
218  explicit rgb_t(uint16_t);
219  explicit rgb_t(int8_t);
220  explicit rgb_t(uint8_t);
221  explicit rgb_t(cquad_t);
222  explicit rgb_t(cdouble_t);
223  explicit rgb_t(cfloat_t);
224  explicit rgb_t(rgba_t);
225 };
226 
227 struct rgba_t
228 {
229  char red;
230  char green;
231  char blue;
232  char alpha;
233 
234  explicit operator float() const;
235  explicit operator double() const;
236  explicit operator long double() const;
237  explicit operator int64_t() const;
238  explicit operator uint64_t() const;
239  explicit operator int32_t() const;
240  explicit operator uint32_t() const;
241  explicit operator int16_t() const;
242  explicit operator uint16_t() const;
243  explicit operator int8_t() const;
244  explicit operator uint8_t() const;
245  explicit operator cquad_t() const;
246  explicit operator cdouble_t() const;
247  explicit operator cfloat_t() const;
248 
249  rgba_t& operator=(float v);
250  rgba_t& operator=(double v);
251  rgba_t& operator=(long double v);
252  rgba_t& operator=(int64_t v);
253  rgba_t& operator=(uint64_t v);
254  rgba_t& operator=(int32_t v);
255  rgba_t& operator=(uint32_t v);
256  rgba_t& operator=(int16_t v);
257  rgba_t& operator=(uint16_t v);
258  rgba_t& operator=(int8_t v);
259  rgba_t& operator=(uint8_t v);
260 
261  rgba_t() : red(0), green(0), blue(0), alpha(0) {} ;
262  rgba_t(char r, char g, char b, char a = 0) :
263  red(r), green(g), blue(b), alpha(a) {} ;
264  explicit rgba_t(float);
265  explicit rgba_t(double);
266  explicit rgba_t(long double);
267  explicit rgba_t(int64_t);
268  explicit rgba_t(uint64_t);
269  explicit rgba_t(int32_t);
270  explicit rgba_t(uint32_t);
271  explicit rgba_t(int16_t);
272  explicit rgba_t(uint16_t);
273  explicit rgba_t(int8_t);
274  explicit rgba_t(uint8_t);
275  explicit rgba_t(cquad_t);
276  explicit rgba_t(cdouble_t);
277  explicit rgba_t(cfloat_t);
278  explicit rgba_t(rgb_t);
279 };
280 
281 
282 std::ostream& operator<< (std::ostream& stream, const rgb_t& v);
283 std::ostream& operator<< (std::ostream& stream, const rgba_t& v);
284 
285 // math
286 
288 //cdouble_t operator+(const cdouble_t& lhs, const double& rhs);
289 //cdouble_t operator+(const double& lhs, const cdouble_t& rhs);
290 //cdouble_t operator-(const cdouble_t& lhs, const double& rhs);
291 //cdouble_t operator-(const double& lhs, const cdouble_t& rhs);
292 //cdouble_t operator*(const cdouble_t& lhs, const double& rhs);
293 //cdouble_t operator*(const double& lhs, const cdouble_t& rhs);
294 //cdouble_t operator/(const cdouble_t& lhs, const double& rhs);
295 //cdouble_t operator/(const double& lhs, const cdouble_t& rhs);
296 //
298 //cfloat_t operator+(const cfloat_t& lhs, const double& rhs);
299 //cfloat_t operator+(const double& lhs, const cfloat_t& rhs);
300 //cfloat_t operator-(const cfloat_t& lhs, const double& rhs);
301 //cfloat_t operator-(const double& lhs, const cfloat_t& rhs);
302 //cfloat_t operator*(const cfloat_t& lhs, const double& rhs);
303 //cfloat_t operator*(const double& lhs, const cfloat_t& rhs);
304 //cfloat_t operator/(const cfloat_t& lhs, const double& rhs);
305 //cfloat_t operator/(const double& lhs, const cfloat_t& rhs);
306 
307 // rgb - double
308 rgb_t operator+(const rgb_t& lhs, const double& rhs);
309 rgb_t operator+(const double& lhs, const rgb_t& rhs);
310 rgb_t operator-(const rgb_t& lhs, const double& rhs);
311 rgb_t operator-(const double& lhs, const rgb_t& rhs);
312 rgb_t operator*(const rgb_t& lhs, const double& rhs);
313 rgb_t operator*(const double& lhs, const rgb_t& rhs);
314 rgb_t operator/(const rgb_t& lhs, const double& rhs);
315 rgb_t operator/(const double& lhs, const rgb_t& rhs);
316 
317 // rgba - double
318 rgba_t operator+(const rgba_t& lhs, const double& rhs);
319 rgba_t operator+(const double& lhs, const rgba_t& rhs);
320 rgba_t operator-(const rgba_t& lhs, const double& rhs);
321 rgba_t operator-(const double& lhs, const rgba_t& rhs);
322 rgba_t operator*(const rgba_t& lhs, const double& rhs);
323 rgba_t operator*(const double& lhs, const rgba_t& rhs);
324 rgba_t operator/(const rgba_t& lhs, const double& rhs);
325 rgba_t operator/(const double& lhs, const rgba_t& rhs);
326 
327 //cdouble_t operator*(const cfloat_t& lhs, const double& rhs)
328 //{
329 // return cdouble_t(lhs.real()*rhs, lhs.imag()*rhs);
330 //}
331 //
332 //cdouble_t operator*(const cdouble_t& lhs, const double& rhs)
333 //{
334 // return cdouble_t(lhs.real()*rhs, lhs.imag()*rhs);
335 //}
336 //
337 //cdouble_t operator*(const cdouble_t& lhs, const rgba_t& rhs)
338 //{
339 // double v = (double)rhs;
340 // return cdouble_t(lhs.real()*v, lhs.imag()*v);
341 //}
342 
343 } //npl
344 
345 #endif //NPLTYPES_H
ptr< T > dPtrCast(const ptr< F > &in)
Shorter name for dynamic_pointer_cast.
Definition: npltypes.h:54
char green
Definition: npltypes.h:176
Definition: accessors.h:29
cdouble_t(double re=0, double im=0)
Definition: npltypes.h:84
char green
Definition: npltypes.h:230
rgb_t(char r, char g, char b)
Definition: npltypes.h:208
Matrix< D1, D2 > operator+(const Matrix< D1, D2 > &lhs, const Matrix< D1, D2 > &rhs)
STL namespace.
cfloat_t(double re=0, double im=0)
Definition: npltypes.h:119
char blue
Definition: npltypes.h:177
char blue
Definition: npltypes.h:231
std::ostream & operator<<(std::ostream &os, const Matrix< D1, D2 > &b)
rgba_t & operator=(float v)
rgba_t(char r, char g, char b, char a=0)
Definition: npltypes.h:262
Matrix< D1, D3 > operator*(const Matrix< D1, D2 > &lhs, const Matrix< D2, D3 > &rhs)
cfloat_t & operator=(const std::complex< double > &v)
char alpha
Definition: npltypes.h:232
cquad_t & operator=(const std::complex< double > &v)
std::shared_ptr< T > ptr
Make the shared_ptr name shorter...
Definition: npltypes.h:42
cdouble_t & operator=(const std::complex< double > &v)
cquad_t(double re=0, double im=0)
Definition: npltypes.h:154
char red
Definition: npltypes.h:175
char red
Definition: npltypes.h:229
rgb_t operator/(const rgb_t &lhs, const double &rhs)
rgb_t & operator=(float v)
Matrix< D1, D2 > operator-(const Matrix< D1, D2 > &lhs, const Matrix< D1, D2 > &rhs)
Metric
Information-based Metric to use.
Definition: npltypes.h:33