modified: examples/src/contour_test.c

master
Dsplib 2023-12-18 22:45:44 +03:00
rodzic 35d01e6acc
commit 6726287f55
1 zmienionych plików z 291 dodań i 283 usunięć

Wyświetl plik

@ -5,10 +5,8 @@
#define N 3
#define M 4
#define BSIZE 256
typedef double point2d_t[2];
typedef struct
@ -207,12 +205,12 @@ double dist(point2d_t* p0, point2d_t* p1)
int line_create(linseg_t *ls, int nls, point2d_t** line, int* np)
int line_create(linseg_t* ls, int nls, point2d_t** line, int* np)
{
int i, j, c, n;
if(!line || !ls || !np)
return ERROR_PTR;
// printf("*line = %x, *np = %d \n", *line, *np);
i = 0;
while(!(ls[i].flag) && i < nls)
i++;
@ -221,7 +219,9 @@ int line_create(linseg_t *ls, int nls, point2d_t** line, int* np)
*np = 0;
return RES_OK;
}
//printf("i = %d, ls[%d] = [%.1f %.1f] -- [%.1f, %.1f]\n",
// i, i, ls[i].p[0][0], ls[i].p[0][1],
// ls[i].p[1][0], ls[i].p[1][1]);
n = BSIZE;
if((*line) == NULL)
(*line) = (point2d_t*)malloc(n*sizeof(point2d_t));
@ -235,7 +235,7 @@ int line_create(linseg_t *ls, int nls, point2d_t** line, int* np)
(*line)[c][0] = ls[i].p[1][0];
(*line)[c][1] = ls[i].p[1][1];
c++;
ls[0].flag = 0;
ls[i].flag = 0;
for(i = 0; i < nls; i++)
{
@ -246,6 +246,8 @@ int line_create(linseg_t *ls, int nls, point2d_t** line, int* np)
//сравниваем с первой точкой отрезка ls[j]
if(dist((*line)+c-1, ls[j].p) < 1E-8)
{
// printf("c0 = %d, j0 = %d\n", c, j);
// проверяем выделение памяти.
// при необходимости увеличиваем
if(c>=n)
@ -266,6 +268,8 @@ int line_create(linseg_t *ls, int nls, point2d_t** line, int* np)
//сравниваем со второй точкой отрезка ls[j]
if(dist((*line)+c-1, ls[j].p+1) < 1E-8)
{
// printf("c1 = %d, j1 = %d\n", c, j);
// проверяем выделение памяти.
// при необходимости увеличиваем
if(c>=n)
@ -283,8 +287,6 @@ int line_create(linseg_t *ls, int nls, point2d_t** line, int* np)
}
}
}
(*line) = (point2d_t*)realloc((*line), c*sizeof(point2d_t));
*np = c;
@ -292,40 +294,46 @@ int line_create(linseg_t *ls, int nls, point2d_t** line, int* np)
}
int main(int argc, char* argv[])
{
/* Matrix
z = [ 0 0 0 0;
z = [ 0 0 1 0;
0 1 1 0;
0 0 0 0];
in array a by columns
*/
double z[N*M] = { 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0};
double z[N*M] = { 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0};
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, j;
point2d_t** line = NULL;
int *np = NULL;
line = (point2d_t**)malloc(10*sizeof(point2d_t*));
memset(line,0,10*sizeof(point2d_t*));
np = (int*)malloc(10*sizeof(int));
memset(np, 0, 10*sizeof(int));
linseg_create(z, x, y, N, M, 0.1, &ls, &nls);
linseg_create(z, x, y, N, M, 0.5, &ls, &nls);
for(i =0; i< nls; i++)
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]);
line_create(ls, nls, line, np);
for(i =0; i< np[0]; i++)
printf("%[%.1f %.1f] -- ", line[0][i][0], line[0][i][1]);
printf("\n");
line_create(ls, nls, line+1, np+1);
for(i =0; i< np[1]; i++)
printf("%[%.1f %.1f] -- ", line[1][i][0], line[1][i][1]);
i = -1;
do
{
i++;
line_create(ls, nls, line+i, np);
for(j =0; j< np[i]; j++)
printf("%[%.1f %.1f] -- ", line[i][j][0], line[i][j][1]);
printf("\n");
}while(np[i]);
return 0;
}