diff --git a/Polyhedron/demo/Polyhedron/Plugins/Point_set/CMakeLists.txt b/Polyhedron/demo/Polyhedron/Plugins/Point_set/CMakeLists.txt index df97b278ef6..888168aba6b 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/Point_set/CMakeLists.txt +++ b/Polyhedron/demo/Polyhedron/Plugins/Point_set/CMakeLists.txt @@ -22,6 +22,16 @@ if(EIGEN3_FOUND) polyhedron_demo_plugin(point_set_shape_detection_plugin Point_set_shape_detection_plugin ${point_set_shape_detectionUI_FILES} KEYWORDS PointSetProcessing Classification) target_link_libraries(point_set_shape_detection_plugin PUBLIC scene_surface_mesh_item scene_points_with_normal_item scene_polygon_soup_item scene_callback_signaler) + find_package(OpenGR) + if (OpenGR_FOUND) + include_directories(SYSTEM ${OpenGR_INCLUDE_DIR}) + polyhedron_demo_plugin(register_point_sets_plugin Register_point_sets_plugin) + target_link_libraries(register_point_sets_plugin PUBLIC scene_points_with_normal_item) + else() + message(STATUS "NOTICE: registration plugin requires OpenGR, and will not be compiled.") + endif() + + else(EIGEN3_FOUND) message(STATUS "NOTICE: Eigen 3.1 (or greater) was not found. Surface reconstruction plugin will not be available.") message(STATUS "NOTICE: Eigen 3.1 (or greater) was not found. Normal estimation plugins will not be available.") diff --git a/Polyhedron/demo/Polyhedron/Plugins/Point_set/Register_point_sets_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/Point_set/Register_point_sets_plugin.cpp new file mode 100644 index 00000000000..a728ddba123 --- /dev/null +++ b/Polyhedron/demo/Polyhedron/Plugins/Point_set/Register_point_sets_plugin.cpp @@ -0,0 +1,164 @@ +#include "config.h" +#include "Scene_points_with_normal_item.h" +#include +#include + +#define CGAL_OPENGR_VERBOSE +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + + +using namespace CGAL::Three; +class Polyhedron_demo_register_point_sets_plugin : + public QObject, + public Polyhedron_demo_plugin_helper +{ + Q_OBJECT + Q_INTERFACES(CGAL::Three::Polyhedron_demo_plugin_interface) + Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.PluginInterface/1.0") + +private: + QAction* actionRegisterPointSets; + +public: + void init(QMainWindow* mainWindow, CGAL::Three::Scene_interface* scene_interface, Messages_interface*) { + scene = scene_interface; + mw = mainWindow; + actionRegisterPointSets = new QAction(tr("Register point sets"), mainWindow); + actionRegisterPointSets->setObjectName("actionRegisterPointSets"); + connect(actionRegisterPointSets, SIGNAL(triggered()), this, SLOT(on_actionRegisterPointSets_triggered())); + } + + QList actions() const { + return QList() << actionRegisterPointSets; + } + + bool applicable(QAction*) const { + return get_point_set_items().size() >= 2; + } + + std::vector get_point_set_items() const + { + std::vector items; + + Q_FOREACH(int index, scene->selectionIndices()) + { + Scene_points_with_normal_item* item = + qobject_cast(scene->item(index)); + if(item && item->point_set()->has_normal_map()) + items.push_back (item); + } + + return items; + } + +public Q_SLOTS: + void on_actionRegisterPointSets_triggered(); +private : + Scene_interface *scene; +}; // end Polyhedron_demo_register_point_sets_plugin + +void Polyhedron_demo_register_point_sets_plugin::on_actionRegisterPointSets_triggered() +{ + std::vector items = get_point_set_items(); + + QMultipleInputDialog dialog ("Register point sets", mw); + + QSpinBox* nb_samples = dialog.add("Number of samples:"); + nb_samples->setRange (3, 100000000); + nb_samples->setValue (200); + + QDoubleSpinBox* accuracy = dialog.add("Accuracy:"); + accuracy->setDecimals (5); + accuracy->setRange (0.00001, 100000.0); + accuracy->setValue (0.05); + accuracy->setSingleStep (0.1); + + QDoubleSpinBox* overlap = dialog.add("Overlap:"); + overlap->setDecimals (2); + overlap->setRange (0.01, 1.0); + overlap->setValue (0.2); + overlap->setSingleStep (0.1); + + QSpinBox* max_time = dialog.add("Maximum running time:"); + max_time->setRange (1, 36000); + max_time->setValue (60); + max_time->setSuffix (QString(" s")); + + dialog.add("Which point set is the reference? (others will be altered)"); + std::vector buttons; + for (std::size_t i = 0; i < items.size(); ++ i) + { + buttons.push_back (dialog.add (items[i]->name().toStdString().c_str())); + if (i == 0) + buttons.back()->setChecked(true); + } + + if (!dialog.exec()) + return; + + QApplication::setOverrideCursor(Qt::WaitCursor); + + std::size_t ref = 0; + for (std::size_t i = 0; i < items.size(); ++ i) + if (buttons[i]->isChecked()) + { + ref = i; + break; + } + + for (std::size_t i = 0; i < items.size(); ++ i) + { + if (i == ref) + continue; + + CGAL::Timer task_timer; task_timer.start(); + std::cerr << "Registering " << items[i]->name().toStdString() << " with " << items[ref]->name().toStdString() << std::endl; + + Point_set& ps1 = *(items[ref]->point_set()); + Point_set& ps2 = *(items[i]->point_set()); + + double score = + CGAL::OpenGR::register_point_sets(ps1, ps2, + CGAL::parameters::point_map(ps1.point_map()) + .normal_map(ps1.normal_map()) + .number_of_samples(nb_samples->value()) + .maximum_running_time(max_time->value()) + .accuracy(accuracy->value()) + .overlap(overlap->value()), + CGAL::parameters::point_map(ps2.point_map()) + .normal_map(ps2.normal_map())); + + std::size_t memory = CGAL::Memory_sizer().virtual_size(); + std::cerr << "Registration score: " << score << " (" + << task_timer.time() << " seconds, " + << (memory>>20) << " Mb allocated)" + << std::endl; + } + + for (std::size_t i = 0; i < items.size(); ++ i) + { + items[i]->invalidateOpenGLBuffers(); + scene->itemChanged(items[i]); + } + + QApplication::restoreOverrideCursor(); +} + + +#include "Register_point_sets_plugin.moc"