Apollo 11.0
自动驾驶开放平台
misc.h
浏览该文件的文档.
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/*
18Copyright (C) 2006 Pedro Felzenszwalb
19This program is free software; you can redistribute it and/or modify
20it under the terms of the GNU General Public License as published by
21the Free Software Foundation; either version 2 of the License, or
22(at your option) any later version.
23This program is distributed in the hope that it will be useful,
24but WITHOUT ANY WARRANTY; without even the implied warranty of
25MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26GNU General Public License for more details.
27You should have received a copy of the GNU General Public License
28along with this program; if not, write to the Free Software
29Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30*/
31
32#pragma once
33
34#include <cmath>
35namespace apollo {
36namespace perception {
37namespace lidar {
38typedef unsigned char uchar;
39typedef struct {
43} rgb;
52inline bool operator==(const rgb &a, const rgb &b) {
53 return ((a.r == b.r) && (a.g == b.g) && (a.b == b.b));
54}
62template <class T>
63inline T abs(const T &x) {
64 return (x > 0 ? x : -x);
65}
73template <class T>
74inline int sign(const T &x) {
75 return (x >= 0 ? 1 : -1);
76}
84template <class T>
85inline T square(const T &x) {
86 return x * x;
87}
97template <class T>
98inline T bound(const T &x, const T &min, const T &max) {
99 return (x < min ? min : (x > max ? max : x));
100}
111template <class T>
112inline bool check_bound(const T &x, const T &min, const T &max) {
113 return ((x < min) || (x > max));
114}
121inline int vlib_round(float x) {
122 return static_cast<int>(x + 0.5F);
123}
130inline int vlib_round(double x) {
131 return static_cast<int>(x + 0.5);
132}
140inline double gaussian(double val, double sigma) {
141 return exp(-square(val / sigma) / 2) / (sqrt(2 * M_PI) * sigma);
142}
143} // namespace lidar
144} // namespace perception
145} // namespace apollo
double gaussian(double val, double sigma)
Get gaussian value of val based on sigma
Definition misc.h:140
T square(const T &x)
get square of value x
Definition misc.h:85
bool operator==(const rgb &a, const rgb &b)
Definition of equal sign
Definition misc.h:52
int vlib_round(float x)
Get round value of x
Definition misc.h:121
unsigned char uchar
Definition misc.h:38
bool check_bound(const T &x, const T &min, const T &max)
Check bound of x
Definition misc.h:112
int sign(const T &x)
Get sign of value x
Definition misc.h:74
T abs(const T &x)
Get absolute value of x
Definition misc.h:63
T bound(const T &x, const T &min, const T &max)
Get bound of value x
Definition misc.h:98
class register implement
Definition arena_queue.h:37