C library of triangulation algorithms (for the problems of mobile robot positioning or resection)
Data Structures | Macros | Functions
toolbox.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  color
 

Functions

tfloat detMatrix33 (tfloat M[][3])
 Computes the determinant of a 3x3 matrix. More...
 
tfloat gaussianRand (void)
 
void get_angles (tfloat *a1, tfloat *a2, tfloat *a3, tfloat xr, tfloat yr, tfloat or, tfloat x1, tfloat y1, tfloat x2, tfloat y2, tfloat x3, tfloat y3)
 
void grayscale2RGB (tfloat imageG[], tfloat imageRGB[], unsigned int width, unsigned int height, unsigned int Max)
 Convert a grayscale to an RGB image. More...
 
void initRand (void)
 Initializes the random number generator with current time.
 
color mapRGB (double v, double vmin, double vmax)
 
tfloat mean (tfloat data[], unsigned long N)
 Computes the algebraic mean of the array data[] of length N. More...
 
int saveMapAndScale (tfloat image[], unsigned int Width, unsigned int Height, unsigned int Mode, unsigned int Max, tfloat P1)
 
tfloat triangulationGDOP (tfloat xr, tfloat yr, tfloat x1, tfloat y1, tfloat x2, tfloat y2, tfloat x3, tfloat y3)
 
tfloat triangulationMethod (tfloat *x, tfloat *y, tfloat alpha1, tfloat alpha2, tfloat alpha3, tfloat x1, tfloat y1, tfloat x2, tfloat y2, tfloat x3, tfloat y3, int method)
 
tfloat triangulationSensitivity (tfloat xTrue, tfloat yTrue, tfloat x1, tfloat y1, tfloat x2, tfloat y2, tfloat x3, tfloat y3, int method, tfloat sigmaAngle, tfloat sigmaBeacon, unsigned int n, int outputType, double thresh)
 
tfloat variance (tfloat data[], unsigned long N)
 Computes the variance of the array data[] of length N. More...
 
int writePGM (tfloat image[], unsigned int width, unsigned int height, unsigned int Max, char *fileName)
 
int writePPM (tfloat image[], unsigned int width, unsigned int height, unsigned int Max, char *fileName)
 

Function Documentation

tfloat detMatrix33 ( tfloat  M[][3])
inline

Computes the determinant of a 3x3 matrix.

Parameters
M[][3]
Returns

Definition at line 358 of file toolbox.c.

Referenced by triangulationGDOP().

359 {
360  return M[0][0]*M[1][1]*M[2][2] + M[0][1]*M[1][2]*M[2][0] + M[1][0]*M[2][1]*M[0][2] - M[0][2]*M[1][1]*M[2][0] - M[0][1]*M[1][0]*M[2][2] - M[1][2]*M[2][1]*M[0][0] ;
361 }
tfloat gaussianRand ( void  )

Returns an occurence of a normally distributed random variable. Uses the Marsaglia polar method (polar version of Box-Muller transform). http://en.wikipedia.org/wiki/Box_Muller_transform

Returns

Definition at line 204 of file toolbox.c.

Referenced by triangulationSensitivity().

205 {
206  tfloat u , v , s = 0.0 ;
207 
208  while( s == 0.0 || s >= 1.0 )
209  {
210  u = ( ( (tfloat) random() / (tfloat) RAND_MAX ) * 2.0 ) - 1.0 ;
211  v = ( ( (tfloat) random() / (tfloat) RAND_MAX ) * 2.0 ) - 1.0 ;
212  s = u*u + v*v ;
213  }
214 
215  return u * sqrt( -2 * log(s) / s ) ;
216 }
double tfloat
Defines the type for float/double.
Definition: const.h:38
void get_angles ( tfloat a1,
tfloat a2,
tfloat a3,
tfloat  xr,
tfloat  yr,
tfloat  or,
tfloat  x1,
tfloat  y1,
tfloat  x2,
tfloat  y2,
tfloat  x3,
tfloat  y3 
)

Computes the angles (a1,a2,a3) measured by a robot (xr,yr) from beacons (x1,y1), (x2,y2), (x3,y3). The orientation of the robot is given by 'or', and angles are computed relatively to 'or'.

