diff --git a/Polyhedron/demo/Polyhedron/Plugins/PCA/Clipping_box_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/PCA/Clipping_box_plugin.cpp index 49a7bd3e090..a7209a9ac8d 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/PCA/Clipping_box_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/PCA/Clipping_box_plugin.cpp @@ -70,17 +70,21 @@ 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; shift_pressing = false; @@ -95,10 +99,11 @@ 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); + CGAL::QGLViewer::QGLViewerPool().first()->installEventFilter(item); + } connect(item, SIGNAL(destroyed()), this, SLOT(enableAction())); connect(item, &Scene_edit_box_item::aboutToBeDestroyed, @@ -111,7 +116,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(); }); @@ -119,8 +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(); - viewer->installEventFilter(item); scene->addItem(item); actionClipbox->setEnabled(false); @@ -196,6 +199,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 { @@ -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. + + + + 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..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); + } + }; @@ -568,6 +594,7 @@ protected: } protected Q_SLOTS: + void select_points() { Scene_points_with_normal_item* point_set_item = getSelectedItem(); @@ -590,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); 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 } }