diff --git a/.gitignore b/.gitignore index 7af1263b9e4268725f8468ad196934385982c214..23a71970bac08314e394b6fc9f8faffaec2e7202 100644 --- a/.gitignore +++ b/.gitignore @@ -16,4 +16,5 @@ /.project /src/delaunay.html /src/perf.data -/src/xyz \ No newline at end of file +/src/xyz +/tests/ diff --git a/src/delaunay.h b/src/delaunay.h index 66092a8c11c30c39a3cc8f696caeda692d653e4c..8dff37d376d7111218ee75fbff06b5c885517c61 100644 --- a/src/delaunay.h +++ b/src/delaunay.h @@ -23,11 +23,11 @@ vertex vector(vertex, vertex); double distance(vertex, vertex); void printPoint(vertex); void delaunayCws(vertex*, int); -void drawPoints(vertex*, int); void write_ppm(const char*); void clockwiseNextDelaunayEdge(int *p, int *q, int *r, vertex *S, int *size, int *right); int firstDelaunayEdgeIncidentTo(int j, vertex* S, int size); char* vertexToString(vertex); circle circleFrom3Points(vertex, vertex, vertex); +void circleCenter(const vertex*, const vertex*, const vertex*, vertex*); #endif /* SRC_DELAUNAY_H_ */ diff --git a/src/dwyer.c b/src/dwyer.c index d030ff13baf064ff727709786c359b100f65e2cc..4b09b2042bb7d2062ea6c132f9b75111b84f0a56 100644 --- a/src/dwyer.c +++ b/src/dwyer.c @@ -1,4 +1,4 @@ -#define POSTSCRIPT +//#define POSTSCRIPT /****************************************************************/ /* DELAUNAY TRIANGULATION /* VORONOI DIAGRAM @@ -537,7 +537,7 @@ plot_site(v) VERTEX_PTR v; { printf("p%d drawsite\n", v); #endif #ifdef OUTPUTFILE - svgDrawSite(va[v].v); + //svgDrawSite(va[v].v); #endif } @@ -1151,7 +1151,6 @@ double xx, yy, curmax; /* Parse command line. */ -prog = 'm'; if ((prog == 'd') || (prog == 'g')) { /* plot_dt_construction = (n<=342) */ @@ -1219,8 +1218,8 @@ printf("[ ] 0 setdash\n"); for (i=1; i<=n; i++) { printf("/p%0d {%lf %lf} def ", i, X(i), Y(i)); plot_site(i); -#endif } +#endif switch (prog) { case 'm': diff --git a/src/helper.c b/src/helper.c index 2727e38ef10e97d382af656c294d2a8f262d08fc..60470b17b9a6795bd37fefb2a6dd79630e5aa12b 100644 --- a/src/helper.c +++ b/src/helper.c @@ -29,7 +29,7 @@ void svgDrawTriangle(vertex a, vertex b, vertex c) { void svgDrawSite(vertex v) { #ifdef OUTPUTFILE - fprintf(out, "<circle cx=\"%f\" cy=\"%f\" r=\"%f\" stroke=\"black\" stroke-width=\"1\" fill=\"black\" />", v.x*W, v.y*H, 2.0); + fprintf(out, "<circle cx=\"%lf\" cy=\"%lf\" r=\"%lf\" stroke=\"black\" stroke-width=\"1\" fill=\"black\" />", v.x*W, v.y*H, 2.0); #endif } @@ -45,3 +45,12 @@ void writeSvgEnd () { #endif } + +void drawSites(vertex *v, int n){ +#ifdef OUTPUTFILE + for(int i = 0; i < n; i++) { + svgDrawSite(v[i]); + } +#endif +} + diff --git a/src/helper.h b/src/helper.h index 3264a3c696bc09d8f2dafd9501050e7bf199e0e7..867de7226a59760d520e9534ffa6c99ff7b8a0a6 100644 --- a/src/helper.h +++ b/src/helper.h @@ -12,8 +12,8 @@ #include <stdio.h> -#define W 2000 -#define H 2000 +#define W 1500 +#define H 1500 #ifdef OUTPUTFILE FILE *out; @@ -36,5 +36,6 @@ void svgDrawLine(vertex, vertex); void svgDrawCircle(circle); void svgDrawTriangle(vertex, vertex, vertex); void svgDrawSite(vertex); +void drawSites(vertex*, int); #endif /* HELPER_H_ */ diff --git a/src/main.c b/src/main.c index 49640866c62e4b74cae63ba6b4bd0e6ecb24da19..3b42476a722c1c6e0c52130fa84b867ad95b5228 100644 --- a/src/main.c +++ b/src/main.c @@ -7,53 +7,68 @@ #include "main.h" - - +/** + * 1. function a=cws_delaunay b=cws_voronoi c=dwyer delaunay d=dwyer voronoi + * 2. f if a file is used; g if sites should be generated + * 3. if f: filelocation/filename; if g: number of sites to be generated + * 4. number of executions + * @param argc should be 5 + * @param argv parameters + * @return + */ int main(int argc, char *argv[]) { - //input: 1. function 0=cws_delaunay 2. # of points, 3. # of executions - //create_image(); - //write_ppm ( "sine.ppm" ); - int numberOfPoints = 10000; - int function = 0; + //input: 1. function a=cws_delaunay b=cws 2. # of points, 3. # of executions + int size; + char *function; int executions = 1; - if(argc > 0) { - //printf("%s\n", argv[0]); + char *file; + vertex *points; + if(argc != 5) { + fprintf(stderr, "Input should have 5 Arguments."); + exit(EXIT_FAILURE); } - //printf("%d\n", argc); - if(argc == 2) { - //printf("%s\n", argv[1]); - //numberOfPoints = atoi(argv[1]); + + //function = argv[0]; + if(argv[2][0] == 'f'){ + file = argv[3]; + readFile(file, &points, &size); + } else if(argv[2][0] == 'g') { + size = atoi(argv[3]); + points = malloc(size * sizeof(vertex)); + generatePoints(points, size); } + executions = atoi(argv[4]); - vertex *points = malloc(numberOfPoints * sizeof(vertex)); - generatePoints(points, numberOfPoints); - printf("%lu\n", numberOfPoints * sizeof(vertex)); - //drawPoints(points, numberOfPoints); + printf("%lu\n", size * sizeof(vertex)); #ifdef OUTPUTFILE out = fopen ( OUTPUTFILE, "w" ); writeSvgStart ( out ); + drawSites(points, size); #endif clock_t begin = clock(); - switch(function){ - case 0: + switch(argv[1][0]){ + case 'a': for(int i = 0; i < executions; i++) { - delaunayCws(points, numberOfPoints); + delaunayCws(points, size); } break; - case 1: + case 'b': for(int i = 0; i < executions; i++) { - voronoiCws(points, numberOfPoints); + voronoiCws(points, size); } break; - case 2: - printf("test\n"); - fflush(stdout); + case 'c': for(int i = 0; i < executions; i++) { - dwyer('m', points, numberOfPoints); + dwyer('m', points, size); + } + break; + case 'd': + for(int i = 0; i < executions; i++) { + dwyer('v', points, size); } break; default: @@ -87,17 +102,23 @@ void generatePoints(vertex* points, int size) { } } - -void readFile(char* file, vertex* v, int size){ +void readFile(char *file, vertex **v, int *size){ FILE *f; f=fopen(file,"rt"); if(f == NULL) { fprintf(stderr, "No such file: %s\n", file); - return; + exit(EXIT_FAILURE); + } + if(fscanf(f, "%d\n", size) != 1){ + fprintf(stderr, "Number of sites not specified in %s\n", file); + exit(EXIT_FAILURE); } - for(int i = 0; i < size && fscanf(f, "%lf %lf", &v[i].x, &v[i].y) == 2; i++){ - printf("%f %f\n", v[i].x, v[i].y); + *v = malloc(*size * sizeof(vertex)); + printf("Number of Points: %d\n", *size); + int i; + for(i = 0; i < *size && fscanf(f, "%lf %lf\n", &(*v)[i].x, &(*v)[i].y) == 2; i++); + if(i != *size) { + fprintf(stderr, "Number of sites specified in %s does not match with the actual number of points\n", file); } - fflush(stdout); fclose(f); } diff --git a/src/main.h b/src/main.h index 0c72aa2720483e0a8e244375088c6137ce094e17..7425128744ea8384cdbc7564d53afe325301a94d 100644 --- a/src/main.h +++ b/src/main.h @@ -19,7 +19,7 @@ */ void generatePoints(vertex* v, int size); -void readFile(char* file, vertex* v, int size); +void readFile(char *file, vertex **v, int *size); #endif /* MAIN_H_ */ diff --git a/src/voronoi.c b/src/voronoi.c index 15bafae9de32c9dc458d174b500c0a09ad234927..e85ba99a4b3622ec3882a4232a4ca9ada06e892a 100644 --- a/src/voronoi.c +++ b/src/voronoi.c @@ -84,7 +84,7 @@ void voronoiCws(vertex* S, int size) { clockwiseNextDelaunayEdge(&i, &j, &k, S, &size, &isTriangle); if(isTriangle == 2) { //currentV = vertexCircle2vertex((vertexCircle){S[i], S[j], S[k]}); - circleCenter(S[i], S[j], S[k], currentV); + circleCenter(&S[i], &S[j], &S[k], ¤tV); if(first) { first = 0; firstV = currentV;