Mercurial > octave
comparison src/graphics.cc @ 11167:51ac3a08e53c
Fix {d,pb}aspectratios for OpenGL backends.
author | Konstantinos Poulios <logari81@googlemail.com> |
---|---|
date | Thu, 28 Oct 2010 14:12:46 +0200 |
parents | 31e7e9f94850 |
children | 36442102c340 |
comparison
equal
deleted
inserted
replaced
11166:9cdf43d1fa16 | 11167:51ac3a08e53c |
---|---|
3909 zd/(zlimits(1)-zlimits(0))); | 3909 zd/(zlimits(1)-zlimits(0))); |
3910 translate (x_gl_mat1, -xo, -yo, -zo); | 3910 translate (x_gl_mat1, -xo, -yo, -zo); |
3911 x_gl_mat2 = x_viewport * x_projection; | 3911 x_gl_mat2 = x_viewport * x_projection; |
3912 } | 3912 } |
3913 | 3913 |
3914 static void | |
3915 normalized_aspectratios (Matrix& aspectratios, const Matrix& scalefactors, | |
3916 double xlength, double ylength, double zlength) | |
3917 { | |
3918 double xval = xlength/scalefactors(0); | |
3919 double yval = ylength/scalefactors(1); | |
3920 double zval = zlength/scalefactors(2); | |
3921 | |
3922 double minval = xmin (xmin (xval, yval), zval); | |
3923 | |
3924 aspectratios(0) = xval/minval; | |
3925 aspectratios(1) = yval/minval; | |
3926 aspectratios(2) = zval/minval; | |
3927 } | |
3928 | |
3929 static void | |
3930 max_axes_scale (double& s, Matrix& limits, const Matrix& kids, | |
3931 double pbfactor, double dafactor, char limit_type, bool tight) | |
3932 { | |
3933 if (tight) | |
3934 { | |
3935 double minval = octave_Inf; | |
3936 double maxval = -octave_Inf; | |
3937 double min_pos = octave_Inf; | |
3938 get_children_limits (minval, maxval, min_pos, kids, limit_type); | |
3939 if (!xisinf (minval) && !xisnan (minval) | |
3940 && !xisinf (maxval) && !xisnan (maxval)) | |
3941 { | |
3942 limits(0) = minval; | |
3943 limits(1) = maxval; | |
3944 s = xmax(s, (maxval - minval) / (pbfactor * dafactor)); | |
3945 } | |
3946 } | |
3947 else | |
3948 s = xmax(s, (limits(1) - limits(0)) / (pbfactor * dafactor)); | |
3949 } | |
3950 | |
3951 static bool updating_aspectratios = false; | |
3952 | |
3914 void | 3953 void |
3915 axes::properties::update_aspectratios (void) | 3954 axes::properties::update_aspectratios (void) |
3916 { | 3955 { |
3956 if (updating_aspectratios) | |
3957 return; | |
3958 | |
3917 Matrix xlimits = get_xlim ().matrix_value (); | 3959 Matrix xlimits = get_xlim ().matrix_value (); |
3918 Matrix ylimits = get_ylim ().matrix_value (); | 3960 Matrix ylimits = get_ylim ().matrix_value (); |
3919 Matrix zlimits = get_zlim ().matrix_value (); | 3961 Matrix zlimits = get_zlim ().matrix_value (); |
3920 | 3962 |
3921 double dx = (xlimits(1)-xlimits(0)); | 3963 double dx = (xlimits(1)-xlimits(0)); |
3922 double dy = (ylimits(1)-ylimits(0)); | 3964 double dy = (ylimits(1)-ylimits(0)); |
3923 double dz = (zlimits(1)-zlimits(0)); | 3965 double dz = (zlimits(1)-zlimits(0)); |
3924 | 3966 |
3967 Matrix da = get_dataaspectratio ().matrix_value (); | |
3968 Matrix pba = get_plotboxaspectratio ().matrix_value (); | |
3969 | |
3925 if (dataaspectratiomode_is ("auto")) | 3970 if (dataaspectratiomode_is ("auto")) |
3926 { | 3971 { |
3927 double dmin = xmin (xmin (dx, dy), dz); | 3972 if (plotboxaspectratiomode_is ("auto")) |
3928 Matrix da (1, 3, 0.0); | 3973 { |
3929 | 3974 pba = Matrix (1, 3, 1.0); |
3930 da(0) = dx/dmin; | 3975 plotboxaspectratio.set (pba, false); |
3931 da(1) = dy/dmin; | 3976 } |
3932 da(2) = dz/dmin; | 3977 |
3933 | 3978 normalized_aspectratios (da, pba, dx, dy, dz); |
3934 dataaspectratio = da; | 3979 dataaspectratio.set (da, false); |
3935 } | 3980 } |
3936 | 3981 else if (plotboxaspectratiomode_is ("auto")) |
3937 if (plotboxaspectratiomode_is ("auto")) | 3982 { |
3938 { | 3983 normalized_aspectratios (pba, da, dx, dy, dz); |
3939 if (dataaspectratiomode_is ("auto")) | 3984 plotboxaspectratio.set (pba, false); |
3940 plotboxaspectratio = Matrix (1, 3, 1.0); | 3985 } |
3986 else | |
3987 { | |
3988 double s = -octave_Inf; | |
3989 bool modified_limits = false; | |
3990 Matrix kids; | |
3991 | |
3992 if (xlimmode_is ("auto") && ylimmode_is ("auto") && zlimmode_is ("auto")) | |
3993 { | |
3994 modified_limits = true; | |
3995 kids = get_children (); | |
3996 max_axes_scale (s, xlimits, kids, pba(0), da(0), 'x', true); | |
3997 max_axes_scale (s, ylimits, kids, pba(1), da(1), 'y', true); | |
3998 max_axes_scale (s, zlimits, kids, pba(2), da(2), 'z', true); | |
3999 } | |
4000 else if (xlimmode_is ("auto") && ylimmode_is ("auto")) | |
4001 { | |
4002 modified_limits = true; | |
4003 max_axes_scale (s, zlimits, kids, pba(2), da(2), 'z', false); | |
4004 } | |
4005 else if (ylimmode_is ("auto") && zlimmode_is ("auto")) | |
4006 { | |
4007 modified_limits = true; | |
4008 max_axes_scale (s, xlimits, kids, pba(0), da(0), 'x', false); | |
4009 } | |
4010 else if (zlimmode_is ("auto") && xlimmode_is ("auto")) | |
4011 { | |
4012 modified_limits = true; | |
4013 max_axes_scale (s, ylimits, kids, pba(1), da(1), 'y', false); | |
4014 } | |
4015 | |
4016 if (modified_limits) | |
4017 { | |
4018 | |
4019 unwind_protect frame; | |
4020 frame.protect_var (updating_aspectratios); | |
4021 | |
4022 updating_aspectratios = true; | |
4023 | |
4024 dx = pba(0) *da(0); | |
4025 dy = pba(1) *da(1); | |
4026 dz = pba(2) *da(2); | |
4027 if (xisinf (s)) | |
4028 s = 1 / xmin (xmin (dx, dy), dz); | |
4029 | |
4030 if (xlimmode_is ("auto")) | |
4031 { | |
4032 dx = s * dx; | |
4033 xlimits(0) = 0.5 * (xlimits(0) + xlimits(1) - dx); | |
4034 xlimits(1) = xlimits(0) + dx; | |
4035 set_xlim (xlimits); | |
4036 set_xlimmode ("auto"); | |
4037 } | |
4038 | |
4039 if (ylimmode_is ("auto")) | |
4040 { | |
4041 dy = s * dy; | |
4042 ylimits(0) = 0.5 * (ylimits(0) + ylimits(1) - dy); | |
4043 ylimits(1) = ylimits(0) + dy; | |
4044 set_ylim (ylimits); | |
4045 set_ylimmode ("auto"); | |
4046 } | |
4047 | |
4048 if (zlimmode_is ("auto")) | |
4049 { | |
4050 dz = s * dz; | |
4051 zlimits(0) = 0.5 * (zlimits(0) + zlimits(1) - dz); | |
4052 zlimits(1) = zlimits(0) + dz; | |
4053 set_zlim (zlimits); | |
4054 set_zlimmode ("auto"); | |
4055 } | |
4056 } | |
3941 else | 4057 else |
3942 { | 4058 { |
3943 Matrix da = get_dataaspectratio ().matrix_value (); | 4059 normalized_aspectratios (pba, da, dx, dy, dz); |
3944 Matrix pba (1, 3, 0.0); | 4060 plotboxaspectratio.set (pba, false); |
3945 | 4061 } |
3946 pba(0) = dx/da(0); | 4062 } |
3947 pba(1) = dy/da(1); | |
3948 pba(2) = dz/da(2); | |
3949 } | |
3950 } | |
3951 | |
3952 // FIXME -- if plotboxaspectratiomode is "manual", limits | |
3953 // and/or dataaspectratio might be adapted. | |
3954 } | 4063 } |
3955 | 4064 |
3956 // The INTERNAL flag defines whether position or outerposition is used. | 4065 // The INTERNAL flag defines whether position or outerposition is used. |
3957 | 4066 |
3958 Matrix | 4067 Matrix |
4446 static bool updating_axis_limits = false; | 4555 static bool updating_axis_limits = false; |
4447 | 4556 |
4448 void | 4557 void |
4449 axes::update_axis_limits (const std::string& axis_type) | 4558 axes::update_axis_limits (const std::string& axis_type) |
4450 { | 4559 { |
4451 if (updating_axis_limits) | 4560 if (updating_axis_limits || updating_aspectratios) |
4452 return; | 4561 return; |
4453 | 4562 |
4454 Matrix kids = xproperties.get_children (); | 4563 Matrix kids = xproperties.get_children (); |
4455 | 4564 |
4456 double min_val = octave_Inf; | 4565 double min_val = octave_Inf; |