GNU Octave  4.4.1
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-2018 Michael Goffioul
4 
5 This file is part of Octave.
6 
7 Octave is free software: you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <https://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if ! defined (octave_gl_render_h)
24 #define octave_gl_render_h 1
25 
26 #include "octave-config.h"
27 
28 #include "graphics.h"
29 #include "text-renderer.h"
30 
31 namespace octave
32 {
33  class
34  OCTINTERP_API
36  {
37  public:
38 
39  opengl_renderer (void);
40 
41  // No copying!
42 
43  opengl_renderer (const opengl_renderer&) = delete;
44 
45  opengl_renderer& operator = (const opengl_renderer&) = delete;
46 
47  virtual ~opengl_renderer (void) = default;
48 
49  virtual void draw (const graphics_object& go, bool toplevel = true);
50 
51  virtual void draw (const Matrix& hlist, bool toplevel = false)
52  {
53  int len = hlist.numel ();
54 
55  for (int i = len-1; i >= 0; i--)
56  {
58 
59  if (obj)
60  draw (obj, toplevel);
61  }
62  }
63 
64  virtual void set_viewport (int w, int h);
65  virtual graphics_xform get_transform (void) const { return xform; }
66  virtual uint8NDArray get_pixels (int width, int height);
67 
68  virtual void finish (void);
69 
70  protected:
71  virtual void draw_figure (const figure::properties& props);
72  virtual void draw_axes (const axes::properties& props);
73  virtual void draw_line (const line::properties& props);
74  virtual void draw_surface (const surface::properties& props);
75  virtual void draw_patch (const patch::properties& props);
76  virtual void draw_light (const light::properties& props);
77  virtual void draw_hggroup (const hggroup::properties& props);
78  virtual void draw_text (const text::properties& props);
79  virtual void draw_text_background (const text::properties& props,
80  bool do_rotate = false);
81  virtual void draw_image (const image::properties& props);
82  virtual void draw_uipanel (const uipanel::properties& props,
83  const graphics_object& go);
84  virtual void draw_uibuttongroup (const uibuttongroup::properties& props,
85  const graphics_object& go);
86  virtual void init_gl_context (bool enhanced, const Matrix& backgroundColor);
87  virtual void setup_opengl_transformation (const axes::properties& props);
88 
89  virtual void set_clipbox (double x1, double x2, double y1, double y2,
90  double z1, double z2);
91  virtual void set_clipping (bool on);
92  virtual void set_font (const base_properties& props);
93  virtual void set_color (const Matrix& c);
94  virtual void set_interpreter (const caseless_str& interp)
95  {
96  interpreter = interp;
97  }
98  virtual void set_linewidth (float w);
99  virtual void set_linestyle (const std::string& s, bool stipple = false,
100  double linewidth = 0.5);
101  virtual void set_linecap (const std::string&) { };
102  virtual void set_linejoin (const std::string&) { };
103  virtual void set_polygon_offset (bool on, float offset = 0.0f);
104  virtual void set_selecting (bool on)
105  {
106  selecting = on;
107  }
108 
109  virtual void init_marker (const std::string& m, double size, float width);
110  virtual void end_marker (void);
111  virtual void draw_marker (double x, double y, double z,
112  const Matrix& lc, const Matrix& fc);
113 
114  virtual void text_to_pixels (const std::string& txt,
115  uint8NDArray& pixels,
116  Matrix& bbox,
117  int halign = 0, int valign = 0,
118  double rotation = 0.0);
119 
120  virtual void text_to_strlist (const std::string& txt,
121  std::list<text_renderer::string>& lst,
122  Matrix& bbox,
123  int halign = 0, int valign = 0,
124  double rotation = 0.0);
125 
126  virtual Matrix render_text (const std::string& txt,
127  double x, double y, double z,
128  int halign, int valign, double rotation = 0.0);
129 
130  virtual void draw_pixels (int w, int h, const float *data);
131  virtual void draw_pixels (int w, int h, const uint8_t *data);
132  virtual void draw_pixels (int w, int h, const uint16_t *data);
133 
134  virtual void render_grid (const double linewidth,
135  const std::string& gridstyle,
136  const Matrix& gridcolor, const double gridalpha,
137  const Matrix& ticks, double lim1, double lim2,
138  double p1, double p1N, double p2, double p2N,
139  int xyz, bool is_3D);
140 
141  virtual void render_tickmarks (const Matrix& ticks, double lim1, double lim2,
142  double p1, double p1N, double p2, double p2N,
143  double dx, double dy, double dz,
144  int xyz, bool doubleside);
145 
146  virtual void render_ticktexts (const Matrix& ticks,
147  const string_vector& ticklabels,
148  double lim1, double lim2,
149  double p1, double p2,
150  int xyz, int ha, int va,
151  int& wmax, int& hmax);
152 
153  private:
154 
155  bool is_nan_or_inf (double x, double y, double z) const
156  {
157  return (math::isnan (x) || math::isnan (y)
158  || math::isnan (z)
159  || math::isinf (x) || math::isinf (y)
160  || math::isinf (z));
161  }
162 
163  octave_uint8 clip_code (double x, double y, double z) const
164  {
165  return ((x < xmin ? 1 : 0)
166  | (x > xmax ? 1 : 0) << 1
167  | (y < ymin ? 1 : 0) << 2
168  | (y > ymax ? 1 : 0) << 3
169  | (z < zmin ? 1 : 0) << 4
170  | (z > zmax ? 1 : 0) << 5
171  | (is_nan_or_inf (x, y, z) ? 0 : 1) << 6);
172  }
173 
174  void set_normal (int bfl_mode, const NDArray& n, int j, int i);
175 
176  unsigned int make_marker_list (const std::string& m, double size,
177  bool filled) const;
178 
179  void draw_axes_planes (const axes::properties& props);
180  void draw_axes_boxes (const axes::properties& props);
181 
182  void draw_axes_grids (const axes::properties& props);
183  void draw_axes_x_grid (const axes::properties& props);
184  void draw_axes_y_grid (const axes::properties& props);
185  void draw_axes_z_grid (const axes::properties& props);
186 
187  void draw_axes_children (const axes::properties& props);
188 
189  void draw_all_lights (const base_properties& props,
190  std::list<graphics_object>& obj_list);
191 
192  private:
193  // The graphics toolkit associated with the figure being rendered.
195 
196  // axes transformation data
198 
199  // axis limits in model scaled coordinate
200  double xmin, xmax;
201  double ymin, ymax;
202  double zmin, zmax;
203 
204  // Z projection limits in windows coordinate
205  double xZ1, xZ2;
206 
207  // call lists identifiers for markers
208  unsigned int marker_id, filled_marker_id;
209 
210  // camera information for primitive sorting and lighting
211  ColumnVector camera_pos, camera_dir, view_vector;
212 
213  // interpreter to be used by text_to_pixels
215 
217 
218  // light object present and visible
220  unsigned int current_light;
222 
223  // Indicate we are drawing for selection purpose
224  bool selecting;
225  private:
226  class patch_tesselator;
227  };
228 }
229 
230 #endif
graphics_toolkit toolkit
Definition: gl-render.h:194
virtual void set_selecting(bool on)
Definition: gl-render.h:104
octave_int< T > xmax(const octave_int< T > &x, const octave_int< T > &y)
caseless_str interpreter
Definition: gl-render.h:214
F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE * f
virtual void draw(const Matrix &hlist, bool toplevel=false)
Definition: gl-render.h:51
unsigned int marker_id
Definition: gl-render.h:208
bool isnan(bool)
Definition: lo-mappers.h:187
bool isinf(double x)
Definition: lo-mappers.h:225
nd example oindent opens the file binary numeric values will be read assuming they are stored in IEEE format with the least significant bit and then converted to the native representation Opening a file that is already open simply opens it again and returns a separate file id It is not an error to open a file several though writing to the same file through several different file ids may produce unexpected results The possible values of text mode reading and writing automatically converts linefeeds to the appropriate line end character for the you may append a you must also open the file in binary mode The parameter conversions are currently only supported for and permissions will be set to and then everything is written in a single operation This is very efficient and improves performance c
Definition: file-io.cc:587
s
Definition: file-io.cc:2729
double h
Definition: graphics.cc:11808
text_renderer txt_renderer
Definition: gl-render.h:216
std::complex< double > w(std::complex< double > z, double relerr=0)
virtual void set_linecap(const std::string &)
Definition: gl-render.h:101
octave_uint8 clip_code(double x, double y, double z) const
Definition: gl-render.h:163
Definition: dMatrix.h:36
bool is_nan_or_inf(double x, double y, double z) const
Definition: gl-render.h:155
octave_int< T > xmin(const octave_int< T > &x, const octave_int< T > &y)
virtual graphics_xform get_transform(void) const
Definition: gl-render.h:65
unsigned int current_light
Definition: gl-render.h:220
virtual void set_linejoin(const std::string &)
Definition: gl-render.h:102
graphics_xform xform
Definition: gl-render.h:197
the element is set to zero In other the statement xample y
Definition: data.cc:5264
static graphics_object get_object(double val)
Definition: graphics.in.h:6098
static bool is_nan_or_inf(const octave_value &val)
Definition: oct-stream.cc:5580
for i
Definition: data.cc:5264
octave_idx_type numel(void) const
Number of elements in the array.
Definition: Array.h:366
virtual void set_interpreter(const caseless_str &interp)
Definition: gl-render.h:94
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
Definition: utils.cc:888
ColumnVector view_vector
Definition: gl-render.h:211
void xform(ColumnVector &v, const Matrix &m)
Definition: graphics.cc:5454
more on
Definition: toplev.cc:236
F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T const F77_DBLE * x