Mercurial > octave-nkf
comparison src/graphics.cc @ 7447:25018e35b4cb
[project @ 2008-02-05 22:38:57 by jwe]
author | jwe |
---|---|
date | Tue, 05 Feb 2008 22:40:52 +0000 |
parents | 4bfbec4b0e24 |
children | b1cfd33a364b |
comparison
equal
deleted
inserted
replaced
7446:4bfbec4b0e24 | 7447:25018e35b4cb |
---|---|
1417 xset (0, "currentfigure", cf.value ()); | 1417 xset (0, "currentfigure", cf.value ()); |
1418 } | 1418 } |
1419 } | 1419 } |
1420 | 1420 |
1421 Matrix | 1421 Matrix |
1422 figure::properties::get_boundingbox (void) const | 1422 figure::properties::get_boundingbox (bool) const |
1423 { | 1423 { |
1424 graphics_backend b = get_backend (); | 1424 graphics_backend b = get_backend (); |
1425 // FIXME: screen size should be obtained from root object | 1425 // FIXME: screen size should be obtained from root object |
1426 Matrix screen_size = b.get_screen_size (); | 1426 Matrix screen_size = b.get_screen_size (); |
1427 Matrix pos; | 1427 Matrix pos; |
1429 pos = convert_position (get_position ().matrix_value (), get_units (), | 1429 pos = convert_position (get_position ().matrix_value (), get_units (), |
1430 "pixels", screen_size, b); | 1430 "pixels", screen_size, b); |
1431 | 1431 |
1432 pos(0)--; | 1432 pos(0)--; |
1433 pos(1)--; | 1433 pos(1)--; |
1434 pos(1) = screen_size(1) - pos(1) - pos(3); | |
1434 | 1435 |
1435 return pos; | 1436 return pos; |
1436 } | 1437 } |
1437 | 1438 |
1438 octave_value | 1439 octave_value |
1954 Matrix x_cube = x_view * unit_cube (); | 1955 Matrix x_cube = x_view * unit_cube (); |
1955 ColumnVector cmin = x_cube.row_min (), cmax = x_cube.row_max (); | 1956 ColumnVector cmin = x_cube.row_min (), cmax = x_cube.row_max (); |
1956 double xM = cmax(0)-cmin(0); | 1957 double xM = cmax(0)-cmin(0); |
1957 double yM = cmax(1)-cmin(1); | 1958 double yM = cmax(1)-cmin(1); |
1958 | 1959 |
1959 Matrix bb = get_boundingbox (); | 1960 Matrix bb = get_boundingbox (true); |
1960 Matrix cs = get_backend ().get_canvas_size (__myhandle__); | |
1961 double fh = cs(1); | |
1962 | 1961 |
1963 double v_angle; | 1962 double v_angle; |
1964 | 1963 |
1965 if (cameraviewanglemode_is ("auto")) | 1964 if (cameraviewanglemode_is ("auto")) |
1966 { | 1965 { |
1990 | 1989 |
1991 if (dowarp) | 1990 if (dowarp) |
1992 { | 1991 { |
1993 xM *= pf; | 1992 xM *= pf; |
1994 yM *= pf; | 1993 yM *= pf; |
1995 translate (x_viewport, bb(0)+bb(2)/2, fh-(bb(1)+bb(3)/2)+1, 0); | 1994 translate (x_viewport, bb(0)+bb(2)/2, bb(1)+bb(3)/2, 0); |
1996 scale (x_viewport, bb(2)/xM, -bb(3)/yM, 1); | 1995 scale (x_viewport, bb(2)/xM, -bb(3)/yM, 1); |
1997 } | 1996 } |
1998 else | 1997 else |
1999 { | 1998 { |
2000 double pix = 1; | 1999 double pix = 1; |
2005 else | 2004 else |
2006 pix = bb(2); | 2005 pix = bb(2); |
2007 } | 2006 } |
2008 else | 2007 else |
2009 pix = (bb(2) < bb(3) ? bb(2) : bb(3)); | 2008 pix = (bb(2) < bb(3) ? bb(2) : bb(3)); |
2010 translate (x_viewport, bb(0)+bb(2)/2, fh-(bb(1)+bb(3)/2)+1, 0); | 2009 translate (x_viewport, bb(0)+bb(2)/2, bb(1)+bb(3)/2, 0); |
2011 scale (x_viewport, pix, -pix, 1); | 2010 scale (x_viewport, pix, -pix, 1); |
2012 } | 2011 } |
2013 | 2012 |
2014 x_normrender = x_viewport * x_projection * x_view; | 2013 x_normrender = x_viewport * x_projection * x_view; |
2015 | 2014 |
2083 | 2082 |
2084 // FIXME: if plotboxaspectratiomode is "manual", limits | 2083 // FIXME: if plotboxaspectratiomode is "manual", limits |
2085 // and/or dataaspectratio might be adapted | 2084 // and/or dataaspectratio might be adapted |
2086 } | 2085 } |
2087 | 2086 |
2087 // The INTERNAL flag defines whether position or outerposition is used. | |
2088 | |
2088 Matrix | 2089 Matrix |
2089 axes::properties::get_boundingbox (void) const | 2090 axes::properties::get_boundingbox (bool internal) const |
2090 { | 2091 { |
2091 graphics_backend b = get_backend (); | 2092 graphics_object obj = gh_manager::get_object (get_parent ()); |
2092 Matrix pos; | 2093 Matrix parent_bb = obj.get_properties ().get_boundingbox (true); |
2093 | 2094 Matrix pos = (internal ? |
2094 pos = convert_position (get_position ().matrix_value (), get_units (), | 2095 get_position ().matrix_value () |
2095 "pixels", b.get_canvas_size (__myhandle__), b); | 2096 : get_outerposition ().matrix_value ()); |
2097 | |
2098 | |
2099 pos = convert_position (pos, get_units (), "pixels", | |
2100 parent_bb.extract_n (0, 2, 1, 2), get_backend ()); | |
2096 pos(0)--; | 2101 pos(0)--; |
2097 pos(1)--; | 2102 pos(1)--; |
2103 pos(1) = parent_bb(3) - pos(1) - pos(3); | |
2098 | 2104 |
2099 return pos; | 2105 return pos; |
2100 } | 2106 } |
2101 | 2107 |
2102 ColumnVector | 2108 ColumnVector |
2231 | 2237 |
2232 return retval; | 2238 return retval; |
2233 } | 2239 } |
2234 | 2240 |
2235 // magform(x) Returns (a, b), where x = a * 10^b, a >= 1., and b is | 2241 // magform(x) Returns (a, b), where x = a * 10^b, a >= 1., and b is |
2236 // integral. Used by calc_ticks | 2242 // integral. |
2237 | 2243 |
2238 void | 2244 void |
2239 axes::properties::magform (double x, double& a, int &b) | 2245 axes::properties::magform (double x, double& a, int& b) |
2240 { | 2246 { |
2241 if (x == 0) | 2247 if (x == 0) |
2242 { | 2248 { |
2243 a = 0; | 2249 a = 0; |
2244 b = 0; | 2250 b = 0; |
2261 } | 2267 } |
2262 | 2268 |
2263 // A translation from Tom Holoryd's python code at | 2269 // A translation from Tom Holoryd's python code at |
2264 // http://kurage.nimh.nih.gov/tomh/tics.py | 2270 // http://kurage.nimh.nih.gov/tomh/tics.py |
2265 // FIXME -- add log ticks | 2271 // FIXME -- add log ticks |
2272 | |
2266 void | 2273 void |
2267 axes::properties::calc_ticks (const array_property& lims, array_property& ticks) | 2274 axes::properties::calc_ticks (const array_property& lims, array_property& ticks) |
2268 { | 2275 { |
2269 | |
2270 int ticint = 5; | 2276 int ticint = 5; |
2271 | 2277 |
2272 if (lims.get ().is_empty ()) | 2278 if (lims.get ().is_empty ()) |
2273 return; | 2279 return; |
2274 | 2280 |
2280 // Plots", Communications of the ACM, 10 (1973), 639-640. | 2286 // Plots", Communications of the ACM, 10 (1973), 639-640. |
2281 // Also cited as ACM Algorithm 463. | 2287 // Also cited as ACM Algorithm 463. |
2282 | 2288 |
2283 double a; | 2289 double a; |
2284 int b, x; | 2290 int b, x; |
2285 magform ( (hi-lo)/ticint, a, b); | 2291 |
2286 if (a < 1.41) // sqrt(2) | 2292 magform ((hi-lo)/ticint, a, b); |
2293 | |
2294 static const double sqrt_2 = sqrt (2.0); | |
2295 static const double sqrt_10 = sqrt (10.0); | |
2296 static const double sqrt_50 = sqrt (50.0); | |
2297 | |
2298 if (a < sqrt_2) | |
2287 x = 1; | 2299 x = 1; |
2288 else if (a < 3.16) // sqrt(10) | 2300 else if (a < sqrt_10) |
2289 x = 2; | 2301 x = 2; |
2290 else if (a < 7.07) // sqrt(50) | 2302 else if (a < sqrt_50) |
2291 x = 5; | 2303 x = 5; |
2292 else | 2304 else |
2293 x = 10; | 2305 x = 10; |
2294 | |
2295 | 2306 |
2296 double sep = x * std::pow (10., b); | 2307 double sep = x * std::pow (10., b); |
2297 | 2308 |
2298 // FIXME x can now be used to set minor ticks | 2309 // FIXME x can now be used to set minor ticks |
2299 if (x == 10) | 2310 if (x == 10) |
2300 x = 1; | 2311 x = 1; |
2301 | 2312 |
2302 | |
2303 // The following guarantees that if zero is in the range, it will be | 2313 // The following guarantees that if zero is in the range, it will be |
2304 // included as a tic. | 2314 // included as a tic. |
2305 | 2315 |
2306 int i1 = static_cast<int> (std::floor (lo / sep)); | 2316 int i1 = static_cast<int> (std::floor (lo / sep)); |
2307 int i2 = static_cast<int> (std::ceil (hi / sep)); | 2317 int i2 = static_cast<int> (std::ceil (hi / sep)); |
2308 | 2318 |
2309 Matrix limits (1, i2-i1+1); | 2319 Matrix limits (1, i2-i1+1); |
2310 for (int i=0; i<i2-i1+1; i++) | 2320 for (int i = 0; i < i2-i1+1; i++) |
2311 limits (i) = sep*(i+i1); | 2321 limits (i) = sep*(i+i1); |
2312 | 2322 |
2313 ticks = limits; | 2323 ticks = limits; |
2314 | |
2315 } | 2324 } |
2316 | 2325 |
2317 static bool updating_axis_limits = false; | 2326 static bool updating_axis_limits = false; |
2318 | 2327 |
2319 void | 2328 void |
3213 | 3222 |
3214 return retval; | 3223 return retval; |
3215 } | 3224 } |
3216 | 3225 |
3217 octave_value | 3226 octave_value |
3218 get_property_from_handle (double handle, const std::string &property, | 3227 get_property_from_handle (double handle, const std::string& property, |
3219 const std::string &func) | 3228 const std::string& func) |
3220 { | 3229 { |
3221 graphics_object obj = gh_manager::get_object (handle); | 3230 graphics_object obj = gh_manager::get_object (handle); |
3222 octave_value retval; | 3231 octave_value retval; |
3223 | 3232 |
3224 if (obj) | 3233 if (obj) |
3231 | 3240 |
3232 return retval; | 3241 return retval; |
3233 } | 3242 } |
3234 | 3243 |
3235 bool | 3244 bool |
3236 set_property_in_handle (double handle, const std::string &property, | 3245 set_property_in_handle (double handle, const std::string& property, |
3237 const octave_value &arg, const std::string &func) | 3246 const octave_value& arg, const std::string& func) |
3238 { | 3247 { |
3239 graphics_object obj = gh_manager::get_object (handle); | 3248 graphics_object obj = gh_manager::get_object (handle); |
3240 int ret = false; | 3249 int ret = false; |
3241 | 3250 |
3242 if (obj) | 3251 if (obj) |