misc.h
Go to the documentation of this file.
00001 /*
00002 Copyright (C) 2006 Pedro Felzenszwalb
00003 
00004 This program is free software; you can redistribute it and/or modify
00005 it under the terms of the GNU General Public License as published by
00006 the Free Software Foundation; either version 2 of the License, or
00007 (at your option) any later version.
00008 
00009 This program is distributed in the hope that it will be useful,
00010 but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 GNU General Public License for more details.
00013 
00014 You should have received a copy of the GNU General Public License
00015 along with this program; if not, write to the Free Software
00016 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00017 */
00018 
00019 /* random stuff */
00020 
00021 #ifndef MISC_H
00022 #define MISC_H
00023 
00024 #include <cmath>
00025 
00026 #ifndef M_PI
00027 #define M_PI 3.141592653589793
00028 #endif
00029 
00030 typedef unsigned char uchar;
00031 
00032 typedef struct {
00033     uchar r, g, b;
00034     unsigned int idx;
00035 } rgb;
00036 
00037 inline bool operator==(const rgb &a, const rgb &b) {
00038   return ((a.r == b.r) && (a.g == b.g) && (a.b == b.b));
00039 }
00040 
00041 template <class T>
00042 inline T abs(const T &x) { return (x > 0 ? x : -x); };
00043 
00044 template <class T>
00045 inline int sign(const T &x) { return (x >= 0 ? 1 : -1); };
00046 
00047 template <class T>
00048 inline T square(const T &x) { return x*x; };
00049 
00050 template <class T>
00051 inline T bound(const T &x, const T &min, const T &max) {
00052   return (x < min ? min : (x > max ? max : x));
00053 }
00054 
00055 template <class T>
00056 inline bool check_bound(const T &x, const T&min, const T &max) {
00057   return ((x < min) || (x > max));
00058 }
00059 
00060 inline int vlib_round(float x) { return (int)(x + 0.5F); }
00061 
00062 inline int vlib_round(double x) { return (int)(x + 0.5); }
00063 
00064 inline double gaussian(double val, double sigma) {
00065   return exp(-square(val/sigma)/2)/(sqrt(2*M_PI)*sigma);
00066 }
00067 
00068 #endif


cpl_superpixels
Author(s): Tucker Hermans
autogenerated on Wed Nov 27 2013 11:38:57