mirror of https://github.com/CGAL/cgal
Add triangulate_polygons() to the demo
This commit is contained in:
parent
8a39016780
commit
e5c8323825
|
|
@ -100,7 +100,7 @@ add_custom_target(self_intersection_plugin)
|
|||
add_dependencies(self_intersection_plugin selection_plugin)
|
||||
|
||||
polyhedron_demo_plugin(triangulate_facets_plugin Triangulate_facets_plugin KEYWORDS PMP)
|
||||
target_link_libraries(triangulate_facets_plugin PUBLIC scene_surface_mesh_item scene_selection_item)
|
||||
target_link_libraries(triangulate_facets_plugin PUBLIC scene_surface_mesh_item scene_selection_item scene_polygon_soup_item)
|
||||
|
||||
polyhedron_demo_plugin(corefinement_plugin Corefinement_plugin KEYWORDS PMP)
|
||||
target_link_libraries(corefinement_plugin PUBLIC scene_surface_mesh_item)
|
||||
|
|
|
|||
|
|
@ -4,10 +4,13 @@
|
|||
#include "Messages_interface.h"
|
||||
#include <CGAL/Three/Polyhedron_demo_plugin_helper.h>
|
||||
#include <CGAL/Three/Three.h>
|
||||
|
||||
#include "Scene_surface_mesh_item.h"
|
||||
#include "Scene_polyhedron_selection_item.h"
|
||||
#include "Scene_polygon_soup_item.h"
|
||||
|
||||
#include <CGAL/Polygon_mesh_processing/triangulate_faces.h>
|
||||
|
||||
using namespace CGAL::Three;
|
||||
class Polyhedron_demo_triangulate_facets_plugin :
|
||||
public QObject,
|
||||
|
|
@ -20,13 +23,13 @@ class Polyhedron_demo_triangulate_facets_plugin :
|
|||
typedef Scene_surface_mesh_item::Face_graph FaceGraph;
|
||||
typedef boost::graph_traits<FaceGraph>::face_descriptor face_descriptor;
|
||||
|
||||
struct Visitor
|
||||
struct Selection_updater_visitor
|
||||
: public CGAL::Polygon_mesh_processing::Hole_filling::Default_visitor
|
||||
{
|
||||
typedef typename Scene_polyhedron_selection_item::Selection_set_facet Container;
|
||||
Container& faces;
|
||||
|
||||
Visitor(Container& container)
|
||||
Selection_updater_visitor(Container& container)
|
||||
: faces(container)
|
||||
{}
|
||||
void before_subface_creations(face_descriptor fd)
|
||||
|
|
@ -67,6 +70,8 @@ public:
|
|||
return true;
|
||||
if ( qobject_cast<Scene_polyhedron_selection_item*>(scene->item(index)))
|
||||
return true;
|
||||
if(qobject_cast<Scene_polygon_soup_item*>(scene->item(index)))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
@ -83,24 +88,38 @@ public Q_SLOTS:
|
|||
Scene_polyhedron_selection_item* selection_item =
|
||||
qobject_cast<Scene_polyhedron_selection_item*>(scene->item(index));
|
||||
|
||||
SMesh* pMesh = (sm_item != nullptr)
|
||||
? sm_item->polyhedron()
|
||||
Scene_polygon_soup_item* soup_item =
|
||||
qobject_cast<Scene_polygon_soup_item*>(scene->item(index));
|
||||
|
||||
if (soup_item)
|
||||
{
|
||||
soup_item->triangulate();
|
||||
}
|
||||
else
|
||||
{
|
||||
SMesh* pMesh = (sm_item != nullptr) ? sm_item->polyhedron()
|
||||
: selection_item->polyhedron();
|
||||
|
||||
if(!pMesh) continue;
|
||||
if(is_triangle_mesh(*pMesh)) {
|
||||
if(!pMesh)
|
||||
continue;
|
||||
|
||||
if(is_triangle_mesh(*pMesh))
|
||||
{
|
||||
CGAL::Three::Three::warning(tr("The polyhedron \"%1\" is already triangulated.")
|
||||
.arg(sm_item->name()) );
|
||||
continue;
|
||||
}
|
||||
|
||||
if (sm_item)
|
||||
{
|
||||
if (!CGAL::Polygon_mesh_processing::triangulate_faces(*pMesh))
|
||||
CGAL::Three::Three::warning(tr("Some facets could not be triangulated."));
|
||||
|
||||
sm_item->invalidateOpenGLBuffers();
|
||||
}
|
||||
else if (selection_item)
|
||||
{
|
||||
Visitor visitor(selection_item->selected_facets);
|
||||
Selection_updater_visitor visitor(selection_item->selected_facets);
|
||||
if (!CGAL::Polygon_mesh_processing::triangulate_faces(
|
||||
selection_item->selected_facets,
|
||||
*pMesh,
|
||||
|
|
@ -114,8 +133,9 @@ public Q_SLOTS:
|
|||
selection_item->itemChanged();
|
||||
}
|
||||
|
||||
sm_item->resetColors();
|
||||
sm_item->invalidateOpenGLBuffers();
|
||||
sm_item->resetColors(); // @todo should have a visitor to give the color of the parent face
|
||||
}
|
||||
|
||||
scene->itemChanged(sm_item);
|
||||
} // end of the loop on the selected items
|
||||
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@
|
|||
#include <CGAL/Polygon_mesh_processing/orientation.h>
|
||||
#include <CGAL/Polygon_mesh_processing/repair.h>
|
||||
#include <CGAL/Polygon_mesh_processing/repair_polygon_soup.h>
|
||||
#include <CGAL/Polygon_mesh_processing/triangulate_faces.h>
|
||||
#include <CGAL/Polygon_2.h>
|
||||
#include <CGAL/version.h>
|
||||
|
||||
|
|
@ -419,6 +420,32 @@ void Scene_polygon_soup_item::inside_out()
|
|||
invalidateOpenGLBuffers();
|
||||
}
|
||||
|
||||
void Scene_polygon_soup_item::repair(bool erase_dup, bool req_same_orientation)
|
||||
{
|
||||
QApplication::setOverrideCursor(Qt::BusyCursor);
|
||||
CGAL::Polygon_mesh_processing::repair_polygon_soup(
|
||||
d->soup->points,
|
||||
d->soup->polygons,
|
||||
CGAL::parameters::erase_all_duplicates(erase_dup)
|
||||
.require_same_orientation(req_same_orientation));
|
||||
QApplication::restoreOverrideCursor();
|
||||
invalidateOpenGLBuffers();
|
||||
}
|
||||
|
||||
bool Scene_polygon_soup_item::triangulate()
|
||||
{
|
||||
QApplication::setOverrideCursor(Qt::BusyCursor);
|
||||
|
||||
bool success = true;
|
||||
|
||||
CGAL::Polygon_mesh_processing::triangulate_polygons(d->soup->points, d->soup->polygons);
|
||||
|
||||
QApplication::restoreOverrideCursor();
|
||||
invalidateOpenGLBuffers();
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
bool
|
||||
Scene_polygon_soup_item::orient(std::vector<std::size_t>& non_manifold_vertices)
|
||||
{
|
||||
|
|
@ -894,20 +921,6 @@ void Scene_polygon_soup_item::computeElements() const
|
|||
QApplication::restoreOverrideCursor();
|
||||
}
|
||||
|
||||
void Scene_polygon_soup_item::repair(bool erase_dup, bool req_same_orientation)
|
||||
{
|
||||
QApplication::setOverrideCursor(Qt::BusyCursor);
|
||||
CGAL::Polygon_mesh_processing::repair_polygon_soup(
|
||||
d->soup->points,
|
||||
d->soup->polygons,
|
||||
CGAL::parameters::
|
||||
erase_all_duplicates(erase_dup)
|
||||
.require_same_orientation(req_same_orientation));
|
||||
QApplication::restoreOverrideCursor();
|
||||
|
||||
// CGAL::Three::Three::information(
|
||||
}
|
||||
|
||||
CGAL::Three::Scene_item::Header_data Scene_polygon_soup_item::header() const
|
||||
{
|
||||
CGAL::Three::Scene_item::Header_data data;
|
||||
|
|
|
|||
|
|
@ -187,6 +187,7 @@ public Q_SLOTS:
|
|||
bool exportAsSurfaceMesh(SMesh*);
|
||||
void inside_out();
|
||||
void repair(bool erase_dup, bool req_same_orientation);
|
||||
bool triangulate();
|
||||
|
||||
void setDisplayNonManifoldEdges(const bool);
|
||||
bool displayNonManifoldEdges() const;
|
||||
|
|
|
|||
Loading…
Reference in New Issue