Parameters
a1
a2
a3
xr
yr
or
x1
y1
x2
y2
x3
y3

Definition at line 85 of file toolbox.c.

Referenced by triangulationSensitivity(), and usage().

86 {
87  *a1 = atan2( (y1 - yr) , (x1 - xr) ) - or ;
88  *a2 = atan2( (y2 - yr) , (x2 - xr) ) - or ;
89  *a3 = atan2( (y3 - yr) , (x3 - xr) ) - or ;
90 }
void grayscale2RGB ( tfloat  imageG[],
tfloat  imageRGB[],
unsigned int  width,
unsigned int  height,
unsigned int  Max 
)

Convert a grayscale to an RGB image.

Parameters
imageG[]
imageRGB[]
width
height
Max

Definition at line 439 of file toolbox.c.

References mapRGB().

Referenced by saveMapAndScale().

440 {
441  unsigned int i , j ;
442  tfloat v ;
443  color c ;
444 
445  for( j = 0 ; j < height ; ++j )
446  {
447  for( i = 0 ; i < width ; ++i )
448  {
449  v = imageG [ (height-j-1)*width + i ] ;
450  c = mapRGB( v , 0.0 , Max ) ;
451  imageRGB [ (height-j-1)*width*3 + i*3 + 0 ] = c.r * Max ;
452  imageRGB [ (height-j-1)*width*3 + i*3 + 1 ] = c.g * Max ;
453  imageRGB [ (height-j-1)*width*3 + i*3 + 2 ] = c.b * Max ;
454  }
455  }
456 }
color mapRGB(tfloat v, tfloat vmin, tfloat vmax)
Definition: toolbox.c:472
Definition: toolbox.h:14
double tfloat
Defines the type for float/double.
Definition: const.h:38

Here is the call graph for this function:

color mapRGB ( tfloat  v,
tfloat  vmin,
tfloat  vmax 
)

Return a RGB color value given a scalar v in the range [vmin,vmax] In this case each colour component ranges from 0 (no contribution) to 1 (fully saturated), modifications for other ranges is trivial. The colour is clipped at the end of the scales if v is outside the range [vmin,vmax] http://stackoverflow.com/questions/7706339/grayscale-to-red-green-blue-matlab-jet-color-scale

Parameters
v
vmin
vmax
Returns

Definition at line 472 of file toolbox.c.

Referenced by grayscale2RGB().

473 {
474  color c = { 1.0 , 1.0 , 1.0 } ; /* white */
475  tfloat dv ;
476 
477  if (v < vmin) v = vmin ;
478  if (v > vmax) v = vmax ;
479  dv = vmax - vmin ;
480 
481  if ( v < ( vmin + 0.25 * dv ) ) {
482  c.r = 0 ;
483  c.g = 4 * ( v - vmin ) / dv ;
484  } else if ( v < ( vmin + 0.5 * dv ) ) {
485  c.r = 0 ;
486  c.b = 1 + 4 * ( vmin + 0.25 * dv - v ) / dv ;
487  } else if ( v < ( vmin + 0.75 * dv ) ) {
488  c.r = 4 * ( v - vmin - 0.5 * dv ) / dv ;
489  c.b = 0 ;
490  } else {
491  c.g = 1 + 4 * ( vmin + 0.75 * dv - v ) / dv ;
492  c.b = 0 ;
493  }
494 
495  return c ;
496 }
Definition: toolbox.h:14
double tfloat
Defines the type for float/double.
Definition: const.h:38
tfloat mean ( tfloat  data[],
unsigned long  N 
)

Computes the algebraic mean of the array data[] of length N.

Parameters
data[]
N
Returns

Definition at line 153 of file toolbox.c.

References mean().

Referenced by mean(), triangulationSensitivity(), and variance().

154 {
155  unsigned long i ;
156  tfloat mean = 0.0 ;
157 
158  for( i = 0 ; i < N ; ++i )
159  mean += data[i] ;
160  mean /= N ;
161 
162  return mean ;
163 }
double tfloat
Defines the type for float/double.
Definition: const.h:38
tfloat mean(tfloat data[], unsigned long N)
Computes the algebraic mean of the array data[] of length N.
Definition: toolbox.c:153

Here is the call graph for this function:

