quickhull/main.cpp

81 lines
2.8 KiB
C++

#include <iostream> // cin, cout
#include <cstring> // strcmp
#include <vector>
#include <list> // TODO: replace vector in Display with list for easier insertion!
#include "Display.h"
#include "NumberGenerator.h"
#include "Point.h"
#include "Quickhull.h"
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 <filename> read random numbers from file
// -rngCount <count> generates count random float values
// -rngMode <mode> 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
// -stepsize <size> time between autosteps; if 0 or not provided -> manual steps
// TODO: care a little more <3
int stepSize = 0;
int valCount = 100;
int rngMode = 1;
std::string fileRnd = "";
bool vis = false;
bool akl = false;
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], "--stepsize") == 0) stepSize = std::stoi(argv[i + 1]);
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]);
}
std::list<Point> points;
if (fileRnd.empty() == false) // read random numbers
{
std::cout << "reading random numbers from file: " << fileRnd << "..." << std::endl;
points = NumberGenerator::read_numbers(fileRnd);
}
else // generate random numbers
{
std::cout << "generating " << valCount << " random numbers for mode " << rngMode << "..." << std::endl;
points = NumberGenerator::generate_numbers(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<Point> v_points;
for (Point const& pt : points)
{
v_points.push_back(pt);
}
Display display(v_points, stepSize, akl);
display.show();
}
else
{
std::list<Point> hull;
Quickhull::run(points, hull, akl);
}
return 0;
}