comparison Framework/Toolbox/LinearAlgebra.h @ 181:ff8556874557 wasm

speedup
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 14 Mar 2018 17:48:02 +0100
parents 7105e51e4907
children 964118e7e6de
comparison
equal deleted inserted replaced
180:4da803580da9 181:ff8556874557
49 49
50 bool ParseVector(Vector& target, 50 bool ParseVector(Vector& target,
51 const Orthanc::DicomMap& dataset, 51 const Orthanc::DicomMap& dataset,
52 const Orthanc::DicomTag& tag); 52 const Orthanc::DicomTag& tag);
53 53
54 void AssignVector(Vector& v, 54 inline void AssignVector(Vector& v,
55 double v1); 55 double v1,
56 56 double v2)
57 void AssignVector(Vector& v, 57 {
58 double v1, 58 v.resize(2);
59 double v2); 59 v[0] = v1;
60 60 v[1] = v2;
61 void AssignVector(Vector& v, 61 }
62 double v1, 62
63 double v2, 63
64 double v3); 64 inline void AssignVector(Vector& v,
65 65 double v1)
66 void AssignVector(Vector& v, 66 {
67 double v1, 67 v.resize(1);
68 double v2, 68 v[0] = v1;
69 double v3, 69 }
70 double v4); 70
71 71
72 Vector CreateVector(double v1); 72 inline void AssignVector(Vector& v,
73 73 double v1,
74 Vector CreateVector(double v1, 74 double v2,
75 double v2); 75 double v3)
76 76 {
77 Vector CreateVector(double v1, 77 v.resize(3);
78 double v2, 78 v[0] = v1;
79 double v3); 79 v[1] = v2;
80 80 v[2] = v3;
81 Vector CreateVector(double v1, 81 }
82 double v2, 82
83 double v3, 83
84 double v4); 84 inline void AssignVector(Vector& v,
85 double v1,
86 double v2,
87 double v3,
88 double v4)
89 {
90 v.resize(4);
91 v[0] = v1;
92 v[1] = v2;
93 v[2] = v3;
94 v[3] = v4;
95 }
96
97
98 inline Vector CreateVector(double v1)
99 {
100 Vector v;
101 AssignVector(v, v1);
102 return v;
103 }
104
105
106 inline Vector CreateVector(double v1,
107 double v2)
108 {
109 Vector v;
110 AssignVector(v, v1, v2);
111 return v;
112 }
113
114
115 inline Vector CreateVector(double v1,
116 double v2,
117 double v3)
118 {
119 Vector v;
120 AssignVector(v, v1, v2, v3);
121 return v;
122 }
123
124
125 inline Vector CreateVector(double v1,
126 double v2,
127 double v3,
128 double v4)
129 {
130 Vector v;
131 AssignVector(v, v1, v2, v3, v4);
132 return v;
133 }
134
85 135
86 inline bool IsNear(double x, 136 inline bool IsNear(double x,
87 double y, 137 double y,
88 double threshold) 138 double threshold)
89 { 139 {
90 return fabs(x - y) < threshold; 140 return fabs(x - y) < threshold;
91 } 141 }
92 142
93 bool IsNear(double x, 143 inline bool IsNear(double x,
94 double y); 144 double y)
145 {
146 // As most input is read as single-precision numbers, we take the
147 // epsilon machine for float32 into consideration to compare numbers
148 return IsNear(x, y, 10.0 * std::numeric_limits<float>::epsilon());
149 }
95 150
96 inline bool IsCloseToZero(double x) 151 inline bool IsCloseToZero(double x)
97 { 152 {
98 return IsNear(x, 0.0); 153 return IsNear(x, 0.0);
99 } 154 }