int saveMapAndScale ( tfloat  image[],
unsigned int  width,
unsigned int  height,
unsigned int  mode,
unsigned int  Max,
tfloat  P1 
)

Scales 'image[]' according to 'mode', 'Max', and 'P1'. Saves scaled image in "map.pgm" and corresponding scale in "scale.pgm"

Parameters
image[]
width
height
mode
Max
P1
Returns

Definition at line 378 of file toolbox.c.

References grayscale2RGB(), map_to_grayscale_hist(), map_to_grayscale_lin(), map_to_grayscale_log(), map_to_grayscale_sat(), writePGM(), and writePPM().

Referenced by usage().

379 {
380  tfloat *map = ( tfloat * ) malloc( width * height * sizeof(tfloat) ) ; if( map == NULL ) return -1 ;
381  tfloat *scale = ( tfloat * ) malloc( (width/SWP) * height * sizeof(tfloat) ) ; if( scale == NULL ) return -1 ;
382  tfloat *map_color = ( tfloat * ) malloc( width * height * 3 * sizeof(tfloat) ) ; if( map_color == NULL ) return -1 ;
383  tfloat *scale_color = ( tfloat * ) malloc( (width/SWP) * height * 3 * sizeof(tfloat) ) ; if( scale_color == NULL ) return -1 ;
384 
385  switch( mode )
386  {
387  case 0:
388  map_to_grayscale_lin( image , map , scale , width , height , Max ) ;
389  break;
390  case 1:
391  map_to_grayscale_log( image , map , scale , width , height , Max , P1 ) ;
392  break;
393  case 2:
394  map_to_grayscale_hist( image , map , width , height , Max ) ;
395  break;
396  case 3:
397  map_to_grayscale_sat( image , map , width , height , 100 ) ;
398  map_to_grayscale_lin( map , map , scale , width , height , Max ) ;
399  break;
400  case 4:
401  map_to_grayscale_sat( image , map , width , height , 100 ) ;
402  map_to_grayscale_log( map , map , scale , width , height , Max , P1 ) ;
403  break;
404  default:
405  fprintf(stderr, "saveMapAndScale(): Bad map scaling mode!\n") ;
406  free( map ) ;
407  free( scale ) ;
408  free( map_color ) ;
409  free( scale_color ) ;
410  return -1 ;
411  }
412  writePGM( map , width , height , Max , "map.pgm" ) ;
413  writePGM( scale , width/SWP , height , Max , "scale.pgm" ) ; /* for now, there is no scale for mode 2. To Do */
414 
415  grayscale2RGB( map , map_color , width , height , Max ) ;
416  grayscale2RGB( scale , scale_color , width/SWP , height , Max ) ;
417 
418  writePPM( map_color , width , height , Max , "map.ppm" ) ;
419  writePPM( scale_color , width/SWP , height , Max , "scale.ppm" ) ; /* for now, there is no scale for mode 2. To Do */
420 
421  /* free memory */
422  free( map ) ;
423  free( scale ) ;
424  free( map_color ) ;
425  free( scale_color ) ;
426 
427  return 0 ;
428 }
void grayscale2RGB(tfloat imageG[], tfloat imageRGB[], unsigned int width, unsigned int height, unsigned int Max)
Convert a grayscale to an RGB image.
Definition: toolbox.c:439
double tfloat
Defines the type for float/double.
Definition: const.h:38
static void map_to_grayscale_log(tfloat *in, tfloat *out, tfloat *scale, unsigned int width, unsigned int height, unsigned int numgraylevels, tfloat P1)
Definition: toolbox.c:719
int writePPM(tfloat image[], unsigned int width, unsigned int height, unsigned int Max, char *fileName)
Definition: toolbox.c:551
static void map_to_grayscale_hist(tfloat *in, tfloat *out, unsigned int width, unsigned int height, unsigned int numgraylevels)
Definition: toolbox.c:612
static void map_to_grayscale_lin(tfloat *in, tfloat *out, tfloat *scale, unsigned int width, unsigned int height, unsigned int numgraylevels)
Definition: toolbox.c:679
int writePGM(tfloat image[], unsigned int width, unsigned int height, unsigned int Max, char *fileName)
Definition: toolbox.c:513
static void map_to_grayscale_sat(tfloat *in, tfloat *out, unsigned int width, unsigned int height, unsigned int p)
Definition: toolbox.c:644

