From 49a109fa363299753dab7816eb541f12baa7e00b Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Tue, 26 Mar 2019 15:06:40 +0100 Subject: [PATCH 1/4] Add a button to enable clipping 2D to avoid conflict with selection --- .../Plugins/PCA/Clipping_box_plugin.cpp | 21 ++++++++++--- .../Plugins/PCA/Clipping_box_widget.ui | 31 ++++++++++++++++--- 2 files changed, 42 insertions(+), 10 deletions(-) diff --git a/Polyhedron/demo/Polyhedron/Plugins/PCA/Clipping_box_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/PCA/Clipping_box_plugin.cpp index 49a7bd3e090..0b51141785a 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/PCA/Clipping_box_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/PCA/Clipping_box_plugin.cpp @@ -70,16 +70,23 @@ void Clipping_box_plugin::init(QMainWindow* mainWindow, CGAL::Three::Scene_inter scene = scene_interface; mw = mainWindow; actionClipbox = new QAction(tr("Create Clipping Box"), mainWindow); - connect(actionClipbox, SIGNAL(triggered()), - this, SLOT(clipbox())); dock_widget = new ClipWidget("Clip box", mw); dock_widget->setVisible(false); // do not show at the beginning addDockWidget(dock_widget); + + + connect(actionClipbox, &QAction::triggered, + this, [this](){ + dock_widget->show(); + dock_widget->raise(); + tab_change(); + }); connect(dock_widget->pushButton, SIGNAL(toggled(bool)), this, SLOT(clip(bool))); CGAL::QGLViewer* viewer = *CGAL::QGLViewer::QGLViewerPool().begin(); + viewer->installEventFilter(this); item = NULL; visualizer = NULL; @@ -95,8 +102,6 @@ void Clipping_box_plugin::clipbox() return; } QApplication::setOverrideCursor(Qt::WaitCursor); - dock_widget->show(); - dock_widget->raise(); if(!item) item = new Scene_edit_box_item(scene); connect(item, SIGNAL(destroyed()), @@ -121,6 +126,10 @@ void Clipping_box_plugin::clipbox() item->setRenderingMode(FlatPlusEdges); CGAL::QGLViewer* viewer = *CGAL::QGLViewer::QGLViewerPool().begin(); viewer->installEventFilter(item); + connect(dock_widget->clipButton, &QPushButton::toggled, + dock_widget->clipButton, [viewer](){ + viewer->setFocus(); + }); scene->addItem(item); actionClipbox->setEnabled(false); @@ -207,7 +216,8 @@ void Clipping_box_plugin::tab_change() bool Clipping_box_plugin::eventFilter(QObject *, QEvent *event) { static QImage background; - if (dock_widget->isHidden() || !(dock_widget->isActiveWindow()) || dock_widget->tabWidget->currentIndex() != 1) + if (dock_widget->isHidden() || !(dock_widget->isActiveWindow()) || dock_widget->tabWidget->currentIndex() != 1 + || (dock_widget->tabWidget->currentIndex() == 1 && !dock_widget->clipButton->isChecked())) return false; if(event->type() == QEvent::KeyPress || event->type() == QEvent::KeyRelease) @@ -317,6 +327,7 @@ bool Clipping_box_plugin::eventFilter(QObject *, QEvent *event) { viewer->enableClippingBox(planes); dock_widget->unclipButton->setEnabled(true); + dock_widget->clipButton->setChecked(false); visualizer = NULL; QApplication::restoreOverrideCursor(); static_cast(viewer)->set2DSelectionMode(false); diff --git a/Polyhedron/demo/Polyhedron/Plugins/PCA/Clipping_box_widget.ui b/Polyhedron/demo/Polyhedron/Plugins/PCA/Clipping_box_widget.ui index 220fa76978a..7c79e142124 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/PCA/Clipping_box_widget.ui +++ b/Polyhedron/demo/Polyhedron/Plugins/PCA/Clipping_box_widget.ui @@ -100,6 +100,16 @@ + + + + Clip + + + true + + + @@ -141,11 +151,22 @@ - - - Info: SHIFT+Click to clip. - - + + + + + Info: SHIFT+Click to clip + + + + + + + While "Clip" is toggled. + + + + From 2a261c1d2f2862859c4e69b790c618f2a964b435 Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Tue, 26 Mar 2019 15:24:28 +0100 Subject: [PATCH 2/4] Fix event filter problems --- .../Plugins/PCA/Clipping_box_plugin.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/Polyhedron/demo/Polyhedron/Plugins/PCA/Clipping_box_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/PCA/Clipping_box_plugin.cpp index 0b51141785a..b2cc16bce70 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/PCA/Clipping_box_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/PCA/Clipping_box_plugin.cpp @@ -87,7 +87,6 @@ void Clipping_box_plugin::init(QMainWindow* mainWindow, CGAL::Three::Scene_inter CGAL::QGLViewer* viewer = *CGAL::QGLViewer::QGLViewerPool().begin(); - viewer->installEventFilter(this); item = NULL; visualizer = NULL; shift_pressing = false; @@ -103,7 +102,10 @@ void Clipping_box_plugin::clipbox() } QApplication::setOverrideCursor(Qt::WaitCursor); if(!item) + { item = new Scene_edit_box_item(scene); + CGAL::QGLViewer::QGLViewerPool().first()->installEventFilter(item); + } connect(item, SIGNAL(destroyed()), this, SLOT(enableAction())); connect(item, &Scene_edit_box_item::aboutToBeDestroyed, @@ -116,7 +118,7 @@ void Clipping_box_plugin::clipbox() this, [this](){ dock_widget->unclipButton->setDisabled(true); CGAL::Three::Viewer_interface* viewer = static_cast( - *CGAL::QGLViewer::QGLViewerPool().begin()); + CGAL::QGLViewer::QGLViewerPool().first()); viewer->disableClippingBox(); viewer->update(); }); @@ -125,11 +127,6 @@ void Clipping_box_plugin::clipbox() item->setName("Clipping box"); item->setRenderingMode(FlatPlusEdges); CGAL::QGLViewer* viewer = *CGAL::QGLViewer::QGLViewerPool().begin(); - viewer->installEventFilter(item); - connect(dock_widget->clipButton, &QPushButton::toggled, - dock_widget->clipButton, [viewer](){ - viewer->setFocus(); - }); scene->addItem(item); actionClipbox->setEnabled(false); @@ -205,6 +202,12 @@ void Clipping_box_plugin::tab_change() item = NULL; } action->setChecked(true); + CGAL::QGLViewer* viewer = *CGAL::QGLViewer::QGLViewerPool().begin(); + connect(dock_widget->clipButton, &QPushButton::toggled, + this, [this, viewer](){ + viewer->setFocus(); + viewer->installEventFilter(this); + }); } else { From 1bd785ae44983dedee816e8ba1181260262fcb82 Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Tue, 26 Mar 2019 15:30:34 +0100 Subject: [PATCH 3/4] Don't select clipped points --- .../Plugins/PCA/Clipping_box_plugin.cpp | 3 -- .../Point_set/Point_set_selection_plugin.cpp | 34 +++++++++++++++++++ Polyhedron/demo/Polyhedron/Viewer.cpp | 10 ++++++ Polyhedron/demo/Polyhedron/Viewer.h | 2 ++ Three/include/CGAL/Three/Viewer_interface.h | 2 ++ 5 files changed, 48 insertions(+), 3 deletions(-) diff --git a/Polyhedron/demo/Polyhedron/Plugins/PCA/Clipping_box_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/PCA/Clipping_box_plugin.cpp index b2cc16bce70..a7209a9ac8d 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/PCA/Clipping_box_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/PCA/Clipping_box_plugin.cpp @@ -85,8 +85,6 @@ void Clipping_box_plugin::init(QMainWindow* mainWindow, CGAL::Three::Scene_inter connect(dock_widget->pushButton, SIGNAL(toggled(bool)), this, SLOT(clip(bool))); - CGAL::QGLViewer* viewer = *CGAL::QGLViewer::QGLViewerPool().begin(); - item = NULL; visualizer = NULL; shift_pressing = false; @@ -126,7 +124,6 @@ void Clipping_box_plugin::clipbox() this, &Clipping_box_plugin::tab_change); item->setName("Clipping box"); item->setRenderingMode(FlatPlusEdges); - CGAL::QGLViewer* viewer = *CGAL::QGLViewer::QGLViewerPool().begin(); scene->addItem(item); actionClipbox->setEnabled(false); diff --git a/Polyhedron/demo/Polyhedron/Plugins/Point_set/Point_set_selection_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/Point_set/Point_set_selection_plugin.cpp index f7623c9baba..5d6ac03f74f 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/Point_set/Point_set_selection_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/Point_set/Point_set_selection_plugin.cpp @@ -568,6 +568,31 @@ protected: } protected Q_SLOTS: + + bool is_inside(QVector4D* box, const Kernel::Point_3& p) + { + if(!static_cast(CGAL::QGLViewer::QGLViewerPool().first())->isClipping()){ + return true; + } + double x = p.x(), + y = p.y(), + z = p.z(); + + if(box[0][0]*x+box[0][1]*y+box[0][2]*z+box[0][3]>0) + return false; + if(box[1][0]*x+box[1][1]*y+box[1][2]*z+box[1][3]>0) + return false; + if(box[2][0]*x+box[2][1]*y+box[2][2]*z+box[2][3]>0) + return false; + if(box[3][0]*x+box[3][1]*y+box[3][2]*z+box[3][3]>0) + return false; + if(box[4][0]*x+box[4][1]*y+box[4][2]*z+box[4][3]>0) + return false; + if(box[5][0]*x+box[5][1]*y+box[5][2]*z+box[5][3]>0) + return false; + return true; + } + void select_points() { Scene_points_with_normal_item* point_set_item = getSelectedItem(); @@ -604,6 +629,15 @@ protected Q_SLOTS: [&] (const Point_set::Index& idx) -> bool { return !selected_bitmap[idx]; })); + QVector4D* clipbox = static_cast(viewer)->clipBox(); + for(Point_set::iterator it = points->first_selected(); + it != points->end(); + ++it) + { + if(!is_inside(clipbox, points->point(*it))) + points->unselect(*it); + } + point_set_item->invalidateOpenGLBuffers(); point_set_item->itemChanged(); } diff --git a/Polyhedron/demo/Polyhedron/Viewer.cpp b/Polyhedron/demo/Polyhedron/Viewer.cpp index 444e80d5dde..728464c6133 100644 --- a/Polyhedron/demo/Polyhedron/Viewer.cpp +++ b/Polyhedron/demo/Polyhedron/Viewer.cpp @@ -1683,5 +1683,15 @@ void Viewer::setGlPointSize(const GLfloat &p) { d->gl_point_size = p; } const GLfloat& Viewer::getGlPointSize() const { return d->gl_point_size; } +QVector4D* Viewer::clipBox() const +{ + return d->clipbox; +} + +bool Viewer::isClipping() const +{ + return d->clipping; +} + #include "Viewer.moc" diff --git a/Polyhedron/demo/Polyhedron/Viewer.h b/Polyhedron/demo/Polyhedron/Viewer.h index d86acdeb212..9e494475b05 100644 --- a/Polyhedron/demo/Polyhedron/Viewer.h +++ b/Polyhedron/demo/Polyhedron/Viewer.h @@ -154,6 +154,8 @@ public: float total_pass()Q_DECL_OVERRIDE; const GLfloat& getGlPointSize()const Q_DECL_OVERRIDE; void setGlPointSize(const GLfloat& p) Q_DECL_OVERRIDE; + QVector4D* clipBox() const Q_DECL_OVERRIDE; + bool isClipping() const Q_DECL_OVERRIDE; }; // end class Viewer diff --git a/Three/include/CGAL/Three/Viewer_interface.h b/Three/include/CGAL/Three/Viewer_interface.h index 84a65fb7617..72c5e8cb20d 100644 --- a/Three/include/CGAL/Three/Viewer_interface.h +++ b/Three/include/CGAL/Three/Viewer_interface.h @@ -276,6 +276,8 @@ public: virtual int currentPass()const = 0; virtual bool isDepthWriting()const = 0; virtual QOpenGLFramebufferObject* depthPeelingFbo() = 0; + virtual QVector4D* clipBox() const =0; + virtual bool isClipping() const = 0; }; // end class Viewer_interface } } From 71dc56756604d077e11044a39d1b440c29d18f86 Mon Sep 17 00:00:00 2001 From: Simon Giraudot Date: Wed, 27 Mar 2019 10:18:02 +0100 Subject: [PATCH 4/4] Integrate clipping test in selection functor --- .../Point_set/Point_set_selection_plugin.cpp | 65 +++++++++---------- 1 file changed, 30 insertions(+), 35 deletions(-) diff --git a/Polyhedron/demo/Polyhedron/Plugins/Point_set/Point_set_selection_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/Point_set/Point_set_selection_plugin.cpp index 5d6ac03f74f..8b6f4f59a26 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/Point_set/Point_set_selection_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/Point_set/Point_set_selection_plugin.cpp @@ -58,6 +58,7 @@ class Selection_test { const CGAL::qglviewer::Vec offset; Scene_edit_box_item* edit_box; Selection_visualizer* visualizer; + QVector4D* clipbox; const Ui::PointSetSelection& ui_widget; @@ -69,6 +70,7 @@ public: const CGAL::qglviewer::Vec offset, Scene_edit_box_item* edit_box, Selection_visualizer* visualizer, + QVector4D* clipbox, const Ui::PointSetSelection& ui_widget) : point_set (point_set) , selected (selected) @@ -76,6 +78,7 @@ public: , offset (offset) , edit_box (edit_box) , visualizer (visualizer) + , clipbox (clipbox) , ui_widget (ui_widget) { } @@ -91,8 +94,15 @@ public: void apply (std::size_t i) const { Point_set::Index idx = *(point_set->begin() + i); - const Kernel::Point_3& p = point_set->point (idx); + + // Points outside clipbox are not affected + if (!is_inside_clipbox (p)) + { + selected[idx] = point_set->is_selected (point_set->begin() + i); + return; + } + CGAL::qglviewer::Vec vp (p.x (), p.y (), p.z ()); bool now_selected = false; if(!ui_widget.box->isChecked()) @@ -127,6 +137,22 @@ public: selected[idx] = (already_selected && !now_selected); } } + + bool is_inside_clipbox (const Kernel::Point_3& p) const + { + if(!static_cast(CGAL::QGLViewer::QGLViewerPool().first())->isClipping()) + return true; + + double x = p.x(), y = p.y(), z = p.z(); + + return !(clipbox[0][0]*x+clipbox[0][1]*y+clipbox[0][2]*z+clipbox[0][3]>0 || + clipbox[1][0]*x+clipbox[1][1]*y+clipbox[1][2]*z+clipbox[1][3]>0 || + clipbox[2][0]*x+clipbox[2][1]*y+clipbox[2][2]*z+clipbox[2][3]>0 || + clipbox[3][0]*x+clipbox[3][1]*y+clipbox[3][2]*z+clipbox[3][3]>0 || + clipbox[4][0]*x+clipbox[4][1]*y+clipbox[4][2]*z+clipbox[4][3]>0 || + clipbox[5][0]*x+clipbox[5][1]*y+clipbox[5][2]*z+clipbox[5][3]>0); + } + }; @@ -569,30 +595,6 @@ protected: protected Q_SLOTS: - bool is_inside(QVector4D* box, const Kernel::Point_3& p) - { - if(!static_cast(CGAL::QGLViewer::QGLViewerPool().first())->isClipping()){ - return true; - } - double x = p.x(), - y = p.y(), - z = p.z(); - - if(box[0][0]*x+box[0][1]*y+box[0][2]*z+box[0][3]>0) - return false; - if(box[1][0]*x+box[1][1]*y+box[1][2]*z+box[1][3]>0) - return false; - if(box[2][0]*x+box[2][1]*y+box[2][2]*z+box[2][3]>0) - return false; - if(box[3][0]*x+box[3][1]*y+box[3][2]*z+box[3][3]>0) - return false; - if(box[4][0]*x+box[4][1]*y+box[4][2]*z+box[4][3]>0) - return false; - if(box[5][0]*x+box[5][1]*y+box[5][2]*z+box[5][3]>0) - return false; - return true; - } - void select_points() { Scene_points_with_normal_item* point_set_item = getSelectedItem(); @@ -615,7 +617,9 @@ protected Q_SLOTS: bool* selected_bitmap = new bool[points->size()]; // std::vector is not thread safe Selection_test selection_test (points, selected_bitmap, - camera, offset, edit_box, visualizer, ui_widget); + camera, offset, edit_box, visualizer, + static_cast(viewer)->clipBox(), + ui_widget); #ifdef CGAL_LINKED_WITH_TBB tbb::parallel_for(tbb::blocked_range(0, points->size()), selection_test); @@ -629,15 +633,6 @@ protected Q_SLOTS: [&] (const Point_set::Index& idx) -> bool { return !selected_bitmap[idx]; })); - QVector4D* clipbox = static_cast(viewer)->clipBox(); - for(Point_set::iterator it = points->first_selected(); - it != points->end(); - ++it) - { - if(!is_inside(clipbox, points->point(*it))) - points->unselect(*it); - } - point_set_item->invalidateOpenGLBuffers(); point_set_item->itemChanged(); }