GNU Octave 7.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
gl-render.h
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 2008-2022 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
34namespace octave
35{
36 class opengl_functions;
37
38 class
39 OCTINTERP_API
41 {
42 public:
43
45
46 // No copying!
47
49
50 opengl_renderer& operator = (const opengl_renderer&) = delete;
51
52 virtual ~opengl_renderer (void) = default;
53
54 opengl_functions& get_opengl_functions (void) const { return m_glfcns; }
55
56 virtual void draw (const graphics_object& go, bool toplevel = true);
57
58 // The following version of the draw method is not declared virtual
59 // because no derived class overrides it.
60
61 void draw (const Matrix& hlist, bool toplevel = false);
62
63 virtual void set_viewport (int w, int h);
64 virtual void set_device_pixel_ratio (double dpr) { m_devpixratio = dpr; }
65 virtual Matrix get_viewport_scaled (void) const;
66 virtual graphics_xform get_transform (void) const { return m_xform; }
67 virtual uint8NDArray get_pixels (int width, int height);
68
69 virtual void draw_zoom_box (int width, int height,
70 int x1, int y1, int x2, int y2,
71 const Matrix& overlaycolor,
72 double overlayalpha,
73 const Matrix& bordercolor,
74 double borderalpha, double borderwidth);
75
76 virtual void finish (void);
77
78 protected:
79
80 virtual void draw_figure (const figure::properties& props);
81 virtual void draw_axes (const axes::properties& props);
82 virtual void draw_line (const line::properties& props);
83 virtual void draw_surface (const surface::properties& props);
84 virtual void draw_patch (const patch::properties& props);
85 virtual void draw_scatter (const scatter::properties& props);
86 virtual void draw_light (const light::properties& props);
87 virtual void draw_hggroup (const hggroup::properties& props);
88 virtual void draw_text (const text::properties& props);
89 virtual void draw_text_background (const text::properties& props,
90 bool do_rotate = false);
91 virtual void draw_image (const image::properties& props);
92 virtual void draw_uipanel (const uipanel::properties& props,
93 const graphics_object& go);
94 virtual void draw_uibuttongroup (const uibuttongroup::properties& props,
95 const graphics_object& go);
96 virtual void init_gl_context (bool enhanced, const Matrix& backgroundColor);
97 virtual void setup_opengl_transformation (const axes::properties& props);
98
99 virtual void set_clipbox (double x1, double x2, double y1, double y2,
100 double z1, double z2);
101 virtual void set_clipping (bool on);
102 virtual void set_font (const base_properties& props);
103 virtual void set_color (const Matrix& c);
104 virtual void set_interpreter (const caseless_str& interp)
105 {
106 m_interpreter = interp;
107 }
108 virtual void set_linewidth (float w);
109 virtual void set_linestyle (const std::string& s, bool stipple = false,
110 double linewidth = 0.5);
111 virtual void set_linecap (const std::string&) { };
112 virtual void set_linejoin (const std::string&) { };
113 virtual void set_polygon_offset (bool on, float offset = 0.0f);
114 virtual void set_selecting (bool on)
115 {
116 m_selecting = on;
117 }
118
119 virtual void init_marker (const std::string& m, double size, float width);
120 virtual void change_marker (const std::string& m, double size);
121 virtual void end_marker (void);
122 virtual void draw_marker (double x, double y, double z,
123 const Matrix& lc, const Matrix& fc,
124 const double la = 1.0, const double fa = 1.0);
125
126 virtual void text_to_pixels (const std::string& txt,
127 uint8NDArray& pixels,
128 Matrix& bbox,
129 int halign = 0, int valign = 0,
130 double rotation = 0.0);
131
132 virtual void text_to_strlist (const std::string& txt,
133 std::list<text_renderer::string>& lst,
134 Matrix& bbox,
135 int halign = 0, int valign = 0,
136 double rotation = 0.0);
137
138 virtual Matrix render_text (const std::string& txt,
139 double x, double y, double z,
140 int halign, int valign, double rotation = 0.0);
141
142 virtual void render_grid (const double linewidth,
143 const std::string& gridstyle,
144 const Matrix& gridcolor, const double gridalpha,
145 const Matrix& ticks, double lim1, double lim2,
146 double p1, double p1N, double p2, double p2N,
147 int xyz, bool is_3D);
148
149 virtual void render_tickmarks (const Matrix& ticks, double lim1, double lim2,
150 double p1, double p1N, double p2, double p2N,
151 double dx, double dy, double dz,
152 int xyz, bool doubleside);
153
154 virtual void render_ticktexts (const Matrix& ticks,
155 const string_vector& ticklabels,
156 double lim1, double lim2,
157 double p1, double p2,
158 int xyz, int ha, int va,
159 int& wmax, int& hmax);
160
161 virtual void draw_zoom_rect (int x1, int y1, int x2, int y2);
162
163 //--------
164
166
167 // axis limits in model scaled coordinate
168 double m_xmin, m_xmax;
169 double m_ymin, m_ymax;
170 double m_zmin, m_zmax;
171
172 // Factor used for translating Octave pixels to actual device pixels
174
175 // axes transformation data
176 graphics_xform m_xform;
177
178 private:
179
180 class patch_tessellator;
181
182 void init_maxlights (void);
183
184 std::string get_string (unsigned int id) const;
185
186 bool is_nan_or_inf (double x, double y, double z) const
187 {
188 return (math::isnan (x) || math::isnan (y)
189 || math::isnan (z)
190 || math::isinf (x) || math::isinf (y)
191 || math::isinf (z));
192 }
193
194 uint8_t clip_code (double x, double y, double z) const
195 {
196 return ((x < m_xmin ? 1 : 0)
197 | (x > m_xmax ? 1 : 0) << 1
198 | (y < m_ymin ? 1 : 0) << 2
199 | (y > m_ymax ? 1 : 0) << 3
200 | (z < m_zmin ? 1 : 0) << 4
201 | (z > m_zmax ? 1 : 0) << 5
202 | (is_nan_or_inf (x, y, z) ? 0 : 1) << 6);
203 }
204
205 void render_text (uint8NDArray pixels, Matrix bbox,
206 double x, double y, double z, double rotation);
207
208 void set_normal (int bfl_mode, const NDArray& n, int j, int i);
209
210 void set_ortho_coordinates (void);
211
212 void restore_previous_coordinates (void);
213
214 double points_to_pixels (const double val) const;
215
216 unsigned int make_marker_list (const std::string& m, double size,
217 bool filled) const;
218
219 void draw_axes_planes (const axes::properties& props);
220 void draw_axes_boxes (const axes::properties& props);
221
222 void draw_axes_grids (const axes::properties& props);
223 void draw_axes_x_grid (const axes::properties& props);
224 void draw_axes_y_grid (const axes::properties& props);
225 void draw_axes_z_grid (const axes::properties& props);
226
227 void draw_axes_children (const axes::properties& props);
228
229 void draw_all_lights (const base_properties& props,
230 std::list<graphics_object>& obj_list);
231
232 void draw_texture_image (const octave_value cdata,
233 Matrix x, Matrix y, bool ortho = false);
234
235 //--------
236
237 // The graphics m_toolkit associated with the figure being rendered.
239
240 // Z projection limits in windows coordinate
241 double m_xZ1, m_xZ2;
242
243 // call lists identifiers for markers
244 unsigned int m_marker_id, m_filled_marker_id;
245
246 // camera information for primitive sorting and lighting
247 ColumnVector m_camera_pos, m_camera_dir, m_view_vector;
248
249 // interpreter to be used by text_to_pixels
251
253
254 // light object present and visible
255 unsigned int m_current_light;
256 unsigned int m_max_lights;
257
258 // Indicate we are drawing for selection purpose
260
261 // Indicate we are drawing for printing purpose
263 };
264}
265
266#endif
Definition: dMatrix.h:42
virtual void set_interpreter(const caseless_str &interp)
Definition: gl-render.h:104
bool is_nan_or_inf(double x, double y, double z) const
Definition: gl-render.h:186
unsigned int m_filled_marker_id
Definition: gl-render.h:244
opengl_functions & m_glfcns
Definition: gl-render.h:165
unsigned int m_max_lights
Definition: gl-render.h:256
virtual void set_linejoin(const std::string &)
Definition: gl-render.h:112
unsigned int m_current_light
Definition: gl-render.h:255
graphics_xform m_xform
Definition: gl-render.h:176
ColumnVector m_camera_dir
Definition: gl-render.h:247
virtual graphics_xform get_transform(void) const
Definition: gl-render.h:66
virtual ~opengl_renderer(void)=default
uint8_t clip_code(double x, double y, double z) const
Definition: gl-render.h:194
text_renderer m_txt_renderer
Definition: gl-render.h:252
graphics_toolkit m_toolkit
Definition: gl-render.h:238
virtual void set_device_pixel_ratio(double dpr)
Definition: gl-render.h:64
virtual void set_linecap(const std::string &)
Definition: gl-render.h:111
virtual void set_selecting(bool on)
Definition: gl-render.h:114
opengl_functions & get_opengl_functions(void) const
Definition: gl-render.h:54
opengl_renderer(const opengl_renderer &)=delete
caseless_str m_interpreter
Definition: gl-render.h:250
F77_RET_T const F77_DBLE * x
std::complex< double > w(std::complex< double > z, double relerr=0)
T::properties & properties(graphics_object obj)
bool isnan(bool)
Definition: lo-mappers.h:178
bool isinf(double x)
Definition: lo-mappers.h:203
static bool is_nan_or_inf(const octave_value &val)
Definition: oct-stream.cc:5695
void draw(QDomElement &parent_elt, pdfpainter &painter)