Here is the call graph for this function:

tfloat triangulationGDOP ( tfloat  xr,
tfloat  yr,
tfloat  x1,
tfloat  y1,
tfloat  x2,
tfloat  y2,
tfloat  x3,
tfloat  y3 
)

Computes the first order Geometric Dilution of Precision (GDOP) for triangulation, given the robot position (xr,yr), and beacons locations (x1,y1), (x2,y2), and (x3,y3).

Parameters
xr
yr
x1
y1
x2
y2
x3
y3
Returns

Definition at line 334 of file toolbox.c.

References detMatrix33().

Referenced by usage().

335 {
336  tfloat jacobian[3][3] , det , d1 , d2 , d3 ;
337 
338  d1 = ( x1 - xr ) * ( x1 - xr ) + ( y1 - yr ) * ( y1 - yr ) ;
339  d2 = ( x2 - xr ) * ( x2 - xr ) + ( y2 - yr ) * ( y2 - yr ) ;
340  d3 = ( x3 - xr ) * ( x3 - xr ) + ( y3 - yr ) * ( y3 - yr ) ;
341 
342  jacobian[0][0] = ( y1 - yr ) / d1 ; jacobian[0][1] = ( x1 - xr ) / d1 ; jacobian[0][2] = 1.0 ;
343  jacobian[1][0] = ( y2 - yr ) / d2 ; jacobian[1][1] = ( x2 - xr ) / d2 ; jacobian[1][2] = 1.0 ;
344  jacobian[2][0] = ( y3 - yr ) / d3 ; jacobian[2][1] = ( x3 - xr ) / d3 ; jacobian[2][2] = 1.0 ;
345 
346  det = detMatrix33( jacobian ) ;
347 
348  return 1.0 / fabs( det ) ;
349 }
tfloat detMatrix33(tfloat M[][3])
Computes the determinant of a 3x3 matrix.
Definition: toolbox.c:358
double tfloat
Defines the type for float/double.
Definition: const.h:38

Here is the call graph for this function:

tfloat triangulationMethod ( tfloat x,
tfloat y,
tfloat  alpha1,
tfloat  alpha2,
tfloat  alpha3,
tfloat  x1,
tfloat  y1,
tfloat  x2,
tfloat  y2,
tfloat  x3,
tfloat  y3,
int  method 
)

Triangulates robot position (x,y) from measured angles alpha1, alpha2, and alpha3, and beacons locations (x1,y1), (x2,y2), and (x3,y3). Uses triangulation method 'm' given in command line.

Parameters
x
y
alpha1
alpha2
alpha3
x1
y1
x2
y2
x3
y3
method
Returns

Definition at line 112 of file toolbox.c.

References triangulationPierlot().

Referenced by triangulationSensitivity(), and usage().

