#include <QApplication>
#include <QMainWindow>
#include <QAction>
#include <QVector>
#include <CGAL/Three/Scene_item.h>
#include <CGAL/Three/Viewer_interface.h>
#include <CGAL/Three/Scene_group_item.h>
#ifdef scene_triangle_item_EXPORTS
# define SCENE_TRIANGLE_ITEM_EXPORT Q_DECL_EXPORT
#else
# define SCENE_TRIANGLE_ITEM_EXPORT Q_DECL_IMPORT
#endif
{
Q_OBJECT
public :
Scene_triangle_item(double ax,double ay, double az,
double bx,double by, double bz,
double cx,double cy, double cz);
}
double bx,double by, double bz,
double cx,double cy, double cz) const Q_DECL_OVERRIDE;
Scene_item*
clone()
const Q_DECL_OVERRIDE {
return 0;}
QString
toolTip()
const Q_DECL_OVERRIDE {
return QString();}
private:
mutable std::vector<float> vertices;
mutable int nb_pos;
mutable QOpenGLShaderProgram *program;
};
Scene_triangle_item::Scene_triangle_item(double ax,double ay, double az,
double bx,double by, double bz,
double cx,double cy, double cz)
{
nb_pos = 0;
are_buffers_filled = false;
bx, by, bz,
cx, cy, cz);
}
void Scene_triangle_item::computeElements(double ax, double ay, double az,
double bx, double by, double bz,
double cx, double cy, double cz)const
{
vertices.resize(9);
vertices[0] = ax; vertices[1] = ay; vertices[2] = az;
vertices[3] = bx; vertices[4] = by; vertices[5] = bz;
vertices[6] = cx; vertices[7] = cy; vertices[8] = cz;
}
{
if(!are_buffers_filled)
{
1, 0, 0,
0.5, 0.5, 0);
}
vaos[0]->bind();
program->bind();
program->setAttributeValue(
"colors", this->
color());
viewer->glDrawArrays(GL_TRIANGLES, 0, static_cast<GLsizei>(nb_pos/3));
vaos[0]->release();
program->release();
}
void Scene_triangle_item::invalidateOpenGLBuffers()
{
are_buffers_filled = false;
}
{
{
program->bind();
vaos[0]->bind();
buffers[0].bind();
buffers[0].allocate(vertices.data(),
static_cast<GLsizei>(vertices.size()*sizeof(float)));
program->enableAttributeArray("vertex");
program->setAttributeBuffer("vertex",GL_FLOAT,0,3);
buffers[0].release();
vaos[0]->release();
program->release();
}
nb_pos = vertices.size();
vertices.resize(0);
std::vector<float>(vertices).swap(vertices);
are_buffers_filled = true;
}
#include <CGAL/Three/Polyhedron_demo_plugin_helper.h>
class Q_DECL_EXPORT Polyhedron_demo_example_plugin :
public QObject,
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.PluginInterface/1.0")
public :
this->scene = scene_interface;
this->mw = mainWindow;
QAction* actionDrawTriangle= new QAction("Draw Triangle", mw);
if(actionDrawTriangle) {
connect(actionDrawTriangle, SIGNAL(triggered()),
this, SLOT(draw_triangle()));
_actions << actionDrawTriangle;
}
}
bool applicable(QAction*) const Q_DECL_OVERRIDE
{
return true;
}
QList<QAction*> actions() const Q_DECL_OVERRIDE{
return _actions;
}
public Q_SLOTS:
void draw_triangle() {
triangle = new Scene_triangle_item(0, 0, 0,
1, 0, 0,
0.5, 0.5, 0);
triangle->setName(QString("Basic triangle"));
scene->addItem(triangle);
}
private:
QList<QAction*> _actions;
};
#include "Example_plugin.moc"