diff --git a/Polyhedron/demo/Polyhedron/CMakeLists.txt b/Polyhedron/demo/Polyhedron/CMakeLists.txt index c2d17f13c03..404e10a6d31 100644 --- a/Polyhedron/demo/Polyhedron/CMakeLists.txt +++ b/Polyhedron/demo/Polyhedron/CMakeLists.txt @@ -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}) endmacro(add_item) + add_item(scene_spheres_item Scene_spheres_item) add_item(scene_c2t3_item Scene_c2t3_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_transform_item Plugins/PCA/Scene_polyhedron_transform_item.cpp ) @@ -272,8 +273,9 @@ if(CGAL_Qt5_FOUND AND Qt5_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND) target_link_libraries(scene_nef_polyhedron_item scene_polyhedron_item) 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( demo_framework gl_splat) - + diff --git a/Polyhedron/demo/Polyhedron/MainWindow.cpp b/Polyhedron/demo/Polyhedron/MainWindow.cpp index 58f21095194..feb1f1a4f56 100644 --- a/Polyhedron/demo/Polyhedron/MainWindow.cpp +++ b/Polyhedron/demo/Polyhedron/MainWindow.cpp @@ -1745,7 +1745,7 @@ void MainWindow::restoreCollapseState() void MainWindow::make_new_group() { Scene_group_item * group = new Scene_group_item("New group"); - scene->add_group(group); + scene->addItem(group); } void MainWindow::on_upButton_pressed() diff --git a/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/Mesh_3_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/Mesh_3_plugin.cpp index b3cb2c5519f..0fd0eb84b34 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/Mesh_3_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/Mesh_3_plugin.cpp @@ -439,7 +439,7 @@ treat_result(Scene_item& source_item, const Scene_interface::Item_id index = scene->mainSelectionIndex(); scene->itemChanged(index); - + scene->setSelectedItem(-1); Scene_interface::Item_id new_item_id = scene->addItem(&result_item); scene->setSelectedItem(new_item_id); } diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_3.qrc b/Polyhedron/demo/Polyhedron/Polyhedron_3.qrc index 7556d9f170d..040c1c655ee 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_3.qrc +++ b/Polyhedron/demo/Polyhedron/Polyhedron_3.qrc @@ -39,5 +39,6 @@ resources/shader_c3t3.v resources/shader_c3t3.f resources/shader_plane_two_faces.f + resources/shader_spheres.v diff --git a/Polyhedron/demo/Polyhedron/Scene.cpp b/Polyhedron/demo/Polyhedron/Scene.cpp index fa0ff09a9db..7751ccd580b 100644 --- a/Polyhedron/demo/Polyhedron/Scene.cpp +++ b/Polyhedron/demo/Polyhedron/Scene.cpp @@ -50,10 +50,6 @@ Scene::Scene(QObject* parent) Scene::Item_id Scene::addItem(CGAL::Three::Scene_item* item) { - CGAL::Three::Scene_group_item* group = - qobject_cast(item); - if(group) - m_group_entries.prepend(group); Bbox bbox_before = bbox(); m_entries.push_back(item); connect(item, SIGNAL(itemChanged()), @@ -80,6 +76,10 @@ Scene::addItem(CGAL::Three::Scene_item* item) Q_EMIT updated(); Item_id id = m_entries.size() - 1; Q_EMIT newItem(id); + CGAL::Three::Scene_group_item* group = + qobject_cast(item); + if(group) + add_group(group); //if group selected, add item to it if(mainSelectionIndex() >=0) { @@ -91,7 +91,7 @@ Scene::addItem(CGAL::Three::Scene_item* item) if(selected_group) { 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(); itemChanged(index); Q_EMIT restoreCollapsedState(); - group_added(); + redraw_model(); return item; } @@ -231,7 +231,7 @@ Scene::~Scene() { Q_FOREACH(CGAL::Three::Scene_item* item_ptr, m_entries) { - delete item_ptr; + item_ptr->deleteLater(); } m_entries.clear(); @@ -737,66 +737,62 @@ bool Scene::dropMimeData(const QMimeData * /*data*/, int /*column*/, const QModelIndex &parent) { - //gets the moving items - QList items; - QList groups_children; + //gets the moving items + QList items; + QList groups_children; - //get IDs of all children of selected groups - Q_FOREACH(int i, selected_items_list) - { - CGAL::Three::Scene_group_item* group = - qobject_cast(item(i)); - if(group) - Q_FOREACH(Scene_item* child, group->getChildren()) - groups_children << item_id(child); - } - // Insure that children of selected groups will not be added twice - Q_FOREACH(int i, selected_items_list) - { - if(!groups_children.contains(i)) - items << item(i); - } - //Gets the group at the drop position + //get IDs of all children of selected groups + Q_FOREACH(int i, selected_items_list) + { CGAL::Three::Scene_group_item* group = - qobject_cast(this->item(index_map[parent])); - bool one_contained = false; + qobject_cast(item(i)); if(group) - { + Q_FOREACH(Scene_item* child, group->getChildren()) + groups_children << item_id(child); + } + // Insure that children of selected groups will not be added twice + Q_FOREACH(int i, selected_items_list) + { + if(!groups_children.contains(i)) + items << item(i); + } + //Gets the group at the drop position + CGAL::Three::Scene_group_item* group = + qobject_cast(this->item(index_map[parent])); + bool one_contained = false; + if(group) + { Q_FOREACH(int id, selected_items_list) - if(group->getChildren().contains(item(id))) - { - one_contained = true; - break; - } - } + if(group->getChildren().contains(item(id))) + { + one_contained = true; + 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(!group ||one_contained) { - //unless the drop zone is empty, which means the item should be removed from all groups. - if(!parent.isValid()) + //unless the drop zone is empty, which means the item should be removed from all groups. + 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(group_item->getChildren().contains(item)) - { - group_item->removeChild(item); - break; - } - } - group_added(); - return true; + if(item->parentGroup()) + { + item->parentGroup()->removeChild(item); + } } - return false; + redraw_model(); + return true; + } + return false; } - Q_FOREACH(Scene_item* item, items) - changeGroup(item, group); + Q_FOREACH(Scene_item* item, items) + changeGroup(item, group); //group->addChild(item(mainSelectionIndex())); - group_added(); + redraw_model(); return true; - - } void Scene::moveRowUp() @@ -820,7 +816,7 @@ void Scene::moveRowUp() int newId = index_map.value(index(baseId.row()-1, baseId.column(),baseId.parent())) ; m_entries.move(mainSelectionIndex(), newId); } - group_added(); + redraw_model(); 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())) ; m_entries.move(mainSelectionIndex(), newId); } - group_added(); + redraw_model(); setSelectedItem(m_entries.indexOf(selected_item)); } } @@ -1102,7 +1098,7 @@ QList Scene::item_entries() const { return m_entries; } -void Scene::group_added() +void Scene::redraw_model() { //makes the hierarchy in the tree //clears the model @@ -1118,18 +1114,11 @@ void Scene::group_added() void Scene::changeGroup(Scene_item *item, CGAL::Three::Scene_group_item *target_group) { //remove item from the containing group if any - if(item->has_group!=0) - Q_FOREACH(CGAL::Three::Scene_group_item* group, m_group_entries) - { - if(group->getChildren().contains(item)) - { - remove_item_from_groups(item); - break; - } - } - //add the item to the target group - target_group->addChild(item); - item->moveToGroup(target_group); + if(item->parentGroup()) + item->parentGroup()->removeChild(item); + //add the item to the target group + target_group->addChild(item); + item->moveToGroup(target_group); } float Scene::get_bbox_length() const @@ -1250,16 +1239,14 @@ void Scene::add_group(Scene_group_item* group) Q_FOREACH(int id, indices) changeGroup(item(id),group); changeGroup(group, existing_group); - addItem(group); - group_added(); + redraw_model(); } - //else wer create a new group + //else we create a new group else { Q_FOREACH(int id, indices) changeGroup(item(id),group); - addItem(group); - group_added(); + redraw_model(); } } diff --git a/Polyhedron/demo/Polyhedron/Scene.h b/Polyhedron/demo/Polyhedron/Scene.h index ea2c968209f..a79c62cf562 100644 --- a/Polyhedron/demo/Polyhedron/Scene.h +++ b/Polyhedron/demo/Polyhedron/Scene.h @@ -178,9 +178,8 @@ public Q_SLOTS: //!Removes item from all the groups of the scene. void remove_item_from_groups(CGAL::Three::Scene_item* item); - void add_group(Scene_group_item* group); //!Re-organizes the sceneView. - void group_added(); + void redraw_model(); //! Sets the selected item to the target index. void setSelectedItemIndex(int i) { @@ -249,7 +248,7 @@ private Q_SLOTS: //! Casts a selection ray and calls the item function select. void setSelectionRay(double, double, double, double, double, double); void callDraw(){ QGLViewer* viewer = *QGLViewer::QGLViewerPool().begin(); viewer->update();} - + void add_group(Scene_group_item* group); private: /*! Calls the drawing functions of each visible item according * to its current renderingMode. If with_names is true, uses diff --git a/Polyhedron/demo/Polyhedron/Scene_c3t3_item.cpp b/Polyhedron/demo/Polyhedron/Scene_c3t3_item.cpp index 7f771aea7ca..981345463b5 100644 --- a/Polyhedron/demo/Polyhedron/Scene_c3t3_item.cpp +++ b/Polyhedron/demo/Polyhedron/Scene_c3t3_item.cpp @@ -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"<addShaderFromSourceFile(QOpenGLShader::Fragment,":/cgal/Polyhedron_3/resources/shader_c3t3.f" )) - { - std::cerr<<"adding fragment shader FAILED"<link()) - { - //std::cerr<<"linking Program FAILED"<log(); - } -} double complex_diag(const Scene_item* item) { const Scene_item::Bbox& bbox = item->bbox(); 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_item(NumberOfBuffers, NumberOfVaos) + : Scene_group_item("unnamed", NumberOfBuffers, NumberOfVaos) , d(new Scene_c3t3_item_priv(this)) , frame(new ManipulatedFrame()) , last_known_scene(NULL) @@ -146,18 +129,19 @@ Scene_c3t3_item::Scene_c3t3_item() s_normals.resize(0); ws_vertex.resize(0); need_changed = false; + spheres = NULL; + compute_bbox(); startTimer(0); connect(frame, SIGNAL(modified()), this, SLOT(changed())); c3t3_changed(); setRenderingMode(FlatPlusEdges); - compile_shaders(); spheres_are_shown = false; create_flat_and_wire_sphere(1.0f,s_vertex,s_normals, ws_vertex); } 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)) , frame(new ManipulatedFrame()) , last_known_scene(NULL) @@ -172,12 +156,13 @@ Scene_c3t3_item::Scene_c3t3_item(const C3t3& c3t3) s_normals.resize(0); ws_vertex.resize(0); need_changed = false; + spheres = NULL; + compute_bbox(); startTimer(0); connect(frame, SIGNAL(modified()), this, SLOT(changed())); reset_cut_plane(); c3t3_changed(); setRenderingMode(FlatPlusEdges); - compile_shaders(); spheres_are_shown = false; 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(); - program = getShaderProgram(PROGRAM_WITHOUT_LIGHT); - attrib_buffers(viewer, PROGRAM_WITHOUT_LIGHT); + program = getShaderProgram(PROGRAM_NO_SELECTION); + attrib_buffers(viewer, PROGRAM_NO_SELECTION); program->bind(); program->setAttributeValue("colors", QColor(Qt::black)); QMatrix4x4 f_mat; @@ -563,48 +548,9 @@ void Scene_c3t3_item::draw(CGAL::Three::Viewer_interface* viewer) const { if(spheres_are_shown) { - vaos[Spheres]->bind(); - 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(s_vertex.size()/3), - static_cast(s_radius.size())); - program_sphere->release(); - vaos[Spheres]->release(); + spheres->setPlane(this->plane()); } + Scene_group_item::draw(viewer); } 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) { vaos[Grid]->bind(); - program = getShaderProgram(PROGRAM_WITHOUT_LIGHT); - attrib_buffers(viewer, PROGRAM_WITHOUT_LIGHT); + program = getShaderProgram(PROGRAM_NO_SELECTION); + attrib_buffers(viewer, PROGRAM_NO_SELECTION); program->bind(); program->setAttributeValue("colors", QColor(Qt::black)); QMatrix4x4 f_mat; @@ -665,46 +611,9 @@ void Scene_c3t3_item::draw_edges(CGAL::Three::Viewer_interface* viewer) const { if(spheres_are_shown) { - vaos[Wired_spheres]->bind(); - 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(ws_vertex.size()/3), - static_cast(s_radius.size())); - program_sphere->release(); - vaos[Wired_spheres]->release(); + spheres->setPlane(this->plane()); } + Scene_group_item::draw_edges(viewer); } 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(); vaos[Grid]->bind(); - program = getShaderProgram(PROGRAM_WITHOUT_LIGHT); - attrib_buffers(viewer, PROGRAM_WITHOUT_LIGHT); + program = getShaderProgram(PROGRAM_NO_SELECTION); + attrib_buffers(viewer, PROGRAM_NO_SELECTION); program->bind(); program->setAttributeValue("colors", this->color()); 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 { - program = getShaderProgram(PROGRAM_WITHOUT_LIGHT, viewer); + program = getShaderProgram(PROGRAM_NO_SELECTION, viewer); program->bind(); vaos[Grid]->bind(); @@ -1011,93 +920,7 @@ void Scene_c3t3_item::initialize_buffers(CGAL::Three::Viewer_interface *viewer) program->release(); } - //vao containing the data for the spheres - { - program_sphere->bind(); - - vaos[Spheres]->bind(); - buffers[Sphere_vertices].bind(); - buffers[Sphere_vertices].allocate(s_vertex.data(), - static_cast(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(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(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(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(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(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(); + program->release(); are_buffers_filled = true; } @@ -1180,6 +1003,44 @@ void Scene_c3t3_item::compute_intersections() 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 incident_vertices; + d->c3t3.triangulation().incident_vertices(vit, std::back_inserter(incident_vertices)); + bool red = vit->is_special(); + for(std::vector::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() { @@ -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 incident_vertices; - d->c3t3.triangulation().incident_vertices(vit, std::back_inserter(incident_vertices)); - bool red = vit->is_special(); - for(std::vector::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) { 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 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(); + +} diff --git a/Polyhedron/demo/Polyhedron/Scene_c3t3_item.h b/Polyhedron/demo/Polyhedron/Scene_c3t3_item.h index b7508f7f55b..2459a7b7a2e 100644 --- a/Polyhedron/demo/Polyhedron/Scene_c3t3_item.h +++ b/Polyhedron/demo/Polyhedron/Scene_c3t3_item.h @@ -3,6 +3,7 @@ #include "Scene_c3t3_item_config.h" #include "C3t3_type.h" +#include "Scene_spheres_item.h" #include #include @@ -19,8 +20,7 @@ #include #include - -#include +#include #include #include #include @@ -29,7 +29,7 @@ struct Scene_c3t3_item_priv; using namespace CGAL::Three; class SCENE_C3T3_ITEM_EXPORT Scene_c3t3_item - : public Scene_item + : public Scene_group_item { Q_OBJECT public: @@ -86,8 +86,12 @@ public: && 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 { return 0; } @@ -129,12 +133,11 @@ private: void data_item_destroyed(); - void show_spheres(bool b) + void reset_spheres() { - spheres_are_shown = b; - Q_EMIT redraw(); - + spheres = NULL; } + void show_spheres(bool b); virtual QPixmap graphicalToolTip() const; void update_histogram(); @@ -170,12 +173,6 @@ private: Facet_colors, Edges_vertices, Grid_vertices, - Sphere_vertices, - Sphere_normals, - Sphere_colors, - Sphere_radius, - Sphere_center, - Wired_spheres_vertices, iEdges_vertices, iFacet_vertices, iFacet_normals, @@ -187,8 +184,6 @@ private: Facets=0, Edges, Grid, - Spheres, - Wired_spheres, iEdges, iFacets, NumberOfVaos @@ -196,6 +191,7 @@ private: qglviewer::ManipulatedFrame* frame; CGAL::Three::Scene_interface* last_known_scene; + Scene_spheres_item *spheres; bool spheres_are_shown; const Scene_item* data_item_; QPixmap histogram_; @@ -226,14 +222,14 @@ private: mutable std::vector s_radius; mutable std::vector s_center; mutable QOpenGLShaderProgram *program; - mutable QOpenGLShaderProgram *program_sphere; + using Scene_item::initialize_buffers; void initialize_buffers(CGAL::Three::Viewer_interface *viewer); void initialize_intersection_buffers(CGAL::Three::Viewer_interface *viewer); + void compute_spheres(); void compute_elements(); void compute_intersections(); - void compile_shaders(); }; #endif // SCENE_C3T3_ITEM_H diff --git a/Polyhedron/demo/Polyhedron/Scene_group_item.cpp b/Polyhedron/demo/Polyhedron/Scene_group_item.cpp index e3d870e38ab..b005d2fd3e0 100644 --- a/Polyhedron/demo/Polyhedron/Scene_group_item.cpp +++ b/Polyhedron/demo/Polyhedron/Scene_group_item.cpp @@ -3,8 +3,8 @@ #include using namespace CGAL::Three; -Scene_group_item::Scene_group_item(QString name) - : Scene_item(0,0) +Scene_group_item::Scene_group_item(QString name, int nb_vbos, int nb_vaos ) + : Scene_item(nb_vbos, nb_vaos) { this->name_ = name; expanded = true; @@ -53,20 +53,20 @@ void Scene_group_item::addChild(Scene_item* new_item) if(!children.contains(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 = qobject_cast(new_item); if(group) Q_FOREACH(Scene_item* child, group->getChildren()) - add_group_number(child); - new_item->has_group++; + update_group_number(child,n+1); + new_item->has_group = n; } void Scene_group_item::setColor(QColor c) { diff --git a/Polyhedron/demo/Polyhedron/Scene_polyhedron_item.cpp b/Polyhedron/demo/Polyhedron/Scene_polyhedron_item.cpp index 166603041d9..7297fdc493c 100644 --- a/Polyhedron/demo/Polyhedron/Scene_polyhedron_item.cpp +++ b/Polyhedron/demo/Polyhedron/Scene_polyhedron_item.cpp @@ -736,13 +736,15 @@ Scene_polyhedron_item::toolTip() const QObject::tr("

Polyhedron %1 (mode: %5, color: %6)

" "

Number of vertices: %2
" "Number of edges: %3
" - "Number of facets: %4") + "Number of facets: %4
" + "has_group = %7") .arg(this->name()) .arg(poly->size_of_vertices()) .arg(poly->size_of_halfedges()/2) .arg(poly->size_of_facets()) .arg(this->renderingModeName()) - .arg(this->color().name()); + .arg(this->color().name()) + .arg(this->has_group); str += QString("
Number of isolated vertices : %1
").arg(getNbIsolatedvertices()); return str; } diff --git a/Polyhedron/demo/Polyhedron/Scene_spheres_item.cpp b/Polyhedron/demo/Polyhedron/Scene_spheres_item.cpp new file mode 100644 index 00000000000..96c1747abb0 --- /dev/null +++ b/Polyhedron/demo/Polyhedron/Scene_spheres_item.cpp @@ -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(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(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(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(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(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(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(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(vertices.size()/3), + static_cast(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(vertices.size()/3), + static_cast(nb_centers)); + program->release(); + vaos[Edges]->release(); +} +void Scene_spheres_item::add_sphere(CGAL::Sphere_3 *sphere, CGAL::Color color) +{ + sphere_pair pair_(sphere, color); + spheres.append(pair_); +} + +void Scene_spheres_item::remove_sphere(CGAL::Sphere_3 *sphere) +{ + Q_FOREACH(sphere_pair pair_, spheres) + if(pair_.first == sphere) + { + spheres.removeAll(pair_); + break; + } +} diff --git a/Polyhedron/demo/Polyhedron/Scene_spheres_item.h b/Polyhedron/demo/Polyhedron/Scene_spheres_item.h new file mode 100644 index 00000000000..e4a2efb88f4 --- /dev/null +++ b/Polyhedron/demo/Polyhedron/Scene_spheres_item.h @@ -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 +#include +#include +#include +#include +#include +#include + +#include +#include + +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::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* sphere, CGAL::Color = CGAL::Color(120,120,120)); + void remove_sphere(CGAL::Sphere_3* 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 plane; + bool has_plane; + + QList spheres; + mutable std::vector vertices; + mutable std::vector normals; + mutable std::vector edges; + mutable std::vector colors; + mutable std::vector edges_colors; + mutable std::vector centers; + mutable std::vector radius; + mutable QOpenGLShaderProgram *program; + mutable int nb_centers; + void initializeBuffers(CGAL::Three::Viewer_interface *viewer)const; + +}; + +#endif // SCENE_SPHERES_ITEM_H diff --git a/Polyhedron/demo/Polyhedron/Viewer.cpp b/Polyhedron/demo/Polyhedron/Viewer.cpp index 2e4c47ce637..96b92cfb79e 100644 --- a/Polyhedron/demo/Polyhedron/Viewer.cpp +++ b/Polyhedron/demo/Polyhedron/Viewer.cpp @@ -458,96 +458,47 @@ void Viewer::attrib_buffers(int program_name) const { QVector4D specular(0.0f, 0.0f, 0.0f, 1.0f); QOpenGLShaderProgram* program = getShaderProgram(program_name); program->bind(); + program->setUniformValue("mvp_matrix", mvp_mat); switch(program_name) { - case PROGRAM_NO_SELECTION: - program->setUniformValue("mvp_matrix", mvp_mat); - - program->setUniformValue("f_matrix",f_mat); - break; 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: - 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_EDGES: - program->setUniformValue("mvp_matrix", mvp_mat); - break; - 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); - - - break; - case PROGRAM_WITH_TEXTURE: - - 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("s_texture",0); - program->setUniformValue("f_matrix",f_mat); - - 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: - - program->setUniformValue("mvp_matrix", mvp_mat); - program->setUniformValue("s_texture",0); - - break; case PROGRAM_INSTANCED: - - program->setUniformValue("mvp_matrix", mvp_mat); - program->setUniformValue("mv_matrix", mv_mat); - + case PROGRAM_WITH_TEXTURE: + case PROGRAM_CUTPLANE_SPHERES: + case PROGRAM_SPHERES: 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); + } + 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; + case PROGRAM_WITHOUT_LIGHT: + program->setUniformValue("f_matrix",f_mat); + break; + case PROGRAM_WITH_TEXTURE: + program->setUniformValue("mv_matrix", mv_mat); + program->setUniformValue("s_texture",0); + program->setUniformValue("f_matrix",f_mat); + break; + case PROGRAM_WITH_TEXTURED_EDGES: + program->setUniformValue("s_texture",0); + break; + case PROGRAM_NO_SELECTION: + program->setUniformValue("f_matrix",f_mat); break; } program->release(); @@ -1110,6 +1061,51 @@ QOpenGLShaderProgram* Viewer::getShaderProgram(int name) const } 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"<addShaderFromSourceFile(QOpenGLShader::Fragment,":/cgal/Polyhedron_3/resources/shader_c3t3.f" )) + { + std::cerr<<"adding fragment shader FAILED"<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"<addShaderFromSourceFile(QOpenGLShader::Fragment,":/cgal/Polyhedron_3/resources/shader_with_light.f" )) + { + std::cerr<<"adding fragment shader FAILED"<bindAttributeLocation("colors", 1); + program->link(); + d->shader_programs[PROGRAM_SPHERES] = program; + return program; + + } + break; + default: std::cerr<<"ERROR : Program not found."<(item); - if(group) - Q_FOREACH(Scene_item* child, group->getChildren()) - removeChild(child); - item->has_group=0; + update_group_number(item,0); children.removeOne(item); } //!Moves a child up in the list. @@ -139,7 +134,8 @@ private: //!Contains a reference to all the children of this group. QList children; //!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; }; //end of class Scene_group_item diff --git a/Three/include/CGAL/Three/Scene_item.h b/Three/include/CGAL/Three/Scene_item.h index 18a3c214e57..f8e69ff0693 100644 --- a/Three/include/CGAL/Three/Scene_item.h +++ b/Three/include/CGAL/Three/Scene_item.h @@ -72,6 +72,8 @@ public: 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_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.*/ }; typedef CGAL::Three::Scene_interface::Bbox Bbox; diff --git a/Three/include/CGAL/Three/Viewer_interface.h b/Three/include/CGAL/Three/Viewer_interface.h index 4263fcb3586..eefe0a1f505 100644 --- a/Three/include/CGAL/Three/Viewer_interface.h +++ b/Three/include/CGAL/Three/Viewer_interface.h @@ -61,6 +61,8 @@ public: 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_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.*/ };