26 #if defined (HAVE_CONFIG_H)
34 #if defined (HAVE_WINDOWS_H)
35 # define WIN32_LEAN_AND_MEAN
51 #if defined (HAVE_OPENGL)
54 next_power_of_2 (
int n)
64 #define LIGHT_MODE GL_FRONT_AND_BACK
94 #if ! defined (CALLBACK)
107 : m_glfcns (glfcns), m_id (), m_w (), m_h (), m_tw (), m_th (),
108 m_tx (), m_ty (), m_valid (
false)
113 : m_glfcns (glfcns), m_id (
id), m_w (
w), m_h (h), m_tw (tw), m_th (th),
114 m_tx (
double(m_w)/m_tw), m_ty (
double(m_h)/m_th), m_valid (
true)
117 OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (texture_rep)
122 m_glfcns.glDeleteTextures (1, &m_id);
125 void bind (
int mode)
const
128 m_glfcns.glBindTexture (mode, m_id);
131 void tex_coord (
double q,
double r)
const
134 m_glfcns.glTexCoord2d (q*m_tx,
r*m_ty);
147 opengl_texture () =
delete;
150 : m_rep (
new texture_rep (glfcns))
155 : m_rep (
new texture_rep (glfcns,
id,
w, h, tw, th))
158 OCTAVE_DEFAULT_COPY_DELETE (opengl_texture)
163 void bind (
int mode = GL_TEXTURE_2D)
const { m_rep->bind (mode); }
165 void tex_coord (
double q,
double r)
const { m_rep->tex_coord (q,
r); }
167 bool is_valid ()
const {
return m_rep->m_valid; }
171 opengl_texture (
const std::shared_ptr<texture_rep>& new_rep)
175 std::shared_ptr<texture_rep> m_rep;
181 opengl_texture retval (glfcns);
186 if (dv.ndims () == 3 && (dv(2) == 3 || dv(2) == 4))
191 h = dv(0),
w = dv(1);
196 glGetIntegerv (GL_MAX_TEXTURE_SIZE, &max_size);
197 static bool warned =
false;
198 if (h > max_size ||
w > max_size)
202 warning (
"opengl_texture::create: the opengl library in use "
203 "doesn't support images with either dimension larger "
204 "than %d. Not rendering.", max_size);
208 return opengl_texture (glfcns);
214 tw = next_power_of_2 (
w);
215 th = next_power_of_2 (h);
226 for (
int i = 0; i < h; i++)
228 for (
int j = 0, idx = i*tw*3; j <
w; j++, idx += 3)
230 a[idx] = xdata(i, j, 0);
231 a[idx+1] = xdata(i, j, 1);
232 a[idx+2] = xdata(i, j, 2);
236 glfcns.
glTexImage2D (GL_TEXTURE_2D, 0, 3, tw, th, 0, GL_RGB,
246 for (
int i = 0; i < h; i++)
248 for (
int j = 0, idx = i*tw*3; j <
w; j++, idx += 3)
250 a[idx] = xdata(i, j, 0);
251 a[idx+1] = xdata(i, j, 1);
252 a[idx+2] = xdata(i, j, 2);
256 glfcns.
glTexImage2D (GL_TEXTURE_2D, 0, 3, tw, th, 0, GL_RGB,
265 for (
int i = 0; i < h; i++)
267 for (
int j = 0, idx = i*tw*3; j <
w; j++, idx += 3)
269 a[idx] = xdata(i, j, 0);
270 a[idx+1] = xdata(i, j, 1);
271 a[idx+2] = xdata(i, j, 2);
276 GL_RGB, GL_UNSIGNED_SHORT, a);
284 for (
int i = 0; i < h; i++)
286 for (
int j = 0, idx = i*tw*3; j <
w; j++, idx += 3)
288 a[idx] = xdata(i, j, 0);
289 a[idx+1] = xdata(i, j, 1);
290 a[idx+2] = xdata(i, j, 2);
295 GL_RGB, GL_UNSIGNED_BYTE, a);
303 for (
int i = 0; i < h; i++)
305 for (
int j = 0, idx = i*tw*4; j <
w; j++, idx += 4)
307 a[idx] = xdata(i, j, 0);
308 a[idx+1] = xdata(i, j, 1);
309 a[idx+2] = xdata(i, j, 2);
310 a[idx+3] = xdata(i, j, 3);
314 glfcns.
glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, tw, th, 0,
315 GL_RGBA, GL_UNSIGNED_BYTE, a);
320 warning (
"opengl_texture::create: invalid image data type, expected double, single, uint8, or uint16");
331 warning (
"opengl_texture::create: OpenGL error while generating texture data");
333 retval = opengl_texture (glfcns,
id,
w, h, tw, th);
337 warning (
"opengl_texture::create: invalid texture data size");
346 #if defined (HAVE_FRAMEWORK_OPENGL) && defined (HAVE_GLUTESSCALLBACK_THREEDOTS)
347 typedef GLvoid (
CALLBACK *fcn) (...);
354 opengl_tessellator () : m_glu_tess (nullptr), m_fill () { init (); }
356 OCTAVE_DISABLE_COPY_MOVE (opengl_tessellator)
358 virtual ~opengl_tessellator ()
359 {
if (m_glu_tess) gluDeleteTess (m_glu_tess); }
361 void begin_polygon (
bool filled =
true)
363 gluTessProperty (m_glu_tess, GLU_TESS_BOUNDARY_ONLY,
364 (filled ? GL_FALSE : GL_TRUE));
366 gluTessBeginPolygon (m_glu_tess,
this);
369 void end_polygon ()
const
370 { gluTessEndPolygon (m_glu_tess); }
372 void begin_contour ()
const
373 { gluTessBeginContour (m_glu_tess); }
375 void end_contour ()
const
376 { gluTessEndContour (m_glu_tess); }
378 void add_vertex (
double *loc,
void *data)
const
379 { gluTessVertex (m_glu_tess, loc, data); }
382 virtual void begin (GLenum ) { }
384 virtual void end () { }
386 virtual void vertex (
void * ) { }
388 virtual void combine (GLdouble [3] ,
void *[4] ,
389 GLfloat [4] ,
void ** ) { }
391 virtual void edge_flag (GLboolean ) { }
393 virtual void error (GLenum err)
394 {
::error (
"OpenGL tessellation error (%d)", err); }
398 m_glu_tess = gluNewTess ();
400 gluTessCallback (m_glu_tess, GLU_TESS_BEGIN_DATA,
401 reinterpret_cast<fcn
> (tess_begin));
402 gluTessCallback (m_glu_tess, GLU_TESS_END_DATA,
403 reinterpret_cast<fcn
> (tess_end));
404 gluTessCallback (m_glu_tess, GLU_TESS_VERTEX_DATA,
405 reinterpret_cast<fcn
> (tess_vertex));
406 gluTessCallback (m_glu_tess, GLU_TESS_COMBINE_DATA,
407 reinterpret_cast<fcn
> (tess_combine));
408 gluTessCallback (m_glu_tess, GLU_TESS_EDGE_FLAG_DATA,
409 reinterpret_cast<fcn
> (tess_edge_flag));
410 gluTessCallback (m_glu_tess, GLU_TESS_ERROR_DATA,
411 reinterpret_cast<fcn
> (tess_error));
414 bool is_filled ()
const {
return m_fill; }
417 static void CALLBACK tess_begin (GLenum type,
void *t)
418 {
reinterpret_cast<opengl_tessellator *
> (t)->begin (type); }
420 static void CALLBACK tess_end (
void *t)
421 {
reinterpret_cast<opengl_tessellator *
> (t)->end (); }
423 static void CALLBACK tess_vertex (
void *v,
void *t)
424 {
reinterpret_cast<opengl_tessellator *
> (t)->vertex (v); }
426 static void CALLBACK tess_combine (GLdouble c[3],
void *v[4], GLfloat
w[4],
428 {
reinterpret_cast<opengl_tessellator *
> (t)->combine (c, v,
w, out); }
430 static void CALLBACK tess_edge_flag (GLboolean flag,
void *t)
431 {
reinterpret_cast<opengl_tessellator *
> (t)->edge_flag (flag); }
433 static void CALLBACK tess_error (GLenum err,
void *t)
434 {
reinterpret_cast<opengl_tessellator *
> (t)->
error (err); }
438 GLUtesselator *m_glu_tess;
446 class vertex_data_rep
451 : m_coords (), m_color (), m_vertex_normal (), m_face_normal (),
452 m_alpha (), m_ambient (), m_diffuse (), m_specular (),
453 m_specular_exp (), m_specular_color_refl ()
457 const Matrix& fn,
double a,
float as,
float ds,
float ss,
459 : m_coords (c), m_color (col), m_vertex_normal (vn),
460 m_face_normal (fn), m_alpha (a), m_ambient (as), m_diffuse (ds),
461 m_specular (ss), m_specular_exp (se), m_specular_color_refl (scr)
464 OCTAVE_DEFAULT_COPY (vertex_data_rep)
466 ~vertex_data_rep () =
default;
476 float m_specular_exp;
477 float m_specular_color_refl;
483 vertex_data () : m_rep (nil_rep ()) { }
486 const Matrix& fn,
double a,
float as,
float ds,
float ss,
488 : m_rep (new vertex_data_rep (c, col, vn, fn, a, as, ds, ss, se, scr))
491 vertex_data (
const vertex_data&) =
default;
493 ~vertex_data () =
default;
495 vertex_data& operator = (
const vertex_data&) =
default;
497 vertex_data_rep * get_rep ()
const {
return m_rep.get (); }
501 static std::shared_ptr<vertex_data_rep> nil_rep ()
503 static std::shared_ptr<vertex_data_rep> nr (
new vertex_data_rep ());
508 std::shared_ptr<vertex_data_rep> m_rep;
512 opengl_renderer::patch_tessellator :
public opengl_tessellator
518 : opengl_tessellator (), m_renderer (
r),
519 m_color_mode (cmode), m_light_mode (lmode), m_face_lighting (fl),
520 m_index (idx), m_first (true), m_tmp_vdata ()
523 OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (patch_tessellator)
525 ~patch_tessellator () =
default;
528 void begin (GLenum type)
541 m_renderer->set_polygon_offset (
true, m_index);
552 m_renderer->set_polygon_offset (
false);
555 void vertex (
void *data)
559 vertex_data::vertex_data_rep *v
560 =
reinterpret_cast<vertex_data::vertex_data_rep *
> (data);
566 if (m_color_mode ==
INTERP || (m_color_mode ==
FLAT && ! is_filled ()))
570 if (col.
numel () == 3)
572 glfcns.
glColor4d (col(0), col(1), col(2), v->m_alpha);
573 if (m_light_mode > 0)
576 float buf[4] = { 0.0f, 0.0f, 0.0f, 1.0f };
579 for (
int k = 0; k < 3; k++)
580 buf[k] = (v->m_specular
581 * (v->m_specular_color_refl +
582 (1 - v->m_specular_color_refl) * col(k)));
586 for (
int k = 0; k < 3; k++)
587 buf[k] = (v->m_diffuse * col(k));
590 for (
int k = 0; k < 3; k++)
591 buf[k] = (v->m_ambient * col(k));
597 if (m_light_mode ==
FLAT && m_first)
599 else if (m_light_mode ==
GOURAUD)
607 void combine (GLdouble xyz[3],
void *data[4], GLfloat
w[4],
void **out_data)
609 vertex_data::vertex_data_rep *v[4];
612 for (
int i = 0; i < 4; i++)
614 v[i] =
reinterpret_cast<vertex_data::vertex_data_rep *
> (data[i]);
616 if (vmax == 4 && ! v[i])
630 if (v[0]->m_color.numel ())
633 for (
int ic = 0; ic < 3; ic++)
634 for (
int iv = 0; iv < vmax; iv++)
635 cc(ic) += (
w[iv] * v[iv]->m_color (ic));
638 if (v[0]->m_vertex_normal.numel () > 0)
640 for (
int in = 0; in < 3; in++)
641 for (
int iv = 0; iv < vmax; iv++)
642 vnn(in) += (
w[iv] * v[iv]->m_vertex_normal (in));
645 if (v[0]->m_face_normal.numel () > 0)
647 for (
int in = 0; in < 3; in++)
648 for (
int iv = 0; iv < vmax; iv++)
649 fnn(in) += (
w[iv] * v[iv]->m_face_normal (in));
652 for (
int iv = 0; iv < vmax; iv++)
653 aa += (
w[iv] * v[iv]->m_alpha);
655 vertex_data new_v (vv, cc, vnn, fnn, aa, v[0]->m_ambient, v[0]->m_diffuse,
656 v[0]->m_specular, v[0]->m_specular_exp,
657 v[0]->m_specular_color_refl);
658 m_tmp_vdata.push_back (new_v);
660 *out_data = new_v.get_rep ();
670 bool m_face_lighting;
673 std::list<vertex_data> m_tmp_vdata;
679 opengl_renderer::patch_tessellator
687 : m_glfcns (glfcns), m_xmin (), m_xmax (), m_ymin (), m_ymax (),
688 m_zmin (), m_zmax (), m_devpixratio (1.0), m_xform (), m_toolkit (),
689 m_xZ1 (), m_xZ2 (), m_marker_id (), m_filled_marker_id (),
690 m_camera_pos (), m_camera_dir (), m_view_vector (),
691 m_interpreter (
"none"), m_txt_renderer (), m_current_light (0),
692 m_max_lights (0), m_selecting (false), m_printing (false)
698 #if defined (HAVE_OPENGL)
703 static bool ok = (
sizeof (int) <=
sizeof (GLsizei));
706 error (
"the size of GLsizei is smaller than the size of int");
726 if (go.
isa (
"figure"))
728 else if (go.
isa (
"axes"))
730 else if (go.
isa (
"line"))
732 else if (go.
isa (
"surface"))
734 else if (go.
isa (
"patch"))
736 else if (go.
isa (
"scatter"))
738 else if (go.
isa (
"light"))
740 else if (go.
isa (
"hggroup"))
742 else if (go.
isa (
"text"))
744 else if (go.
isa (
"image"))
746 else if (go.
isa (
"uimenu") || go.
isa (
"uicontrol")
747 || go.
isa (
"uicontextmenu") || go.
isa (
"uitoolbar")
748 || go.
isa (
"uipushtool") || go.
isa (
"uitoggletool")
749 || go.
isa (
"uitable"))
751 else if (go.
isa (
"uipanel"))
756 else if (go.
isa (
"uibuttongroup"))
763 warning (
"opengl_renderer: cannot render object of type '%s'",
767 #if defined (HAVE_OPENGL)
771 warning (
"opengl_renderer: Error '%s' (%d) occurred drawing '%s' object",
772 gluErrorString (gl_error), gl_error,
786 #if defined (HAVE_OPENGL)
839 #if defined (HAVE_OPENGL)
853 bool has_multisample =
false;
856 GLint iMultiSample, iNumSamples;
859 if (iMultiSample == GL_TRUE && iNumSamples > 0)
860 has_multisample =
true;
863 if (! has_multisample)
890 warning (
"opengl_renderer: Error '%s' (%d) occurred in init_gl_context",
891 gluErrorString (gl_error), gl_error);
895 octave_unused_parameter (enhanced);
896 octave_unused_parameter (c);
908 const std::string& gridstyle,
909 const Matrix& gridcolor,
const double gridalpha,
910 const Matrix& ticks,
double lim1,
double lim2,
911 double p1,
double p1N,
double p2,
double p2N,
914 #if defined (HAVE_OPENGL)
919 for (
int i = 0; i < ticks.
numel (); i++)
921 double val = ticks(i);
922 if (lim1 <= val && val <= lim2)
955 double black[3] = {0, 0, 0};
960 octave_unused_parameter (linewidth);
961 octave_unused_parameter (gridstyle);
962 octave_unused_parameter (gridcolor);
963 octave_unused_parameter (gridalpha);
964 octave_unused_parameter (ticks);
965 octave_unused_parameter (lim1);
966 octave_unused_parameter (lim2);
967 octave_unused_parameter (p1);
968 octave_unused_parameter (p1N);
969 octave_unused_parameter (p2);
970 octave_unused_parameter (p2N);
971 octave_unused_parameter (xyz);
972 octave_unused_parameter (is_3D);
984 double lim1,
double lim2,
985 double p1,
double p1N,
986 double p2,
double p2N,
987 double dx,
double dy,
double dz,
988 int xyz,
bool mirror)
990 #if defined (HAVE_OPENGL)
994 for (
int i = 0; i < ticks.
numel (); i++)
996 double val = ticks(i);
998 if (lim1 <= val && val <= lim2)
1037 octave_unused_parameter (ticks);
1038 octave_unused_parameter (lim1);
1039 octave_unused_parameter (lim2);
1040 octave_unused_parameter (p1);
1041 octave_unused_parameter (p1N);
1042 octave_unused_parameter (p2);
1043 octave_unused_parameter (p2N);
1044 octave_unused_parameter (dx);
1045 octave_unused_parameter (dy);
1046 octave_unused_parameter (dz);
1047 octave_unused_parameter (xyz);
1048 octave_unused_parameter (mirror);
1061 double lim1,
double lim2,
1062 double p1,
double p2,
1063 int xyz,
int ha,
int va,
1064 int& wmax,
int& hmax)
1066 #if defined (HAVE_OPENGL)
1068 int nticks = ticks.
numel ();
1069 int nlabels = ticklabels.
numel ();
1074 for (
int i = 0; i < nticks; i++)
1076 double val = ticks(i);
1078 if (lim1 <= val && val <= lim2)
1082 std::string label (ticklabels(i % nlabels));
1083 label.erase (0, label.find_first_not_of (
' '));
1084 label = label.substr (0, label.find_last_not_of (
' ')+1);
1101 wmax =
std::max (wmax,
static_cast<int> (b(2)));
1102 hmax =
std::max (hmax,
static_cast<int> (b(3)));
1108 octave_unused_parameter (ticks);
1109 octave_unused_parameter (ticklabels);
1110 octave_unused_parameter (lim1);
1111 octave_unused_parameter (lim2);
1112 octave_unused_parameter (p1);
1113 octave_unused_parameter (p2);
1114 octave_unused_parameter (xyz);
1115 octave_unused_parameter (ha);
1116 octave_unused_parameter (va);
1117 octave_unused_parameter (wmax);
1118 octave_unused_parameter (hmax);
1131 #if defined (HAVE_OPENGL)
1141 octave_unused_parameter (x1);
1142 octave_unused_parameter (x2);
1143 octave_unused_parameter (y1);
1144 octave_unused_parameter (y2);
1156 int x1,
int y1,
int x2,
int y2,
1157 const Matrix& overlaycolor,
1158 double overlayalpha,
1159 const Matrix& bordercolor,
1160 double borderalpha,
double borderwidth)
1162 #if defined (HAVE_OPENGL)
1199 octave_unused_parameter (width);
1200 octave_unused_parameter (height);
1201 octave_unused_parameter (x1);
1202 octave_unused_parameter (x2);
1203 octave_unused_parameter (y1);
1204 octave_unused_parameter (y2);
1205 octave_unused_parameter (overlaycolor);
1206 octave_unused_parameter (overlayalpha);
1207 octave_unused_parameter (bordercolor);
1208 octave_unused_parameter (borderalpha);
1209 octave_unused_parameter (borderwidth);
1222 #if defined (HAVE_OPENGL)
1241 return pix.
permute (perm).index (idx);
1248 octave_unused_parameter (width);
1249 octave_unused_parameter (height);
1259 #if defined (HAVE_OPENGL)
1276 #if defined (HAVE_OPENGL)
1284 const double expansion_fac = 100.0;
1288 const double single_prec_fac = 10.0;
1290 double avgZ = x_zlim(0) / 2.0 + x_zlim(1) / 2.0;
1292 =
std::max (expansion_fac * (x_zlim(1)-x_zlim(0)),
1293 single_prec_fac * std::abs (avgZ)
1294 * std::numeric_limits<float>::epsilon ());
1295 m_xZ1 = avgZ - span;
1296 m_xZ2 = avgZ + span;
1321 octave_unused_parameter (props);
1334 #if defined (HAVE_OPENGL)
1381 octave_unused_parameter (props);
1394 #if defined (HAVE_OPENGL)
1421 bool plotyy = (props.
has_property (
"__plotyy_axes__"));
1431 std::swap (zpTick, zpTickN);
1440 if (! isXOrigin || props.
is_box() || ! is2D)
1469 if (! isYOrigin || props.
is_box() || ! is2D)
1475 if (props.
is_box () && ! plotyy)
1496 if (! color.
isempty () && ! is2D)
1541 octave_unused_parameter (props);
1554 #if defined (HAVE_OPENGL)
1571 double fy = props.
get_fy ();
1572 double fz = props.
get_fz ();
1594 bool tick_along_z = nearhoriz ||
math::isinf (fy);
1602 bool do_xgrid = (props.
is_xgrid () && (gridstyle !=
"none"));
1604 && (minorgridstyle !=
"none")
1608 bool is_origin_low = is_origin && (y_min + y_max) < 0;
1625 if (minorgridcolor.
isempty ())
1626 do_xminorgrid =
false;
1629 if (do_xminorgrid && ! do_xgrid)
1631 gridstyle = minorgridstyle;
1632 gridcolor = minorgridcolor;
1633 gridalpha = minorgridalpha;
1640 minorgridstyle, minorgridcolor, minorgridalpha,
1641 xmticks, x_min, x_max,
1642 yPlane, yPlaneN, layer2Dtop ? zPlaneN : zPlane, zPlaneN,
1648 gridstyle, gridcolor, gridalpha,
1649 xticks, x_min, x_max,
1650 yPlane, yPlaneN, layer2Dtop ? zPlaneN : zPlane, zPlaneN,
1660 double y_axis_pos = 0.;
1676 is_origin ? y_axis_pos : ypTick, ypTick,
1677 zpTick, zpTickN, 0., 0.,
1678 (is_origin_low ? -1. : 1.) *
1680 0, ! is_origin && mirror);
1683 is_origin ? y_axis_pos : ypTick, ypTickN,
1685 (is_origin_low ? -1. : 1.) *
1687 0., 0, ! is_origin && mirror);
1695 is_origin ? y_axis_pos : ypTick, ypTick,
1696 zpTick, zpTickN, 0., 0.,
1697 (is_origin_low ? -1. : 1.) *
1699 0, ! is_origin && mirror);
1702 is_origin ? y_axis_pos : ypTick, ypTickN,
1704 (is_origin_low ? -1. : 1.) *
1706 0., 0, ! is_origin && mirror);
1710 if (xticklabels.
numel () > 0)
1714 : (xyzSym || is_origin_low ? 0 : 2));
1717 : (x2Dtop || is_origin_low ? 0 : 2));
1721 is_origin ? y_axis_pos : ypTick,
1723 (is_origin_low ? -1. : 1.) *
1725 0, halign, valign, wmax, hmax);
1728 (is_origin ? y_axis_pos : ypTick) +
1729 (is_origin_low ? -1. : 1.) *
1731 zpTick, 0, halign, valign, wmax, hmax);
1741 octave_unused_parameter (props);
1754 #if defined (HAVE_OPENGL)
1771 double fx = props.
get_fx ();
1772 double fz = props.
get_fz ();
1794 bool tick_along_z = nearhoriz ||
math::isinf (fx);
1802 bool do_ygrid = (props.
is_ygrid () && (gridstyle !=
"none"));
1804 && (minorgridstyle !=
"none")
1808 bool is_origin_low = is_origin && (x_min + x_max) < 0;
1826 if (minorgridcolor.
isempty ())
1827 do_yminorgrid =
false;
1830 if (do_yminorgrid && ! do_ygrid)
1832 gridstyle = minorgridstyle;
1833 gridcolor = minorgridcolor;
1834 gridalpha = minorgridalpha;
1841 minorgridstyle, minorgridcolor, minorgridalpha,
1842 ymticks, y_min, y_max,
1843 xPlane, xPlaneN, layer2Dtop ? zPlaneN : zPlane, zPlaneN,
1849 gridstyle, gridcolor, gridalpha,
1850 yticks, y_min, y_max,
1851 xPlane, xPlaneN, layer2Dtop ? zPlaneN : zPlane, zPlaneN,
1861 double x_axis_pos = 0.;
1877 is_origin ? x_axis_pos : xpTick, xpTick,
1878 zpTick, zpTickN, 0., 0.,
1879 (is_origin_low ? -1. : 1.) *
1881 1, ! is_origin && mirror);
1884 is_origin ? x_axis_pos : xpTick, xpTickN,
1886 (is_origin_low ? -1. : 1.) *
1888 0., 0., 1, ! is_origin && mirror);
1896 is_origin ? x_axis_pos : xpTick, xpTick,
1897 zpTick, zpTickN, 0., 0.,
1898 (is_origin_low ? -1. : 1.) *
1900 1, ! is_origin && mirror);
1903 is_origin ? x_axis_pos : xpTick, xpTickN,
1905 (is_origin_low ? -1. : 1.) *
1907 0., 0., 1, ! is_origin && mirror);
1911 if (yticklabels.
numel () > 0)
1915 : (! xyzSym || y2Dright || is_origin_low ? 0 : 2));
1918 : (is_origin_low ? 0 : 2));
1922 is_origin ? x_axis_pos : xpTick,
1924 (is_origin_low ? -1. : 1.) *
1926 1, halign, valign, wmax, hmax);
1929 (is_origin ? x_axis_pos : xpTick) +
1930 (is_origin_low ? -1. : 1.) *
1932 zpTick, 1, halign, valign, wmax, hmax);
1942 octave_unused_parameter (props);
1967 double fx = props.
get_fx ();
1968 double fy = props.
get_fy ();
1991 bool do_zgrid = (props.
is_zgrid () && (gridstyle !=
"none"));
1993 && (minorgridstyle !=
"none")
2011 if (minorgridcolor.
isempty ())
2012 do_zminorgrid =
false;
2015 if (do_zminorgrid && ! do_zgrid)
2017 gridstyle = minorgridstyle;
2018 gridcolor = minorgridcolor;
2019 gridalpha = minorgridalpha;
2026 minorgridstyle, minorgridcolor, minorgridalpha,
2027 zmticks, z_min, z_max,
2028 xPlane, xPlaneN, yPlane, yPlaneN, 2,
true);
2033 gridstyle, gridcolor, gridalpha,
2034 zticks, z_min, z_max,
2035 xPlane, xPlaneN, yPlane, yPlaneN, 2,
true);
2063 yPlaneN, yPlane, 0.,
2094 yPlaneN, yPlane, 0.,
2106 if (zticklabels.
numel () > 0)
2109 int valign = (zstate ==
AXE_VERT_DIR ? 1 : (zSign ? 3 : 2));
2115 xPlaneN +
math::signum (xPlaneN-xPlane)*fx*ztickoffset,
2116 yPlane, 2, halign, valign, wmax, hmax);
2120 2, halign, valign, wmax, hmax);
2126 yPlaneN +
math::signum (yPlaneN-yPlane)*fy*ztickoffset,
2127 2, halign, valign, wmax, hmax);
2131 yPlaneN, 2, halign, valign, wmax, hmax);
2144 #if defined (HAVE_OPENGL)
2146 GLboolean antialias;
2150 if (antialias == GL_TRUE)
2158 draw_axes_x_grid (props);
2159 draw_axes_y_grid (props);
2160 draw_axes_z_grid (props);
2162 if (antialias == GL_TRUE)
2166 octave_unused_parameter (props);
2178 std::list<graphics_object>& obj_list)
2180 #if defined (HAVE_OPENGL)
2194 if (go.
isa (
"light") && ! m_selecting)
2196 if (m_current_light-GL_LIGHT0 < m_max_lights)
2203 else if (go.
isa (
"hggroup")
2207 obj_list.push_back (go);
2212 octave_unused_parameter (props);
2213 octave_unused_parameter (obj_list);
2226 #if defined (HAVE_OPENGL)
2228 std::list<graphics_object> obj_list;
2229 std::list<graphics_object>::iterator it;
2245 "light: Maximum number of lights (%d) in these axes is "
2246 "exceeded.", m_max_lights);
2248 m_current_light = GL_LIGHT0;
2249 draw_all_lights (props, obj_list);
2252 for (
unsigned int i = props.
get_num_lights (); i < m_max_lights; i++)
2259 float cb[4] = { 1.0, 1.0, 1.0, 1.0 };
2261 for (
int i = 0; i < 3; i++)
2262 cb[i] = ambient_color(i);
2267 it = obj_list.begin ();
2268 while (it != obj_list.end ())
2279 it = obj_list.erase (it);
2302 octave_unused_parameter (props);
2315 #if defined (HAVE_OPENGL)
2335 if (x_max > floatmax || y_max > floatmax || z_max > floatmax
2336 || x_min < -floatmax || y_min < -floatmax || z_min < -floatmax)
2338 warning (
"opengl_renderer: data values greater than float capacity. (1) Scale data, or (2) Use gnuplot");
2352 draw_axes_planes (props);
2354 if (! is2D || props.
layer_is (
"bottom"))
2356 draw_axes_grids (props);
2358 draw_axes_boxes (props);
2361 set_clipbox (x_min, x_max, y_min, y_max, z_min, z_max);
2363 draw_axes_children (props);
2365 if (is2D && props.
layer_is (
"top"))
2367 draw_axes_grids (props);
2369 draw_axes_boxes (props);
2374 octave_unused_parameter (props);
2387 #if defined (HAVE_OPENGL)
2395 bool has_z = (z.
numel () > 0);
2399 uint8_t clip_mask = (props.
is_clipping () ? 0x7F : 0x40);
2400 uint8_t clip_ok = 0x40;
2402 std::vector<uint8_t> clip (
n);
2405 for (
int i = 0; i <
n; i++)
2406 clip[i] = (clip_code (
x(i), y(i), z(i)) & clip_mask);
2411 for (
int i = 0; i <
n; i++)
2412 clip[i] = (clip_code (
x(i), y(i), z_mid) & clip_mask);
2427 for (
int i = 1; i <
n; i++)
2429 if ((clip[i-1] & clip[i]) == clip_ok)
2453 for (
int i = 1; i <
n; i++)
2455 if ((clip[i-1] & clip[i]) == clip_ok)
2505 for (
int i = 0; i <
n; i++)
2507 if (clip[i] == clip_ok)
2520 octave_unused_parameter (props);
2533 #if defined (HAVE_OPENGL)
2547 bool has_vertex_normals = (vn_dims(0) == zr && vn_dims(1) == zc
2548 && vn_dims(2) == 3);
2551 bool has_face_normals = (fn_dims(0) == zr - 1 && fn_dims(1) == zc - 1
2552 && fn_dims(2) == 3);
2563 (has_face_normals ? 1 : 0) :
2564 (has_vertex_normals ? 2 : 0)));
2572 (has_face_normals ? 1 : 0) :
2573 (has_vertex_normals ? 2 : 0)));
2590 float cb[4] = { 0.0, 0.0, 0.0, 1.0 };
2595 bool x_mat = (
x.rows () == z.
rows ());
2598 i1 = i2 = j1 = j2 = 0;
2600 if ((fc_mode > 0 && fc_mode < 3) || ec_mode > 0)
2605 for (
int i = 0; i < zr; i++)
2610 for (
int j = 0; j < zc; j++)
2615 clip(i, j) = is_nan_or_inf (
x(i1, j), y(i, j1), z(i, j));
2619 if (fa_mode > 0 || ea_mode > 0)
2625 if (fl_mode > 0 || el_mode > 0)
2644 for (
int i = 0; i < 3; i++)
2645 cb[i] = as * fcolor(i);
2648 for (
int i = 0; i < 3; i++)
2649 cb[i] = ds * fcolor(i);
2652 for (
int i = 0; i < 3; i++)
2653 cb[i] = ss * (scr + (1-scr) * fcolor(i));
2658 if ((fl_mode > 0) && do_lighting)
2661 ? GL_SMOOTH : GL_FLAT);
2666 for (
int i = 1; i < zc; i++)
2674 for (
int j = 1; j < zr; j++)
2677 if (clip(j-1, i-1) || clip(j, i-1)
2678 || clip(j-1, i) || clip(j, i))
2681 if (fc_mode ==
FLAT)
2687 else if (fc_mode ==
INTERP)
2707 tex.tex_coord (
double (i-1) / (zc-1),
2708 double (j-1) / (zr-1));
2709 else if (fc_mode > 0)
2712 for (
int k = 0; k < 3; k++)
2713 cb[k] = c(j-1, i-1, k);
2718 for (
int k = 0; k < 3; k++)
2722 for (
int k = 0; k < 3; k++)
2723 cb[k] = ds * c(j-1, i-1, k);
2726 for (
int k = 0; k < 3; k++)
2727 cb[k] = ss * (scr + (1-scr) * c(j-1, i-1, k));
2732 set_normal (bfl_mode, (fl_mode ==
GOURAUD ? vn : fn),
2739 tex.tex_coord (
double (i) / (zc-1),
2740 double (j-1) / (zr-1));
2741 else if (fc_mode ==
INTERP)
2743 for (
int k = 0; k < 3; k++)
2744 cb[k] = c(j-1, i, k);
2749 for (
int k = 0; k < 3; k++)
2753 for (
int k = 0; k < 3; k++)
2754 cb[k] = ds * c(j-1, i, k);
2757 for (
int k = 0; k < 3; k++)
2758 cb[k] = ss * (scr + (1-scr) * c(j-1, i, k));
2764 set_normal (bfl_mode, vn, j-1, i);
2770 tex.tex_coord (
double (i) / (zc-1),
double (j) / (zr-1));
2771 else if (fc_mode ==
INTERP)
2773 for (
int k = 0; k < 3; k++)
2779 for (
int k = 0; k < 3; k++)
2783 for (
int k = 0; k < 3; k++)
2784 cb[k] = ds * c(j, i, k);
2787 for (
int k = 0; k < 3; k++)
2788 cb[k] = ss * (scr + (1-scr) * c(j, i, k));
2793 set_normal (bfl_mode, vn, j, i);
2799 tex.tex_coord (
double (i-1) / (zc-1),
2800 double (j) / (zr-1));
2801 else if (fc_mode ==
INTERP)
2803 for (
int k = 0; k < 3; k++)
2804 cb[k] = c(j, i-1, k);
2809 for (
int k = 0; k < 3; k++)
2813 for (
int k = 0; k < 3; k++)
2814 cb[k] = ds * c(j, i-1, k);
2817 for (
int k = 0; k < 3; k++)
2818 cb[k] = ss * (scr + (1-scr) * c(j, i-1, k));
2823 set_normal (bfl_mode, vn, j, i-1);
2835 if ((fl_mode > 0) && do_lighting)
2854 for (
int i = 0; i < 3; i++)
2855 cb[i] = as * ecolor(i);
2858 for (
int i = 0; i < 3; i++)
2859 cb[i] = ds * ecolor(i);
2862 for (
int i = 0; i < 3; i++)
2863 cb[i] = ss * (scr + (1-scr) * ecolor(i));
2868 if ((el_mode > 0) && do_lighting)
2871 ? GL_SMOOTH : GL_FLAT);
2883 for (
int i = 0; i < zc; i++)
2891 for (
int j = 1; j < zr; j++)
2893 if (clip(j-1, i) || clip(j, i))
2896 if (ec_mode ==
FLAT)
2902 else if (ec_mode ==
INTERP)
2921 for (
int k = 0; k < 3; k++)
2922 cb[k] = c(j-1, i, k);
2927 for (
int k = 0; k < 3; k++)
2932 for (
int k = 0; k < 3; k++)
2933 cb[k] = ds * c(j-1, i, k);
2937 for (
int k = 0; k < 3; k++)
2938 cb[k] = ss * (scr + (1-scr) * c(j-1, i, k));
2946 set_normal (bfl_mode, vn, j-1, i);
2948 set_normal (bfl_mode, fn, j-1,
std::min (i, zc-2));
2956 for (
int k = 0; k < 3; k++)
2962 for (
int k = 0; k < 3; k++)
2967 for (
int k = 0; k < 3; k++)
2968 cb[k] = ds * c(j, i, k);
2972 for (
int k = 0; k < 3; k++)
2973 cb[k] = ss * (scr + (1-scr) * c(j, i, k));
2979 set_normal (bfl_mode, vn, j, i);
2992 for (
int j = 0; j < zr; j++)
3000 for (
int i = 1; i < zc; i++)
3002 if (clip(j, i-1) || clip(j, i))
3005 if (ec_mode ==
FLAT)
3011 else if (ec_mode ==
INTERP)
3030 for (
int k = 0; k < 3; k++)
3031 cb[k] = c(j, i-1, k);
3036 for (
int k = 0; k < 3; k++)
3041 for (
int k = 0; k < 3; k++)
3042 cb[k] = ds * c(j, i-1, k);
3046 for (
int k = 0; k < 3; k++)
3047 cb[k] = ss * (scr + (1-scr) * c(j, i-1, k));
3055 set_normal (bfl_mode, vn, j, i-1);
3057 set_normal (bfl_mode, fn,
std::min (j, zr-2), i-1);
3065 for (
int k = 0; k < 3; k++)
3071 for (
int k = 0; k < 3; k++)
3076 for (
int k = 0; k < 3; k++)
3077 cb[k] = ds * c(j, i, k);
3081 for (
int k = 0; k < 3; k++)
3082 cb[k] = ss * (scr + (1-scr) * c(j, i, k));
3088 set_normal (bfl_mode, vn, j, i);
3100 if ((el_mode > 0) && do_lighting)
3144 uint8_t clip_mask = (props.
is_clipping () ? 0x7F : 0x40);
3145 uint8_t clip_ok = 0x40;
3147 for (
int i = 0; i < zc; i++)
3152 for (
int j = 0; j < zr; j++)
3157 if ((clip_code (
x(j1, i), y(j, i1), z(j, i)) & clip_mask)
3161 if ((do_edge && mecolor.
isempty ())
3162 || (do_face && mfcolor.
isempty ()))
3167 for (
int k = 0; k < 3; k++)
3185 octave_unused_parameter (props);
3200 #if defined (HAVE_OPENGL)
3206 warning (
"opengl_renderer: %s. Not rendering.", msg.c_str ());
3219 int fcmax =
f.columns ();
3221 bool has_z = (v.
columns () > 2);
3222 bool has_facecolor =
false;
3223 bool has_facealpha =
false;
3253 bool has_vertex_normals = (vn.
rows () == nv);
3255 bool has_face_normals = (fn.
rows () == nf);
3260 for (
int i = 0; i < nv; i++)
3261 clip(i) = is_nan_or_inf (v(i, 0), v(i, 1), v(i, 2));
3263 for (
int i = 0; i < nv; i++)
3264 clip(i) = is_nan_or_inf (v(i, 0), v(i, 1), 0);
3269 for (
int i = 0; i < nf; i++)
3274 for (
int j = 0; j < fcmax && !
math::isnan (
f(i, j)); j++, count++)
3275 fclip = (fclip || clip(
int (
f(i, j) - 1)));
3281 if (draw_all || fc_mode > 0 || ec_mode > 0)
3292 if (draw_all || fc_mode > 0)
3298 if (draw_all || ec_mode > 0)
3307 has_facecolor = ((c.
numel () > 0) && (c.
rows () ==
f.rows ()));
3310 if (fa_mode > 0 || ea_mode > 0)
3314 has_facealpha = ((a.
numel () > 0) && (a.
rows () ==
f.rows ()));
3321 std::vector<vertex_data> vdata (
f.numel ());
3323 for (
int i = 0; i < nf; i++)
3324 for (
int j = 0; j < count_f(i); j++)
3326 int idx = int (
f(i, j) - 1);
3334 vv(0) = v(idx, 0); vv(1) = v(idx, 1);
3337 if (((fl_mode ==
FLAT) || (el_mode ==
FLAT)) && has_face_normals)
3341 dir = ((fn(i, 0) * m_view_vector(0)
3342 + fn(i, 1) * m_view_vector(1)
3343 + fn(i, 2) * m_view_vector(2) < 0)
3344 ? ((bfl_mode > 1) ? 0.0 : -1.0) : 1.0);
3345 fnn(0) = dir * fn(i, 0);
3346 fnn(1) = dir * fn(i, 1);
3347 fnn(2) = dir * fn(i, 2);
3349 if ((fl_mode ==
GOURAUD || el_mode ==
GOURAUD) && has_vertex_normals)
3353 dir = ((vn(idx, 0) * m_view_vector(0)
3354 + vn(idx, 1) * m_view_vector(1)
3355 + vn(idx, 2) * m_view_vector(2) < 0)
3356 ? ((bfl_mode > 1) ? 0.0 : -1.0) : 1.0);
3357 vnn(0) = dir * vn(idx, 0);
3358 vnn(1) = dir * vn(idx, 1);
3359 vnn(2) = dir * vn(idx, 2);
3365 cc(0) = c(i, 0), cc(1) = c(i, 1), cc(2) = c(i, 2);
3367 cc(0) = c(idx, 0), cc(1) = c(idx, 1), cc(2) = c(idx, 2);
3371 else if (a.
numel () > 0)
3380 = vertex_data (vv, cc, vnn, fnn, aa, as, ds, ss, se, scr);
3383 if (fl_mode > 0 || el_mode > 0)
3396 float cb[4] = { 0.0f, 0.0f, 0.0f, 1.0f };
3398 for (
int i = 0; i < 3; i++)
3399 cb[i] = as * fcolor(i);
3402 for (
int i = 0; i < 3; i++)
3403 cb[i] = ds * fcolor(i);
3406 for (
int i = 0; i < 3; i++)
3407 cb[i] = ss * (scr + (1-scr) * fcolor(i));
3412 if ((fl_mode > 0) && do_lighting)
3419 patch_tessellator tess (
this, fc_mode, fl_mode,
true, 1.0);
3421 std::vector<octave_idx_type>::const_iterator it;
3424 for (
int i = 0; i < nf; i++)
3429 bool is_non_planar =
false;
3433 is_non_planar =
true;
3454 i_end = count_f(i) - 1;
3458 tess.begin_polygon (
true);
3459 tess.begin_contour ();
3462 for (
int j = i_end; j > i_start; j--)
3464 vertex_data::vertex_data_rep *vv
3465 = vdata[i+j*fr].get_rep ();
3467 tess.add_vertex (vv->m_coords.fortran_vec (), vv);
3472 vertex_data::vertex_data_rep *vv = vdata[i].get_rep ();
3474 if (fc_mode ==
FLAT)
3477 Matrix col = vv->m_color;
3479 if (col.
numel () == 3)
3484 float cb[4] = { 0.0f, 0.0f, 0.0f, 1.0f };
3486 for (
int k = 0; k < 3; k++)
3487 cb[k] = (vv->m_ambient * col(k));
3491 for (
int k = 0; k < 3; k++)
3492 cb[k] = (vv->m_diffuse * col(k));
3496 for (
int k = 0; k < 3; k++)
3497 cb[k] = vv->m_specular *
3498 (vv->m_specular_color_refl
3499 + (1-vv->m_specular_color_refl) *
3507 tess.add_vertex (vv->m_coords.fortran_vec (), vv);
3510 tess.end_contour ();
3511 tess.end_polygon ();
3513 while (i_start > 0);
3516 if ((fl_mode > 0) && do_lighting)
3537 float cb[4] = { 0.0f, 0.0f, 0.0f, 1.0f };
3541 for (
int i = 0; i < 3; i++)
3542 cb[i] = (as * ecolor(i));
3547 if ((el_mode > 0) && do_lighting)
3561 patch_tessellator tess (
this, ec_mode, el_mode,
false);
3563 for (
int i = 0; i < nf; i++)
3565 bool is_non_planar =
false;
3568 is_non_planar =
true;
3569 if (clip_f(i) || is_non_planar)
3577 ? GL_SMOOTH : GL_FLAT);
3580 for (
int j = count_f(i)-1; j >= 0; j--)
3582 if (! clip(
int (
f(i, j) - 1)))
3584 vertex_data::vertex_data_rep *vv
3585 = vdata[i+j*fr].get_rep ();
3586 const Matrix m = vv->m_coords;
3594 Matrix col = vv->m_color;
3596 if (col.
numel () == 3)
3609 int j = count_f(i)-1;
3610 if (flag && ! clip(
int (
f(i, j) - 1)))
3612 vertex_data::vertex_data_rep *vv
3613 = vdata[i+j*fr].get_rep ();
3614 const Matrix m = vv->m_coords;
3617 Matrix col = vv->m_color;
3619 if (col.
numel () == 3)
3630 tess.begin_polygon (
false);
3631 tess.begin_contour ();
3633 for (
int j = count_f(i)-1; j >= 0; j--)
3635 vertex_data::vertex_data_rep *vv
3636 = vdata[i+j*fr].get_rep ();
3637 tess.add_vertex (vv->m_coords.fortran_vec (), vv);
3640 tess.end_contour ();
3641 tess.end_polygon ();
3648 if ((el_mode > 0) && do_lighting)
3669 bool has_markerfacecolor = draw_all ||
false;
3676 if (mc.
rows () == 1)
3689 has_markerfacecolor = ((c.
numel () > 0)
3690 && (c.
rows () ==
f.rows ()));
3697 uint8_t clip_mask = (props.
is_clipping () ? 0x7F : 0x40);
3698 uint8_t clip_ok = 0x40;
3700 for (
int i = 0; i < nf; i++)
3701 for (
int j = 0; j < count_f(i); j++)
3703 int idx = int (
f(i, j) - 1);
3705 if ((clip_code (v(idx, 0), v(idx, 1), (has_z ? v(idx, 2) : 0))
3706 & clip_mask) != clip_ok)
3713 if (has_markerfacecolor)
3714 cc(0) = c(i, 0), cc(1) = c(i, 1), cc(2) = c(i, 2);
3716 cc(0) = c(idx, 0), cc(1) = c(idx, 1), cc(2) = c(idx, 2);
3724 draw_marker (v(idx, 0), v(idx, 1), (has_z ? v(idx, 2) : 0), lc, fc);
3732 octave_unused_parameter (props);
3745 #if defined (HAVE_OPENGL)
3751 warning (
"opengl_renderer: %s. Not rendering.", msg.c_str ());
3755 bool draw_all = m_selecting;
3757 if (draw_all || (! props.
marker_is (
"none")
3795 uint8_t clip_mask = (props.
is_clipping () ? 0x7F : 0x40);
3796 uint8_t clip_ok = 0x40;
3812 for (
int i = 0; i < np; i++)
3814 if ((clip_code (
x(i), y(i), (has_z ? z(i) : 0.0)) & clip_mask)
3833 draw_marker (
x(i), y(i), (has_z ? z(i) : 0.0), lc, fc, mea, mfa);
3841 octave_unused_parameter (props);
3854 #if defined (HAVE_OPENGL)
3860 float pos[4] = { 0, 0, 0, 0 };
3862 for (
int i = 0; i < 3; i++)
3869 float col[4] = { 1, 1, 1, 1 };
3871 for (
int i = 0; i < 3; i++)
3878 octave_unused_parameter (props);
3895 opengl_renderer::set_ortho_coordinates ()
3897 #if defined (HAVE_OPENGL)
3920 opengl_renderer::restore_previous_coordinates ()
3922 #if defined (HAVE_OPENGL)
3943 #if defined (HAVE_OPENGL)
3952 || (clip_code (pos(0), pos(1), pos.
numel () > 2 ? pos(2) : 0.0) == 0x40))
3968 octave_unused_parameter (props);
3982 #if defined (HAVE_OPENGL)
3995 set_ortho_coordinates ();
4006 double m = points_to_pixels (props.
get_margin ());
4050 restore_previous_coordinates ();
4054 octave_unused_parameter (props);
4067 #if defined (HAVE_OPENGL)
4073 draw_texture_image (cdata,
x, y);
4077 octave_unused_parameter (props);
4091 #if defined (HAVE_OPENGL)
4096 double x0, x1, y0, y1;
4100 dx = (
x(1) -
x(0)) / (
w - 1);
4107 dy = (y(1) - y(0)) / (h - 1);
4113 if (dv.ndims () == 3 && (dv(2) == 3 || dv(2) == 4))
4115 opengl_texture tex = opengl_texture::create (
m_glfcns, cdata);
4116 if (tex.is_valid ())
4124 tex.tex_coord (0.0, 0.0);
4130 tex.tex_coord (1.0, 0.0);
4136 tex.tex_coord (1.0, 1.0);
4142 tex.tex_coord (0.0, 1.0);
4153 warning (
"opengl_renderer: invalid image size (expected MxNx3 or MxN)");
4157 octave_unused_parameter (cdata);
4158 octave_unused_parameter (
x);
4159 octave_unused_parameter (y);
4160 octave_unused_parameter (ortho);
4177 for (
int i =
len-1; i >= 0; i--)
4182 draw (obj, toplevel);
4189 #if defined (HAVE_OPENGL)
4195 octave_unused_parameter (
w);
4196 octave_unused_parameter (h);
4209 Matrix retval (1, 4, 0.0);
4211 #if defined (HAVE_OPENGL)
4212 #if defined (HAVE_FRAMEWORK_OPENGL)
4220 for (
int i = 0; i < 4; i++)
4238 #if defined (HAVE_OPENGL)
4247 octave_unused_parameter (c);
4260 bool do_anti_alias = props.
get (
"fontsmoothing").
string_value () ==
"on";
4272 #if defined (HAVE_OPENGL)
4288 octave_unused_parameter (on);
4289 octave_unused_parameter (offset);
4302 #if defined (HAVE_OPENGL)
4308 octave_unused_parameter (
w);
4322 #if defined (HAVE_OPENGL)
4328 uint16_t pattern = 0xFFFF;
4360 if (solid && ! use_stipple)
4367 octave_unused_parameter (s);
4368 octave_unused_parameter (use_stipple);
4369 octave_unused_parameter (linewidth);
4381 double z1,
double z2)
4383 #if defined (HAVE_OPENGL)
4385 double dx = (x2-x1);
4386 double dy = (y2-y1);
4387 double dz = (z2-z1);
4389 x1 -= 0.001*dx; x2 += 0.001*dx;
4390 y1 -= 0.001*dy; y2 += 0.001*dy;
4391 z1 -= 0.001*dz; z2 += 0.001*dz;
4395 p(0) = -1; p(3) = x2;
4397 p(0) = 1; p(3) = -x1;
4399 p(0) = 0; p(1) = -1; p(3) = y2;
4401 p(1) = 1; p(3) = -y1;
4403 p(1) = 0; p(2) = -1; p(3) = z2;
4405 p(2) = 1; p(3) = -z1;
4414 octave_unused_parameter (x1);
4415 octave_unused_parameter (x2);
4416 octave_unused_parameter (y1);
4417 octave_unused_parameter (y2);
4418 octave_unused_parameter (z1);
4419 octave_unused_parameter (z2);
4432 #if defined (HAVE_OPENGL)
4436 if (enable != has_clipping)
4439 for (
int i = 0; i < 6; i++)
4442 for (
int i = 0; i < 6; i++)
4448 octave_unused_parameter (enable);
4461 #if defined (HAVE_OPENGL)
4474 m_marker_id = make_marker_list (
m, size,
false);
4475 m_filled_marker_id = make_marker_list (
m, size,
true);
4479 octave_unused_parameter (
m);
4480 octave_unused_parameter (size);
4481 octave_unused_parameter (width);
4494 #if defined (HAVE_OPENGL)
4496 m_marker_id = make_marker_list (
m, size,
false);
4497 m_filled_marker_id = make_marker_list (
m, size,
true);
4501 octave_unused_parameter (
m);
4502 octave_unused_parameter (size);
4515 #if defined (HAVE_OPENGL)
4539 const double la,
const double fa)
4541 #if defined (HAVE_OPENGL)
4548 if (m_filled_marker_id > 0 && fc.
numel () > 0)
4553 if (lc.
numel () > 0)
4564 else if (m_marker_id > 0 && lc.
numel () > 0)
4572 octave_unused_parameter (
x);
4573 octave_unused_parameter (y);
4574 octave_unused_parameter (z);
4575 octave_unused_parameter (lc);
4576 octave_unused_parameter (fc);
4577 octave_unused_parameter (la);
4578 octave_unused_parameter (fa);
4589 opengl_renderer::init_maxlights ()
4591 #if defined (HAVE_OPENGL)
4594 if (m_max_lights == 0)
4598 m_max_lights = max_lights;
4612 opengl_renderer::get_string (
unsigned int id)
const
4614 #if defined (HAVE_OPENGL)
4620 std::ostringstream buf;
4624 return std::string (buf.str ());
4628 octave_unused_parameter (
id);
4634 return std::string ();
4640 opengl_renderer::set_normal (
int bfl_mode,
const NDArray&
n,
int j,
int i)
4642 #if defined (HAVE_OPENGL)
4644 double x =
n(j, i, 0);
4645 double y =
n(j, i, 1);
4646 double z =
n(j, i, 2);
4648 double d = sqrt (
x*
x + y*y + z*z);
4653 dir = ((
x*m_view_vector(0) + y*m_view_vector(1) + z*m_view_vector(2) < 0)
4654 ? ((bfl_mode > 1) ? 0.0 : -1.0) : 1.0);
4660 octave_unused_parameter (bfl_mode);
4661 octave_unused_parameter (
n);
4662 octave_unused_parameter (j);
4663 octave_unused_parameter (i);
4674 opengl_renderer::points_to_pixels (
const double val)
const
4680 static const double pix_per_pts =
4683 double retval = val;
4686 retval *= pix_per_pts;
4692 opengl_renderer::make_marker_list (
const std::string& marker,
double size,
4695 #if defined (HAVE_OPENGL)
4699 if (filled && (c ==
'+' || c ==
'x' || c ==
'*' || c ==
'.'
4700 || c ==
'|' || c ==
'_'))
4706 double sz = points_to_pixels (size);
4709 const double sqrt2d4 = 0.35355339059327;
4710 double tt = sz*sqrt2d4;
4761 if (sz > 0 && sz < 3)
4764 int div =
static_cast<int> (M_PI * sz / 12);
4768 double ang_step = M_PI / div;
4771 for (
double ang = 0; ang < 2*M_PI; ang += ang_step)
4786 int div =
static_cast<int> (M_PI * sz / 4);
4790 double ang_step = M_PI / div;
4793 for (
double ang = 0; ang < 2*M_PI; ang += ang_step)
4837 dr = 1.0 - sin (M_PI/10)/sin (3*M_PI/10)*1.02;
4840 for (
int i = 0; i < 2*5; i++)
4842 ang = (-0.5 + double (i+1) / 5) * M_PI;
4843 r = 1.0 - (dr * fmod (
double (i+1), 2.0));
4852 dr = 1.0 - 0.5/sin (M_PI/3)*1.02;
4855 for (
int i = 0; i < 2*6; i++)
4857 ang = (0.5 + double (i+1) / 6.0) * M_PI;
4858 r = 1.0 - (dr * fmod (
double (i+1), 2.0));
4865 warning (
"opengl_renderer: unsupported marker '%s'", marker.c_str ());
4875 octave_unused_parameter (marker);
4876 octave_unused_parameter (size);
4877 octave_unused_parameter (filled);
4891 int halign,
int valign,
double rotation)
4893 m_txt_renderer.
text_to_pixels (txt, pixels, bbox, halign, valign,
4894 rotation, m_interpreter);
4899 std::list<text_renderer::string>& lst,
4901 int halign,
int valign,
double rotation)
4904 rotation, m_interpreter);
4909 double x,
double y,
double z,
4910 int halign,
int valign,
double rotation)
4912 #if defined (HAVE_OPENGL)
4919 if (m_txt_renderer.
ok ())
4931 octave_unused_parameter (txt);
4932 octave_unused_parameter (
x);
4933 octave_unused_parameter (y);
4934 octave_unused_parameter (z);
4935 octave_unused_parameter (halign);
4936 octave_unused_parameter (valign);
4937 octave_unused_parameter (rotation);
4949 double x,
double y,
double z,
double rotation)
4951 #if defined (HAVE_OPENGL)
4964 set_ortho_coordinates ();
4976 draw_texture_image (pixels.
permute (perm),
4977 xdata, ydata,
true);
4979 restore_previous_coordinates ();
4988 octave_unused_parameter (pixels);
4989 octave_unused_parameter (bbox);
4990 octave_unused_parameter (
x);
4991 octave_unused_parameter (y);
4992 octave_unused_parameter (z);
4993 octave_unused_parameter (rotation);
5003 OCTAVE_END_NAMESPACE(
octave)
charNDArray max(char d, const charNDArray &m)
charNDArray min(char d, const charNDArray &m)
T * fortran_vec()
Size of the specified dimension.
octave_idx_type rows() const
const T * data() const
Size of the specified dimension.
octave_idx_type columns() const
bool isempty() const
Size of the specified dimension.
const dim_vector & dims() const
Return a const-reference so that dims ()(i) works efficiently.
octave_idx_type numel() const
Number of elements in the array.
MArray< T > permute(const Array< octave_idx_type > &vec, bool inv=false) const
void resize(octave_idx_type nr, octave_idx_type nc, double rfv=0)
bool yscale_is(const std::string &v) const
double get_gridalpha() const
octave_value get_xtick() const
unsigned int get_num_lights() const
bool ycolormode_is(const std::string &v) const
octave_value get_cameraposition() const
double get_xtickoffset() const
bool layer_is(const std::string &v) const
double get_ytickoffset() const
Matrix get_ambientlightcolor_rgb() const
Matrix get_opengl_matrix_1() const
bool xscale_is(const std::string &v) const
bool zcolormode_is(const std::string &v) const
bool is_yminortick() const
std::string get_minorgridlinestyle() const
graphics_handle get_xlabel() const
double get_yPlane() const
octave_value get_xminortickvalues() const
double get_minorgridalpha() const
graphics_handle get_ylabel() const
bool is_xminortick() const
double get_ypTick() const
bool get_layer2Dtop() const
bool get_is2D(bool include_kids=false) const
double get_ypTickN() const
octave_value get_zticklabel() const
double get_linewidth() const
octave_value get_xticklabel() const
bool get_nearhoriz() const
Matrix get_minorgridcolor_rgb() const
double get_xpTick() const
double get_ztickoffset() const
octave_value get_ytick() const
bool is_zminortick() const
Matrix get_zcolor_rgb() const
bool is_yminorgrid() const
graphics_xform get_transform() const
std::string get_gridlinestyle() const
octave_value get_yticklabel() const
double get_yticklen() const
Matrix get_opengl_matrix_2() const
double get_xPlane() const
Matrix get_xcolor_rgb() const
std::string get_boxstyle() const
graphics_handle get_zlabel() const
bool get_y2Dright() const
Matrix get_ycolor_rgb() const
std::string get_box() const
bool ycolor_is(const std::string &v) const
Matrix get_gridcolor_rgb() const
bool has_property(const caseless_str &pname) const
octave_value get_zminortickvalues() const
octave_value get_yminortickvalues() const
Matrix get_transform_zlim() const
double get_zPlane() const
double get_zpTickN() const
bool tickdir_is(const std::string &v) const
double get_xpTickN() const
bool is_xminorgrid() const
bool xaxislocation_is(const std::string &v) const
double get_zticklen() const
double get_zpTick() const
bool gridcolormode_is(const std::string &v) const
bool zcolor_is(const std::string &v) const
octave_value get_color() const
bool is_zminorgrid() const
octave_value get_ztick() const
bool xcolor_is(const std::string &v) const
double get_yPlaneN() const
bool xcolormode_is(const std::string &v) const
Matrix get_color_rgb() const
double get_xticklen() const
double get_xPlaneN() const
bool minorgridcolormode_is(const std::string &v) const
double get_zPlaneN() const
std::string get_ticklabelinterpreter() const
bool yaxislocation_is(const std::string &v) const
virtual octave::graphics_toolkit get_toolkit() const
graphics_handle get___myhandle__() const
bool pickableparts_is(const std::string &v) const
virtual octave_value get(const caseless_str &pname) const
Matrix get_all_children() const
Matrix get_children() const
virtual std::string graphics_object_name() const
std::string get_tag() const
Vector representing the dimensions (size) of an Array.
graphics_object get_object(double val) const
octave_value get(bool all=false) const
void set(const caseless_str &name, const octave_value &val)
graphics_object get_ancestor(const std::string &type) const
base_properties & get_properties()
bool isa(const std::string &go_name) const
bool valid_object() const
static const idx_vector colon
static idx_vector make_range(octave_idx_type start, octave_idx_type step, octave_idx_type len)
octave_value get_xdata() const
octave_value get_color_data() const
octave_value get_ydata() const
octave_value get_position() const
bool style_is(const std::string &v) const
octave_value get_color() const
std::string get_marker() const
bool marker_is(const std::string &v) const
Matrix get_color_rgb() const
double get_linewidth() const
bool markeredgecolor_is(const std::string &v) const
double get_markersize() const
std::string get_linestyle() const
Matrix get_markeredgecolor_rgb() const
bool markerfacecolor_is(const std::string &v) const
bool linestyle_is(const std::string &v) const
bool color_is(const std::string &v) const
octave_value get_ydata() const
std::string get_linejoin() const
octave_value get_zdata() const
Matrix get_markerfacecolor_rgb() const
octave_value get_xdata() const
uint16NDArray uint16_array_value() const
bool is_single_type() const
bool is_uint8_type() const
bool is_uint16_type() const
std::string string_value(bool force=false) const
string_vector string_vector_value(bool pad=false) const
NDArray array_value(bool frc_str_conv=false) const
bool is_double_type() const
uint8NDArray uint8_array_value() const
FloatNDArray float_array_value(bool frc_str_conv=false) const
Matrix matrix_value(bool frc_str_conv=false) const
double double_value(bool frc_str_conv=false) const
virtual GLboolean glIsEnabled(GLenum cap)
virtual void glHint(GLenum target, GLenum mode)
virtual void glGetIntegerv(GLenum pname, GLint *data)
virtual void glBegin(GLenum mode)
virtual void glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels)
virtual void glClipPlane(GLenum plane, const GLdouble *equation)
virtual void glMatrixMode(GLenum mode)
virtual void glBindTexture(GLenum target, GLuint texture)
virtual const GLubyte * glGetString(GLenum name)
virtual void glVertex2d(GLdouble x, GLdouble y)
virtual void glNewList(GLuint list, GLenum mode)
virtual void glPopMatrix()
virtual void glVertex3d(GLdouble x, GLdouble y, GLdouble z)
virtual void glLineStipple(GLint factor, GLushort pattern)
virtual void glLoadIdentity()
virtual void glPolygonOffset(GLfloat factor, GLfloat units)
virtual void glLineWidth(GLfloat width)
virtual void glColor3fv(const GLfloat *v)
virtual void glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
virtual void glColor4d(GLdouble red, GLdouble green, GLdouble blue, GLdouble alpha)
virtual void glRotated(GLdouble angle, GLdouble x, GLdouble y, GLdouble z)
virtual void glGenTextures(GLsizei n, GLuint *textures)
virtual void glDisable(GLenum cap)
virtual void glCallList(GLuint list)
virtual void glDepthFunc(GLenum fcn)
virtual void glClear(GLbitfield mask)
virtual void glNormal3dv(const GLdouble *v)
virtual void glColor3f(GLfloat red, GLfloat green, GLfloat blue)
virtual void glColor4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
virtual void glVertex3dv(const GLdouble *v)
virtual void glNormal3d(GLdouble nx, GLdouble ny, GLdouble nz)
virtual void glAlphaFunc(GLenum fcn, GLclampf ref)
virtual void glMaterialf(GLenum face, GLenum pname, GLfloat param)
virtual void glPolygonMode(GLenum face, GLenum mode)
virtual void glClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
virtual void glColor3dv(const GLdouble *v)
virtual GLuint glGenLists(GLsizei range)
virtual void glDeleteLists(GLuint list, GLsizei range)
virtual void glColor4fv(const GLfloat *v)
virtual void glTexParameteri(GLenum target, GLenum pname, GLint param)
virtual void glPopAttrib()
virtual void glEnable(GLenum cap)
virtual void glGetBooleanv(GLenum pname, GLboolean *data)
virtual void glBlendFunc(GLenum sfactor, GLenum dfactor)
virtual void glShadeModel(GLenum mode)
virtual void glEdgeFlag(GLboolean flag)
virtual void glOrtho(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near_val, GLdouble far_val)
virtual void glTexImage2D(GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels)
virtual void glPushAttrib(GLbitfield mask)
virtual void glMultMatrixd(const GLdouble *m)
virtual void glPixelStorei(GLenum pname, GLint param)
virtual void glPushMatrix()
virtual void glScaled(GLdouble x, GLdouble y, GLdouble z)
virtual void glLightfv(GLenum light, GLenum pname, const GLfloat *params)
virtual GLenum glGetError()
virtual void glTranslated(GLdouble x, GLdouble y, GLdouble z)
virtual void glMaterialfv(GLenum face, GLenum pname, const GLfloat *params)
virtual uint8NDArray get_pixels(int width, int height)
virtual void draw_patch(const patch::properties &props)
opengl_functions & m_glfcns
virtual void init_marker(const std::string &m, double size, float width)
virtual void set_linestyle(const std::string &s, bool stipple=false, double linewidth=0.5)
virtual void set_clipping(bool on)
virtual void text_to_pixels(const std::string &txt, uint8NDArray &pixels, Matrix &bbox, int halign=0, int valign=0, double rotation=0.0)
virtual void set_linewidth(float w)
virtual void draw_scatter(const scatter::properties &props)
virtual Matrix get_viewport_scaled() const
virtual void draw_line(const line::properties &props)
virtual void draw_uibuttongroup(const uibuttongroup::properties &props, const graphics_object &go)
opengl_renderer(opengl_functions &glfcns)
virtual void draw_text_background(const text::properties &props, bool do_rotate=false)
virtual Matrix render_text(const std::string &txt, double x, double y, double z, int halign, int valign, double rotation=0.0)
virtual void draw_image(const image::properties &props)
virtual void render_grid(const double linewidth, const std::string &gridstyle, const Matrix &gridcolor, const double gridalpha, const Matrix &ticks, double lim1, double lim2, double p1, double p1N, double p2, double p2N, int xyz, bool is_3D)
virtual void draw_marker(double x, double y, double z, const Matrix &lc, const Matrix &fc, const double la=1.0, const double fa=1.0)
virtual void init_gl_context(bool enhanced, const Matrix &backgroundColor)
virtual void draw(const graphics_object &go, bool toplevel=true)
virtual void draw_hggroup(const hggroup::properties &props)
virtual void draw_axes(const axes::properties &props)
virtual void change_marker(const std::string &m, double size)
virtual void set_polygon_offset(bool on, float offset=0.0f)
virtual void draw_surface(const surface::properties &props)
virtual void draw_uipanel(const uipanel::properties &props, const graphics_object &go)
virtual void draw_zoom_rect(int x1, int y1, int x2, int y2)
virtual void set_interpreter(const caseless_str &interp)
virtual void render_ticktexts(const Matrix &ticks, const string_vector &ticklabels, double lim1, double lim2, double p1, double p2, int xyz, int ha, int va, int &wmax, int &hmax)
virtual void draw_light(const light::properties &props)
virtual void draw_zoom_box(int width, int height, int x1, int y1, int x2, int y2, const Matrix &overlaycolor, double overlayalpha, const Matrix &bordercolor, double borderalpha, double borderwidth)
virtual void end_marker()
virtual void set_viewport(int w, int h)
virtual graphics_xform get_transform() const
virtual void draw_text(const text::properties &props)
virtual void set_font(const base_properties &props)
virtual void set_linecap(const std::string &)
virtual void draw_figure(const figure::properties &props)
virtual void render_tickmarks(const Matrix &ticks, double lim1, double lim2, double p1, double p1N, double p2, double p2N, double dx, double dy, double dz, int xyz, bool doubleside)
virtual void text_to_strlist(const std::string &txt, std::list< text_renderer::string > &lst, Matrix &bbox, int halign=0, int valign=0, double rotation=0.0)
virtual void set_clipbox(double x1, double x2, double y1, double y2, double z1, double z2)
virtual void setup_opengl_transformation(const axes::properties &props)
virtual void set_linejoin(const std::string &)
virtual void set_color(const Matrix &c)
double get_ambientstrength() const
bool edgealpha_is_double() const
bool has_bad_data(std::string &msg) const
bool linestyle_is(const std::string &v) const
bool backfacelighting_is(const std::string &v) const
bool edgecolor_is_rgb() const
double get_markersize() const
bool markerfacecolor_is(const std::string &v) const
bool markeredgecolor_is(const std::string &v) const
double get_linewidth() const
bool marker_is(const std::string &v) const
bool facealpha_is(const std::string &v) const
double get_specularstrength() const
Matrix get_markeredgecolor_rgb() const
double get_edgealpha_double() const
double get_diffusestrength() const
octave_value get_vertices() const
bool facecolor_is_rgb() const
bool edgelighting_is(const std::string &v) const
std::string get_marker() const
octave_value get_color_data() const
double get_specularexponent() const
double get_specularcolorreflectance() const
std::string get_linestyle() const
bool facelighting_is(const std::string &v) const
Matrix get_edgecolor_rgb() const
bool edgealpha_is(const std::string &v) const
double get_facealpha_double() const
bool facealpha_is_double() const
Matrix get_markerfacecolor_rgb() const
octave_value get_vertexnormals() const
bool get_do_lighting() const
octave_value get_facenormals() const
bool edgecolor_is(const std::string &v) const
Matrix get_facecolor_rgb() const
std::vector< std::vector< octave_idx_type > > m_coplanar_last_idx
octave_value get_faces() const
bool facecolor_is(const std::string &v) const
bool markeredgecolor_is(const std::string &v) const
octave_value get_zdata() const
bool marker_is(const std::string &v) const
std::string get_marker() const
double get_linewidth() const
double get_markerfacealpha() const
octave_value get_sizedata() const
octave_value get_xdata() const
Matrix get_markeredgecolor_rgb() const
octave_value get_ydata() const
double get_markeredgealpha() const
octave_value get_color_data() const
bool markerfacecolor_is(const std::string &v) const
Matrix get_markerfacecolor_rgb() const
bool has_bad_data(std::string &msg) const
octave_idx_type numel() const
bool edgealpha_is(const std::string &v) const
bool backfacelighting_is(const std::string &v) const
octave_value get_ydata() const
octave_value get_xdata() const
double get_markersize() const
Matrix get_markerfacecolor_rgb() const
bool facealpha_is(const std::string &v) const
bool get_do_lighting() const
bool facelighting_is(const std::string &v) const
octave_value get_color_data() const
double get_diffusestrength() const
bool edgecolor_is(const std::string &v) const
Matrix get_markeredgecolor_rgb() const
bool meshstyle_is(const std::string &v) const
double get_edgealpha_double() const
double get_ambientstrength() const
Matrix get_facecolor_rgb() const
double get_specularstrength() const
double get_linewidth() const
bool edgelighting_is(const std::string &v) const
bool facecolor_is(const std::string &v) const
bool linestyle_is(const std::string &v) const
octave_value get_vertexnormals() const
bool facealpha_is_double() const
double get_specularcolorreflectance() const
bool marker_is(const std::string &v) const
double get_specularexponent() const
std::string get_linestyle() const
octave_value get_zdata() const
octave_value get_facenormals() const
bool facecolor_is_rgb() const
bool markerfacecolor_is(const std::string &v) const
bool edgecolor_is_rgb() const
double get_facealpha_double() const
std::string get_marker() const
bool edgealpha_is_double() const
Matrix get_edgecolor_rgb() const
bool markeredgecolor_is(const std::string &v) const
std::string get_linestyle() const
Matrix get_data_position() const
octave_value get_string() const
double get_margin() const
double get_linewidth() const
Matrix get_edgecolor_rgb() const
Matrix get_backgroundcolor_rgb() const
Matrix get_extent_matrix(bool rotated=false) const
double get_rotation() const
const uint8NDArray & get_pixels() const
bool color_is(const std::string &v) const
void text_to_strlist(const std::string &txt, std::list< string > &lst, Matrix &box, int halign, int valign, double rotation=0.0, const caseless_str &interpreter="tex")
void text_to_pixels(const std::string &txt, uint8NDArray &pxls, Matrix &bbox, int halign, int valign, double rotation=0.0, const caseless_str &interpreter="tex", bool handle_rotation=true)
void set_anti_aliasing(bool val)
void set_color(const Matrix &c)
void set_font(const std::string &name, const std::string &weight, const std::string &angle, double size)
Matrix get_backgroundcolor_rgb() const
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
void warning(const char *fmt,...)
void warning_with_id(const char *id, const char *fmt,...)
void() error(const char *fmt,...)
#define panic_impossible()
void err_disabled_feature(const std::string &fcn, const std::string &feature, const std::string &pkg)
gh_manager & __get_gh_manager__()
F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE * d
F77_RET_T const F77_DBLE * x
F77_RET_T const F77_DBLE const F77_DBLE * f
std::complex< double > w(std::complex< double > z, double relerr=0)
#define OCTAVE_LOCAL_BUFFER(T, buf, size)