/*glut keyboard function*/ void keyboard(unsigned char key, int x, int y) { switch (key) { case 0x1B: case'q': case 'Q': exit(0); break; case 'n': case 'N': create_vertex(); break; case 'h': case 'H': printarr(); break; case 'c': case 'C': quick_hull(); break; case 't': case 'T': quickHull_Top(allPoints[findMin()],allPoints[findMax()]); break; case 'b': case 'B': quickHull_Bottom(allPoints[findMin()],allPoints[findMax()]); break; case 'p': case 'P': quick_hull_peel(); break; case 'k': case 'K': display_hull(); break; case 'r': case 'R': reset(); break; } }//keyboard
MainWindow::MainWindow(QWidget *parent): QMainWindow(parent) { setupUi(this); /* the structure of the main window's central widget *---------------------------------------------------* | central widget | | | | *---------------------------*-----------------* | | | rendering context | scroll area | | | | OpenGL widget | *-------------* | | | | | | side widget | | | | | | | | | | | | | | | | | | | | *-------------* | | | *---------------------------*-----------------* | | | *---------------------------------------------------* */ _side_widget = new SideWidget(this); _scroll_area = new QScrollArea(this); _scroll_area->setWidget(_side_widget); _scroll_area->setSizePolicy(_side_widget->sizePolicy()); _scroll_area->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); _gl_widget = new GLWidget(this); _layout = new QHBoxLayout(); _layout->addWidget(_gl_widget); _layout->addWidget(_scroll_area); _central_widget = new QWidget(this); _central_widget->setLayout(_layout); setCentralWidget(_central_widget); // creating a signal slot mechanism between the rendering context and the side widget connect(_side_widget->rotate_x_slider, SIGNAL(valueChanged(int)), _gl_widget, SLOT(set_angle_x(int))); connect(_side_widget->rotate_y_slider, SIGNAL(valueChanged(int)), _gl_widget, SLOT(set_angle_y(int))); connect(_side_widget->rotate_z_slider, SIGNAL(valueChanged(int)), _gl_widget, SLOT(set_angle_z(int))); connect(_side_widget->zoom_factor_spin_box, SIGNAL(valueChanged(double)), _gl_widget, SLOT(set_zoom_factor(double))); connect(_side_widget->trans_x_spin_box, SIGNAL(valueChanged(double)), _gl_widget, SLOT(set_trans_x(double))); connect(_side_widget->trans_y_spin_box, SIGNAL(valueChanged(double)), _gl_widget, SLOT(set_trans_y(double))); connect(_side_widget->trans_z_spin_box, SIGNAL(valueChanged(double)), _gl_widget, SLOT(set_trans_z(double))); connect(_side_widget->loadButton, SIGNAL(clicked()), _gl_widget, SLOT(loadPointCloud())); connect(_side_widget->slowButton, SIGNAL(clicked()), _gl_widget, SLOT(slowConvexHull())); connect(_side_widget->quick_hull_button, SIGNAL(clicked()), _gl_widget, SLOT(quick_hull())); connect(_side_widget->fast_hull_button, SIGNAL(clicked()), _gl_widget, SLOT(fast_hull())); connect(_side_widget->load_model_button, SIGNAL(clicked()), _gl_widget, SLOT(load_model())); connect(_gl_widget, SIGNAL(show_volume(double)), this, SLOT(show_volume(double))); connect(_side_widget->load_polygon, SIGNAL(clicked()), _gl_widget, SLOT(load_polygon())); connect(_side_widget->load_3d_button, SIGNAL(clicked()), _gl_widget, SLOT(load_3d())); connect(_side_widget->convex_3d_button, SIGNAL(clicked()), _gl_widget, SLOT(convex_3d())); connect(_side_widget->step_button, SIGNAL(clicked()), _gl_widget, SLOT(step_convex())); }
int main(int argc, char* argv[]) { int do_single_run; if(argc == 2) do_single_run = atoi(argv[1]); else if(argc == 1) do_single_run = 0; else { std::cout << "Invalid number of args." << std::endl; return -1; } if(do_single_run == 1) { number_of_points = 10; std::vector<Coordinate> points; points.reserve(number_of_points); std::vector<Coordinate> hull_points; // Random number generator std::mt19937 mersenne_twister(std::chrono::high_resolution_clock::now().time_since_epoch().count()); // Generate random points for (int i = 0; i < number_of_points; ++i) { Coordinate pt; pt.x = (float)(mersenne_twister() % 1000); pt.y = (float)(mersenne_twister() % 1000); points.push_back(pt); } // Find the time take for algorithm srand(time(NULL)); clock_t start, end; std::sort(points.begin(), points.end()); start = clock(); quick_hull(points, hull_points); end = clock(); // Save all points to a file { FILE *fp = fopen("points.csv", "w"); for (const auto &pt : points) { fprintf(fp, "%.1f,%.1f\n", pt.x, pt.y); } fclose(fp); } // Save only convex hull points { FILE *fp = fopen("hull.csv", "w"); for (const auto &pt : hull_points) { fprintf(fp, "%.1f,%.1f\n", pt.x, pt.y); } fclose(fp); } std::cout << "Time Taken(" << number_of_points << "): " << clock_time(start,end) << TIME_UNIT << std::endl; return 0; } std::ofstream my_file; my_file.open("convex_hull_results.csv"); my_file << "No. of Points,Time (" << TIME_UNIT << ")" << std::endl; std::cout << "Generating..." << std::endl; while(number_of_points <= FINAL_SIZE) { std::cout << " " << number_of_points << std::endl; std::vector<Coordinate> points; points.reserve(number_of_points); std::vector<Coordinate> hull_points; // Random number generator std::mt19937 mersenne_twister(std::chrono::high_resolution_clock::now().time_since_epoch().count()); // Generate random points for (int i = 0; i < number_of_points; ++i) { Coordinate pt; pt.x = (float)(mersenne_twister() % 1000); pt.y = (float)(mersenne_twister() % 1000); points.push_back(pt); } // Find the time take for algorithm srand(time(NULL)); clock_t start, end; std::sort(points.begin(), points.end()); start = clock(); quick_hull(points, hull_points); end = clock(); my_file << number_of_points << "," << clock_time(start,end) << std::endl; number_of_points += INCREMENT; } my_file.close(); return 0; }