OpenPose 1.0.0rc2 OpenPose: A Real-Time Multi-Person Key-Point Detection And Multi-Threading C++ Library

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
fastMath.hpp
Go to the documentation of this file.
1 #ifndef OPENPOSE_UTILITIES_MATH_HPP
2 #define OPENPOSE_UTILITIES_MATH_HPP
3
4 namespace op
5 {
6 // Use op::round/max/min for basic types (int, char, long, float, double, etc). Never with classes!
7 // `std::` alternatives uses 'const T&' instead of 'const T' as argument.
8 // E.g., std::round is really slow (~300 ms vs ~10 ms when I individually apply it to each element of a whole
9 // image array
10
11 // Round functions
12 // Signed
13 template<typename T>
14 inline char charRound(const T a)
15 {
16 return char(a+0.5f);
17 }
18
19 template<typename T>
20 inline signed char sCharRound(const T a)
21 {
22 return (signed char)(a+0.5f);
23 }
24
25 template<typename T>
26 inline int intRound(const T a)
27 {
28 return int(a+0.5f);
29 }
30
31 template<typename T>
32 inline long longRound(const T a)
33 {
34 return long(a+0.5f);
35 }
36
37 template<typename T>
38 inline long long longLongRound(const T a)
39 {
40 return (long long)(a+0.5f);
41 }
42
43 // Unsigned
44 template<typename T>
45 inline unsigned char uCharRound(const T a)
46 {
47 return (unsigned char)(a+0.5f);
48 }
49
50 template<typename T>
51 inline unsigned int uIntRound(const T a)
52 {
53 return (unsigned int)(a+0.5f);
54 }
55
56 template<typename T>
57 inline unsigned long ulongRound(const T a)
58 {
59 return (unsigned long)(a+0.5f);
60 }
61
62 template<typename T>
63 inline unsigned long long uLongLongRound(const T a)
64 {
65 return (unsigned long long)(a+0.5f);
66 }
67
68 // Max/min functions
69 template<typename T>
70 inline T fastMax(const T a, const T b)
71 {
72 return (a > b ? a : b);
73 }
74
75 template<typename T>
76 inline T fastMin(const T a, const T b)
77 {
78 return (a < b ? a : b);
79 }
80
81 template<class T>
82 inline T fastTruncate(T value, T min = 0, T max = 1)
83 {
84 return fastMin(max, fastMax(min, value));
85 }
86 }
87
88 #endif // OPENPOSE_UTILITIES_MATH_HPP
op::uIntRound
unsigned int uIntRound(const T a)
Definition: fastMath.hpp:51
op::fastMax
T fastMax(const T a, const T b)
Definition: fastMath.hpp:70
op::fastTruncate
T fastTruncate(T value, T min=0, T max=1)
Definition: fastMath.hpp:82
op::charRound
char charRound(const T a)
Definition: fastMath.hpp:14
op::longRound
long longRound(const T a)
Definition: fastMath.hpp:32
op::ulongRound
unsigned long ulongRound(const T a)
Definition: fastMath.hpp:57
op::sCharRound
signed char sCharRound(const T a)
Definition: fastMath.hpp:20
op::uCharRound
unsigned char uCharRound(const T a)
Definition: fastMath.hpp:45
op::fastMin
T fastMin(const T a, const T b)
Definition: fastMath.hpp:76
op::intRound
int intRound(const T a)
Definition: fastMath.hpp:26
op::uLongLongRound
unsigned long long uLongLongRound(const T a)
Definition: fastMath.hpp:63
op::longLongRound
long long longLongRound(const T a)
Definition: fastMath.hpp:38