GNU Octave 10.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 
Loading...
Searching...
No Matches
gl-render.h
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 2008-2025 The Octave Project Developers
4//
5// See the file COPYRIGHT.md in the top-level directory of this
6// distribution or <https://octave.org/copyright/>.
7//
8// This file is part of Octave.
9//
10// Octave is free software: you can redistribute it and/or modify it
11// under the terms of the GNU General Public License as published by
12// the Free Software Foundation, either version 3 of the License, or
13// (at your option) any later version.
14//
15// Octave is distributed in the hope that it will be useful, but
16// WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18// GNU General Public License for more details.
19//
20// You should have received a copy of the GNU General Public License
21// along with Octave; see the file COPYING. If not, see
22// <https://www.gnu.org/licenses/>.
23//
24////////////////////////////////////////////////////////////////////////
25
26#if ! defined (octave_gl_render_h)
27#define octave_gl_render_h 1
28
29#include "octave-config.h"
30
31#include "graphics.h"
32#include "text-renderer.h"
33
35
37
38class OCTINTERP_API opengl_renderer
39{
40public:
41
43
44 OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (opengl_renderer)
45
46 virtual ~opengl_renderer () = default;
47
48 opengl_functions& get_opengl_functions () const { return m_glfcns; }
49
50 virtual void draw (const graphics_object& go, bool toplevel = true);
51
52 // The following version of the draw method is not declared virtual
53 // because no derived class overrides it.
54
55 void draw (const Matrix& hlist, bool toplevel = false);
56
57 virtual void set_viewport (int w, int h);
58 virtual void set_device_pixel_ratio (double dpr) { m_devpixratio = dpr; }
59 virtual Matrix get_viewport_scaled () const;
60 virtual graphics_xform get_transform () const { return m_xform; }
61 virtual uint8NDArray get_pixels (int width, int height);
62
63 virtual void draw_zoom_box (int width, int height,
64 int x1, int y1, int x2, int y2,
65 const Matrix& overlaycolor,
66 double overlayalpha,
67 const Matrix& bordercolor,
68 double borderalpha, double borderwidth);
69
70 virtual void finish ();
71
72protected:
73
74 virtual void draw_figure (const figure::properties& props);
75 virtual void draw_axes (const axes::properties& props);
76 virtual void draw_line (const line::properties& props);
77 virtual void draw_surface (const surface::properties& props);
78 virtual void draw_patch (const patch::properties& props);
79 virtual void draw_scatter (const scatter::properties& props);
80 virtual void draw_light (const light::properties& props);
81 virtual void draw_hggroup (const hggroup::properties& props);
82 virtual void draw_text (const text::properties& props);
83 virtual void draw_text_background (const text::properties& props,
84 bool do_rotate = false);
85 virtual void draw_image (const image::properties& props);
86 virtual void draw_uipanel (const uipanel::properties& props,
87 const graphics_object& go);
88 virtual void draw_uibuttongroup (const uibuttongroup::properties& props,
89 const graphics_object& go);
90 virtual void init_gl_context (bool enhanced, const Matrix& backgroundColor);
91 virtual void setup_opengl_transformation (const axes::properties& props);
92
93 virtual void set_clipbox (double x1, double x2, double y1, double y2,
94 double z1, double z2);
95 virtual void set_clipping (bool on);
96 virtual void set_font (const base_properties& props);
97 virtual void set_color (const Matrix& c);
98 virtual void set_interpreter (const caseless_str& interp)
99 {
100 m_interpreter = interp;
101 }
102 virtual void set_linewidth (float w);
103 virtual void set_linestyle (const std::string& s, bool stipple = false,
104 double linewidth = 0.5);
105 virtual void set_linecap (const std::string&) { };
106 virtual void set_linejoin (const std::string&) { };
107 virtual void set_polygon_offset (bool on, float offset = 0.0f);
108 virtual void set_selecting (bool on)
109 {
110 m_selecting = on;
111 }
112
113 virtual void init_marker (const std::string& m, double size, float width);
114 virtual void change_marker (const std::string& m, double size);
115 virtual void end_marker ();
116 virtual void draw_marker (double x, double y, double z,
117 const Matrix& lc, const Matrix& fc,
118 const double la = 1.0, const double fa = 1.0);
119
120 virtual void text_to_pixels (const std::string& txt,
121 uint8NDArray& pixels,
122 Matrix& bbox,
123 int halign = 0, int valign = 0,
124 double rotation = 0.0);
125
126 virtual void text_to_strlist (const std::string& txt,
127 std::list<text_renderer::string>& lst,
128 Matrix& bbox,
129 int halign = 0, int valign = 0,
130 double rotation = 0.0);
131
132 virtual Matrix render_text (const std::string& txt,
133 double x, double y, double z,
134 int halign, int valign, double rotation = 0.0);
135
136 virtual void render_grid (const double linewidth,
137 const std::string& gridstyle,
138 const Matrix& gridcolor, const double gridalpha,
139 const Matrix& ticks, double lim1, double lim2,
140 double p1, double p1N, double p2, double p2N,
141 int xyz, bool is_3D);
142
143 virtual void render_tickmarks (const Matrix& ticks,
144 double lim1, double lim2,
145 double p1, double p1N, double p2, double p2N,
146 double dx, double dy, double dz,
147 int xyz, bool doubleside, bool tickdir_both);
148
149 virtual void render_ticktexts (const Matrix& ticks,
150 const string_vector& ticklabels,
151 double lim1, double lim2,
152 double p1, double p2,
153 int xyz, int ha, int va,
154 int& wmax, int& hmax);
155
156 virtual void draw_zoom_rect (int x1, int y1, int x2, int y2);
157
158 //--------
159
161
162 // axis limits in model scaled coordinate
163 double m_xmin, m_xmax;
164 double m_ymin, m_ymax;
165 double m_zmin, m_zmax;
166
167 // Factor used for translating Octave pixels to actual device pixels
169
170 // axes transformation data
171 graphics_xform m_xform;
172
173private:
174
175 class patch_tessellator;
176
177 void init_maxlights ();
178
179 std::string get_string (unsigned int id) const;
180
181 bool is_nan_or_inf (double x, double y, double z) const
182 {
183 return (math::isnan (x) || math::isnan (y)
184 || math::isnan (z)
185 || math::isinf (x) || math::isinf (y)
186 || math::isinf (z));
187 }
188
189 uint8_t clip_code (double x, double y, double z) const
190 {
191 return ((x < m_xmin ? 1 : 0)
192 | (x > m_xmax ? 1 : 0) << 1
193 | (y < m_ymin ? 1 : 0) << 2
194 | (y > m_ymax ? 1 : 0) << 3
195 | (z < m_zmin ? 1 : 0) << 4
196 | (z > m_zmax ? 1 : 0) << 5
197 | (is_nan_or_inf (x, y, z) ? 0 : 1) << 6);
198 }
199
200 void render_text (uint8NDArray pixels, Matrix bbox,
201 double x, double y, double z, double rotation);
202
203 void set_normal (int bfl_mode, const NDArray& n, int j, int i);
204
205 void set_ortho_coordinates ();
206
207 void restore_previous_coordinates ();
208
209 double points_to_pixels (const double val) const;
210
211 unsigned int make_marker_list (const std::string& m, double size,
212 bool filled) const;
213
214 void draw_axes_planes (const axes::properties& props);
215 void draw_axes_boxes (const axes::properties& props);
216
217 void draw_axes_grids (const axes::properties& props);
218 void draw_axes_x_grid (const axes::properties& props);
219 void draw_axes_y_grid (const axes::properties& props);
220 void draw_axes_z_grid (const axes::properties& props);
221
222 void draw_axes_children (const axes::properties& props);
223
224 void draw_all_lights (const base_properties& props,
225 std::list<graphics_object>& obj_list);
226
227 void draw_texture_image (const octave_value cdata,
228 Matrix x, Matrix y, bool ortho = false);
229
230 //--------
231
232 // The graphics m_toolkit associated with the figure being rendered.
233 graphics_toolkit m_toolkit;
234
235 // Z projection limits in windows coordinate
236 double m_xZ1, m_xZ2;
237
238 // call lists identifiers for markers
239 unsigned int m_marker_id, m_filled_marker_id;
240
241 // camera information for primitive sorting and lighting
242 ColumnVector m_camera_pos, m_camera_dir, m_view_vector;
243
244 // interpreter to be used by text_to_pixels
245 caseless_str m_interpreter;
246
247 text_renderer m_txt_renderer;
248
249 // light object present and visible
250 unsigned int m_current_light;
251 unsigned int m_max_lights;
252
253 // Indicate we are drawing for selection purpose
254 bool m_selecting;
255
256 // Indicate we are drawing for printing purpose
257 bool m_printing;
258};
259
260OCTAVE_END_NAMESPACE(octave)
261
262#endif
opengl_functions & m_glfcns
Definition gl-render.h:160
double m_devpixratio
Definition gl-render.h:168
virtual void set_interpreter(const caseless_str &interp)
Definition gl-render.h:98
graphics_xform m_xform
Definition gl-render.h:171
virtual void set_selecting(bool on)
Definition gl-render.h:108
virtual graphics_xform get_transform() const
Definition gl-render.h:60
virtual void set_linecap(const std::string &)
Definition gl-render.h:105
virtual void set_device_pixel_ratio(double dpr)
Definition gl-render.h:58
virtual void set_linejoin(const std::string &)
Definition gl-render.h:106
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
F77_RET_T const F77_DBLE * x
void draw(QDomElement &parent_elt, pdfpainter &painter)