mirror of https://github.com/CGAL/cgal
Merge pull request #1613 from maxGimeno/Polyhedron_demo-Edit_box_plugin-GF
Polyhedron_demo: Edit box plugin
This commit is contained in:
commit
38bcd090f0
|
|
@ -221,6 +221,7 @@ if(CGAL_Qt5_FOUND AND Qt5_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND)
|
|||
target_link_libraries(scene_c3t3_item scene_polyhedron_item scene_polygon_soup_item scene_basic_objects ${TBB_LIBRARIES})
|
||||
add_item(scene_polyhedron_item Scene_polyhedron_item.cpp)
|
||||
add_item(scene_polyhedron_transform_item Plugins/PCA/Scene_polyhedron_transform_item.cpp )
|
||||
add_item(scene_edit_box_item Plugins/PCA/Scene_edit_box_item.cpp )
|
||||
add_item(scene_image_item Scene_image_item.cpp)
|
||||
|
||||
# special
|
||||
|
|
|
|||
|
|
@ -6,7 +6,8 @@ qt5_wrap_ui( transformUI_FILES Transformation_widget.ui )
|
|||
polyhedron_demo_plugin(affine_transform_plugin Affine_transform_plugin ${transformUI_FILES})
|
||||
target_link_libraries(affine_transform_plugin scene_polyhedron_item scene_polyhedron_transform_item scene_points_with_normal_item)
|
||||
|
||||
polyhedron_demo_plugin(trivial_plugin Trivial_plugin)
|
||||
polyhedron_demo_plugin(edit_box_plugin Edit_box_plugin)
|
||||
target_link_libraries(edit_box_plugin scene_edit_box_item scene_polyhedron_item)
|
||||
|
||||
polyhedron_demo_plugin(create_bbox_mesh_plugin Create_bbox_mesh_plugin)
|
||||
target_link_libraries(create_bbox_mesh_plugin scene_polyhedron_item)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,135 @@
|
|||
#include <QtCore/qglobal.h>
|
||||
|
||||
#include <CGAL/Three/Scene_item.h>
|
||||
#include <CGAL/Three/Scene_interface.h>
|
||||
#include "Scene_edit_box_item.h"
|
||||
#include "Scene_polyhedron_item.h"
|
||||
#include <CGAL/Three/Viewer_interface.h>
|
||||
#include <CGAL/boost/graph/helpers.h>
|
||||
#include <QAction>
|
||||
#include <QMainWindow>
|
||||
#include <QApplication>
|
||||
|
||||
|
||||
#include <CGAL/Three/Polyhedron_demo_plugin_interface.h>
|
||||
#include <CGAL/Polygon_mesh_processing/triangulate_faces.h>
|
||||
using namespace CGAL::Three;
|
||||
class Edit_box_plugin :
|
||||
public QObject,
|
||||
public Polyhedron_demo_plugin_interface
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(CGAL::Three::Polyhedron_demo_plugin_interface)
|
||||
Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.PluginInterface/1.0")
|
||||
|
||||
public:
|
||||
void init(QMainWindow* mainWindow, CGAL::Three::Scene_interface* scene_interface, Messages_interface*);
|
||||
QList<QAction*> actions() const {
|
||||
return QList<QAction*>() << actionBbox
|
||||
<< actionExport;
|
||||
}
|
||||
|
||||
bool applicable(QAction* a) const {
|
||||
if(a==actionBbox &&scene->numberOfEntries() > 0)
|
||||
return true;
|
||||
else if(a==actionExport )
|
||||
{
|
||||
for(int i = 0, end = scene->numberOfEntries();
|
||||
i < end; ++i)
|
||||
{
|
||||
if(qobject_cast<Scene_edit_box_item*>(scene->item(i)))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;}
|
||||
public Q_SLOTS:
|
||||
|
||||
void bbox();
|
||||
void enableAction();
|
||||
void exportToPoly();
|
||||
|
||||
private:
|
||||
CGAL::Three::Scene_interface* scene;
|
||||
QAction* actionBbox;
|
||||
QAction* actionExport;
|
||||
|
||||
|
||||
}; // end Edit_box_plugin
|
||||
|
||||
void Edit_box_plugin::init(QMainWindow* mainWindow, CGAL::Three::Scene_interface* scene_interface, Messages_interface*)
|
||||
{
|
||||
scene = scene_interface;
|
||||
actionBbox = new QAction(tr("Create Bbox"), mainWindow);
|
||||
connect(actionBbox, SIGNAL(triggered()),
|
||||
this, SLOT(bbox()));
|
||||
actionExport = new QAction(tr("Export to Polyhedron item"), mainWindow);
|
||||
connect(actionExport, SIGNAL(triggered()),
|
||||
this, SLOT(exportToPoly()));
|
||||
}
|
||||
|
||||
void Edit_box_plugin::bbox()
|
||||
{
|
||||
for(int i = 0, end = scene->numberOfEntries();
|
||||
i < end; ++i)
|
||||
{
|
||||
if(qobject_cast<Scene_edit_box_item*>(scene->item(i)))
|
||||
return;
|
||||
}
|
||||
QApplication::setOverrideCursor(Qt::WaitCursor);
|
||||
Scene_edit_box_item* item = new Scene_edit_box_item(scene);
|
||||
connect(item, SIGNAL(destroyed()),
|
||||
this, SLOT(enableAction()));
|
||||
item->setName("Edit box");
|
||||
item->setRenderingMode(FlatPlusEdges);
|
||||
QGLViewer* viewer = *QGLViewer::QGLViewerPool().begin();
|
||||
viewer->installEventFilter(item);
|
||||
scene->addItem(item);
|
||||
actionBbox->setEnabled(false);
|
||||
|
||||
QApplication::restoreOverrideCursor();
|
||||
}
|
||||
|
||||
void Edit_box_plugin::enableAction() {
|
||||
actionBbox->setEnabled(true);
|
||||
}
|
||||
|
||||
void Edit_box_plugin::exportToPoly()
|
||||
{
|
||||
int id =0;
|
||||
Scene_edit_box_item* item = NULL;
|
||||
for(int i = 0, end = scene->numberOfEntries();
|
||||
i < end; ++i)
|
||||
{
|
||||
item = qobject_cast<Scene_edit_box_item*>(scene->item(i));
|
||||
if(item)
|
||||
{
|
||||
id = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
Polyhedron::Point_3 points[8];
|
||||
for(int i=0; i<8; ++i)
|
||||
{
|
||||
points[i] = Polyhedron::Point_3(item->point(i,0),item->point(i,1), item->point(i,2));
|
||||
}
|
||||
Scene_polyhedron_item* poly_item = new Scene_polyhedron_item();
|
||||
CGAL::make_hexahedron(
|
||||
points[0],
|
||||
points[1],
|
||||
points[2],
|
||||
points[3],
|
||||
points[4],
|
||||
points[5],
|
||||
points[6],
|
||||
points[7],
|
||||
*poly_item->polyhedron());
|
||||
CGAL::Polygon_mesh_processing::triangulate_faces(*poly_item->polyhedron());
|
||||
item->setName("Edit box");
|
||||
item->setRenderingMode(FlatPlusEdges);
|
||||
scene->replaceItem(id, poly_item, true);
|
||||
item->deleteLater();
|
||||
actionBbox->setEnabled(true);
|
||||
}
|
||||
#include "Edit_box_plugin.moc"
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,52 @@
|
|||
#ifndef SCENE_EDIT_BOX_ITEM_H
|
||||
#define SCENE_EDIT_BOX_ITEM_H
|
||||
|
||||
#include <CGAL/Three/Scene_item.h>
|
||||
#include <CGAL/Simple_cartesian.h>
|
||||
#include "create_sphere.h"
|
||||
#include "Scene_edit_box_item_config.h"
|
||||
struct Scene_edit_box_item_priv;
|
||||
class SCENE_EDIT_BOX_ITEM_EXPORT Scene_edit_box_item: public CGAL::Three::Scene_item
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
typedef CGAL::Simple_cartesian<double> Kernel;
|
||||
struct vertex;
|
||||
struct edge;
|
||||
struct face;
|
||||
Scene_edit_box_item(const CGAL::Three::Scene_interface* scene_interface);
|
||||
~Scene_edit_box_item();
|
||||
bool isFinite() const { return true; }
|
||||
bool isEmpty() const { return false; }
|
||||
void compute_bbox() const;
|
||||
|
||||
bool manipulatable() const { return true; }
|
||||
ManipulatedFrame* manipulatedFrame();
|
||||
Scene_edit_box_item* clone() const {
|
||||
return 0;
|
||||
}
|
||||
|
||||
QString toolTip() const;
|
||||
|
||||
bool eventFilter(QObject *, QEvent *);
|
||||
// Indicate if rendering mode is supported
|
||||
bool supportsRenderingMode(RenderingMode m) const;
|
||||
void draw(CGAL::Three::Viewer_interface *) const;
|
||||
void drawHl(CGAL::Three::Viewer_interface *) const;
|
||||
void drawEdges(CGAL::Three::Viewer_interface* viewer) const;
|
||||
void drawSpheres(CGAL::Three::Viewer_interface* viewer, const QMatrix4x4 f_matrix) const;
|
||||
void invalidateOpenGLBuffers()
|
||||
{
|
||||
compute_bbox();
|
||||
are_buffers_filled = false;
|
||||
}
|
||||
double point(short i, short j) const;
|
||||
|
||||
public Q_SLOTS:
|
||||
void highlight();
|
||||
void clearHL();
|
||||
protected:
|
||||
friend struct Scene_edit_box_item_priv;
|
||||
Scene_edit_box_item_priv* d;
|
||||
};
|
||||
#endif // SCENE_EDIT_BOX_ITEM_H
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
#ifndef SCENE_EDIT_BOX_ITEM_CONFIG_H
|
||||
#define SCENE_EDIT_BOX_ITEM_CONFIG_H
|
||||
|
||||
#ifdef scene_edit_box_item_EXPORTS
|
||||
# define SCENE_EDIT_BOX_ITEM_EXPORT Q_DECL_EXPORT
|
||||
#else
|
||||
# define SCENE_EDIT_BOX_ITEM_EXPORT Q_DECL_IMPORT
|
||||
#endif
|
||||
|
||||
#endif // SCENE_EDIT_BOX_ITEM_CONFIG_H
|
||||
|
|
@ -1,205 +0,0 @@
|
|||
#include <QtCore/qglobal.h>
|
||||
|
||||
#include <CGAL/Three/Scene_item.h>
|
||||
#include <CGAL/Three/Scene_interface.h>
|
||||
#include <CGAL/gl.h>
|
||||
|
||||
#include <CGAL/Three/Viewer_interface.h>
|
||||
#include <QAction>
|
||||
#include <QMainWindow>
|
||||
#include <QApplication>
|
||||
|
||||
class Q_DECL_EXPORT Scene_bbox_item : public CGAL::Three::Scene_item
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
Scene_bbox_item(const CGAL::Three::Scene_interface* scene_interface)
|
||||
: Scene_item(1,1), scene(scene_interface)
|
||||
|
||||
{
|
||||
positions_lines.resize(0);
|
||||
are_buffers_filled = false;
|
||||
}
|
||||
~Scene_bbox_item()
|
||||
{
|
||||
}
|
||||
bool isFinite() const { return true; }
|
||||
bool isEmpty() const { return true; }
|
||||
void compute_bbox() const { _bbox = scene->bbox(); }
|
||||
|
||||
Scene_bbox_item* clone() const {
|
||||
return 0;
|
||||
}
|
||||
|
||||
QString toolTip() const {
|
||||
const Bbox& bb = scene->bbox();
|
||||
return QString("<p><b>Scene bounding box</b></p>"
|
||||
"<p>x range: (%1, %2)<br />"
|
||||
"y range: (%3, %4)<br />"
|
||||
"z range: (%5, %6)</p>")
|
||||
.arg(bb.xmin()).arg(bb.xmax())
|
||||
.arg(bb.ymin()).arg(bb.ymax())
|
||||
.arg(bb.zmin()).arg(bb.zmax());
|
||||
}
|
||||
|
||||
// Indicate if rendering mode is supported
|
||||
bool supportsRenderingMode(RenderingMode m) const {
|
||||
return (m == Wireframe);
|
||||
}
|
||||
|
||||
void drawEdges(CGAL::Three::Viewer_interface* viewer) const
|
||||
{
|
||||
if(!are_buffers_filled)
|
||||
{
|
||||
computeElements();
|
||||
initializeBuffers(viewer);
|
||||
}
|
||||
vaos[0]->bind();
|
||||
program = getShaderProgram(PROGRAM_WITHOUT_LIGHT);
|
||||
attribBuffers(viewer, PROGRAM_WITHOUT_LIGHT);
|
||||
program->bind();
|
||||
program->setAttributeValue("colors", this->color());
|
||||
viewer->glDrawArrays(GL_LINES, 0, static_cast<GLsizei>(positions_lines.size()/3));
|
||||
vaos[0]->release();
|
||||
program->release();
|
||||
|
||||
}
|
||||
|
||||
void invalidateOpenGLBuffers()
|
||||
{
|
||||
compute_bbox();
|
||||
are_buffers_filled = false;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
mutable std::vector<float> positions_lines;
|
||||
mutable QOpenGLShaderProgram *program;
|
||||
using CGAL::Three::Scene_item::initializeBuffers;
|
||||
void initializeBuffers(CGAL::Three::Viewer_interface *viewer)const
|
||||
{
|
||||
|
||||
//vao containing the data for the lines
|
||||
{
|
||||
program = getShaderProgram(PROGRAM_WITHOUT_LIGHT, viewer);
|
||||
program->bind();
|
||||
|
||||
vaos[0]->bind();
|
||||
buffers[0].bind();
|
||||
buffers[0].allocate(positions_lines.data(),
|
||||
static_cast<GLsizei>(positions_lines.size()*sizeof(float)));
|
||||
program->enableAttributeArray("vertex");
|
||||
program->setAttributeBuffer("vertex",GL_FLOAT,0,3);
|
||||
buffers[0].release();
|
||||
|
||||
vaos[0]->release();
|
||||
program->release();
|
||||
|
||||
}
|
||||
are_buffers_filled = true;
|
||||
}
|
||||
|
||||
void computeElements() const
|
||||
{
|
||||
QApplication::setOverrideCursor(Qt::WaitCursor);
|
||||
positions_lines.clear();
|
||||
const Bbox& bb = scene->bbox();
|
||||
positions_lines.push_back(bb.xmin()); positions_lines.push_back(bb.ymin()); positions_lines.push_back(bb.zmin());
|
||||
positions_lines.push_back(bb.xmax()); positions_lines.push_back(bb.ymin()); positions_lines.push_back(bb.zmin());
|
||||
positions_lines.push_back(bb.xmin()); positions_lines.push_back(bb.ymin()); positions_lines.push_back(bb.zmin());
|
||||
positions_lines.push_back(bb.xmin()); positions_lines.push_back(bb.ymax()); positions_lines.push_back(bb.zmin());
|
||||
positions_lines.push_back(bb.xmin()); positions_lines.push_back(bb.ymin()); positions_lines.push_back(bb.zmin());
|
||||
positions_lines.push_back(bb.xmin()); positions_lines.push_back(bb.ymin()); positions_lines.push_back(bb.zmax());
|
||||
|
||||
positions_lines.push_back(bb.xmax()); positions_lines.push_back(bb.ymin()); positions_lines.push_back(bb.zmin());
|
||||
positions_lines.push_back(bb.xmax()); positions_lines.push_back(bb.ymax()); positions_lines.push_back(bb.zmin());
|
||||
positions_lines.push_back(bb.xmax()); positions_lines.push_back(bb.ymin()); positions_lines.push_back(bb.zmin());
|
||||
positions_lines.push_back(bb.xmax()); positions_lines.push_back(bb.ymin()); positions_lines.push_back(bb.zmax());
|
||||
|
||||
positions_lines.push_back(bb.xmin()); positions_lines.push_back(bb.ymax()); positions_lines.push_back(bb.zmin());
|
||||
positions_lines.push_back(bb.xmax()); positions_lines.push_back(bb.ymax()); positions_lines.push_back(bb.zmin());
|
||||
positions_lines.push_back(bb.xmin()); positions_lines.push_back(bb.ymax()); positions_lines.push_back(bb.zmin());
|
||||
positions_lines.push_back(bb.xmin()); positions_lines.push_back(bb.ymax()); positions_lines.push_back(bb.zmax());
|
||||
|
||||
positions_lines.push_back(bb.xmin()); positions_lines.push_back(bb.ymin()); positions_lines.push_back(bb.zmax());
|
||||
positions_lines.push_back(bb.xmax()); positions_lines.push_back(bb.ymin()); positions_lines.push_back(bb.zmax());
|
||||
positions_lines.push_back(bb.xmin()); positions_lines.push_back(bb.ymin()); positions_lines.push_back(bb.zmax());
|
||||
positions_lines.push_back(bb.xmin()); positions_lines.push_back(bb.ymax()); positions_lines.push_back(bb.zmax());
|
||||
|
||||
positions_lines.push_back(bb.xmax()); positions_lines.push_back(bb.ymax()); positions_lines.push_back(bb.zmax());
|
||||
positions_lines.push_back(bb.xmin()); positions_lines.push_back(bb.ymax()); positions_lines.push_back(bb.zmax());
|
||||
positions_lines.push_back(bb.xmax()); positions_lines.push_back(bb.ymax()); positions_lines.push_back(bb.zmax());
|
||||
positions_lines.push_back(bb.xmax()); positions_lines.push_back(bb.ymin()); positions_lines.push_back(bb.zmax());
|
||||
positions_lines.push_back(bb.xmax()); positions_lines.push_back(bb.ymax()); positions_lines.push_back(bb.zmax());
|
||||
positions_lines.push_back(bb.xmax()); positions_lines.push_back(bb.ymax()); positions_lines.push_back(bb.zmin());
|
||||
QApplication::restoreOverrideCursor();
|
||||
}
|
||||
|
||||
const CGAL::Three::Scene_interface* scene;
|
||||
};
|
||||
|
||||
#include <CGAL/Three/Polyhedron_demo_plugin_interface.h>
|
||||
using namespace CGAL::Three;
|
||||
class Polyhedron_demo_trivial_plugin :
|
||||
public QObject,
|
||||
public Polyhedron_demo_plugin_interface
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(CGAL::Three::Polyhedron_demo_plugin_interface)
|
||||
Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.PluginInterface/1.0")
|
||||
|
||||
public:
|
||||
void init(QMainWindow* mainWindow, CGAL::Three::Scene_interface* scene_interface, Messages_interface*);
|
||||
QList<QAction*> actions() const {
|
||||
return QList<QAction*>() << actionBbox;
|
||||
}
|
||||
|
||||
bool applicable(QAction*) const {
|
||||
if(scene->numberOfEntries() > 0)
|
||||
return true;
|
||||
return false;}
|
||||
public Q_SLOTS:
|
||||
|
||||
void bbox();
|
||||
void enableAction();
|
||||
|
||||
private:
|
||||
CGAL::Three::Scene_interface* scene;
|
||||
QAction* actionBbox;
|
||||
|
||||
|
||||
}; // end Polyhedron_demo_trivial_plugin
|
||||
|
||||
void Polyhedron_demo_trivial_plugin::init(QMainWindow* mainWindow, CGAL::Three::Scene_interface* scene_interface, Messages_interface*)
|
||||
{
|
||||
scene = scene_interface;
|
||||
actionBbox = new QAction(tr("Create Bbox"), mainWindow);
|
||||
connect(actionBbox, SIGNAL(triggered()),
|
||||
this, SLOT(bbox()));
|
||||
}
|
||||
|
||||
void Polyhedron_demo_trivial_plugin::bbox()
|
||||
{
|
||||
for(int i = 0, end = scene->numberOfEntries();
|
||||
i < end; ++i)
|
||||
{
|
||||
if(qobject_cast<Scene_bbox_item*>(scene->item(i)))
|
||||
return;
|
||||
}
|
||||
QApplication::setOverrideCursor(Qt::WaitCursor);
|
||||
Scene_item* item = new Scene_bbox_item(scene);
|
||||
connect(item, SIGNAL(destroyed()),
|
||||
this, SLOT(enableAction()));
|
||||
item->setName("Scene bbox");
|
||||
item->setColor(Qt::black);
|
||||
item->setRenderingMode(Wireframe);
|
||||
scene->addItem(item);
|
||||
actionBbox->setEnabled(false);
|
||||
QApplication::restoreOverrideCursor();
|
||||
}
|
||||
|
||||
void Polyhedron_demo_trivial_plugin::enableAction() {
|
||||
actionBbox->setEnabled(true);
|
||||
}
|
||||
|
||||
#include "Trivial_plugin.moc"
|
||||
|
|
@ -47,4 +47,7 @@
|
|||
<file>resources/euler_facet.png</file>
|
||||
<file>resources/euler_vertex.png</file>
|
||||
</qresource>
|
||||
<qresource prefix="/cgal/cursors">
|
||||
<file>resources/rotate_around_cursor.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
|
|
|||
Binary file not shown.
|
After Width: | Height: | Size: 1.2 KiB |
Loading…
Reference in New Issue