-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzero_crossing.c
58 lines (50 loc) · 1.29 KB
/
zero_crossing.c
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
#include "mex.h"
void mexFunction(
int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[])
{
double *phi;
mxLogical *contour;
int iWidth, iHeight;
/* The input must be a noncomplex scalar double.*/
iHeight = mxGetM(prhs[0]);
iWidth = mxGetN(prhs[0]);
/* Create matrix for the return argument. */
plhs[0] = mxCreateLogicalMatrix(iHeight,iWidth);
/* Assign pointers to each input and output. */
phi = mxGetPr(prhs[0]);
contour = mxGetLogicals(plhs[0]);
for (int i = 0; i < iWidth; i++)
{
for (int j = 0; j < iHeight; j++)
{
if (phi[i*iHeight+j] >= 0)
{
bool bIsNeighbourBelowZero = false;
for (int k = -1; k <= 1; k++)
{
for (int l = -1; l <= 1; l++)
{
if (i+k >= 0 && i+k < iWidth &&
j+l >= 0 && j+l < iHeight &&
phi[(i+k)*iHeight+j+l] < 0)
{
if (-phi[(i+k)*iHeight+j+l] < phi[i*iHeight+j])
{
contour[(i+k)*iHeight+j+l] = true;
}
else
{
contour[i*iHeight+j] = true;
}
}
}
}
// if (bIsNeighbourBelowZero)
// {
// contour[i*iHeight+j] = true;
// }
}
}
}
}