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