kopia lustrzana https://github.com/Dsplib/libdspl-2.0
modified: examples/src/contour_test.c
rodzic
35d01e6acc
commit
6726287f55
|
@ -5,10 +5,8 @@
|
||||||
|
|
||||||
#define N 3
|
#define N 3
|
||||||
#define M 4
|
#define M 4
|
||||||
|
|
||||||
#define BSIZE 256
|
#define BSIZE 256
|
||||||
|
|
||||||
|
|
||||||
typedef double point2d_t[2];
|
typedef double point2d_t[2];
|
||||||
|
|
||||||
typedef struct
|
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;
|
int i, j, c, n;
|
||||||
if(!line || !ls || !np)
|
if(!line || !ls || !np)
|
||||||
return ERROR_PTR;
|
return ERROR_PTR;
|
||||||
|
// printf("*line = %x, *np = %d \n", *line, *np);
|
||||||
i = 0;
|
i = 0;
|
||||||
while(!(ls[i].flag) && i < nls)
|
while(!(ls[i].flag) && i < nls)
|
||||||
i++;
|
i++;
|
||||||
|
@ -221,7 +219,9 @@ int line_create(linseg_t *ls, int nls, point2d_t** line, int* np)
|
||||||
*np = 0;
|
*np = 0;
|
||||||
return RES_OK;
|
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;
|
n = BSIZE;
|
||||||
if((*line) == NULL)
|
if((*line) == NULL)
|
||||||
(*line) = (point2d_t*)malloc(n*sizeof(point2d_t));
|
(*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][0] = ls[i].p[1][0];
|
||||||
(*line)[c][1] = ls[i].p[1][1];
|
(*line)[c][1] = ls[i].p[1][1];
|
||||||
c++;
|
c++;
|
||||||
ls[0].flag = 0;
|
ls[i].flag = 0;
|
||||||
|
|
||||||
for(i = 0; i < nls; i++)
|
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]
|
//сравниваем с первой точкой отрезка ls[j]
|
||||||
if(dist((*line)+c-1, ls[j].p) < 1E-8)
|
if(dist((*line)+c-1, ls[j].p) < 1E-8)
|
||||||
{
|
{
|
||||||
|
// printf("c0 = %d, j0 = %d\n", c, j);
|
||||||
|
|
||||||
// проверяем выделение памяти.
|
// проверяем выделение памяти.
|
||||||
// при необходимости увеличиваем
|
// при необходимости увеличиваем
|
||||||
if(c>=n)
|
if(c>=n)
|
||||||
|
@ -266,6 +268,8 @@ int line_create(linseg_t *ls, int nls, point2d_t** line, int* np)
|
||||||
//сравниваем со второй точкой отрезка ls[j]
|
//сравниваем со второй точкой отрезка ls[j]
|
||||||
if(dist((*line)+c-1, ls[j].p+1) < 1E-8)
|
if(dist((*line)+c-1, ls[j].p+1) < 1E-8)
|
||||||
{
|
{
|
||||||
|
// printf("c1 = %d, j1 = %d\n", c, j);
|
||||||
|
|
||||||
// проверяем выделение памяти.
|
// проверяем выделение памяти.
|
||||||
// при необходимости увеличиваем
|
// при необходимости увеличиваем
|
||||||
if(c>=n)
|
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));
|
(*line) = (point2d_t*)realloc((*line), c*sizeof(point2d_t));
|
||||||
*np = c;
|
*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[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
/* Matrix
|
/* Matrix
|
||||||
z = [ 0 0 0 0;
|
z = [ 0 0 1 0;
|
||||||
0 1 1 0;
|
0 1 1 0;
|
||||||
0 0 0 0];
|
0 0 0 0];
|
||||||
in array a by columns
|
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 x[N] = {0.0, 1.0, 2.0};
|
||||||
double y[M] = {0.0, 1.0, 2.0, 3.0};
|
double y[M] = {0.0, 1.0, 2.0, 3.0};
|
||||||
linseg_t *ls = NULL;
|
linseg_t *ls = NULL;
|
||||||
int nls, i;
|
int nls, i, j;
|
||||||
point2d_t** line = NULL;
|
point2d_t** line = NULL;
|
||||||
int *np = NULL;
|
int *np = NULL;
|
||||||
|
|
||||||
line = (point2d_t**)malloc(10*sizeof(point2d_t*));
|
line = (point2d_t**)malloc(10*sizeof(point2d_t*));
|
||||||
memset(line,0,10*sizeof(point2d_t*));
|
memset(line,0,10*sizeof(point2d_t*));
|
||||||
|
|
||||||
np = (int*)malloc(10*sizeof(int));
|
np = (int*)malloc(10*sizeof(int));
|
||||||
memset(np, 0, 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++)
|
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]);
|
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);
|
i = -1;
|
||||||
for(i =0; i< np[0]; i++)
|
do
|
||||||
printf("%[%.1f %.1f] -- ", line[0][i][0], line[0][i][1]);
|
{
|
||||||
printf("\n");
|
i++;
|
||||||
line_create(ls, nls, line+1, np+1);
|
line_create(ls, nls, line+i, np);
|
||||||
for(i =0; i< np[1]; i++)
|
for(j =0; j< np[i]; j++)
|
||||||
printf("%[%.1f %.1f] -- ", line[1][i][0], line[1][i][1]);
|
printf("%[%.1f %.1f] -- ", line[i][j][0], line[i][j][1]);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
}while(np[i]);
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Ładowanie…
Reference in New Issue