GNU Octave  4.2.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
gl-render.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2008-2017 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 the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 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 <http://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
36  {
37  public:
38 
39  opengl_renderer (void);
40 
41  virtual ~opengl_renderer (void) { }
42 
43  virtual void draw (const graphics_object& go, bool toplevel = true);
44 
45  virtual void draw (const Matrix& hlist, bool toplevel = false)
46  {
47  int len = hlist.numel ();
48 
49  for (int i = len-1; i >= 0; i--)
50  {
52 
53  if (obj)
54  draw (obj, toplevel);
55  }
56  }
57 
58  virtual void set_viewport (int w, int h);
59  virtual graphics_xform get_transform (void) const { return xform; }
60 
61  virtual void finish (void);
62 
63  protected:
64  virtual void draw_figure (const figure::properties& props);
65  virtual void draw_axes (const axes::properties& props);
66  virtual void draw_line (const line::properties& props);
67  virtual void draw_surface (const surface::properties& props);
68  virtual void draw_patch (const patch::properties& props);
69  virtual void draw_light (const light::properties& props);
70  virtual void draw_hggroup (const hggroup::properties& props);
71  virtual void draw_text (const text::properties& props);
72  virtual void draw_image (const image::properties& props);
73  virtual void draw_uipanel (const uipanel::properties& props,
74  const graphics_object& go);
75  virtual void draw_uibuttongroup (const uibuttongroup::properties& props,
76  const graphics_object& go);
77  virtual void init_gl_context (bool enhanced, const Matrix& backgroundColor);
78  virtual void setup_opengl_transformation (const axes::properties& props);
79 
80  virtual void set_color (const Matrix& c);
81  virtual void set_polygon_offset (bool on, float offset = 0.0f);
82  virtual void set_linewidth (float w);
83  virtual void set_linestyle (const std::string& s, bool stipple = false,
84  double linewidth = 0.5);
85  virtual void set_clipbox (double x1, double x2, double y1, double y2,
86  double z1, double z2);
87  virtual void set_clipping (bool on);
88  virtual void set_font (const base_properties& props);
89  virtual void set_interpreter (const caseless_str& interp)
90  {
91  interpreter = interp;
92  }
93 
94  virtual void init_marker (const std::string& m, double size, float width);
95  virtual void end_marker (void);
96  virtual void draw_marker (double x, double y, double z,
97  const Matrix& lc, const Matrix& fc);
98 
99  virtual void text_to_pixels (const std::string& txt,
100  uint8NDArray& pixels,
101  Matrix& bbox,
102  int halign = 0, int valign = 0,
103  double rotation = 0.0);
104 
105  virtual void text_to_strlist (const std::string& txt,
106  std::list<text_renderer::string>& lst,
107  Matrix& bbox,
108  int halign = 0, int valign = 0,
109  double rotation = 0.0);
110 
111  virtual Matrix render_text (const std::string& txt,
112  double x, double y, double z,
113  int halign, int valign, double rotation = 0.0);
114 
115  virtual void draw_pixels (int w, int h, const float *data);
116  virtual void draw_pixels (int w, int h, const uint8_t *data);
117  virtual void draw_pixels (int w, int h, const uint16_t *data);
118 
119  virtual void render_grid (const double linewidth,
120  const std::string& gridstyle,
121  const Matrix& gridcolor, const double gridalpha,
122  const Matrix& ticks, double lim1, double lim2,
123  double p1, double p1N, double p2, double p2N,
124  int xyz, bool is_3D);
125 
126  virtual void render_tickmarks (const Matrix& ticks, double lim1, double lim2,
127  double p1, double p1N, double p2, double p2N,
128  double dx, double dy, double dz,
129  int xyz, bool doubleside);
130 
131  virtual void render_ticktexts (const Matrix& ticks,
132  const string_vector& ticklabels,
133  double lim1, double lim2,
134  double p1, double p2,
135  int xyz, int ha, int va,
136  int& wmax, int& hmax);
137 
138  private:
139 
140  // No copying!
141 
143 
144  opengl_renderer& operator = (const opengl_renderer&);
145 
146  bool is_nan_or_inf (double x, double y, double z) const
147  {
148  return (octave::math::isnan (x) || octave::math::isnan (y)
149  || octave::math::isnan (z)
151  || octave::math::isinf (z));
152  }
153 
154  octave_uint8 clip_code (double x, double y, double z) const
155  {
156  return ((x < xmin ? 1 : 0)
157  | (x > xmax ? 1 : 0) << 1
158  | (y < ymin ? 1 : 0) << 2
159  | (y > ymax ? 1 : 0) << 3
160  | (z < zmin ? 1 : 0) << 4
161  | (z > zmax ? 1 : 0) << 5
162  | (is_nan_or_inf (x, y, z) ? 0 : 1) << 6);
163  }
164 
165  void set_normal (int bfl_mode, const NDArray& n, int j, int i);
166 
167  unsigned int make_marker_list (const std::string& m, double size,
168  bool filled) const;
169 
170  void draw_axes_planes (const axes::properties& props);
171  void draw_axes_boxes (const axes::properties& props);
172 
173  void draw_axes_x_grid (const axes::properties& props);
174  void draw_axes_y_grid (const axes::properties& props);
175  void draw_axes_z_grid (const axes::properties& props);
176 
177  void draw_axes_children (const axes::properties& props);
178 
179  void draw_all_lights (const base_properties& props,
180  std::list<graphics_object>& obj_list);
181 
182  private:
183  // The graphics toolkit associated with the figure being rendered.
185 
186  // axes transformation data
188 
189  // axis limits in model scaled coordinate
190  double xmin, xmax;
191  double ymin, ymax;
192  double zmin, zmax;
193 
194  // Z projection limits in windows coordinate
195  double xZ1, xZ2;
196 
197  // call lists identifiers for markers
198  unsigned int marker_id, filled_marker_id;
199 
200  // camera information for primitive sorting and lighting
201  ColumnVector camera_pos, camera_dir, view_vector;
202 
203  // interpreter to be used by text_to_pixels
205 
207 
208  // light object present and visible
210  unsigned int current_light;
212 
213  private:
214  class patch_tesselator;
215  };
216 }
217 
218 #endif
graphics_toolkit toolkit
Definition: gl-render.h:184
Octave interface to the compression and uncompression libraries.
Definition: aepbalance.cc:47
virtual graphics_xform get_transform(void) const
Definition: gl-render.h:59
octave_int< T > xmax(const octave_int< T > &x, const octave_int< T > &y)
caseless_str interpreter
Definition: gl-render.h:204
octave_idx_type numel(void) const
Number of elements in the array.
Definition: Array.h:363
F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &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 F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T F77_REAL F77_REAL &F77_RET_T F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE const F77_DBLE * f
bool isnan(double x)
Definition: lo-mappers.cc:347
virtual void draw(const Matrix &hlist, bool toplevel=false)
Definition: gl-render.h:45
unsigned int marker_id
Definition: gl-render.h:198
s
Definition: file-io.cc:2682
octave_uint8 clip_code(double x, double y, double z) const
Definition: gl-render.h:154
double h
Definition: graphics.cc:11205
#define OCTINTERP_API
Definition: mexproto.h:69
text_renderer txt_renderer
Definition: gl-render.h:206
nd deftypefn *octave_map m
Definition: ov-struct.cc:2058
std::complex< double > w(std::complex< double > z, double relerr=0)
Definition: dMatrix.h:37
the sparsity preserving column transformation such that that defines the pivoting threshold can be given in which case it defines the c
Definition: lu.cc:138
bool isinf(double x)
Definition: lo-mappers.cc:387
octave_int< T > xmin(const octave_int< T > &x, const octave_int< T > &y)
static bool is_nan_or_inf(const octave_value &val)
Definition: oct-stream.cc:5524
bool is_nan_or_inf(double x, double y, double z) const
Definition: gl-render.h:146
unsigned int current_light
Definition: gl-render.h:210
=val(i)}if ode{val(i)}occurs in table i
Definition: lookup.cc:239
virtual ~opengl_renderer(void)
Definition: gl-render.h:41
graphics_xform xform
Definition: gl-render.h:187
the element is set to zero In other the statement xample y
Definition: data.cc:5342
static graphics_object get_object(double val)
Definition: graphics.h:13794
OCTAVE_EXPORT octave_value_list any number nd example oindent prints the prompt xample Pick a any number!nd example oindent and waits for the user to enter a value The string entered by the user is evaluated as an so it may be a literal a variable or any other valid Octave code The number of return their size
Definition: input.cc:871
virtual void set_interpreter(const caseless_str &interp)
Definition: gl-render.h:89
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:854
ColumnVector view_vector
Definition: gl-render.h:201
void xform(ColumnVector &v, const Matrix &m)
Definition: graphics.cc:5162
F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &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 F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T F77_REAL F77_REAL &F77_RET_T F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE * x