diff --git a/Polyhedron/demo/Polyhedron/Plugins/PMP/Selection_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/PMP/Selection_plugin.cpp index 7534498a7af..4bad41e70cf 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/PMP/Selection_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/PMP/Selection_plugin.cpp @@ -777,6 +777,7 @@ public Q_SLOTS: case 0: Q_EMIT set_operation_mode(-1); on_Selection_type_combo_box_changed(ui_widget.Selection_type_combo_box->currentIndex()); + selection_item->polyhedron_item()->switchToGouraudPlusEdge(false); break; //Edition mode case 1: @@ -812,7 +813,13 @@ public Q_SLOTS: { Scene_polyhedron_selection_item* selection_item = getSelectedItem(); if(selection_item) + { selection_item->on_Ctrlz_pressed(); + if(mode == 11) + selection_item->polyhedron_item()->switchToGouraudPlusEdge(true); + else + selection_item->polyhedron_item()->switchToGouraudPlusEdge(false); + } if(ui_widget.selectionOrEuler->currentIndex() == 0) { Q_EMIT set_operation_mode(-1); diff --git a/Polyhedron/demo/Polyhedron/Plugins/Surface_mesh_deformation/Scene_edit_polyhedron_item.cpp b/Polyhedron/demo/Polyhedron/Plugins/Surface_mesh_deformation/Scene_edit_polyhedron_item.cpp index b4f7a15dfec..e15b5185976 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/Surface_mesh_deformation/Scene_edit_polyhedron_item.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/Surface_mesh_deformation/Scene_edit_polyhedron_item.cpp @@ -944,7 +944,7 @@ void Scene_edit_polyhedron_item::draw(CGAL::Three::Viewer_interface* viewer) con Tc* tc = getTriangleContainer(Priv::Facets); tc->setColor(this->color()); tc->draw(viewer, true); - drawEdges(viewer); + //drawEdges(viewer); draw_ROI_and_control_vertices(viewer); drawTransparent(viewer); } diff --git a/Polyhedron/demo/Polyhedron/Plugins/Surface_mesh_deformation/Scene_edit_polyhedron_item.h b/Polyhedron/demo/Polyhedron/Plugins/Surface_mesh_deformation/Scene_edit_polyhedron_item.h index aa754d89692..49b5576fd0a 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/Surface_mesh_deformation/Scene_edit_polyhedron_item.h +++ b/Polyhedron/demo/Polyhedron/Plugins/Surface_mesh_deformation/Scene_edit_polyhedron_item.h @@ -273,7 +273,7 @@ public: // Indicate if rendering mode is supported bool supportsRenderingMode(RenderingMode m) const { - return m == Gouraud; + return m == GouraudPlusEdges; } void draw(CGAL::Three::Viewer_interface*) const; void drawEdges(CGAL::Three::Viewer_interface*) const; diff --git a/Polyhedron/demo/Polyhedron/Scene.cpp b/Polyhedron/demo/Polyhedron/Scene.cpp index 701d2f7d639..3de29f2b3b2 100644 --- a/Polyhedron/demo/Polyhedron/Scene.cpp +++ b/Polyhedron/demo/Polyhedron/Scene.cpp @@ -543,7 +543,7 @@ void Scene::renderScene(const QList &items, } if(group ||item.visible()) { - if( group || item.renderingMode() == Flat || item.renderingMode() == FlatPlusEdges || item.renderingMode() == Gouraud) + if( group || item.renderingMode() == Flat || item.renderingMode() == FlatPlusEdges || item.renderingMode() == Gouraud || item.renderingMode() == GouraudPlusEdges ) { if(with_names) { viewer->glClearDepthf(1.0); @@ -591,7 +591,8 @@ void Scene::renderWireScene(const QList &items, { if( group || (!with_names && item.renderingMode() == FlatPlusEdges ) || item.renderingMode() == Wireframe - || item.renderingMode() == PointsPlusNormals) + || item.renderingMode() == PointsPlusNormals + || item.renderingMode() == GouraudPlusEdges) { viewer->setGlPointSize(2.f); item.drawEdges(viewer); diff --git a/Polyhedron/demo/Polyhedron/Scene_group_item.cpp b/Polyhedron/demo/Polyhedron/Scene_group_item.cpp index 4ec4bd87c7a..1c10698db8f 100644 --- a/Polyhedron/demo/Polyhedron/Scene_group_item.cpp +++ b/Polyhedron/demo/Polyhedron/Scene_group_item.cpp @@ -183,7 +183,8 @@ void Scene_group_item::renderChildren(Viewer_interface *viewer, if(getChild(id)->visible() && (getChild(id)->renderingMode() == Flat || getChild(id)->renderingMode() == FlatPlusEdges || - getChild(id)->renderingMode() == Gouraud)) + getChild(id)->renderingMode() == Gouraud || + getChild(id)->renderingMode() == GouraudPlusEdges)) { getChild(id)->draw(viewer); } @@ -191,7 +192,8 @@ void Scene_group_item::renderChildren(Viewer_interface *viewer, if(getChild(id)->visible() && (getChild(id)->renderingMode() == FlatPlusEdges || getChild(id)->renderingMode() == Wireframe - || getChild(id)->renderingMode() == PointsPlusNormals)) + || getChild(id)->renderingMode() == PointsPlusNormals + || getChild(id)->renderingMode() == GouraudPlusEdges)) { getChild(id)->drawEdges(viewer); } diff --git a/Polyhedron/demo/Polyhedron/Scene_item.cpp b/Polyhedron/demo/Polyhedron/Scene_item.cpp index 7093872e5e3..17590ca5e5c 100644 --- a/Polyhedron/demo/Polyhedron/Scene_item.cpp +++ b/Polyhedron/demo/Polyhedron/Scene_item.cpp @@ -79,6 +79,8 @@ const char* slotName(RenderingMode mode) { return SLOT(setGouraudMode()); case PointsPlusNormals: return SLOT(setPointsPlusNormalsMode()); + case GouraudPlusEdges: + return SLOT(setGouraudPlusEdgesMode()); default: Q_ASSERT(false); return ""; diff --git a/Polyhedron/demo/Polyhedron/Scene_polyhedron_selection_item.cpp b/Polyhedron/demo/Polyhedron/Scene_polyhedron_selection_item.cpp index 57d91757be6..c612b965bad 100644 --- a/Polyhedron/demo/Polyhedron/Scene_polyhedron_selection_item.cpp +++ b/Polyhedron/demo/Polyhedron/Scene_polyhedron_selection_item.cpp @@ -1017,7 +1017,6 @@ bool Scene_polyhedron_selection_item::treat_selection(const std::setmanipulated_frame->setPosition(p.x()+offset.x, p.y()+offset.y, p.z()+offset.z); + if(property("is_highlighting").toBool()) + { + setProperty("need_hl_restore", true); + set_highlighting(false); + } invalidateOpenGLBuffers(); } break; @@ -1827,6 +1831,7 @@ Scene_polyhedron_selection_item::Scene_polyhedron_selection_item(Scene_face_grap Scene_polyhedron_selection_item::~Scene_polyhedron_selection_item() { + poly_item->switchToGouraudPlusEdge(false); delete d; Q_FOREACH(CGAL::QGLViewer* v, CGAL::QGLViewer::QGLViewerPool()){ CGAL::Three::Viewer_interface* viewer = dynamic_cast(v); diff --git a/Polyhedron/demo/Polyhedron/Scene_surface_mesh_item.cpp b/Polyhedron/demo/Polyhedron/Scene_surface_mesh_item.cpp index 181274cd4c6..330a51c7238 100644 --- a/Polyhedron/demo/Polyhedron/Scene_surface_mesh_item.cpp +++ b/Polyhedron/demo/Polyhedron/Scene_surface_mesh_item.cpp @@ -125,6 +125,12 @@ struct Scene_surface_mesh_item_priv{ alphaSlider = NULL; has_vcolors = false; has_fcolors = false; + supported_rendering_modes << FlatPlusEdges + << Wireframe + << Flat + << Gouraud + << GouraudPlusEdges + << Points; item->setProperty("classname", QString("surface_mesh")); } @@ -152,6 +158,12 @@ struct Scene_surface_mesh_item_priv{ alphaSlider = NULL; has_vcolors = false; has_fcolors = false; + supported_rendering_modes << FlatPlusEdges + << Wireframe + << Flat + << Gouraud + << GouraudPlusEdges + << Points; item->setProperty("classname", QString("surface_mesh")); } @@ -251,6 +263,7 @@ struct Scene_surface_mesh_item_priv{ int genus; bool self_intersect; mutable QSlider* alphaSlider; + QList supported_rendering_modes; }; const char* aabb_property_name = "Scene_surface_mesh_item aabb tree"; @@ -742,7 +755,8 @@ void Scene_surface_mesh_item::draw(CGAL::Three::Viewer_interface *viewer) const } - if(renderingMode() == Gouraud) + if(renderingMode() == Gouraud || + renderingMode() == GouraudPlusEdges) { getTriangleContainer(0)->setColor(color()); getTriangleContainer(0)->setSelected(is_selected); @@ -805,7 +819,7 @@ Scene_surface_mesh_item::selection_changed(bool p_is_selected) bool Scene_surface_mesh_item::supportsRenderingMode(RenderingMode m) const -{ return (m == FlatPlusEdges || m == Wireframe || m == Flat || m == Gouraud || m == Points); } +{ return d->supported_rendering_modes.contains(m); } CGAL::Three::Scene_item::Bbox Scene_surface_mesh_item::bbox() const { @@ -2282,36 +2296,40 @@ void Scene_surface_mesh_item::computeItemColorVectorAutomatically(bool b) this->setProperty("recompute_colors",b); } +void write_in_vbo(Vbo* vbo, cgal_gl_data* data, + std::size_t size) +{ + vbo->bind(); + vbo->vbo.write((3*size)*sizeof(cgal_gl_data), + data, + 3*sizeof(cgal_gl_data)); + vbo->release(); +} + +//only works on indexed data void Scene_surface_mesh_item::updateVertex(vertex_descriptor vh) { - typedef CGAL::Buffer_for_vao CPF; - const CGAL::qglviewer::Vec offset = static_cast( CGAL::QGLViewer::QGLViewerPool().first())->offset(); - //gouraud { std::size_t id = vh; - QOpenGLBuffer *vbo = &(getTriangleContainer(0)->getVbo(Tri::Smooth_vertices)->vbo); cgal_gl_data new_point[3]; Point_3 p = face_graph()->point(vh); for(int i=0; i<3; ++i) new_point[i]=p[i]+offset[i]; + write_in_vbo(getTriangleContainer(0)->getVbo(Tri::Smooth_vertices), + new_point, + id); - getTriangleContainer(0)->getVbo(Tri::Smooth_vertices)->bind(); - vbo->write(static_cast(3*sizeof(cgal_gl_data)*id),new_point,static_cast(3*sizeof(cgal_gl_data))); - getTriangleContainer(0)->getVbo(Tri::Smooth_vertices)->release(); + write_in_vbo( + getPointContainer(0)->getVbo(Pt::Vertices), + new_point,id); - vbo =&(getPointContainer(0)->getVbo(Pt::Vertices)->vbo); - getPointContainer(0)->getVbo(Pt::Vertices)->bind(); - vbo->write(static_cast(3*sizeof(cgal_gl_data)*id),new_point,static_cast(3*sizeof(cgal_gl_data))); - getPointContainer(0)->getVbo(Pt::Vertices)->release(); - - vbo =&(getEdgeContainer(0)->getVbo(Ed::Vertices)->vbo); - getEdgeContainer(0)->getVbo(Pt::Vertices)->bind(); - vbo->write(static_cast(3*sizeof(cgal_gl_data)*id),new_point,static_cast(3*sizeof(cgal_gl_data))); - getEdgeContainer(0)->getVbo(Pt::Vertices)->release(); + write_in_vbo( + getEdgeContainer(0)->getVbo(Ed::Vertices), + new_point,id); for(auto v_it : CGAL::vertices_around_target(vh, *face_graph())) { @@ -2319,323 +2337,34 @@ void Scene_surface_mesh_item::updateVertex(vertex_descriptor vh) for(int i=0; i<3; ++i) new_point[i]=n[i]; id = v_it; - vbo =&(getTriangleContainer(0)->getVbo(Tri::Smooth_normals)->vbo); - getTriangleContainer(0)->getVbo(Tri::Smooth_normals)->bind(); - vbo->write(static_cast(3*sizeof(cgal_gl_data)*id),new_point,static_cast(3*sizeof(cgal_gl_data))); - getTriangleContainer(0)->getVbo(Tri::Smooth_normals)->release(); - } - } - //flat - std::size_t size = 0; - if(CGAL::is_triangle_mesh(*face_graph())) - { - size = 3; - } - else if (CGAL::is_quad_mesh(*face_graph())) - { - size = 6; - } - - for(auto f : CGAL::faces_around_target(halfedge(vh, *face_graph()), *face_graph())) - { - if(size == 0) - { - for(std::size_t i = 0; i < (std::size_t)f; ++i) - { - size += CGAL::degree(f, *face_graph()); - } - } - EPICK::Vector_3 n = CGAL::Polygon_mesh_processing::compute_face_normal(f, *face_graph()); - cgal_gl_data new_normal[3]; - for(int i=0; i<3; ++i) - new_normal[i]=n[i]; - - std::size_t id = f; - std::size_t vid = 0; - - if(is_triangle(halfedge(f,*face_graph()),*face_graph())) - { - for(halfedge_descriptor hd : halfedges_around_face(halfedge(f, *face_graph()),*face_graph())) - { - Point_3 p = face_graph()->point(source(hd, *face_graph())); - cgal_gl_data new_point[3]; - for(int i=0; i<3; ++i) - { - new_point[i]=p[i]+offset[i]; - } - QOpenGLBuffer *vbo = &(getTriangleContainer(1)->getVbo(Tri::Flat_normals)->vbo); - getTriangleContainer(1)->getVbo(Tri::Flat_normals)->bind(); - vbo->write(static_cast((3*size*id+vid)*sizeof(cgal_gl_data)),new_normal, static_cast(3*sizeof(cgal_gl_data))); - getTriangleContainer(1)->getVbo(Tri::Flat_normals)->release(); - - vbo = &(getTriangleContainer(1)->getVbo(Tri::Flat_vertices)->vbo); - getTriangleContainer(1)->getVbo(Tri::Flat_vertices)->bind(); - vbo->write(static_cast((3*size*id+vid)*sizeof(cgal_gl_data)),new_point, static_cast(3*sizeof(cgal_gl_data))); - getTriangleContainer(1)->getVbo(Tri::Flat_vertices)->release(); - vid+=3; - } - } - else - { - std::vector facet_points; - for(halfedge_descriptor hd : halfedges_around_face(halfedge(f, *face_graph()),*face_graph())) - { - facet_points.push_back(face_graph()->point(target(hd, *face_graph()))); - } - bool is_convex = CPF::is_facet_convex(facet_points, n); - if(is_convex && is_quad(halfedge(f,*face_graph()),*face_graph())) - { - //1st half - halfedge_descriptor hd = halfedge(f, *face_graph()); - Point_3 p = face_graph()->point(source(hd, *face_graph())); - cgal_gl_data new_point[3]; - for(int i=0; i<3; ++i) - { - new_point[i]=p[i]+offset[i]; - } - QOpenGLBuffer *vbo = &(getTriangleContainer(1)->getVbo(Tri::Flat_normals)->vbo); - getTriangleContainer(1)->getVbo(Tri::Flat_normals)->bind(); - vbo->write(static_cast((3*size*id+vid)*sizeof(cgal_gl_data)),new_normal, static_cast(3*sizeof(cgal_gl_data))); - getTriangleContainer(1)->getVbo(Tri::Flat_normals)->release(); - vbo = &(getTriangleContainer(1)->getVbo(Tri::Flat_vertices)->vbo); - getTriangleContainer(1)->getVbo(Tri::Flat_vertices)->bind(); - vbo->write(static_cast((3*size*id+vid)*sizeof(cgal_gl_data)),new_point, static_cast(3*sizeof(cgal_gl_data))); - getTriangleContainer(1)->getVbo(Tri::Flat_vertices)->release(); - vid+=3; - - hd = next(halfedge(f, *face_graph()),*face_graph()); - p = face_graph()->point(source(hd, *face_graph())); - for(int i=0; i<3; ++i) - { - new_point[i]=p[i]+offset[i]; - } - vbo = &(getTriangleContainer(1)->getVbo(Tri::Flat_normals)->vbo); - getTriangleContainer(1)->getVbo(Tri::Flat_normals)->bind(); - vbo->write(static_cast((3*size*id+vid)*sizeof(cgal_gl_data)),new_normal, static_cast(3*sizeof(cgal_gl_data))); - getTriangleContainer(1)->getVbo(Tri::Flat_normals)->release(); - vbo = &(getTriangleContainer(1)->getVbo(Tri::Flat_vertices)->vbo); - getTriangleContainer(1)->getVbo(Tri::Flat_vertices)->bind(); - vbo->write(static_cast((3*size*id+vid)*sizeof(cgal_gl_data)),new_point, static_cast(3*sizeof(cgal_gl_data))); - getTriangleContainer(1)->getVbo(Tri::Flat_vertices)->release(); - vid+=3; - - hd = next(next(halfedge(f, *face_graph()),*face_graph()), *face_graph()); - p = face_graph()->point(source(hd, *face_graph())); - for(int i=0; i<3; ++i) - { - new_point[i]=p[i]+offset[i]; - } - vbo = &(getTriangleContainer(1)->getVbo(Tri::Flat_normals)->vbo); - getTriangleContainer(1)->getVbo(Tri::Flat_normals)->bind(); - vbo->write(static_cast((3*size*id+vid)*sizeof(cgal_gl_data)),new_normal, static_cast(3*sizeof(cgal_gl_data))); - getTriangleContainer(1)->getVbo(Tri::Flat_normals)->release(); - vbo = &(getTriangleContainer(1)->getVbo(Tri::Flat_vertices)->vbo); - getTriangleContainer(1)->getVbo(Tri::Flat_vertices)->bind(); - vbo->write(static_cast((3*size*id+vid)*sizeof(cgal_gl_data)),new_point, static_cast(3*sizeof(cgal_gl_data))); - getTriangleContainer(1)->getVbo(Tri::Flat_vertices)->release(); - vid+=3; - - //2nd half - hd = halfedge(f, *face_graph()); - p = face_graph()->point(source(hd, *face_graph())); - for(int i=0; i<3; ++i) - { - new_point[i]=p[i]+offset[i]; - } - vbo = &(getTriangleContainer(1)->getVbo(Tri::Flat_normals)->vbo); - getTriangleContainer(1)->getVbo(Tri::Flat_normals)->bind(); - vbo->write(static_cast((3*size*id+vid)*sizeof(cgal_gl_data)),new_normal, static_cast(3*sizeof(cgal_gl_data))); - getTriangleContainer(1)->getVbo(Tri::Flat_normals)->release(); - vbo = &(getTriangleContainer(1)->getVbo(Tri::Flat_vertices)->vbo); - getTriangleContainer(1)->getVbo(Tri::Flat_vertices)->bind(); - vbo->write(static_cast((3*size*id+vid)*sizeof(cgal_gl_data)),new_point, static_cast(3*sizeof(cgal_gl_data))); - getTriangleContainer(1)->getVbo(Tri::Flat_vertices)->release(); - vid+=3; - - hd = next(next(halfedge(f, *face_graph()),*face_graph()), *face_graph()); - p = face_graph()->point(source(hd, *face_graph())); - for(int i=0; i<3; ++i) - { - new_point[i]=p[i]+offset[i]; - } - vbo = &(getTriangleContainer(1)->getVbo(Tri::Flat_normals)->vbo); - getTriangleContainer(1)->getVbo(Tri::Flat_normals)->bind(); - vbo->write(static_cast((3*size*id+vid)*sizeof(cgal_gl_data)),new_normal, static_cast(3*sizeof(cgal_gl_data))); - getTriangleContainer(1)->getVbo(Tri::Flat_normals)->release(); - vbo = &(getTriangleContainer(1)->getVbo(Tri::Flat_vertices)->vbo); - getTriangleContainer(1)->getVbo(Tri::Flat_vertices)->bind(); - vbo->write(static_cast((3*size*id+vid)*sizeof(cgal_gl_data)),new_point, static_cast(3*sizeof(cgal_gl_data))); - getTriangleContainer(1)->getVbo(Tri::Flat_vertices)->release(); - vid+=3; - - hd = prev(halfedge(f, *face_graph()), *face_graph()); - p = face_graph()->point(source(hd, *face_graph())); - for(int i=0; i<3; ++i) - { - new_point[i]=p[i]+offset[i]; - } - vbo = &(getTriangleContainer(1)->getVbo(Tri::Flat_normals)->vbo); - getTriangleContainer(1)->getVbo(Tri::Flat_normals)->bind(); - vbo->write(static_cast((3*size*id+vid)*sizeof(cgal_gl_data)),new_normal, static_cast(3*sizeof(cgal_gl_data))); - getTriangleContainer(1)->getVbo(Tri::Flat_normals)->release(); - vbo = &(getTriangleContainer(1)->getVbo(Tri::Flat_vertices)->vbo); - getTriangleContainer(1)->getVbo(Tri::Flat_vertices)->bind(); - vbo->write(static_cast((3*size*id+vid)*sizeof(cgal_gl_data)),new_point, static_cast(3*sizeof(cgal_gl_data))); - getTriangleContainer(1)->getVbo(Tri::Flat_vertices)->release(); - } - else if(is_convex) - { - Point_3 p0,p1,p2; - SMesh::Halfedge_around_face_circulator he(halfedge(f, *face_graph()), *face_graph()); - SMesh::Halfedge_around_face_circulator he_end = he; - - while(next(*he, *face_graph()) != prev(*he_end, *face_graph())) - { - ++he; - vertex_descriptor v0(target(*he_end, *face_graph())), - v1(target(*he, *face_graph())), - v2(target(next(*he, *face_graph()), *face_graph())); - p0 = face_graph()->point(v0); - p1 = face_graph()->point(v1); - p2 = face_graph()->point(v2); - cgal_gl_data new_point[3]; - QOpenGLBuffer *vbo =nullptr; - for(int i=0; i<3; ++i) - { - new_point[i]=p0[i]+offset[i]; - } - vbo = &(getTriangleContainer(1)->getVbo(Tri::Flat_normals)->vbo); - getTriangleContainer(1)->getVbo(Tri::Flat_normals)->bind(); - vbo->write(static_cast((3*size*id+vid)*sizeof(cgal_gl_data)),new_normal, static_cast(3*sizeof(cgal_gl_data))); - getTriangleContainer(1)->getVbo(Tri::Flat_normals)->release(); - vbo = &(getTriangleContainer(1)->getVbo(Tri::Flat_vertices)->vbo); - getTriangleContainer(1)->getVbo(Tri::Flat_vertices)->bind(); - vbo->write(static_cast((3*size*id+vid)*sizeof(cgal_gl_data)),new_point, static_cast(3*sizeof(cgal_gl_data))); - getTriangleContainer(1)->getVbo(Tri::Flat_vertices)->release(); - - for(int i=0; i<3; ++i) - { - new_point[i]=p1[i]+offset[i]; - } - vbo = &(getTriangleContainer(1)->getVbo(Tri::Flat_normals)->vbo); - getTriangleContainer(1)->getVbo(Tri::Flat_normals)->bind(); - vbo->write(static_cast((3*size*id+vid)*sizeof(cgal_gl_data)),new_normal, static_cast(3*sizeof(cgal_gl_data))); - getTriangleContainer(1)->getVbo(Tri::Flat_normals)->release(); - vbo = &(getTriangleContainer(1)->getVbo(Tri::Flat_vertices)->vbo); - getTriangleContainer(1)->getVbo(Tri::Flat_vertices)->bind(); - vbo->write(static_cast((3*size*id+vid)*sizeof(cgal_gl_data)),new_point, static_cast(3*sizeof(cgal_gl_data))); - getTriangleContainer(1)->getVbo(Tri::Flat_vertices)->release(); - - for(int i=0; i<3; ++i) - { - new_point[i]=p2[i]+offset[i]; - } - vbo = &(getTriangleContainer(1)->getVbo(Tri::Flat_normals)->vbo); - getTriangleContainer(1)->getVbo(Tri::Flat_normals)->bind(); - vbo->write(static_cast((3*size*id+vid)*sizeof(cgal_gl_data)),new_normal, static_cast(3*sizeof(cgal_gl_data))); - getTriangleContainer(1)->getVbo(Tri::Flat_normals)->release(); - vbo = &(getTriangleContainer(1)->getVbo(Tri::Flat_vertices)->vbo); - getTriangleContainer(1)->getVbo(Tri::Flat_vertices)->bind(); - vbo->write(static_cast((3*size*id+vid)*sizeof(cgal_gl_data)),new_point, static_cast(3*sizeof(cgal_gl_data))); - getTriangleContainer(1)->getVbo(Tri::Flat_vertices)->release(); - } - } - else - { - //Computes the normal of the facet - if(n == CGAL::NULL_VECTOR) - { - boost::graph_traits::halfedge_descriptor start = prev(halfedge(f, *face_graph()), *face_graph()); - boost::graph_traits::halfedge_descriptor hd = halfedge(f, *face_graph()); - boost::graph_traits::halfedge_descriptor next_=next(hd, *face_graph()); - do - { - const Point_3& pa = face_graph()->point(target(hd, *face_graph())); - const Point_3& pb = face_graph()->point(target(next_, *face_graph())); - const Point_3& pc = face_graph()->point(target(prev(hd, *face_graph()), *face_graph())); - if (!CGAL::collinear (pa, pb, pc)) - { - n = CGAL::cross_product(pb-pa, pc -pa); - break; - } - next_ =next(next_, *face_graph()); - }while(next_ != start); - - if (n == CGAL::NULL_VECTOR) // No normal could be computed, return - { - qDebug()<<"Warning : normal is not valid. Facet not updated"; - continue; - } - } - //check if normal contains NaN values - if (n.x() != n.x() || n.y() != n.y() || n.z() != n.z()) - { - qDebug()<<"Warning : normal is not valid. Facet not displayed"; - continue; - } - - typedef FacetTriangulator::vertex_descriptor> FT; - EPICK::Vector_3 voffset(offset.x,offset.y,offset.z); - FT triangulation(f,n,face_graph(), voffset); - //iterates on the internal faces - for(FT::CDT::Finite_faces_iterator - ffit = triangulation.cdt->finite_faces_begin(), - end = triangulation.cdt->finite_faces_end(); - ffit != end; ++ffit) - { - if(ffit->info().is_external) - continue; - Point_3 p = ffit->vertex(0)->point(); - cgal_gl_data new_point[3]; - for(int i=0; i<3; ++i) - { - new_point[i]=p[i]; - } - QOpenGLBuffer *vbo = &(getTriangleContainer(1)->getVbo(Tri::Flat_normals)->vbo); - getTriangleContainer(1)->getVbo(Tri::Flat_normals)->bind(); - vbo->write(static_cast((3*size*id+vid)*sizeof(cgal_gl_data)),new_normal, 3*sizeof(cgal_gl_data)); - getTriangleContainer(1)->getVbo(Tri::Flat_normals)->release(); - vbo = &(getTriangleContainer(1)->getVbo(Tri::Flat_vertices)->vbo); - getTriangleContainer(1)->getVbo(Tri::Flat_vertices)->bind(); - vbo->write(static_cast((3*size*id+vid)*sizeof(cgal_gl_data)),new_point, 3*sizeof(cgal_gl_data)); - getTriangleContainer(1)->getVbo(Tri::Flat_vertices)->release(); - vid+=3; - - - p = ffit->vertex(1)->point(); - for(int i=0; i<3; ++i) - { - new_point[i]=p[i]; - } - vbo = &(getTriangleContainer(1)->getVbo(Tri::Flat_normals)->vbo); - getTriangleContainer(1)->getVbo(Tri::Flat_normals)->bind(); - vbo->write(static_cast((3*size*id+vid)*sizeof(cgal_gl_data)),new_normal, 3*sizeof(cgal_gl_data)); - getTriangleContainer(1)->getVbo(Tri::Flat_normals)->release(); - vbo = &(getTriangleContainer(1)->getVbo(Tri::Flat_vertices)->vbo); - getTriangleContainer(1)->getVbo(Tri::Flat_vertices)->bind(); - vbo->write(static_cast((3*size*id+vid)*sizeof(cgal_gl_data)),new_point, 3*sizeof(cgal_gl_data)); - getTriangleContainer(1)->getVbo(Tri::Flat_vertices)->release(); - vid+=3; - - p=ffit->vertex(2)->point(); - for(int i=0; i<3; ++i) - { - new_point[i]=p[i]; - } - vbo = &(getTriangleContainer(1)->getVbo(Tri::Flat_normals)->vbo); - getTriangleContainer(1)->getVbo(Tri::Flat_normals)->bind(); - vbo->write(static_cast((3*size*id+vid)*sizeof(cgal_gl_data)),new_normal, 3*sizeof(cgal_gl_data)); - getTriangleContainer(1)->getVbo(Tri::Flat_normals)->release(); - vbo = &(getTriangleContainer(1)->getVbo(Tri::Flat_vertices)->vbo); - getTriangleContainer(1)->getVbo(Tri::Flat_vertices)->bind(); - vbo->write(static_cast((3*size*id+vid)*sizeof(cgal_gl_data)),new_point, 3*sizeof(cgal_gl_data)); - getTriangleContainer(1)->getVbo(Tri::Flat_vertices)->release(); - vid+=3; - - } - } + write_in_vbo( + getTriangleContainer(0)->getVbo(Tri::Smooth_normals), + new_point,id); } } invalidate_aabb_tree(); redraw(); } + +void Scene_surface_mesh_item::switchToGouraudPlusEdge(bool b) +{ + if (!b && !d->supported_rendering_modes.contains(Flat)) + { + d->supported_rendering_modes = QList() << FlatPlusEdges + << Wireframe + << Flat + << Gouraud + << Points; + setFlatPlusEdgesMode(); + invalidateOpenGLBuffers(); + redraw(); + } + else if(b) + { + d->supported_rendering_modes = QList() << GouraudPlusEdges + << Wireframe + << Gouraud + << Points; + setGouraudPlusEdgesMode(); + } +} diff --git a/Polyhedron/demo/Polyhedron/Scene_surface_mesh_item.h b/Polyhedron/demo/Polyhedron/Scene_surface_mesh_item.h index b36c7c58afc..0306acce865 100644 --- a/Polyhedron/demo/Polyhedron/Scene_surface_mesh_item.h +++ b/Polyhedron/demo/Polyhedron/Scene_surface_mesh_item.h @@ -155,7 +155,7 @@ public: void computeElements() const Q_DECL_OVERRIDE; void initializeBuffers(CGAL::Three::Viewer_interface*)const Q_DECL_OVERRIDE; void updateVertex(vertex_descriptor vh); - + void switchToGouraudPlusEdge(bool b); //replace flatPlusEdge by gouraudPlusEdge and ban Flat. Q_SIGNALS: void item_is_about_to_be_changed(); void selection_done(); diff --git a/Polyhedron/demo/Polyhedron/Three.cpp b/Polyhedron/demo/Polyhedron/Three.cpp index 6c7641af2b2..f3e50064776 100644 --- a/Polyhedron/demo/Polyhedron/Three.cpp +++ b/Polyhedron/demo/Polyhedron/Three.cpp @@ -201,6 +201,8 @@ QString Three::modeName(RenderingMode mode) { return QObject::tr("Gouraud"); case PointsPlusNormals: return QObject::tr("pts+normals"); + case GouraudPlusEdges: + return QObject::tr("gouraud+edges"); default: Q_ASSERT(false); return QObject::tr("unknown"); diff --git a/Three/include/CGAL/Three/Scene_interface.h b/Three/include/CGAL/Three/Scene_interface.h index 71d772a3263..8ec578afe83 100644 --- a/Three/include/CGAL/Three/Scene_interface.h +++ b/Three/include/CGAL/Three/Scene_interface.h @@ -41,6 +41,7 @@ enum RenderingMode Flat, //!Renders only faces, with a lighting per face. FlatPlusEdges, //!Renders flat faces and edges. Gouraud, //!Renders only faces, with a lighting per vertex. + GouraudPlusEdges, //!Renders faces with a lighting per vertex, and edges. ShadedPoints, //!Renders only points with lighting. NumberOfRenderingMode //!Number of values in this enum. }; diff --git a/Three/include/CGAL/Three/Scene_item.h b/Three/include/CGAL/Three/Scene_item.h index 8337c9dfbc3..21f8a6c2510 100644 --- a/Three/include/CGAL/Three/Scene_item.h +++ b/Three/include/CGAL/Three/Scene_item.h @@ -377,6 +377,10 @@ public Q_SLOTS: void setPointsPlusNormalsMode(){ setRenderingMode(PointsPlusNormals); } + //!Sets the RenderingMode to GouraudPlusEdges. + void setGouraudPlusEdgesMode(){ + setRenderingMode(GouraudPlusEdges); + } //!Emits an aboutToBeDestroyed() signal. //!Override this function to delete what needs to be deleted on destruction.