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 } }