Make repair_plugin work for Surface_mesh

This commit is contained in:
Andreas Fabri 2017-03-10 13:25:59 +01:00 committed by Maxime Gimeno
parent 8e7c2439b8
commit 1ec6d7b058
3 changed files with 42 additions and 19 deletions

View File

@ -1126,7 +1126,7 @@ bool remove_self_intersections(TriangleMesh& tm, const int max_steps = 7, bool v
boundary_hedges.resize(boundary_hedges_initial_size); boundary_hedges.resize(boundary_hedges_initial_size);
BOOST_FOREACH(face_descriptor fh, faces_to_remove) BOOST_FOREACH(face_descriptor fh, faces_to_remove)
{ {
halfedge_descriptor h = fh->halfedge(); halfedge_descriptor h = halfedge(fh,tm);
for (int i=0;i<3; ++i) for (int i=0;i<3; ++i)
{ {
if ( is_border( opposite(h, tm), tm) ){ if ( is_border( opposite(h, tm), tm) ){
@ -1154,7 +1154,7 @@ bool remove_self_intersections(TriangleMesh& tm, const int max_steps = 7, bool v
std::set<vertex_descriptor> border_vertices; std::set<vertex_descriptor> border_vertices;
BOOST_FOREACH(halfedge_descriptor h, boundary_hedges) BOOST_FOREACH(halfedge_descriptor h, boundary_hedges)
{ {
if (!border_vertices.insert(h->vertex()).second){ if (!border_vertices.insert(target(h,tm)).second){
BOOST_FOREACH(halfedge_descriptor hh, halfedges_around_target(h,tm)){ BOOST_FOREACH(halfedge_descriptor hh, halfedges_around_target(h,tm)){
if (!is_border(hh, tm)) if (!is_border(hh, tm))
faces_to_remove.insert(face(hh, tm)); faces_to_remove.insert(face(hh, tm));
@ -1176,7 +1176,7 @@ bool remove_self_intersections(TriangleMesh& tm, const int max_steps = 7, bool v
std::set<edge_descriptor> edges_to_remove; std::set<edge_descriptor> edges_to_remove;
BOOST_FOREACH(face_descriptor fh, faces_to_remove) BOOST_FOREACH(face_descriptor fh, faces_to_remove)
{ {
BOOST_FOREACH(halfedge_descriptor h, halfedges_around_face(fh->halfedge(),tm)) BOOST_FOREACH(halfedge_descriptor h, halfedges_around_face(halfedge(fh,tm),tm))
{ {
if (halfedge(target(h, tm), tm)==h) // limit the number of insertions if (halfedge(target(h, tm), tm)==h) // limit the number of insertions
vertices_to_remove.insert(target(h, tm)); vertices_to_remove.insert(target(h, tm));

View File

@ -88,7 +88,7 @@ polyhedron_demo_plugin(surface_intersection_plugin Surface_intersection_plugin)
target_link_libraries(surface_intersection_plugin scene_polyhedron_item scene_polylines_item) target_link_libraries(surface_intersection_plugin scene_polyhedron_item scene_polylines_item)
polyhedron_demo_plugin(repair_polyhedron_plugin Repair_polyhedron_plugin) polyhedron_demo_plugin(repair_polyhedron_plugin Repair_polyhedron_plugin)
target_link_libraries(repair_polyhedron_plugin scene_polyhedron_item) target_link_libraries(repair_polyhedron_plugin scene_surface_mesh_item scene_polyhedron_item)
qt5_wrap_ui( isotropicRemeshingUI_FILES Isotropic_remeshing_dialog.ui) qt5_wrap_ui( isotropicRemeshingUI_FILES Isotropic_remeshing_dialog.ui)
polyhedron_demo_plugin(isotropic_remeshing_plugin Isotropic_remeshing_plugin ${isotropicRemeshingUI_FILES}) polyhedron_demo_plugin(isotropic_remeshing_plugin Isotropic_remeshing_plugin ${isotropicRemeshingUI_FILES})

View File

@ -1,6 +1,7 @@
#include <QtCore/qglobal.h> #include <QtCore/qglobal.h>
#include "Scene_polyhedron_item.h" #include "Scene_polyhedron_item.h"
#include "Scene_surface_mesh_item.h"
#include <CGAL/Three/Scene_interface.h> #include <CGAL/Three/Scene_interface.h>
#include "Polyhedron_type.h" #include "Polyhedron_type.h"
#include <CGAL/Three/Polyhedron_demo_plugin_interface.h> #include <CGAL/Three/Polyhedron_demo_plugin_interface.h>
@ -13,7 +14,6 @@
#include <QObject> #include <QObject>
#include <CGAL/Polygon_mesh_processing/repair.h> #include <CGAL/Polygon_mesh_processing/repair.h>
#include <CGAL/boost/graph/graph_traits_Polyhedron_3.h>
using namespace CGAL::Three; using namespace CGAL::Three;
class Polyhedron_demo_repair_polyhedron_plugin : class Polyhedron_demo_repair_polyhedron_plugin :
@ -58,9 +58,15 @@ public:
bool applicable(QAction*) const bool applicable(QAction*) const
{ {
int item_id = scene->mainSelectionIndex(); int item_id = scene->mainSelectionIndex();
return qobject_cast<Scene_polyhedron_item*>( return qobject_cast<Scene_polyhedron_item*>(scene->item(item_id)) ||
scene->item(item_id)); qobject_cast<Scene_surface_mesh_item*>(scene->item(item_id));
} }
template <typename Item>
void on_actionRemoveIsolatedVertices_triggered(Scene_interface::Item_id index);
template <typename Item>
void on_actionRemoveDegenerateFaces_triggered(Scene_interface::Item_id index);
template <typename Item>
void on_actionRemoveSelfIntersections_triggered(Scene_interface::Item_id index);
public Q_SLOTS: public Q_SLOTS:
void on_actionRemoveIsolatedVertices_triggered(); void on_actionRemoveIsolatedVertices_triggered();
@ -75,13 +81,11 @@ private:
Messages_interface* messages; Messages_interface* messages;
}; // end Polyhedron_demo_repair_polyhedron_plugin }; // end Polyhedron_demo_repair_polyhedron_plugin
template <typename Item>
void Polyhedron_demo_repair_polyhedron_plugin::on_actionRemoveIsolatedVertices_triggered() void Polyhedron_demo_repair_polyhedron_plugin::on_actionRemoveIsolatedVertices_triggered(Scene_interface::Item_id index)
{ {
const Scene_interface::Item_id index = scene->mainSelectionIndex(); Item* poly_item =
qobject_cast<Item*>(scene->item(index));
Scene_polyhedron_item* poly_item =
qobject_cast<Scene_polyhedron_item*>(scene->item(index));
if (poly_item) if (poly_item)
{ {
std::size_t nbv = std::size_t nbv =
@ -94,12 +98,18 @@ void Polyhedron_demo_repair_polyhedron_plugin::on_actionRemoveIsolatedVertices_t
} }
} }
void Polyhedron_demo_repair_polyhedron_plugin::on_actionRemoveDegenerateFaces_triggered() void Polyhedron_demo_repair_polyhedron_plugin::on_actionRemoveIsolatedVertices_triggered()
{ {
const Scene_interface::Item_id index = scene->mainSelectionIndex(); const Scene_interface::Item_id index = scene->mainSelectionIndex();
on_actionRemoveIsolatedVertices_triggered<Scene_polyhedron_item>(index);
on_actionRemoveIsolatedVertices_triggered<Scene_surface_mesh_item>(index);
}
Scene_polyhedron_item* poly_item = template <typename Item>
qobject_cast<Scene_polyhedron_item*>(scene->item(index)); void Polyhedron_demo_repair_polyhedron_plugin::on_actionRemoveDegenerateFaces_triggered(Scene_interface::Item_id index)
{
Item* poly_item =
qobject_cast<Item*>(scene->item(index));
if (poly_item) if (poly_item)
{ {
std::size_t nbv = std::size_t nbv =
@ -112,12 +122,18 @@ void Polyhedron_demo_repair_polyhedron_plugin::on_actionRemoveDegenerateFaces_tr
} }
} }
void Polyhedron_demo_repair_polyhedron_plugin::on_actionRemoveSelfIntersections_triggered() void Polyhedron_demo_repair_polyhedron_plugin::on_actionRemoveDegenerateFaces_triggered()
{ {
const Scene_interface::Item_id index = scene->mainSelectionIndex(); const Scene_interface::Item_id index = scene->mainSelectionIndex();
on_actionRemoveDegenerateFaces_triggered<Scene_polyhedron_item>(index);
on_actionRemoveDegenerateFaces_triggered<Scene_surface_mesh_item>(index);
}
Scene_polyhedron_item* poly_item = template <typename Item>
qobject_cast<Scene_polyhedron_item*>(scene->item(index)); void Polyhedron_demo_repair_polyhedron_plugin::on_actionRemoveSelfIntersections_triggered(Scene_interface::Item_id index)
{
Item* poly_item =
qobject_cast<Item*>(scene->item(index));
if (poly_item) if (poly_item)
{ {
bool solved = bool solved =
@ -130,4 +146,11 @@ void Polyhedron_demo_repair_polyhedron_plugin::on_actionRemoveSelfIntersections_
} }
} }
void Polyhedron_demo_repair_polyhedron_plugin::on_actionRemoveSelfIntersections_triggered()
{
const Scene_interface::Item_id index = scene->mainSelectionIndex();
on_actionRemoveSelfIntersections_triggered<Scene_polyhedron_item>(index);
on_actionRemoveSelfIntersections_triggered<Scene_surface_mesh_item>(index);
}
#include "Repair_polyhedron_plugin.moc" #include "Repair_polyhedron_plugin.moc"