115 {
116  switch( method )
117  {
118  case 1: return triangulationPierlot(x, y, alpha1, alpha2, alpha3, x1, y1, x2, y2, x3, y3) ;
119  case 2: return triangulationEsteves(x, y, alpha1, alpha2, alpha3, x1, y1, x2, y2, x3, y3) ;
120  case 3: return triangulationFontLlagunes(x, y, alpha1, alpha2, alpha3, x1, y1, x2, y2, x3, y3) ;
121  case 4: return triangulationZalama(x, y, alpha1, alpha2, alpha3, x1, y1, x2, y2, x3, y3) ;
122  case 5: return triangulationMcGillemTrigo(x, y, alpha1, alpha2, alpha3, x1, y1, x2, y2, x3, y3) ;
123  case 6: return triangulationMcGillemGeometric(x, y, alpha1, alpha2, alpha3, x1, y1, x2, y2, x3, y3) ;
124  case 7: return triangulationEaston(x, y, alpha1, alpha2, alpha3, x1, y1, x2, y2, x3, y3) ;
125  case 8: return triangulationHmam(x, y, alpha1, alpha2, alpha3, x1, y1, x2, y2, x3, y3) ;
126  case 9: return triangulationCohenTrigo(x, y, alpha1, alpha2, alpha3, x1, y1, x2, y2, x3, y3) ;
127  case 10: return triangulationCohenGeometric(x, y, alpha1, alpha2, alpha3, x1, y1, x2, y2, x3, y3) ;
128  case 11: return triangulationCohenGeometricOriginal(x, y, alpha1, alpha2, alpha3, x1, y1, x2, y2, x3, y3) ;
129  case 12: return triangulationTsukiyama(x, y, alpha1, alpha2, alpha3, x1, y1, x2, y2, x3, y3) ;
130  case 13: return triangulationTsukiyamaOriginal(x, y, alpha1, alpha2, alpha3, x1, y1, x2, y2, x3, y3) ;
131  case 14: return triangulationMadsen(x, y, alpha1, alpha2, alpha3, x1, y1, x2, y2, x3, y3) ;
132  case 15: return triangulationLukic(x, y, alpha1, alpha2, alpha3, x1, y1, x2, y2, x3, y3) ;
133  case 16: return triangulationLukicOriginal(x, y, alpha1, alpha2, alpha3, x1, y1, x2, y2, x3, y3) ;
134  case 17: return triangulationTienstra(x, y, alpha1, alpha2, alpha3, x1, y1, x2, y2, x3, y3) ;
135  case 18: return triangulationLigas(x, y, alpha1, alpha2, alpha3, x1, y1, x2, y2, x3, y3) ;
136  case 19: return triangulationFontLlagunes2(x, y, alpha1, alpha2, alpha3, x1, y1, x2, y2, x3, y3) ;
137  case 20: return triangulationKaestner(x, y, alpha1, alpha2, alpha3, x1, y1, x2, y2, x3, y3) ;
138  case 21: return triangulationCollins(x, y, alpha1, alpha2, alpha3, x1, y1, x2, y2, x3, y3) ;
139  case 22: return triangulationCassini(x, y, alpha1, alpha2, alpha3, x1, y1, x2, y2, x3, y3) ;
140  case 42: return triangulationPierlot2(x, y, alpha1, alpha2, alpha3, x1, y1, x2, y2, x3, y3) ;
141  default: fprintf(stderr, "triangulationMethod(): Bad method number!\n") ; return -1 ;
142  }
143 }
tfloat triangulationPierlot(tfloat *x, tfloat *y, tfloat alpha1, tfloat alpha2, tfloat alpha3, tfloat x1, tfloat y1, tfloat x2, tfloat y2, tfloat x3, tfloat y3)
Definition: total.c:16

Here is the call graph for this function:

tfloat triangulationSensitivity ( tfloat  xTrue,
tfloat  yTrue,
tfloat  x1,
tfloat  y1,
tfloat  x2,
tfloat  y2,
tfloat  x3,
tfloat  y3,
int  method,
tfloat  sigmaAngle,
tfloat  sigmaBeacon,
unsigned int  n,
int  outputType,
double  thresh 
)

Simulates the beacon position sensitivity of the triangulation method 'm', for measured angles alpha1, alpha2, and alpha3, and beacons locations (x1,y1), (x2,y2), and (x3,y3). 'sigma' is the standard deviation of beacon coordinates. The simulation is performed 'n' times.

Parameters
xTrue
yTrue
x1
y1
x2
y2
x3
y3
method
sigmaAngle
sigmaBeacon
n
outputType
thresh
Returns

Definition at line 242 of file toolbox.c.

References gaussianRand(), get_angles(), initRand(), mean(), PI, triangulationMethod(), and variance().

Referenced by usage().

