Intermediary step:

- Created a Scene_spheres_item
- Made the Scene_c3t3_item a group_item
- Changed the spheres management in the c3t3_item
- Fixed the has_group maintanance in group_items
This commit is contained in:
Maxime Gimeno 2016-04-18 15:35:05 +02:00
parent 4af747178a
commit 3ab7050205
17 changed files with 573 additions and 430 deletions

View File

@ -225,9 +225,10 @@ if(CGAL_Qt5_FOUND AND Qt5_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND)
target_link_libraries(${item_name} demo_framework ${CGAL_LIBRARIES} ${Boost_LIBRARIES}) target_link_libraries(${item_name} demo_framework ${CGAL_LIBRARIES} ${Boost_LIBRARIES})
endmacro(add_item) endmacro(add_item)
add_item(scene_spheres_item Scene_spheres_item)
add_item(scene_c2t3_item Scene_c2t3_item.cpp) add_item(scene_c2t3_item Scene_c2t3_item.cpp)
add_item(scene_c3t3_item Scene_c3t3_item.cpp) add_item(scene_c3t3_item Scene_c3t3_item.cpp)
target_link_libraries(scene_c3t3_item scene_polyhedron_item scene_polygon_soup_item ${TBB_LIBRARIES}) target_link_libraries(scene_c3t3_item scene_polyhedron_item scene_polygon_soup_item scene_spheres_item ${TBB_LIBRARIES})
add_item(scene_polyhedron_item Scene_polyhedron_item.cpp) 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_polyhedron_transform_item Plugins/PCA/Scene_polyhedron_transform_item.cpp )
@ -272,6 +273,7 @@ if(CGAL_Qt5_FOUND AND Qt5_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND)
target_link_libraries(scene_nef_polyhedron_item scene_polyhedron_item) target_link_libraries(scene_nef_polyhedron_item scene_polyhedron_item)
add_item(scene_points_with_normal_item Scene_points_with_normal_item.cpp) add_item(scene_points_with_normal_item Scene_points_with_normal_item.cpp)
target_link_libraries( scene_points_with_normal_item gl_splat) target_link_libraries( scene_points_with_normal_item gl_splat)
target_link_libraries( demo_framework gl_splat) target_link_libraries( demo_framework gl_splat)

View File

@ -1745,7 +1745,7 @@ void MainWindow::restoreCollapseState()
void MainWindow::make_new_group() void MainWindow::make_new_group()
{ {
Scene_group_item * group = new Scene_group_item("New group"); Scene_group_item * group = new Scene_group_item("New group");
scene->add_group(group); scene->addItem(group);
} }
void MainWindow::on_upButton_pressed() void MainWindow::on_upButton_pressed()

View File

@ -439,7 +439,7 @@ treat_result(Scene_item& source_item,
const Scene_interface::Item_id index = scene->mainSelectionIndex(); const Scene_interface::Item_id index = scene->mainSelectionIndex();
scene->itemChanged(index); scene->itemChanged(index);
scene->setSelectedItem(-1);
Scene_interface::Item_id new_item_id = scene->addItem(&result_item); Scene_interface::Item_id new_item_id = scene->addItem(&result_item);
scene->setSelectedItem(new_item_id); scene->setSelectedItem(new_item_id);
} }

View File

@ -39,5 +39,6 @@
<file>resources/shader_c3t3.v</file> <file>resources/shader_c3t3.v</file>
<file>resources/shader_c3t3.f</file> <file>resources/shader_c3t3.f</file>
<file>resources/shader_plane_two_faces.f</file> <file>resources/shader_plane_two_faces.f</file>
<file>resources/shader_spheres.v</file>
</qresource> </qresource>
</RCC> </RCC>

View File

@ -50,10 +50,6 @@ Scene::Scene(QObject* parent)
Scene::Item_id Scene::Item_id
Scene::addItem(CGAL::Three::Scene_item* item) Scene::addItem(CGAL::Three::Scene_item* item)
{ {
CGAL::Three::Scene_group_item* group =
qobject_cast<CGAL::Three::Scene_group_item*>(item);
if(group)
m_group_entries.prepend(group);
Bbox bbox_before = bbox(); Bbox bbox_before = bbox();
m_entries.push_back(item); m_entries.push_back(item);
connect(item, SIGNAL(itemChanged()), connect(item, SIGNAL(itemChanged()),
@ -80,6 +76,10 @@ Scene::addItem(CGAL::Three::Scene_item* item)
Q_EMIT updated(); Q_EMIT updated();
Item_id id = m_entries.size() - 1; Item_id id = m_entries.size() - 1;
Q_EMIT newItem(id); Q_EMIT newItem(id);
CGAL::Three::Scene_group_item* group =
qobject_cast<CGAL::Three::Scene_group_item*>(item);
if(group)
add_group(group);
//if group selected, add item to it //if group selected, add item to it
if(mainSelectionIndex() >=0) if(mainSelectionIndex() >=0)
{ {
@ -91,7 +91,7 @@ Scene::addItem(CGAL::Three::Scene_item* item)
if(selected_group) if(selected_group)
{ {
selected_group->addChild(item); selected_group->addChild(item);
group_added(); redraw_model();
} }
} }
} }
@ -120,7 +120,7 @@ Scene::replaceItem(Scene::Item_id index, CGAL::Three::Scene_item* item, bool emi
Q_EMIT updated(); Q_EMIT updated();
itemChanged(index); itemChanged(index);
Q_EMIT restoreCollapsedState(); Q_EMIT restoreCollapsedState();
group_added(); redraw_model();
return item; return item;
} }
@ -231,7 +231,7 @@ Scene::~Scene()
{ {
Q_FOREACH(CGAL::Three::Scene_item* item_ptr, m_entries) Q_FOREACH(CGAL::Three::Scene_item* item_ptr, m_entries)
{ {
delete item_ptr; item_ptr->deleteLater();
} }
m_entries.clear(); m_entries.clear();
@ -767,6 +767,7 @@ bool Scene::dropMimeData(const QMimeData * /*data*/,
{ {
one_contained = true; one_contained = true;
break; break;
} }
} }
//if the drop item is not a group_item or if it already contains the item, then the drop action must be ignored //if the drop item is not a group_item or if it already contains the item, then the drop action must be ignored
@ -776,16 +777,13 @@ bool Scene::dropMimeData(const QMimeData * /*data*/,
if(!parent.isValid()) if(!parent.isValid())
{ {
Q_FOREACH(Scene_item* item, items) Q_FOREACH(Scene_item* item, items)
while(item->has_group!=0)
{ {
Q_FOREACH(CGAL::Three::Scene_group_item* group_item, m_group_entries) if(item->parentGroup())
if(group_item->getChildren().contains(item))
{ {
group_item->removeChild(item); item->parentGroup()->removeChild(item);
break;
} }
} }
group_added(); redraw_model();
return true; return true;
} }
return false; return false;
@ -793,10 +791,8 @@ bool Scene::dropMimeData(const QMimeData * /*data*/,
Q_FOREACH(Scene_item* item, items) Q_FOREACH(Scene_item* item, items)
changeGroup(item, group); changeGroup(item, group);
//group->addChild(item(mainSelectionIndex())); //group->addChild(item(mainSelectionIndex()));
group_added(); redraw_model();
return true; return true;
} }
void Scene::moveRowUp() void Scene::moveRowUp()
@ -820,7 +816,7 @@ void Scene::moveRowUp()
int newId = index_map.value(index(baseId.row()-1, baseId.column(),baseId.parent())) ; int newId = index_map.value(index(baseId.row()-1, baseId.column(),baseId.parent())) ;
m_entries.move(mainSelectionIndex(), newId); m_entries.move(mainSelectionIndex(), newId);
} }
group_added(); redraw_model();
setSelectedItem(m_entries.indexOf(selected_item)); setSelectedItem(m_entries.indexOf(selected_item));
} }
} }
@ -845,7 +841,7 @@ void Scene::moveRowDown()
int newId = index_map.value(index(baseId.row()+1, baseId.column(),baseId.parent())) ; int newId = index_map.value(index(baseId.row()+1, baseId.column(),baseId.parent())) ;
m_entries.move(mainSelectionIndex(), newId); m_entries.move(mainSelectionIndex(), newId);
} }
group_added(); redraw_model();
setSelectedItem(m_entries.indexOf(selected_item)); setSelectedItem(m_entries.indexOf(selected_item));
} }
} }
@ -1102,7 +1098,7 @@ QList<Scene_item*> Scene::item_entries() const
{ {
return m_entries; return m_entries;
} }
void Scene::group_added() void Scene::redraw_model()
{ {
//makes the hierarchy in the tree //makes the hierarchy in the tree
//clears the model //clears the model
@ -1118,15 +1114,8 @@ void Scene::group_added()
void Scene::changeGroup(Scene_item *item, CGAL::Three::Scene_group_item *target_group) void Scene::changeGroup(Scene_item *item, CGAL::Three::Scene_group_item *target_group)
{ {
//remove item from the containing group if any //remove item from the containing group if any
if(item->has_group!=0) if(item->parentGroup())
Q_FOREACH(CGAL::Three::Scene_group_item* group, m_group_entries) item->parentGroup()->removeChild(item);
{
if(group->getChildren().contains(item))
{
remove_item_from_groups(item);
break;
}
}
//add the item to the target group //add the item to the target group
target_group->addChild(item); target_group->addChild(item);
item->moveToGroup(target_group); item->moveToGroup(target_group);
@ -1250,16 +1239,14 @@ void Scene::add_group(Scene_group_item* group)
Q_FOREACH(int id, indices) Q_FOREACH(int id, indices)
changeGroup(item(id),group); changeGroup(item(id),group);
changeGroup(group, existing_group); changeGroup(group, existing_group);
addItem(group); redraw_model();
group_added();
} }
//else wer create a new group //else we create a new group
else else
{ {
Q_FOREACH(int id, indices) Q_FOREACH(int id, indices)
changeGroup(item(id),group); changeGroup(item(id),group);
addItem(group); redraw_model();
group_added();
} }
} }

