/* main.c * * Created by Rory Healy (healyr@student.unimelb.edu.au) * Created on 25th August 2021 * Last modified 8th September 2021 * * Lists the watchtowers that are in each face of the polygon. * The polygon can be split using a pair of integers, which represent * the edge numbers that should be connected. This comes from stdin. * * To run the program type: * ./voronoi1 dataset_file polygon_file output_file < splits * * Options: * dataset_file required Path to the dataset file (CSV) * polygon_file required Path to the polygon file (txt) * output_file required Output solution file * splits optional Pairs of integers to split the edges * */ #ifndef DCEL_HEADER #include "dcel.h" #endif #ifndef COMMON_HEADER #include "common.h" #endif #ifndef VORONOI_HEADER #include "voronoi.h" #endif #ifndef INPUT_HEADER #include "input.h" #endif // int main(int argc, char **argv) { // /* Input and output files */ // FILE *datasetFile = NULL, *polygonFile = NULL, *outputFile = NULL; // checkInputArgs(argc, argv, &datasetFile, &polygonFile, &outputFile); // /* Stores information about the towers given in dataset file */ // tower_t **towers = malloc(sizeof(*towers)); // checkNullPointer(towers); // int numTowers = 0; // towers = readTowers(towers, datasetFile, &numTowers); // /* Stores information about the vertices in the polygon file */ // vertex_t **vertices = malloc(sizeof(*vertices)); // checkNullPointer(vertices); // int numVertices = 0; // vertices = readPolygon(vertices, polygonFile, &numVertices); // /* Create DCEL structure from vertices */ // /* Check for splits, split the polygon if needed */ // /* Counts towers in each polygon, outputs to outputFile */ // /* Cleaning up data */ // freeTowers(towers, numTowers); // freeVertices(vertices, numVertices); // fclose(datasetFile); // fclose(polygonFile); // fclose(outputFile); // return 0; // } int main(int argc, char **argv) { /* Ensure input arguments are correct */ enum stages stage = getStage(argv[1]); int expectedArgs = getExpectedArgs(stage); if (expectedArgs != argc) { printArgError(stage, "Incorrect number of inputs."); } /* Then run the program according to the stage given */ switch(stage) { /* Expected usage: ./voronoi2 1 pointsFile outputFile */ case STAGE_1: { FILE *pointsFile = NULL, *outputFile = NULL; pointsFile = safeFileOpen(&pointsFile, argv[2], "r"); outputFile = safeFileOpen(&outputFile, argv[3], "w"); fclose(pointsFile); fclose(outputFile); break; } /* Expected usage: ./voronoi2 2 pointsFile polygonFile outputFile */ case STAGE_2: { FILE *pointsFile = NULL, *polygonFile = NULL, *outputFile = NULL; pointsFile = safeFileOpen(&pointsFile, argv[2], "r"); polygonFile = safeFileOpen(&polygonFile, argv[3], "r"); outputFile = safeFileOpen(&outputFile, argv[4], "w"); fclose(pointsFile); fclose(polygonFile); fclose(outputFile); break; } /* Expected usage: ./voronoi2 3 dataFile polygonFile outputFile */ case STAGE_3: { FILE *dataFile = NULL, *polygonFile = NULL, *outputFile = NULL; dataFile = safeFileOpen(&dataFile, argv[2], "r"); polygonFile = safeFileOpen(&polygonFile, argv[3], "r"); outputFile = safeFileOpen(&outputFile, argv[4], "w"); fclose(dataFile); fclose(polygonFile); fclose(outputFile); break; } /* Expected usage: /voronoi2 4 dataFile polygonFile outputFile */ case STAGE_4: { FILE *dataFile = NULL, *polygonFile = NULL, *outputFile = NULL; dataFile = safeFileOpen(&dataFile, argv[2], "r"); polygonFile = safeFileOpen(&polygonFile, argv[3], "r"); outputFile = safeFileOpen(&outputFile, argv[4], "w"); fclose(dataFile); fclose(polygonFile); fclose(outputFile); break; } /* Return error if stage number isn't defined. */ case STAGE_ERROR: default: fprintf(stderr, "Stage was not handled ENUM value (%d)\n", stage); exit(EXIT_FAILURE); } return 0; }