Merge pull request #1281 from maxGimeno/Polyhedron_demo-Groups_for_shape_detection-GF

Polyhedron_demo: sub-groups for shape detection
This commit is contained in:
Laurent Rineau 2016-07-20 18:10:41 +02:00 committed by GitHub
commit e2a0aef1a5
1 changed files with 52 additions and 4 deletions

View File

@ -2,6 +2,8 @@
#include "Scene_points_with_normal_item.h"
#include "Scene_polygon_soup_item.h"
#include "Scene_polyhedron_item.h"
#include <CGAL/Three/Scene_group_item.h>
#include <CGAL/Three/Polyhedron_demo_plugin_helper.h>
#include <CGAL/Three/Polyhedron_demo_plugin_interface.h>
@ -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<Scene_group_item *> 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<CGAL::Shape_detection_3::Plane<Traits> >();
}
groups[0] = new Scene_group_item("Planes");
shape_detection.add_shape_factory<CGAL::Shape_detection_3::Plane<Traits> >();
}
if(dialog.detect_cylinder()){
groups[1] = new Scene_group_item("Cylinders");
shape_detection.add_shape_factory<CGAL::Shape_detection_3::Cylinder<Traits> >();
}
if(dialog.detect_torus()){
shape_detection.add_shape_factory< CGAL::Shape_detection_3::Torus<Traits> >();
groups[2] = new Scene_group_item("Torus");
shape_detection.add_shape_factory< CGAL::Shape_detection_3::Torus<Traits> >();
}
if(dialog.detect_cone()){
groups[3] = new Scene_group_item("Cones");
shape_detection.add_shape_factory< CGAL::Shape_detection_3::Cone<Traits> >();
}
if(dialog.detect_sphere()){
groups[4] = new Scene_group_item("Spheres");
shape_detection.add_shape_factory< CGAL::Shape_detection_3::Sphere<Traits> >();
}
@ -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<CGAL::Shape_detection_3::Cone<Traits> *>(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<CGAL::Shape_detection_3::Cylinder<Traits> *>(shape.get()))
{
if(scene->item_id(groups[1]) == -1)
scene->addItem(groups[1]);
scene->changeGroup(point_item, groups[1]);
}
else if (dynamic_cast<CGAL::Shape_detection_3::Plane<Traits> *>(shape.get()))
{
if(scene->item_id(groups[0]) == -1)
scene->addItem(groups[0]);
scene->changeGroup(point_item, groups[0]);
}
else if (dynamic_cast<CGAL::Shape_detection_3::Cone<Traits> *>(shape.get()))
{
if(scene->item_id(groups[3]) == -1)
scene->addItem(groups[3]);
scene->changeGroup(point_item, groups[3]);
}
else if (dynamic_cast<CGAL::Shape_detection_3::Torus<Traits> *>(shape.get()))
{
if(scene->item_id(groups[2]) == -1)
scene->addItem(groups[2]);
scene->changeGroup(point_item, groups[2]);
}
else if (dynamic_cast<CGAL::Shape_detection_3::Sphere<Traits> *>(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);