Apollo  6.0
Open source self driving car software
misc.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2019 The Apollo Authors. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *****************************************************************************/
16 
17 /*
18 Copyright (C) 2006 Pedro Felzenszwalb
19 This program is free software; you can redistribute it and/or modify
20 it under the terms of the GNU General Public License as published by
21 the Free Software Foundation; either version 2 of the License, or
22 (at your option) any later version.
23 This program is distributed in the hope that it will be useful,
24 but WITHOUT ANY WARRANTY; without even the implied warranty of
25 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 GNU General Public License for more details.
27 You should have received a copy of the GNU General Public License
28 along with this program; if not, write to the Free Software
29 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 */
31 
32 #pragma once
33 
34 #include <cmath>
35 namespace apollo {
36 namespace perception {
37 namespace lidar {
38 typedef unsigned char uchar;
39 typedef struct {
40  uchar r;
41  uchar g;
42  uchar b;
43 } rgb;
44 inline bool operator==(const rgb &a, const rgb &b) {
45  return ((a.r == b.r) && (a.g == b.g) && (a.b == b.b));
46 }
47 template <class T>
48 inline T abs(const T &x) {
49  return (x > 0 ? x : -x);
50 }
51 template <class T>
52 inline int sign(const T &x) {
53  return (x >= 0 ? 1 : -1);
54 }
55 template <class T>
56 inline T square(const T &x) {
57  return x * x;
58 }
59 template <class T>
60 inline T bound(const T &x, const T &min, const T &max) {
61  return (x < min ? min : (x > max ? max : x));
62 }
63 template <class T>
64 inline bool check_bound(const T &x, const T &min, const T &max) {
65  return ((x < min) || (x > max));
66 }
67 inline int vlib_round(float x) { return static_cast<int>(x + 0.5F); }
68 inline int vlib_round(double x) { return static_cast<int>(x + 0.5); }
69 inline double gaussian(double val, double sigma) {
70  return exp(-square(val / sigma) / 2) / (sqrt(2 * M_PI) * sigma);
71 }
72 } // namespace lidar
73 } // namespace perception
74 } // namespace apollo
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
T bound(const T &x, const T &min, const T &max)
Definition: misc.h:60
T abs(const T &x)
Definition: misc.h:48
double gaussian(double val, double sigma)
Definition: misc.h:69
Definition: misc.h:39
bool check_bound(const T &x, const T &min, const T &max)
Definition: misc.h:64
uchar r
Definition: misc.h:40
uchar b
Definition: misc.h:42
T square(const T &x)
Definition: misc.h:56
unsigned char uchar
Definition: misc.h:38
int vlib_round(float x)
Definition: misc.h:67
bool operator==(const rgb &a, const rgb &b)
Definition: misc.h:44
uchar g
Definition: misc.h:41
int sign(const T &x)
Definition: misc.h:52