kopia lustrzana https://github.com/Dsplib/libdspl-2.0
Merge branch 'master' of https://github.com/Dsplib/libdspl-2.0
Changes to be committed: modified: examples/src/contour_test.cmaster
commit
d18c8c4f7e
|
@ -7,11 +7,19 @@
|
||||||
#define M 4
|
#define M 4
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
typedef double point2d_t[2];
|
typedef double point2d_t[2];
|
||||||
typedef point2d_t linseg_t[2];
|
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
point2d_t p[2];
|
||||||
|
int flag;
|
||||||
|
} linseg_t;
|
||||||
|
|
||||||
|
|
||||||
|
int add_linseg(linseg_t** ls, int* lsnum, int* lscnt,
|
||||||
|
point2d_t* p0, point2d_t* p1)
|
||||||
|
|
||||||
int add_linseg(linseg_t** ls, int* lsnum, int* lscnt, point2d_t* p0, point2d_t* p1)
|
|
||||||
{
|
{
|
||||||
int n, c;
|
int n, c;
|
||||||
n = *lsnum;
|
n = *lsnum;
|
||||||
|
@ -29,10 +37,11 @@ int add_linseg(linseg_t** ls, int* lsnum, int* lscnt, point2d_t* p0, point2d_t*
|
||||||
(*ls) = (linseg_t*)realloc((*ls), n * sizeof(linseg_t));
|
(*ls) = (linseg_t*)realloc((*ls), n * sizeof(linseg_t));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(*ls)[c][0][0] = p0[0][0];
|
(*ls)[c].p[0][0] = p0[0][0];
|
||||||
(*ls)[c][0][1] = p0[0][1];
|
(*ls)[c].p[0][1] = p0[0][1];
|
||||||
(*ls)[c][1][0] = p1[0][0];
|
(*ls)[c].p[1][0] = p1[0][0];
|
||||||
(*ls)[c][1][1] = p1[0][1];
|
(*ls)[c].p[1][1] = p1[0][1];
|
||||||
|
(*ls)[c].flag = 0;
|
||||||
c++;
|
c++;
|
||||||
(*lsnum) = n;
|
(*lsnum) = n;
|
||||||
(*lscnt) = c;
|
(*lscnt) = c;
|
||||||
|
@ -40,11 +49,16 @@ int add_linseg(linseg_t** ls, int* lsnum, int* lscnt, point2d_t* p0, point2d_t*
|
||||||
return RES_OK;
|
return RES_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int linseg_create(int* z, int n, int m, linseg_t** ls, int* sz)
|
int linseg_create(double* z, double* x, double* y,
|
||||||
|
int n, int m, double lev,
|
||||||
|
linseg_t** ls, int* sz)
|
||||||
{
|
{
|
||||||
int lsnum, lscnt, t, in, im, i;
|
int lsnum, lscnt, t, in, im, i;
|
||||||
point2d_t p0 = {0};
|
point2d_t p0 = {0};
|
||||||
point2d_t p1 = {0};
|
point2d_t p1 = {0};
|
||||||
|
|
||||||
|
double dx;
|
||||||
|
double dy;
|
||||||
|
|
||||||
if((ls== NULL)||(z==NULL))
|
if((ls== NULL)||(z==NULL))
|
||||||
return ERROR_PTR;
|
return ERROR_PTR;
|
||||||
|
@ -56,38 +70,53 @@ int linseg_create(int* z, int n, int m, linseg_t** ls, int* sz)
|
||||||
for(im = 0; im < m-1; im++)
|
for(im = 0; im < m-1; im++)
|
||||||
{
|
{
|
||||||
i = in + im * n;
|
i = in + im * n;
|
||||||
t = z[i]*8 + z[i+n]*4 + z[i+n+1]*2 + z[i+1];
|
t = 0;
|
||||||
|
t += z[i] > lev ? 8 : 0;
|
||||||
|
t += z[i+n] > lev ? 4 : 0;
|
||||||
|
t += z[i+n+1] > lev ? 2 : 0;
|
||||||
|
t += z[i+1] > lev ? 1 : 0;
|
||||||
|
|
||||||
printf("%d, %d, %d\n", in, im, t);
|
printf("%d, %d, %d\n", in, im, t);
|
||||||
switch(t)
|
switch(t)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
p0[0] = (double) in + 0.5;
|
// z[i,j] * (1-dx) + z[i+1, j] * dx = lev
|
||||||
p0[1] = (double) im;
|
// z[i,j] + dx *(z[i+1, j] - z[i,j]) = lev
|
||||||
p1[0] = (double) in + 1.0;
|
dx = (lev - z[i]) / (z[i+1] - z[i]);
|
||||||
p1[1] = (double) im + 0.5;
|
p0[0] = x[in] + dx;
|
||||||
|
p0[1] = y[im];
|
||||||
|
dy = (lev - z[i+1]) / (z[i+n+1] - z[i+1]);
|
||||||
|
p1[0] = x[in+1];
|
||||||
|
p1[1] = y[im] + dy;
|
||||||
add_linseg(ls, &lsnum, &lscnt, &p0, &p1);
|
add_linseg(ls, &lsnum, &lscnt, &p0, &p1);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
p0[0] = (double) in + 0.5;
|
dx = (lev - z[i+n]) / (z[i+n+1] - z[i+n]);
|
||||||
p0[1] = (double) im + 1.0;
|
p0[0] = x[in] + dx;
|
||||||
p1[0] = (double) in + 1.0;
|
p0[1] = y[im + 1];
|
||||||
p1[1] = (double) im + 0.5;
|
|
||||||
|
dy = (lev - z[i+1]) / (z[i+n+1] - z[i+1]);
|
||||||
|
p1[0] = x[in + 1];
|
||||||
|
p1[1] = y[im] + dy;
|
||||||
add_linseg(ls, &lsnum, &lscnt, &p0, &p1);
|
add_linseg(ls, &lsnum, &lscnt, &p0, &p1);
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
p0[0] = (double) in + 0.5;
|
dx = (lev - z[i]) / (z[i+1] - z[i]);
|
||||||
p0[1] = (double) im;
|
p0[0] = (double) in + dx;
|
||||||
p1[0] = (double) in + 0.5;
|
p0[1] = y[im];
|
||||||
p1[1] = (double) im + 1.0;
|
p1[0] = (double) in + dx;
|
||||||
|
p1[1] = y[im + 1];
|
||||||
add_linseg(ls, &lsnum, &lscnt, &p0, &p1);
|
add_linseg(ls, &lsnum, &lscnt, &p0, &p1);
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
p0[0] = (double) in;
|
dy = (lev - z[i]) / (z[i+n] - z[i]);
|
||||||
p0[1] = (double) im + 0.5;
|
p0[0] = x[in];
|
||||||
p1[0] = (double) in + 0.5;
|
p0[1] = y[im] + dy;
|
||||||
p1[1] = (double) im + 1.0;
|
dx = (lev - z[i+n]) / (z[i+n+1] - z[i+n]);
|
||||||
|
p1[0] = x[in] + dx;
|
||||||
|
p1[1] = y[im + 1];
|
||||||
add_linseg(ls, &lsnum, &lscnt, &p0, &p1);
|
add_linseg(ls, &lsnum, &lscnt, &p0, &p1);
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
|
@ -97,10 +126,12 @@ int linseg_create(int* z, int n, int m, linseg_t** ls, int* sz)
|
||||||
case 7:
|
case 7:
|
||||||
break;
|
break;
|
||||||
case 8:
|
case 8:
|
||||||
p0[0] = (double) in;
|
dy = (lev - z[i]) / (z[i+n] - z[i]);
|
||||||
p0[1] = (double) im + 0.5;
|
p0[0] = x[in];
|
||||||
p1[0] = (double) in + 0.5;
|
p0[1] = y[im] + dy;
|
||||||
p1[1] = (double) im;
|
dx = (lev - z[i]) / (z[i+1] - z[i]);
|
||||||
|
p1[0] = x[in] + dx;
|
||||||
|
p1[1] = y[im];
|
||||||
add_linseg(ls, &lsnum, &lscnt, &p0, &p1);
|
add_linseg(ls, &lsnum, &lscnt, &p0, &p1);
|
||||||
break;
|
break;
|
||||||
case 9:
|
case 9:
|
||||||
|
@ -108,10 +139,12 @@ int linseg_create(int* z, int n, int m, linseg_t** ls, int* sz)
|
||||||
case 10:
|
case 10:
|
||||||
break;
|
break;
|
||||||
case 12:
|
case 12:
|
||||||
p0[0] = (double) in + 0.5;
|
dx = (lev - z[i]) / (z[i+1] - z[i]);
|
||||||
p0[1] = (double) im;
|
p0[0] = x[in] + dx;
|
||||||
p1[0] = (double) in + 0.5;
|
p0[1] = y[im];
|
||||||
p1[1] = (double) im + 1.0;
|
|
||||||
|
p1[0] = x[in] + dx;
|
||||||
|
p1[1] = y[im+1];
|
||||||
add_linseg(ls, &lsnum, &lscnt, &p0, &p1);
|
add_linseg(ls, &lsnum, &lscnt, &p0, &p1);
|
||||||
break;
|
break;
|
||||||
case 13:
|
case 13:
|
||||||
|
@ -129,8 +162,6 @@ int linseg_create(int* z, int n, int m, linseg_t** ls, int* sz)
|
||||||
}
|
}
|
||||||
*ls = (linseg_t*)realloc(*ls, lscnt * sizeof(linseg_t));
|
*ls = (linseg_t*)realloc(*ls, lscnt * sizeof(linseg_t));
|
||||||
*sz = lscnt;
|
*sz = lscnt;
|
||||||
|
|
||||||
|
|
||||||
return RES_OK;
|
return RES_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,12 +173,14 @@ int main(int argc, char* argv[])
|
||||||
0 0 0 0];
|
0 0 0 0];
|
||||||
in array a by columns
|
in array a by columns
|
||||||
*/
|
*/
|
||||||
int z[N*M] = { 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0};
|
double z[N*M] = { 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0};
|
||||||
linseg_t *ls = NULL;
|
double x[N] = {0.0, 1.0, 2.0};
|
||||||
|
double y[M] = {0.0, 1.0, 2.0, 3.0};
|
||||||
|
linseg_t *ls = NULL;
|
||||||
int nls, i;
|
int nls, i;
|
||||||
|
|
||||||
linseg_create(z, N, M, &ls, &nls);
|
linseg_create(z, x, y, N, M, 0.1, &ls, &nls);
|
||||||
for(i =0; i< nls; i++)
|
for(i =0; i< nls; i++)
|
||||||
printf("%d, [%.1f %.1f] -- [%.1f %.1f]\n", i, ls[i][0][0], ls[i][0][1], ls[i][1][0], ls[i][1][1]);
|
printf("%d, [%.1f %.1f] -- [%.1f %.1f]\n", i, ls[i].p[0][0], ls[i].p[0][1], ls[i].p[1][0], ls[i].p[1][1]);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Ładowanie…
Reference in New Issue