diff --git a/Polyhedron/demo/Polyhedron/Mesh_segmentation_dialog.ui b/Polyhedron/demo/Polyhedron/Mesh_segmentation_dialog.ui index 127dd8ff69f..f015ce2f0fc 100644 --- a/Polyhedron/demo/Polyhedron/Mesh_segmentation_dialog.ui +++ b/Polyhedron/demo/Polyhedron/Mesh_segmentation_dialog.ui @@ -18,7 +18,7 @@ - Square root of number of rays: + Number of rays: Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter @@ -28,7 +28,7 @@ - 5 + 25 @@ -85,7 +85,7 @@ 0.500000000000000 - 15.500000000000000 + 23.000000000000000 diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_mesh_segmentation_plugin.cpp b/Polyhedron/demo/Polyhedron/Polyhedron_demo_mesh_segmentation_plugin.cpp index 22278ca5fb7..ecfd6deb4e4 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_mesh_segmentation_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_mesh_segmentation_plugin.cpp @@ -14,6 +14,7 @@ #include #include //#include +#include class Polyhedron_demo_mesh_segmentation_plugin : public QObject, @@ -36,8 +37,9 @@ public: connect(actionSegmentation, SIGNAL(triggered()),this, SLOT(on_actionSegmentation_triggered())); } } - - void colorize(CGAL::Surface_mesh_segmentation& segmentation, std::vector& color_vector, bool sdf); + + template + void colorize( Polyhedron* mesh, FacetValuePropertyMap facet_value_pmap, std::vector& color_vector, bool sdf); public slots: void on_actionSegmentation_triggered(); void on_Partition_button_clicked(); @@ -74,88 +76,84 @@ void Polyhedron_demo_mesh_segmentation_plugin::on_actionSegmentation_triggered() //} void Polyhedron_demo_mesh_segmentation_plugin::on_SDF_button_clicked() { - const Scene_interface::Item_id index = scene->mainSelectionIndex(); + Scene_interface::Item_id index = scene->mainSelectionIndex(); Scene_polyhedron_item* item = qobject_cast(scene->item(index)); Scene_polyhedron_with_color_item* item_colored = qobject_cast(scene->item(index)); if(!item && !item_colored) { return; } QApplication::setOverrideCursor(Qt::WaitCursor); - int number_of_rays_sqrt = ui_dialog->Number_of_rays_spin_box->value(); - double cone_angle = (ui_dialog->Cone_angle_spin_box->value() / 180.0) * CGAL_PI; - int number_of_clusters = ui_dialog->Number_of_clusters_spin_box->value(); + int number_of_rays = ui_dialog->Number_of_rays_spin_box->value(); + double cone_angle = (ui_dialog->Cone_angle_spin_box->value() / 180.0) * CGAL_PI; + typedef std::map< CGAL::Surface_mesh_segmentation::Facet_const_iterator, double> internal_map; + internal_map facet_value_map_internal; + boost::associative_property_map sdf_pmap(facet_value_map_internal); + CGAL::Surface_mesh_segmentation* segmentation = NULL; if(!item_colored) - { + { Polyhedron* pMesh = item->polyhedron(); item->setVisible(false); Scene_polyhedron_with_color_item* new_item = new Scene_polyhedron_with_color_item(*pMesh); + int index = 0; + for(Polyhedron::Facet_iterator facet_it = new_item->polyhedron()->facets_begin(); + facet_it != new_item->polyhedron()->facets_end(); ++facet_it) + { + facet_it->set_patch_id(index++); + } new_item->setName(tr("%1_segmented").arg(item->name())); std::vector color_vector; CGAL::Surface_mesh_segmentation* segmentation - = new CGAL::Surface_mesh_segmentation(new_item->polyhedron(), number_of_rays_sqrt, cone_angle, number_of_clusters); - segmentation->calculate_sdf_values(); + = new CGAL::Surface_mesh_segmentation(*new_item->polyhedron()); + segmentation->calculate_sdf_values(sdf_pmap, cone_angle, number_of_rays); + + colorize(new_item->polyhedron(), sdf_pmap, color_vector, true); - colorize(*segmentation, color_vector, true); new_item->set_color_vector(color_vector); new_item->segmentation = segmentation; Scene_interface::Item_id new_item_index = scene->addItem(new_item); scene->setSelectedItem(new_item_index); - scene->itemChanged(new_item_index); + scene->itemChanged(new_item_index); } else - { + { std::vector color_vector; CGAL::Surface_mesh_segmentation* segmentation = item_colored->segmentation; - if( segmentation->number_of_rays_sqrt != number_of_rays_sqrt || - segmentation->cone_angle != cone_angle) - { - segmentation->number_of_rays_sqrt = number_of_rays_sqrt; - segmentation->cone_angle = cone_angle; - // - //QFuture future = QtConcurrent::run(calculata_sdf_values, segmentation); - //while(!future.isFinished()) //should be event-base...not like busy-wait. - // ui_dialog->Sdf_value_calculation_bar->setValue(static_cast(segmentation->get_process_of_sdf_calculation() * 100)); - segmentation->calculate_sdf_values(); - //segmentation->apply_GMM_fitting_with_K_means_init(); - } - - colorize(*segmentation, color_vector, true); + + segmentation->calculate_sdf_values(sdf_pmap, cone_angle, number_of_rays); + + colorize(item_colored->polyhedron(), sdf_pmap, color_vector, true); item_colored->set_color_vector(color_vector); scene->itemChanged(index); - scene->setSelectedItem(index); + scene->setSelectedItem(index); } QApplication::restoreOverrideCursor(); } void Polyhedron_demo_mesh_segmentation_plugin::on_Partition_button_clicked() -{ - +{ const Scene_interface::Item_id index = scene->mainSelectionIndex(); Scene_polyhedron_with_color_item* item_colored = qobject_cast(scene->item(index)); if(!item_colored) { return; } QApplication::setOverrideCursor(Qt::WaitCursor); - int number_of_rays_sqrt = ui_dialog->Number_of_rays_spin_box->value(); - double cone_angle = (ui_dialog->Cone_angle_spin_box->value() / 180.0) * CGAL_PI; int number_of_clusters = ui_dialog->Number_of_clusters_spin_box->value(); double smoothness = ui_dialog->Smoothness_spin_box->value(); std::vector color_vector; CGAL::Surface_mesh_segmentation* segmentation = item_colored->segmentation; - segmentation->number_of_centers = number_of_clusters; - segmentation->apply_GMM_fitting_and_K_means(); - - segmentation->smoothing_lambda = smoothness; - segmentation->apply_graph_cut(); - segmentation->assign_segments(); + typedef std::map::Facet_const_iterator, int> internal_map; + internal_map facet_value_map_internal; + boost::associative_property_map partition_pmap(facet_value_map_internal); - colorize(*segmentation, color_vector, false); + segmentation->partition(partition_pmap, number_of_clusters, smoothness); + + colorize(item_colored->polyhedron(), partition_pmap, color_vector, false); item_colored->set_color_vector(color_vector); scene->itemChanged(index); scene->setSelectedItem(index); @@ -164,30 +162,28 @@ void Polyhedron_demo_mesh_segmentation_plugin::on_Partition_button_clicked() //qApp->processEvents(); } -void Polyhedron_demo_mesh_segmentation_plugin::colorize(CGAL::Surface_mesh_segmentation& segmentation, - std::vector& color_vector, bool sdf) +template +void Polyhedron_demo_mesh_segmentation_plugin::colorize( + Polyhedron* mesh, + FacetValuePropertyMap facet_value_pmap, + std::vector& color_vector, + bool sdf) { - QColor predefined_list[] = { Qt::red, Qt::darkRed, Qt::green, Qt::darkGreen, Qt::blue, Qt::darkBlue , Qt::cyan, Qt::darkCyan, Qt::magenta, Qt::darkMagenta, Qt::yellow, Qt::darkYellow, Qt::gray, Qt::darkGray, Qt::lightGray, Qt::white, Qt::black}; - - color_vector.reserve(segmentation.sdf_values.size()); - int findex = 0; - for(CGAL::Surface_mesh_segmentation::Facet_iterator facet_it = segmentation.mesh->facets_begin(); - facet_it != segmentation.mesh->facets_end(); ++facet_it, ++findex) + + for(Polyhedron::Facet_const_iterator facet_it = mesh->facets_begin(); + facet_it != mesh->facets_end(); ++facet_it) { - facet_it->set_patch_id(findex); - //int cluster_color = (int) (255.0 / segmentation.number_of_centers) * segmentation.centers[facet_it]; if(sdf) { - int sdf_color = (int) (255 * segmentation.sdf_values[facet_it]); + int sdf_color = static_cast(255.0 * boost::get(facet_value_pmap, facet_it)); color_vector.push_back(QColor(sdf_color,sdf_color,sdf_color)); } else { - color_vector.push_back(predefined_list[segmentation.segments[facet_it] % 17]); - } - + color_vector.push_back(predefined_list[ static_cast(boost::get(facet_value_pmap, facet_it)) % 17]); + } } } diff --git a/Polyhedron/demo/Polyhedron/Scene_polyhedron_with_color_item.h b/Polyhedron/demo/Polyhedron/Scene_polyhedron_with_color_item.h index e82e904ee22..31cc9875cf8 100644 --- a/Polyhedron/demo/Polyhedron/Scene_polyhedron_with_color_item.h +++ b/Polyhedron/demo/Polyhedron/Scene_polyhedron_with_color_item.h @@ -3,7 +3,7 @@ #include "Scene_polyhedron_with_color_item_config.h" #include "Scene_item_with_display_list.h" -#include "Polyhedron_type_fwd.h" +#include "Polyhedron_type.h" #include #include