View File

@ -178,9 +178,8 @@ public Q_SLOTS:
//!Removes item from all the groups of the scene. //!Removes item from all the groups of the scene.
void remove_item_from_groups(CGAL::Three::Scene_item* item); void remove_item_from_groups(CGAL::Three::Scene_item* item);
void add_group(Scene_group_item* group);
//!Re-organizes the sceneView. //!Re-organizes the sceneView.
void group_added(); void redraw_model();
//! Sets the selected item to the target index. //! Sets the selected item to the target index.
void setSelectedItemIndex(int i) void setSelectedItemIndex(int i)
{ {
@ -249,7 +248,7 @@ private Q_SLOTS:
//! Casts a selection ray and calls the item function select. //! Casts a selection ray and calls the item function select.
void setSelectionRay(double, double, double, double, double, double); void setSelectionRay(double, double, double, double, double, double);
void callDraw(){ QGLViewer* viewer = *QGLViewer::QGLViewerPool().begin(); viewer->update();} void callDraw(){ QGLViewer* viewer = *QGLViewer::QGLViewerPool().begin(); viewer->update();}
void add_group(Scene_group_item* group);
private: private:
/*! Calls the drawing functions of each visible item according /*! Calls the drawing functions of each visible item according
* to its current renderingMode. If with_names is true, uses * to its current renderingMode. If with_names is true, uses

View File

@ -100,24 +100,7 @@ struct Set_show_tetrahedra {
} }
}; };
void Scene_c3t3_item::compile_shaders()
{
program_sphere = new QOpenGLShaderProgram(this);
if(!program_sphere->addShaderFromSourceFile(QOpenGLShader::Vertex,":/cgal/Polyhedron_3/resources/shader_c3t3_spheres.v"))
{
std::cerr<<"adding vertex shader FAILED"<<std::endl;
}
if(!program_sphere->addShaderFromSourceFile(QOpenGLShader::Fragment,":/cgal/Polyhedron_3/resources/shader_c3t3.f" ))
{
std::cerr<<"adding fragment shader FAILED"<<std::endl;
}
if(!program_sphere->link())
{
//std::cerr<<"linking Program FAILED"<<std::endl;
qDebug() << program_sphere->log();
}
}
double complex_diag(const Scene_item* item) { double complex_diag(const Scene_item* item) {
const Scene_item::Bbox& bbox = item->bbox(); const Scene_item::Bbox& bbox = item->bbox();
const double& xdelta = bbox.xmax-bbox.xmin; const double& xdelta = bbox.xmax-bbox.xmin;
@ -130,7 +113,7 @@ double complex_diag(const Scene_item* item) {
} }
Scene_c3t3_item::Scene_c3t3_item() Scene_c3t3_item::Scene_c3t3_item()
: Scene_item(NumberOfBuffers, NumberOfVaos) : Scene_group_item("unnamed", NumberOfBuffers, NumberOfVaos)
, d(new Scene_c3t3_item_priv(this)) , d(new Scene_c3t3_item_priv(this))
, frame(new ManipulatedFrame()) , frame(new ManipulatedFrame())
, last_known_scene(NULL) , last_known_scene(NULL)
@ -146,18 +129,19 @@ Scene_c3t3_item::Scene_c3t3_item()
s_normals.resize(0); s_normals.resize(0);
ws_vertex.resize(0); ws_vertex.resize(0);
need_changed = false; need_changed = false;
spheres = NULL;
compute_bbox();
startTimer(0); startTimer(0);
connect(frame, SIGNAL(modified()), this, SLOT(changed())); connect(frame, SIGNAL(modified()), this, SLOT(changed()));
c3t3_changed(); c3t3_changed();
setRenderingMode(FlatPlusEdges); setRenderingMode(FlatPlusEdges);
compile_shaders();
spheres_are_shown = false; spheres_are_shown = false;
create_flat_and_wire_sphere(1.0f,s_vertex,s_normals, ws_vertex); create_flat_and_wire_sphere(1.0f,s_vertex,s_normals, ws_vertex);
} }
Scene_c3t3_item::Scene_c3t3_item(const C3t3& c3t3) Scene_c3t3_item::Scene_c3t3_item(const C3t3& c3t3)
: Scene_item(NumberOfBuffers, NumberOfVaos) : Scene_group_item("unnamed", NumberOfBuffers, NumberOfVaos)
, d(new Scene_c3t3_item_priv(c3t3, this)) , d(new Scene_c3t3_item_priv(c3t3, this))
, frame(new ManipulatedFrame()) , frame(new ManipulatedFrame())
, last_known_scene(NULL) , last_known_scene(NULL)
@ -172,12 +156,13 @@ Scene_c3t3_item::Scene_c3t3_item(const C3t3& c3t3)
s_normals.resize(0); s_normals.resize(0);
ws_vertex.resize(0); ws_vertex.resize(0);
need_changed = false; need_changed = false;
spheres = NULL;
compute_bbox();
startTimer(0); startTimer(0);
connect(frame, SIGNAL(modified()), this, SLOT(changed())); connect(frame, SIGNAL(modified()), this, SLOT(changed()));
reset_cut_plane(); reset_cut_plane();
c3t3_changed(); c3t3_changed();
setRenderingMode(FlatPlusEdges); setRenderingMode(FlatPlusEdges);
compile_shaders();
spheres_are_shown = false; spheres_are_shown = false;
create_flat_and_wire_sphere(1.0f,s_vertex,s_normals, ws_vertex); create_flat_and_wire_sphere(1.0f,s_vertex,s_normals, ws_vertex);
} }
@ -518,8 +503,8 @@ void Scene_c3t3_item::draw(CGAL::Three::Viewer_interface* viewer) const {
} }
vaos[Grid]->bind(); vaos[Grid]->bind();
program = getShaderProgram(PROGRAM_WITHOUT_LIGHT); program = getShaderProgram(PROGRAM_NO_SELECTION);
attrib_buffers(viewer, PROGRAM_WITHOUT_LIGHT); attrib_buffers(viewer, PROGRAM_NO_SELECTION);
program->bind(); program->bind();
program->setAttributeValue("colors", QColor(Qt::black)); program->setAttributeValue("colors", QColor(Qt::black));
QMatrix4x4 f_mat; QMatrix4x4 f_mat;
@ -563,48 +548,9 @@ void Scene_c3t3_item::draw(CGAL::Three::Viewer_interface* viewer) const {
if(spheres_are_shown) if(spheres_are_shown)
{ {
vaos[Spheres]->bind(); spheres->setPlane(this->plane());
program_sphere->bind();
//ModelViewMatrix used for the transformation of the camera.
QMatrix4x4 mvp_mat;
// ModelView Matrix used for the lighting system
QMatrix4x4 mv_mat;
GLdouble d_mat[16];
GLint is_both_sides = 0;
viewer->camera()->getModelViewProjectionMatrix(d_mat);
//Convert the GLdoubles matrices in GLfloats
for (int i=0; i<16; ++i){
mvp_mat.data()[i] = GLfloat(d_mat[i]);
}
viewer->camera()->getModelViewMatrix(d_mat);
for (int i=0; i<16; ++i)
mv_mat.data()[i] = GLfloat(d_mat[i]);
QVector4D position(0.0f,0.0f,1.0f, 1.0f );
QVector4D ambient(0.4f, 0.4f, 0.4f, 0.4f);
// Diffuse
QVector4D diffuse(1.0f, 1.0f, 1.0f, 1.0f);
// Specular
QVector4D specular(0.0f, 0.0f, 0.0f, 1.0f);
viewer->glGetIntegerv(GL_LIGHT_MODEL_TWO_SIDE, &is_both_sides);
QVector4D cp(this->plane().a(),this->plane().b(),this->plane().c(),this->plane().d());
program_sphere->setUniformValue("cutplane", cp);
program_sphere->setUniformValue("mvp_matrix", mvp_mat);
program_sphere->setUniformValue("mv_matrix", mv_mat);
program_sphere->setUniformValue("light_pos", position);
program_sphere->setUniformValue("light_diff",diffuse);
program_sphere->setUniformValue("light_spec", specular);
program_sphere->setUniformValue("light_amb", ambient);
program_sphere->setUniformValue("spec_power", 51.8f);
program_sphere->setUniformValue("is_two_side", is_both_sides);
viewer->glDrawArraysInstanced(GL_TRIANGLES, 0,
static_cast<GLsizei>(s_vertex.size()/3),
static_cast<GLsizei>(s_radius.size()));
program_sphere->release();
vaos[Spheres]->release();
} }
Scene_group_item::draw(viewer);
} }
void Scene_c3t3_item::draw_edges(CGAL::Three::Viewer_interface* viewer) const { void Scene_c3t3_item::draw_edges(CGAL::Three::Viewer_interface* viewer) const {
@ -624,8 +570,8 @@ void Scene_c3t3_item::draw_edges(CGAL::Three::Viewer_interface* viewer) const {
if(renderingMode() == Wireframe) if(renderingMode() == Wireframe)
{ {
vaos[Grid]->bind(); vaos[Grid]->bind();
program = getShaderProgram(PROGRAM_WITHOUT_LIGHT); program = getShaderProgram(PROGRAM_NO_SELECTION);
attrib_buffers(viewer, PROGRAM_WITHOUT_LIGHT); attrib_buffers(viewer, PROGRAM_NO_SELECTION);
program->bind(); program->bind();
program->setAttributeValue("colors", QColor(Qt::black)); program->setAttributeValue("colors", QColor(Qt::black));
QMatrix4x4 f_mat; QMatrix4x4 f_mat;
@ -665,46 +611,9 @@ void Scene_c3t3_item::draw_edges(CGAL::Three::Viewer_interface* viewer) const {
if(spheres_are_shown) if(spheres_are_shown)
{ {
vaos[Wired_spheres]->bind(); spheres->setPlane(this->plane());
program_sphere->bind();
//ModelViewMatrix used for the transformation of the camera.
QMatrix4x4 mvp_mat;
// ModelView Matrix used for the lighting system
QMatrix4x4 mv_mat;
GLdouble d_mat[16];
GLint is_both_sides = 0;
viewer->camera()->getModelViewProjectionMatrix(d_mat);
//Convert the GLdoubles matrices in GLfloats
for (int i=0; i<16; ++i){
mvp_mat.data()[i] = GLfloat(d_mat[i]);
}
viewer->camera()->getModelViewMatrix(d_mat);
for (int i=0; i<16; ++i)
mv_mat.data()[i] = GLfloat(d_mat[i]);
QVector4D position(0.0f,0.0f,1.0f, 1.0f );
QVector4D ambient(0.4f, 0.4f, 0.4f, 0.4f);
// Diffuse
QVector4D diffuse(1.0f, 1.0f, 1.0f, 1.0f);
// Specular
QVector4D specular(0.0f, 0.0f, 0.0f, 1.0f);
viewer->glGetIntegerv(GL_LIGHT_MODEL_TWO_SIDE, &is_both_sides);
program_sphere->setUniformValue("mvp_matrix", mvp_mat);
program_sphere->setUniformValue("mv_matrix", mv_mat);
program_sphere->setUniformValue("light_pos", position);
program_sphere->setUniformValue("light_diff",diffuse);
program_sphere->setUniformValue("light_spec", specular);
program_sphere->setUniformValue("light_amb", ambient);
program_sphere->setUniformValue("spec_power", 51.8f);
program_sphere->setUniformValue("is_two_side", is_both_sides);
viewer->glDrawArraysInstanced(GL_TRIANGLES, 0,
static_cast<GLsizei>(ws_vertex.size()/3),
static_cast<GLsizei>(s_radius.size()));
program_sphere->release();
vaos[Wired_spheres]->release();
} }
Scene_group_item::draw_edges(viewer);
} }
void Scene_c3t3_item::draw_points(CGAL::Three::Viewer_interface * viewer) const void Scene_c3t3_item::draw_points(CGAL::Three::Viewer_interface * viewer) const
@ -727,8 +636,8 @@ void Scene_c3t3_item::draw_points(CGAL::Three::Viewer_interface * viewer) const
program->release(); program->release();
vaos[Grid]->bind(); vaos[Grid]->bind();
program = getShaderProgram(PROGRAM_WITHOUT_LIGHT); program = getShaderProgram(PROGRAM_NO_SELECTION);
attrib_buffers(viewer, PROGRAM_WITHOUT_LIGHT); attrib_buffers(viewer, PROGRAM_NO_SELECTION);
program->bind(); program->bind();
program->setAttributeValue("colors", this->color()); program->setAttributeValue("colors", this->color());
QMatrix4x4 f_mat; QMatrix4x4 f_mat;
@ -997,7 +906,7 @@ void Scene_c3t3_item::initialize_buffers(CGAL::Three::Viewer_interface *viewer)
//vao containing the data for the grid //vao containing the data for the grid
{ {
program = getShaderProgram(PROGRAM_WITHOUT_LIGHT, viewer); program = getShaderProgram(PROGRAM_NO_SELECTION, viewer);
program->bind(); program->bind();
vaos[Grid]->bind(); vaos[Grid]->bind();
@ -1011,93 +920,7 @@ void Scene_c3t3_item::initialize_buffers(CGAL::Three::Viewer_interface *viewer)
program->release(); program->release();
} }
//vao containing the data for the spheres program->release();
{
program_sphere->bind();
vaos[Spheres]->bind();
buffers[Sphere_vertices].bind();
buffers[Sphere_vertices].allocate(s_vertex.data(),
static_cast<int>(s_vertex.size()*sizeof(float)));
program_sphere->enableAttributeArray("vertex");
program_sphere->setAttributeBuffer("vertex", GL_FLOAT, 0, 3);
buffers[Sphere_vertices].release();
buffers[Sphere_normals].bind();
buffers[Sphere_normals].allocate(s_normals.data(),
static_cast<int>(s_normals.size()*sizeof(float)));
program_sphere->enableAttributeArray("normals");
program_sphere->setAttributeBuffer("normals", GL_FLOAT, 0, 3);
buffers[Sphere_normals].release();
buffers[Sphere_colors].bind();
buffers[Sphere_colors].allocate(s_colors.data(),
static_cast<int>(s_colors.size()*sizeof(float)));
program_sphere->enableAttributeArray("colors");
program_sphere->setAttributeBuffer("colors", GL_FLOAT, 0, 3);
buffers[Sphere_colors].release();
buffers[Sphere_radius].bind();
buffers[Sphere_radius].allocate(s_radius.data(),
static_cast<int>(s_radius.size()*sizeof(float)));
program_sphere->enableAttributeArray("radius");
program_sphere->setAttributeBuffer("radius", GL_FLOAT, 0, 1);
buffers[Sphere_radius].release();
buffers[Sphere_center].bind();
buffers[Sphere_center].allocate(s_center.data(),
static_cast<int>(s_center.size()*sizeof(float)));
program_sphere->enableAttributeArray("center");
program_sphere->setAttributeBuffer("center", GL_FLOAT, 0, 3);
buffers[Sphere_center].release();
viewer->glVertexAttribDivisor(program_sphere->attributeLocation("center"), 1);
viewer->glVertexAttribDivisor(program_sphere->attributeLocation("radius"), 1);
viewer->glVertexAttribDivisor(program_sphere->attributeLocation("colors"), 1);
vaos[Spheres]->release();
}
//vao containing the data for the wired spheres
{
program_sphere->bind();
vaos[Wired_spheres]->bind();
buffers[Wired_spheres_vertices].bind();
buffers[Wired_spheres_vertices].allocate(s_vertex.data(),
static_cast<int>(s_vertex.size()*sizeof(float)));
program_sphere->enableAttributeArray("vertex");
program_sphere->setAttributeBuffer("vertex", GL_FLOAT, 0, 3);
buffers[Wired_spheres_vertices].release();
buffers[Sphere_normals].bind();
program_sphere->enableAttributeArray("normals");
program_sphere->setAttributeBuffer("normals", GL_FLOAT, 0, 3);
buffers[Sphere_normals].release();
buffers[Sphere_colors].bind();
program_sphere->enableAttributeArray("colors");
program_sphere->setAttributeBuffer("colors", GL_FLOAT, 0, 3);
buffers[Sphere_colors].release();
buffers[Sphere_radius].bind();
program_sphere->enableAttributeArray("radius");
program_sphere->setAttributeBuffer("radius", GL_FLOAT, 0, 1);
buffers[Sphere_radius].release();
buffers[Sphere_center].bind();
program_sphere->enableAttributeArray("center");
program_sphere->setAttributeBuffer("center", GL_FLOAT, 0, 3);
buffers[Sphere_center].release();
viewer->glVertexAttribDivisor(program_sphere->attributeLocation("center"), 1);
viewer->glVertexAttribDivisor(program_sphere->attributeLocation("radius"), 1);
viewer->glVertexAttribDivisor(program_sphere->attributeLocation("colors"), 1);
vaos[Wired_spheres]->release();
program_sphere->release();
}
program_sphere->release();
are_buffers_filled = true; are_buffers_filled = true;
} }
@ -1180,6 +1003,44 @@ void Scene_c3t3_item::compute_intersections()
boost::make_function_output_iterator(Compute_intersection(*this->d))); boost::make_function_output_iterator(Compute_intersection(*this->d)));
} }
void Scene_c3t3_item::compute_spheres()
{
if(!spheres)
return;
for(Tr::Finite_vertices_iterator
vit = d->c3t3.triangulation().finite_vertices_begin(),
end = d->c3t3.triangulation().finite_vertices_end();
vit != end; ++vit)
{
if(vit->point().weight()==0) continue;
typedef Tr::Vertex_handle Vertex_handle;
std::vector<Vertex_handle> incident_vertices;
d->c3t3.triangulation().incident_vertices(vit, std::back_inserter(incident_vertices));
bool red = vit->is_special();
for(std::vector<Vertex_handle>::const_iterator
vvit = incident_vertices.begin(), end = incident_vertices.end();
vvit != end; ++vvit)
{
if(Kernel::Sphere_3(vit->point().point(),
vit->point().weight()).bounded_side((*vvit)->point().point())
== CGAL::ON_BOUNDED_SIDE)
red = true;
}
QColor c;
if(red)
c = QColor(Qt::red);
else
c = this->color().darker(250);
Kernel::Point_3 center(vit->point().point().x(),
vit->point().point().y(),
vit->point().point().z());
float radius = CGAL::sqrt(vit->point().weight());
Kernel::Sphere_3* sphere = new Kernel::Sphere_3(center, radius);
spheres->add_sphere(sphere, CGAL::Color(c.red(), c.green(), c.blue()));
}
spheres->invalidateOpenGLBuffers();
}
void Scene_c3t3_item::compute_elements() void Scene_c3t3_item::compute_elements()
{ {
@ -1249,50 +1110,8 @@ void Scene_c3t3_item::compute_elements()
} }
//The Spheres
{
for(Tr::Finite_vertices_iterator
vit = d->c3t3.triangulation().finite_vertices_begin(),
end = d->c3t3.triangulation().finite_vertices_end();
vit != end; ++vit)
{
if(vit->point().weight()==0) continue;
typedef Tr::Vertex_handle Vertex_handle;
std::vector<Vertex_handle> incident_vertices;
d->c3t3.triangulation().incident_vertices(vit, std::back_inserter(incident_vertices));
bool red = vit->is_special();
for(std::vector<Vertex_handle>::const_iterator
vvit = incident_vertices.begin(), end = incident_vertices.end();
vvit != end; ++vvit)
{
if(Kernel::Sphere_3(vit->point().point(),
vit->point().weight()).bounded_side((*vvit)->point().point())
== CGAL::ON_BOUNDED_SIDE)
red = true;
}
if(red){
s_colors.push_back(1.0);
s_colors.push_back(0.0);
s_colors.push_back(0.0);
}
else{
QColor c = this->color().darker(250);
s_colors.push_back(c.redF());
s_colors.push_back(c.greenF());
s_colors.push_back(c.blueF());
}
s_center.push_back(vit->point().point().x());
s_center.push_back(vit->point().point().y());
s_center.push_back(vit->point().point().z());
s_radius.push_back(CGAL::sqrt(vit->point().weight()));
}
}
} }
bool Scene_c3t3_item::load_binary(std::istream& is) bool Scene_c3t3_item::load_binary(std::istream& is)
{ {
if(!CGAL::Mesh_3::load_binary_file(is, c3t3())) return false; if(!CGAL::Mesh_3::load_binary_file(is, c3t3())) return false;
@ -1329,3 +1148,22 @@ Scene_c3t3_item::setColor(QColor c)
// function and the intersection is not drawn before the next draw call // function and the intersection is not drawn before the next draw call
are_intersection_buffers_filled = false; are_intersection_buffers_filled = false;
} }
void Scene_c3t3_item::show_spheres(bool b)
{
spheres_are_shown = b;
if(b && !spheres)
{
spheres = new Scene_spheres_item(this, true);
connect(spheres, SIGNAL(aboutToBeDestroyed()), this, SLOT(reset_spheres()));
last_known_scene->addItem(spheres);
last_known_scene->changeGroup(spheres, this);
compute_spheres();
}
else if (!b)
{
last_known_scene->erase(last_known_scene->item_id(spheres));
spheres = NULL;
}
Q_EMIT redraw();
}

View File

@ -3,6 +3,7 @@
#include "Scene_c3t3_item_config.h" #include "Scene_c3t3_item_config.h"
#include "C3t3_type.h" #include "C3t3_type.h"
#include "Scene_spheres_item.h"
#include <QVector> #include <QVector>
#include <QColor> #include <QColor>
@ -19,8 +20,7 @@
#include <QOpenGLShaderProgram> #include <QOpenGLShaderProgram>
#include <CGAL/Three/Viewer_interface.h> #include <CGAL/Three/Viewer_interface.h>
#include <CGAL/Three/Scene_group_item.h>
#include <CGAL/Three/Scene_item.h>
#include <Scene_polyhedron_item.h> #include <Scene_polyhedron_item.h>
#include <Scene_polygon_soup_item.h> #include <Scene_polygon_soup_item.h>
#include <CGAL/IO/File_binary_mesh_3.h> #include <CGAL/IO/File_binary_mesh_3.h>
@ -29,7 +29,7 @@ struct Scene_c3t3_item_priv;
using namespace CGAL::Three; using namespace CGAL::Three;
class SCENE_C3T3_ITEM_EXPORT Scene_c3t3_item class SCENE_C3T3_ITEM_EXPORT Scene_c3t3_item
: public Scene_item : public Scene_group_item
{ {
Q_OBJECT Q_OBJECT
public: public:
@ -86,8 +86,12 @@ public:
&& c3t3().number_of_cells_in_complex() == 0 ); && c3t3().number_of_cells_in_complex() == 0 );
} }
void compute_bbox() const;
void compute_bbox() const;
Scene_item::Bbox bbox() const
{
return Scene_item::bbox();
}
Scene_c3t3_item* clone() const { Scene_c3t3_item* clone() const {
return 0; return 0;
} }
@ -129,12 +133,11 @@ private:
void data_item_destroyed(); void data_item_destroyed();
void show_spheres(bool b) void reset_spheres()
{ {
spheres_are_shown = b; spheres = NULL;
Q_EMIT redraw();
} }
void show_spheres(bool b);
virtual QPixmap graphicalToolTip() const; virtual QPixmap graphicalToolTip() const;
void update_histogram(); void update_histogram();
@ -170,12 +173,6 @@ private:
Facet_colors, Facet_colors,
Edges_vertices, Edges_vertices,
Grid_vertices, Grid_vertices,
Sphere_vertices,
Sphere_normals,
Sphere_colors,
Sphere_radius,
Sphere_center,
Wired_spheres_vertices,
iEdges_vertices, iEdges_vertices,
iFacet_vertices, iFacet_vertices,
iFacet_normals, iFacet_normals,
@ -187,8 +184,6 @@ private:
Facets=0, Facets=0,
Edges, Edges,
Grid, Grid,
Spheres,
Wired_spheres,
iEdges, iEdges,
iFacets, iFacets,
NumberOfVaos NumberOfVaos
@ -196,6 +191,7 @@ private:
qglviewer::ManipulatedFrame* frame; qglviewer::ManipulatedFrame* frame;
CGAL::Three::Scene_interface* last_known_scene; CGAL::Three::Scene_interface* last_known_scene;
Scene_spheres_item *spheres;
bool spheres_are_shown; bool spheres_are_shown;
const Scene_item* data_item_; const Scene_item* data_item_;
QPixmap histogram_; QPixmap histogram_;
@ -226,14 +222,14 @@ private:
mutable std::vector<float> s_radius; mutable std::vector<float> s_radius;
mutable std::vector<float> s_center; mutable std::vector<float> s_center;
mutable QOpenGLShaderProgram *program; mutable QOpenGLShaderProgram *program;
mutable QOpenGLShaderProgram *program_sphere;
using Scene_item::initialize_buffers; using Scene_item::initialize_buffers;
void initialize_buffers(CGAL::Three::Viewer_interface *viewer); void initialize_buffers(CGAL::Three::Viewer_interface *viewer);
void initialize_intersection_buffers(CGAL::Three::Viewer_interface *viewer); void initialize_intersection_buffers(CGAL::Three::Viewer_interface *viewer);
void compute_spheres();
void compute_elements(); void compute_elements();
void compute_intersections(); void compute_intersections();
void compile_shaders();
}; };
#endif // SCENE_C3T3_ITEM_H #endif // SCENE_C3T3_ITEM_H

View File

@ -3,8 +3,8 @@
#include <QDebug> #include <QDebug>
using namespace CGAL::Three; using namespace CGAL::Three;
Scene_group_item::Scene_group_item(QString name) Scene_group_item::Scene_group_item(QString name, int nb_vbos, int nb_vaos )
: Scene_item(0,0) : Scene_item(nb_vbos, nb_vaos)
{ {
this->name_ = name; this->name_ = name;
expanded = true; expanded = true;
@ -53,20 +53,20 @@ void Scene_group_item::addChild(Scene_item* new_item)
if(!children.contains(new_item)) if(!children.contains(new_item))
{ {
children.append(new_item); children.append(new_item);
add_group_number(new_item); update_group_number(new_item, has_group+1);
} }
} }
void Scene_group_item::add_group_number(Scene_item * new_item) void Scene_group_item::update_group_number(Scene_item * new_item, int n)
{ {
Scene_group_item* group = Scene_group_item* group =
qobject_cast<Scene_group_item*>(new_item); qobject_cast<Scene_group_item*>(new_item);
if(group) if(group)
Q_FOREACH(Scene_item* child, group->getChildren()) Q_FOREACH(Scene_item* child, group->getChildren())
add_group_number(child); update_group_number(child,n+1);
new_item->has_group++; new_item->has_group = n;
} }
void Scene_group_item::setColor(QColor c) void Scene_group_item::setColor(QColor c)
{ {

View File

@ -736,13 +736,15 @@ Scene_polyhedron_item::toolTip() const
QObject::tr("<p>Polyhedron <b>%1</b> (mode: %5, color: %6)</p>" QObject::tr("<p>Polyhedron <b>%1</b> (mode: %5, color: %6)</p>"
"<p>Number of vertices: %2<br />" "<p>Number of vertices: %2<br />"
"Number of edges: %3<br />" "Number of edges: %3<br />"
"Number of facets: %4") "Number of facets: %4<br />"
"has_group = %7")
.arg(this->name()) .arg(this->name())
.arg(poly->size_of_vertices()) .arg(poly->size_of_vertices())
.arg(poly->size_of_halfedges()/2) .arg(poly->size_of_halfedges()/2)
.arg(poly->size_of_facets()) .arg(poly->size_of_facets())
.arg(this->renderingModeName()) .arg(this->renderingModeName())
.arg(this->color().name()); .arg(this->color().name())
.arg(this->has_group);
str += QString("<br />Number of isolated vertices : %1<br />").arg(getNbIsolatedvertices()); str += QString("<br />Number of isolated vertices : %1<br />").arg(getNbIsolatedvertices());
return str; return str;
} }

View File

@ -0,0 +1,205 @@
#include "Scene_spheres_item.h"
void Scene_spheres_item::computeElements() const
{
colors.clear();
edges_colors.clear();
centers.clear();
radius.clear();
Q_FOREACH(sphere_pair sp, spheres)
{
colors.push_back((float)sp.second.red()/255);
colors.push_back((float)sp.second.green()/255);
colors.push_back((float)sp.second.blue()/255);
edges_colors.push_back((float)sp.second.red()/255);
edges_colors.push_back((float)sp.second.green()/255);
edges_colors.push_back((float)sp.second.blue()/255);
centers.push_back(sp.first->center().x());
centers.push_back(sp.first->center().y());
centers.push_back(sp.first->center().z());
radius.push_back(sp.first->squared_radius());
}
}
void Scene_spheres_item::initializeBuffers(CGAL::Three::Viewer_interface *viewer) const
{
if(has_plane)
{
program = getShaderProgram(PROGRAM_CUTPLANE_SPHERES, viewer);
attrib_buffers(viewer, PROGRAM_CUTPLANE_SPHERES);
}
else
{
program = getShaderProgram(PROGRAM_SPHERES, viewer);
attrib_buffers(viewer, PROGRAM_SPHERES);
}
program->bind();
vaos[Facets]->bind();
buffers[Vertices].bind();
buffers[Vertices].allocate(vertices.data(),
static_cast<int>(vertices.size()*sizeof(float)));
program->enableAttributeArray("vertex");
program->setAttributeBuffer("vertex", GL_FLOAT, 0, 3);
buffers[Vertices].release();
buffers[Normals].bind();
buffers[Normals].allocate(normals.data(),
static_cast<int>(normals.size()*sizeof(float)));
program->enableAttributeArray("normals");
program->setAttributeBuffer("normals", GL_FLOAT, 0, 3);
buffers[Normals].release();
buffers[Color].bind();
buffers[Color].allocate(colors.data(),
static_cast<int>(colors.size()*sizeof(float)));
program->enableAttributeArray("colors");
program->setAttributeBuffer("colors", GL_FLOAT, 0, 3);
buffers[Color].release();
buffers[Radius].bind();
buffers[Radius].allocate(radius.data(),
static_cast<int>(radius.size()*sizeof(float)));
program->enableAttributeArray("radius");
program->setAttributeBuffer("radius", GL_FLOAT, 0, 1);
buffers[Radius].release();
buffers[Center].bind();
buffers[Center].allocate(centers.data(),
static_cast<int>(centers.size()*sizeof(float)));
program->enableAttributeArray("center");
program->setAttributeBuffer("center", GL_FLOAT, 0, 3);
buffers[Center].release();
viewer->glVertexAttribDivisor(program->attributeLocation("center"), 1);
viewer->glVertexAttribDivisor(program->attributeLocation("radius"), 1);
viewer->glVertexAttribDivisor(program->attributeLocation("colors"), 1);
vaos[Facets]->release();
vaos[Edges]->bind();
buffers[Edge_vertices].bind();
buffers[Edge_vertices].allocate(edges.data(),
static_cast<int>(edges.size()*sizeof(float)));
program->enableAttributeArray("vertex");
program->setAttributeBuffer("vertex", GL_FLOAT, 0, 3);
buffers[Edge_vertices].release();
buffers[Normals].bind();
program->enableAttributeArray("normals");
program->setAttributeBuffer("normals", GL_FLOAT, 0, 3);
buffers[Normals].release();
buffers[Edge_color].bind();
buffers[Edge_color].allocate(edges_colors.data(),
static_cast<int>(edges_colors.size()*sizeof(float)));
program->enableAttributeArray("colors");
program->setAttributeBuffer("colors", GL_FLOAT, 0, 3);
buffers[Edge_color].release();
buffers[Radius].bind();
program->enableAttributeArray("radius");
program->setAttributeBuffer("radius", GL_FLOAT, 0, 1);
buffers[Radius].release();
buffers[Center].bind();
program->enableAttributeArray("center");
program->setAttributeBuffer("center", GL_FLOAT, 0, 3);
buffers[Center].release();
viewer->glVertexAttribDivisor(program->attributeLocation("center"), 1);
viewer->glVertexAttribDivisor(program->attributeLocation("radius"), 1);
viewer->glVertexAttribDivisor(program->attributeLocation("colors"), 1);
vaos[Edges]->release();
program->release();
nb_centers = centers.size();
centers.clear();
centers.swap(centers);
colors.clear();
colors.swap(colors);
radius.clear();
radius.swap(radius);
edges_colors.clear();
edges_colors.swap(edges_colors);
are_buffers_filled = true;
}
void Scene_spheres_item::draw(Viewer_interface *viewer) const
{
if (!are_buffers_filled)
{
computeElements();
initializeBuffers(viewer);
}
vaos[Facets]->bind();
if(has_plane)
{
program = getShaderProgram(PROGRAM_CUTPLANE_SPHERES, viewer);
attrib_buffers(viewer, PROGRAM_CUTPLANE_SPHERES);
program->bind();
QVector4D cp(plane.a(),plane.b(),plane.c(),plane.d());
program->setUniformValue("cutplane", cp);
}
else
{
program = getShaderProgram(PROGRAM_SPHERES, viewer);
attrib_buffers(viewer, PROGRAM_SPHERES);
program->bind();
}
viewer->glDrawArraysInstanced(GL_TRIANGLES, 0,
static_cast<GLsizei>(vertices.size()/3),
static_cast<GLsizei>(nb_centers));
program->release();
vaos[Facets]->release();
}
void Scene_spheres_item::draw_edges(Viewer_interface *viewer) const
{
if (!are_buffers_filled)
{
computeElements();
initializeBuffers(viewer);
}
vaos[Edges]->bind();
if(has_plane)
{
program = getShaderProgram(PROGRAM_CUTPLANE_SPHERES, viewer);
attrib_buffers(viewer, PROGRAM_CUTPLANE_SPHERES);
program->bind();
QVector4D cp(plane.a(),plane.b(),plane.c(),plane.d());
program->setUniformValue("cutplane", cp);
}
else
{
program = getShaderProgram(PROGRAM_SPHERES, viewer);
attrib_buffers(viewer, PROGRAM_SPHERES);
program->bind();
}
viewer->glDrawArraysInstanced(GL_LINES, 0,
static_cast<GLsizei>(vertices.size()/3),
static_cast<GLsizei>(nb_centers));
program->release();
vaos[Edges]->release();
}
void Scene_spheres_item::add_sphere(CGAL::Sphere_3<Kernel> *sphere, CGAL::Color color)
{
sphere_pair pair_(sphere, color);
spheres.append(pair_);
}
void Scene_spheres_item::remove_sphere(CGAL::Sphere_3<Kernel> *sphere)
{
Q_FOREACH(sphere_pair pair_, spheres)
if(pair_.first == sphere)
{
spheres.removeAll(pair_);
break;
}
}

View File

@ -0,0 +1,96 @@
#ifndef SCENE_SPHERES_ITEM_H
#define SCENE_SPHERES_ITEM_H
#include "Scene_basic_objects_config.h"
#include "create_sphere.h"
#include "CGAL/Three/Scene_group_item.h"
#include <CGAL/Three/Scene_item.h>
#include <CGAL/Three/Scene_interface.h>
#include <CGAL/Three/Viewer_interface.h>
#include <CGAL/Sphere_3.h>
#include <CGAL/Plane_3.h>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <QOpenGLShaderProgram>
#include <QList>
#include<vector>
class SCENE_BASIC_OBJECTS_EXPORT Scene_spheres_item
: public CGAL::Three::Scene_item
{
Q_OBJECT
public:
typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
typedef std::pair<CGAL::Sphere_3<Kernel>*, CGAL::Color> sphere_pair ;
Scene_spheres_item(Scene_group_item* parent, bool planed = false)
:CGAL::Three::Scene_item(NbOfVbos,NbOfVaos)
,precision(36)
,has_plane(planed)
{
setParent(parent);
create_flat_and_wire_sphere(1.0f,vertices,normals, edges);
}
~Scene_spheres_item() {
Q_FOREACH(sphere_pair sphere, spheres)
delete sphere.first;
}
bool isFinite() const { return false; }
bool isEmpty() const { return false; }
Scene_item* clone() const {return 0;}
QString toolTip() const {return QString();}
bool supportsRenderingMode(RenderingMode m) const {
return (m == Gouraud || m == Wireframe);
}
void compute_bbox() const { _bbox = Bbox(); }
void add_sphere(CGAL::Sphere_3<Kernel>* sphere, CGAL::Color = CGAL::Color(120,120,120));
void remove_sphere(CGAL::Sphere_3<Kernel>* sphere);
void setPrecision(int prec) { precision = prec; }
void draw(CGAL::Three::Viewer_interface* viewer) const;
void draw_edges(CGAL::Three::Viewer_interface* viewer) const;
void invalidateOpenGLBuffers(){are_buffers_filled = false;}
void computeElements() const;
void setPlane(Kernel::Plane_3 p_plane) { plane = p_plane; }
private:
enum Vbos
{
Vertices = 0,
Edge_vertices,
Normals,
Center,
Radius,
Color,
Edge_color,
NbOfVbos
};
enum Vaos
{
Facets = 0,
Edges,
NbOfVaos
};
int precision;
mutable CGAL::Plane_3<Kernel> plane;
bool has_plane;
QList<sphere_pair> spheres;
mutable std::vector<float> vertices;
mutable std::vector<float> normals;
mutable std::vector<float> edges;
mutable std::vector<float> colors;
mutable std::vector<float> edges_colors;
mutable std::vector<float> centers;
mutable std::vector<float> radius;
mutable QOpenGLShaderProgram *program;
mutable int nb_centers;
void initializeBuffers(CGAL::Three::Viewer_interface *viewer)const;
};
#endif // SCENE_SPHERES_ITEM_H

View File

@ -458,26 +458,16 @@ void Viewer::attrib_buffers(int program_name) const {
QVector4D specular(0.0f, 0.0f, 0.0f, 1.0f); QVector4D specular(0.0f, 0.0f, 0.0f, 1.0f);
QOpenGLShaderProgram* program = getShaderProgram(program_name); QOpenGLShaderProgram* program = getShaderProgram(program_name);
program->bind(); program->bind();
program->setUniformValue("mvp_matrix", mvp_mat);
switch(program_name) switch(program_name)
{ {
case PROGRAM_NO_SELECTION:
program->setUniformValue("mvp_matrix", mvp_mat);
program->setUniformValue("f_matrix",f_mat);
break;
case PROGRAM_WITH_LIGHT: case PROGRAM_WITH_LIGHT:
program->setUniformValue("mvp_matrix", mvp_mat);
program->setUniformValue("mv_matrix", mv_mat);
program->setUniformValue("light_pos", position);
program->setUniformValue("light_diff",diffuse);
program->setUniformValue("light_spec", specular);
program->setUniformValue("light_amb", ambient);
program->setUniformValue("spec_power", 51.8f);
program->setUniformValue("is_two_side", is_both_sides);
break;
case PROGRAM_C3T3: case PROGRAM_C3T3:
program->setUniformValue("mvp_matrix", mvp_mat); case PROGRAM_PLANE_TWO_FACES:
program->setUniformValue("mv_matrix", mv_mat); case PROGRAM_INSTANCED:
case PROGRAM_WITH_TEXTURE:
case PROGRAM_CUTPLANE_SPHERES:
case PROGRAM_SPHERES:
program->setUniformValue("light_pos", position); program->setUniformValue("light_pos", position);
program->setUniformValue("light_diff",diffuse); program->setUniformValue("light_diff",diffuse);
program->setUniformValue("light_spec", specular); program->setUniformValue("light_spec", specular);
@ -485,69 +475,30 @@ void Viewer::attrib_buffers(int program_name) const {
program->setUniformValue("spec_power", 51.8f); program->setUniformValue("spec_power", 51.8f);
program->setUniformValue("is_two_side", is_both_sides); program->setUniformValue("is_two_side", is_both_sides);
break; break;
case PROGRAM_C3T3_EDGES: }
program->setUniformValue("mvp_matrix", mvp_mat); switch(program_name)
{
case PROGRAM_WITH_LIGHT:
case PROGRAM_C3T3:
case PROGRAM_PLANE_TWO_FACES:
case PROGRAM_INSTANCED:
case PROGRAM_CUTPLANE_SPHERES:
case PROGRAM_SPHERES:
program->setUniformValue("mv_matrix", mv_mat);
break; break;
case PROGRAM_WITHOUT_LIGHT: case PROGRAM_WITHOUT_LIGHT:
program->setUniformValue("mvp_matrix", mvp_mat);
program->setUniformValue("mv_matrix", mv_mat);
program->setUniformValue("light_pos", position);
program->setUniformValue("light_diff", diffuse);
program->setUniformValue("light_spec", specular);
program->setUniformValue("light_amb", ambient);
program->setUniformValue("spec_power", 51.8f);
program->setUniformValue("is_two_side", is_both_sides);
program->setAttributeValue("normals", 0.0,0.0,0.0);
program->setUniformValue("f_matrix",f_mat); program->setUniformValue("f_matrix",f_mat);
break; break;
case PROGRAM_WITH_TEXTURE: case PROGRAM_WITH_TEXTURE:
program->setUniformValue("mvp_matrix", mvp_mat);
program->setUniformValue("mv_matrix", mv_mat); program->setUniformValue("mv_matrix", mv_mat);
program->setUniformValue("light_pos", position);
program->setUniformValue("light_diff",diffuse);
program->setUniformValue("light_spec", specular);
program->setUniformValue("light_amb", ambient);
program->setUniformValue("spec_power", 51.8f);
program->setUniformValue("s_texture",0); program->setUniformValue("s_texture",0);
program->setUniformValue("f_matrix",f_mat); program->setUniformValue("f_matrix",f_mat);
break; break;
case PROGRAM_PLANE_TWO_FACES:
program->setUniformValue("mvp_matrix", mvp_mat);
program->setUniformValue("mv_matrix", mv_mat);
program->setUniformValue("light_pos", position);
program->setUniformValue("light_diff",diffuse);
program->setUniformValue("light_spec", specular);
program->setUniformValue("light_amb", ambient);
program->setUniformValue("spec_power", 51.8f);
program->setUniformValue("is_two_side", is_both_sides);
break;
case PROGRAM_WITH_TEXTURED_EDGES: case PROGRAM_WITH_TEXTURED_EDGES:
program->setUniformValue("mvp_matrix", mvp_mat);
program->setUniformValue("s_texture",0); program->setUniformValue("s_texture",0);
break; break;
case PROGRAM_INSTANCED: case PROGRAM_NO_SELECTION:
program->setUniformValue("f_matrix",f_mat);
program->setUniformValue("mvp_matrix", mvp_mat);
program->setUniformValue("mv_matrix", mv_mat);
program->setUniformValue("light_pos", position);
program->setUniformValue("light_diff",diffuse);
program->setUniformValue("light_spec", specular);
program->setUniformValue("light_amb", ambient);
program->setUniformValue("spec_power", 51.8f);
program->setUniformValue("is_two_side", is_both_sides);
break;
case PROGRAM_INSTANCED_WIRE:
program->setUniformValue("mvp_matrix", mvp_mat);
break; break;
} }
program->release(); program->release();
@ -1110,6 +1061,51 @@ QOpenGLShaderProgram* Viewer::getShaderProgram(int name) const
} }
break; break;
case PROGRAM_CUTPLANE_SPHERES:
if( d->shader_programs[PROGRAM_CUTPLANE_SPHERES])
{
return d->shader_programs[PROGRAM_CUTPLANE_SPHERES];
}
else
{
QOpenGLShaderProgram *program = new QOpenGLShaderProgram(viewer);
if(!program->addShaderFromSourceFile(QOpenGLShader::Vertex,":/cgal/Polyhedron_3/resources/shader_c3t3_spheres.v"))
{
std::cerr<<"adding vertex shader FAILED"<<std::endl;
}
if(!program->addShaderFromSourceFile(QOpenGLShader::Fragment,":/cgal/Polyhedron_3/resources/shader_c3t3.f" ))
{
std::cerr<<"adding fragment shader FAILED"<<std::endl;
}
program->bindAttributeLocation("colors", 1);
program->link();
d->shader_programs[PROGRAM_CUTPLANE_SPHERES] = program;
return program;
}
case PROGRAM_SPHERES:
if( d->shader_programs[PROGRAM_SPHERES])
{
return d->shader_programs[PROGRAM_SPHERES];
}
else
{
QOpenGLShaderProgram *program = new QOpenGLShaderProgram(viewer);
if(!program->addShaderFromSourceFile(QOpenGLShader::Vertex,":/cgal/Polyhedron_3/resources/shader_spheres.v" ))
{
std::cerr<<"adding vertex shader FAILED"<<std::endl;
}
if(!program->addShaderFromSourceFile(QOpenGLShader::Fragment,":/cgal/Polyhedron_3/resources/shader_with_light.f" ))
{
std::cerr<<"adding fragment shader FAILED"<<std::endl;
}
program->bindAttributeLocation("colors", 1);
program->link();
d->shader_programs[PROGRAM_SPHERES] = program;
return program;
}
break;
default: default:
std::cerr<<"ERROR : Program not found."<<std::endl; std::cerr<<"ERROR : Program not found."<<std::endl;
return 0; return 0;

View File

@ -0,0 +1,21 @@
#version 120
attribute highp vec4 vertex;
attribute highp vec3 normals;
attribute highp vec3 colors;
attribute highp vec3 center;
attribute highp float radius;
uniform highp mat4 mvp_matrix;
uniform highp mat4 mv_matrix;
varying highp vec4 fP;
varying highp vec3 fN;
varying highp vec4 color;
void main(void)
{
color = vec4(colors, 1.0);
fP = mv_matrix * vertex;
fN = mat3(mv_matrix)* normals;
gl_Position = mvp_matrix *
vec4(radius*vertex.x + center.x, radius* vertex.y + center.y, radius*vertex.z + center.z, 1.0) ;
}

View File

@ -40,7 +40,7 @@ class DEMO_FRAMEWORK_EXPORT Scene_group_item : public Scene_item
{ {
Q_OBJECT Q_OBJECT
public : public :
Scene_group_item(QString name = QString("New group")); Scene_group_item(QString name = QString("New group"), int nb_vbos = 0, int nb_vaos = 0);
~Scene_group_item() {} ~Scene_group_item() {}
//!Returns false to avoid disturbing the BBox of the scene. //!Returns false to avoid disturbing the BBox of the scene.
bool isFinite() const; bool isFinite() const;
@ -122,12 +122,7 @@ public :
//!@see getChildren @see addChild //!@see getChildren @see addChild
void removeChild( Scene_item* item) void removeChild( Scene_item* item)
{ {
Scene_group_item* group = update_group_number(item,0);
qobject_cast<Scene_group_item*>(item);
if(group)
Q_FOREACH(Scene_item* child, group->getChildren())
removeChild(child);
item->has_group=0;
children.removeOne(item); children.removeOne(item);
} }
//!Moves a child up in the list. //!Moves a child up in the list.
@ -139,7 +134,8 @@ private:
//!Contains a reference to all the children of this group. //!Contains a reference to all the children of this group.
QList<Scene_item*> children; QList<Scene_item*> children;
//!Updates the property has_group for each group and sub-groups containing new_item. //!Updates the property has_group for each group and sub-groups containing new_item.
void add_group_number(Scene_item*new_item); void update_group_number(Scene_item*new_item, int n);
bool expanded; bool expanded;
}; //end of class Scene_group_item }; //end of class Scene_group_item

View File

@ -72,6 +72,8 @@ public:
PROGRAM_INSTANCED_WIRE, /** Used to display instanced rendered wired spheres. Not affected by light.*/ PROGRAM_INSTANCED_WIRE, /** Used to display instanced rendered wired spheres. Not affected by light.*/
PROGRAM_C3T3, /** Used to render a c3t3_item. It discards any fragment on a side of a plane, meaning that nothing is displayed on this side of the plane. Affected by light.*/ PROGRAM_C3T3, /** Used to render a c3t3_item. It discards any fragment on a side of a plane, meaning that nothing is displayed on this side of the plane. Affected by light.*/
PROGRAM_C3T3_EDGES, /** Used to render the edges of a c3t3_item. It discards any fragment on a side of a plane, meaning that nothing is displayed on this side of the plane. Not affected by light.*/ PROGRAM_C3T3_EDGES, /** Used to render the edges of a c3t3_item. It discards any fragment on a side of a plane, meaning that nothing is displayed on this side of the plane. Not affected by light.*/
PROGRAM_CUTPLANE_SPHERES, /** Used to render the spheres of an item with a cut plane.*/
PROGRAM_SPHERES, /** Used to render one or several spheres.*/
NB_OF_PROGRAMS /** Holds the number of different programs in this enum.*/ NB_OF_PROGRAMS /** Holds the number of different programs in this enum.*/
}; };
typedef CGAL::Three::Scene_interface::Bbox Bbox; typedef CGAL::Three::Scene_interface::Bbox Bbox;

