clipping_box_plugin

This commit is contained in:
Maxime Gimeno 2018-09-27 10:52:56 +02:00
parent 56e58b8f99
commit bfce2fb06e
4 changed files with 86 additions and 65 deletions

View File

@ -1,6 +1,7 @@
#include <QtCore/qglobal.h>
#include <CGAL/Three/Scene_item.h>
#include <CGAL/Three/Scene_item.h>
#include <CGAL/Three/Three.h>
#include <CGAL/Three/Scene_interface.h>
#include "Scene_edit_box_item.h"
#include <CGAL/Three/Viewer_interface.h>
@ -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<Kernel> Mesh;
Viewer_interface* viewer = static_cast<Viewer_interface*>(*CGAL::QGLViewer::QGLViewerPool().begin());
if(b)
Q_FOREACH(CGAL::QGLViewer* v, CGAL::QGLViewer::QGLViewerPool())
{
if(!item)
CGAL::Three::Viewer_interface* viewer =
qobject_cast<CGAL::Three::Viewer_interface*>(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"

View File

@ -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);

View File

@ -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<CGAL::Three::Viewer_interface*, bool> is_init;
QMap<CGAL::Three::Viewer_interface*, bool> 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;
}

View File

@ -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`.