GNU Octave  8.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-2023 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 
36 class opengl_functions;
37 
38 class
39 OCTINTERP_API
41 {
42 public:
43 
45 
46  // No copying!
47 
48  opengl_renderer (const opengl_renderer&) = delete;
49 
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,
150  double lim1, double lim2,
151  double p1, double p1N, double p2, double p2N,
152  double dx, double dy, double dz,
153  int xyz, bool doubleside);
154 
155  virtual void render_ticktexts (const Matrix& ticks,
156  const string_vector& ticklabels,
157  double lim1, double lim2,
158  double p1, double p2,
159  int xyz, int ha, int va,
160  int& wmax, int& hmax);
161 
162  virtual void draw_zoom_rect (int x1, int y1, int x2, int y2);
163 
164  //--------
165 
167 
168  // axis limits in model scaled coordinate
169  double m_xmin, m_xmax;
170  double m_ymin, m_ymax;
171  double m_zmin, m_zmax;
172 
173  // Factor used for translating Octave pixels to actual device pixels
175 
176  // axes transformation data
177  graphics_xform m_xform;
178 
179 private:
180 
181  class patch_tessellator;
182 
183  void init_maxlights (void);
184 
185  std::string get_string (unsigned int id) const;
186 
187  bool is_nan_or_inf (double x, double y, double z) const
188  {
189  return (math::isnan (x) || math::isnan (y)
190  || math::isnan (z)
191  || math::isinf (x) || math::isinf (y)
192  || math::isinf (z));
193  }
194 
195  uint8_t clip_code (double x, double y, double z) const
196  {
197  return ((x < m_xmin ? 1 : 0)
198  | (x > m_xmax ? 1 : 0) << 1
199  | (y < m_ymin ? 1 : 0) << 2
200  | (y > m_ymax ? 1 : 0) << 3
201  | (z < m_zmin ? 1 : 0) << 4
202  | (z > m_zmax ? 1 : 0) << 5
203  | (is_nan_or_inf (x, y, z) ? 0 : 1) << 6);
204  }
205 
206  void render_text (uint8NDArray pixels, Matrix bbox,
207  double x, double y, double z, double rotation);
208 
209  void set_normal (int bfl_mode, const NDArray& n, int j, int i);
210 
211  void set_ortho_coordinates (void);
212 
213  void restore_previous_coordinates (void);
214 
215  double points_to_pixels (const double val) const;
216 
217  unsigned int make_marker_list (const std::string& m, double size,
218  bool filled) const;
219 
220  void draw_axes_planes (const axes::properties& props);
221  void draw_axes_boxes (const axes::properties& props);
222 
223  void draw_axes_grids (const axes::properties& props);
224  void draw_axes_x_grid (const axes::properties& props);
225  void draw_axes_y_grid (const axes::properties& props);
226  void draw_axes_z_grid (const axes::properties& props);
227 
228  void draw_axes_children (const axes::properties& props);
229 
230  void draw_all_lights (const base_properties& props,
231  std::list<graphics_object>& obj_list);
232 
233  void draw_texture_image (const octave_value cdata,
234  Matrix x, Matrix y, bool ortho = false);
235 
236  //--------
237 
238  // The graphics m_toolkit associated with the figure being rendered.
240 
241  // Z projection limits in windows coordinate
242  double m_xZ1, m_xZ2;
243 
244  // call lists identifiers for markers
245  unsigned int m_marker_id, m_filled_marker_id;
246 
247  // camera information for primitive sorting and lighting
248  ColumnVector m_camera_pos, m_camera_dir, m_view_vector;
249 
250  // interpreter to be used by text_to_pixels
252 
254 
255  // light object present and visible
256  unsigned int m_current_light;
257  unsigned int m_max_lights;
258 
259  // Indicate we are drawing for selection purpose
261 
262  // Indicate we are drawing for printing purpose
264 };
265 
267 
268 #endif
OCTAVE_END_NAMESPACE(octave)
Definition: dMatrix.h:42
opengl_functions & operator=(const opengl_functions &)=default
virtual graphics_xform get_transform(void) const
Definition: gl-render.h:66
virtual ~opengl_renderer(void)=default
opengl_functions & m_glfcns
Definition: gl-render.h:166
double m_devpixratio
Definition: gl-render.h:174
caseless_str m_interpreter
Definition: gl-render.h:251
ColumnVector m_camera_dir
Definition: gl-render.h:248
unsigned int m_current_light
Definition: gl-render.h:256
text_renderer m_txt_renderer
Definition: gl-render.h:253
graphics_toolkit m_toolkit
Definition: gl-render.h:239
uint8_t clip_code(double x, double y, double z) const
Definition: gl-render.h:195
virtual void set_interpreter(const caseless_str &interp)
Definition: gl-render.h:104
graphics_xform m_xform
Definition: gl-render.h:177
virtual void set_selecting(bool on)
Definition: gl-render.h:114
opengl_renderer(const opengl_renderer &)=delete
unsigned int m_filled_marker_id
Definition: gl-render.h:245
unsigned int m_max_lights
Definition: gl-render.h:257
virtual void set_linecap(const std::string &)
Definition: gl-render.h:111
bool is_nan_or_inf(double x, double y, double z) const
Definition: gl-render.h:187
virtual void set_device_pixel_ratio(double dpr)
Definition: gl-render.h:64
opengl_functions & get_opengl_functions(void) const
Definition: gl-render.h:54
virtual void set_linejoin(const std::string &)
Definition: gl-render.h:112
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
bool isinf(double x)
Definition: lo-mappers.h:203
bool isnan(bool)
Definition: lo-mappers.h:178
F77_RET_T const F77_DBLE * x
T octave_idx_type m
Definition: mx-inlines.cc:773
octave_idx_type n
Definition: mx-inlines.cc:753
std::complex< double > w(std::complex< double > z, double relerr=0)
T::properties & properties(graphics_object obj)
static bool is_nan_or_inf(const octave_value &val)
Definition: oct-stream.cc:5740
void draw(QDomElement &parent_elt, pdfpainter &painter)