View File

@ -61,6 +61,8 @@ public:
PROGRAM_INSTANCED_WIRE, /** Used to display instanced rendered wired spheres. Not affected by light.*/ PROGRAM_INSTANCED_WIRE, /** Used to display instanced rendered wired spheres. Not affected by light.*/
PROGRAM_C3T3, /** Used to render a c3t3_item. It discards any fragment on a side of a plane, meaning that nothing is displayed on this side of the plane. Affected by light.*/ PROGRAM_C3T3, /** Used to render a c3t3_item. It discards any fragment on a side of a plane, meaning that nothing is displayed on this side of the plane. Affected by light.*/
PROGRAM_C3T3_EDGES, /** Used to render the edges of a c3t3_item. It discards any fragment on a side of a plane, meaning that nothing is displayed on this side of the plane. Not affected by light.*/ PROGRAM_C3T3_EDGES, /** Used to render the edges of a c3t3_item. It discards any fragment on a side of a plane, meaning that nothing is displayed on this side of the plane. Not affected by light.*/
PROGRAM_CUTPLANE_SPHERES, /** Used to render the spheres of an item with a cut plane.*/
PROGRAM_SPHERES, /** Used to render one or several spheres.*/
NB_OF_PROGRAMS /** Holds the number of different programs in this enum.*/ NB_OF_PROGRAMS /** Holds the number of different programs in this enum.*/
}; };