244 {
245  tfloat alpha1 ;
246  tfloat alpha2 ;
247  tfloat alpha3 ;
248  tfloat oTrue = 0.0 ;
249  tfloat xNoise = 0.0 ;
250  tfloat yNoise = 0.0 ;
251  tfloat oNoise = 0.0 ;
252  tfloat qual = 0.0 ;
253 
254  tfloat ea1=0.0, ea2=0.0, ea3=0.0, ex1=0.0, ey1=0.0, ex2=0.0, ey2=0.0, ex3=0.0, ey3=0.0, s ;
255  tfloat *errP = ( tfloat * ) malloc( n * sizeof(tfloat) ) ; if( errP == NULL ) return -1 ;
256  tfloat *errO = ( tfloat * ) malloc( n * sizeof(tfloat) ) ; if( errO == NULL ) return -1 ;
257  tfloat *Qual = ( tfloat * ) malloc( n * sizeof(tfloat) ) ; if( Qual == NULL ) return -1 ;
258 
259  int i ;
260 
261  initRand() ;
262 
263  for ( i = 0 ; i < n ; ++i )
264  {
265  if ( sigmaAngle != 0.0 )
266  {
267  ea1 = gaussianRand() * sigmaAngle ;
268  ea2 = gaussianRand() * sigmaAngle ;
269  ea3 = gaussianRand() * sigmaAngle ;
270  }
271  if ( sigmaBeacon != 0.0 )
272  {
273  ex1 = gaussianRand() * sigmaBeacon ;
274  ey1 = gaussianRand() * sigmaBeacon ;
275  ex2 = gaussianRand() * sigmaBeacon ;
276  ey2 = gaussianRand() * sigmaBeacon ;
277  ex3 = gaussianRand() * sigmaBeacon ;
278  ey3 = gaussianRand() * sigmaBeacon ;
279  }
280 
281  get_angles(&alpha1, &alpha2, &alpha3, xTrue, yTrue, 0.0, x1+ex1, y1+ey1, x2+ex2, y2+ey2, x3+ex3, y3+ey3) ;
282  qual = triangulationMethod(&xNoise, &yNoise, alpha1+ea1, alpha2+ea2, alpha3+ea3, x1, y1, x2, y2, x3, y3, method) ;
283  qual = abs( qual ) ;
284  oNoise = atan2( (y1-yNoise) , (x1-xNoise) ) - alpha1 ;
285  /*tfloat oNoise2, oNoise3, sinMean, cosMean ;
286  oNoise2 = atan2( (y2-yNoise) , (x2-xNoise) ) - alpha2 ;
287  oNoise3 = atan2( (y3-yNoise) , (x3-xNoise) ) - alpha3 ;
288  sinMean = (sin(oNoise)+sin(oNoise2)+sin(oNoise3))/3;
289  cosMean = (cos(oNoise)+cos(oNoise2)+cos(oNoise3))/3;
290  oNoise = atan2( sinMean , cosMean ) ;*/
291 
292  errP[ i ] = sqrt( (xTrue-xNoise)*(xTrue-xNoise) + (yTrue-yNoise)*(yTrue-yNoise) ) ;
293  errO[ i ] = oTrue - oNoise ; while( errO[ i ] > PI ) errO[ i ] -= TWOPI ; while( errO[ i ] <= -PI ) errO[ i ] += TWOPI ;
294  Qual[ i ] = qual ;
295  }
296 
297  switch( outputType )
298  {
299  case 1: s = sqrt ( variance ( errP , n ) ) ; break ;
300  case 2: s = sqrt ( variance ( errO , n ) ) * RAD2DEG ; break ;
301  case 3: s = mean ( Qual , n ) ; break ;
302  default: fprintf( stderr , "triangulationSensitivity(): Bad output type!\n" ) ; return -1 ;
303  }
304 
305  free ( errP ) ;
306  free ( errO ) ;
307  free ( Qual ) ;
308 
309  if( thresh > 0.0 )
310  {
311  if( s <= thresh ) return 1.0 ;
312  else return 0.0 ;
313  }
314  else return s ;
315 
316 }
void get_angles(tfloat *a1, tfloat *a2, tfloat *a3, tfloat xr, tfloat yr, tfloat or, tfloat x1, tfloat y1, tfloat x2, tfloat y2, tfloat x3, tfloat y3)
Definition: toolbox.c:85
void initRand()
Initializes the random number generator with current time.
Definition: toolbox.c:190
tfloat variance(tfloat data[], unsigned long N)
Computes the variance of the array data[] of length N.
Definition: toolbox.c:173
#define PI
The value of PI.
Definition: const.h:12
double tfloat
Defines the type for float/double.
Definition: const.h:38
tfloat mean(tfloat data[], unsigned long N)
Computes the algebraic mean of the array data[] of length N.
Definition: toolbox.c:153
tfloat triangulationMethod(tfloat *x, tfloat *y, tfloat alpha1, tfloat alpha2, tfloat alpha3, tfloat x1, tfloat y1, tfloat x2, tfloat y2, tfloat x3, tfloat y3, int method)
Definition: toolbox.c:112
tfloat gaussianRand()
Definition: toolbox.c:204

