From 261eb678b067038b22d7c2796d890c1a6a2e47b9 Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Fri, 24 Jul 2020 16:13:58 +0200 Subject: [PATCH] Update displayed ids when moving a point --- .../Scene_polyhedron_selection_item.cpp | 14 ++++++++ .../Scene_polyhedron_selection_item.h | 3 ++ .../Polyhedron/Scene_surface_mesh_item.cpp | 34 ++++++++++++++++--- .../demo/Polyhedron/Scene_surface_mesh_item.h | 1 + 4 files changed, 47 insertions(+), 5 deletions(-) diff --git a/Polyhedron/demo/Polyhedron/Scene_polyhedron_selection_item.cpp b/Polyhedron/demo/Polyhedron/Scene_polyhedron_selection_item.cpp index 9980dccebc8..4be91c33f3d 100644 --- a/Polyhedron/demo/Polyhedron/Scene_polyhedron_selection_item.cpp +++ b/Polyhedron/demo/Polyhedron/Scene_polyhedron_selection_item.cpp @@ -2610,3 +2610,17 @@ CGAL::Three::Scene_item::Header_data Scene_polyhedron_selection_item::header() c data.titles.append(QString("Average")); return data; } + + +void Scene_polyhedron_selection_item::updateDisplayedIds(QEvent* e) +{ + if(e->type() == QEvent::MouseButtonRelease ) + { + QMouseEvent* mouse_event = static_cast(e); + if((mouse_event->button() == Qt::RightButton || mouse_event->button() == Qt::MiddleButton) + && temp_selected_vertices.size() == 1) { + fg_vertex_descriptor vh = *temp_selected_vertices.begin(); + poly_item->updateIds(vh); + } + } +} diff --git a/Polyhedron/demo/Polyhedron/Scene_polyhedron_selection_item.h b/Polyhedron/demo/Polyhedron/Scene_polyhedron_selection_item.h index be40f12bf37..71cd28e6f85 100644 --- a/Polyhedron/demo/Polyhedron/Scene_polyhedron_selection_item.h +++ b/Polyhedron/demo/Polyhedron/Scene_polyhedron_selection_item.h @@ -799,6 +799,7 @@ public: } void selection_changed(bool); + void updateDisplayedIds(QEvent *e); Q_SIGNALS: void updateInstructions(QString); @@ -875,6 +876,8 @@ protected: } } + updateDisplayedIds(gen_event); + if(!visible() || !k_ring_selector.state.shift_pressing) { return false; } if(gen_event->type() == QEvent::Wheel) { diff --git a/Polyhedron/demo/Polyhedron/Scene_surface_mesh_item.cpp b/Polyhedron/demo/Polyhedron/Scene_surface_mesh_item.cpp index 00db43a908a..9adcad6ad56 100644 --- a/Polyhedron/demo/Polyhedron/Scene_surface_mesh_item.cpp +++ b/Polyhedron/demo/Polyhedron/Scene_surface_mesh_item.cpp @@ -136,6 +136,7 @@ struct Scene_surface_mesh_item_priv{ << GouraudPlusEdges << Points; item->setProperty("classname", QString("surface_mesh")); + ids_need_update = false; } Scene_surface_mesh_item_priv(SMesh* sm, Scene_surface_mesh_item *parent): @@ -168,7 +169,8 @@ struct Scene_surface_mesh_item_priv{ << Gouraud << GouraudPlusEdges << Points; - item->setProperty("classname", QString("surface_mesh")); + item->setProperty("classname", QString("surface_mesh"));\ + ids_need_update = false; } ~Scene_surface_mesh_item_priv() @@ -224,7 +226,6 @@ struct Scene_surface_mesh_item_priv{ mutable bool edges_displayed; mutable bool faces_displayed; mutable bool all_displayed; - mutable QList text_ids; mutable std::vector targeted_id; std::string comments; @@ -239,7 +240,6 @@ struct Scene_surface_mesh_item_priv{ mutable bool isinit; mutable std::vector idx_data_; mutable std::size_t idx_data_size; - mutable std::map current_indices; //map im values to ghosts-free values mutable std::vector idx_edge_data_; mutable std::size_t idx_edge_data_size; mutable std::vector idx_feature_edge_data_; @@ -267,6 +267,7 @@ struct Scene_surface_mesh_item_priv{ bool has_nm_vertices; int genus; bool self_intersect; + bool ids_need_update; mutable QSlider* alphaSlider; QList supported_rendering_modes; }; @@ -2017,6 +2018,7 @@ void Scene_surface_mesh_item_priv::fillTargetedIds(const face_descriptor &select CGAL::Three::Viewer_interface *viewer, const CGAL::qglviewer::Vec& offset) { + all_displayed = false; compute_displayed_ids(*smesh_, viewer, selected_fh, @@ -2369,9 +2371,31 @@ void Scene_surface_mesh_item::updateVertex(vertex_descriptor vh) getTriangleContainer(0)->getVbo(Tri::Smooth_normals), new_point,id); } + d->ids_need_update = true; + redraw(); + } +} + +void Scene_surface_mesh_item::updateIds(vertex_descriptor vh) +{ + if(d->ids_need_update && + (d->faces_displayed || d->vertices_displayed || d->edges_displayed)) + { + invalidate_aabb_tree(); + + if(d->all_displayed) + { + d->killIds(); + d->all_displayed = true; + ::printVertexIds(*d->smesh_, d->textVItems); + } + else + { + d->fillTargetedIds(face(halfedge(vh, *d->smesh_), *d->smesh_), + face_graph()->point(vh), CGAL::Three::Three::mainViewer(), CGAL::Three::Three::mainViewer()->offset()); + } + d->ids_need_update = false; } - invalidate_aabb_tree(); - redraw(); } void Scene_surface_mesh_item::switchToGouraudPlusEdge(bool b) diff --git a/Polyhedron/demo/Polyhedron/Scene_surface_mesh_item.h b/Polyhedron/demo/Polyhedron/Scene_surface_mesh_item.h index 42e82106626..b0d55547bea 100644 --- a/Polyhedron/demo/Polyhedron/Scene_surface_mesh_item.h +++ b/Polyhedron/demo/Polyhedron/Scene_surface_mesh_item.h @@ -156,6 +156,7 @@ public: void computeElements() const Q_DECL_OVERRIDE; void initializeBuffers(CGAL::Three::Viewer_interface*)const Q_DECL_OVERRIDE; void updateVertex(vertex_descriptor vh); + void updateIds(vertex_descriptor vh); void switchToGouraudPlusEdge(bool b); //replace flatPlusEdge by gouraudPlusEdge and ban Flat. Q_SIGNALS: void item_is_about_to_be_changed();