Structural deformable models
Macros | Functions
mathutil.h File Reference
#include <math.h>
#include "simpletypes.h"
#include <stdlib.h>
Include dependency graph for mathutil.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define M_PI   3.14159265359
 
#define M_1_PI   (1/M_PI)
 
#define M_E   2.718281828
 
#define M_SQRT2PI   2.5066283
 
#define frand(max)   (((float)rand())*(max)/RAND_MAX)
 
#define FRAND1   (((float)rand())/RAND_MAX)
 

Functions

int absint (int v)
 
template<class T >
bool clamp (T &x, T &y, const T x0, const T y0, const T x1, const T y1)
 
float fgauss01 ()
 
float gauss (float x, float stdev)
 
float gauss2 (float x2, float stdev)
 
double gaussd (float x, double stdev)
 
float gaussd2 (float x2, double stdev)
 
float mapAngle360 (float a)
 
float mapAngle360 (float a, float mina)
 
float mapAngle180 (float a)
 
float mapAngle2PI (float a)
 
float mapAngle2PI (float a, float mina)
 
float mapAnglePI (float a)
 
float mapAnglePI (float a, float cnta)
 
dword power2 (dword x)
 

Macro Definition Documentation

#define frand (   max)    (((float)rand())*(max)/RAND_MAX)
#define FRAND1   (((float)rand())/RAND_MAX)

Definition at line 49 of file mathutil.h.

Referenced by Searcher::mutate().

#define M_1_PI   (1/M_PI)

Definition at line 12 of file mathutil.h.

Referenced by Point2D::angle(), VVector< float, 4 >::angle(), and mapAngle2PI().

#define M_E   2.718281828

Definition at line 15 of file mathutil.h.

#define M_PI   3.14159265359
#define M_SQRT2PI   2.5066283

Definition at line 18 of file mathutil.h.

Referenced by gauss(), gauss2(), gaussd(), gaussd2(), and EMDGauss::ratePropVec().

Function Documentation

int absint ( int  v)
inline

Definition at line 21 of file mathutil.h.

Referenced by Image< T >::addLine().

21 { return v<0 ? -v : v;}
template<class T >
bool clamp ( T &  x,
T &  y,
const T  x0,
const T  y0,
const T  x1,
const T  y1 
)

Definition at line 24 of file mathutil.h.

Referenced by Point2D::clamp().

25 {
26  bool ret=false;
27  if(x<x0) { ret = true; x = x0;}
28  if(x>x1) { ret = true; x = x1;}
29  if(y<y0) { ret = true; y = y0;}
30  if(y>y1) { ret = true; y = y1;}
31  return ret;
32 }
float fgauss01 ( )
inline

Definition at line 53 of file mathutil.h.

References frand, and dmutil::sqrt().

Referenced by Dataset::addNoise(), Brain::distributeModel(), EMDGauss::getPropVec(), and makeNoiseImage().

54 {
55  float x, y, r2;
56  do
57  {
58  /* choose x,y in uniform square (-1,-1) to (+1,+1) */
59  x = -1 + frand(2);
60  y = -1 + frand(2);
61  /* see if it is in the unit circle */
62  r2 = x * x + y * y;
63  } while (r2 > 1.0 || r2 == 0);
64  /* Box-Mueller transform */
65  return y * sqrt (-2.0 * log (r2) / r2);
66 }
#define frand(max)
Definition: mathutil.h:48
DMatrix< T > & sqrt(DMatrix< T > &mat)
Definition: DMatrixUtil.h:81
float gauss ( float  x,
float  stdev 
)
inline

Definition at line 68 of file mathutil.h.

References M_SQRT2PI.

68  {
69  return exp(-x*x/(2*stdev*stdev)) / (stdev*M_SQRT2PI);
70 }
#define M_SQRT2PI
Definition: mathutil.h:18
DMatrix< T > stdev(const DMatrix< T > &mat)
Definition: DMatrixUtil.h:106
float gauss2 ( float  x2,
float  stdev 
)
inline

Definition at line 71 of file mathutil.h.

References M_SQRT2PI.

