Skip to content
Snippets Groups Projects
Commit 143051af authored by mika's avatar mika
Browse files

inputhandling + fix readFile + drawPoints + fix voronoi_cws

parent a204593a
Branches
No related tags found
No related merge requests found
......@@ -16,4 +16,5 @@
/.project
/src/delaunay.html
/src/perf.data
/src/xyz
\ No newline at end of file
/src/xyz
/tests/
......@@ -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_ */
#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':
......
......@@ -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
}
......@@ -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_ */
......@@ -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);
}
......@@ -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_ */
......@@ -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], &currentV);
if(first) {
first = 0;
firstV = currentV;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment