#include // cin, cout #include // strcmp #include #include // TODO: replace vector in Display with list for easier insertion! #include // timings #include "Display.h" #include "NumberGenerator.h" #include "Point.h" #include "Quickhull.h" std::list randomPoints (const std::string &fileRnd, const int valCount, const int rngMode) { if (fileRnd.empty() == false) // read random numbers { std::cout << "reading random numbers from file: " << fileRnd << "..." << std::endl; return NumberGenerator::read_numbers(fileRnd); } else // generate random numbers { std::cout << "generating " << valCount << " random numbers for mode " << rngMode << "..." << std::endl; return NumberGenerator::generate_numbers(valCount, rngMode); } } int main (int argc, char **argv) { // read program arguments // -v mode with enabled visualization // -akl using Akl-Toussaint heuristic beforehand // https://en.wikipedia.org/wiki/Convex_hull_algorithms#Akl%E2%80%93Toussaint_heuristic // -f read random numbers from file // -rngCount generates count random float values // -rngMode if generating float values this specifies the mode: // 1. random numbers in screen range // 2. numbers are ordered as rectangle // 3. numbers are ordered as circle around screen center // -runs runs performance mode multiple times // -stepsize time between autosteps; if 0 or not provided -> manual steps // TODO: care a little more <3 bool vis = false; bool akl = false; std::string fileRnd = ""; int valCount = 10; int rngMode = 1; int runs = 1; int stepSize = 0; for (int i = 0; i < argc; ++i) { if (strcmp(argv[i], "-v") == 0) vis = true; else if (strcmp(argv[i], "--akl") == 0) akl = true; else if (strcmp(argv[i], "-f") == 0) fileRnd = argv[i + 1]; else if (strcmp(argv[i], "--rngcount") == 0) valCount = std::stoi(argv[i + 1]); else if (strcmp(argv[i], "--rngmode") == 0) rngMode = std::stoi(argv[i + 1]); else if (strcmp(argv[i], "--runs") == 0) runs = std::stoi(argv[i + 1]); else if (strcmp(argv[i], "--stepsize") == 0) stepSize = std::stoi(argv[i + 1]); } std::list points = randomPoints(fileRnd, valCount, rngMode); #ifdef _DEBUG for (Point& pt : points) { std::cout << "pt: " << pt.x() << ", " << pt.y() << std::endl; } #endif // TEST to check SFML coordinate system //points.push_back(Point(0, 0)); if (vis) { // TODO: replace implementation to use list instead of vector std::vector v_points; for (Point const& pt : points) { v_points.push_back(pt); } Display display(v_points, stepSize, akl); display.show(); } else { std::list hull; std::chrono::duration total; auto start2 = std::chrono::high_resolution_clock::now(); // TODO: remove, just for comparison for (int i = 0; i < runs; ++i) { std::cout << "running quickhull perf mode " << (i + 1) << " of " << runs << "..." << std::endl; auto start = std::chrono::high_resolution_clock::now(); Quickhull::get_hull(points, hull, akl); auto diff = std::chrono::duration(std::chrono::high_resolution_clock::now() - start); total += diff; std::cout << "diff: " << diff.count() << "ms" << std::endl; if (i < runs - 1) { points = randomPoints(fileRnd, valCount, rngMode); } else { // --------------------------------------------------------------- // TODO: remove, just for comparison auto diff2 = std::chrono::duration(std::chrono::high_resolution_clock::now() - start2); std::cout << "total time spent: " << diff2.count() << "ms" << std::endl; // --------------------------------------------------------------- std::cout << "average time spent: " << total.count()/runs << "ms" << std::endl; Quickhull::show(points, hull); } } } return 0; }