diff --git a/Polyhedron/demo/Polyhedron/Plugins/Point_set/Point_set_shape_detection_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/Point_set/Point_set_shape_detection_plugin.cpp index ae1d55956a2..e79231d2498 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/Point_set/Point_set_shape_detection_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/Point_set/Point_set_shape_detection_plugin.cpp @@ -2,6 +2,8 @@ #include "Scene_points_with_normal_item.h" #include "Scene_polygon_soup_item.h" #include "Scene_polyhedron_item.h" +#include + #include #include @@ -104,6 +106,7 @@ public: }; void Polyhedron_demo_point_set_shape_detection_plugin::on_actionDetect_triggered() { + CGAL::Random rand(time(0)); const CGAL::Three::Scene_interface::Item_id index = scene->mainSelectionIndex(); @@ -135,20 +138,27 @@ void Polyhedron_demo_point_set_shape_detection_plugin::on_actionDetect_triggered Shape_detection shape_detection; shape_detection.set_input(*points); + std::vector groups; + groups.resize(5); // Shapes to be searched for are registered by using the template Shape_factory if(dialog.detect_plane()){ - shape_detection.add_shape_factory >(); - } + groups[0] = new Scene_group_item("Planes"); + shape_detection.add_shape_factory >(); + } if(dialog.detect_cylinder()){ + groups[1] = new Scene_group_item("Cylinders"); shape_detection.add_shape_factory >(); } if(dialog.detect_torus()){ - shape_detection.add_shape_factory< CGAL::Shape_detection_3::Torus >(); + groups[2] = new Scene_group_item("Torus"); + shape_detection.add_shape_factory< CGAL::Shape_detection_3::Torus >(); } if(dialog.detect_cone()){ + groups[3] = new Scene_group_item("Cones"); shape_detection.add_shape_factory< CGAL::Shape_detection_3::Cone >(); } if(dialog.detect_sphere()){ + groups[4] = new Scene_group_item("Spheres"); shape_detection.add_shape_factory< CGAL::Shape_detection_3::Sphere >(); } @@ -242,6 +252,9 @@ void Polyhedron_demo_point_set_shape_detection_plugin::on_actionDetect_triggered .arg (QString::number (shape->indices_of_assigned_points().size()))); poly_item->setRenderingMode (Flat); scene->addItem(poly_item); + if(scene->item_id(groups[0]) == -1) + scene->addItem(groups[0]); + scene->changeGroup(poly_item, groups[0]); } } else if (dynamic_cast *>(shape.get())) @@ -258,13 +271,48 @@ void Polyhedron_demo_point_set_shape_detection_plugin::on_actionDetect_triggered point_item->setName(QString::fromStdString(ss.str())); point_item->set_has_normals(true); point_item->setRenderingMode(item->renderingMode()); - if (dialog.generate_subset()) + + if (dialog.generate_subset()){ scene->addItem(point_item); + if (dynamic_cast *>(shape.get())) + { + if(scene->item_id(groups[1]) == -1) + scene->addItem(groups[1]); + scene->changeGroup(point_item, groups[1]); + } + else if (dynamic_cast *>(shape.get())) + { + if(scene->item_id(groups[0]) == -1) + scene->addItem(groups[0]); + scene->changeGroup(point_item, groups[0]); + } + else if (dynamic_cast *>(shape.get())) + { + if(scene->item_id(groups[3]) == -1) + scene->addItem(groups[3]); + scene->changeGroup(point_item, groups[3]); + } + else if (dynamic_cast *>(shape.get())) + { + if(scene->item_id(groups[2]) == -1) + scene->addItem(groups[2]); + scene->changeGroup(point_item, groups[2]); + } + else if (dynamic_cast *>(shape.get())) + { + if(scene->item_id(groups[4]) == -1) + scene->addItem(groups[4]); + scene->changeGroup(point_item, groups[4]); + } + } else delete point_item; ++index; } + Q_FOREACH(Scene_group_item* group, groups) + if(group && group->getChildren().empty()) + delete group; // Updates scene scene->itemChanged(index);