25 namespace perception {
29 inline float IAbs(
float a) {
return a < 0.f ? -a : a; }
30 inline int IAbs(
int a) {
return a < 0 ? -a : a; }
31 inline double IAbs(
double a) {
return a < 0.0 ? -a : a; }
35 inline float IDiv(
float a,
float b) {
return ((b != 0.f) ? (a / b) : 1.0f); }
36 inline float IDiv(
float a,
int b) {
37 return ((b != 0) ? (a / static_cast<float>(b)) : 1.0f);
39 inline float IDiv(
float a,
unsigned int b) {
42 result = a /
static_cast<float>(b);
46 inline double IDiv(
int a,
int b) {
47 return ((b != 0) ? (static_cast<double>(a) / b) : 1.0);
49 inline double IDiv(
unsigned int a,
unsigned int b) {
52 result =
static_cast<double>(a) / b;
56 inline double IDiv(
double a,
double b) {
return ((b != 0.0) ? (a / b) : 1.0); }
57 inline double IDiv(
double a,
int b) {
return ((b != 0) ? (a / b) : 1.0); }
58 inline double IDiv(
double a,
unsigned int b) {
69 inline float IRec(
float a) {
return ((a != 0.0f) ? ((1.0f) / a) : 1.0f); }
70 inline double IRec(
int a) {
return ((a != 0) ? ((1.0) / a) : 1.0); }
71 inline double IRec(
unsigned int a) {
return ((a != 0) ? ((1.0) / a) : 1.0); }
72 inline double IRec(
double a) {
return ((a != 0.0) ? ((1.0) / a) : 1.0); }
76 inline float ISqrt(
float a) {
return (a >= 0.0f) ? (sqrtf(a)) : 0.0f; }
78 return (a > 0) ? (sqrt(static_cast<double>(a))) : 0.0;
80 inline double ISqrt(
unsigned int a) {
81 return (a > 0) ? (sqrt(static_cast<double>(a))) : 0.0;
83 inline double ISqrt(
double a) {
return (a >= 0.0) ? (sqrt(a)) : 0.0; }
88 return (a >= 0.f) ? powf(a, 1.f / 3) : -powf(-a, 1.f / 3);
91 return (a >= 0) ? pow(static_cast<double>(a), 1.0 / 3)
92 : -pow(-static_cast<double>(a), 1.0 / 3);
94 inline double ICbrt(
unsigned int a) {
95 return pow(static_cast<double>(a), 1.0 / 3);
98 return (a >= 0.0) ? pow(a, 1.0 / 3) : -pow(-a, 1.0 / 3);
103 inline float ISqr(
float a) {
return (a * a); }
104 inline int ISqr(
int a) {
return (a * a); }
105 inline unsigned int ISqr(
unsigned int a) {
return (a * a); }
106 inline double ISqr(
double a) {
return (a * a); }
107 inline int ISqr(
char a) {
return (static_cast<int>(a) * static_cast<int>(a)); }
108 inline int ISqr(
unsigned char a) {
109 return (static_cast<int>(a) * static_cast<int>(a));
114 inline float ICub(
float a) {
return (a * a * a); }
115 inline int ICub(
int a) {
return (a * a * a); }
116 inline unsigned int ICub(
unsigned int a) {
return (a * a * a); }
117 inline double ICub(
double a) {
return (a * a * a); }
119 return (static_cast<int>(a) * static_cast<int>(a) * static_cast<int>(a));
121 inline int ICub(
unsigned char a) {
122 return (static_cast<int>(a) * static_cast<int>(a) * static_cast<int>(a));
126 inline float ILog(
float x) {
return ((x > 0.f) ? logf(x) : 0.f); }
128 return ((x > 0) ? log(static_cast<double>(x)) : 0.0);
130 inline double ILog(
unsigned int x) {
131 return ((x > 0) ? log(static_cast<double>(x)) : 0.0);
133 inline double ILog(
double x) {
return ((x > 0.0) ? log(x) : 0.0); }
136 inline float IExp(
float x) {
return (expf(x)); }
137 inline double IExp(
int x) {
return exp(static_cast<double>(x)); }
138 inline double IExp(
unsigned int x) {
return exp(static_cast<double>(x)); }
139 inline double IExp(
double x) {
return exp(x); }
142 inline float IPow(
float a,
float b) {
return powf(a, b); }
143 inline float IPow(
float a,
int b) {
return powf(a, static_cast<float>(b)); }
144 inline double IPow(
int a,
int b) {
145 return pow(static_cast<double>(a), static_cast<double>(b));
147 inline double IPow(
unsigned int a,
unsigned int b) {
148 return pow(static_cast<double>(a), static_cast<double>(b));
150 inline double IPow(
double a,
double b) {
return pow(a, b); }
151 inline double IPow(
double a,
int b) {
return pow(a, static_cast<double>(b)); }
154 template <
typename T>
156 return ((a <= b) ? a : b);
160 template <
typename T>
162 return ((a >= b) ? a : b);
166 template <
typename T>
175 template <
typename T>
188 template <
typename T>
199 return ((a >= 0.f) ? (static_cast<int>(a + 0.5f))
200 : (static_cast<int>(a - 0.5f)));
203 return ((a >= 0.0) ? (static_cast<int>(a + 0.5))
204 : (static_cast<int>(a - 0.5)));
209 inline int ICeil(
int a) {
return (a); }
210 inline int ICeil(
float a) {
return static_cast<int>(ceilf(a)); }
211 inline int ICeil(
double a) {
return static_cast<int>(ceil(a)); }
214 inline float ISin(
float alpha) {
return sinf(alpha); }
215 inline double ISin(
double alpha) {
return sin(alpha); }
216 inline float ICos(
float alpha) {
return cosf(alpha); }
217 inline double ICos(
double alpha) {
return cos(alpha); }
218 inline float ITan(
float alpha) {
return tanf(alpha); }
219 inline double ITan(
double alpha) {
return tan(alpha); }
257 inline float IAtan2(
float y,
float x) {
return atan2f(y, x); }
258 inline double IAtan2(
double y,
double x) {
return atan2(y, x); }
275 inline unsigned int IHamming(
unsigned int a,
unsigned int b) {
276 unsigned int distance = 0;
277 unsigned int val = a ^ b;
288 unsigned int distance = 0;
289 unsigned int val = a ^ b;
290 unsigned char *p = (
unsigned char *)&val;
292 distance = kIUByteBitCountLut[p[0]] + kIUByteBitCountLut[p[1]] +
293 kIUByteBitCountLut[p[2]] + kIUByteBitCountLut[p[3]];
298 template <
typename T>
305 template <
typename T>
306 inline void ISwap(T *a, T *b,
int n) {
307 for (
int i = 0; i < n; i++) {
311 template <
typename T>
316 template <
typename T>
322 template <
typename T>
333 template <
typename T>
344 template <
typename T>
350 return (max_val - 1);
356 template <
typename T>
358 for (
int i = 0; i < m; i++) {
362 template <
typename T>
367 template <
typename T>
373 template <
typename T>
380 template <
typename T>
387 template <
typename T>
395 template <
typename T>
407 template <
typename T>
423 template <
typename T>
425 for (
int i = 0; i < m; i++) {
429 template <
typename T>
434 template <
typename T>
440 template <
typename T>
447 template <
typename T>
454 template <
typename T>
462 template <
typename T>
474 template <
typename T>
491 template <
typename T>
494 for (
int i = 0; i < l; i++) {
495 for (
int j = 0; j < m; j++) {
503 template <
typename T>
505 for (
int i = 0; i < n; i++) {
506 a[i] =
static_cast<T
>(i);
513 inline void IGaussian2D(
float *kernel,
int n,
const float sigma) {
515 const float cen = (
static_cast<float>(n - 1)) / 2;
517 IDiv(0.5f, (sigma * sigma));
518 float dr, drsqr, dc, dcsqr, v, ksum = 0.f;
520 for (r = 0; r < n; ++r) {
521 dr =
static_cast<float>(r) - cen;
523 for (c = 0; c < n; ++c) {
524 dc =
static_cast<float>(c) - cen;
526 v =
IExp(-(drsqr + dcsqr) * nf);
532 v =
IDiv(1.0f, ksum);
533 for (i = 0; i < n * n; ++i) {
538 inline void IGaussian2D(
double *kernel,
int n,
const double sigma) {
540 const double cen = (
static_cast<double>(n - 1)) / 2;
542 IDiv(0.5, (sigma * sigma));
543 double dr, drsqr, dc, dcsqr, v, ksum = 0.0;
545 for (r = 0; r < n; ++r) {
546 dr =
static_cast<double>(r) - cen;
548 for (c = 0; c < n; ++c) {
549 dc =
static_cast<double>(c) - cen;
551 v =
IExp(-(drsqr + dcsqr) * nf);
558 for (i = 0; i < n * n; ++i) {
565 template <
typename T>
566 inline void IMove(
const T &a, T *b) {
572 template <
typename T>
573 inline bool IWithin1D(
const T x,
const T start,
const T length) {
574 return (x >= start && x < (length + start));
581 template <
typename T>
582 inline bool IWithin2D(
const T p[2],
const T x_upper_left,
const T y_upper_left,
583 const T width,
const T height) {
584 return (p[0] >= x_upper_left && p[1] >= y_upper_left &&
585 p[0] < width + x_upper_left && p[1] < height + y_upper_left);
591 template <
typename T>
592 inline bool IWithin2D(
const T x,
const T y,
const T x_upper_left,
593 const T y_upper_left,
const T width,
const T height) {
594 return (x >= x_upper_left && y >= y_upper_left && x < width + x_upper_left &&
595 y < height + y_upper_left);
T ISign(T a)
Definition: i_basic.h:176
int IRound(int a)
Definition: i_basic.h:197
void IMove(const T &a, T *b)
Definition: i_basic.h:566
float IAbs(float a)
Definition: i_basic.h:29
void IMakeConstReference12x12(const T a[144], const T *p[12])
Definition: i_basic.h:475
float IAsin(float alpha)
Definition: i_basic.h:221
void IMakeReference3x3(T a[9], T *p[3])
Definition: i_basic.h:368
void IMakeReference(T *a, T **p, int m, int n)
Definition: i_basic.h:357
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
bool IWithin1D(const T x, const T start, const T length)
Definition: i_basic.h:573
void IMakeReference2x2(T a[4], T *p[2])
Definition: i_basic.h:363
unsigned int IHammingLut(unsigned int a, unsigned int b)
Definition: i_basic.h:287
float IRec(float a)
Definition: i_basic.h:69
float IPow(float a, float b)
Definition: i_basic.h:142
T IMax(T a, T b)
Definition: i_basic.h:161
float IRadiansToDegree(float r)
Definition: i_basic.h:260
void IMakeConstReference9x9(const T a[81], const T *p[9])
Definition: i_basic.h:463
void IMakeReference9x9(T a[81], T *p[9])
Definition: i_basic.h:396
float ISqr(float a)
Definition: i_basic.h:103
float ILog(float x)
Definition: i_basic.h:126
T ISignNeverZero(T a)
Definition: i_basic.h:189
const double PI
Definition: const_var.h:77
float IExp(float x)
Definition: i_basic.h:136
Definition: i_constant.h:22
float ICub(float a)
Definition: i_basic.h:114
float IDegreeToRadians(float d)
Definition: i_basic.h:266
void IMakeConstReference(const T *a, const T **p, int m, int n)
Definition: i_basic.h:424
T IInterval(T a, T min_val, T max_val)
Definition: i_basic.h:334
int ICeil(int a)
Definition: i_basic.h:209
T IIntervalHalfopen(T a, T min_val, T max_val)
Definition: i_basic.h:345
float ISin(float alpha)
Definition: i_basic.h:214
void IMakeReference12x12(T a[144], T *p[12])
Definition: i_basic.h:408
float IDiv(float a, float b)
Definition: i_basic.h:35
void ISwap2(T *a, T *b)
Definition: i_basic.h:312
float ICos(float alpha)
Definition: i_basic.h:216
void IMakeReference5x9(T a[45], T *p[5])
Definition: i_basic.h:388
float IAcos(float alpha)
Definition: i_basic.h:239
void IMakeConstReference2x2(const T a[4], const T *p[2])
Definition: i_basic.h:430
void IMakeConstReference3x3(const T a[9], const T *p[3])
Definition: i_basic.h:435
void IMakeConstReference4x9(const T a[36], const T *p[4])
Definition: i_basic.h:448
void IGaussian2D(float *kernel, int n, const float sigma)
Definition: i_basic.h:513
void IMakeReference4x4(T a[16], T *p[4])
Definition: i_basic.h:374
unsigned int IHamming(unsigned int a, unsigned int b)
Definition: i_basic.h:275
T IAverage(T a, T b)
Definition: i_basic.h:167
void ISwap(T &a, T &b)
Definition: i_basic.h:299
void IMakeConstReference5x9(const T a[45], const T *p[5])
Definition: i_basic.h:455
void ISwap4(T *a, T *b)
Definition: i_basic.h:323
void IRamp(T *a, int n)
Definition: i_basic.h:504
float ISqrt(float a)
Definition: i_basic.h:76
T IMin(T a, T b)
Definition: i_basic.h:155
float ICbrt(float a)
Definition: i_basic.h:87
bool IWithin2D(const T p[2], const T x_upper_left, const T y_upper_left, const T width, const T height)
Definition: i_basic.h:582
void ISwap3(T *a, T *b)
Definition: i_basic.h:317
void IMakeConstReference4x4(const T a[16], const T *p[4])
Definition: i_basic.h:441
float IAtan2(float y, float x)
Definition: i_basic.h:257
float ITan(float alpha)
Definition: i_basic.h:218
void IMakeReference4x9(T a[36], T *p[4])
Definition: i_basic.h:381