00001 #ifndef Impala_Core_Array_MakeGaussian2d_h
00002 #define Impala_Core_Array_MakeGaussian2d_h
00003
00004 #include "Util/Math.h"
00005 #include "Core/Array/Arrays.h"
00006
00007 namespace Impala
00008 {
00009 namespace Core
00010 {
00011 namespace Array
00012 {
00013
00014
00015 #ifndef M_PI
00016 #define M_PI 3.14159265358979323846
00017 #endif
00018
00019
00020
00021 #define ABS(a) ((a) < 0.0 ? -(a) : (a))
00022
00023
00028 inline Array2dScalarReal64*
00029 MakeGaussian2d(double st, double sr, double phi, int dert, double n)
00030 {
00031 int xx, yy, width, height;
00032 double l, divido;
00033
00034 phi = phi*M_PI/180.0;
00035 if (phi == 0.0) {
00036 width = (int)(n*st);
00037 height = (int)(n*sr);
00038 } else {
00039 l = sqrt(sr*sr/(cos(phi)*cos(phi)) + st*st/(sin(phi)*sin(phi)));
00040 width = (int)(n*ABS(st*st/tan(phi) + sr*sr*tan(phi))/l + 0.5);
00041 l = sqrt(st*st/(cos(phi)*cos(phi)) + sr*sr/(sin(phi)*sin(phi)));
00042 height = (int)(n*ABS(sr*sr/tan(phi) + st*st*tan(phi))/l + 0.5);
00043 }
00044 divido = 1./(2*M_PI*sr*st);
00045
00046 double* fData = new double[(2*width+1) * (2*height+1)];
00047
00048 int i=0;
00049 for (yy=0; yy<2*height+1; yy++) {
00050 for (xx=0; xx<2*width+1; xx++) {
00051 if (dert==2) {
00052 divido = (pow((cos(phi)*(xx-width)+sin(phi)*(yy-height))/st,
00053 2.0)-1.)/(2*M_PI*sr*st*st);
00054 }
00055 fData[i] = (double)(divido * exp(-0.5 *
00056 (pow(( cos(phi)*(xx-width)+sin(phi)*(yy-height))/st,2.0)+
00057 pow((-sin(phi)*(xx-width)+cos(phi)*(yy-height))/sr,2.0))));
00058 i++;
00059 }
00060 }
00061 return ArrayCreate<Array2dScalarReal64>(2*width+1, 2*height+1, 0, 0, fData);
00062 }
00063
00064 #undef ABS
00065
00066 }
00067 }
00068 }
00069
00070 #endif