Referenced by EMDGauss::ratePropVec().

71  {
72  return exp(-x2/(2*stdev*stdev)) / (stdev*M_SQRT2PI);
73 }
#define M_SQRT2PI
Definition: mathutil.h:18
DMatrix< T > stdev(const DMatrix< T > &mat)
Definition: DMatrixUtil.h:106
double gaussd ( float  x,
double  stdev 
)
inline

Definition at line 74 of file mathutil.h.

References M_SQRT2PI.

74  {
75  return exp(-x*x/(2*stdev*stdev)) / (stdev*M_SQRT2PI);
76 }
#define M_SQRT2PI
Definition: mathutil.h:18
DMatrix< T > stdev(const DMatrix< T > &mat)
Definition: DMatrixUtil.h:106
float gaussd2 ( float  x2,
double  stdev 
)
inline

Definition at line 77 of file mathutil.h.

References M_SQRT2PI.

Referenced by create2DGaussian().

77  {
78  return exp(-x2/(2*stdev*stdev)) / (stdev*M_SQRT2PI);
79 }
#define M_SQRT2PI
Definition: mathutil.h:18
DMatrix< T > stdev(const DMatrix< T > &mat)
Definition: DMatrixUtil.h:106
float mapAngle180 ( float  a)
inline

Definition at line 92 of file mathutil.h.

References mapAngle360().

92  {
93  a = mapAngle360(a);
94  return a<=180 ? a : a-360;
95 }
float mapAngle360(float a)
Definition: mathutil.h:81
float mapAngle2PI ( float  a)
inline

Definition at line 97 of file mathutil.h.

References M_1_PI, and M_PI.

Referenced by ExpectationMap::correctLBUB(), Model::getDirection(), ExpectationMap::getPropVec(), mapAnglePI(), and ExpectationMap::ratePropVec().

97  {
98  float turns=floor(a*(0.5*M_1_PI));
99  return a-(2*M_PI)*turns;
100 }
#define M_1_PI
Definition: mathutil.h:12
#define M_PI
Definition: mathutil.h:9
float mapAngle2PI ( float  a,
float  mina 
)
inline

Definition at line 102 of file mathutil.h.

References M_1_PI, and M_PI.

102  {
103  float turns=floor((a-mina)*(0.5*M_1_PI));
104  return a-(2*M_PI)*turns;
105 }
#define M_1_PI
Definition: mathutil.h:12
#define M_PI
Definition: mathutil.h:9
float mapAngle360 ( float  a)
inline

Definition at line 81 of file mathutil.h.

Referenced by mapAngle180().

81  {
82  int d=(int)a/360 - (int)(a<0);
83  return a-360*(float)d;
84 }
float mapAngle360 ( float  a,
float  mina 
)
inline

Definition at line 86 of file mathutil.h.

86  {
87  float ashift = a-mina;
88  int d=(int)ashift/360 - (int)(ashift<0);
89  return a-360*(float)d;
90 }
float mapAnglePI ( float  a)
inline

Definition at line 107 of file mathutil.h.

References M_PI, and mapAngle2PI().

Referenced by Model::addTorque(), StructTable::adjustByAvgDir(), Searcher::buildClusters(), and EMDXformer::ratePropVec().

107  {
108  a = mapAngle2PI(a);
109  return (a>M_PI) ? a-(2*M_PI) : a;
110 }
float mapAngle2PI(float a)
Definition: mathutil.h:97
#define M_PI
Definition: mathutil.h:9
float mapAnglePI ( float  a,
float  cnta 
)
inline

Definition at line 112 of file mathutil.h.

References M_PI, and mapAngle2PI().

112  {
113  a = mapAngle2PI(a, cnta);
114  return (a-cnta>M_PI) ? a-(2*M_PI) : a;
115 }
float mapAngle2PI(float a)
Definition: mathutil.h:97
#define M_PI
Definition: mathutil.h:9
dword power2 ( dword  x)
inline

Definition at line 117 of file mathutil.h.

Referenced by GLImage::setImage().

118 {
119  return 1<< int(ceil(log(float(x))/log(2.f)));
120 }