1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
| #include "matrix.h"
#include "mex.h"
#define max(a,b) ((a)>(b)? (a):(b))
#define min(a,b) ((a)<(b)? (a):(b))
int indexWrapper(int i, int j, int k, int nx, int ny)
{
int index = k * nx * ny + j * nx + i;
return index;
}
void modify_T_field(int rx, int ry, int a, int b, int c, int r0, int l, int n, int flash_effet, double *temp_field, double *matrice_flash, const mwSize *dims_flash)
{
int x1=max(rx-a,1)-1;
int x2=min(rx+a,l)-1;
int y1=max(ry-b,1)-1;
int y2=min(ry+b,c)-1;
int a1=r0-(rx-x1)-1;
int a2=a1+(x2-x1);
int b1=r0-(ry-y1)-1;
int b2=b1+(y2-y1);
int nxf = dims_flash[0];
int nyf = dims_flash[1];
for(int i = x1; i<=x2; i++)
{
for(int j = y1; j<=y2; j++)
{
for(int k = n; k <= n+flash_effet-1; k++)
{
int ia = a1 + i - x1;
int ja = b1 + j - y1;
int ka = k - n;
//temp_field[indexWrapper(i,j,k,c,l)] += matrice_flash[indexWrapper(ia,ja,ka,nxf,nyf)];
temp_field[indexWrapper(i,j,k,c,l)] = 0.95;
}
}
}
}
void computeField(int a, int b, int c, int r0, int l, int n, int flash_effet, double *x, double *y, double *temp_field, double *matrice_flash, const mwSize *dims_flash)
{
for(int i = 0; i<n; i++)
{
int rx = x[i];
int ry = y[i];
modify_T_field(rx, ry, a, b, c, r0, l, i, flash_effet, temp_field, matrice_flash, dims_flash);
}
}
/* The gateway function */
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
double *temp_field;
double *matrice_flash;
double *x;
double *y;
int a;
int b;
int c;
int l;
int n;
int r0;
int flash_effect;
/* get the value of the scalar input */
temp_field = mxGetPr(prhs[0]);
matrice_flash= mxGetPr(prhs[1]);
x = mxGetPr(prhs[2]);
y = mxGetPr(prhs[3]);
a = mxGetScalar(prhs[4]);
b = mxGetScalar(prhs[5]);
c = mxGetScalar(prhs[6]);
l = mxGetScalar(prhs[7]);
n = mxGetScalar(prhs[8]);
r0 = mxGetScalar(prhs[9]);
flash_effect = mxGetScalar(prhs[10]);
const mwSize *dims_flash = mxGetDimensions(prhs[1]);
//
computeField(a, b, c, r0, l, n, flash_effect, x, y, temp_field, matrice_flash, dims_flash);
} |