diff --git a/Polyhedron/demo/Polyhedron/Plugins/PCA/Clipping_box_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/PCA/Clipping_box_plugin.cpp index 4dde5cd50e2..dc2d6e7f167 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/PCA/Clipping_box_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/PCA/Clipping_box_plugin.cpp @@ -1,6 +1,7 @@ #include -#include +#include +#include #include #include "Scene_edit_box_item.h" #include @@ -52,6 +53,11 @@ public Q_SLOTS: void enableAction(); void clipbox(); void clip(bool); + void connectNewViewer(QObject* o) + { + if(item) + o->installEventFilter(item); + } private: QAction* actionClipbox; ClipWidget* dock_widget; @@ -72,6 +78,8 @@ void Clipping_box_plugin::init(QMainWindow* mainWindow, CGAL::Three::Scene_inter connect(dock_widget->pushButton, SIGNAL(toggled(bool)), this, SLOT(clip(bool))); item = NULL; + connect(mw, SIGNAL(newViewerCreated(QObject*)), + this, SLOT(connectNewViewer(QObject*))); } void Clipping_box_plugin::clipbox() @@ -96,8 +104,8 @@ dock_widget->show(); }); item->setName("Clipping box"); item->setRenderingMode(FlatPlusEdges); - CGAL::QGLViewer* viewer = *CGAL::QGLViewer::QGLViewerPool().begin(); - viewer->installEventFilter(item); + Q_FOREACH(CGAL::QGLViewer* viewer, CGAL::QGLViewer::QGLViewerPool()) + viewer->installEventFilter(item); scene->addItem(item); actionClipbox->setEnabled(false); @@ -113,53 +121,58 @@ void Clipping_box_plugin::clip(bool b) { typedef CGAL::Epick Kernel; typedef CGAL::Polyhedron_3 Mesh; - Viewer_interface* viewer = static_cast(*CGAL::QGLViewer::QGLViewerPool().begin()); - if(b) + + Q_FOREACH(CGAL::QGLViewer* v, CGAL::QGLViewer::QGLViewerPool()) { - if(!item) + CGAL::Three::Viewer_interface* viewer = + qobject_cast(v); + if(b) { - dock_widget->hide(); - return; + if(!item) + { + dock_widget->hide(); + return; + } + Mesh m; + Kernel::Point_3 points[8]; + for(int i=0; i<8; ++i) + { + points[i] = Kernel::Point_3(item->point(i,0),item->point(i,1), item->point(i,2)); + } + CGAL::make_hexahedron( + points[0], + points[3], + points[2], + points[1], + points[5], + points[4], + points[7], + points[6], + m); + QVector4D planes[6]; + int fid=0; + BOOST_FOREACH(Mesh::Facet_iterator f, faces(m)) + { + Kernel::Vector_3 normal = CGAL::Polygon_mesh_processing::compute_face_normal(f,m); + double norm = normal.squared_length()*normal.squared_length(); + Kernel::Plane_3 plane(f->halfedge()->vertex()->point(), 1.1*normal/norm); + planes[fid++] = QVector4D(plane.a(), + plane.b(), + plane.c(), + plane.d()); + } + viewer->enableClippingBox(planes); } - Mesh m; - Kernel::Point_3 points[8]; - for(int i=0; i<8; ++i) + else { - points[i] = Kernel::Point_3(item->point(i,0),item->point(i,1), item->point(i,2)); + viewer->disableClippingBox(); + if(!item) + { + dock_widget->hide(); + } } - CGAL::make_hexahedron( - points[0], - points[3], - points[2], - points[1], - points[5], - points[4], - points[7], - points[6], - m); - QVector4D planes[6]; - int fid=0; - BOOST_FOREACH(Mesh::Facet_iterator f, faces(m)) - { - Kernel::Vector_3 normal = CGAL::Polygon_mesh_processing::compute_face_normal(f,m); - double norm = normal.squared_length()*normal.squared_length(); - Kernel::Plane_3 plane(f->halfedge()->vertex()->point(), 1.1*normal/norm); - planes[fid++] = QVector4D(plane.a(), - plane.b(), - plane.c(), - plane.d()); - } - viewer->enableClippingBox(planes); + viewer->update(); } - else - { - viewer->disableClippingBox(); - if(!item) - { - dock_widget->hide(); - } - } - viewer->update(); } #include "Clipping_box_plugin.moc" diff --git a/Polyhedron/demo/Polyhedron/Plugins/PCA/Scene_edit_box_item.cpp b/Polyhedron/demo/Polyhedron/Plugins/PCA/Scene_edit_box_item.cpp index afe650b979b..f36a7f5f4ce 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/PCA/Scene_edit_box_item.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/PCA/Scene_edit_box_item.cpp @@ -317,8 +317,8 @@ void Scene_edit_box_item::drawSpheres(Viewer_interface *viewer, const QMatrix4x4 Tc* tc = getTriangleContainer(Priv::Spheres); tc->setFrameMatrix(f_matrix); tc->setMvMatrix(mv_mat); + tc->setClipping(false); tc->getVao(viewer)->bind(); - tc->getVao(viewer)->program->setUniformValue("is_clipbox_on", false); tc->getVao(viewer)->program->setAttributeValue("radius",radius); tc->getVao(viewer)->release(); tc->setColor(QColor(Qt::red)); @@ -375,9 +375,7 @@ void Scene_edit_box_item::drawEdges(Viewer_interface* viewer) const ec->setViewport(vp); ec->setWidth(6.0f); } - ec->getVao(viewer)->bind(); - ec->getVao(viewer)->program->setUniformValue("is_clipbox_on", false); - ec->getVao(viewer)->release(); + ec->setClipping(false); ec->setFrameMatrix(f_matrix); ec->setColor(QColor(Qt::black)); ec->draw(viewer, true); @@ -906,9 +904,7 @@ void Scene_edit_box_item_priv::draw_picking(Viewer_interface* viewer) { Tc* tc = item->getTriangleContainer(P_Faces); tc->setFrameMatrix(f_matrix); - tc->getVao(viewer)->bind(); - tc->getVao(viewer)->program->setUniformValue("is_clipbox_on", false); - tc->getVao(viewer)->release(); + tc->setClipping(false); tc->draw(viewer, false); } double radius =std::sqrt( @@ -917,8 +913,8 @@ void Scene_edit_box_item_priv::draw_picking(Viewer_interface* viewer) (item->point(6,2) - item->point(0,2)) * (item->point(6,2) - item->point(0,2))) *0.02 ; Tc* tc = item->getTriangleContainer(P_Spheres); tc->setFrameMatrix(f_matrix); + tc->setClipping(false); tc->getVao(viewer)->bind(); - tc->getVao(viewer)->program->setUniformValue("is_clipbox_on", false); tc->getVao(viewer)->program->setAttributeValue("radius", (float)radius); tc->getVao(viewer)->release(); tc->draw(viewer, false); @@ -932,9 +928,7 @@ void Scene_edit_box_item_priv::draw_picking(Viewer_interface* viewer) ec->setWidth(6.0f); } ec->setFrameMatrix(f_matrix); - ec->getVao(viewer)->bind(); - ec->getVao(viewer)->program->setUniformValue("is_clipbox_on", false); - ec->getVao(viewer)->release(); + ec->setClipping(false); ec->draw(viewer, false); } @@ -1117,9 +1111,9 @@ void Scene_edit_box_item::drawHl(Viewer_interface* viewer)const (point(6,0) - point(0,0)) * (point(6,0) - point(0,0)) + (point(6,1) - point(0,1)) * (point(6,1) - point(0,1)) + (point(6,2) - point(0,2)) * (point(6,2) - point(0,2))) *0.02 ; + tc->setClipping(false); tc->getVao(viewer)->bind(); tc->getVao(viewer)->program->setUniformValue("radius", (float)radius); - tc->getVao(viewer)->program->setUniformValue("is_clipbox_on", false); tc->getVao(viewer)->release(); tc->draw(viewer, true); } @@ -1132,9 +1126,7 @@ void Scene_edit_box_item::drawHl(Viewer_interface* viewer)const ec->setViewport(vp); ec->setWidth(6.0f); } - ec->getVao(viewer)->bind(); - ec->getVao(viewer)->program->setUniformValue("is_clipbox_on", false); - ec->getVao(viewer)->release(); + ec->setClipping(false); ec->setFrameMatrix(f_matrix); ec->setColor(QColor(Qt::yellow)); ec->draw(viewer, true); @@ -1149,9 +1141,7 @@ void Scene_edit_box_item::drawHl(Viewer_interface* viewer)const Tc* tc = getTriangleContainer(Priv::S_Faces); tc->setMvMatrix(mv_mat); tc->setFrameMatrix(f_matrix); - tc->getVao(viewer)->bind(); - tc->getVao(viewer)->program->setUniformValue("is_clipbox_on", false); - tc->getVao(viewer)->release(); + tc->setClipping(false); tc->setColor(QColor(Qt::yellow)); tc->setAlpha(0.5); @@ -1194,9 +1184,7 @@ void Scene_edit_box_item::drawTransparent(CGAL::Three::Viewer_interface*viewer)c Tc* tc = getTriangleContainer(Priv::Faces); tc->setMvMatrix(mv_mat); tc->setFrameMatrix(f_matrix); - tc->getVao(viewer)->bind(); - tc->getVao(viewer)->program->setUniformValue("is_clipbox_on", false); - tc->getVao(viewer)->release(); + tc->setClipping(false); tc->setColor(QColor(128,128,128,128)); tc->setAlpha(0.5); tc->draw(viewer, true); diff --git a/Polyhedron/demo/Polyhedron/Primitive_container.cpp b/Polyhedron/demo/Polyhedron/Primitive_container.cpp index ae8fd561401..509f6b8c3e0 100755 --- a/Polyhedron/demo/Polyhedron/Primitive_container.cpp +++ b/Polyhedron/demo/Polyhedron/Primitive_container.cpp @@ -7,6 +7,7 @@ struct D program_id(program), indexed(indexed), is_selected(false), + clipping(true), flat_size(0), idx_size(0), tuple_size(3), @@ -26,6 +27,7 @@ struct D QMap is_init; QMap is_gl_init; bool is_selected; + bool clipping; std::size_t flat_size; std::size_t center_size; std::size_t idx_size; @@ -58,6 +60,9 @@ void Primitive_container::bindUniformValues(CGAL::Three::Viewer_interface* viewe viewer->getShaderProgram(d->program_id)->setUniformValue("is_selected", true); else viewer->getShaderProgram(d->program_id)->setUniformValue("is_selected", false); + //override clipping if necessary + if(!d->clipping) + viewer->getShaderProgram(d->program_id)->setUniformValue("is_clipbox_on", false); viewer->getShaderProgram(d->program_id)->release(); } @@ -264,3 +269,13 @@ QSize Primitive_container::getTextureSize() const { return QSize(d->texture->Width, d->texture->Height); } + +bool Primitive_container::getClipping() const +{ + return d->clipping; +} + +void Primitive_container::setClipping(bool b) +{ + d->clipping = b; +} diff --git a/Three/include/CGAL/Three/Primitive_container.h b/Three/include/CGAL/Three/Primitive_container.h index 82d76edef90..a707d3bc19f 100755 --- a/Three/include/CGAL/Three/Primitive_container.h +++ b/Three/include/CGAL/Three/Primitive_container.h @@ -170,6 +170,9 @@ public: void setOffset(std::size_t id, int offset); //!setter for the tuple size: the number of coordinates of one vertex. void setTupleSize(int ts); + //!setter for the clipping. If `b` is `false`, then the clipping box will have no effect. + void setClipping(bool b); + //!@} //! @@ -220,6 +223,8 @@ public: GLuint getTextureId() const; //! getter for the size of the texture. QSize getTextureSize() const; + //! getter for the clipping. Default is `true`. + bool getClipping() const; //! //!Use this to specify if the container `Vbo`s are filled for `viewer`.