From cd8f9e9755cffb37a77d95437541d0364f6fd6c5 Mon Sep 17 00:00:00 2001 From: mika <mika@mika-ideacentre-Y710-Cube-15ISH> Date: Mon, 10 Dec 2018 19:57:14 +0100 Subject: [PATCH] some clean-up --- .gitignore | 4 ++ src/dwyer.c | 13 ++++-- src/helper.c | 4 +- src/helper.h | 7 ++- src/main.c | 126 ++++++++++++++++++++++++++++++++------------------ src/voronoi.c | 11 ----- src/voronoi.h | 38 +-------------- 7 files changed, 102 insertions(+), 101 deletions(-) diff --git a/.gitignore b/.gitignore index 23a7197..2604a44 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,7 @@ /src/perf.data /src/xyz /tests/ +/bla +/points +/testdata +/testdata2.csv diff --git a/src/dwyer.c b/src/dwyer.c index 1c5ec4f..a3b7039 100644 --- a/src/dwyer.c +++ b/src/dwyer.c @@ -1,4 +1,4 @@ -#define POSTSCRIPT +//#define POSTSCRIPT /****************************************************************/ /* DELAUNAY TRIANGULATION /* VORONOI DIAGRAM @@ -1203,14 +1203,12 @@ printf("[ ] 0 setdash\n"); vp[i] = i; NORM(i) = X(i)*X(i) + Y(i)*Y(i); } - free(sites); +// free(sites); n=i-1; vp[0] = 0; vp[n+1] = n+1; /* sentinals for sorting routines */ vpsortx(1,n); delete_all_edges(); - printf("test\n"); - fflush(stdout); if (prog == 'g') build_delaunay(vp, 1, n, &left, &right, n); else if (prog != 'c') @@ -1238,5 +1236,12 @@ printf("[ ] 0 setdash\n"); break; } } +free(va); +free(vp); +free(org); +free(len); +free(hq); +free(next); + return 0; } diff --git a/src/helper.c b/src/helper.c index e596ae8..18bfaa8 100644 --- a/src/helper.c +++ b/src/helper.c @@ -11,7 +11,7 @@ void svgDrawLine(vertex a, vertex b) { #ifdef OUTPUTFILE - fprintf(out, "<line vector-effect=\"non-scaling-stroke\" x1=\"%f\" y1=\"%f\" x2=\"%f\" y2=\"%f\" style=\"stroke:red;stroke-width:1\" />\n", a.x, a.y, b.x, b.y); + fprintf(out, "<line vector-effect=\"non-scaling-stroke\" x1=\"%f\" y1=\"%f\" x2=\"%f\" y2=\"%f\" style=\"stroke:blue;stroke-width:1\" />\n", a.x, a.y, b.x, b.y); #endif } @@ -23,7 +23,7 @@ void svgDrawCircle(circle c) { void svgDrawTriangle(vertex a, vertex b, vertex c) { #ifdef OUTPUTFILE - fprintf(out, "<polygon vector-effect=\"non-scaling-stroke\" points=\"%f,%f %f,%f %f,%f\" style=\"fill:none;stroke:purple;stroke-width:1\" />\n", a.x, a.y, b.x, b.y, c.x, c.y); + fprintf(out, "<polygon vector-effect=\"non-scaling-stroke\" points=\"%f,%f %f,%f %f,%f\" style=\"fill:none;stroke:black;stroke-width:1\" />\n", a.x, a.y, b.x, b.y, c.x, c.y); #endif } diff --git a/src/helper.h b/src/helper.h index 8513546..c9eafc8 100644 --- a/src/helper.h +++ b/src/helper.h @@ -8,6 +8,9 @@ #ifndef HELPER_H_ #define HELPER_H_ +/** + * use if you want to have an output + */ #define OUTPUTFILE "output.html" #include <stdio.h> @@ -19,8 +22,8 @@ double viewboxMinX; double viewboxMinY; double viewboxMaxX; double viewboxMaxY; -#define W 1000 -#define R .2 +#define W 400 //size of the svg-File +#define R 1.0 //Point size #endif diff --git a/src/main.c b/src/main.c index 6722441..21c658c 100644 --- a/src/main.c +++ b/src/main.c @@ -1,3 +1,13 @@ + +/** + * use if you want to use command line input + */ +#define INPUT + +/** + * used for doing the Runtimetest + */ +//#define RUNTIMETEST /* * main.c * @@ -8,27 +18,25 @@ #include "main.h" /** - * 1. function a=cws_delaunay b=cws_voronoi c=dwyer delaunay d=dwyer voronoi + * 1. function 0=cws_delaunay 1=cws_voronoi 2=dwyer delaunay 3=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 a=cws_delaunay b=cws 2. # of points, 3. # of executions int size; - char *function; - int executions = 1; - char *file; + int function; vertex *points; - if(argc != 5) { - fprintf(stderr, "Input should have 5 Arguments."); +#ifdef INPUT + char *file; + if(argc != 4) { + fprintf(stderr, "Input should have 4 Arguments."); exit(EXIT_FAILURE); } - //function = argv[0]; + function = atoi(argv[1]); if(argv[2][0] == 'f'){ file = argv[3]; readFile(file, &points, &size); @@ -36,73 +44,96 @@ int main(int argc, char *argv[]) { size = atoi(argv[3]); points = malloc(size * sizeof(vertex)); generatePoints(points, size); +#ifdef OUTPUTFILE viewboxMinX = 0; viewboxMinY = 0; viewboxMaxX = 1; viewboxMaxY = 1; +#endif } - executions = atoi(argv[4]); - +#endif - printf("%lu\n", size * sizeof(vertex)); #ifdef OUTPUTFILE out = fopen ( OUTPUTFILE, "w" ); writeSvgStart ( out ); - drawSites(points, size); +#endif +#ifdef RUNTIMETEST + size = 2; + int line = 2; + printf(",cwsdel,cwsvon,dwydel,dwyvon,\n"); + for(int k = 0; k < 18; k++) { + size *= 2; + printf("%d", size); + for(int i = 0; i < 10; i++) { + // vertex points[size]; + printf(","); + points = malloc(size * sizeof(vertex)); + generatePoints(points, size); + for(function = 0; function < 4; function++) { + clock_t begin = clock(); #endif - clock_t begin = clock(); - - switch(argv[1][0]){ - case 'a': - for(int i = 0; i < executions; i++) { - delaunayCws(points, size); - } + switch(function){ + case 0: + delaunayCws(points, size); break; - case 'b': - for(int i = 0; i < executions; i++) { - voronoiCws(points, size); - } + case 1: + voronoiCws(points, size); break; - case 'c': - for(int i = 0; i < executions; i++) { - dwyer('m', points, size); - } + case 2: + dwyer('m', points, size); break; - case 'd': - for(int i = 0; i < executions; i++) { - dwyer('v', points, size); - } + case 3: + dwyer('v', points, size); break; default: break; - } + } - clock_t end = clock(); +#ifdef RUNTIMETEST + clock_t end = clock(); + double number_of_clocks = (double) (end-begin); + double time_spent = (double)(end - begin) / CLOCKS_PER_SEC; -#ifdef OUTPUTFILE - writeSvgEnd ( out ); - fclose(out); + + printf("%f,", time_spent); + } + printf("\n"); + line++; + + free(points); + } + printf("average,=AVERAGE(B%d:B%d),=AVERAGE(C%d:C%d),=AVERAGE(D%d:D%d),=AVERAGE(E%d:E%d),\n", line-1, line-10, line-1, line-10, line-1, line-10, line-1, line-10); + printf("max,=MAX(B%d:B%d),=MAX(C%d:C%d),=MAX(D%d:D%d),=MAX(E%d:E%d),\n", line-1, line-10, line-1, line-10, line-1, line-10, line-1, line-10); + printf("min,=MIN(B%d:B%d),=MIN(C%d:C%d),=MIN(D%d:D%d),=MIN(E%d:E%d),\n", line-1, line-10, line-1, line-10, line-1, line-10, line-1, line-10); + line += 3; + + } #endif - double number_of_clocks = (double) (end-begin); - double time_spent = (double)(end - begin) / CLOCKS_PER_SEC; - printf("Number of clocks: %f\n", number_of_clocks); - printf("Time spent: %f\n", time_spent); + + + + + + +#ifdef OUTPUTFILE + drawSites(points, size); + writeSvgEnd ( out ); + fclose(out); +#endif + return EXIT_SUCCESS; } void generatePoints(vertex* points, int size) { - double x, y; int seed = time(NULL); srand(seed); for(int i = 0; i < size; i++) { - x = (double) rand()/RAND_MAX; - y = (double) rand()/RAND_MAX; - points[i] = (vertex) {x, y}; + points[i] = (vertex) {(double) rand()/RAND_MAX, (double) rand()/RAND_MAX}; } } @@ -120,11 +151,14 @@ void readFile(char *file, vertex **v, int *size){ *v = malloc(*size * sizeof(vertex)); printf("Number of Points: %d\n", *size); int i; +#ifdef OUTPUTFILE viewboxMinX = (*v)[0].x; viewboxMinY = (*v)[0].y; viewboxMaxX = (*v)[0].x; viewboxMaxY = (*v)[0].y; +#endif for(i = 0; i < *size && fscanf(f, "%lf, %lf\n", &(*v)[i].x, &(*v)[i].y) == 2; i++) { +#ifdef OUTPUTFILE if(i == 0){ viewboxMinX = (*v)[0].x; viewboxMinY = (*v)[0].y; @@ -141,7 +175,7 @@ void readFile(char *file, vertex **v, int *size){ } else if((*v)[i].y > viewboxMaxY) { viewboxMaxY = (*v)[i].y; } - printf("%f\n", viewboxMinX); +#endif } if(i != *size) { diff --git a/src/voronoi.c b/src/voronoi.c index e85ba99..14f5f55 100644 --- a/src/voronoi.c +++ b/src/voronoi.c @@ -8,22 +8,11 @@ #include "voronoi.h" -circle center(vertexCircle vc) { - - circle c = circleFrom3Points(vc.a, vc.b, vc.c); - return c; -} int reportEdge(vertex a, vertex b) { - //svgDrawCircle(a,out); - //svgDrawCircle(b,out); svgDrawLine(a, b); return 0; } -vertex vertexCircle2vertex(vertexCircle vc) { - vertex v = center(vc).center; - return v; -} /** * returns the vertex, that you get, when you go right from the center of a and b until you hit the border of the room, where the points are diff --git a/src/voronoi.h b/src/voronoi.h index 5f8a6a1..97538de 100644 --- a/src/voronoi.h +++ b/src/voronoi.h @@ -11,45 +11,11 @@ #include "delaunay.h" #include "helper.h" - -/** - * a vertex represented by a circle, where it is the center - */ -typedef struct { - vertex a; - vertex b; - vertex c; -} vertexCircle; - -//TODO better name -/** - * an edge represented by 2 vertexCircles - */ -typedef struct { - vertexCircle a; - vertexCircle b; -} edgeCircle; - -/** - * returns the first Voronoi vertex on the boundary of the Voronoi region associated with the point p e S - * @param point p e S - * @return the first Voronoi vertex on the boundary of the Voronoi region associated with p - */ -vertexCircle firstVoronoiVertexAssociatedWith(vertex p); - /** - * returns the next Voronoi edge incident to e.a, following e in the clockwise direction - * @param e - * @return + * use, if you want to Draw the dual Delaunay-Triangulation together with the Voronoi-Diagram */ -edgeCircle clockwiseNextVoronoiEdge(edgeCircle e); +//#define DEL -/** - * returns the Voronoi edge following e along the boundary of its Voronoi region - * @param e - * @return - */ -edgeCircle nextVoronoiEdgeOnBoudary(edgeCircle e); int reportEdge(vertex, vertex); -- GitLab