From 219ea871d73bc7bbaefa819718ac519eba298b04 Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Thu, 17 Apr 2025 15:55:54 +0200 Subject: [PATCH] copy the parts of gsoc2024-basic_viewer_glfw-tgrillon that concern only the qt basic viewer --- .../CGAL/draw_arrangement_2.h | 7 +- .../include/CGAL/draw_arrangement_2.h | 6 +- .../doc/Basic_viewer/Basic_viewer.txt | 2 +- .../doc/Basic_viewer/CGAL/Graphics_scene.h | 30 + .../doc/Basic_viewer/CGAL/Qt/Basic_viewer.h | 177 +- .../examples/Basic_viewer/CMakeLists.txt | 12 +- .../Basic_viewer/draw_mesh_and_points.cpp | 2 +- Basic_viewer/include/CGAL/Basic_shaders.h | 850 ++++++++-- Basic_viewer/include/CGAL/Buffer_for_vao.h | 2 +- Basic_viewer/include/CGAL/Graphics_scene.h | 275 ++-- Basic_viewer/include/CGAL/Qt/Basic_viewer.h | 1420 ++++++++++------- .../CGAL/draw_polygon_set_2.h | 4 +- .../include/CGAL/draw_polygon_set_2.h | 6 +- Installation/lib/cmake/CGAL/CGALConfig.cmake | 7 + .../CGAL/draw_linear_cell_complex.h | 4 +- Nef_3/doc/Nef_3/CGAL/draw_nef_3.h | 4 +- Nef_3/include/CGAL/draw_nef_3.h | 6 +- .../CGAL/draw_periodic_2_triangulation_2.h | 4 +- .../CGAL/draw_periodic_2_triangulation_2.h | 6 +- Point_set_3/include/CGAL/draw_point_set_3.h | 10 +- .../CGAL/draw_multipolygon_with_holes_2.h | 6 +- Polygon/include/CGAL/draw_polygon_2.h | 10 +- .../include/CGAL/draw_polygon_with_holes_2.h | 10 +- .../doc/Polyhedron/CGAL/draw_polyhedron.h | 4 +- Polyhedron/include/CGAL/draw_polyhedron.h | 4 +- .../include/CGAL/draw_straight_skeleton_2.h | 6 +- Surface_mesh/include/CGAL/draw_surface_mesh.h | 10 +- .../CGAL/draw_face_graph_with_paths.h | 4 +- .../Surface_mesh_topology/draw_facewidth.h | 4 - .../include/CGAL/draw_face_graph_with_paths.h | 4 - .../CGAL/draw_constrained_triangulation_2.h | 4 +- .../CGAL/draw_triangulation_2.h | 4 +- .../CGAL/draw_constrained_triangulation_2.h | 4 - .../include/CGAL/draw_triangulation_2.h | 6 +- .../CGAL/draw_triangulation_3.h | 4 +- .../include/CGAL/draw_triangulation_3.h | 6 +- .../CGAL/draw_voronoi_diagram_2.h | 4 +- .../include/CGAL/draw_voronoi_diagram_2.h | 6 +- 38 files changed, 1961 insertions(+), 973 deletions(-) diff --git a/Arrangement_on_surface_2/doc/Arrangement_on_surface_2/CGAL/draw_arrangement_2.h b/Arrangement_on_surface_2/doc/Arrangement_on_surface_2/CGAL/draw_arrangement_2.h index 39d637cde4a..905588aaf88 100644 --- a/Arrangement_on_surface_2/doc/Arrangement_on_surface_2/CGAL/draw_arrangement_2.h +++ b/Arrangement_on_surface_2/doc/Arrangement_on_surface_2/CGAL/draw_arrangement_2.h @@ -29,11 +29,8 @@ namespace CGAL { * `CGAL::Arrangement_2` class template. Parameters of the drawing are taken * from the optional graphics scene options parameter. * - * A call to this function blocks the execution of the program until the drawing - * window is closed. This function requires `CGAL_Qt6`, and is only available if - * the macro `CGAL_USE_BASIC_VIEWER` is defined. Linking with the cmake target - * `CGAL::CGAL_Basic_viewer` will link with `CGAL_Qt6` and add the definition - * `CGAL_USE_BASIC_VIEWER`. +A call to this function blocks the execution of the program until the drawing window is closed. This function requires `CGAL_Qt6`, and is only available if the macro `CGAL_USE_BASIC_VIEWER`/`CGAL_USE_BASIC_VIEWER_QT` (Qt viewer) is defined. +Linking with the cmake target `CGAL::CGAL_Basic_viewer`/`CGAL::CGAL_Basic_viewer_Qt` will link with `CGAL_Qt6` and add the definition `CGAL_USE_BASIC_VIEWER`/`CGAL_USE_BASIC_VIEWER_QT`. * * \tparam GeometryTraits_2 a geometry traits type, a model of a 2D arrangement * traits concept. At this point it must be an instance of either diff --git a/Arrangement_on_surface_2/include/CGAL/draw_arrangement_2.h b/Arrangement_on_surface_2/include/CGAL/draw_arrangement_2.h index 3cea58713c9..1057e1c0f8a 100644 --- a/Arrangement_on_surface_2/include/CGAL/draw_arrangement_2.h +++ b/Arrangement_on_surface_2/include/CGAL/draw_arrangement_2.h @@ -25,7 +25,7 @@ #include #include -#include +#include #include #include #include @@ -587,8 +587,6 @@ void add_to_graphics_scene(const CGAL_ARR_TYPE& aos, add_to_graphics_scene(aos, graphics_scene, gso); } -#ifdef CGAL_USE_BASIC_VIEWER - /// Draw an arrangement on surface. template void draw(const CGAL_ARR_TYPE& aos, const GSOptions& gso, @@ -609,8 +607,6 @@ void draw(const CGAL_ARR_TYPE& aos, draw_graphics_scene(graphics_scene, title); } -#endif // CGAL_USE_BASIC_VIEWER - #undef CGAL_ARR_TYPE } // namespace CGAL diff --git a/Basic_viewer/doc/Basic_viewer/Basic_viewer.txt b/Basic_viewer/doc/Basic_viewer/Basic_viewer.txt index 970ddbd5f5f..c90ec42be47 100644 --- a/Basic_viewer/doc/Basic_viewer/Basic_viewer.txt +++ b/Basic_viewer/doc/Basic_viewer/Basic_viewer.txt @@ -131,7 +131,7 @@ Example of drawing of a point cloud and a polyhedron in a same viewer. \cgalFigureEnd -\section BV_BasicViewer The Basic Viewer Class +\section BV_BasicViewer The Qt Basic Viewer Class The class `CGAL::Qt::Basic_viewer` is a \qt widget that inherits from `QGLViewer` and mainly stores a `Graphics_scene` and allows to visualize it and interact with the scene. Since this class is a \qt widget, it can be used into more complex \qt code to create more advanced demos. diff --git a/Basic_viewer/doc/Basic_viewer/CGAL/Graphics_scene.h b/Basic_viewer/doc/Basic_viewer/CGAL/Graphics_scene.h index 8d1abd593f8..63ba3413cab 100644 --- a/Basic_viewer/doc/Basic_viewer/CGAL/Graphics_scene.h +++ b/Basic_viewer/doc/Basic_viewer/CGAL/Graphics_scene.h @@ -102,6 +102,36 @@ public: /// returns `true` if the scene is in 2D, i.e., lies on the XY or XZ or YZ plane. bool is_two_dimensional() const; + + /// set the default color of faces + void set_default_color_face(const CGAL::IO::Color& c); + + /// set the default color of points + void set_default_color_point(const CGAL::IO::Color& c); + + /// set the default color of segments + void set_default_color_segment(const CGAL::IO::Color& c); + + /// set the default color of rays + void set_default_color_ray(const CGAL::IO::Color& c); + + /// set the default color of lines + void set_default_color_line(const CGAL::IO::Color& c); + + /// returns the default color of faces + const CGAL::IO::Color &get_default_color_face() const; + + /// returns the default color of points + const CGAL::IO::Color &get_default_color_point() const; + + /// returns the default color of segments + const CGAL::IO::Color &get_default_color_segment() const; + + /// returns the default color of rays + const CGAL::IO::Color &get_default_color_ray() const; + + /// returns the default color of lines + const CGAL::IO::Color &get_default_color_line() const; }; } // namespace CGAL diff --git a/Basic_viewer/doc/Basic_viewer/CGAL/Qt/Basic_viewer.h b/Basic_viewer/doc/Basic_viewer/CGAL/Qt/Basic_viewer.h index 6ff91f29739..0604905bdae 100644 --- a/Basic_viewer/doc/Basic_viewer/CGAL/Qt/Basic_viewer.h +++ b/Basic_viewer/doc/Basic_viewer/CGAL/Qt/Basic_viewer.h @@ -5,126 +5,187 @@ namespace CGAL { /*! \ingroup PkgBasicViewerClasses -The class `Basic_viewer` is a Qt widget based on `QGLViewer` that allows to visualize 3D elements: points, segments, triangles, rays and lines. This class stores a reference to a `Graphics_scene`. Elements are added through the scene. This class requires `CGAL_Qt6`, and is only available if the macro `CGAL_USE_BASIC_VIEWER` is defined. Linking with the cmake target `CGAL::CGAL_Basic_viewer` will link with `CGAL_Qt6` and add the definition `CGAL_USE_BASIC_VIEWER`. +The class `Basic_viewer` is a Qt widget based on `QGLViewer` that allows to visualize 3D elements: points, segments, triangles, rays and lines. This class stores a reference to a `Graphics_scene`. Elements are added through the scene. This class requires `CGAL_Qt6`, and is only available if the macro `CGAL_USE_BASIC_VIEWER_QT` is defined. Linking with the cmake target `CGAL::CGAL_Basic_viewer` or `CGAL::CGAL_Basic_viewer_Qt` will link with `CGAL_Qt6` and add the definition `CGAL_USE_BASIC_VIEWER` & `CGAL_USE_BASIC_VIEWER_QT`. CGAL::QGLViewer is our internal fork of QGLViewer class which is A versatile 3D OpenGL viewer based on QOpenGLWidget. */ class Basic_viewer : public CGAL::QGLViewer { public: + /// \name Constructors + /// @{ + /// Constructor given a pointer on a `QWidget` (can be a `nullptr`) and a `Graphics_scene`. /// `title` will be the title of the window. Basic_viewer(QWidget* parent, const Graphics_scene& scene, const char* title=""); - /// enables or disables the drawing of vertices. + /// @} + + /// \name Setters + /// @{ + + /// \brief Set size of vertices. + /// \param s The size of vertices. + void size_vertices(float s); + + /// \brief Set size of edges. + /// \param s The size of edges. + void size_edges(float s); + + /// \brief Set size of rays. + /// \param s The size of rays. + void size_rays(float s); + + /// \brief Set size of lines. + /// \param s The size of lines. + void size_lines(float s); + + /// \brief Enables or disables the drawing of vertices. + /// \param b Set to `true` to enable, `false` to disable. void draw_vertices(bool b); - /// enables or disables the drawing of edges. + /// \brief Enables or disables the drawing of edges. + /// \param b Set to `true` to enable, `false` to disable. void draw_edges(bool b); - /// enables or disables the drawing of rays. + /// \brief Enables or disables the drawing of rays. + /// \param b Set to `true` to enable, `false` to disable. void draw_rays(bool b); - /// enables or disables the drawing of lines. + /// \brief Enables or disables the drawing of lines. + /// \param b Set to `true` to enable, `false` to disable. void draw_lines(bool b); - /// enables or disables the drawing of faces. + /// \brief enables or disables the drawing of faces. + /// \param b Set to `true` to enable, `false` to disable. void draw_faces(bool b); - /// enables or disables the use of only one color (if `b` is `true`) or the use of multiple colors (if `b` is `false`). - void use_mono_color(bool b); - /// enables or disables the drawing of texts. + /// \brief enables or disables the drawing of texts. + /// \param b Set to `true` to enable, `false` to disable. void draw_text(bool b); - /// sets the color used for vertices in mono color mode. - void vertices_mono_color(const CGAL::IO::Color& c); + /// \brief Enables or disables the drawing of mesh triangles. + /// \param b Set to `true` to enable, `false` to disable. + void draw_mesh_triangles(bool b); - /// sets the color used for edges in mono color mode. - void edges_mono_color(const CGAL::IO::Color& c); + /// \brief Enables or disables the use of only one color or the use of multiple colors. + /// \param b Set to `true` to use only one color, `false` to use multiple colors. + void use_default_color(bool b); - /// sets the color used for rays in mono color mode. - void rays_mono_color(const CGAL::IO::Color& c); + /// \brief Enables or disables the use of a single color for all normals. + /// \param b Set to `true` to enable, `false` to disable. + void use_default_color_normals(bool b); - /// sets the color used for lines in mono color mode. - void lines_mono_color(const CGAL::IO::Color& c); + /// \brief enables or disables the use of flat shading or the use of smooth shading. + /// \param b Set to `true` for flat shading, `false` for smooth shading. + void flat_shading(bool b); - /// sets the color used for faces in mono color mode. - void faces_mono_color(const CGAL::IO::Color& c); + /// \brief Enables or disables the reversal of normals. + /// \param b Set to `true` to reverse normals, `false` to keep normals as is. + void reverse_normal(bool b); - /// toggles the drawing of vertices. + /// \brief Sets the default color of the normals. + /// \param c The default color of the normals. + void default_color_normals(const CGAL::IO::Color& c); + + /// \brief Sets the height factor value of the normals. + /// \param h The height factor value of the normals. + void normal_height_factor(float h); + + /// \brief Toggles the drawing of vertices. void toggle_draw_vertices(); - /// toggles the drawing of edges. + /// \brief Toggles the drawing of edges. void toggle_draw_edges(); - /// toggles the drawing of rays. + /// \brief Toggles the drawing of rays. void toggle_draw_rays(); - /// toggles the drawing of lines. + /// \brief Toggles the drawing of lines. void toggle_draw_lines(); - /// toggles the drawing of faces. + /// \brief Toggles the drawing of faces. void toggle_draw_faces(); - /// toggles the use of mono color mode. - void toggle_use_mono_color(); + /// \brief Toggles the use of mono color mode. + void toggle_use_default_color(); - /// toggles the drawing of text. + /// \brief Toggles the use of the default color mode for normals. + void toggle_use_default_color_normal(); + + /// \brief Toggles the use of flat shading. + void toggle_flat_shading(); + + /// \brief Toggles the drawing of text. void toggle_draw_text(); - /// returns `true` if vertices are drawn. + /// \brief Reverses all normals of vertices and faces. + void reverse_all_normals(); + + /// @} + + /// \name Getters + /// @{ + + /// \brief Checks if vertices are drawn. + /// \return `true` if vertices are drawn, `false` otherwise. bool draw_vertices() const; - /// returns `true` if edges are drawn. + /// \brief Checks if edges are drawn. + /// \return `true` if edges are drawn, `false` otherwise. bool draw_edges() const; - /// returns `true` if rays are drawn. + /// \brief Checks if rays are drawn. + /// \return `true` if rays are drawn, `false` otherwise. bool draw_rays() const; - /// returns `true` if lines are drawn. + /// \brief Checks if lines are drawn. + /// \return `true` if lines are drawn, `false` otherwise. bool draw_lines() const; - /// returns `true` if faces are drawn. + /// \brief Checks if faces are drawn. + /// \return `true` if faces are drawn, `false` otherwise. bool draw_faces() const; - /// returns `true` if mono color mode is used. - bool use_mono_color() const; - - /// returns `true` if normals are reversed. - bool reverse_normal() const; - - /// returns `true` if text are drawn. + /// \brief Checks if text is drawn. + /// \return `true` if text is drawn, `false` otherwise. bool draw_text() const; - /// returns the mono color used for vertices. - const CGAL::IO::Color& vertices_mono_color() const; + /// \brief Checks if the default color mode is used. + /// \return `true` if mono color mode is used, `false` otherwise. + bool use_default_color() const; - /// returns the mono color used for edges. - const CGAL::IO::Color& edges_mono_color() const; + /// \brief Checks if the default color mode for normals is used. + /// \return `true` if default color mode for normals is used, `false` otherwise. + bool use_default_color_normal() const; - /// returns the mono color used for rays. - const CGAL::IO::Color& rays_mono_color() const; + /// \brief Checks if normals are reversed. + /// \return `true` if normals are reversed, `false` otherwise. + bool reverse_normal() const; - /// returns the mono color used for lines. - const CGAL::IO::Color& lines_mono_color() const; - - /// returns the mono color used for faces. - const CGAL::IO::Color& faces_mono_color() const; - - /// returns `true` if the clipping plane is enabled. + /// \brief Checks if the clipping plane is enabled. + /// \return `true` if the clipping plane is enabled, `false` otherwise. bool clipping_plane_enabled() const; - /// returns the clipping plane when it is enabled. + /// \brief Checks if m_no_2D_mode is false and the graphics scene is two-dimensional. + /// \return `true` if m_no_2D_mode is false and the scene is 2D, `false` otherwise. + bool is_two_dimensional() const; + + /// \brief Gets the clipping plane when enabled. + /// \return The clipping plane as a `CGAL::Exact_predicates_inexact_constructions_kernel::Plane_3` object. CGAL::Exact_predicates_inexact_constructions_kernel::Plane_3 clipping_plane() const; - /// returns the graphics scene of the viewer. + /// \brief Gets the graphics scene of the viewer. + /// \return A reference to the `Graphics_scene` object. const Graphics_scene& graphics_scene() const; - /// reverses all normals of vertices and faces. - void reverse_all_normals(); + /// @} + + /// \name Draw + /// @{ /// draws the viewer without recomputing all internal buffers. virtual void draw(); @@ -132,6 +193,8 @@ public: /// redraws the viewer, i.e., recompute all internal buffers and update the window. virtual void redraw(); + /// @} + /// Function called when a key is pressed. Users can define their own function in order /// to add specific behavior. std::function on_key_pressed; @@ -144,7 +207,7 @@ public: The class `QApplication_and_basic_viewer` regroups a `Basic_viewer` and Qt `QApplication`. The `QApplication` is created in the constructor, but started by the `run()` method. This allows for example users to modify the `on_key_pressed` method of the `Basic_viewer` to define their own behavior. -This class requires `CGAL_Qt6`, and is only available if the macro `CGAL_USE_BASIC_VIEWER` is defined. Linking with the cmake target `CGAL::CGAL_Basic_viewer` will link with `CGAL_Qt6` and add the definition `CGAL_USE_BASIC_VIEWER`. +This class requires `CGAL_Qt6`, and is only available if the macro `CGAL_USE_BASIC_VIEWER` or `CGAL_USE_BASIC_VIEWER_QT` is defined. Linking with the cmake target `CGAL::CGAL_Basic_viewer` or `CGAL::CGAL_Basic_viewer_Qt` will link with `CGAL_Qt6` and add the definition `CGAL_USE_BASIC_VIEWER` & `CGAL_USE_BASIC_VIEWER_QT`. */ class QApplication_and_basic_viewer diff --git a/Basic_viewer/examples/Basic_viewer/CMakeLists.txt b/Basic_viewer/examples/Basic_viewer/CMakeLists.txt index 4106c9defb4..fb0a3d15849 100644 --- a/Basic_viewer/examples/Basic_viewer/CMakeLists.txt +++ b/Basic_viewer/examples/Basic_viewer/CMakeLists.txt @@ -23,12 +23,12 @@ create_single_source_cgal_program("draw_surface_mesh_vcolor.cpp") if(CGAL_Qt6_FOUND) #link it with the required CGAL libraries - target_link_libraries(draw_lcc PRIVATE CGAL::CGAL_Basic_viewer) - target_link_libraries(draw_mesh_and_points PRIVATE CGAL::CGAL_Basic_viewer) - target_link_libraries(draw_several_windows PRIVATE CGAL::CGAL_Basic_viewer) - target_link_libraries(draw_surface_mesh_height PRIVATE CGAL::CGAL_Basic_viewer) - target_link_libraries(draw_surface_mesh_small_faces PRIVATE CGAL::CGAL_Basic_viewer) - target_link_libraries(draw_surface_mesh_vcolor PRIVATE CGAL::CGAL_Basic_viewer) + target_link_libraries(draw_lcc PRIVATE CGAL::CGAL_Basic_viewer_Qt) + target_link_libraries(draw_mesh_and_points PRIVATE CGAL::CGAL_Basic_viewer_Qt) + target_link_libraries(draw_several_windows PRIVATE CGAL::CGAL_Basic_viewer_Qt) + target_link_libraries(draw_surface_mesh_height PRIVATE CGAL::CGAL_Basic_viewer_Qt) + target_link_libraries(draw_surface_mesh_small_faces PRIVATE CGAL::CGAL_Basic_viewer_Qt) + target_link_libraries(draw_surface_mesh_vcolor PRIVATE CGAL::CGAL_Basic_viewer_Qt) else() message("CGAL_Qt6 not configured: examples that require Qt will not be compiled.") endif() diff --git a/Basic_viewer/examples/Basic_viewer/draw_mesh_and_points.cpp b/Basic_viewer/examples/Basic_viewer/draw_mesh_and_points.cpp index e104f016447..a058026d520 100644 --- a/Basic_viewer/examples/Basic_viewer/draw_mesh_and_points.cpp +++ b/Basic_viewer/examples/Basic_viewer/draw_mesh_and_points.cpp @@ -5,7 +5,7 @@ #include #include #include -#include +#include #include #include diff --git a/Basic_viewer/include/CGAL/Basic_shaders.h b/Basic_viewer/include/CGAL/Basic_shaders.h index ff7de984625..ab843a09d3d 100644 --- a/Basic_viewer/include/CGAL/Basic_shaders.h +++ b/Basic_viewer/include/CGAL/Basic_shaders.h @@ -17,131 +17,299 @@ namespace CGAL { - //------------------------------------------------------------------------------ -const char vertex_source_color[]=R"DELIM( +const char VERTEX_SOURCE_COLOR[]=R"DELIM( #version 150 -in highp vec4 vertex; -in highp vec3 normal; -in highp vec3 color; +in highp vec3 a_Pos; +in highp vec3 a_Normal; +in mediump vec3 a_Color; -uniform highp mat4 mvp_matrix; -uniform highp mat4 mv_matrix; -uniform highp float point_size; +out highp vec4 vs_fP; // view space position +out highp vec4 ls_fP; // local space position +out highp vec3 fN; +out mediump vec4 fColor; -out highp vec4 fP; -out highp vec3 fN; -out highp vec4 fColor; -out highp vec4 m_vertex; +uniform highp mat4 u_Mvp; +uniform highp mat4 u_Mv; +uniform mediump float u_PointSize; +uniform mediump vec3 u_DefaultColor; +uniform bool u_UseDefaultColor; void main(void) -{ - fP = mv_matrix * vertex; - fN = mat3(mv_matrix)* normal; - fColor = vec4(color, 1.0); - gl_PointSize = point_size; +{ + fColor = vec4(a_Color, 1.0); + if (u_UseDefaultColor) + { + fColor = vec4(u_DefaultColor, 1.0); + } - m_vertex = vertex; + vec4 pos = vec4(a_Pos, 1.0); - gl_Position = mvp_matrix * vertex; + ls_fP = pos; + vs_fP = u_Mv * pos; + + fN = mat3(u_Mv)* a_Normal; + + gl_Position = u_Mvp * pos; + gl_PointSize = u_PointSize; } )DELIM"; -const char fragment_source_color[]=R"DELIM( +const char FRAGMENT_SOURCE_COLOR[]=R"DELIM( #version 150 -in highp vec4 fP; -in highp vec3 fN; -in highp vec4 fColor; -in highp vec4 m_vertex; +in highp vec4 vs_fP; +in highp vec4 ls_fP; +in highp vec3 fN; +in mediump vec4 fColor; -uniform highp vec4 light_pos; -uniform highp vec4 light_diff; -uniform highp vec4 light_spec; -uniform highp vec4 light_amb; -uniform highp float spec_power; +out mediump vec4 out_color; -uniform highp vec4 clipPlane; -uniform highp vec4 pointPlane; -uniform highp float rendering_mode; -uniform highp float rendering_transparency; +uniform highp vec4 u_LightPos; +uniform mediump vec4 u_LightDiff; +uniform mediump vec4 u_LightSpec; +uniform mediump vec4 u_LightAmb; +uniform mediump float u_SpecPower; -out highp vec4 out_color; +uniform highp vec4 u_ClipPlane; +uniform highp vec4 u_PointPlane; +uniform mediump float u_RenderingMode; +uniform mediump float u_RenderingTransparency; void main(void) { - highp vec3 L = light_pos.xyz - fP.xyz; - highp vec3 V = -fP.xyz; + highp vec3 L = u_LightPos.xyz - vs_fP.xyz; + highp vec3 V = -vs_fP.xyz; - highp vec3 N = normalize(fN); + highp vec3 a_Normal = normalize(fN); L = normalize(L); V = normalize(V); - highp vec3 R = reflect(-L, N); - highp vec4 diffuse = vec4(max(dot(N,L), 0.0) * light_diff.rgb * fColor.rgb, 1.0); - highp vec4 ambient = vec4(light_amb.rgb * fColor.rgb, 1.0); - highp vec4 specular = pow(max(dot(R,V), 0.0), spec_power) * light_spec; + highp vec3 R = reflect(-L, a_Normal); + highp vec4 diffuse = vec4(max(dot(a_Normal,L), 0.0) * u_LightDiff.rgb * fColor.rgb, 1.0); + highp vec4 ambient = vec4(u_LightAmb.rgb * fColor.rgb, 1.0); + highp vec4 specular = pow(max(dot(R,V), 0.0), u_SpecPower) * u_LightSpec; // onPlane == 1: inside clipping plane, should be solid; // onPlane == -1: outside clipping plane, should be transparent; // onPlane == 0: on clipping plane, whatever; - float onPlane = sign(dot((m_vertex.xyz-pointPlane.xyz), clipPlane.xyz)); + float onPlane = sign(dot((ls_fP.xyz-u_PointPlane.xyz), u_ClipPlane.xyz)); // rendering_mode == -1: draw all solid; // rendering_mode == 0: draw solid only; // rendering_mode == 1: draw transparent only; - if (rendering_mode == (onPlane+1)/2) { + if (u_RenderingMode == (onPlane+1)/2) { // discard other than the corresponding half when rendering discard; } // draw corresponding part - out_color = rendering_mode < 1 ? (diffuse + ambient) : - vec4(diffuse.rgb + ambient.rgb, rendering_transparency); + out_color = u_RenderingMode < 1 ? (diffuse + ambient) : + vec4(diffuse.rgb + ambient.rgb, u_RenderingTransparency); } )DELIM"; -const char vertex_source_p_l[]=R"DELIM( +const char VERTEX_SOURCE_P_L[]=R"DELIM( #version 150 -in highp vec4 vertex; -in highp vec3 color; +in highp vec3 a_Pos; +in mediump vec3 a_Color; -uniform highp mat4 mvp_matrix; -uniform highp float point_size; +out mediump vec4 fColor; +out highp vec4 ls_fP; // local space -out highp vec4 fColor; -out highp vec4 m_vertex; +uniform highp mat4 u_Mvp; +uniform mediump float u_PointSize; +uniform bool u_IsOrthographic; +uniform mediump vec3 u_DefaultColor; +uniform bool u_UseDefaultColor; + +bool EqualZero(float value) +{ + return abs(value) < 0.00001; +} void main(void) { - gl_PointSize = point_size; - fColor = vec4(color, 1.0); - m_vertex = vertex; - gl_Position = mvp_matrix * vertex; + fColor = vec4(a_Color, 1.0); + if (u_UseDefaultColor) + { + fColor = vec4(u_DefaultColor, 1.0); + } + + vec4 pos = vec4(a_Pos, 1.0); + + ls_fP = pos; + + gl_Position = u_Mvp * pos; + + float distance = gl_Position.w; + if (u_IsOrthographic) + { + distance = u_PointSize; + } + + float effectiveDistance = EqualZero(distance) ? 0.00001 : distance; + gl_PointSize = u_PointSize / effectiveDistance * 5.0; } )DELIM"; -const char fragment_source_p_l[]=R"DELIM( +const char VERTEX_SOURCE_SHAPE[]=R"DELIM( #version 150 -in highp vec4 fColor; -in highp vec4 m_vertex; +in highp vec3 a_Pos; +in mediump vec3 a_Color; -uniform highp vec4 clipPlane; -uniform highp vec4 pointPlane; -uniform highp float rendering_mode; +out mediump vec4 gColor; +out highp vec4 ls_fP; -out highp vec4 out_color; +uniform highp mat4 u_Mvp; +uniform mediump vec3 u_DefaultColor; +uniform bool u_UseDefaultColor; + +void main(void) +{ + gColor = vec4(a_Color, 1.0); + if (u_UseDefaultColor) + { + gColor = vec4(u_DefaultColor, 1.0); + } + + gl_Position = vec4(a_Pos, 1.0); +} +)DELIM"; + +const char GEOMETRY_SOURCE_SPHERE[]=R"DELIM( +#version 150 +layout(points) in; +layout(triangle_strip, max_vertices = 72) out; // max_vertices = (resolution+1) * 2 * latResolution + +#define PI 3.14159265358979323846 + +in mediump vec4 gColor[]; + +out mediump vec4 fColor; +out highp vec4 ls_fP; + +uniform highp mat4 u_Mvp; +uniform mediump float u_Radius; + +void drawSphere(in vec4 center, in float radius, in float resolution) +{ + float latResolution = resolution*0.5; + float stepTheta = PI/latResolution; + float stepPhi = 2*PI/resolution; + for(int i=0; ineighbor(i); - if (n->info().m_nesting_level==-1) + if (n!=nullptr && n->info().m_nesting_level==-1) { if (tri.is_constrained(e)) { border.push(e); } else { queue.push(n); } diff --git a/Basic_viewer/include/CGAL/Graphics_scene.h b/Basic_viewer/include/CGAL/Graphics_scene.h index 155a471b217..10f3788e501 100644 --- a/Basic_viewer/include/CGAL/Graphics_scene.h +++ b/Basic_viewer/include/CGAL/Graphics_scene.h @@ -64,64 +64,82 @@ public: typedef Local_kernel::Vector_3 Local_vector; Graphics_scene() - : m_buffer_for_mono_points(&arrays[POS_MONO_POINTS], nullptr, - &m_bounding_box, nullptr, nullptr, nullptr), - m_buffer_for_colored_points(&arrays[POS_COLORED_POINTS], nullptr, - &m_bounding_box, &arrays[COLOR_POINTS], - nullptr, nullptr), - m_buffer_for_mono_segments(&arrays[POS_MONO_SEGMENTS], nullptr, - &m_bounding_box, nullptr, nullptr, nullptr), - m_buffer_for_colored_segments(&arrays[POS_COLORED_SEGMENTS], nullptr, - &m_bounding_box, &arrays[COLOR_SEGMENTS], - nullptr, nullptr), - m_buffer_for_mono_rays(&arrays[POS_MONO_RAYS], nullptr, &m_bounding_box, - nullptr, nullptr), - m_buffer_for_colored_rays(&arrays[POS_COLORED_RAYS], nullptr, - &m_bounding_box, &arrays[COLOR_RAYS], nullptr, - nullptr), - m_buffer_for_mono_lines(&arrays[POS_MONO_RAYS], nullptr, - &m_bounding_box, nullptr, nullptr), - m_buffer_for_colored_lines(&arrays[POS_COLORED_LINES], nullptr, - &m_bounding_box, &arrays[COLOR_LINES], - nullptr, nullptr), - m_buffer_for_mono_faces( - &arrays[POS_MONO_FACES], nullptr, &m_bounding_box, nullptr, - &arrays[FLAT_NORMAL_MONO_FACES], &arrays[SMOOTH_NORMAL_MONO_FACES]), - m_buffer_for_colored_faces(&arrays[POS_COLORED_FACES], nullptr, - &m_bounding_box, &arrays[COLOR_FACES], - &arrays[FLAT_NORMAL_COLORED_FACES], - &arrays[SMOOTH_NORMAL_COLORED_FACES]) + : m_buffer_for_points(&arrays[POS_POINTS], nullptr, + &m_bounding_box, &arrays[COLOR_POINTS]), + m_buffer_for_segments(&arrays[POS_SEGMENTS], nullptr, + &m_bounding_box, &arrays[COLOR_SEGMENTS]), + m_buffer_for_rays(&arrays[POS_RAYS], nullptr, &m_bounding_box, + &arrays[COLOR_RAYS]), + m_buffer_for_lines(&arrays[POS_RAYS], nullptr, + &m_bounding_box, &arrays[COLOR_LINES]), + m_buffer_for_faces(&arrays[POS_FACES], nullptr, &m_bounding_box, &arrays[COLOR_FACES], + &arrays[FLAT_NORMAL_FACES], &arrays[SMOOTH_NORMAL_FACES]), + m_default_color_face(60, 60, 200), + m_default_color_point(200, 60, 60), + m_default_color_segment(0, 0, 0), + m_default_color_ray(0, 0, 0), + m_default_color_line(0, 0, 0) {} - const Buffer_for_vao &get_buffer_for_mono_points() const - { return m_buffer_for_mono_points; } + inline + const CGAL::IO::Color &get_default_color_face() const + { return m_default_color_face; } - const Buffer_for_vao &get_buffer_for_colored_points() const - { return m_buffer_for_colored_points; } + inline + const CGAL::IO::Color &get_default_color_point() const + { return m_default_color_point; } - const Buffer_for_vao &get_buffer_for_mono_segments() const - { return m_buffer_for_mono_segments; } + inline + const CGAL::IO::Color &get_default_color_segment() const + { return m_default_color_segment; } - const Buffer_for_vao &get_buffer_for_colored_segments() const - { return m_buffer_for_colored_segments; } + inline + const CGAL::IO::Color &get_default_color_ray() const + { return m_default_color_ray; } - const Buffer_for_vao &get_buffer_for_mono_rays() const - { return m_buffer_for_mono_rays; } + inline + const CGAL::IO::Color &get_default_color_line() const + { return m_default_color_line; } - const Buffer_for_vao &get_buffer_for_colored_rays() const - { return m_buffer_for_colored_rays; } + inline + const Buffer_for_vao &get_buffer_for_points() const + { return m_buffer_for_points; } - const Buffer_for_vao &get_buffer_for_mono_lines() const - { return m_buffer_for_mono_lines; } + inline + void set_default_color_face(const CGAL::IO::Color& c) + { m_default_color_face = c; } - const Buffer_for_vao &get_buffer_for_colored_lines() const - { return m_buffer_for_colored_lines; } + inline + void set_default_color_point(const CGAL::IO::Color& c) + { m_default_color_point = c; } - const Buffer_for_vao &get_buffer_for_mono_faces() const - { return m_buffer_for_mono_faces; } + inline + void set_default_color_segment(const CGAL::IO::Color& c) + { m_default_color_segment = c; } - const Buffer_for_vao &get_buffer_for_colored_faces() const - { return m_buffer_for_colored_faces; } + inline + void set_default_color_ray(const CGAL::IO::Color& c) + { m_default_color_ray = c; } + + inline + void set_default_color_line(const CGAL::IO::Color& c) + { m_default_color_line = c; } + + inline + const Buffer_for_vao &get_buffer_for_segments() const + { return m_buffer_for_segments; } + + inline + const Buffer_for_vao &get_buffer_for_rays() const + { return m_buffer_for_rays; } + + inline + const Buffer_for_vao &get_buffer_for_lines() const + { return m_buffer_for_lines; } + + inline + const Buffer_for_vao &get_buffer_for_faces() const + { return m_buffer_for_faces; } const CGAL::Bbox_3 &bounding_box() const { return m_bounding_box; } @@ -159,31 +177,30 @@ public: void reverse_all_normals() const { - m_buffer_for_mono_faces.negate_normals(); - m_buffer_for_colored_faces.negate_normals(); + m_buffer_for_faces.negate_normals(); } template void add_point(const KPoint &p) - { m_buffer_for_mono_points.add_point(p); } + { m_buffer_for_points.add_point(p, m_default_color_point); } template void add_point(const KPoint &p, const CGAL::IO::Color &acolor) - { m_buffer_for_colored_points.add_point(p, acolor); } + { m_buffer_for_points.add_point(p, acolor); } template void add_segment(const KPoint &p1, const KPoint &p2) - { m_buffer_for_mono_segments.add_segment(p1, p2); } + { m_buffer_for_segments.add_segment(p1, p2, m_default_color_segment); } template void add_segment(const KPoint &p1, const KPoint &p2, const CGAL::IO::Color &acolor) - { m_buffer_for_colored_segments.add_segment(p1, p2, acolor); } + { m_buffer_for_segments.add_segment(p1, p2, acolor); } template void add_ray(const KPoint &p, const KVector &v) { double bigNumber = 1e30; - m_buffer_for_mono_rays.add_ray_segment(p, (p + (bigNumber)*v)); + m_buffer_for_rays.add_ray_segment(p, (p + (bigNumber)*v), m_default_color_ray); } template @@ -191,15 +208,15 @@ public: const CGAL::IO::Color &acolor) { double bigNumber = 1e30; - m_buffer_for_colored_rays.add_ray_segment(p, (p + (bigNumber)*v), acolor); + m_buffer_for_rays.add_ray_segment(p, (p + (bigNumber)*v), acolor); } template void add_line(const KPoint &p, const KVector &v) { double bigNumber = 1e30; - m_buffer_for_mono_lines.add_line_segment((p - (bigNumber)*v), - (p + (bigNumber)*v)); + m_buffer_for_lines.add_line_segment((p - (bigNumber)*v), + (p + (bigNumber)*v), m_default_color_line); } template @@ -207,33 +224,28 @@ public: const CGAL::IO::Color &acolor) { double bigNumber = 1e30; - m_buffer_for_colored_lines.add_line_segment((p - (bigNumber)*v), + m_buffer_for_lines.add_line_segment((p - (bigNumber)*v), (p + (bigNumber)*v), acolor); } template bool add_point_in_face(const KPoint &kp) { - if (m_buffer_for_mono_faces.is_a_face_started()) - { return m_buffer_for_mono_faces.add_point_in_face(kp); } - else if (m_buffer_for_colored_faces.is_a_face_started()) - { return m_buffer_for_colored_faces.add_point_in_face(kp); } + if (m_buffer_for_faces.is_a_face_started()) + { return m_buffer_for_faces.add_point_in_face(kp); } return false; } template bool add_point_in_face(const KPoint &kp, const KVector &p_normal) { - if (m_buffer_for_mono_faces.is_a_face_started()) - { return m_buffer_for_mono_faces.add_point_in_face(kp, p_normal); } - else if (m_buffer_for_colored_faces.is_a_face_started()) - { return m_buffer_for_colored_faces.add_point_in_face(kp, p_normal); } + if (m_buffer_for_faces.is_a_face_started()) + { return m_buffer_for_faces.add_point_in_face(kp, p_normal); } return false; } bool a_face_started() const { - return m_buffer_for_mono_faces.is_a_face_started() || - m_buffer_for_colored_faces.is_a_face_started(); + return m_buffer_for_faces.is_a_face_started(); } void face_begin() @@ -245,7 +257,7 @@ public: << std::endl; } else - { m_buffer_for_mono_faces.face_begin(); } + { m_buffer_for_faces.face_begin(m_default_color_face); } } void face_begin(const CGAL::IO::Color &acolor) @@ -257,15 +269,13 @@ public: << std::endl; } else - { m_buffer_for_colored_faces.face_begin(acolor); } + { m_buffer_for_faces.face_begin(acolor); } } void face_end() { - if (m_buffer_for_mono_faces.is_a_face_started()) - { m_buffer_for_mono_faces.face_end(); } - else if (m_buffer_for_colored_faces.is_a_face_started()) - { m_buffer_for_colored_faces.face_end(); } + if (m_buffer_for_faces.is_a_face_started()) + { m_buffer_for_faces.face_end(); } } template @@ -281,58 +291,38 @@ public: bool empty() const { - return (m_buffer_for_mono_points.is_empty() && - m_buffer_for_colored_points.is_empty() && - m_buffer_for_mono_segments.is_empty() && - m_buffer_for_colored_segments.is_empty() && - m_buffer_for_mono_rays.is_empty() && - m_buffer_for_colored_rays.is_empty() && - m_buffer_for_mono_lines.is_empty() && - m_buffer_for_colored_lines.is_empty() && - m_buffer_for_mono_faces.is_empty() && - m_buffer_for_colored_faces.is_empty()); + return (m_buffer_for_points.is_empty() && + m_buffer_for_segments.is_empty() && + m_buffer_for_rays.is_empty() && + m_buffer_for_lines.is_empty() && + m_buffer_for_faces.is_empty()); } bool has_zero_x() const { - return m_buffer_for_mono_points.has_zero_x() && - m_buffer_for_colored_points.has_zero_x() && - m_buffer_for_mono_segments.has_zero_x() && - m_buffer_for_colored_segments.has_zero_x() && - m_buffer_for_mono_faces.has_zero_x() && - m_buffer_for_colored_faces.has_zero_x() && - m_buffer_for_mono_rays.has_zero_x() && - m_buffer_for_colored_rays.has_zero_x() && - m_buffer_for_mono_lines.has_zero_x() && - m_buffer_for_colored_lines.has_zero_x(); + return m_buffer_for_points.has_zero_x() && + m_buffer_for_segments.has_zero_x() && + m_buffer_for_faces.has_zero_x() && + m_buffer_for_rays.has_zero_x() && + m_buffer_for_lines.has_zero_x(); } bool has_zero_y() const { - return m_buffer_for_mono_points.has_zero_y() && - m_buffer_for_colored_points.has_zero_y() && - m_buffer_for_mono_segments.has_zero_y() && - m_buffer_for_colored_segments.has_zero_y() && - m_buffer_for_mono_faces.has_zero_y() && - m_buffer_for_colored_faces.has_zero_y() && - m_buffer_for_mono_rays.has_zero_y() && - m_buffer_for_colored_rays.has_zero_y() && - m_buffer_for_mono_lines.has_zero_y() && - m_buffer_for_colored_lines.has_zero_y(); + return m_buffer_for_points.has_zero_y() && + m_buffer_for_segments.has_zero_y() && + m_buffer_for_faces.has_zero_y() && + m_buffer_for_rays.has_zero_y() && + m_buffer_for_lines.has_zero_y(); } bool has_zero_z() const { - return m_buffer_for_mono_points.has_zero_z() && - m_buffer_for_colored_points.has_zero_z() && - m_buffer_for_mono_segments.has_zero_z() && - m_buffer_for_colored_segments.has_zero_z() && - m_buffer_for_mono_faces.has_zero_z() && - m_buffer_for_colored_faces.has_zero_z() && - m_buffer_for_mono_rays.has_zero_z() && - m_buffer_for_colored_rays.has_zero_z() && - m_buffer_for_mono_lines.has_zero_z() && - m_buffer_for_colored_lines.has_zero_z(); + return m_buffer_for_points.has_zero_z() && + m_buffer_for_segments.has_zero_z() && + m_buffer_for_faces.has_zero_z() && + m_buffer_for_rays.has_zero_z() && + m_buffer_for_lines.has_zero_z(); } // Returns true if the data structure lies on a XY or XZ or YZ plane @@ -343,16 +333,11 @@ public: void clear() { - m_buffer_for_mono_points.clear(); - m_buffer_for_colored_points.clear(); - m_buffer_for_mono_segments.clear(); - m_buffer_for_colored_segments.clear(); - m_buffer_for_mono_rays.clear(); - m_buffer_for_colored_rays.clear(); - m_buffer_for_mono_lines.clear(); - m_buffer_for_colored_lines.clear(); - m_buffer_for_mono_faces.clear(); - m_buffer_for_colored_faces.clear(); + m_buffer_for_points.clear(); + m_buffer_for_segments.clear(); + m_buffer_for_rays.clear(); + m_buffer_for_lines.clear(); + m_buffer_for_faces.clear(); m_texts.clear(); m_bounding_box=CGAL::Bbox_3(); } @@ -385,16 +370,11 @@ public: // vectors. enum Buffers { BEGIN_POS = 0, - POS_MONO_POINTS = BEGIN_POS, - POS_COLORED_POINTS, - POS_MONO_SEGMENTS, - POS_COLORED_SEGMENTS, - POS_MONO_RAYS, - POS_COLORED_RAYS, - POS_MONO_LINES, - POS_COLORED_LINES, - POS_MONO_FACES, - POS_COLORED_FACES, + POS_POINTS = BEGIN_POS, + POS_SEGMENTS, + POS_RAYS, + POS_LINES, + POS_FACES, END_POS, BEGIN_COLOR = END_POS, COLOR_POINTS = BEGIN_COLOR, @@ -404,25 +384,24 @@ public: COLOR_FACES, END_COLOR, BEGIN_NORMAL = END_COLOR, - SMOOTH_NORMAL_MONO_FACES = BEGIN_NORMAL, - FLAT_NORMAL_MONO_FACES, - SMOOTH_NORMAL_COLORED_FACES, - FLAT_NORMAL_COLORED_FACES, + SMOOTH_NORMAL_FACES = BEGIN_NORMAL, + FLAT_NORMAL_FACES, END_NORMAL, LAST_INDEX = END_NORMAL }; protected: - Buffer_for_vao m_buffer_for_mono_points; - Buffer_for_vao m_buffer_for_colored_points; - Buffer_for_vao m_buffer_for_mono_segments; - Buffer_for_vao m_buffer_for_colored_segments; - Buffer_for_vao m_buffer_for_mono_rays; - Buffer_for_vao m_buffer_for_colored_rays; - Buffer_for_vao m_buffer_for_mono_lines; - Buffer_for_vao m_buffer_for_colored_lines; - Buffer_for_vao m_buffer_for_mono_faces; - Buffer_for_vao m_buffer_for_colored_faces; + Buffer_for_vao m_buffer_for_points; + Buffer_for_vao m_buffer_for_segments; + Buffer_for_vao m_buffer_for_rays; + Buffer_for_vao m_buffer_for_lines; + Buffer_for_vao m_buffer_for_faces; + + CGAL::IO::Color m_default_color_face; + CGAL::IO::Color m_default_color_point; + CGAL::IO::Color m_default_color_segment; + CGAL::IO::Color m_default_color_ray; + CGAL::IO::Color m_default_color_line; std::vector> m_texts; diff --git a/Basic_viewer/include/CGAL/Qt/Basic_viewer.h b/Basic_viewer/include/CGAL/Qt/Basic_viewer.h index 20ef729341d..914328fa594 100644 --- a/Basic_viewer/include/CGAL/Qt/Basic_viewer.h +++ b/Basic_viewer/include/CGAL/Qt/Basic_viewer.h @@ -11,8 +11,8 @@ // Author(s) : Guillaume Damiand // Mostafa Ashraf -#ifndef CGAL_BASIC_VIEWER_H -#define CGAL_BASIC_VIEWER_H +#ifndef CGAL_QT_BASIC_VIEWER_H +#define CGAL_QT_BASIC_VIEWER_H // TODO #include #include @@ -21,8 +21,6 @@ #include #include -#ifdef CGAL_USE_BASIC_VIEWER - #ifdef __GNUC__ #if __GNUC__ >= 9 # pragma GCC diagnostic push @@ -35,7 +33,6 @@ #include #include -#include #include #include #include @@ -78,33 +75,38 @@ public: bool draw_vertices=false, bool draw_edges=true, bool draw_faces=true, - bool use_mono_color=false, + bool use_default_color=false, bool inverse_normal=false, bool draw_rays=true, bool draw_lines=true, bool draw_text=true, bool no_2D_mode=false) : CGAL::QGLViewer(parent), - gBuffer(buf), + m_scene(buf), m_draw_vertices(draw_vertices), m_draw_edges(draw_edges), m_draw_rays(draw_rays), m_draw_lines(draw_lines), m_draw_faces(draw_faces), - m_flatShading(true), - m_use_mono_color(use_mono_color), - m_inverse_normal(inverse_normal), m_draw_text(draw_text), + m_draw_normals(false), + m_draw_cylinder_edge(false), + m_draw_sphere_vertex(false), + m_draw_mesh_triangles(false), + m_geometry_feature_enabled(true), + m_flat_shading(true), + m_use_default_color(use_default_color), + m_use_default_color_normal(false), + m_display_face_normal(false), + m_inverse_normal(inverse_normal), m_no_2D_mode(no_2D_mode), - m_size_points(7.), - m_size_edges(3.1), - m_size_rays(3.1), - m_size_lines(3.1), - m_vertices_mono_color(200, 60, 60), - m_edges_mono_color(0, 0, 0), - m_rays_mono_color(0, 0, 0), - m_lines_mono_color(0, 0, 0), - m_faces_mono_color(60, 60, 200), + m_size_vertices(1.0), + m_size_edges(1.0), + m_size_rays(1.0), + m_size_lines(1.0), + m_size_normals(0.2), + m_height_factor_normals(0.02), + m_default_color_normal(220, 60, 20), m_ambient_color(0.6f, 0.5f, 0.5f, 0.5f), m_are_buffers_initialized(false) { @@ -129,6 +131,13 @@ public: setKeyDescription(::Qt::Key_PageDown, "Increase light (all colors, use shift/alt/ctrl for one rgb component)"); setKeyDescription(::Qt::Key_PageUp, "Decrease light (all colors, use shift/alt/ctrl for one rgb component)"); setKeyDescription(::Qt::Key_O, "Toggles 2D mode only"); + setKeyDescription(::Qt::ControlModifier, ::Qt::Key_V, "Toggle vertices display as sphere"); + setKeyDescription(::Qt::ControlModifier, ::Qt::Key_E, "Toggle edges display as cylinder"); + setKeyDescription(::Qt::ControlModifier, ::Qt::Key_N, "Toggle normals display"); + setKeyDescription(::Qt::ShiftModifier, ::Qt::Key_N, "Toggle face/vertex normals for normal display"); + setKeyDescription(::Qt::ControlModifier, ::Qt::Key_M, "Toggle normals mono color"); + setKeyDescription(::Qt::ControlModifier, ::Qt::Key_T, "Toggle triangles display"); + setKeyDescription(::Qt::Key_F2, "Take a screenshot"); // Add custom mouse description setMouseBindingDescription(::Qt::Key_C, ::Qt::ControlModifier, ::Qt::LeftButton, @@ -170,81 +179,103 @@ public: Q_FOREACH(QOpenGLShader* shader, rendering_program_p_l.shaders()) delete shader; + Q_FOREACH(QOpenGLShader* shader, rendering_program_line.shaders()) + delete shader; Q_FOREACH(QOpenGLShader* shader, rendering_program_face.shaders()) delete shader; Q_FOREACH(QOpenGLShader* shader, rendering_program_clipping_plane.shaders()) delete shader; + Q_FOREACH(QOpenGLShader* shader, rendering_program_sphere.shaders()) + delete shader; + Q_FOREACH(QOpenGLShader* shader, rendering_program_cylinder.shaders()) + delete shader; + Q_FOREACH(QOpenGLShader* shader, rendering_program_normal.shaders()) + delete shader; + Q_FOREACH(QOpenGLShader* shader, rendering_program_triangle.shaders()) + delete shader; delete m_frame_plane; } - void draw_vertices(bool b) + /*****SETTERS*****/ + + inline void size_vertices(float s) + { m_size_vertices = s; } + inline void size_edges(float s) + { m_size_edges = s; } + inline void size_rays(float s) + { m_size_rays = s; } + inline void size_lines(float s) + { m_size_lines = s; } + + inline void draw_vertices(bool b) { m_draw_vertices = b; } - void draw_edges(bool b) + inline void draw_edges(bool b) { m_draw_edges = b; } - void draw_rays(bool b) + inline void draw_rays(bool b) { m_draw_rays = b; } - void draw_lines(bool b) + inline void draw_lines(bool b) { m_draw_lines = b; } - void draw_faces(bool b) + inline void draw_faces(bool b) { m_draw_faces = b; } - void use_mono_color(bool b) - { m_use_mono_color = b; } - void draw_text(bool b) + inline void draw_text(bool b) { m_draw_text = b; } + inline void draw_mesh_triangles(bool b) + { m_draw_mesh_triangles = b; } - void vertices_mono_color(const CGAL::IO::Color& c) - { m_vertices_mono_color=c; } - void edges_mono_color(const CGAL::IO::Color& c) - { m_edges_mono_color=c; } - void rays_mono_color(const CGAL::IO::Color& c) - { m_rays_mono_color=c; } - void lines_mono_color(const CGAL::IO::Color& c) - { m_lines_mono_color=c; } - void faces_mono_color(const CGAL::IO::Color& c) - { m_faces_mono_color=c; } + inline void use_default_color(bool b) + { m_use_default_color = b; } + inline void use_default_color_normal(bool b) + { m_use_default_color_normal = b; } + inline void flat_shading(bool b) + { m_flat_shading = b; } + inline void reverse_normal(bool b) + { m_inverse_normal = b; } + inline void default_color_normals(const CGAL::IO::Color& c) + { m_default_color_normal = c; } + inline void normal_height_factor(float h) + { m_height_factor_normals = h; } - void toggle_draw_vertices() + inline void toggle_draw_vertices() { m_draw_vertices = !m_draw_vertices; } - void toggle_draw_edges() + inline void toggle_draw_edges() { m_draw_edges = !m_draw_edges; } - void toggle_draw_rays() + inline void toggle_draw_rays() { m_draw_rays = !m_draw_rays; } - void toggle_draw_lines() + inline void toggle_draw_lines() { m_draw_lines = !m_draw_lines; } - void toggle_draw_faces() + inline void toggle_draw_faces() { m_draw_faces = !m_draw_faces; } - void toggle_use_mono_color() - { m_use_mono_color = !m_use_mono_color; } - void toggle_draw_text() + inline void toggle_draw_text() { m_draw_text = !m_draw_text; } + inline void toggle_use_default_color() + { m_use_default_color = !m_use_default_color; } + inline void toggle_use_normal_default_color() + { m_use_default_color_normal = !m_use_default_color_normal; } + inline void toggle_flat_shading() + { m_flat_shading = !m_flat_shading; } + inline void toggle_reverse_normal() + { m_inverse_normal = !m_inverse_normal; } - bool draw_vertices() const + /*****************/ + /*****GETTERS*****/ + inline bool draw_vertices() const { return m_draw_vertices; } - bool draw_edges() const + inline bool draw_edges() const { return m_draw_edges; } - bool draw_rays() const + inline bool draw_rays() const { return m_draw_rays; } - bool draw_lines() const + inline bool draw_lines() const { return m_draw_lines; } - bool draw_faces() const + inline bool draw_faces() const { return m_draw_faces; } - bool use_mono_color() const - { return m_use_mono_color; } - bool reverse_normal() const - { return m_inverse_normal; } - bool draw_text() const + inline bool draw_text() const { return m_draw_text; } - - const CGAL::IO::Color& vertices_mono_color() const - { return m_vertices_mono_color; } - const CGAL::IO::Color& edges_mono_color() const - { return m_edges_mono_color; } - const CGAL::IO::Color& rays_mono_color() const - { return m_rays_mono_color; } - const CGAL::IO::Color& lines_mono_color() const - { return m_lines_mono_color; } - const CGAL::IO::Color& faces_mono_color() const - { return m_faces_mono_color; } + inline bool use_default_color() const + { return m_use_default_color; } + inline bool reverse_normal() const + { return m_inverse_normal; } + inline bool flat_shading() const + { return m_flat_shading; } Local_kernel::Plane_3 clipping_plane() const { @@ -258,7 +289,9 @@ public: { return (m_use_clipping_plane!=CLIPPING_PLANE_OFF); } const Graphics_scene& graphics_scene() const - { return gBuffer; } + { return m_scene; } + + /*****************/ virtual void redraw() { @@ -269,12 +302,12 @@ public: void reverse_all_normals() { m_inverse_normal=!m_inverse_normal; - gBuffer.reverse_all_normals(); + m_scene.reverse_all_normals(); } // Returns true if the data structure lies on a plane bool is_two_dimensional() const - { return !m_no_2D_mode && gBuffer.is_two_dimensional(); } + { return !m_no_2D_mode && m_scene.is_two_dimensional(); } virtual void draw() { @@ -289,193 +322,295 @@ public: if(!m_are_buffers_initialized) { initialize_buffers(); } - QColor color; + QVector3D color; attrib_buffers(this); if(m_draw_vertices) { - rendering_program_p_l.bind(); + if (m_draw_sphere_vertex && m_geometry_feature_enabled) + { + auto renderer = [this, &color, &clipPlane, &plane_point](float rendering_mode) { + rendering_program_sphere.bind(); + if (m_use_default_color) + { + auto vertex_color = m_scene.get_default_color_point(); + color = QVector3D((double)vertex_color.red()/(double)255, + (double)vertex_color.green()/(double)255, + (double)vertex_color.blue()/(double)255); + rendering_program_sphere.setUniformValue("u_DefaultColor", color); + rendering_program_sphere.setUniformValue("u_UseDefaultColor", static_cast(1)); + } + else + { + rendering_program_sphere.setUniformValue("u_UseDefaultColor", static_cast(0)); + } + rendering_program_sphere.setUniformValue("u_Radius", static_cast(sceneRadius()*m_size_vertices*0.002)); + rendering_program_sphere.setUniformValue("u_ClipPlane", clipPlane); + rendering_program_sphere.setUniformValue("u_PointPlane", plane_point); + rendering_program_sphere.setUniformValue("u_RenderingMode", rendering_mode); - // rendering_mode == -1: draw all - // rendering_mode == 0: draw inside clipping plane - // rendering_mode == 1: draw outside clipping plane - auto renderer = [this, &color, &clipPlane, &plane_point](float rendering_mode) { - vao[VAO_MONO_POINTS].bind(); - color.setRgbF((double)m_vertices_mono_color.red()/(double)255, - (double)m_vertices_mono_color.green()/(double)255, - (double)m_vertices_mono_color.blue()/(double)255); - rendering_program_p_l.setAttributeValue("color",color); - rendering_program_p_l.setUniformValue("point_size", GLfloat(m_size_points)); - rendering_program_p_l.setUniformValue("clipPlane", clipPlane); - rendering_program_p_l.setUniformValue("pointPlane", plane_point); - rendering_program_p_l.setUniformValue("rendering_mode", rendering_mode); - glDrawArrays(GL_POINTS, 0, static_cast(gBuffer.number_of_elements(GS::POS_MONO_POINTS))); - vao[VAO_MONO_POINTS].release(); + vao[VAO_POINTS].bind(); + glDrawArrays(GL_POINTS, 0, static_cast(m_scene.number_of_elements(GS::POS_POINTS))); + }; - vao[VAO_COLORED_POINTS].bind(); - if (m_use_mono_color) + enum { + DRAW_ALL = -1, // draw all + DRAW_INSIDE_ONLY, // draw only the part inside the clipping plane + DRAW_OUTSIDE_ONLY // draw only the part outside the clipping plane + }; + + if (m_use_clipping_plane == CLIPPING_PLANE_SOLID_HALF_ONLY) { - color.setRgbF((double)m_vertices_mono_color.red()/(double)255, - (double)m_vertices_mono_color.green()/(double)255, - (double)m_vertices_mono_color.blue()/(double)255); - rendering_program_p_l.disableAttributeArray("color"); - rendering_program_p_l.setAttributeValue("color",color); + renderer(DRAW_INSIDE_ONLY); } else { - rendering_program_p_l.enableAttributeArray("color"); + renderer(DRAW_ALL); } - rendering_program_p_l.setUniformValue("point_size", GLfloat(m_size_points)); - rendering_program_p_l.setUniformValue("clipPlane", clipPlane); - rendering_program_p_l.setUniformValue("pointPlane", plane_point); - rendering_program_p_l.setUniformValue("rendering_mode", rendering_mode); - glDrawArrays(GL_POINTS, 0, static_cast(gBuffer.number_of_elements(GS::POS_COLORED_POINTS))); - vao[VAO_COLORED_POINTS].release(); - }; - enum { - DRAW_ALL = -1, // draw all - DRAW_INSIDE_ONLY, // draw only the part inside the clipping plane - DRAW_OUTSIDE_ONLY // draw only the part outside the clipping plane - }; - - if (m_use_clipping_plane == CLIPPING_PLANE_SOLID_HALF_ONLY) - { - renderer(DRAW_INSIDE_ONLY); + rendering_program_sphere.release(); } else { - renderer(DRAW_ALL); - } + auto renderer = [this, &color, &clipPlane, &plane_point](float rendering_mode) { + rendering_program_p_l.bind(); - rendering_program_p_l.release(); + if (m_use_default_color) + { + auto vertex_color = m_scene.get_default_color_point(); + color = QVector3D((double)vertex_color.red()/(double)255, + (double)vertex_color.green()/(double)255, + (double)vertex_color.blue()/(double)255); + rendering_program_p_l.setUniformValue("u_DefaultColor", color); + rendering_program_p_l.setUniformValue("u_UseDefaultColor", static_cast(1)); + } + else + { + rendering_program_p_l.setUniformValue("u_UseDefaultColor", static_cast(0)); + } + rendering_program_p_l.setUniformValue("u_PointSize", GLfloat(m_size_vertices)); + rendering_program_p_l.setUniformValue("u_IsOrthographic", GLint(is_two_dimensional())); + + rendering_program_p_l.setUniformValue("u_ClipPlane", clipPlane); + rendering_program_p_l.setUniformValue("u_PointPlane", plane_point); + rendering_program_p_l.setUniformValue("u_RenderingMode", rendering_mode); + + vao[VAO_POINTS].bind(); + glDrawArrays(GL_POINTS, 0, static_cast(m_scene.number_of_elements(GS::POS_POINTS))); + }; + + enum { + DRAW_ALL = -1, // draw all + DRAW_INSIDE_ONLY, // draw only the part inside the clipping plane + DRAW_OUTSIDE_ONLY // draw only the part outside the clipping plane + }; + + if (m_use_clipping_plane == CLIPPING_PLANE_SOLID_HALF_ONLY) + { + renderer(DRAW_INSIDE_ONLY); + } + else + { + renderer(DRAW_ALL); + } + + rendering_program_p_l.release(); + } } - if(m_draw_edges) + if(m_draw_edges && !m_draw_mesh_triangles) { - rendering_program_p_l.bind(); + if (m_draw_cylinder_edge && m_geometry_feature_enabled) + { + auto renderer = [this, &color, &clipPlane, &plane_point](float rendering_mode) { + rendering_program_cylinder.bind(); - // rendering_mode == -1: draw all - // rendering_mode == 0: draw inside clipping plane - // rendering_mode == 1: draw outside clipping plane - auto renderer = [this, &color, &clipPlane, &plane_point](float rendering_mode) { - vao[VAO_MONO_SEGMENTS].bind(); - color.setRgbF((double)m_edges_mono_color.red()/(double)255, - (double)m_edges_mono_color.green()/(double)255, - (double)m_edges_mono_color.blue()/(double)255); - rendering_program_p_l.setAttributeValue("color",color); - rendering_program_p_l.setUniformValue("clipPlane", clipPlane); - rendering_program_p_l.setUniformValue("pointPlane", plane_point); - rendering_program_p_l.setUniformValue("rendering_mode", rendering_mode); - glLineWidth(m_size_edges); - glDrawArrays(GL_LINES, 0, static_cast(gBuffer.number_of_elements(GS::POS_MONO_SEGMENTS))); - vao[VAO_MONO_SEGMENTS].release(); + if (m_use_default_color) + { + auto edge_color = m_scene.get_default_color_segment(); + color = QVector3D((double)edge_color.red()/(double)255, + (double)edge_color.green()/(double)255, + (double)edge_color.blue()/(double)255); + rendering_program_cylinder.setUniformValue("u_DefaultColor", color); + rendering_program_cylinder.setUniformValue("u_UseDefaultColor", static_cast(1)); + } + else + { + rendering_program_cylinder.setUniformValue("u_UseDefaultColor", static_cast(0)); + } + rendering_program_cylinder.setUniformValue("u_Radius", static_cast(sceneRadius()*m_size_edges*0.001)); + rendering_program_cylinder.setUniformValue("u_ClipPlane", clipPlane); + rendering_program_cylinder.setUniformValue("u_PointPlane", plane_point); + rendering_program_cylinder.setUniformValue("u_RenderingMode", rendering_mode); - vao[VAO_COLORED_SEGMENTS].bind(); - if (m_use_mono_color) + vao[VAO_SEGMENTS].bind(); + glDrawArrays(GL_LINES, 0, static_cast(m_scene.number_of_elements(GS::POS_SEGMENTS))); + }; + + enum { + DRAW_ALL = -1, // draw all + DRAW_INSIDE_ONLY, // draw only the part inside the clipping plane + DRAW_OUTSIDE_ONLY // draw only the part outside the clipping plane + }; + + if (m_use_clipping_plane == CLIPPING_PLANE_SOLID_HALF_ONLY) { - color.setRgbF((double)m_edges_mono_color.red()/(double)255, - (double)m_edges_mono_color.green()/(double)255, - (double)m_edges_mono_color.blue()/(double)255); - rendering_program_p_l.disableAttributeArray("color"); - rendering_program_p_l.setAttributeValue("color",color); + renderer(DRAW_INSIDE_ONLY); } else { - rendering_program_p_l.enableAttributeArray("color"); + renderer(DRAW_ALL); } - rendering_program_p_l.setUniformValue("clipPlane", clipPlane); - rendering_program_p_l.setUniformValue("pointPlane", plane_point); - rendering_program_p_l.setUniformValue("rendering_mode", rendering_mode); - glLineWidth(m_size_edges); - glDrawArrays(GL_LINES, 0, static_cast(gBuffer.number_of_elements(GS::POS_COLORED_SEGMENTS))); - vao[VAO_COLORED_SEGMENTS].release(); - }; - enum { - DRAW_ALL = -1, // draw all - DRAW_INSIDE_ONLY, // draw only the part inside the clipping plane - DRAW_OUTSIDE_ONLY // draw only the part outside the clipping plane - }; - - if (m_use_clipping_plane == CLIPPING_PLANE_SOLID_HALF_ONLY) - { - renderer(DRAW_INSIDE_ONLY); + rendering_program_cylinder.release(); } else { - renderer(DRAW_ALL); - } + auto renderer = [this, &color, &clipPlane, &plane_point](float rendering_mode) { - rendering_program_p_l.release(); + QVector2D viewport = { + CGAL_BASIC_VIEWER_INIT_SIZE_X, + CGAL_BASIC_VIEWER_INIT_SIZE_Y + }; + + rendering_program_line.bind(); + + if (m_use_default_color) + { + auto edge_color = m_scene.get_default_color_segment(); + color = QVector3D((double)edge_color.red()/(double)255, + (double)edge_color.green()/(double)255, + (double)edge_color.blue()/(double)255); + rendering_program_line.setUniformValue("u_DefaultColor", color); + rendering_program_line.setUniformValue("u_UseDefaultColor", static_cast(1)); + } + else + { + rendering_program_line.setUniformValue("u_UseDefaultColor", static_cast(0)); + } + rendering_program_line.setUniformValue("u_PointSize", static_cast(m_size_edges)); + rendering_program_line.setUniformValue("u_IsOrthographic", static_cast(is_two_dimensional())); + + rendering_program_line.setUniformValue("u_Viewport", viewport); + rendering_program_line.setUniformValue("u_ClipPlane", clipPlane); + rendering_program_line.setUniformValue("u_PointPlane", plane_point); + rendering_program_line.setUniformValue("u_RenderingMode", rendering_mode); + + vao[VAO_SEGMENTS].bind(); + glDrawArrays(GL_LINES, 0, static_cast(m_scene.number_of_elements(GS::POS_SEGMENTS))); + }; + + enum { + DRAW_ALL = -1, // draw all + DRAW_INSIDE_ONLY, // draw only the part inside the clipping plane + DRAW_OUTSIDE_ONLY // draw only the part outside the clipping plane + }; + + if (m_use_clipping_plane == CLIPPING_PLANE_SOLID_HALF_ONLY) + { + renderer(DRAW_INSIDE_ONLY); + } + else + { + renderer(DRAW_ALL); + } + + rendering_program_line.release(); + } } if(m_draw_rays) { + auto renderer = [this, &color, &clipPlane, &plane_point](float rendering_mode) { rendering_program_p_l.bind(); - vao[VAO_MONO_RAYS].bind(); - color.setRgbF((double)m_rays_mono_color.red()/(double)255, - (double)m_rays_mono_color.green()/(double)255, - (double)m_rays_mono_color.blue()/(double)255); - rendering_program_p_l.setAttributeValue("color",color); - glLineWidth(m_size_rays); - glDrawArrays(GL_LINES, 0, static_cast(gBuffer.number_of_elements(GS::POS_MONO_RAYS))); - vao[VAO_MONO_RAYS].release(); - - vao[VAO_COLORED_RAYS].bind(); - if (m_use_mono_color) + if (m_use_default_color) { - color.setRgbF((double)m_rays_mono_color.red()/(double)255, - (double)m_rays_mono_color.green()/(double)255, - (double)m_rays_mono_color.blue()/(double)255); - rendering_program_p_l.disableAttributeArray("color"); - rendering_program_p_l.setAttributeValue("color",color); + auto ray_color = m_scene.get_default_color_ray(); + color = QVector3D((double)ray_color.red()/(double)255, + (double)ray_color.green()/(double)255, + (double)ray_color.blue()/(double)255); + rendering_program_p_l.setUniformValue("u_DefaultColor", color); + rendering_program_p_l.setUniformValue("u_UseDefaultColor", static_cast(1)); } else { - rendering_program_p_l.enableAttributeArray("color"); + rendering_program_p_l.setUniformValue("u_UseDefaultColor", static_cast(0)); } - glLineWidth(m_size_rays); - glDrawArrays(GL_LINES, 0, static_cast(gBuffer.number_of_elements(GS::POS_COLORED_RAYS))); - vao[VAO_COLORED_RAYS].release(); + rendering_program_p_l.setUniformValue("u_PointSize", GLfloat(m_size_rays)); + rendering_program_p_l.setUniformValue("u_IsOrthographic", GLint(is_two_dimensional())); - rendering_program_p_l.release(); + rendering_program_p_l.setUniformValue("u_ClipPlane", clipPlane); + rendering_program_p_l.setUniformValue("u_PointPlane", plane_point); + rendering_program_p_l.setUniformValue("u_RenderingMode", rendering_mode); + + vao[VAO_RAYS].bind(); + glDrawArrays(GL_LINES, 0, static_cast(m_scene.number_of_elements(GS::POS_RAYS))); + }; + + enum { + DRAW_ALL = -1, // draw all + DRAW_INSIDE_ONLY, // draw only the part inside the clipping plane + DRAW_OUTSIDE_ONLY // draw only the part outside the clipping plane + }; + + if (m_use_clipping_plane == CLIPPING_PLANE_SOLID_HALF_ONLY) + { + renderer(DRAW_INSIDE_ONLY); + } + else + { + renderer(DRAW_ALL); + } + + rendering_program_p_l.release(); } if(m_draw_lines) { + auto renderer = [this, &color, &clipPlane, &plane_point](float rendering_mode) { rendering_program_p_l.bind(); - vao[VAO_MONO_LINES].bind(); - color.setRgbF((double)m_lines_mono_color.red()/(double)255, - (double)m_lines_mono_color.green()/(double)255, - (double)m_lines_mono_color.blue()/(double)255); - rendering_program_p_l.setAttributeValue("color",color); - glLineWidth(m_size_lines); - glDrawArrays(GL_LINES, 0, static_cast(gBuffer.number_of_elements(GS::POS_MONO_LINES))); - vao[VAO_MONO_LINES].release(); - - rendering_program_p_l.release(); - - vao[VAO_COLORED_LINES].bind(); - if (m_use_mono_color) + if (m_use_default_color) { - color.setRgbF((double)m_lines_mono_color.red()/(double)255, - (double)m_lines_mono_color.green()/(double)255, - (double)m_lines_mono_color.blue()/(double)255); - rendering_program_p_l.disableAttributeArray("color"); - rendering_program_p_l.setAttributeValue("color",color); + auto line_color = m_scene.get_default_color_line(); + color = QVector3D((double)line_color.red()/(double)255, + (double)line_color.green()/(double)255, + (double)line_color.blue()/(double)255); + rendering_program_p_l.setUniformValue("u_DefaultColor", color); + rendering_program_p_l.setUniformValue("u_UseDefaultColor", static_cast(1)); } else { - rendering_program_p_l.enableAttributeArray("color"); + rendering_program_p_l.setUniformValue("u_UseDefaultColor", static_cast(0)); } - glLineWidth(m_size_lines); - glDrawArrays(GL_LINES, 0, static_cast(gBuffer.number_of_elements(GS::POS_COLORED_LINES))); - vao[VAO_COLORED_LINES].release(); + rendering_program_p_l.setUniformValue("u_PointSize", GLfloat(m_size_lines)); + rendering_program_p_l.setUniformValue("u_IsOrthographic", GLint(is_two_dimensional())); - rendering_program_p_l.release(); + rendering_program_p_l.setUniformValue("u_ClipPlane", clipPlane); + rendering_program_p_l.setUniformValue("u_PointPlane", plane_point); + rendering_program_p_l.setUniformValue("u_RenderingMode", rendering_mode); + + vao[VAO_LINES].bind(); + glDrawArrays(GL_LINES, 0, static_cast(m_scene.number_of_elements(GS::POS_LINES))); + }; + + enum { + DRAW_ALL = -1, // draw all + DRAW_INSIDE_ONLY, // draw only the part inside the clipping plane + DRAW_OUTSIDE_ONLY // draw only the part outside the clipping plane + }; + + if (m_use_clipping_plane == CLIPPING_PLANE_SOLID_HALF_ONLY) + { + renderer(DRAW_INSIDE_ONLY); + } + else + { + renderer(DRAW_ALL); + } + + rendering_program_p_l.release(); } // Fix Z-fighting by drawing faces at a depth @@ -489,45 +624,39 @@ public: if (m_draw_faces) { - rendering_program_face.bind(); // reference: https://stackoverflow.com/questions/37780345/opengl-how-to-create-order-independent-transparency // rendering_mode == -1: draw all as solid; // rendering_mode == 0: draw solid only; // rendering_mode == 1: draw transparent only; - auto renderer = [this, &color, &clipPlane, &plane_point](float rendering_mode) { + auto renderer = [this, &color, &clipPlane, &plane_point](float rendering_mode) + { + glEnable(GL_POLYGON_OFFSET_FILL); + glPolygonOffset(2.0, 2.0); + glDepthFunc(GL_LESS); - vao[VAO_MONO_FACES].bind(); - color.setRgbF((double)m_faces_mono_color.red()/(double)255, - (double)m_faces_mono_color.green()/(double)255, - (double)m_faces_mono_color.blue()/(double)255); - rendering_program_face.setAttributeValue("color",color); - rendering_program_face.setUniformValue("rendering_mode", rendering_mode); - rendering_program_face.setUniformValue("rendering_transparency", clipping_plane_rendering_transparency); - rendering_program_face.setUniformValue("clipPlane", clipPlane); - rendering_program_face.setUniformValue("pointPlane", plane_point); - glDrawArrays(GL_TRIANGLES, 0, static_cast(gBuffer.number_of_elements(GS::POS_MONO_FACES))); - vao[VAO_MONO_FACES].release(); - - vao[VAO_COLORED_FACES].bind(); - if (m_use_mono_color) + rendering_program_face.bind(); + if (m_use_default_color) { - color.setRgbF((double)m_faces_mono_color.red()/(double)255, - (double)m_faces_mono_color.green()/(double)255, - (double)m_faces_mono_color.blue()/(double)255); - rendering_program_face.disableAttributeArray("color"); - rendering_program_face.setAttributeValue("color",color); + auto face_color = m_scene.get_default_color_face(); + color = QVector3D((double)face_color.red()/(double)255, + (double)face_color.green()/(double)255, + (double)face_color.blue()/(double)255); + rendering_program_face.setUniformValue("u_DefaultColor", color); + rendering_program_face.setUniformValue("u_UseDefaultColor", static_cast(1)); } else { - rendering_program_face.enableAttributeArray("color"); + rendering_program_face.setUniformValue("u_UseDefaultColor", static_cast(0)); } - rendering_program_face.setUniformValue("rendering_mode", rendering_mode); - rendering_program_face.setUniformValue("rendering_transparency", clipping_plane_rendering_transparency); - rendering_program_face.setUniformValue("clipPlane", clipPlane); - rendering_program_face.setUniformValue("pointPlane", plane_point); - glDrawArrays(GL_TRIANGLES, 0, static_cast(gBuffer.number_of_elements(GS::POS_COLORED_FACES))); - vao[VAO_COLORED_FACES].release(); + rendering_program_face.setUniformValue("u_RenderingMode", rendering_mode); + rendering_program_face.setUniformValue("u_RenderingTransparency", clipping_plane_rendering_transparency); + rendering_program_face.setUniformValue("u_ClipPlane", clipPlane); + rendering_program_face.setUniformValue("u_PointPlane", plane_point); + + vao[VAO_FACES].bind(); + glDrawArrays(GL_TRIANGLES, 0, static_cast(m_scene.number_of_elements(GS::POS_FACES))); + glDisable(GL_POLYGON_OFFSET_FILL); }; auto renderer_clipping_plane = [this](bool clipping_plane_rendering) { @@ -596,12 +725,98 @@ public: rendering_program_face.release(); } + if (m_draw_normals) + { + auto renderer = [this, &color, &clipPlane, &plane_point](float rendering_mode) { + rendering_program_normal.bind(); + if (m_use_default_color_normal) + { + color = QVector3D((double)m_default_color_normal.red()/(double)255, + (double)m_default_color_normal.green()/(double)255, + (double)m_default_color_normal.blue()/(double)255); + rendering_program_normal.setUniformValue("u_DefaultColor", color); + rendering_program_normal.setUniformValue("u_UseDefaultColor", static_cast(1)); + } + else + { + rendering_program_normal.setUniformValue("u_UseDefaultColor", static_cast(0)); + } + rendering_program_normal.setUniformValue("u_Factor", static_cast(m_height_factor_normals)); + rendering_program_normal.setUniformValue("u_SceneRadius", static_cast(sceneRadius())); + if (m_display_face_normal) + { + rendering_program_normal.setUniformValue("u_DisplayFaceNormal", static_cast(1)); + } + else + { + rendering_program_normal.setUniformValue("u_DisplayFaceNormal", static_cast(0)); + } + + rendering_program_normal.setUniformValue("u_ClipPlane", clipPlane); + rendering_program_normal.setUniformValue("u_PointPlane", plane_point); + rendering_program_normal.setUniformValue("u_RenderingMode", rendering_mode); + + vao[VAO_FACES].bind(); + glLineWidth(m_size_normals); + glDrawArrays(GL_TRIANGLES, 0, static_cast(m_scene.number_of_elements(GS::POS_FACES))); + }; + + enum { + DRAW_ALL = -1, // draw all + DRAW_INSIDE_ONLY, // draw only the part inside the clipping plane + DRAW_OUTSIDE_ONLY // draw only the part outside the clipping plane + }; + + if (m_use_clipping_plane == CLIPPING_PLANE_SOLID_HALF_ONLY) + { + renderer(DRAW_INSIDE_ONLY); + } + else + { + renderer(DRAW_ALL); + } + + rendering_program_normal.release(); + } + + if (m_draw_mesh_triangles) + { + + auto renderer = [this, &color, &clipPlane, &plane_point](float rendering_mode) + { + rendering_program_triangle.bind(); + rendering_program_triangle.setUniformValue("u_RenderingMode", rendering_mode); + rendering_program_triangle.setUniformValue("u_ClipPlane", clipPlane); + rendering_program_triangle.setUniformValue("u_PointPlane", plane_point); + + vao[VAO_FACES].bind(); + glDrawArrays(GL_TRIANGLES, 0, static_cast(m_scene.number_of_elements(GS::POS_FACES))); + }; + + enum { + DRAW_ALL = -1, // draw all + DRAW_INSIDE_ONLY, // draw only the part inside the clipping plane + DRAW_OUTSIDE_ONLY // draw only the part outside the clipping plane + }; + + if (m_use_clipping_plane == CLIPPING_PLANE_SOLID_HALF_ONLY) + { + renderer(DRAW_INSIDE_ONLY); + } + else + { + renderer(DRAW_ALL); + } + + rendering_program_triangle.release(); + } + if (m_draw_text) { glDisable(GL_LIGHTING); - for (std::size_t i=0; iprojectedCoordinatesOf (CGAL::qglviewer::Vec(std::get<0>(m_texts_vec[i]).x(), std::get<0>(m_texts_vec[i]).y(), @@ -626,7 +841,12 @@ protected: { rendering_program_face.removeAllShaders(); rendering_program_p_l.removeAllShaders(); + rendering_program_line.removeAllShaders(); rendering_program_clipping_plane.removeAllShaders(); + rendering_program_sphere.removeAllShaders(); + rendering_program_cylinder.removeAllShaders(); + rendering_program_normal.removeAllShaders(); + rendering_program_triangle.removeAllShaders(); // Create the buffers for (unsigned int i=0; icompileSourceCode(source_)) { std::cerr<<"Compiling vertex source FAILED"<compileSourceCode(source_)) - { std::cerr<<"Compiling fragmentsource FAILED"<compileSourceCode(source_)) { std::cerr<<"Compiling vertex source FAILED"<compileSourceCode(source_)) @@ -694,13 +918,13 @@ protected: if (isOpenGL_4_3()) { // clipping plane shader - source_ = vertex_source_clipping_plane; + source_ = VERTEX_SOURCE_CLIPPING_PLANE; QOpenGLShader *vertex_shader_clipping_plane = new QOpenGLShader(QOpenGLShader::Vertex); if (!vertex_shader_clipping_plane->compileSourceCode(source_)) { std::cerr << "Compiling vertex source for clipping plane FAILED" << std::endl; } - source_ = fragment_source_clipping_plane; + source_ = FRAGMENT_SOURCE_CLIPPING_PLANE; QOpenGLShader *fragment_shader_clipping_plane = new QOpenGLShader(QOpenGLShader::Fragment); if (!fragment_shader_clipping_plane->compileSourceCode(source_)) @@ -716,7 +940,7 @@ protected: } // source_ = isOpenGL_4_3() - // ? vertex_source_clipping_plane + // ? VERTEX_SOURCE_CLIPPING_PLANE // : vertex_source_clipping_plane_comp; // QOpenGLShader *vertex_shader_clipping_plane = new QOpenGLShader(QOpenGLShader::Vertex); @@ -724,7 +948,7 @@ protected: // { std::cerr << "Compiling vertex source for clipping plane FAILED" << std::endl; } // source_ = isOpenGL_4_3() - // ? fragment_source_clipping_plane + // ? FRAGMENT_SOURCE_CLIPPING_PLANE // : fragment_source_clipping_plane_comp; // QOpenGLShader *fragment_shader_clipping_plane = new QOpenGLShader(QOpenGLShader::Fragment); @@ -737,6 +961,167 @@ protected: // { std::cerr << "Adding fragment shader for clipping plane FAILED" << std::endl; } // if (!rendering_program_clipping_plane.link()) // { std::cerr << "Linking Program for clipping plane FAILED" << std::endl; } + + // Sphere shader + if (isOpenGL_4_3()) + { + source_ = VERTEX_SOURCE_SHAPE; + + QOpenGLShader *vertex_shader_sphere = new QOpenGLShader(QOpenGLShader::Vertex); + if (!vertex_shader_sphere->compileSourceCode(source_)) + { std::cerr << "Compiling vertex source for sphere FAILED" << std::endl; } + + source_ = GEOMETRY_SOURCE_SPHERE; + + QOpenGLShader *geometry_shader_sphere = new QOpenGLShader(QOpenGLShader::Geometry); + if (!geometry_shader_sphere->compileSourceCode(source_)) + { std::cerr << "Compiling geometry source for sphere FAILED" << std::endl; } + + source_ = FRAGMENT_SOURCE_P_L; + + QOpenGLShader *fragment_shader_sphere = new QOpenGLShader(QOpenGLShader::Fragment); + if (!fragment_shader_sphere->compileSourceCode(source_)) + { std::cerr << "Compiling fragment source for sphere FAILED" << std::endl; } + + + if (!rendering_program_sphere.addShader(vertex_shader_sphere)) + { std::cerr << "Adding vertex shader for sphere FAILED" << std::endl;} + if (!rendering_program_sphere.addShader(geometry_shader_sphere)) + { std::cerr << "Adding geometry shader for sphere FAILED" << std::endl;} + if (!rendering_program_sphere.addShader(fragment_shader_sphere)) + { std::cerr << "Adding fragment shader for clipping plane FAILED" << std::endl; } + if (!rendering_program_sphere.link()) + { std::cerr << "Linking Program for sphere FAILED" << std::endl; } + } + + // Cylinder shader + if (isOpenGL_4_3()) + { + // clipping plane shader + source_ = VERTEX_SOURCE_SHAPE; + + QOpenGLShader *vertex_shader_cylinder = new QOpenGLShader(QOpenGLShader::Vertex); + if (!vertex_shader_cylinder->compileSourceCode(source_)) + { std::cerr << "Compiling vertex source for cylinder FAILED" << std::endl; } + + source_ = GEOMETRY_SOURCE_CYLINDER; + + QOpenGLShader *geometry_shader_cylinder = new QOpenGLShader(QOpenGLShader::Geometry); + if (!geometry_shader_cylinder->compileSourceCode(source_)) + { std::cerr << "Compiling geometry source for cylinder FAILED" << std::endl; } + + source_ = FRAGMENT_SOURCE_P_L; + + QOpenGLShader *fragment_shader_cylinder = new QOpenGLShader(QOpenGLShader::Fragment); + if (!fragment_shader_cylinder->compileSourceCode(source_)) + { std::cerr << "Compiling fragment source for cylinder FAILED" << std::endl; } + + + if (!rendering_program_cylinder.addShader(vertex_shader_cylinder)) + { std::cerr << "Adding vertex shader for cylinder FAILED" << std::endl;} + if (!rendering_program_cylinder.addShader(geometry_shader_cylinder)) + { std::cerr << "Adding geometry shader for cylinder FAILED" << std::endl;} + if (!rendering_program_cylinder.addShader(fragment_shader_cylinder)) + { std::cerr << "Adding fragment shader for clipping plane FAILED" << std::endl; } + if (!rendering_program_cylinder.link()) + { std::cerr << "Linking Program for cylinder FAILED" << std::endl; } + } + + // Normal shader + if (isOpenGL_4_3()) + { + source_ = VERTEX_SOURCE_NORMAL; + + QOpenGLShader *vertex_shader_normal = new QOpenGLShader(QOpenGLShader::Vertex); + if (!vertex_shader_normal->compileSourceCode(source_)) + { std::cerr << "Compiling vertex source for normal FAILED" << std::endl; } + + source_ = GEOMETRY_SOURCE_NORMAL; + + QOpenGLShader *geometry_shader_normal = new QOpenGLShader(QOpenGLShader::Geometry); + if (!geometry_shader_normal->compileSourceCode(source_)) + { std::cerr << "Compiling geometry source for normal FAILED" << std::endl; } + + source_ = FRAGMENT_SOURCE_P_L; + + QOpenGLShader *fragment_shader_normal = new QOpenGLShader(QOpenGLShader::Fragment); + if (!fragment_shader_normal->compileSourceCode(source_)) + { std::cerr << "Compiling fragment source for normal FAILED" << std::endl; } + + + if (!rendering_program_normal.addShader(vertex_shader_normal)) + { std::cerr << "Adding vertex shader for normal FAILED" << std::endl;} + if (!rendering_program_normal.addShader(geometry_shader_normal)) + { std::cerr << "Adding geometry shader for normal FAILED" << std::endl;} + if (!rendering_program_normal.addShader(fragment_shader_normal)) + { std::cerr << "Adding fragment shader for clipping plane FAILED" << std::endl; } + if (!rendering_program_normal.link()) + { std::cerr << "Linking Program for normal FAILED" << std::endl; } + } + + // Normal shader + if (isOpenGL_4_3()) + { + source_ = VERTEX_SOURCE_TRIANGLE; + + QOpenGLShader *vertex_shader_triangle = new QOpenGLShader(QOpenGLShader::Vertex); + if (!vertex_shader_triangle->compileSourceCode(source_)) + { std::cerr << "Compiling vertex source for triangle FAILED" << std::endl; } + + source_ = GEOMETRY_SOURCE_TRIANGLE; + + QOpenGLShader *geometry_shader_triangle = new QOpenGLShader(QOpenGLShader::Geometry); + if (!geometry_shader_triangle->compileSourceCode(source_)) + { std::cerr << "Compiling geometry source for triangle FAILED" << std::endl; } + + source_ = FRAGMENT_SOURCE_P_L; + + QOpenGLShader *fragment_shader_triangle = new QOpenGLShader(QOpenGLShader::Fragment); + if (!fragment_shader_triangle->compileSourceCode(source_)) + { std::cerr << "Compiling fragment source for triangle FAILED" << std::endl; } + + + if (!rendering_program_triangle.addShader(vertex_shader_triangle)) + { std::cerr << "Adding vertex shader for triangle FAILED" << std::endl;} + if (!rendering_program_triangle.addShader(geometry_shader_triangle)) + { std::cerr << "Adding geometry shader for triangle FAILED" << std::endl;} + if (!rendering_program_triangle.addShader(fragment_shader_triangle)) + { std::cerr << "Adding fragment shader for clipping plane FAILED" << std::endl; } + if (!rendering_program_triangle.link()) + { std::cerr << "Linking Program for triangle FAILED" << std::endl; } + } + + // Line shader + if (isOpenGL_4_3()) + { + source_ = VERTEX_SOURCE_LINE_WIDTH; + + QOpenGLShader *vertex_shader_line = new QOpenGLShader(QOpenGLShader::Vertex); + if (!vertex_shader_line->compileSourceCode(source_)) + { std::cerr << "Compiling vertex source for line FAILED" << std::endl; } + + source_ = GEOMETRY_SOURCE_LINE_WIDTH; + + QOpenGLShader *geometry_shader_line = new QOpenGLShader(QOpenGLShader::Geometry); + if (!geometry_shader_line->compileSourceCode(source_)) + { std::cerr << "Compiling geometry source for line FAILED" << std::endl; } + + source_ = FRAGMENT_SOURCE_P_L; + + QOpenGLShader *fragment_shader_line = new QOpenGLShader(QOpenGLShader::Fragment); + if (!fragment_shader_line->compileSourceCode(source_)) + { std::cerr << "Compiling fragment source for line FAILED" << std::endl; } + + + if (!rendering_program_line.addShader(vertex_shader_line)) + { std::cerr << "Adding vertex shader for line FAILED" << std::endl;} + if (!rendering_program_line.addShader(geometry_shader_line)) + { std::cerr << "Adding geometry shader for line FAILED" << std::endl;} + if (!rendering_program_line.addShader(fragment_shader_line)) + { std::cerr << "Adding fragment shader for line FAILED" << std::endl; } + if (!rendering_program_line.link()) + { std::cerr << "Linking Program for line FAILED" << std::endl; } + } } void initialize_buffers() @@ -744,274 +1129,116 @@ protected: set_camera_mode(); rendering_program_p_l.bind(); + unsigned int bufn = 0; + std::vector positions, normals, colors; // 1) POINT SHADER - // 1.1) Mono points - vao[VAO_MONO_POINTS].bind(); + vao[VAO_POINTS].bind(); + positions = m_scene.get_array_of_index(GS::POS_POINTS); + colors = m_scene.get_array_of_index(GS::COLOR_POINTS); - unsigned int bufn = 0; CGAL_assertion(bufn(m_array_for_clipping_plane.size()*sizeof(BufferType))); - rendering_program_clipping_plane.enableAttributeArray("vertex"); - rendering_program_clipping_plane.setAttributeBuffer("vertex", GL_FLOAT, 0, 3); + rendering_program_clipping_plane.enableAttributeArray("a_Pos"); + rendering_program_clipping_plane.setAttributeBuffer("a_Pos", GL_FLOAT, 0, 3); buffers[bufn].release(); @@ -1064,13 +1291,13 @@ protected: 1.0f ); CGAL::Bbox_3 bb; - if (bb==gBuffer.bounding_box()) // Case of "empty" bounding box + if (bb==m_scene.bounding_box()) // Case of "empty" bounding box { bb=Local_point(CGAL::ORIGIN).bbox(); bb=bb + Local_point(1,1,1).bbox(); // To avoid a warning from Qglviewer } else - { bb=gBuffer.bounding_box(); } + { bb=m_scene.bounding_box(); } QVector4D position((bb.xmax()-bb.xmin())/2, (bb.ymax()-bb.ymin())/2, @@ -1078,14 +1305,14 @@ protected: GLfloat shininess = 1.0f; rendering_program_face.bind(); - int mvpLocation = rendering_program_face.uniformLocation("mvp_matrix"); - int mvLocation = rendering_program_face.uniformLocation("mv_matrix"); + int mvpLocation = rendering_program_face.uniformLocation("u_Mvp"); + int mvLocation = rendering_program_face.uniformLocation("u_Mv"); int lightLocation[5]; - lightLocation[0] = rendering_program_face.uniformLocation("light_pos"); - lightLocation[1] = rendering_program_face.uniformLocation("light_diff"); - lightLocation[2] = rendering_program_face.uniformLocation("light_spec"); - lightLocation[3] = rendering_program_face.uniformLocation("light_amb"); - lightLocation[4] = rendering_program_face.uniformLocation("spec_power"); + lightLocation[0] = rendering_program_face.uniformLocation("u_LightPos"); + lightLocation[1] = rendering_program_face.uniformLocation("u_LightDiff"); + lightLocation[2] = rendering_program_face.uniformLocation("u_LightSpec"); + lightLocation[3] = rendering_program_face.uniformLocation("u_LightAmb"); + lightLocation[4] = rendering_program_face.uniformLocation("u_SpecPower"); rendering_program_face.setUniformValue(lightLocation[0], position); rendering_program_face.setUniformValue(lightLocation[1], diffuse); @@ -1097,10 +1324,21 @@ protected: rendering_program_face.release(); rendering_program_p_l.bind(); - int mvpLocation2 = rendering_program_p_l.uniformLocation("mvp_matrix"); - rendering_program_p_l.setUniformValue(mvpLocation2, mvpMatrix); + mvpLocation = rendering_program_p_l.uniformLocation("u_Mvp"); + rendering_program_p_l.setUniformValue(mvpLocation, mvpMatrix); rendering_program_p_l.release(); + // cylinder edge feature + rendering_program_cylinder.bind(); + mvpLocation = rendering_program_cylinder.uniformLocation("u_Mvp"); + rendering_program_cylinder.setUniformValue(mvpLocation, mvpMatrix); + rendering_program_cylinder.release(); + + // sphere vertex feature + rendering_program_sphere.bind(); + mvpLocation = rendering_program_sphere.uniformLocation("u_Mvp"); + rendering_program_sphere.setUniformValue(mvpLocation, mvpMatrix); + rendering_program_sphere.release(); if (isOpenGL_4_3()) { @@ -1110,12 +1348,49 @@ protected: { clipping_mMatrix.data()[i] = m_frame_plane->matrix()[i]; } rendering_program_clipping_plane.bind(); - int vpLocation = rendering_program_clipping_plane.uniformLocation("vp_matrix"); - int mLocation = rendering_program_clipping_plane.uniformLocation("m_matrix"); + int vpLocation = rendering_program_clipping_plane.uniformLocation("u_Vp"); + int mLocation = rendering_program_clipping_plane.uniformLocation("u_M"); rendering_program_clipping_plane.setUniformValue(vpLocation, mvpMatrix); rendering_program_clipping_plane.setUniformValue(mLocation, clipping_mMatrix); rendering_program_clipping_plane.release(); } + + if (isOpenGL_4_3()) + { + rendering_program_normal.bind(); + + QMatrix4x4 projection; + double mat[16]; + viewer->camera()->getProjectionMatrix(mat); + for(unsigned int i=0; i < 16; i++) + { + projection.data()[i] = (float)mat[i]; + } + + int mvLocation = rendering_program_normal.uniformLocation("u_Mv"); + int pLocation = rendering_program_normal.uniformLocation("u_Projection"); + rendering_program_normal.setUniformValue(mvLocation, mvMatrix); + rendering_program_normal.setUniformValue(pLocation, projection); + rendering_program_normal.release(); + } + + if (isOpenGL_4_3()) + { + rendering_program_triangle.bind(); + + int mvpLocation = rendering_program_triangle.uniformLocation("u_Mvp"); + rendering_program_triangle.setUniformValue(mvpLocation, mvpMatrix); + rendering_program_triangle.release(); + } + + if (isOpenGL_4_3()) + { + rendering_program_line.bind(); + + int mvpLocation = rendering_program_line.uniformLocation("u_Mvp"); + rendering_program_line.setUniformValue(mvpLocation, mvpMatrix); + rendering_program_line.release(); + } } void set_camera_mode() @@ -1128,8 +1403,8 @@ protected: constraint.setTranslationConstraintType(CGAL::qglviewer::AxisPlaneConstraint::FREE); double cx=0., cy=0., cz=0.; - if (gBuffer.has_zero_x()) { cx=1.; } - else if (gBuffer.has_zero_y()) { cy=1.; } + if (m_scene.has_zero_x()) { cx=1.; } + else if (m_scene.has_zero_y()) { cy=1.; } else { cz=1.; } camera()->setViewDirection(CGAL::qglviewer::Vec(-cx,-cy,-cz)); @@ -1154,6 +1429,7 @@ protected: glPolygonOffset(1.f,1.f); glClearColor(1.0f,1.0f,1.0f,0.0f); glDisable(GL_BLEND); + glEnable(GL_PROGRAM_POINT_SIZE); glEnable(GL_LINE_SMOOTH); glDisable(GL_POLYGON_SMOOTH_HINT); glBlendFunc(GL_ONE, GL_ZERO); @@ -1162,13 +1438,13 @@ protected: compile_shaders(); CGAL::Bbox_3 bb; - if (bb==gBuffer.bounding_box()) // Case of "empty" bounding box + if (bb==m_scene.bounding_box()) // Case of "empty" bounding box { bb=Local_point(CGAL::ORIGIN).bbox(); bb=bb + Local_point(1,1,1).bbox(); // To avoid a warning from Qglviewer } else - { bb=gBuffer.bounding_box(); } + { bb=m_scene.bounding_box(); } this->camera()->setSceneBoundingBox(CGAL::qglviewer::Vec(bb.xmin(), bb.ymin(), bb.zmin()), @@ -1178,21 +1454,33 @@ protected: m_frame_plane=new CGAL::qglviewer::ManipulatedFrame; + // Check for geometry shader availability + int max_geometry_output_vertices = 0; + glGetIntegerv(GL_MAX_GEOMETRY_OUTPUT_VERTICES, &max_geometry_output_vertices); + int max_geometry_output_components = 0; + glGetIntegerv(GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS, &max_geometry_output_components); + + if (max_geometry_output_vertices < 128 || max_geometry_output_components < 1024) + { + std::cout << "Cylinder edge and sphere vertex feature disabled! (max_geometry_output_vertices=" << max_geometry_output_vertices << ", max_geometry_output_components=" << max_geometry_output_components << ")\n"; + m_geometry_feature_enabled = false; + } + this->showEntireScene(); } void generate_clipping_plane() { - qreal size=((gBuffer.bounding_box().xmax()-gBuffer.bounding_box().xmin()) + - (gBuffer.bounding_box().ymax()-gBuffer.bounding_box().ymin()) + - (gBuffer.bounding_box().zmax()-gBuffer.bounding_box().zmin())); - const unsigned int nbSubdivisions=30; + qreal size=((m_scene.bounding_box().xmax()-m_scene.bounding_box().xmin()) + + (m_scene.bounding_box().ymax()-m_scene.bounding_box().ymin()) + + (m_scene.bounding_box().zmax()-m_scene.bounding_box().zmin())); + const unsigned int nb_subdivisions=30; auto& array = m_array_for_clipping_plane; array.clear(); - for (unsigned int i=0; i<=nbSubdivisions; ++i) + for (unsigned int i=0; i<=nb_subdivisions; ++i) { - const float pos = float(size*(2.0*i/nbSubdivisions-1.0)); + const float pos = float(size*(2.0*i/nb_subdivisions-1.0)); array.push_back(pos); array.push_back(float(-size)); array.push_back(0.f); @@ -1209,6 +1497,27 @@ protected: array.push_back(pos); array.push_back(0.f); } + + // Normal + array.push_back(0.f); + array.push_back(0.f); + array.push_back(0.f); + array.push_back(0.f); + array.push_back(0.f); + array.push_back(1.f); + } + + virtual void mouseDoubleClickEvent(QMouseEvent *e) + { + if ((e->modifiers()==::Qt::ShiftModifier) && (e->button()==::Qt::LeftButton)) + { + if (manipulatedFrame()) + { + camera()->frame()->alignWithFrame(manipulatedFrame(), true); + } + } else { + CGAL::QGLViewer::mouseDoubleClickEvent(e); + } } virtual void keyPressEvent(QKeyEvent *e) @@ -1258,8 +1567,8 @@ protected: } else if ((e->key()==::Qt::Key_M) && (modifiers==::Qt::NoButton)) { - m_use_mono_color=!m_use_mono_color; - displayMessage(QString("Mono color=%1.").arg(m_use_mono_color?"true":"false")); + m_use_default_color=!m_use_default_color; + displayMessage(QString("Mono color=%1.").arg(m_use_default_color?"true":"false")); update(); } else if ((e->key()==::Qt::Key_N) && (modifiers==::Qt::NoButton)) @@ -1270,8 +1579,8 @@ protected: } else if ((e->key()==::Qt::Key_S) && (modifiers==::Qt::NoButton)) { - m_flatShading=!m_flatShading; - if (m_flatShading) + m_flat_shading=!m_flat_shading; + if (m_flat_shading) displayMessage("Flat shading."); else displayMessage("Gouraud shading."); @@ -1333,14 +1642,14 @@ protected: } else if ((e->key()==::Qt::Key_Plus) && (modifiers.testFlag(::Qt::ControlModifier))) { - m_size_points+=.5; - displayMessage(QString("Size of points=%1.").arg(m_size_points)); + m_size_vertices+=.5; + displayMessage(QString("Size of points=%1.").arg(m_size_vertices)); update(); } else if ((e->key()==::Qt::Key_Minus) && (modifiers.testFlag(::Qt::ControlModifier))) { - if (m_size_points>.5) m_size_points-=.5; - displayMessage(QString("Size of points=%1.").arg(m_size_points)); + if (m_size_vertices>.5) m_size_vertices-=.5; + displayMessage(QString("Size of points=%1.").arg(m_size_vertices)); update(); } else if ((e->key()==::Qt::Key_PageUp) && (modifiers==::Qt::NoButton)) @@ -1428,6 +1737,47 @@ protected: update(); } } + else if ((e->key()==::Qt::Key_V) && (modifiers==::Qt::ControlModifier)) + { + m_draw_sphere_vertex = !m_draw_sphere_vertex; + displayMessage(QString("Draw sphere vertex=%1.").arg(m_draw_sphere_vertex?"true":"false")); + update(); + } + else if ((e->key()==::Qt::Key_E) && (modifiers==::Qt::ControlModifier)) + { + m_draw_cylinder_edge = !m_draw_cylinder_edge; + displayMessage(QString("Draw cylinder edge=%1.").arg(m_draw_cylinder_edge?"true":"false")); + update(); + } + else if ((e->key()==::Qt::Key_N) && (modifiers==::Qt::ControlModifier)) + { + m_draw_normals = !m_draw_normals; + displayMessage(QString("Draw normals=%1.").arg(m_draw_normals?"true":"false")); + update(); + } + else if ((e->key()==::Qt::Key_T) && (modifiers==::Qt::ControlModifier)) + { + m_draw_mesh_triangles = !m_draw_mesh_triangles; + displayMessage(QString("Draw triangles=%1.").arg(m_draw_mesh_triangles?"true":"false")); + update(); + } + else if ((e->key()==::Qt::Key_M) && (modifiers==::Qt::ControlModifier)) + { + m_use_default_color_normal = !m_use_default_color_normal; + displayMessage(QString("Normal mono color=%1.").arg(m_use_default_color_normal?"true":"false")); + update(); + } + else if ((e->key()==::Qt::Key_N) && (modifiers==::Qt::ShiftModifier)) + { + m_display_face_normal = !m_display_face_normal; + displayMessage(QString("Display face normal=%1.").arg(m_display_face_normal?"true":"false")); + update(); + } + else if ((e->key()==::Qt::Key_F2)) + { + capture_screenshot(QString("./screenshot.png")); + displayMessage(QString("Screenshot saved in ./screenshot")); + } else { CGAL::QGLViewer::keyPressEvent(e); } // By default call QGLViewer key press } @@ -1467,22 +1817,40 @@ protected: text += "Press Escape to exit the viewer."; return text; } + + void capture_screenshot(const QString& file_path) + { + QScreen *screen; + screen = QApplication::primaryScreen(); + + auto geom = screen->geometry(); + auto qpx_pixmap = screen->grabWindow(this->winId()); + qpx_pixmap.save(file_path); + } + public: std::function on_key_pressed; protected: - const Graphics_scene& gBuffer; + const Graphics_scene& m_scene; bool m_draw_vertices; bool m_draw_edges; bool m_draw_rays; bool m_draw_lines; bool m_draw_faces; - bool m_flatShading; - bool m_use_mono_color; - bool m_inverse_normal; bool m_draw_text; + bool m_draw_normals; + bool m_draw_cylinder_edge; + bool m_draw_sphere_vertex; + bool m_draw_mesh_triangles; + bool m_flat_shading; + bool m_use_default_color; + bool m_use_default_color_normal; + bool m_display_face_normal; + bool m_inverse_normal; bool m_no_2D_mode; + bool m_geometry_feature_enabled; enum { CLIPPING_PLANE_OFF = 0, @@ -1499,17 +1867,16 @@ protected: // filled by users but by the basic viewer. std::vector m_array_for_clipping_plane; - double m_size_points; + double m_size_vertices; double m_size_edges; double m_size_rays; double m_size_lines; + double m_size_normals; - CGAL::IO::Color m_vertices_mono_color; - CGAL::IO::Color m_edges_mono_color; - CGAL::IO::Color m_rays_mono_color; - CGAL::IO::Color m_lines_mono_color; - CGAL::IO::Color m_faces_mono_color; - QVector4D m_ambient_color; + double m_height_factor_normals; + + CGAL::IO::Color m_default_color_normal; + QVector4D m_ambient_color; bool m_are_buffers_initialized; @@ -1523,24 +1890,25 @@ protected: // The following enum gives the indices of the different vao. enum - { VAO_MONO_POINTS=0, - VAO_COLORED_POINTS, - VAO_MONO_SEGMENTS, - VAO_COLORED_SEGMENTS, - VAO_MONO_RAYS, - VAO_COLORED_RAYS, - VAO_MONO_LINES, - VAO_COLORED_LINES, - VAO_MONO_FACES, - VAO_COLORED_FACES, - VAO_CLIPPING_PLANE, - NB_VAO_BUFFERS - }; + { + VAO_POINTS=0, + VAO_SEGMENTS, + VAO_RAYS, + VAO_LINES, + VAO_FACES, + VAO_CLIPPING_PLANE, + NB_VAO_BUFFERS + }; QOpenGLVertexArrayObject vao[NB_VAO_BUFFERS]; QOpenGLShaderProgram rendering_program_face; QOpenGLShaderProgram rendering_program_p_l; + QOpenGLShaderProgram rendering_program_line; QOpenGLShaderProgram rendering_program_clipping_plane; + QOpenGLShaderProgram rendering_program_sphere; + QOpenGLShaderProgram rendering_program_cylinder; + QOpenGLShaderProgram rendering_program_normal; + QOpenGLShaderProgram rendering_program_triangle; // variables for clipping plane bool clipping_plane_rendering = true; // will be toggled when alt+c is pressed, which is used for indicating whether or not to render the clipping plane ; @@ -1617,7 +1985,7 @@ using Qt::Basic_viewer; inline void draw_graphics_scene(const Graphics_scene& graphics_scene, - const char *title="CGAL Basic Viewer") + const char *title="CGAL Basic Viewer (Qt)") { #if defined(CGAL_TEST_SUITE) bool cgal_test_suite = true; @@ -1641,26 +2009,4 @@ void draw_graphics_scene(const Graphics_scene& graphics_scene, } // End namespace CGAL -#else // CGAL_USE_BASIC_VIEWER - -namespace CGAL -{ - - template - void draw(T...) - { - std::cerr<<"Impossible to draw, CGAL_USE_BASIC_VIEWER is not defined."<`. \tparam GSOptions a model of `GraphicsSceneOptionsPolygonSet2` concept. diff --git a/Boolean_set_operations_2/include/CGAL/draw_polygon_set_2.h b/Boolean_set_operations_2/include/CGAL/draw_polygon_set_2.h index 3ae8c90a999..e8af7da33d8 100644 --- a/Boolean_set_operations_2/include/CGAL/draw_polygon_set_2.h +++ b/Boolean_set_operations_2/include/CGAL/draw_polygon_set_2.h @@ -19,10 +19,10 @@ #include -#include #include #include #include +#include namespace CGAL { @@ -166,7 +166,7 @@ void compute_elements(const PWH& pwh, } // End namespace draw_function_for_boolean_set_2 -#ifdef CGAL_USE_BASIC_VIEWER +#if defined(CGAL_USE_BASIC_VIEWER_QT) || defined(CGAL_USE_BASIC_VIEWER) template class Polygon_set_2_basic_viewer_qt : public Basic_viewer @@ -319,7 +319,7 @@ void draw(const CGAL_PS2_TYPE& ps, draw(ps, gso, title); } -#endif // CGAL_USE_BASIC_VIEWER +#endif // CGAL_USE_BASIC_VIEWER_QT || CGAL_USE_BASIC_VIEWER #undef CGAL_PS2_TYPE diff --git a/Installation/lib/cmake/CGAL/CGALConfig.cmake b/Installation/lib/cmake/CGAL/CGALConfig.cmake index 0d20a7e9bbc..9f850cab51f 100644 --- a/Installation/lib/cmake/CGAL/CGALConfig.cmake +++ b/Installation/lib/cmake/CGAL/CGALConfig.cmake @@ -203,6 +203,13 @@ if (NOT TARGET CGAL::CGAL_Basic_viewer) INTERFACE_LINK_LIBRARIES CGAL::CGAL_Qt6) endif() +if (NOT TARGET CGAL::CGAL_Basic_viewer_Qt) + add_library(CGAL::CGAL_Basic_viewer_Qt INTERFACE IMPORTED GLOBAL) + set_target_properties(CGAL::CGAL_Basic_viewer_Qt PROPERTIES + INTERFACE_COMPILE_DEFINITIONS "CGAL_USE_BASIC_VIEWER_QT" + INTERFACE_LINK_LIBRARIES CGAL::CGAL_Qt6) +endif() + #warning: the order in this list has to match the enum in Exact_type_selector set(CGAL_CMAKE_EXACT_NT_BACKEND_OPTIONS GMP_BACKEND GMPXX_BACKEND BOOST_GMP_BACKEND BOOST_BACKEND LEDA_BACKEND MP_FLOAT_BACKEND Default) set(CGAL_CMAKE_EXACT_NT_BACKEND "Default" CACHE STRING "Setting for advanced users that what to change the default number types used in filtered kernels. Some options might not be working depending on how you configured your build.") diff --git a/Linear_cell_complex/doc/Linear_cell_complex/CGAL/draw_linear_cell_complex.h b/Linear_cell_complex/doc/Linear_cell_complex/CGAL/draw_linear_cell_complex.h index 3b8903c87f2..8bd648331e8 100644 --- a/Linear_cell_complex/doc/Linear_cell_complex/CGAL/draw_linear_cell_complex.h +++ b/Linear_cell_complex/doc/Linear_cell_complex/CGAL/draw_linear_cell_complex.h @@ -5,8 +5,8 @@ namespace CGAL { opens a new window and draws a linear cell complex. Parameters of the drawing are taken from the optional graphics scene options parameter. -A call to this function blocks the execution of the program until the drawing window is closed. This function requires `CGAL_Qt6`, and is only available if the macro `CGAL_USE_BASIC_VIEWER` is defined. -Linking with the cmake target `CGAL::CGAL_Basic_viewer` will link with `CGAL_Qt6` and add the definition `CGAL_USE_BASIC_VIEWER`. +A call to this function blocks the execution of the program until the drawing window is closed. This function requires `CGAL_Qt6`, and is only available if the macro `CGAL_USE_BASIC_VIEWER`/`CGAL_USE_BASIC_VIEWER_QT` (Qt viewer) is defined. +Linking with the cmake target `CGAL::CGAL_Basic_viewer`/`CGAL::CGAL_Basic_viewer_Qt` will link with `CGAL_Qt6` and add the definition `CGAL_USE_BASIC_VIEWER`/`CGAL_USE_BASIC_VIEWER_QT`. \tparam LCC which must be an instantiation of a `CGAL::Linear_cell_complex_for_combinatorial_map<...>` or `CGAL::Linear_cell_complex_for_generalized_map<...>`. \tparam GSOptions a model of `GraphicsSceneOptions` concept. diff --git a/Nef_3/doc/Nef_3/CGAL/draw_nef_3.h b/Nef_3/doc/Nef_3/CGAL/draw_nef_3.h index a9618a3d629..75f721ea29e 100644 --- a/Nef_3/doc/Nef_3/CGAL/draw_nef_3.h +++ b/Nef_3/doc/Nef_3/CGAL/draw_nef_3.h @@ -5,8 +5,8 @@ namespace CGAL { opens a new window and draws a nef polyhedron. Parameters of the drawing are taken from the optional graphics scene options parameter. -A call to this function blocks the execution of the program until the drawing window is closed. This function requires `CGAL_Qt6`, and is only available if the macro `CGAL_USE_BASIC_VIEWER` is defined. -Linking with the cmake target `CGAL::CGAL_Basic_viewer` will link with `CGAL_Qt6` and add the definition `CGAL_USE_BASIC_VIEWER`. +A call to this function blocks the execution of the program until the drawing window is closed. This function requires `CGAL_Qt6`, and is only available if the macro `CGAL_USE_BASIC_VIEWER`/`CGAL_USE_BASIC_VIEWER_QT` (Qt viewer) is defined. +Linking with the cmake target `CGAL::CGAL_Basic_viewer`/`CGAL::CGAL_Basic_viewer_Qt` will link with `CGAL_Qt6` and add the definition `CGAL_USE_BASIC_VIEWER`/`CGAL_USE_BASIC_VIEWER_QT`. \tparam NP3 which must be an instantiation of a `CGAL::Nef_polyhedron_3<...>`. \tparam GSOptions a model of `GraphicsSceneOptions` concept. diff --git a/Nef_3/include/CGAL/draw_nef_3.h b/Nef_3/include/CGAL/draw_nef_3.h index aac531bcd5d..a2160b7fad1 100644 --- a/Nef_3/include/CGAL/draw_nef_3.h +++ b/Nef_3/include/CGAL/draw_nef_3.h @@ -15,7 +15,7 @@ #define DRAW_NEF_3_H #include -#include +#include #include #include #include @@ -278,8 +278,6 @@ void add_to_graphics_scene(const CGAL_NEF3_TYPE &anef, add_to_graphics_scene(anef, graphics_scene, gs_options); } -#ifdef CGAL_USE_BASIC_VIEWER - // Specialization of draw function template @@ -301,8 +299,6 @@ void draw(const CGAL_NEF3_TYPE &anef, draw_graphics_scene(buffer, title); } -#endif // CGAL_USE_BASIC_VIEWER - #undef CGAL_NEF3_TYPE } // End namespace CGAL diff --git a/Periodic_2_triangulation_2/doc/Periodic_2_triangulation_2/CGAL/draw_periodic_2_triangulation_2.h b/Periodic_2_triangulation_2/doc/Periodic_2_triangulation_2/CGAL/draw_periodic_2_triangulation_2.h index cc9ad80bdf0..7fbdbb8f988 100644 --- a/Periodic_2_triangulation_2/doc/Periodic_2_triangulation_2/CGAL/draw_periodic_2_triangulation_2.h +++ b/Periodic_2_triangulation_2/doc/Periodic_2_triangulation_2/CGAL/draw_periodic_2_triangulation_2.h @@ -27,8 +27,8 @@ struct Graphics_scene_options_periodic_2_triangulation_2: public CGAL::Graphics_ opens a new window and draws a periodic 2D triangulation. Parameters of the drawing are taken from the optional graphics scene options parameter. -A call to this function blocks the execution of the program until the drawing window is closed. This function requires `CGAL_Qt6`, and is only available if the macro `CGAL_USE_BASIC_VIEWER` is defined. -Linking with the cmake target `CGAL::CGAL_Basic_viewer` will link with `CGAL_Qt6` and add the definition `CGAL_USE_BASIC_VIEWER`. +A call to this function blocks the execution of the program until the drawing window is closed. This function requires `CGAL_Qt6`, and is only available if the macro `CGAL_USE_BASIC_VIEWER`/`CGAL_USE_BASIC_VIEWER_QT` (Qt viewer) is defined. +Linking with the cmake target `CGAL::CGAL_Basic_viewer`/`CGAL::CGAL_Basic_viewer_Qt` will link with `CGAL_Qt6` and add the definition `CGAL_USE_BASIC_VIEWER`/`CGAL_USE_BASIC_VIEWER_QT`. \tparam P2T2 which must be an instantiation of a `CGAL::Periodic_2_triangulation_2<...>`. \tparam GSOptions a model of `GraphicsSceneOptionsPeriodic2Triangulation2` concept. diff --git a/Periodic_2_triangulation_2/include/CGAL/draw_periodic_2_triangulation_2.h b/Periodic_2_triangulation_2/include/CGAL/draw_periodic_2_triangulation_2.h index 048494256b3..e0a636b0854 100644 --- a/Periodic_2_triangulation_2/include/CGAL/draw_periodic_2_triangulation_2.h +++ b/Periodic_2_triangulation_2/include/CGAL/draw_periodic_2_triangulation_2.h @@ -14,7 +14,7 @@ #define DRAW_PERIODIC_2_TRIANGULATION_2_H #include -#include +#include #include #include #include @@ -220,7 +220,7 @@ void add_to_graphics_scene(const CGAL_P2T2_TYPE& p2t2, add_to_graphics_scene(p2t2, graphics_scene, gs_options); } -#ifdef CGAL_USE_BASIC_VIEWER +#if defined(CGAL_USE_BASIC_VIEWER_QT) || defined(CGAL_USE_BASIC_VIEWER) // Specialization of draw function template @@ -278,7 +278,7 @@ void draw(const CGAL_P2T2_TYPE& ap2t2, draw(ap2t2, gs_options, title); } -#endif // CGAL_USE_BASIC_VIEWER +#endif // CGAL_USE_BASIC_VIEWER_QT || CGAL_USE_BASIC_VIEWER #undef CGAL_P2T2_TYPE diff --git a/Point_set_3/include/CGAL/draw_point_set_3.h b/Point_set_3/include/CGAL/draw_point_set_3.h index 35ce674f3a3..e01725be598 100644 --- a/Point_set_3/include/CGAL/draw_point_set_3.h +++ b/Point_set_3/include/CGAL/draw_point_set_3.h @@ -15,7 +15,7 @@ #define CGAL_DRAW_POINT_SET_3_H #include -#include +#include #include #include #include @@ -28,8 +28,8 @@ namespace CGAL { opens a new window and draws a point set. Parameters of the drawing are taken from the optional graphics scene options parameter. -A call to this function blocks the execution of the program until the drawing window is closed. This function requires `CGAL_Qt6`, and is only available if the macro `CGAL_USE_BASIC_VIEWER` is defined. -Linking with the cmake target `CGAL::CGAL_Basic_viewer` will link with `CGAL_Qt6` and add the definition `CGAL_USE_BASIC_VIEWER`. +A call to this function blocks the execution of the program until the drawing window is closed. This function requires `CGAL_Qt6`, and is only available if the macro `CGAL_USE_BASIC_VIEWER`/`CGAL_USE_BASIC_VIEWER_QT` (Qt viewer) is defined. +Linking with the cmake target `CGAL::CGAL_Basic_viewer`/`CGAL::CGAL_Basic_viewer_Qt` will link with `CGAL_Qt6` and add the definition `CGAL_USE_BASIC_VIEWER`/`CGAL_USE_BASIC_VIEWER_QT`. \tparam PS which must be an instantiation of a `CGAL::Point_set_3<...>`. \tparam GSOptions a model of `GraphicsSceneOptions` concept. @@ -147,8 +147,6 @@ void add_to_graphics_scene(const Point_set_3& apointset, add_to_graphics_scene(apointset, graphics_scene, gs_options); } -#ifdef CGAL_USE_BASIC_VIEWER - // Specialization of draw function. template void draw(const Point_set_3& apointset, @@ -169,8 +167,6 @@ void draw(const Point_set_3& apointset, draw_graphics_scene(buffer, title); } -#endif // CGAL_USE_BASIC_VIEWER - } // End namespace CGAL #endif // CGAL_DRAW_POINT_SET_3_H diff --git a/Polygon/include/CGAL/draw_multipolygon_with_holes_2.h b/Polygon/include/CGAL/draw_multipolygon_with_holes_2.h index 8950956786e..ddcc967a1de 100644 --- a/Polygon/include/CGAL/draw_multipolygon_with_holes_2.h +++ b/Polygon/include/CGAL/draw_multipolygon_with_holes_2.h @@ -18,7 +18,7 @@ #ifndef CGAL_DRAW_MULTIPOLYGON_WITH_HOLES_2_H #define CGAL_DRAW_MULTIPOLYGON_WITH_HOLES_2_H -#include +#include #ifdef DOXYGEN_RUNNING namespace CGAL { @@ -44,7 +44,7 @@ void draw(const MPH& aph); #endif -#ifdef CGAL_USE_BASIC_VIEWER +#if defined(CGAL_USE_BASIC_VIEWER_QT) || defined(CGAL_USE_BASIC_VIEWER) #include #include @@ -207,6 +207,6 @@ void draw(const CGAL::Multipolygon_with_holes_2& mpwh, } // End namespace CGAL -#endif // CGAL_USE_BASIC_VIEWER +#endif // CGAL_USE_BASIC_VIEWER_QT || CGAL_USE_BASIC_VIEWER #endif // CGAL_DRAW_MULTIPOLYGON_WITH_HOLES_2_H diff --git a/Polygon/include/CGAL/draw_polygon_2.h b/Polygon/include/CGAL/draw_polygon_2.h index 80becbe5508..38b6da1335f 100644 --- a/Polygon/include/CGAL/draw_polygon_2.h +++ b/Polygon/include/CGAL/draw_polygon_2.h @@ -18,7 +18,7 @@ #ifndef CGAL_DRAW_POLYGON_2_H #define CGAL_DRAW_POLYGON_2_H -#include +#include #include #include #include @@ -31,8 +31,8 @@ namespace CGAL { opens a new window and draws a 2D polygon. Parameters of the drawing are taken from the optional graphics scene options parameter. -A call to this function blocks the execution of the program until the drawing window is closed. This function requires `CGAL_Qt6`, and is only available if the macro `CGAL_USE_BASIC_VIEWER` is defined. -Linking with the cmake target `CGAL::CGAL_Basic_viewer` will link with `CGAL_Qt6` and add the definition `CGAL_USE_BASIC_VIEWER`. +A call to this function blocks the execution of the program until the drawing window is closed. This function requires `CGAL_Qt6`, and is only available if the macro `CGAL_USE_BASIC_VIEWER`/`CGAL_USE_BASIC_VIEWER_QT` (Qt viewer) is defined. +Linking with the cmake target `CGAL::CGAL_Basic_viewer`/`CGAL::CGAL_Basic_viewer_Qt` will link with `CGAL_Qt6` and add the definition `CGAL_USE_BASIC_VIEWER`/`CGAL_USE_BASIC_VIEWER_QT`. \tparam P which must be an instantiation of a `CGAL::Polygon_2<...>`. \tparam GSOptions a model of `GraphicsSceneOptions` concept. @@ -174,8 +174,6 @@ void add_to_graphics_scene(const CGAL_P2_TYPE& ap2, draw_function_for_p2::compute_elements(ap2, graphics_scene, gso); } -#ifdef CGAL_USE_BASIC_VIEWER - // Specialization of draw function. template void draw(const CGAL_P2_TYPE &ap2, @@ -196,8 +194,6 @@ void draw(const CGAL_P2_TYPE &ap2, draw_graphics_scene(buffer, title); } -#endif // CGAL_USE_BASIC_VIEWER - #undef CGAL_P2_TYPE } // End namespace CGAL diff --git a/Polygon/include/CGAL/draw_polygon_with_holes_2.h b/Polygon/include/CGAL/draw_polygon_with_holes_2.h index ff6fde2e8c6..1a7085944be 100644 --- a/Polygon/include/CGAL/draw_polygon_with_holes_2.h +++ b/Polygon/include/CGAL/draw_polygon_with_holes_2.h @@ -18,7 +18,7 @@ #ifndef CGAL_DRAW_POLYGON_WITH_HOLES_2_H #define CGAL_DRAW_POLYGON_WITH_HOLES_2_H -#include +#include #include #include #include @@ -31,8 +31,8 @@ namespace CGAL { opens a new window and draws a 2D polygon with holes. Parameters of the drawing are taken from the optional graphics scene options parameter. -A call to this function blocks the execution of the program until the drawing window is closed. This function requires `CGAL_Qt6`, and is only available if the macro `CGAL_USE_BASIC_VIEWER` is defined. -Linking with the cmake target `CGAL::CGAL_Basic_viewer` will link with `CGAL_Qt6` and add the definition `CGAL_USE_BASIC_VIEWER`. +A call to this function blocks the execution of the program until the drawing window is closed. This function requires `CGAL_Qt6`, and is only available if the macro `CGAL_USE_BASIC_VIEWER`/`CGAL_USE_BASIC_VIEWER_QT` (Qt viewer) is defined. +Linking with the cmake target `CGAL::CGAL_Basic_viewer`/`CGAL::CGAL_Basic_viewer_Qt` will link with `CGAL_Qt6` and add the definition `CGAL_USE_BASIC_VIEWER`/`CGAL_USE_BASIC_VIEWER_QT`. \tparam PH which must be an instantiation of a `CGAL::Polygon_with_holes_2<...>`. \tparam GSOptions a model of `GraphicsSceneOptions` concept. @@ -212,8 +212,6 @@ void add_to_graphics_scene(const CGAL_P2_WITH_HOLES_TYPE& p2, add_to_graphics_scene(p2, graphics_scene, gs_options); } -#ifdef CGAL_USE_BASIC_VIEWER - // Specialization of draw function. template void draw(const CGAL_P2_WITH_HOLES_TYPE& ap2, const GSOptions &gs_options, @@ -233,8 +231,6 @@ void draw(const CGAL_P2_WITH_HOLES_TYPE& ap2, draw_graphics_scene(buffer, title); } -#endif // CGAL_USE_BASIC_VIEWER - #undef CGAL_P2_WITH_HOLES_TYPE } // End namespace CGAL diff --git a/Polyhedron/doc/Polyhedron/CGAL/draw_polyhedron.h b/Polyhedron/doc/Polyhedron/CGAL/draw_polyhedron.h index 7574329050e..ea701a78983 100644 --- a/Polyhedron/doc/Polyhedron/CGAL/draw_polyhedron.h +++ b/Polyhedron/doc/Polyhedron/CGAL/draw_polyhedron.h @@ -5,8 +5,8 @@ namespace CGAL { opens a new window and draws a polyhedron. Parameters of the drawing are taken from the optional graphics scene options parameter. -A call to this function blocks the execution of the program until the drawing window is closed. This function requires `CGAL_Qt6`, and is only available if the macro `CGAL_USE_BASIC_VIEWER` is defined. -Linking with the cmake target `CGAL::CGAL_Basic_viewer` will link with `CGAL_Qt6` and add the definition `CGAL_USE_BASIC_VIEWER`. +A call to this function blocks the execution of the program until the drawing window is closed. This function requires `CGAL_Qt6`, and is only available if the macro `CGAL_USE_BASIC_VIEWER`/`CGAL_USE_BASIC_VIEWER_QT` (Qt viewer) is defined. +Linking with the cmake target `CGAL::CGAL_Basic_viewer`/`CGAL::CGAL_Basic_viewer_Qt` will link with `CGAL_Qt6` and add the definition `CGAL_USE_BASIC_VIEWER`/`CGAL_USE_BASIC_VIEWER_QT`. \tparam P which must be an instantiation of a `CGAL::Polyhedron_3<...>`. \tparam GSOptions a model of `GraphicsSceneOptions` concept. diff --git a/Polyhedron/include/CGAL/draw_polyhedron.h b/Polyhedron/include/CGAL/draw_polyhedron.h index c45ea4e0dd4..357d5a509eb 100644 --- a/Polyhedron/include/CGAL/draw_polyhedron.h +++ b/Polyhedron/include/CGAL/draw_polyhedron.h @@ -18,7 +18,7 @@ #include #include #include -#include +#include namespace CGAL { @@ -48,7 +48,6 @@ void add_to_graphics_scene(const CGAL_POLY_TYPE& apoly, { add_to_graphics_scene_for_fg(apoly, graphics_scene); } // Specialization of draw function: require Qt and the CGAL basic viewer. -#ifdef CGAL_USE_BASIC_VIEWER template -#include +#include #include #include #include @@ -180,8 +180,6 @@ void add_to_graphics_scene(const CGAL_SS_TYPE& ass2, } // Specialization of draw function. -#ifdef CGAL_USE_BASIC_VIEWER - template void draw(const CGAL_SS_TYPE &ass2, const GSOptions &gs_options, const char *title="Straight Skeleton Basic Viewer") @@ -200,8 +198,6 @@ void draw(const CGAL_SS_TYPE &ass2, draw_graphics_scene(buffer, title); } -#endif // CGAL_USE_BASIC_VIEWER - #undef CGAL_SS_TYPE } // End namespace CGAL diff --git a/Surface_mesh/include/CGAL/draw_surface_mesh.h b/Surface_mesh/include/CGAL/draw_surface_mesh.h index 6814f43ab69..fdddb8b7dc0 100644 --- a/Surface_mesh/include/CGAL/draw_surface_mesh.h +++ b/Surface_mesh/include/CGAL/draw_surface_mesh.h @@ -20,8 +20,8 @@ opens a new window and draws a surface mesh. Parameters of the drawing are taken from the optional graphics scene options parameter. -A call to this function blocks the execution of the program until the drawing window is closed. This function requires `CGAL_Qt6`, and is only available if the macro `CGAL_USE_BASIC_VIEWER` is defined. -Linking with the cmake target `CGAL::CGAL_Basic_viewer` will link with `CGAL_Qt6` and add the definition `CGAL_USE_BASIC_VIEWER`. +A call to this function blocks the execution of the program until the drawing window is closed. This function requires `CGAL_Qt6`, and is only available if the macro `CGAL_USE_BASIC_VIEWER`/`CGAL_USE_BASIC_VIEWER_QT` (Qt viewer) is defined. +Linking with the cmake target `CGAL::CGAL_Basic_viewer`/`CGAL::CGAL_Basic_viewer_Qt` will link with `CGAL_Qt6` and add the definition `CGAL_USE_BASIC_VIEWER`/`CGAL_USE_BASIC_VIEWER_QT`. \tparam SM which must be an instantiation of a `CGAL::Surface_mesh<...>`. \tparam GSOptions a model of `GraphicsSceneOptions` concept. @@ -93,7 +93,7 @@ void add_to_graphics_scene(const SM& sm, #include #include #include -#include +#include namespace CGAL { @@ -164,8 +164,6 @@ void add_to_graphics_scene(const Surface_mesh& amesh, { add_to_graphics_scene_for_fg(amesh, graphics_scene, Graphics_scene_options_surface_mesh(amesh)); } -#ifdef CGAL_USE_BASIC_VIEWER - // Specialization of draw function. template void draw(const Surface_mesh& amesh, @@ -186,8 +184,6 @@ void draw(const Surface_mesh& amesh, draw_graphics_scene(buffer, title); } -#endif // CGAL_USE_BASIC_VIEWER - } // End namespace CGAL #endif // DOXYGEN_RUNNING diff --git a/Surface_mesh_topology/doc/Surface_mesh_topology/CGAL/draw_face_graph_with_paths.h b/Surface_mesh_topology/doc/Surface_mesh_topology/CGAL/draw_face_graph_with_paths.h index b09424dbecd..dc764f93211 100644 --- a/Surface_mesh_topology/doc/Surface_mesh_topology/CGAL/draw_face_graph_with_paths.h +++ b/Surface_mesh_topology/doc/Surface_mesh_topology/CGAL/draw_face_graph_with_paths.h @@ -5,8 +5,8 @@ namespace CGAL { opens a new window and draws `amesh`, either a 2D linear cell complex or a model of the FaceGraph concept, plus the paths lying on this mesh given in `apaths`. Parameters of the drawing are taken from the optional graphics scene options parameter. -A call to this function blocks the execution of the program until the drawing window is closed. This function requires `CGAL_Qt6`, and is only available if the macro `CGAL_USE_BASIC_VIEWER` is defined. -Linking with the cmake target `CGAL::CGAL_Basic_viewer` will link with `CGAL_Qt6` and add the definition `CGAL_USE_BASIC_VIEWER`. +A call to this function blocks the execution of the program until the drawing window is closed. This function requires `CGAL_Qt6`, and is only available if the macro `CGAL_USE_BASIC_VIEWER`/`CGAL_USE_BASIC_VIEWER_QT` (Qt viewer) is defined. +Linking with the cmake target `CGAL::CGAL_Basic_viewer`/`CGAL::CGAL_Basic_viewer_Qt` will link with `CGAL_Qt6` and add the definition `CGAL_USE_BASIC_VIEWER`/`CGAL_USE_BASIC_VIEWER_QT`. \tparam Mesh either a 2D linear cell complex or a model of the FaceGraph concept. \tparam GSOptions a model of `GraphicsSceneOptionsFaceGraphWithPaths` concept. diff --git a/Surface_mesh_topology/examples/Surface_mesh_topology/draw_facewidth.h b/Surface_mesh_topology/examples/Surface_mesh_topology/draw_facewidth.h index 5883d7d32d7..3b7cbdfc206 100644 --- a/Surface_mesh_topology/examples/Surface_mesh_topology/draw_facewidth.h +++ b/Surface_mesh_topology/examples/Surface_mesh_topology/draw_facewidth.h @@ -1,8 +1,6 @@ #ifndef DRAW_FACEWIDTH_H #define DRAW_FACEWIDTH_H -#ifdef CGAL_USE_BASIC_VIEWER - #include #include @@ -55,6 +53,4 @@ void draw_facewidth(const LCC& lcc, lcc.free_mark(face_mark); } -#endif // CGAL_USE_BASIC_VIEWER - #endif // DRAW_FACEWIDTH_H diff --git a/Surface_mesh_topology/include/CGAL/draw_face_graph_with_paths.h b/Surface_mesh_topology/include/CGAL/draw_face_graph_with_paths.h index c4aa3b41b05..637e934d2cb 100644 --- a/Surface_mesh_topology/include/CGAL/draw_face_graph_with_paths.h +++ b/Surface_mesh_topology/include/CGAL/draw_face_graph_with_paths.h @@ -386,8 +386,6 @@ void add_to_graphics_scene(const Mesh& mesh, add_to_graphics_scene(mesh, graphics_scene, paths, amark); } -#ifdef CGAL_USE_BASIC_VIEWER - template void draw(const Mesh& mesh, const std::vector >& paths, @@ -436,8 +434,6 @@ void draw(const Mesh& mesh, draw(mesh, paths, title, amark); } -#endif // CGAL_USE_BASIC_VIEWER - } // End namespace CGAL #endif // CGAL_DRAW_FACE_GRAPH_WITH_PATHS_H diff --git a/Triangulation_2/doc/Triangulation_2/CGAL/draw_constrained_triangulation_2.h b/Triangulation_2/doc/Triangulation_2/CGAL/draw_constrained_triangulation_2.h index 2519bcf65b2..3c6045e0d13 100644 --- a/Triangulation_2/doc/Triangulation_2/CGAL/draw_constrained_triangulation_2.h +++ b/Triangulation_2/doc/Triangulation_2/CGAL/draw_constrained_triangulation_2.h @@ -5,8 +5,8 @@ namespace CGAL { opens a new window and draws a constrained triangulation. If the triangulation has constraints they are drawn. The faces inside and outside of the domain, based on the property map, are drawn in different colors. -A call to this function blocks the execution of the program until the drawing window is closed. This function requires `CGAL_Qt6`, and is only available if the macro `CGAL_USE_BASIC_VIEWER` is defined. -Linking with the cmake target `CGAL::CGAL_Basic_viewer` will link with `CGAL_Qt6` and add the definition `CGAL_USE_BASIC_VIEWER`. +A call to this function blocks the execution of the program until the drawing window is closed. This function requires `CGAL_Qt6`, and is only available if the macro `CGAL_USE_BASIC_VIEWER`/`CGAL_USE_BASIC_VIEWER_QT` (Qt viewer) is defined. +Linking with the cmake target `CGAL::CGAL_Basic_viewer`/`CGAL::CGAL_Basic_viewer_Qt` will link with `CGAL_Qt6` and add the definition `CGAL_USE_BASIC_VIEWER`/`CGAL_USE_BASIC_VIEWER_QT`. \tparam CT2 which must be an instantiation of a `CGAL::Constrained_triangulation_2<...>`. \tparam InDomainPMap a class model of `ReadablePropertyMap` with `CT2::Face_handle` as key type and `bool` as value type. diff --git a/Triangulation_2/doc/Triangulation_2/CGAL/draw_triangulation_2.h b/Triangulation_2/doc/Triangulation_2/CGAL/draw_triangulation_2.h index 62dfbdf2854..4ea4f697330 100644 --- a/Triangulation_2/doc/Triangulation_2/CGAL/draw_triangulation_2.h +++ b/Triangulation_2/doc/Triangulation_2/CGAL/draw_triangulation_2.h @@ -5,8 +5,8 @@ namespace CGAL { opens a new window and draws a triangulation. Parameters of the drawing are taken from the optional graphics scene options parameter. -A call to this function blocks the execution of the program until the drawing window is closed. This function requires `CGAL_Qt6`, and is only available if the macro `CGAL_USE_BASIC_VIEWER` is defined. -Linking with the cmake target `CGAL::CGAL_Basic_viewer` will link with `CGAL_Qt6` and add the definition `CGAL_USE_BASIC_VIEWER`. +A call to this function blocks the execution of the program until the drawing window is closed. This function requires `CGAL_Qt6`, and is only available if the macro `CGAL_USE_BASIC_VIEWER`/`CGAL_USE_BASIC_VIEWER_QT` (Qt viewer) is defined. +Linking with the cmake target `CGAL::CGAL_Basic_viewer`/`CGAL::CGAL_Basic_viewer_Qt` will link with `CGAL_Qt6` and add the definition `CGAL_USE_BASIC_VIEWER`/`CGAL_USE_BASIC_VIEWER_QT`. \tparam T2 which must be an instantiation of a `CGAL::Triangulation_2<...>`. \tparam GSOptions a model of `GraphicsSceneOptions` concept. diff --git a/Triangulation_2/include/CGAL/draw_constrained_triangulation_2.h b/Triangulation_2/include/CGAL/draw_constrained_triangulation_2.h index 441ac7f3fcb..dbbb025c034 100644 --- a/Triangulation_2/include/CGAL/draw_constrained_triangulation_2.h +++ b/Triangulation_2/include/CGAL/draw_constrained_triangulation_2.h @@ -81,8 +81,6 @@ void add_to_graphics_scene(const CGAL_T2_TYPE& at2, draw_function_for_t2::compute_elements(at2, graphics_scene, gso); } -#ifdef CGAL_USE_BASIC_VIEWER - template void draw(const CGAL_T2_TYPE& at2, InDomainPmap ipm, const char *title="Constrained Triangulation_2 Basic Viewer") @@ -101,8 +99,6 @@ void draw(const CGAL_T2_TYPE& at2, draw_graphics_scene(buffer, title); } -#endif // CGAL_USE_BASIC_VIEWER - #undef CGAL_T2_TYPE } // End namespace CGAL diff --git a/Triangulation_2/include/CGAL/draw_triangulation_2.h b/Triangulation_2/include/CGAL/draw_triangulation_2.h index f91fa5b4aaa..b0c2b2be062 100644 --- a/Triangulation_2/include/CGAL/draw_triangulation_2.h +++ b/Triangulation_2/include/CGAL/draw_triangulation_2.h @@ -14,7 +14,7 @@ #define CGAL_DRAW_T2_H #include -#include +#include #include #include #include @@ -145,8 +145,6 @@ void add_to_graphics_scene(const CGAL_T2_TYPE& at2, add_to_graphics_scene(at2, graphics_scene, drawingFunctor); } -#ifdef CGAL_USE_BASIC_VIEWER - // Specialization of draw function. template void draw(const CGAL_T2_TYPE &at2, const GSOptions &gs_options, @@ -166,8 +164,6 @@ void draw(const CGAL_T2_TYPE& at2, draw_graphics_scene(buffer, title); } -#endif // CGAL_USE_BASIC_VIEWER - #undef CGAL_T2_TYPE } // End namespace CGAL diff --git a/Triangulation_3/doc/Triangulation_3/CGAL/draw_triangulation_3.h b/Triangulation_3/doc/Triangulation_3/CGAL/draw_triangulation_3.h index dbb9119d83d..192ee8de4f1 100644 --- a/Triangulation_3/doc/Triangulation_3/CGAL/draw_triangulation_3.h +++ b/Triangulation_3/doc/Triangulation_3/CGAL/draw_triangulation_3.h @@ -5,8 +5,8 @@ namespace CGAL { opens a new window and draws a 3D triangulation. Parameters of the drawing are taken from the optional graphics scene options parameter. -A call to this function blocks the execution of the program until the drawing window is closed. This function requires `CGAL_Qt6`, and is only available if the macro `CGAL_USE_BASIC_VIEWER` is defined. -Linking with the cmake target `CGAL::CGAL_Basic_viewer` will link with `CGAL_Qt6` and add the definition `CGAL_USE_BASIC_VIEWER`. +A call to this function blocks the execution of the program until the drawing window is closed. This function requires `CGAL_Qt6`, and is only available if the macro `CGAL_USE_BASIC_VIEWER`/`CGAL_USE_BASIC_VIEWER_QT` (Qt viewer) is defined. +Linking with the cmake target `CGAL::CGAL_Basic_viewer`/`CGAL::CGAL_Basic_viewer_Qt` will link with `CGAL_Qt6` and add the definition `CGAL_USE_BASIC_VIEWER`/`CGAL_USE_BASIC_VIEWER_QT`. \tparam T3 which must be an instantiation of a `CGAL::Triangulation_3<...>`. \tparam GSOptions a model of `GraphicsSceneOptions` concept. diff --git a/Triangulation_3/include/CGAL/draw_triangulation_3.h b/Triangulation_3/include/CGAL/draw_triangulation_3.h index 376b73b8c53..7720555233e 100644 --- a/Triangulation_3/include/CGAL/draw_triangulation_3.h +++ b/Triangulation_3/include/CGAL/draw_triangulation_3.h @@ -14,7 +14,7 @@ #define CGAL_DRAW_T3_H #include -#include +#include #include #include #include @@ -154,8 +154,6 @@ void add_to_graphics_scene(const CGAL_T3_TYPE& at3, add_to_graphics_scene(at3, graphics_scene, gs_options); } -#ifdef CGAL_USE_BASIC_VIEWER - // Specialization of draw function. template void draw(const CGAL_T3_TYPE &at3, const GSOptions &gs_options, @@ -174,8 +172,6 @@ void draw(const CGAL_T3_TYPE &at3, const char *title="T3 Basic Viewer") draw_graphics_scene(buffer, title); } -#endif // CGAL_USE_BASIC_VIEWER - #undef CGAL_T3_TYPE } // End namespace CGAL diff --git a/Voronoi_diagram_2/doc/Voronoi_diagram_2/CGAL/draw_voronoi_diagram_2.h b/Voronoi_diagram_2/doc/Voronoi_diagram_2/CGAL/draw_voronoi_diagram_2.h index baed577bb1a..6ef047520ec 100644 --- a/Voronoi_diagram_2/doc/Voronoi_diagram_2/CGAL/draw_voronoi_diagram_2.h +++ b/Voronoi_diagram_2/doc/Voronoi_diagram_2/CGAL/draw_voronoi_diagram_2.h @@ -27,8 +27,8 @@ struct Graphics_scene_options_voronoi_diagram_2: public CGAL::Graphics_scene_opt opens a new window and draws a 2D voronoi diagram. Parameters of the drawing are taken from the optional graphics scene options parameter. -A call to this function blocks the execution of the program until the drawing window is closed. This function requires `CGAL_Qt6`, and is only available if the macro `CGAL_USE_BASIC_VIEWER` is defined. -Linking with the cmake target `CGAL::CGAL_Basic_viewer` will link with `CGAL_Qt6` and add the definition `CGAL_USE_BASIC_VIEWER`. +A call to this function blocks the execution of the program until the drawing window is closed. This function requires `CGAL_Qt6`, and is only available if the macro `CGAL_USE_BASIC_VIEWER`/`CGAL_USE_BASIC_VIEWER_QT` (Qt viewer) is defined. +Linking with the cmake target `CGAL::CGAL_Basic_viewer`/`CGAL::CGAL_Basic_viewer_Qt` will link with `CGAL_Qt6` and add the definition `CGAL_USE_BASIC_VIEWER`/`CGAL_USE_BASIC_VIEWER_QT`. \tparam VD2 which must be an instantiation of a `CGAL::Voronoi_diagram_2<...>`. \tparam GSOptions a model of `GraphicsSceneOptionsVoronoiDiagram2` concept. diff --git a/Voronoi_diagram_2/include/CGAL/draw_voronoi_diagram_2.h b/Voronoi_diagram_2/include/CGAL/draw_voronoi_diagram_2.h index d5efc0c0a30..deb38a94de8 100644 --- a/Voronoi_diagram_2/include/CGAL/draw_voronoi_diagram_2.h +++ b/Voronoi_diagram_2/include/CGAL/draw_voronoi_diagram_2.h @@ -14,7 +14,7 @@ #define CGAL_DRAW_VORONOI_DIAGRAM_2_H #include -#include +#include #include #include #include @@ -371,7 +371,7 @@ void add_to_graphics_scene(const CGAL_VORONOI_TYPE& v2, add_to_graphics_scene(v2, graphics_scene, gs_options); } -#ifdef CGAL_USE_BASIC_VIEWER +#if defined(CGAL_USE_BASIC_VIEWER) || defined(CGAL_USE_BASIC_VIEWER_QT) // Specialization of draw function. template @@ -449,7 +449,7 @@ void draw(const CGAL_VORONOI_TYPE& av2, draw(av2, gs_options, title); } -#endif // CGAL_USE_BASIC_VIEWER +#endif // CGAL_USE_BASIC_VIEWER || CGAL_USE_BASIC_VIEWER_QT #undef CGAL_VORONOI_TYPE