misc.h
Go to the documentation of this file.
1 /*
2 Copyright (C) 2006 Pedro Felzenszwalb
3 
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8 
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13 
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18 
19 /* random stuff */
20 
21 #pragma once
22 
23 #include <cmath>
24 
25 namespace distance_transform
26 {
27  typedef unsigned char uchar;
28 
29  typedef struct { uchar r, g, b; } rgb;
30 
31  inline bool operator==(const rgb &a, const rgb &b) {
32  return ((a.r == b.r) && (a.g == b.g) && (a.b == b.b));
33  }
34 
35  template <class T>
36  inline T abs(const T &x) { return (x > 0 ? x : -x); }
37 
38  template <class T>
39  inline int sign(const T &x) { return (x >= 0 ? 1 : -1); }
40 
41  template <class T>
42  inline T square(const T &x) { return x*x; }
43 
44  template <class T>
45  inline T bound(const T &x, const T &min, const T &max) {
46  return (x < min ? min : (x > max ? max : x));
47  }
48 
49  template <class T>
50  inline bool check_bound(const T &x, const T&min, const T &max) {
51  return ((x < min) || (x > max));
52  }
53 
54  inline int vlib_round(float x) { return (int)(x + 0.5F); }
55 
56  inline int vlib_round(double x) { return (int)(x + 0.5); }
57 
58  inline double gaussian(double val, double sigma) {
59  return exp(-square(val/sigma)/2)/(sqrt(2*M_PI)*sigma);
60  }
61 
62 } // namespace
bool check_bound(const T &x, const T &min, const T &max)
Definition: misc.h:50
bool operator==(const rgb &a, const rgb &b)
Definition: misc.h:31
double gaussian(double val, double sigma)
Definition: misc.h:58
T abs(const T &x)
Definition: misc.h:36
T square(const T &x)
Definition: misc.h:42
unsigned char uchar
Definition: misc.h:27
T bound(const T &x, const T &min, const T &max)
Definition: misc.h:45
int sign(const T &x)
Definition: misc.h:39
int vlib_round(float x)
Definition: misc.h:54


grid_map_sdf
Author(s): Takahiro Miki , Péter Fankhauser
autogenerated on Tue Jun 1 2021 02:13:49