Skip to content

Commit 88b0438

Browse files
authored
Basic viewer improvements (#8850)
_Please use the following template to help us managing pull requests._ ## Summary of Changes Some improvements to the basic viewer. Following the GSOC 2024 project, see PR #8444, extract all the modifications that concern the current basic_viewer qt (and keep in the original PR the new basic viewer glfw that could be considered later). ## Changes to the documentation - in `Graphics_scene`, functions to set/get default colors: [diff](https://github.com/CGAL/cgal/pull/8850/files#diff-74c5383fef398c7cb3dbfaa8cbc836dbc5a3ad0a7b450442948e7e32d54ced47), and [documentation](https://cgal.github.io/8850/doc/Basic_viewer/classCGAL_1_1Graphics__scene.html) - in `Basic_viewer`, same functions, plus functions for sizes: [diff](https://github.com/CGAL/cgal/pull/8850/files#diff-cc9bfe7d72d61000248f90b7648c07decb71fd8a400ca54e3ecc8c808b0f70fa), and [documentation](https://cgal.github.io/8850/doc/Basic_viewer/classCGAL_1_1Qt_1_1Basic__viewer.html). ## Release Management * Affected package(s): Basic_viewer
2 parents 59921c1 + 010adcc commit 88b0438

File tree

36 files changed

+2024
-965
lines changed

36 files changed

+2024
-965
lines changed

Arrangement_on_surface_2/doc/Arrangement_on_surface_2/CGAL/draw_arrangement_2.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ namespace CGAL {
3131
*
3232
* A call to this function blocks the execution of the program until the drawing
3333
* window is closed. This function requires `CGAL_Qt6`, and is only available if
34-
* the macro `CGAL_USE_BASIC_VIEWER` is defined. Linking with the cmake target
34+
* the macro `CGAL_USE_BASIC_VIEWER` is defined. Linking with the cmake target
3535
* `CGAL::CGAL_Basic_viewer` will link with `CGAL_Qt6` and add the definition
3636
* `CGAL_USE_BASIC_VIEWER`.
3737
*

Arrangement_on_surface_2/include/CGAL/draw_arrangement_2.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include <cstdlib>
2626
#include <random>
2727

28-
#include <CGAL/Qt/Basic_viewer.h>
28+
#include <CGAL/Basic_viewer.h>
2929
#include <CGAL/Graphics_scene.h>
3030
#include <CGAL/Graphics_scene_options.h>
3131
#include <CGAL/Random.h>
@@ -587,8 +587,6 @@ void add_to_graphics_scene(const CGAL_ARR_TYPE& aos,
587587
add_to_graphics_scene(aos, graphics_scene, gso);
588588
}
589589

590-
#ifdef CGAL_USE_BASIC_VIEWER
591-
592590
/// Draw an arrangement on surface.
593591
template <typename GeometryTraits_2, typename TopologyTraits, class GSOptions>
594592
void draw(const CGAL_ARR_TYPE& aos, const GSOptions& gso,
@@ -609,8 +607,6 @@ void draw(const CGAL_ARR_TYPE& aos,
609607
draw_graphics_scene(graphics_scene, title);
610608
}
611609

612-
#endif // CGAL_USE_BASIC_VIEWER
613-
614610
#undef CGAL_ARR_TYPE
615611

616612
} // namespace CGAL

Basic_viewer/doc/Basic_viewer/Basic_viewer.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ Example of drawing of a point cloud and a polyhedron in a same viewer.
131131
\cgalFigureEnd
132132

133133
<!-- /////////////////////////////////////////////////////////////////////////////// -->
134-
\section BV_BasicViewer The Basic Viewer Class
134+
\section BV_BasicViewer The Qt Basic Viewer Class
135135

136136
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.
137137

Basic_viewer/doc/Basic_viewer/CGAL/Graphics_scene.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,36 @@ class Graphics_scene {
102102

103103
/// returns `true` if the scene is in 2D, i.e., lies on the XY or XZ or YZ plane.
104104
bool is_two_dimensional() const;
105+
106+
/// set the default color of faces
107+
void set_default_color_face(const CGAL::IO::Color& c);
108+
109+
/// set the default color of points
110+
void set_default_color_point(const CGAL::IO::Color& c);
111+
112+
/// set the default color of segments
113+
void set_default_color_segment(const CGAL::IO::Color& c);
114+
115+
/// set the default color of rays
116+
void set_default_color_ray(const CGAL::IO::Color& c);
117+
118+
/// set the default color of lines
119+
void set_default_color_line(const CGAL::IO::Color& c);
120+
121+
/// returns the default color of faces
122+
const CGAL::IO::Color &get_default_color_face() const;
123+
124+
/// returns the default color of points
125+
const CGAL::IO::Color &get_default_color_point() const;
126+
127+
/// returns the default color of segments
128+
const CGAL::IO::Color &get_default_color_segment() const;
129+
130+
/// returns the default color of rays
131+
const CGAL::IO::Color &get_default_color_ray() const;
132+
133+
/// returns the default color of lines
134+
const CGAL::IO::Color &get_default_color_line() const;
105135
};
106136

107137
} // namespace CGAL

Basic_viewer/doc/Basic_viewer/CGAL/Qt/Basic_viewer.h

Lines changed: 118 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -12,126 +12,189 @@ CGAL::QGLViewer is our internal fork of <a href="https://github.com/GillesDebunn
1212
class Basic_viewer : public CGAL::QGLViewer
1313
{
1414
public:
15+
/// \name Constructors
16+
/// @{
17+
1518
/// Constructor given a pointer on a `QWidget` (can be a `nullptr`) and a `Graphics_scene`.
1619
/// `title` will be the title of the window.
1720
Basic_viewer(QWidget* parent,
1821
const Graphics_scene& scene,
1922
const char* title="");
2023

21-
/// enables or disables the drawing of vertices.
24+
/// @}
25+
26+
/// \name Setters
27+
/// @{
28+
29+
/// \brief Set size of vertices.
30+
/// \param s The size of vertices.
31+
void size_vertices(float s);
32+
33+
/// \brief Set size of edges.
34+
/// \param s The size of edges.
35+
void size_edges(float s);
36+
37+
/// \brief Set size of rays.
38+
/// \param s The size of rays.
39+
void size_rays(float s);
40+
41+
/// \brief Set size of lines.
42+
/// \param s The size of lines.
43+
void size_lines(float s);
44+
45+
/// \brief Enables or disables the drawing of vertices.
46+
/// \param b Set to `true` to enable, `false` to disable.
2247
void draw_vertices(bool b);
2348

24-
/// enables or disables the drawing of edges.
49+
/// \brief Enables or disables the drawing of edges.
50+
/// \param b Set to `true` to enable, `false` to disable.
2551
void draw_edges(bool b);
2652

27-
/// enables or disables the drawing of rays.
53+
/// \brief Enables or disables the drawing of rays.
54+
/// \param b Set to `true` to enable, `false` to disable.
2855
void draw_rays(bool b);
2956

30-
/// enables or disables the drawing of lines.
57+
/// \brief Enables or disables the drawing of lines.
58+
/// \param b Set to `true` to enable, `false` to disable.
3159
void draw_lines(bool b);
3260

33-
/// enables or disables the drawing of faces.
61+
/// \brief enables or disables the drawing of faces.
62+
/// \param b Set to `true` to enable, `false` to disable.
3463
void draw_faces(bool b);
3564

36-
/// enables or disables the use of only one color (if `b` is `true`) or the use of multiple colors (if `b` is `false`).
37-
void use_mono_color(bool b);
38-
3965
/// enables or disables the drawing of texts.
66+
/// \brief enables or disables the drawing of texts.
67+
/// \param b Set to `true` to enable, `false` to disable.
4068
void draw_text(bool b);
4169

42-
/// sets the color used for vertices in mono color mode.
43-
void vertices_mono_color(const CGAL::IO::Color& c);
70+
/// \brief Enables or disables the drawing of mesh triangles.
71+
/// \param b Set to `true` to enable, `false` to disable.
72+
void draw_mesh_triangles(bool b);
73+
74+
/// \brief Enables or disables the use of only one color or the use of multiple colors.
75+
/// \param b Set to `true` to use only one color, `false` to use multiple colors.
76+
void use_default_color(bool b);
77+
78+
/// \brief Enables or disables the use of a single color for all normals.
79+
/// \param b Set to `true` to enable, `false` to disable.
80+
void use_default_color_normals(bool b);
4481

45-
/// sets the color used for edges in mono color mode.
46-
void edges_mono_color(const CGAL::IO::Color& c);
82+
/// \brief enables or disables the use of flat shading or the use of smooth shading.
83+
/// \param b Set to `true` for flat shading, `false` for smooth shading.
84+
void flat_shading(bool b);
4785

48-
/// sets the color used for rays in mono color mode.
49-
void rays_mono_color(const CGAL::IO::Color& c);
86+
/// \brief Enables or disables the reversal of normals.
87+
/// \param b Set to `true` to reverse normals, `false` to keep normals as is.
88+
void reverse_normal(bool b);
5089

51-
/// sets the color used for lines in mono color mode.
52-
void lines_mono_color(const CGAL::IO::Color& c);
90+
/// \brief Sets the default color of the normals.
91+
/// \param c The default color of the normals.
92+
void default_color_normals(const CGAL::IO::Color& c);
5393

54-
/// sets the color used for faces in mono color mode.
55-
void faces_mono_color(const CGAL::IO::Color& c);
94+
/// \brief Sets the height factor value of the normals.
95+
/// \param h The height factor value of the normals.
96+
void normal_height_factor(float h);
5697

57-
/// toggles the drawing of vertices.
98+
/// \brief Toggles the drawing of vertices.
5899
void toggle_draw_vertices();
59100

60-
/// toggles the drawing of edges.
101+
/// \brief Toggles the drawing of edges.
61102
void toggle_draw_edges();
62103

63-
/// toggles the drawing of rays.
104+
/// \brief Toggles the drawing of rays.
64105
void toggle_draw_rays();
65106

66-
/// toggles the drawing of lines.
107+
/// \brief Toggles the drawing of lines.
67108
void toggle_draw_lines();
68109

69-
/// toggles the drawing of faces.
110+
/// \brief Toggles the drawing of faces.
70111
void toggle_draw_faces();
71112

72-
/// toggles the use of mono color mode.
73-
void toggle_use_mono_color();
113+
/// \brief Toggles the use of mono color mode.
114+
void toggle_use_default_color();
74115

75-
/// toggles the drawing of text.
116+
/// \brief Toggles the use of the default color mode for normals.
117+
void toggle_use_default_color_normal();
118+
119+
/// \brief Toggles the use of flat shading.
120+
void toggle_flat_shading();
121+
122+
/// \brief Toggles the drawing of text.
76123
void toggle_draw_text();
77124

78-
/// returns `true` if vertices are drawn.
125+
/// \brief Reverses all normals of vertices and faces.
126+
void reverse_all_normals();
127+
128+
/// @}
129+
130+
/// \name Getters
131+
/// @{
132+
133+
/// \brief Checks if vertices are drawn.
134+
/// \return `true` if vertices are drawn, `false` otherwise.
79135
bool draw_vertices() const;
80136

81-
/// returns `true` if edges are drawn.
137+
/// \brief Checks if edges are drawn.
138+
/// \return `true` if edges are drawn, `false` otherwise.
82139
bool draw_edges() const;
83140

84-
/// returns `true` if rays are drawn.
141+
/// \brief Checks if rays are drawn.
142+
/// \return `true` if rays are drawn, `false` otherwise.
85143
bool draw_rays() const;
86144

87-
/// returns `true` if lines are drawn.
145+
/// \brief Checks if lines are drawn.
146+
/// \return `true` if lines are drawn, `false` otherwise.
88147
bool draw_lines() const;
89148

90-
/// returns `true` if faces are drawn.
149+
/// \brief Checks if faces are drawn.
150+
/// \return `true` if faces are drawn, `false` otherwise.
91151
bool draw_faces() const;
92152

93-
/// returns `true` if mono color mode is used.
94-
bool use_mono_color() const;
95-
96-
/// returns `true` if normals are reversed.
97-
bool reverse_normal() const;
98-
99-
/// returns `true` if text are drawn.
153+
/// \brief Checks if text is drawn.
154+
/// \return `true` if text is drawn, `false` otherwise.
100155
bool draw_text() const;
101156

102-
/// returns the mono color used for vertices.
103-
const CGAL::IO::Color& vertices_mono_color() const;
104-
105-
/// returns the mono color used for edges.
106-
const CGAL::IO::Color& edges_mono_color() const;
157+
/// \brief Checks if the default color mode is used.
158+
/// \return `true` if mono color mode is used, `false` otherwise.
159+
bool use_default_color() const;
107160

108-
/// returns the mono color used for rays.
109-
const CGAL::IO::Color& rays_mono_color() const;
161+
/// \brief Checks if the default color mode for normals is used.
162+
/// \return `true` if default color mode for normals is used, `false` otherwise.
163+
bool use_default_color_normal() const;
110164

111-
/// returns the mono color used for lines.
112-
const CGAL::IO::Color& lines_mono_color() const;
113-
114-
/// returns the mono color used for faces.
115-
const CGAL::IO::Color& faces_mono_color() const;
165+
/// \brief Checks if normals are reversed.
166+
/// \return `true` if normals are reversed, `false` otherwise.
167+
bool reverse_normal() const;
116168

117-
/// returns `true` if the clipping plane is enabled.
169+
/// \brief Checks if the clipping plane is enabled.
170+
/// \return `true` if the clipping plane is enabled, `false` otherwise.
118171
bool clipping_plane_enabled() const;
119172

120-
/// returns the clipping plane when it is enabled.
173+
/// \brief Checks if m_no_2D_mode is false and the graphics scene is two-dimensional.
174+
/// \return `true` if m_no_2D_mode is false and the scene is 2D, `false` otherwise.
175+
bool is_two_dimensional() const;
176+
177+
/// \brief Gets the clipping plane when enabled.
178+
/// \return The clipping plane as a `CGAL::Exact_predicates_inexact_constructions_kernel::Plane_3` object.
121179
CGAL::Exact_predicates_inexact_constructions_kernel::Plane_3 clipping_plane() const;
122180

123-
/// returns the graphics scene of the viewer.
181+
/// \brief Gets the graphics scene of the viewer.
182+
/// \return A reference to the `Graphics_scene` object.
124183
const Graphics_scene& graphics_scene() const;
125184

126-
/// reverses all normals of vertices and faces.
127-
void reverse_all_normals();
185+
/// @}
186+
187+
/// \name Draw
188+
/// @{
128189

129190
/// draws the viewer without recomputing all internal buffers.
130191
virtual void draw();
131192

132193
/// redraws the viewer, i.e., recompute all internal buffers and update the window.
133194
virtual void redraw();
134195

196+
/// @}
197+
135198
/// Function called when a key is pressed. Users can define their own function in order
136199
/// to add specific behavior.
137200
std::function<bool(QKeyEvent *, CGAL::Qt::Basic_viewer *)> on_key_pressed;

Basic_viewer/examples/Basic_viewer/draw_mesh_and_points.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include <CGAL/draw_polyhedron.h>
66
#include <CGAL/draw_point_set_3.h>
77
#include <CGAL/Graphics_scene_options.h>
8-
#include <CGAL/Qt/Basic_viewer.h>
8+
#include <CGAL/Basic_viewer.h>
99

1010
#include <vector>
1111
#include <iostream>

Basic_viewer/examples/Basic_viewer/draw_several_windows.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include <CGAL/draw_polyhedron.h>
66
#include <CGAL/draw_point_set_3.h>
77
#include <CGAL/Graphics_scene_options.h>
8-
#include <CGAL/Qt/Basic_viewer.h>
8+
#include <CGAL/Basic_viewer.h>
99

1010
#ifdef CGAL_USE_BASIC_VIEWER
1111
#include <QMainWindow>

0 commit comments

Comments
 (0)