diff --git a/Polyhedron/demo/Polyhedron/MainWindow.cpp b/Polyhedron/demo/Polyhedron/MainWindow.cpp index 6f9073421dd..6866f6ef032 100644 --- a/Polyhedron/demo/Polyhedron/MainWindow.cpp +++ b/Polyhedron/demo/Polyhedron/MainWindow.cpp @@ -1323,6 +1323,8 @@ void MainWindow::selectSceneItem(int i) else { QItemSelection s = proxyModel->mapSelectionFromSource(scene->createSelection(i)); + if(s.empty()) + return; QModelIndex mi = proxyModel->mapFromSource(scene->getModelIndexFromId(i).first()); sceneView->setCurrentIndex(mi); sceneView->selectionModel()->select(s, @@ -1347,7 +1349,8 @@ void MainWindow::selectSceneItems(QList is) sceneView->setCurrentIndex(i); sceneView->selectionModel()->select(s, QItemSelectionModel::ClearAndSelect); - sceneView->scrollTo(s.indexes().first()); + if(!s.empty()) + sceneView->scrollTo(s.indexes().first()); } } @@ -1392,10 +1395,7 @@ void MainWindow::removeSceneItemFromSelection(int i) void MainWindow::selectAll() { - QItemSelection s = - proxyModel->mapSelectionFromSource(scene->createSelectionAll()); - sceneView->selectionModel()->select(s, - QItemSelectionModel::ClearAndSelect); + sceneView->selectAll(); } int MainWindow::getSelectedSceneItemIndex() const @@ -1789,12 +1789,12 @@ void MainWindow::updateInfo() { CGAL::Bbox_3 bbox = item->bbox(); if(bbox !=CGAL::Bbox_3()) item_text += QString("
Bounding box: min (%1,%2,%3), max (%4,%5,%6)
") - .arg(bbox.xmin()) - .arg(bbox.ymin()) - .arg(bbox.zmin()) - .arg(bbox.xmax()) - .arg(bbox.ymax()) - .arg(bbox.zmax()); + .arg(bbox.xmin(),0, 'g', 17) + .arg(bbox.ymin(),0, 'g', 17) + .arg(bbox.zmin(),0, 'g', 17) + .arg(bbox.xmax(),0, 'g', 17) + .arg(bbox.ymax(),0, 'g', 17) + .arg(bbox.zmax(),0, 'g', 17); if(!item_filename.isEmpty()) { item_text += QString("
File: %1
").arg(item_filename); } diff --git a/Polyhedron/demo/Polyhedron/Plugins/PCA/Affine_transform_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/PCA/Affine_transform_plugin.cpp index 4a99a1101c0..75b996dda51 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/PCA/Affine_transform_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/PCA/Affine_transform_plugin.cpp @@ -450,7 +450,7 @@ void Polyhedron_demo_affine_transform_plugin::grid() Kernel::Aff_transformation_3 trans(CGAL::TRANSLATION, Kernel::Vector_3(i*x_t,j*y_t,k*z_t)); CGAL::Polygon_mesh_processing::transform(trans, e); Facegraph_item* t_item = new Facegraph_item(e); - t_item->setName(tr("%1 %2%3%4") + t_item->setName(tr("%1 %2,%3,%4") .arg(item->name()) .arg(i) .arg(j) diff --git a/Polyhedron/demo/Polyhedron/Scene.cpp b/Polyhedron/demo/Polyhedron/Scene.cpp index 2fcc276a1ce..8ea8f34d521 100644 --- a/Polyhedron/demo/Polyhedron/Scene.cpp +++ b/Polyhedron/demo/Polyhedron/Scene.cpp @@ -704,7 +704,22 @@ Scene::draw_aux(bool with_names, CGAL::Three::Viewer_interface* viewer) Q_FOREACH(Item_id id, children) { Scene_item* item = m_entries[id]; - if(item->alpha() == 1.0f) + Scene_group_item* group = qobject_cast(item); + bool is_transparent=false; + if(item->alpha() != 1.0f) + is_transparent = true; + else if(group) + { + for(const auto& child : group->getChildren()) + { + if(group->getChild(child)->alpha() < 1.0f) + { + is_transparent = true; + break; + } + } + } + if(!is_transparent) opaque_items.push_back(id); else transparent_items.push_back(id); @@ -1200,6 +1215,8 @@ bool Scene::sort_lists(QVector >&sorted_lists, bool up) } void Scene::moveRowUp() { + if(selectionIndices().isEmpty()) + return; QVector >sorted_lists(1); QList to_select; //sort lists according to the indices of each item in its container (scene or group) @@ -1251,6 +1268,8 @@ void Scene::moveRowUp() } void Scene::moveRowDown() { + if(selectionIndices().isEmpty()) + return; QVector >sorted_lists(1); QList to_select; //sort lists according to the indices of each item in its container (scene or group) @@ -1300,7 +1319,9 @@ void Scene::moveRowDown() } } } - selectionChanged(to_select); + if(!to_select.isEmpty()){ + selectionChanged(to_select); + } } Scene::Item_id Scene::mainSelectionIndex() const { return (selectionIndices().size() == 1) ? selected_item : -1; diff --git a/Polyhedron/demo/Polyhedron/Scene_c3t3_item.cpp b/Polyhedron/demo/Polyhedron/Scene_c3t3_item.cpp index f350e500775..ed1fd56a3ec 100644 --- a/Polyhedron/demo/Polyhedron/Scene_c3t3_item.cpp +++ b/Polyhedron/demo/Polyhedron/Scene_c3t3_item.cpp @@ -153,7 +153,7 @@ public : alphaSlider->setMaximum(255); alphaSlider->setValue(255); } - viewer->makeCurrent(); + //viewer->makeCurrent(); const EPICK::Plane_3& plane = qobject_cast(this->parent())->plane(); float shrink_factor = qobject_cast(this->parent())->getShrinkFactor(); QVector4D cp = cgal_plane_to_vector4d(plane); diff --git a/Polyhedron/demo/Polyhedron/Scene_polygon_soup_item.cpp b/Polyhedron/demo/Polyhedron/Scene_polygon_soup_item.cpp index e4d61b95ef9..952c845aa55 100644 --- a/Polyhedron/demo/Polyhedron/Scene_polygon_soup_item.cpp +++ b/Polyhedron/demo/Polyhedron/Scene_polygon_soup_item.cpp @@ -546,12 +546,14 @@ Scene_polygon_soup_item::draw(CGAL::Three::Viewer_interface* viewer) const { if(d->soup->fcolors.empty()) getTriangleContainer(Priv::Flat_facets)->setColor(this->color()); + getTriangleContainer(Priv::Flat_facets)->setAlpha(alpha()); getTriangleContainer(Priv::Flat_facets)->draw(viewer, d->soup->fcolors.empty()); } else if(renderingMode() == Gouraud) { if(d->soup->vcolors.empty()) getTriangleContainer(Priv::Smooth_facets)->setColor(this->color()); + getTriangleContainer(Priv::Smooth_facets)->setAlpha(alpha()); getTriangleContainer(Priv::Smooth_facets)->draw(viewer, d->soup->vcolors.empty()); } } diff --git a/Polyhedron/demo/Polyhedron/Scene_polyhedron_selection_item.cpp b/Polyhedron/demo/Polyhedron/Scene_polyhedron_selection_item.cpp index faae911f852..10b5b4e3fb8 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 936152e5086..dbfca601296 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 19e7013495b..af7964d3164 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, @@ -2368,9 +2370,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 ce3ea53002a..b8b88be572f 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(); diff --git a/Polyhedron/demo/Polyhedron/Viewer.cpp b/Polyhedron/demo/Polyhedron/Viewer.cpp index 8c53251c18c..95ede4b08db 100644 --- a/Polyhedron/demo/Polyhedron/Viewer.cpp +++ b/Polyhedron/demo/Polyhedron/Viewer.cpp @@ -408,6 +408,7 @@ Viewer::~Viewer() .arg(d->back_color.greenF()) .arg(d->back_color.blueF())); + d->vao.destroy(); if(d->_recentFunctions) delete d->_recentFunctions; if(d->painter) @@ -1559,12 +1560,18 @@ void Viewer_impl::showDistance(QPoint pixel) TextItem *ACoord = new TextItem(float(APoint.x), float(APoint.y), float(APoint.z), - QString("A(%1,%2,%3)").arg(APoint.x-viewer->offset().x).arg(APoint.y-viewer->offset().y).arg(APoint.z-viewer->offset().z), true, font, Qt::red, true); + QString("A(%1,%2,%3)") + .arg(APoint.x-viewer->offset().x, 0, 'g', 10) + .arg(APoint.y-viewer->offset().y, 0, 'g', 10) + .arg(APoint.z-viewer->offset().z, 0, 'g', 10), true, font, Qt::red, true); distance_text.append(ACoord); TextItem *BCoord = new TextItem(float(BPoint.x), float(BPoint.y), float(BPoint.z), - QString("B(%1,%2,%3)").arg(BPoint.x-viewer->offset().x).arg(BPoint.y-viewer->offset().y).arg(BPoint.z-viewer->offset().z), true, font, Qt::red, true); + QString("B(%1,%2,%3)") + .arg(BPoint.x-viewer->offset().x, 0, 'g', 10) + .arg(BPoint.y-viewer->offset().y, 0, 'g', 10) + .arg(BPoint.z-viewer->offset().z, 0, 'g', 10), true, font, Qt::red, true); distance_text.append(BCoord); CGAL::qglviewer::Vec centerPoint = 0.5*(BPoint+APoint); TextItem *centerCoord = new TextItem(float(centerPoint.x), @@ -1582,7 +1589,7 @@ void Viewer_impl::showDistance(QPoint pixel) .arg(BPoint.x-viewer->offset().x) .arg(BPoint.y-viewer->offset().y) .arg(BPoint.z-viewer->offset().z) - .arg(dist))); + .arg(dist, 0, 'g', 10))); } } diff --git a/Three/include/CGAL/Three/Scene_draw_interface.h b/Three/include/CGAL/Three/Scene_draw_interface.h index 3a77569d102..4ceaa728a23 100644 --- a/Three/include/CGAL/Three/Scene_draw_interface.h +++ b/Three/include/CGAL/Three/Scene_draw_interface.h @@ -16,6 +16,7 @@ #include #include +#include class QKeyEvent; class QPoint; namespace CGAL