/***************************************************************** This file includes the utility routines used in the program ******************************************************************/ #define UTIL_SOURCE_C_C #include "util.h" float sqrtf(float x) { return (float)sqrt((double)x); } /*********************************************/ int Round(float x) { if(x>0) return( (int)(x+0.5) ); return( (int)(x-0.5) ); } /**********************************************/ /* return random [0,1] */ /**********************************************/ float Unit_Random(void) { float r; /* return(rand()/2147483647.0); */ /* 2**31-1 */ r=rand()/32767.0; while(r==0 || r==1) r=rand()/32767.0; return(r); } MAT_VECT Create_3D_Matrix(int height,int width, int length) { MAT_VECT p; int i; printf("Creating a vector image with size %d x %d x %d ... ", height, width, length); fflush(stdout); p = (MAT_VECT)malloc(sizeof(MAT)*height); for (i=0; i< height; i++) { if ( (i%(height/20))==0) { printf("-"); fflush(stdout); } p[i] = Create_Matrix(width, length); } printf(" Done!\n"); return p; } void Free_3D_Matrix(MAT_VECT a3Dmat, int height, int width) { int i; for (i=0; i < height; i++) Free_Matrix(a3Dmat[i], width); free(a3Dmat); } /******************************************************* allocate the space for matrix *******************************************************/ MAT Create_Matrix(int height,int width) { MAT p; int i; p=(float **)malloc(height*sizeof(float *)); for(i=0; imax) max=mat[i][j]; if (min == max) max = min +1; ratio= ((float)(high-low-1.0))/((float)(max-min)); for(i=0; i maxVal) mat[i][j] = maxVal; } return(mat); } /************************************************ initialize the matrix as random noise ************************************************/ MAT_I Create_Const_Matrix(int height,int width, int cVal) { int i, j; MAT_I mat; mat=Create_Int_Matrix(height, width); for(i=0; i