Here is the call graph for this function:

tfloat variance ( tfloat  data[],
unsigned long  N 
)

Computes the variance of the array data[] of length N.

Parameters
data[]
N
Returns

Definition at line 173 of file toolbox.c.

References mean(), and variance().

Referenced by triangulationSensitivity(), and variance().

174 {
175  unsigned long i ;
176  tfloat m = 0.0 , variance = 0.0 ;
177 
178  m = mean( data , N ) ;
179 
180  for( i = 0 ; i < N ; ++i )
181  variance += (data[i]-m) * (data[i]-m) ;
182  variance /= N ;
183 
184  return variance ;
185 }
tfloat variance(tfloat data[], unsigned long N)
Computes the variance of the array data[] of length N.
Definition: toolbox.c:173
double tfloat
Defines the type for float/double.
Definition: const.h:38
tfloat mean(tfloat data[], unsigned long N)
Computes the algebraic mean of the array data[] of length N.
Definition: toolbox.c:153

Here is the call graph for this function:

int writePGM ( tfloat  image[],
unsigned int  width,
unsigned int  height,
unsigned int  Max,
char *  fileName 
)

Writes a PGM ASCII file in 'fileName'. image[] is the array of values, width/height are the dimensions, Max is the maximum desired value in the file. http://netpbm.sourceforge.net/doc/ppm.html http://en.wikipedia.org/wiki/Netpbm_format

Parameters
image[]
width
height
Max
fileName
Returns

Definition at line 513 of file toolbox.c.

Referenced by saveMapAndScale().

514 {
515  unsigned int i , j ;
516  FILE *file = fopen( fileName , "w" ) ; if( file == NULL ) return -1 ;
517 
518  /* write PGM ASCII file */
519  fprintf( file , "P2\n" ) ;
520  fprintf( file , "%d\n", width ) ;
521  fprintf( file , "%d\n", height ) ;
522  fprintf( file , "%d\n", Max ) ;
523  for( j = 0 ; j < height ; ++j )
524  {
525  for( i = 0 ; i < width ; ++i )
526  {
527  fprintf( file , "%u ", ( unsigned int ) image [ (height-j-1)*width + i ] ) ;
528  }
529  fprintf( file , "\n" ) ;
530  }
531 
532  fclose( file ) ;
533 
534  return 0 ;
535 }
int writePPM ( tfloat  image[],
unsigned int  width,
unsigned int  height,
unsigned int  Max,
char *  fileName 
)

Writes a PPM ASCII file in 'fileName'. image[] is the array of values, width/height are the dimensions, Max is the maximum desired value in the file. http://netpbm.sourceforge.net/doc/ppm.html http://en.wikipedia.org/wiki/Netpbm_format

Parameters
image[]
width
height
Max
fileName
Returns

Definition at line 551 of file toolbox.c.

Referenced by saveMapAndScale().

552 {
553  unsigned int i , j ;
554  FILE *file = fopen( fileName , "w" ) ; if( file == NULL ) return -1 ;
555 
556  /* write PGM ASCII file */
557  fprintf( file , "P3\n" ) ;
558  fprintf( file , "%d\n", width ) ;
559  fprintf( file , "%d\n", height ) ;
560  fprintf( file , "%d\n", Max ) ;
561  for( j = 0 ; j < height ; ++j )
562  {
563  for( i = 0 ; i < width ; ++i )
564  {
565  fprintf( file , "%u ", ( unsigned int ) image [ (height-j-1)*width*3 + i*3 ] ) ;
566  fprintf( file , "%u ", ( unsigned int ) image [ (height-j-1)*width*3 + i*3 + 1 ] ) ;
567  fprintf( file , "%u ", ( unsigned int ) image [ (height-j-1)*width*3 + i*3 + 2 ] ) ;
568  }
569  fprintf( file , "\n" ) ;
570  }
571 
572  fclose( file ) ;
573 
574  return 0 ;
575 }