Mercurial > octave-nkf
annotate src/graphics.cc @ 7844:3d60445d3638
Add new double_radio_property class for alpha values.
author | Michael Goffioul <michael.goffioul@gmail.com> |
---|---|
date | Tue, 26 Feb 2008 22:06:47 +0100 |
parents | d3dcfdfdc434 |
children | 40b16e04172a |
rev | line source |
---|---|
6406 | 1 /* |
2 | |
3 Copyright (C) 2007 John W. Eaton | |
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 | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
6406 | 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 | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
6406 | 20 |
21 */ | |
22 | |
23 #ifdef HAVE_CONFIG_H | |
24 #include <config.h> | |
25 #endif | |
26 | |
27 #include <cctype> | |
7222 | 28 #include <cfloat> |
7286 | 29 #include <cstdlib> |
6406 | 30 |
31 #include <algorithm> | |
32 #include <list> | |
33 #include <map> | |
34 #include <set> | |
35 #include <string> | |
36 | |
7409 | 37 #include "file-ops.h" |
38 #include "file-stat.h" | |
39 | |
6705 | 40 #include "defun.h" |
41 #include "error.h" | |
6595 | 42 #include "graphics.h" |
7409 | 43 #include "input.h" |
6705 | 44 #include "ov.h" |
45 #include "oct-obj.h" | |
46 #include "oct-map.h" | |
47 #include "ov-fcn-handle.h" | |
48 #include "parse.h" | |
7409 | 49 #include "toplev.h" |
7222 | 50 #include "unwind-prot.h" |
6595 | 51 |
6406 | 52 static void |
53 gripe_set_invalid (const std::string& pname) | |
54 { | |
55 error ("set: invalid value for %s property", pname.c_str ()); | |
56 } | |
57 | |
7363 | 58 static Matrix |
59 jet_colormap (void) | |
60 { | |
61 Matrix cmap (64, 3, 0.0); | |
62 | |
63 for (octave_idx_type i = 0; i < 64; i++) | |
64 { | |
65 // This is the jet colormap. It would be nice to be able | |
66 // to feval the jet function but since there is a static | |
67 // property object that includes a colormap_property | |
68 // object, we need to initialize this before main is even | |
69 // called, so calling an interpreted function is not | |
70 // possible. | |
71 | |
72 double x = i / 63.0; | |
73 | |
74 if (x >= 3.0/8.0 && x < 5.0/8.0) | |
75 cmap(i,0) = 4.0 * x - 3.0/2.0; | |
76 else if (x >= 5.0/8.0 && x < 7.0/8.0) | |
77 cmap(i,0) = 1.0; | |
78 else if (x >= 7.0/8.0) | |
79 cmap(i,0) = -4.0 * x + 9.0/2.0; | |
80 | |
81 if (x >= 1.0/8.0 && x < 3.0/8.0) | |
82 cmap(i,1) = 4.0 * x - 1.0/2.0; | |
83 else if (x >= 3.0/8.0 && x < 5.0/8.0) | |
84 cmap(i,1) = 1.0; | |
85 else if (x >= 5.0/8.0 && x < 7.0/8.0) | |
86 cmap(i,1) = -4.0 * x + 7.0/2.0; | |
87 | |
88 if (x < 1.0/8.0) | |
89 cmap(i,2) = 4.0 * x + 1.0/2.0; | |
90 else if (x >= 1.0/8.0 && x < 3.0/8.0) | |
91 cmap(i,2) = 1.0; | |
92 else if (x >= 3.0/8.0 && x < 5.0/8.0) | |
93 cmap(i,2) = -4.0 * x + 5.0/2.0; | |
94 } | |
95 | |
96 return cmap; | |
97 } | |
98 | |
99 static Matrix | |
100 default_colororder (void) | |
101 { | |
102 Matrix retval (7, 3, 0.0); | |
103 | |
104 retval(0,2) = 1.0; | |
105 | |
106 retval(1,1) = 0.5; | |
107 | |
108 retval(2,0) = 1.0; | |
109 | |
110 retval(3,1) = 0.75; | |
111 retval(3,2) = 0.75; | |
112 | |
113 retval(4,0) = 0.75; | |
114 retval(4,2) = 0.75; | |
115 | |
116 retval(5,0) = 0.75; | |
117 retval(5,1) = 0.75; | |
118 | |
119 retval(6,0) = 0.25; | |
120 retval(6,1) = 0.25; | |
121 retval(6,2) = 0.25; | |
122 | |
123 return retval; | |
124 } | |
125 | |
126 static Matrix | |
127 default_lim (void) | |
128 { | |
129 Matrix m (1, 2, 0); | |
130 m(1) = 1; | |
131 return m; | |
132 } | |
133 | |
134 static Matrix | |
135 default_data (void) | |
136 { | |
137 Matrix retval (1, 2); | |
138 | |
139 retval(0) = 0; | |
140 retval(1) = 1; | |
141 | |
142 return retval; | |
143 } | |
144 | |
7427 | 145 static Matrix |
146 default_axes_position (void) | |
147 { | |
148 Matrix m (1, 4, 0.0); | |
149 m(0) = 0.13; | |
150 m(1) = 0.11; | |
151 m(2) = 0.775; | |
152 m(3) = 0.815; | |
153 return m; | |
154 } | |
155 | |
156 static Matrix | |
157 default_axes_outerposition (void) | |
158 { | |
159 Matrix m (1, 4, 0.0); | |
160 m(2) = m(3) = 1.0; | |
161 return m; | |
162 } | |
163 | |
7445 | 164 static Matrix |
165 default_figure_position (void) | |
166 { | |
167 Matrix m (1, 4, 0.0); | |
168 m(0) = 300; | |
169 m(1) = 200; | |
170 m(2) = 560; | |
171 m(3) = 420; | |
172 return m; | |
173 } | |
174 | |
7822
edbaa13397ee
Implement callbackobject property in root object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7820
diff
changeset
|
175 static void |
edbaa13397ee
Implement callbackobject property in root object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7820
diff
changeset
|
176 xset_gcbo (const graphics_handle& h) |
edbaa13397ee
Implement callbackobject property in root object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7820
diff
changeset
|
177 { |
edbaa13397ee
Implement callbackobject property in root object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7820
diff
changeset
|
178 graphics_object go = gh_manager::get_object (0); |
edbaa13397ee
Implement callbackobject property in root object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7820
diff
changeset
|
179 root_figure::properties& props = |
edbaa13397ee
Implement callbackobject property in root object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7820
diff
changeset
|
180 dynamic_cast<root_figure::properties&> (go.get_properties ()); |
edbaa13397ee
Implement callbackobject property in root object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7820
diff
changeset
|
181 |
edbaa13397ee
Implement callbackobject property in root object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7820
diff
changeset
|
182 props.set_callbackobject (h.as_octave_value ()); |
edbaa13397ee
Implement callbackobject property in root object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7820
diff
changeset
|
183 } |
edbaa13397ee
Implement callbackobject property in root object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7820
diff
changeset
|
184 |
edbaa13397ee
Implement callbackobject property in root object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7820
diff
changeset
|
185 static void |
edbaa13397ee
Implement callbackobject property in root object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7820
diff
changeset
|
186 xreset_gcbo (void *) |
edbaa13397ee
Implement callbackobject property in root object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7820
diff
changeset
|
187 { |
edbaa13397ee
Implement callbackobject property in root object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7820
diff
changeset
|
188 xset_gcbo (graphics_handle ()); |
edbaa13397ee
Implement callbackobject property in root object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7820
diff
changeset
|
189 } |
edbaa13397ee
Implement callbackobject property in root object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7820
diff
changeset
|
190 |
7367 | 191 // NOTE: "cb" is passed by value, because "function_value" method |
192 // is non-const; passing "cb" by const-reference is not | |
193 // possible | |
194 | |
195 static void | |
196 execute_callback (octave_value cb, const graphics_handle& h, | |
197 const octave_value& data) | |
198 { | |
199 octave_value_list args; | |
200 octave_function *fcn = 0; | |
201 | |
202 args(0) = h.as_octave_value (); | |
7824
adb520646d7e
Fix execution of callback strings and allow execution of callback by name.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7822
diff
changeset
|
203 if (data.is_defined ()) |
adb520646d7e
Fix execution of callback strings and allow execution of callback by name.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7822
diff
changeset
|
204 args(1) = data; |
adb520646d7e
Fix execution of callback strings and allow execution of callback by name.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7822
diff
changeset
|
205 else |
adb520646d7e
Fix execution of callback strings and allow execution of callback by name.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7822
diff
changeset
|
206 args(1) = Matrix (); |
7367 | 207 |
7822
edbaa13397ee
Implement callbackobject property in root object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7820
diff
changeset
|
208 unwind_protect::begin_frame ("execute_callback"); |
edbaa13397ee
Implement callbackobject property in root object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7820
diff
changeset
|
209 unwind_protect::add (xreset_gcbo); |
edbaa13397ee
Implement callbackobject property in root object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7820
diff
changeset
|
210 |
edbaa13397ee
Implement callbackobject property in root object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7820
diff
changeset
|
211 xset_gcbo (h); |
edbaa13397ee
Implement callbackobject property in root object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7820
diff
changeset
|
212 |
7367 | 213 BEGIN_INTERRUPT_WITH_EXCEPTIONS; |
214 | |
215 if (cb.is_function_handle ()) | |
216 fcn = cb.function_value (); | |
217 else if (cb.is_string ()) | |
218 { | |
7824
adb520646d7e
Fix execution of callback strings and allow execution of callback by name.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7822
diff
changeset
|
219 int status; |
7367 | 220 std::string s = cb.string_value (); |
7824
adb520646d7e
Fix execution of callback strings and allow execution of callback by name.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7822
diff
changeset
|
221 |
adb520646d7e
Fix execution of callback strings and allow execution of callback by name.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7822
diff
changeset
|
222 eval_string (s, false, status); |
7367 | 223 } |
224 else if (cb.is_cell () && cb.length () > 0 | |
225 && (cb.rows () == 1 || cb.columns () == 1) | |
226 && cb.cell_value ()(0).is_function_handle ()) | |
227 { | |
228 Cell c = cb.cell_value (); | |
229 | |
230 fcn = c(0).function_value (); | |
231 if (! error_state) | |
232 { | |
233 for (int i = 0; i < c.length () ; i++) | |
234 args(2+i) = c(i); | |
235 } | |
236 } | |
237 else | |
7373 | 238 { |
239 std::string nm = cb.class_name (); | |
240 error ("trying to execute non-executable object (class = %s)", | |
241 nm.c_str ()); | |
242 } | |
7367 | 243 |
7822
edbaa13397ee
Implement callbackobject property in root object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7820
diff
changeset
|
244 if (fcn && ! error_state) |
7367 | 245 feval (fcn, args); |
246 | |
247 END_INTERRUPT_WITH_EXCEPTIONS; | |
7822
edbaa13397ee
Implement callbackobject property in root object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7820
diff
changeset
|
248 |
edbaa13397ee
Implement callbackobject property in root object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7820
diff
changeset
|
249 unwind_protect::run_frame ("execute_callback"); |
7367 | 250 } |
251 | |
7427 | 252 static Matrix |
253 convert_position (const Matrix& pos, const caseless_str& from_units, | |
254 const caseless_str& to_units, | |
255 const Matrix& parent_dim = Matrix (1, 2, 0.0), | |
256 const graphics_backend& backend = graphics_backend ()) | |
257 { | |
258 Matrix retval (1, 4); | |
259 double res = 0; | |
260 | |
261 if (from_units.compare ("pixels")) | |
262 retval = pos; | |
263 else if (from_units.compare ("normalized")) | |
264 { | |
265 retval(0) = pos(0) * parent_dim(0) + 1; | |
266 retval(1) = pos(1) * parent_dim(1) + 1; | |
267 retval(2) = pos(2) * parent_dim(0); | |
268 retval(3) = pos(3) * parent_dim(1); | |
269 } | |
270 else if (from_units.compare ("characters")) | |
271 { | |
272 // FIXME: implement this | |
273 } | |
274 else | |
275 { | |
276 res = backend.get_screen_resolution (); | |
277 | |
278 double f = 0.0; | |
279 | |
280 if (from_units.compare ("points")) | |
281 f = res / 72.0; | |
282 else if (from_units.compare ("inches")) | |
283 f = res; | |
284 else if (from_units.compare ("centimeters")) | |
285 f = res / 2.54; | |
286 | |
287 if (f > 0) | |
288 { | |
289 retval(0) = pos(0) * f + 1; | |
290 retval(1) = pos(1) * f + 1; | |
291 retval(2) = pos(2) * f; | |
292 retval(3) = pos(3) * f; | |
293 } | |
294 } | |
295 | |
296 if (! to_units.compare ("pixels")) | |
297 { | |
298 if (to_units.compare ("normalized")) | |
299 { | |
300 retval(0) = (retval(0) - 1) / parent_dim(0); | |
301 retval(1) = (retval(1) - 1) / parent_dim(1); | |
302 retval(2) /= parent_dim(0); | |
303 retval(3) /= parent_dim(1); | |
304 } | |
305 else if (to_units.compare ("characters")) | |
306 { | |
307 // FIXME: implement this | |
308 } | |
309 else | |
310 { | |
311 if (res <= 0) | |
312 res = backend.get_screen_resolution (); | |
313 | |
314 double f = 0.0; | |
315 | |
316 if (to_units.compare ("points")) | |
317 f = res / 72.0; | |
318 else if (to_units.compare ("inches")) | |
319 f = res; | |
320 else if (to_units.compare ("centimeters")) | |
321 f = res / 2.54; | |
322 | |
323 if (f > 0) | |
324 { | |
325 retval(0) = (retval(0) - 1) / f; | |
326 retval(1) = (retval(1) - 1) / f; | |
327 retval(2) /= f; | |
328 retval(3) /= f; | |
329 } | |
330 } | |
331 } | |
332 | |
333 return retval; | |
334 } | |
335 | |
7829
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
336 static graphics_object |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
337 xget_ancestor (graphics_object go, const std::string& type) |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
338 { |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
339 do |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
340 { |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
341 if (go.valid_object ()) |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
342 { |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
343 if (go.isa (type)) |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
344 return go; |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
345 else |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
346 go = gh_manager::get_object (go.get_parent ()); |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
347 } |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
348 else |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
349 return graphics_object (); |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
350 } while (true); |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
351 } |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
352 |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
353 static octave_value |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
354 convert_cdata (const base_properties& props, const octave_value& cdata, |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
355 bool is_scaled, int cdim) |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
356 { |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
357 dim_vector dv (cdata.dims ()); |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
358 |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
359 if (dv.length () == cdim && dv(cdim-1) == 3) |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
360 return cdata; |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
361 |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
362 Matrix cmap (1, 3, 0.0); |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
363 Matrix clim (1, 2, 0.0); |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
364 |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
365 graphics_object go = gh_manager::get_object (props.get___myhandle__ ()); |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
366 graphics_object fig = xget_ancestor (go, "figure"); |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
367 |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
368 if (fig.valid_object ()) |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
369 { |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
370 Matrix _cmap = fig.get (caseless_str ("colormap")).matrix_value (); |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
371 |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
372 if (! error_state) |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
373 cmap = _cmap; |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
374 } |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
375 |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
376 if (is_scaled) |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
377 { |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
378 graphics_object ax = xget_ancestor (go, "axes"); |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
379 |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
380 if (ax.valid_object ()) |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
381 { |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
382 Matrix _clim = ax.get (caseless_str ("clim")).matrix_value (); |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
383 |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
384 if (! error_state) |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
385 clim = _clim; |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
386 } |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
387 } |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
388 |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
389 dv.resize (cdim); |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
390 dv(cdim-1) = 3; |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
391 |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
392 NDArray a (dv); |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
393 |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
394 int lda = static_cast<int> (a.numel () / 3); |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
395 int nc = cmap.rows (); |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
396 |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
397 double *av = a.fortran_vec (); |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
398 const double *cmapv = cmap.data (); |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
399 const double *cv = 0; |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
400 const octave_uint8 *icv = 0; |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
401 |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
402 if (cdata.is_integer_type ()) |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
403 icv = cdata.uint8_array_value ().data (); |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
404 else |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
405 cv = cdata.array_value ().data (); |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
406 |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
407 for (int i = 0; i < lda; i++) |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
408 { |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
409 double x = (cv ? cv[i] : double (icv[i])); |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
410 |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
411 if (is_scaled) |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
412 x = xround ((nc - 1) * (x - clim(0)) / (clim(1) - clim(0))); |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
413 else |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
414 x = xround (x - 1); |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
415 |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
416 if (x < 0) |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
417 x = 0; |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
418 else if (x >= nc) |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
419 x = (nc - 1); |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
420 |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
421 int idx = static_cast<int> (x); |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
422 |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
423 av[i] = cmapv[idx]; |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
424 av[i+lda] = cmapv[idx+nc]; |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
425 av[i+2*lda] = cmapv[idx+2*nc]; |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
426 } |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
427 |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
428 return octave_value (a); |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
429 } |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
430 |
7836
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
431 template<class T> |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
432 static void |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
433 get_array_limits (const Array<T>& m, double& emin, double& emax, |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
434 double& eminp) |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
435 { |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
436 const T *data = m.data (); |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
437 int n = m.numel (); |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
438 |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
439 for (int i = 0; i < n; i++) |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
440 { |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
441 double e = double (data[i]); |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
442 |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
443 if (! (xisinf (e) || xisnan (e))) |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
444 { |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
445 if (e < emin) |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
446 emin = e; |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
447 |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
448 if (e > emax) |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
449 emax = e; |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
450 |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
451 if (e >= 0 && e < eminp) |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
452 eminp = e; |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
453 } |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
454 } |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
455 } |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
456 |
6406 | 457 // --------------------------------------------------------------------- |
458 | |
6705 | 459 radio_values::radio_values (const std::string& opt_string) |
6406 | 460 { |
6705 | 461 size_t beg = 0; |
462 size_t len = opt_string.length (); | |
463 bool done = len == 0; | |
6681 | 464 |
6705 | 465 while (! done) |
466 { | |
467 size_t end = opt_string.find ('|', beg); | |
6681 | 468 |
6705 | 469 if (end == std::string::npos) |
470 { | |
471 end = len; | |
472 done = true; | |
473 } | |
6681 | 474 |
6705 | 475 std::string t = opt_string.substr (beg, end-beg); |
6681 | 476 |
6705 | 477 // Might want more error checking here... |
478 if (t[0] == '{') | |
479 { | |
480 t = t.substr (1, t.length () - 2); | |
481 default_val = t; | |
482 } | |
483 else if (beg == 0) // ensure default value | |
484 default_val = t; | |
6681 | 485 |
6705 | 486 possible_vals.insert (t); |
6681 | 487 |
6705 | 488 beg = end + 1; |
489 } | |
490 } | |
6681 | 491 |
6705 | 492 bool |
6761 | 493 color_values::str2rgb (std::string str) |
6681 | 494 { |
6705 | 495 double tmp_rgb[3] = {0, 0, 0}; |
496 bool retval = true; | |
6761 | 497 unsigned int len = str.length(); |
6681 | 498 |
6925 | 499 std::transform (str.begin (), str.end (), str.begin (), tolower); |
500 | |
6761 | 501 if (str.compare(0, len, "blue", 0, len) == 0) |
502 tmp_rgb[2] = 1; | |
6925 | 503 else if (str.compare(0, len, "black", 0, len) == 0 || |
504 str.compare(0, len, "k", 0, len) == 0) | |
6761 | 505 tmp_rgb[0] = tmp_rgb[1] = tmp_rgb[2] = 0; |
506 else if (str.compare(0, len, "red", 0, len) == 0) | |
507 tmp_rgb[0] = 1; | |
508 else if (str.compare(0, len, "green", 0, len) == 0) | |
509 tmp_rgb[1] = 1; | |
510 else if (str.compare(0, len, "yellow", 0, len) == 0) | |
511 tmp_rgb[0] = tmp_rgb[1] = 1; | |
512 else if (str.compare(0, len, "magenta", 0, len) == 0) | |
513 tmp_rgb[0] = tmp_rgb[2] = 1; | |
514 else if (str.compare(0, len, "cyan", 0, len) == 0) | |
515 tmp_rgb[1] = tmp_rgb[2] = 1; | |
6925 | 516 else if (str.compare(0, len, "white", 0, len) == 0 || |
517 str.compare(0, len, "w", 0, len) == 0) | |
6761 | 518 tmp_rgb[0] = tmp_rgb[1] = tmp_rgb[2] = 1; |
519 else | |
520 retval = false; | |
6406 | 521 |
6705 | 522 if (retval) |
523 { | |
524 for (int i = 0; i < 3; i++) | |
7363 | 525 xrgb(i) = tmp_rgb[i]; |
6705 | 526 } |
6563 | 527 |
6705 | 528 return retval; |
529 } | |
6681 | 530 |
7363 | 531 void |
532 color_property::set (const octave_value& val) | |
6790 | 533 { |
534 if (val.is_string ()) | |
535 { | |
536 std::string s = val.string_value (); | |
537 | |
538 if (! s.empty ()) | |
539 { | |
6898 | 540 if (radio_val.contains (s)) |
6790 | 541 { |
542 current_val = s; | |
543 current_type = radio_t; | |
544 } | |
545 else | |
546 { | |
547 color_values col (s); | |
548 if (! error_state) | |
549 { | |
550 color_val = col; | |
551 current_type = color_t; | |
552 } | |
553 else | |
7363 | 554 error ("invalid value for color property \"%s\" (value = %s)", |
555 get_name ().c_str (), s.c_str ()); | |
6790 | 556 } |
557 } | |
558 else | |
7363 | 559 error ("invalid value for color property \"%s\"", |
560 get_name ().c_str ()); | |
6790 | 561 } |
562 else if (val.is_real_matrix ()) | |
563 { | |
564 Matrix m = val.matrix_value (); | |
565 | |
566 if (m.numel () == 3) | |
567 { | |
568 color_values col (m (0), m (1), m(2)); | |
569 if (! error_state) | |
570 { | |
571 color_val = col; | |
572 current_type = color_t; | |
573 } | |
574 } | |
575 else | |
7363 | 576 error ("invalid value for color property \"%s\"", |
577 get_name ().c_str ()); | |
6790 | 578 } |
579 else | |
7363 | 580 error ("invalid value for color property \"%s\"", |
581 get_name ().c_str ()); | |
6790 | 582 } |
583 | |
7844
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7843
diff
changeset
|
584 void |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7843
diff
changeset
|
585 double_radio_property::set (const octave_value& val) |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7843
diff
changeset
|
586 { |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7843
diff
changeset
|
587 if (val.is_string ()) |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7843
diff
changeset
|
588 { |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7843
diff
changeset
|
589 std::string s = val.string_value (); |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7843
diff
changeset
|
590 |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7843
diff
changeset
|
591 if (! s.empty () && radio_val.contains (s)) |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7843
diff
changeset
|
592 { |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7843
diff
changeset
|
593 current_val = s; |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7843
diff
changeset
|
594 current_type = radio_t; |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7843
diff
changeset
|
595 } |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7843
diff
changeset
|
596 else |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7843
diff
changeset
|
597 error ("invalid value for double_radio property \"%s\"", |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7843
diff
changeset
|
598 get_name ().c_str ()); |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7843
diff
changeset
|
599 } |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7843
diff
changeset
|
600 else if (val.is_scalar_type () && val.is_real_type ()) |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7843
diff
changeset
|
601 { |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7843
diff
changeset
|
602 dval = val.double_value (); |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7843
diff
changeset
|
603 current_type = double_t; |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7843
diff
changeset
|
604 } |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7843
diff
changeset
|
605 else |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7843
diff
changeset
|
606 error ("invalid value for double_radio property \"%s\"", |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7843
diff
changeset
|
607 get_name ().c_str ()); |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7843
diff
changeset
|
608 } |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7843
diff
changeset
|
609 |
7363 | 610 bool |
611 array_property::validate (const octave_value& v) | |
612 { | |
7364 | 613 bool xok = false; |
7363 | 614 |
615 // FIXME: should we always support []? | |
616 if (v.is_empty () && v.is_double_type ()) | |
617 return true; | |
618 | |
619 // check value type | |
620 if (type_constraints.size () > 0) | |
621 { | |
622 for (std::list<std::string>::const_iterator it = type_constraints.begin (); | |
7364 | 623 ! xok && it != type_constraints.end (); ++it) |
7836
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
624 if ((*it) == v.class_name ()) |
7364 | 625 xok = true; |
7363 | 626 } |
627 else | |
7364 | 628 xok = v.is_double_type (); |
7363 | 629 |
7364 | 630 if (xok) |
7363 | 631 { |
632 dim_vector vdims = v.dims (); | |
633 int vlen = vdims.length (); | |
634 | |
7364 | 635 xok = false; |
7363 | 636 |
637 // check value size | |
638 if (size_constraints.size () > 0) | |
639 for (std::list<dim_vector>::const_iterator it = size_constraints.begin (); | |
7364 | 640 ! xok && it != size_constraints.end (); ++it) |
7363 | 641 { |
642 dim_vector itdims = (*it); | |
643 | |
644 if (itdims.length () == vlen) | |
645 { | |
7364 | 646 xok = true; |
7363 | 647 |
7364 | 648 for (int i = 0; xok && i < vlen; i++) |
7363 | 649 if (itdims(i) >= 0 && itdims(i) != vdims(i)) |
7364 | 650 xok = false; |
7363 | 651 } |
652 } | |
653 else | |
654 return true; | |
655 } | |
656 | |
7364 | 657 return xok; |
7363 | 658 } |
659 | |
660 void | |
7836
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
661 array_property::get_data_limits (void) |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
662 { |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
663 xmin = xminp = octave_Inf; |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
664 xmax = -octave_Inf; |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
665 |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
666 if (! data.is_empty ()) |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
667 { |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
668 if (data.is_integer_type ()) |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
669 { |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
670 if (data.is_int8_type ()) |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
671 get_array_limits (data.int8_array_value (), xmin, xmax, xminp); |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
672 else if (data.is_uint8_type ()) |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
673 get_array_limits (data.uint8_array_value (), xmin, xmax, xminp); |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
674 else if (data.is_int16_type ()) |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
675 get_array_limits (data.int16_array_value (), xmin, xmax, xminp); |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
676 else if (data.is_uint16_type ()) |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
677 get_array_limits (data.uint16_array_value (), xmin, xmax, xminp); |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
678 else if (data.is_int32_type ()) |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
679 get_array_limits (data.int32_array_value (), xmin, xmax, xminp); |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
680 else if (data.is_uint32_type ()) |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
681 get_array_limits (data.uint32_array_value (), xmin, xmax, xminp); |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
682 else if (data.is_int64_type ()) |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
683 get_array_limits (data.int64_array_value (), xmin, xmax, xminp); |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
684 else if (data.is_uint64_type ()) |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
685 get_array_limits (data.uint64_array_value (), xmin, xmax, xminp); |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
686 } |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
687 else |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
688 get_array_limits (data.array_value (), xmin, xmax, xminp); |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
689 } |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
690 } |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
691 |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
692 void |
7363 | 693 handle_property::set (const octave_value& v) |
694 { | |
695 double dv = v.double_value (); | |
696 | |
697 if (! error_state) | |
698 { | |
699 graphics_handle gh = gh_manager::lookup (dv); | |
700 | |
701 if (xisnan (gh.value ()) || gh.ok ()) | |
702 current_val = gh; | |
703 else | |
704 error ("set: invalid graphics handle (= %g) for property \"%s\"", | |
705 dv, get_name ().c_str ()); | |
706 } | |
707 else | |
708 error ("set: invalid graphics handle for property \"%s\"", | |
709 get_name ().c_str ()); | |
710 } | |
711 | |
712 bool | |
7367 | 713 callback_property::validate (const octave_value& v) const |
7363 | 714 { |
7367 | 715 // case 1: function handle |
716 // case 2: cell array with first element being a function handle | |
717 // case 3: string corresponding to known function name | |
718 // case 4: evaluatable string | |
719 // case 5: empty matrix | |
720 | |
721 if (v.is_function_handle ()) | |
722 return true; | |
723 else if (v.is_string ()) | |
724 // complete validation will be done at execution-time | |
725 return true; | |
726 else if (v.is_cell () && v.length () > 0 | |
727 && (v.rows() == 1 || v.columns () == 1) | |
728 && v.cell_value ()(0).is_function_handle ()) | |
729 return true; | |
730 else if (v.is_empty ()) | |
731 return true; | |
732 | |
733 return false; | |
7363 | 734 } |
735 | |
736 void | |
7367 | 737 callback_property::execute (const octave_value& data) const |
7363 | 738 { |
7367 | 739 if (callback.is_defined () && ! callback.is_empty ()) |
740 execute_callback (callback, get_parent (), data); | |
7363 | 741 } |
742 | |
7824
adb520646d7e
Fix execution of callback strings and allow execution of callback by name.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7822
diff
changeset
|
743 void |
adb520646d7e
Fix execution of callback strings and allow execution of callback by name.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7822
diff
changeset
|
744 callback_property::execute (const octave_value& cb, const graphics_handle& h, |
adb520646d7e
Fix execution of callback strings and allow execution of callback by name.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7822
diff
changeset
|
745 const octave_value& data) |
adb520646d7e
Fix execution of callback strings and allow execution of callback by name.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7822
diff
changeset
|
746 { |
adb520646d7e
Fix execution of callback strings and allow execution of callback by name.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7822
diff
changeset
|
747 if (cb.is_defined () && ! cb.is_empty ()) |
adb520646d7e
Fix execution of callback strings and allow execution of callback by name.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7822
diff
changeset
|
748 execute_callback (cb, h, data); |
adb520646d7e
Fix execution of callback strings and allow execution of callback by name.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7822
diff
changeset
|
749 } |
adb520646d7e
Fix execution of callback strings and allow execution of callback by name.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7822
diff
changeset
|
750 |
7363 | 751 // --------------------------------------------------------------------- |
6681 | 752 |
6705 | 753 void |
7189 | 754 property_list::set (const caseless_str& name, const octave_value& val) |
6681 | 755 { |
6705 | 756 size_t offset = 0; |
6681 | 757 |
6705 | 758 size_t len = name.length (); |
6681 | 759 |
6705 | 760 if (len > 4) |
761 { | |
7189 | 762 caseless_str pfx = name.substr (0, 4); |
6681 | 763 |
6705 | 764 if (pfx.compare ("axes") || pfx.compare ("line") |
765 || pfx.compare ("text")) | |
766 offset = 4; | |
767 else if (len > 5) | |
768 { | |
769 pfx = name.substr (0, 5); | |
6681 | 770 |
6807 | 771 if (pfx.compare ("image") || pfx.compare ("patch")) |
6705 | 772 offset = 5; |
773 else if (len > 6) | |
774 { | |
775 pfx = name.substr (0, 6); | |
6681 | 776 |
6705 | 777 if (pfx.compare ("figure")) |
778 offset = 6; | |
779 else if (len > 7) | |
780 { | |
781 pfx = name.substr (0, 7); | |
6681 | 782 |
6705 | 783 if (pfx.compare ("surface")) |
784 offset = 7; | |
785 } | |
786 } | |
787 } | |
6681 | 788 |
6705 | 789 if (offset > 0) |
790 { | |
791 // FIXME -- should we validate property names and values here? | |
6406 | 792 |
6705 | 793 std::string pname = name.substr (offset); |
6406 | 794 |
6705 | 795 std::transform (pfx.begin (), pfx.end (), pfx.begin (), tolower); |
796 std::transform (pname.begin (), pname.end (), pname.begin (), tolower); | |
6406 | 797 |
6705 | 798 bool remove = false; |
799 if (val.is_string ()) | |
800 { | |
7189 | 801 caseless_str tval = val.string_value (); |
6406 | 802 |
6705 | 803 remove = tval.compare ("remove"); |
804 } | |
6406 | 805 |
6705 | 806 pval_map_type& pval_map = plist_map[pfx]; |
6406 | 807 |
6705 | 808 if (remove) |
809 { | |
810 pval_map_iterator p = pval_map.find (pname); | |
6406 | 811 |
6705 | 812 if (p != pval_map.end ()) |
813 pval_map.erase (p); | |
814 } | |
815 else | |
816 pval_map[pname] = val; | |
817 } | |
818 } | |
6406 | 819 |
6705 | 820 if (offset == 0) |
821 error ("invalid default property specification"); | |
822 } | |
6406 | 823 |
6705 | 824 octave_value |
7189 | 825 property_list::lookup (const caseless_str& name) const |
6705 | 826 { |
827 octave_value retval; | |
6406 | 828 |
6705 | 829 size_t offset = 0; |
6406 | 830 |
6705 | 831 size_t len = name.length (); |
6406 | 832 |
6705 | 833 if (len > 4) |
834 { | |
7189 | 835 caseless_str pfx = name.substr (0, 4); |
6406 | 836 |
6705 | 837 if (pfx.compare ("axes") || pfx.compare ("line") |
838 || pfx.compare ("text")) | |
839 offset = 4; | |
840 else if (len > 5) | |
841 { | |
842 pfx = name.substr (0, 5); | |
6406 | 843 |
6807 | 844 if (pfx.compare ("image") || pfx.compare ("patch")) |
6705 | 845 offset = 5; |
846 else if (len > 6) | |
847 { | |
848 pfx = name.substr (0, 6); | |
6406 | 849 |
6705 | 850 if (pfx.compare ("figure")) |
851 offset = 6; | |
852 else if (len > 7) | |
853 { | |
854 pfx = name.substr (0, 7); | |
6406 | 855 |
6705 | 856 if (pfx.compare ("surface")) |
857 offset = 7; | |
858 } | |
859 } | |
860 } | |
6406 | 861 |
6705 | 862 if (offset > 0) |
863 { | |
864 std::string pname = name.substr (offset); | |
6406 | 865 |
6705 | 866 std::transform (pfx.begin (), pfx.end (), pfx.begin (), tolower); |
867 std::transform (pname.begin (), pname.end (), pname.begin (), tolower); | |
6406 | 868 |
6705 | 869 plist_map_const_iterator p = find (pfx); |
6432 | 870 |
6705 | 871 if (p != end ()) |
872 { | |
873 const pval_map_type& pval_map = p->second; | |
6406 | 874 |
6705 | 875 pval_map_const_iterator q = pval_map.find (pname); |
6406 | 876 |
6705 | 877 if (q != pval_map.end ()) |
878 retval = q->second; | |
879 } | |
880 } | |
881 } | |
6406 | 882 |
6705 | 883 return retval; |
884 } | |
6406 | 885 |
6705 | 886 Octave_map |
887 property_list::as_struct (const std::string& prefix_arg) const | |
888 { | |
889 Octave_map m; | |
6406 | 890 |
6705 | 891 for (plist_map_const_iterator p = begin (); p != end (); p++) |
892 { | |
893 std::string prefix = prefix_arg + p->first; | |
6406 | 894 |
6705 | 895 const pval_map_type pval_map = p->second; |
6406 | 896 |
6705 | 897 for (pval_map_const_iterator q = pval_map.begin (); |
898 q != pval_map.end (); | |
899 q++) | |
900 m.assign (prefix + q->first, q->second); | |
901 } | |
6406 | 902 |
6705 | 903 return m; |
904 } | |
6432 | 905 |
6874 | 906 graphics_handle::graphics_handle (const octave_value& a) |
907 : val (octave_NaN) | |
908 { | |
909 if (a.is_empty ()) | |
910 /* do nothing */; | |
911 else | |
912 { | |
913 double tval = a.double_value (); | |
914 | |
915 if (! error_state) | |
916 val = tval; | |
917 else | |
918 error ("invalid graphics handle"); | |
919 } | |
920 } | |
921 | |
6705 | 922 void |
923 graphics_object::set (const octave_value_list& args) | |
924 { | |
925 int nargin = args.length (); | |
6406 | 926 |
6705 | 927 if (nargin == 0) |
928 rep->defaults (); | |
929 else if (nargin % 2 == 0) | |
930 { | |
931 for (int i = 0; i < nargin; i += 2) | |
932 { | |
7189 | 933 caseless_str name = args(i).string_value (); |
6406 | 934 |
6705 | 935 if (! error_state) |
936 { | |
937 octave_value val = args(i+1); | |
6406 | 938 |
6705 | 939 if (val.is_string ()) |
940 { | |
7189 | 941 caseless_str tval = val.string_value (); |
6406 | 942 |
6705 | 943 if (tval.compare ("default")) |
944 val = get_default (name); | |
945 else if (tval.compare ("factory")) | |
946 val = get_factory_default (name); | |
947 } | |
6406 | 948 |
6705 | 949 if (error_state) |
950 break; | |
6406 | 951 |
6705 | 952 rep->set (name, val); |
953 } | |
954 else | |
955 error ("set: expecting argument %d to be a property name", i); | |
956 } | |
957 } | |
958 else | |
959 error ("set: invalid number of arguments"); | |
960 } | |
6406 | 961 |
962 | |
6705 | 963 graphics_handle |
964 gh_manager::get_handle (const std::string& go_name) | |
965 { | |
966 graphics_handle retval; | |
6406 | 967 |
6705 | 968 if (go_name == "figure") |
969 { | |
970 // We always want the lowest unused figure number. | |
6406 | 971 |
6705 | 972 retval = 1; |
6425 | 973 |
6705 | 974 while (handle_map.find (retval) != handle_map.end ()) |
975 retval++; | |
976 } | |
977 else | |
978 { | |
979 free_list_iterator p = handle_free_list.begin (); | |
6406 | 980 |
6705 | 981 if (p != handle_free_list.end ()) |
982 { | |
983 retval = *p; | |
984 handle_free_list.erase (p); | |
985 } | |
986 else | |
7286 | 987 { |
988 static double maxrand = RAND_MAX + 2.0; | |
989 | |
990 retval = graphics_handle (next_handle); | |
991 | |
7304 | 992 next_handle = ceil (next_handle) - 1.0 - (rand () + 1.0) / maxrand; |
7286 | 993 } |
6705 | 994 } |
6406 | 995 |
6705 | 996 return retval; |
997 } | |
6406 | 998 |
6705 | 999 void |
1000 gh_manager::do_free (const graphics_handle& h) | |
1001 { | |
7056 | 1002 if (h.ok ()) |
6705 | 1003 { |
6874 | 1004 if (h.value () != 0) |
6705 | 1005 { |
6874 | 1006 iterator p = handle_map.find (h); |
1007 | |
1008 if (p != handle_map.end ()) | |
1009 { | |
7403 | 1010 p->second.get_properties ().set_beingdeleted (true); |
1011 p->second.get_properties ().execute_deletefcn (); | |
7367 | 1012 |
6874 | 1013 handle_map.erase (p); |
1014 | |
1015 if (h.value () < 0) | |
1016 handle_free_list.insert (h); | |
1017 } | |
1018 else | |
1019 error ("graphics_handle::free: invalid object %g", h.value ()); | |
6705 | 1020 } |
1021 else | |
6874 | 1022 error ("graphics_handle::free: can't delete root figure"); |
6705 | 1023 } |
1024 } | |
6406 | 1025 |
1026 gh_manager *gh_manager::instance = 0; | |
1027 | |
1028 static void | |
7189 | 1029 xset (const graphics_handle& h, const caseless_str& name, |
6406 | 1030 const octave_value& val) |
1031 { | |
1032 graphics_object obj = gh_manager::get_object (h); | |
1033 obj.set (name, val); | |
1034 } | |
1035 | |
1036 static void | |
1037 xset (const graphics_handle& h, const octave_value_list& args) | |
1038 { | |
1039 if (args.length () > 0) | |
1040 { | |
1041 graphics_object obj = gh_manager::get_object (h); | |
1042 obj.set (args); | |
1043 } | |
1044 } | |
1045 | |
1046 | |
1047 static octave_value | |
7189 | 1048 xget (const graphics_handle& h, const caseless_str& name) |
6406 | 1049 { |
1050 graphics_object obj = gh_manager::get_object (h); | |
1051 return obj.get (name); | |
1052 } | |
1053 | |
1054 static graphics_handle | |
1055 reparent (const octave_value& ov, const std::string& who, | |
1056 const std::string& property, const graphics_handle& new_parent, | |
1057 bool adopt = true) | |
1058 { | |
1059 graphics_handle h = octave_NaN; | |
1060 | |
1061 double val = ov.double_value (); | |
1062 | |
1063 if (! error_state) | |
1064 { | |
1065 h = gh_manager::lookup (val); | |
1066 | |
7056 | 1067 if (h.ok ()) |
6406 | 1068 { |
1069 graphics_object obj = gh_manager::get_object (h); | |
1070 | |
1071 graphics_handle parent_h = obj.get_parent (); | |
1072 | |
1073 graphics_object parent_obj = gh_manager::get_object (parent_h); | |
1074 | |
1075 parent_obj.remove_child (h); | |
1076 | |
1077 if (adopt) | |
6874 | 1078 obj.set ("parent", new_parent.value ()); |
6406 | 1079 else |
1080 obj.reparent (new_parent); | |
1081 } | |
1082 else | |
1083 error ("%s: invalid graphics handle (= %g) for %s", | |
1084 who.c_str (), val, property.c_str ()); | |
1085 } | |
1086 else | |
1087 error ("%s: expecting %s to be a graphics handle", | |
1088 who.c_str (), property.c_str ()); | |
1089 | |
1090 return h; | |
1091 } | |
1092 | |
1093 // This function is NOT equivalent to the scripting language function gcf. | |
1094 graphics_handle | |
1095 gcf (void) | |
1096 { | |
1097 octave_value val = xget (0, "currentfigure"); | |
1098 | |
1099 return val.is_empty () ? octave_NaN : val.double_value (); | |
1100 } | |
1101 | |
1102 // This function is NOT equivalent to the scripting language function gca. | |
1103 graphics_handle | |
1104 gca (void) | |
1105 { | |
1106 octave_value val = xget (gcf (), "currentaxes"); | |
1107 | |
1108 return val.is_empty () ? octave_NaN : val.double_value (); | |
1109 } | |
1110 | |
1111 static void | |
1112 adopt (const graphics_handle& p, const graphics_handle& h) | |
1113 { | |
1114 graphics_object parent_obj = gh_manager::get_object (p); | |
1115 | |
1116 parent_obj.adopt (h); | |
1117 } | |
1118 | |
1119 static bool | |
7056 | 1120 is_handle (const graphics_handle& h) |
1121 { | |
1122 return h.ok (); | |
1123 } | |
1124 | |
1125 static bool | |
6406 | 1126 is_handle (double val) |
1127 { | |
6874 | 1128 graphics_handle h = gh_manager::lookup (val); |
1129 | |
1130 return h.ok (); | |
6406 | 1131 } |
1132 | |
1133 static bool | |
1134 is_handle (const octave_value& val) | |
1135 { | |
7142 | 1136 return val.is_real_scalar () && is_handle (val.double_value ()); |
6406 | 1137 } |
1138 | |
1139 static bool | |
1140 is_figure (double val) | |
1141 { | |
1142 graphics_object obj = gh_manager::get_object (val); | |
1143 | |
1144 return obj && obj.isa ("figure"); | |
1145 } | |
1146 | |
7370 | 1147 static void |
1148 xcreatefcn (const graphics_handle& h) | |
1149 { | |
1150 graphics_object obj = gh_manager::get_object (h); | |
1151 obj.get_properties ().execute_createfcn (); | |
1152 } | |
1153 | |
6406 | 1154 // --------------------------------------------------------------------- |
1155 | |
1156 static int | |
1157 compare (const void *a_arg, const void *b_arg) | |
1158 { | |
1159 double a = *(static_cast<const double *> (a_arg)); | |
1160 double b = *(static_cast<const double *> (b_arg)); | |
1161 | |
1162 return a > b ? 1 : (a < b) ? -1 : 0; | |
1163 } | |
1164 | |
1165 static Matrix | |
1166 maybe_set_children (const Matrix& kids, const octave_value& val) | |
1167 { | |
1168 const Matrix new_kids = val.matrix_value (); | |
1169 | |
1170 bool ok = true; | |
1171 | |
1172 if (! error_state) | |
1173 { | |
1174 if (kids.numel () == new_kids.numel ()) | |
1175 { | |
1176 Matrix t1 = kids; | |
1177 Matrix t2 = new_kids; | |
1178 | |
1179 t1.qsort (compare); | |
1180 t2.qsort (compare); | |
1181 | |
1182 if (t1 != t2) | |
1183 ok = false; | |
1184 } else | |
1185 ok = false; | |
1186 | |
1187 if (! ok) | |
1188 error ("set: new children must be a permutation of existing children"); | |
1189 } | |
1190 else | |
1191 { | |
1192 ok = false; | |
1193 error ("set: expecting children to be array of graphics handles"); | |
1194 } | |
1195 | |
1196 return ok ? new_kids : kids; | |
1197 } | |
1198 | |
6705 | 1199 void |
1200 base_properties::set_from_list (base_graphics_object& obj, | |
1201 property_list& defaults) | |
6406 | 1202 { |
6705 | 1203 std::string go_name = graphics_object_name (); |
6406 | 1204 |
6705 | 1205 property_list::plist_map_const_iterator p = defaults.find (go_name); |
6406 | 1206 |
6705 | 1207 if (p != defaults.end ()) |
1208 { | |
1209 const property_list::pval_map_type pval_map = p->second; | |
6406 | 1210 |
6705 | 1211 for (property_list::pval_map_const_iterator q = pval_map.begin (); |
1212 q != pval_map.end (); | |
1213 q++) | |
1214 { | |
1215 std::string pname = q->first; | |
6406 | 1216 |
6705 | 1217 obj.set (pname, q->second); |
6406 | 1218 |
6705 | 1219 if (error_state) |
1220 { | |
1221 error ("error setting default property %s", pname.c_str ()); | |
1222 break; | |
1223 } | |
1224 } | |
1225 } | |
1226 } | |
6406 | 1227 |
7363 | 1228 octave_value |
1229 base_properties::get (const caseless_str& name) const | |
1230 { | |
1231 octave_value retval; | |
1232 | |
1233 if (name.compare ("tag")) | |
1234 retval = get_tag (); | |
1235 else if (name.compare ("type")) | |
1236 retval = get_type (); | |
1237 else if (name.compare ("__modified__")) | |
1238 retval = is_modified (); | |
1239 else if (name.compare ("parent")) | |
1240 retval = get_parent ().as_octave_value (); | |
1241 else if (name.compare ("children")) | |
1242 retval = children; | |
7366 | 1243 else if (name.compare ("busyaction")) |
1244 retval = get_busyaction (); | |
1245 else if (name.compare ("buttondownfcn")) | |
1246 retval = get_buttondownfcn (); | |
1247 else if (name.compare ("clipping")) | |
1248 retval = get_clipping (); | |
1249 else if (name.compare ("createfcn")) | |
1250 retval = get_createfcn (); | |
1251 else if (name.compare ("deletefcn")) | |
1252 retval = get_deletefcn (); | |
1253 else if (name.compare ("handlevisibility")) | |
1254 retval = get_handlevisibility (); | |
1255 else if (name.compare ("hittest")) | |
1256 retval = get_hittest (); | |
1257 else if (name.compare ("interruptible")) | |
1258 retval = get_interruptible (); | |
1259 else if (name.compare ("selected")) | |
1260 retval = get_selected (); | |
1261 else if (name.compare ("selectionhighlight")) | |
1262 retval = get_selectionhighlight (); | |
1263 else if (name.compare ("uicontextmenu")) | |
1264 retval = get_uicontextmenu (); | |
1265 else if (name.compare ("userdata")) | |
1266 retval = get_userdata (); | |
1267 else if (name.compare ("visible")) | |
1268 retval = get_visible (); | |
7403 | 1269 else if (name.compare ("beingdeleted")) |
1270 retval = get_beingdeleted (); | |
7363 | 1271 else |
1272 { | |
1273 std::map<caseless_str, property>::const_iterator it = all_props.find (name); | |
1274 | |
1275 if (it != all_props.end ()) | |
1276 retval = it->second.get (); | |
1277 else | |
1278 error ("get: unknown property \"%s\"", name.c_str ()); | |
1279 } | |
1280 | |
1281 return retval; | |
1282 } | |
1283 | |
1284 octave_value | |
7379 | 1285 base_properties::get (bool all) const |
7363 | 1286 { |
1287 Octave_map m; | |
1288 | |
1289 for (std::map<caseless_str, property>::const_iterator it = all_props.begin (); | |
1290 it != all_props.end (); ++it) | |
7379 | 1291 if (all || ! it->second.is_hidden ()) |
1292 m.assign (it->second.get_name (), it->second.get ()); | |
7363 | 1293 |
1294 m.assign ("tag", get_tag ()); | |
1295 m.assign ("type", get_type ()); | |
7379 | 1296 if (all) |
1297 m.assign ("__modified__", is_modified ()); | |
7363 | 1298 m.assign ("parent", get_parent ().as_octave_value ()); |
1299 m.assign ("children", children); | |
7366 | 1300 m.assign ("busyaction", get_busyaction ()); |
1301 m.assign ("buttondownfcn", get_buttondownfcn ()); | |
1302 m.assign ("clipping", get_clipping ()); | |
1303 m.assign ("createfcn", get_createfcn ()); | |
1304 m.assign ("deletefcn", get_deletefcn ()); | |
1305 m.assign ("handlevisibility", get_handlevisibility ()); | |
1306 m.assign ("hittest", get_hittest ()); | |
1307 m.assign ("interruptible", get_interruptible ()); | |
1308 m.assign ("selected", get_selected ()); | |
1309 m.assign ("selectionhighlight", get_selectionhighlight ()); | |
1310 m.assign ("uicontextmenu", get_uicontextmenu ()); | |
1311 m.assign ("userdata", get_userdata ()); | |
1312 m.assign ("visible", get_visible ()); | |
7403 | 1313 m.assign ("beingdeleted", get_beingdeleted ()); |
7363 | 1314 |
1315 return m; | |
1316 } | |
1317 | |
1318 void | |
1319 base_properties::set (const caseless_str& name, const octave_value& val) | |
1320 { | |
1321 if (name.compare ("tag")) | |
1322 set_tag (val); | |
1323 else if (name.compare ("__modified__")) | |
1324 __modified__ = val; | |
1325 else if (name.compare ("parent")) | |
1326 set_parent (val); | |
1327 else if (name.compare ("children")) | |
1328 maybe_set_children (children, val); | |
7366 | 1329 else if (name.compare ("busyaction")) |
1330 set_busyaction (val); | |
1331 else if (name.compare ("buttondownfcn")) | |
1332 set_buttondownfcn (val); | |
1333 else if (name.compare ("clipping")) | |
1334 set_clipping (val); | |
1335 else if (name.compare ("createfcn")) | |
1336 set_createfcn (val); | |
1337 else if (name.compare ("deletefcn")) | |
1338 set_deletefcn (val); | |
1339 else if (name.compare ("handlevisibility")) | |
1340 set_handlevisibility (val); | |
1341 else if (name.compare ("hittest")) | |
1342 set_hittest (val); | |
1343 else if (name.compare ("interruptible")) | |
1344 set_interruptible (val); | |
1345 else if (name.compare ("selected")) | |
1346 set_selected (val); | |
1347 else if (name.compare ("selectionhighlight")) | |
1348 set_selectionhighlight (val); | |
1349 else if (name.compare ("uicontextmenu")) | |
1350 set_uicontextmenu (val); | |
1351 else if (name.compare ("userdata")) | |
1352 set_userdata (val); | |
1353 else if (name.compare ("visible")) | |
1354 set_visible (val); | |
7363 | 1355 else |
1356 { | |
1357 std::map<caseless_str, property>::iterator it = all_props.find (name); | |
1358 | |
1359 if (it != all_props.end ()) | |
1360 it->second.set (val); | |
1361 else | |
1362 error ("set: unknown property \"%s\"", name.c_str ()); | |
1363 } | |
1364 | |
1365 if (! error_state && ! name.compare ("__modified__")) | |
1366 mark_modified (); | |
1367 } | |
1368 | |
1369 property | |
1370 base_properties::get_property (const caseless_str& name) const | |
1371 { | |
1372 std::map<caseless_str, property>::const_iterator it = all_props.find (name); | |
1373 | |
1374 if (it == all_props.end ()) | |
1375 return property (); | |
1376 else | |
1377 return it->second; | |
1378 } | |
1379 | |
6705 | 1380 void |
1381 base_properties::remove_child (const graphics_handle& h) | |
6406 | 1382 { |
6705 | 1383 octave_idx_type k = -1; |
1384 octave_idx_type n = children.numel (); | |
1385 for (octave_idx_type i = 0; i < n; i++) | |
6406 | 1386 { |
6874 | 1387 if (h.value () == children(i)) |
6406 | 1388 { |
6705 | 1389 k = i; |
1390 break; | |
6406 | 1391 } |
1392 } | |
1393 | |
6705 | 1394 if (k >= 0) |
6406 | 1395 { |
6705 | 1396 Matrix new_kids (1, n-1); |
1397 octave_idx_type j = 0; | |
1398 for (octave_idx_type i = 0; i < n; i++) | |
1399 { | |
1400 if (i != k) | |
1401 new_kids(j++) = children(i); | |
1402 } | |
1403 children = new_kids; | |
7378 | 1404 mark_modified (); |
6406 | 1405 } |
6705 | 1406 } |
6406 | 1407 |
6836 | 1408 void |
1409 base_properties::set_parent (const octave_value& val) | |
6705 | 1410 { |
1411 double tmp = val.double_value (); | |
6406 | 1412 |
6705 | 1413 graphics_handle new_parent = octave_NaN; |
6406 | 1414 |
6705 | 1415 if (! error_state) |
1416 { | |
1417 new_parent = gh_manager::lookup (tmp); | |
6406 | 1418 |
7056 | 1419 if (new_parent.ok ()) |
6705 | 1420 { |
7363 | 1421 graphics_object parent_obj = gh_manager::get_object (get_parent ()); |
6406 | 1422 |
6705 | 1423 parent_obj.remove_child (__myhandle__); |
6406 | 1424 |
7363 | 1425 parent = new_parent.as_octave_value (); |
6406 | 1426 |
7363 | 1427 ::adopt (parent.handle_value (), __myhandle__); |
6705 | 1428 } |
1429 else | |
1430 error ("set: invalid graphics handle (= %g) for parent", tmp); | |
1431 } | |
1432 else | |
1433 error ("set: expecting parent to be a graphics handle"); | |
1434 } | |
6432 | 1435 |
6705 | 1436 void |
6836 | 1437 base_properties::mark_modified (void) |
1438 { | |
7363 | 1439 __modified__ = "on"; |
1440 graphics_object parent_obj = gh_manager::get_object (get_parent ()); | |
7379 | 1441 if (parent_obj) |
1442 parent_obj.mark_modified (); | |
6836 | 1443 } |
1444 | |
1445 void | |
1446 base_properties::override_defaults (base_graphics_object& obj) | |
1447 { | |
7363 | 1448 graphics_object parent_obj = gh_manager::get_object (get_parent ()); |
6836 | 1449 parent_obj.override_defaults (obj); |
1450 } | |
1451 | |
1452 void | |
7214 | 1453 base_properties::update_axis_limits (const std::string& axis_type) const |
1454 { | |
7363 | 1455 graphics_handle h = (get_type () == "axes") ? __myhandle__ : get_parent (); |
7214 | 1456 |
1457 graphics_object obj = gh_manager::get_object (h); | |
1458 | |
1459 if (obj.isa ("axes")) | |
1460 obj.update_axis_limits (axis_type); | |
1461 } | |
1462 | |
1463 void | |
6836 | 1464 base_properties::delete_children (void) |
1465 { | |
1466 octave_idx_type n = children.numel (); | |
1467 | |
1468 for (octave_idx_type i = 0; i < n; i++) | |
1469 gh_manager::free (children(i)); | |
1470 } | |
1471 | |
7419 | 1472 graphics_backend |
1473 base_properties::get_backend (void) const | |
1474 { | |
1475 graphics_object go = gh_manager::get_object (get_parent ()); | |
1476 | |
1477 if (go) | |
1478 return go.get_backend (); | |
1479 else | |
1480 return graphics_backend (); | |
1481 } | |
1482 | |
7828
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
1483 void |
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
1484 base_properties::update_boundingbox (void) |
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
1485 { |
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
1486 Matrix kids = get_children (); |
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
1487 |
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
1488 for (int i = 0; i < kids.numel (); i++) |
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
1489 { |
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
1490 graphics_object go = gh_manager::get_object (kids(i)); |
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
1491 |
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
1492 if (go.valid_object ()) |
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
1493 go.get_properties ().update_boundingbox (); |
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
1494 } |
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
1495 } |
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
1496 |
7363 | 1497 // --------------------------------------------------------------------- |
1498 | |
7408 | 1499 class gnuplot_backend : public base_graphics_backend |
1500 { | |
1501 public: | |
1502 gnuplot_backend (void) | |
1503 : base_graphics_backend ("gnuplot") { } | |
1504 | |
1505 ~gnuplot_backend (void) { } | |
1506 | |
1507 bool is_valid (void) const { return true; } | |
1508 | |
1509 void close_figure (const octave_value& pstream) const | |
1510 { | |
1511 if (! pstream.is_empty()) | |
1512 { | |
1513 octave_value_list args; | |
7680
a0ec02774303
Use popen2 for communication with gnuplot
David Bateman <dbateman@free.fr>
parents:
7527
diff
changeset
|
1514 Matrix fids = pstream.matrix_value (); |
a0ec02774303
Use popen2 for communication with gnuplot
David Bateman <dbateman@free.fr>
parents:
7527
diff
changeset
|
1515 |
a0ec02774303
Use popen2 for communication with gnuplot
David Bateman <dbateman@free.fr>
parents:
7527
diff
changeset
|
1516 if (! error_state) |
a0ec02774303
Use popen2 for communication with gnuplot
David Bateman <dbateman@free.fr>
parents:
7527
diff
changeset
|
1517 { |
a0ec02774303
Use popen2 for communication with gnuplot
David Bateman <dbateman@free.fr>
parents:
7527
diff
changeset
|
1518 args(1) = "\nquit;\n"; |
a0ec02774303
Use popen2 for communication with gnuplot
David Bateman <dbateman@free.fr>
parents:
7527
diff
changeset
|
1519 args(0) = octave_value (fids (0)); |
a0ec02774303
Use popen2 for communication with gnuplot
David Bateman <dbateman@free.fr>
parents:
7527
diff
changeset
|
1520 feval ("fputs", args); |
a0ec02774303
Use popen2 for communication with gnuplot
David Bateman <dbateman@free.fr>
parents:
7527
diff
changeset
|
1521 args.resize (1); |
a0ec02774303
Use popen2 for communication with gnuplot
David Bateman <dbateman@free.fr>
parents:
7527
diff
changeset
|
1522 feval ("fflush", args); |
a0ec02774303
Use popen2 for communication with gnuplot
David Bateman <dbateman@free.fr>
parents:
7527
diff
changeset
|
1523 feval ("pclose", args); |
a0ec02774303
Use popen2 for communication with gnuplot
David Bateman <dbateman@free.fr>
parents:
7527
diff
changeset
|
1524 if (fids.numel () > 1) |
a0ec02774303
Use popen2 for communication with gnuplot
David Bateman <dbateman@free.fr>
parents:
7527
diff
changeset
|
1525 { |
a0ec02774303
Use popen2 for communication with gnuplot
David Bateman <dbateman@free.fr>
parents:
7527
diff
changeset
|
1526 args(0) = octave_value (fids (1)); |
a0ec02774303
Use popen2 for communication with gnuplot
David Bateman <dbateman@free.fr>
parents:
7527
diff
changeset
|
1527 feval ("pclose", args); |
a0ec02774303
Use popen2 for communication with gnuplot
David Bateman <dbateman@free.fr>
parents:
7527
diff
changeset
|
1528 } |
a0ec02774303
Use popen2 for communication with gnuplot
David Bateman <dbateman@free.fr>
parents:
7527
diff
changeset
|
1529 } |
7408 | 1530 } |
1531 } | |
1532 | |
1533 void redraw_figure (const graphics_handle& fh) const | |
1534 { | |
1535 octave_value_list args; | |
1536 args(0) = fh.as_octave_value (); | |
1537 feval ("gnuplot_drawnow", args); | |
1538 } | |
1539 | |
1540 void print_figure (const graphics_handle& fh, const std::string& term, | |
1541 const std::string& file, bool mono, | |
1542 const std::string& debug_file) const | |
1543 { | |
1544 octave_value_list args; | |
1545 if (! debug_file.empty ()) | |
1546 args(4) = debug_file; | |
7409 | 1547 args(3) = mono; |
1548 args(2) = file; | |
1549 args(1) = term; | |
1550 args(0) = fh.as_octave_value (); | |
7408 | 1551 feval ("gnuplot_drawnow", args); |
1552 } | |
1553 | |
7409 | 1554 Matrix get_canvas_size (const graphics_handle&) const |
7427 | 1555 { |
1556 Matrix sz (1, 2, 0.0); | |
1557 return sz; | |
1558 } | |
1559 | |
1560 double get_screen_resolution (void) const | |
1561 { return 72.0; } | |
7445 | 1562 |
1563 Matrix get_screen_size (void) const | |
1564 { return Matrix (1, 2, 0.0); } | |
7408 | 1565 }; |
1566 | |
1567 graphics_backend | |
1568 graphics_backend::default_backend (void) | |
1569 { | |
1570 if (available_backends.size () == 0) | |
1571 register_backend (new gnuplot_backend ()); | |
1572 | |
1573 return available_backends["gnuplot"]; | |
1574 } | |
1575 | |
1576 std::map<std::string, graphics_backend> graphics_backend::available_backends; | |
1577 | |
1578 // --------------------------------------------------------------------- | |
1579 | |
7363 | 1580 #include "graphics-props.cc" |
1581 | |
1582 // --------------------------------------------------------------------- | |
1583 | |
6836 | 1584 void |
7363 | 1585 root_figure::properties::set_currentfigure (const octave_value& v) |
6874 | 1586 { |
7378 | 1587 graphics_handle val (v); |
7363 | 1588 |
6874 | 1589 if (error_state) |
1590 return; | |
1591 | |
7059 | 1592 if (xisnan (val.value ()) || is_handle (val)) |
6874 | 1593 { |
1594 currentfigure = val; | |
1595 | |
7363 | 1596 gh_manager::push_figure (val); |
6874 | 1597 } |
1598 else | |
1599 gripe_set_invalid ("currentfigure"); | |
1600 } | |
1601 | |
7822
edbaa13397ee
Implement callbackobject property in root object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7820
diff
changeset
|
1602 void |
edbaa13397ee
Implement callbackobject property in root object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7820
diff
changeset
|
1603 root_figure::properties::set_callbackobject (const octave_value& v) |
edbaa13397ee
Implement callbackobject property in root object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7820
diff
changeset
|
1604 { |
edbaa13397ee
Implement callbackobject property in root object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7820
diff
changeset
|
1605 graphics_handle val (v); |
edbaa13397ee
Implement callbackobject property in root object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7820
diff
changeset
|
1606 |
edbaa13397ee
Implement callbackobject property in root object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7820
diff
changeset
|
1607 if (error_state) |
edbaa13397ee
Implement callbackobject property in root object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7820
diff
changeset
|
1608 return; |
edbaa13397ee
Implement callbackobject property in root object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7820
diff
changeset
|
1609 |
edbaa13397ee
Implement callbackobject property in root object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7820
diff
changeset
|
1610 if (xisnan (val.value ())) |
edbaa13397ee
Implement callbackobject property in root object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7820
diff
changeset
|
1611 { |
edbaa13397ee
Implement callbackobject property in root object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7820
diff
changeset
|
1612 if (! cbo_stack.empty ()) |
edbaa13397ee
Implement callbackobject property in root object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7820
diff
changeset
|
1613 { |
edbaa13397ee
Implement callbackobject property in root object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7820
diff
changeset
|
1614 val = cbo_stack.front (); |
edbaa13397ee
Implement callbackobject property in root object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7820
diff
changeset
|
1615 |
edbaa13397ee
Implement callbackobject property in root object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7820
diff
changeset
|
1616 cbo_stack.pop_front (); |
edbaa13397ee
Implement callbackobject property in root object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7820
diff
changeset
|
1617 } |
edbaa13397ee
Implement callbackobject property in root object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7820
diff
changeset
|
1618 |
edbaa13397ee
Implement callbackobject property in root object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7820
diff
changeset
|
1619 callbackobject = val; |
edbaa13397ee
Implement callbackobject property in root object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7820
diff
changeset
|
1620 } |
edbaa13397ee
Implement callbackobject property in root object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7820
diff
changeset
|
1621 else if (is_handle (val)) |
edbaa13397ee
Implement callbackobject property in root object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7820
diff
changeset
|
1622 { |
edbaa13397ee
Implement callbackobject property in root object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7820
diff
changeset
|
1623 if (get_callbackobject ().ok ()) |
edbaa13397ee
Implement callbackobject property in root object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7820
diff
changeset
|
1624 cbo_stack.push_front (get_callbackobject ()); |
edbaa13397ee
Implement callbackobject property in root object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7820
diff
changeset
|
1625 |
edbaa13397ee
Implement callbackobject property in root object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7820
diff
changeset
|
1626 callbackobject = val; |
edbaa13397ee
Implement callbackobject property in root object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7820
diff
changeset
|
1627 } |
edbaa13397ee
Implement callbackobject property in root object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7820
diff
changeset
|
1628 else |
edbaa13397ee
Implement callbackobject property in root object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7820
diff
changeset
|
1629 gripe_set_invalid ("callbackobject"); |
edbaa13397ee
Implement callbackobject property in root object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7820
diff
changeset
|
1630 } |
edbaa13397ee
Implement callbackobject property in root object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7820
diff
changeset
|
1631 |
6406 | 1632 property_list |
1633 root_figure::factory_properties = root_figure::init_factory_properties (); | |
1634 | |
1635 // --------------------------------------------------------------------- | |
1636 | |
7363 | 1637 void |
1638 figure::properties::set_currentaxes (const octave_value& v) | |
1639 { | |
7378 | 1640 graphics_handle val (v); |
6705 | 1641 |
6874 | 1642 if (error_state) |
1643 return; | |
1644 | |
7070 | 1645 if (xisnan (val.value ()) || is_handle (val)) |
6874 | 1646 currentaxes = val; |
1647 else | |
1648 gripe_set_invalid ("currentaxes"); | |
1649 } | |
1650 | |
1651 void | |
1652 figure::properties::set_visible (const octave_value& val) | |
1653 { | |
1654 std::string s = val.string_value (); | |
1655 | |
1656 if (! error_state) | |
1657 { | |
1658 if (s == "on") | |
1659 xset (0, "currentfigure", __myhandle__.value ()); | |
1660 | |
1661 visible = val; | |
1662 } | |
1663 } | |
1664 | |
1665 void | |
7408 | 1666 figure::properties::close (bool pop) |
6705 | 1667 { |
7408 | 1668 if (backend) |
1669 backend.close_figure (get___plot_stream__ ()); | |
1670 | |
1671 if (pop) | |
6406 | 1672 { |
7408 | 1673 gh_manager::pop_figure (__myhandle__); |
1674 | |
1675 graphics_handle cf = gh_manager::current_figure (); | |
1676 | |
1677 xset (0, "currentfigure", cf.value ()); | |
6406 | 1678 } |
6705 | 1679 } |
6432 | 1680 |
7445 | 1681 Matrix |
7447 | 1682 figure::properties::get_boundingbox (bool) const |
7445 | 1683 { |
1684 graphics_backend b = get_backend (); | |
1685 // FIXME: screen size should be obtained from root object | |
1686 Matrix screen_size = b.get_screen_size (); | |
1687 Matrix pos; | |
1688 | |
1689 pos = convert_position (get_position ().matrix_value (), get_units (), | |
1690 "pixels", screen_size, b); | |
1691 | |
1692 pos(0)--; | |
1693 pos(1)--; | |
7447 | 1694 pos(1) = screen_size(1) - pos(1) - pos(3); |
7445 | 1695 |
1696 return pos; | |
1697 } | |
1698 | |
7828
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
1699 void |
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
1700 figure::properties::set_boundingbox (const Matrix& bb) |
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
1701 { |
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
1702 graphics_backend b = get_backend (); |
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
1703 // FIXME: screen size should be obtained from root object |
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
1704 Matrix screen_size = b.get_screen_size (); |
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
1705 Matrix pos = bb; |
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
1706 |
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
1707 pos(1) = screen_size(1) - pos(1) - pos(3); |
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
1708 pos(1)++; |
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
1709 pos(0)++; |
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
1710 pos = convert_position (pos, "pixels", get_units (), screen_size, b); |
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
1711 |
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
1712 set_position (pos); |
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
1713 } |
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
1714 |
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
1715 void |
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
1716 figure::properties::set_position (const octave_value& v) |
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
1717 { |
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
1718 if (! error_state) |
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
1719 { |
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
1720 Matrix old_bb, new_bb; |
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
1721 |
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
1722 old_bb = get_boundingbox (); |
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
1723 position = v; |
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
1724 new_bb = get_boundingbox (); |
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
1725 |
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
1726 if (old_bb != new_bb) |
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
1727 { |
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
1728 // FIXME: maybe this should be converted into a more generic |
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
1729 // call like "update_gui (this)" |
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
1730 get_backend ().set_figure_position (__myhandle__, new_bb); |
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
1731 if (old_bb(2) != new_bb(2) || old_bb(3) != new_bb(3)) |
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
1732 { |
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
1733 execute_resizefcn (); |
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
1734 update_boundingbox (); |
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
1735 } |
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
1736 } |
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
1737 |
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
1738 mark_modified (); |
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
1739 } |
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
1740 } |
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
1741 |
6836 | 1742 octave_value |
7189 | 1743 figure::get_default (const caseless_str& name) const |
6836 | 1744 { |
1745 octave_value retval = default_properties.lookup (name); | |
1746 | |
1747 if (retval.is_undefined ()) | |
1748 { | |
1749 graphics_handle parent = get_parent (); | |
1750 graphics_object parent_obj = gh_manager::get_object (parent); | |
1751 | |
1752 retval = parent_obj.get_default (name); | |
1753 } | |
1754 | |
1755 return retval; | |
1756 } | |
1757 | |
6406 | 1758 // --------------------------------------------------------------------- |
1759 | |
7363 | 1760 void |
1761 axes::properties::set_title (const octave_value& v) | |
6962 | 1762 { |
7363 | 1763 graphics_handle val = ::reparent (v, "set", "title", __myhandle__, false); |
6962 | 1764 |
6874 | 1765 if (! error_state) |
1766 { | |
7363 | 1767 gh_manager::free (title.handle_value ()); |
6874 | 1768 title = val; |
1769 } | |
1770 } | |
1771 | |
1772 void | |
7363 | 1773 axes::properties::set_xlabel (const octave_value& v) |
6874 | 1774 { |
7363 | 1775 graphics_handle val = ::reparent (v, "set", "xlabel", __myhandle__, false); |
6874 | 1776 |
1777 if (! error_state) | |
1778 { | |
7363 | 1779 gh_manager::free (xlabel.handle_value ()); |
6874 | 1780 xlabel = val; |
1781 } | |
1782 } | |
1783 | |
1784 void | |
7363 | 1785 axes::properties::set_ylabel (const octave_value& v) |
6874 | 1786 { |
7363 | 1787 graphics_handle val = ::reparent (v, "set", "ylabel", __myhandle__, false); |
6874 | 1788 |
1789 if (! error_state) | |
1790 { | |
7363 | 1791 gh_manager::free (ylabel.handle_value ()); |
6874 | 1792 ylabel = val; |
1793 } | |
1794 } | |
1795 | |
1796 void | |
7363 | 1797 axes::properties::set_zlabel (const octave_value& v) |
6874 | 1798 { |
7363 | 1799 graphics_handle val = ::reparent (v, "set", "zlabel", __myhandle__, false); |
6874 | 1800 |
1801 if (! error_state) | |
1802 { | |
7363 | 1803 gh_manager::free (zlabel.handle_value ()); |
6874 | 1804 zlabel = val; |
1805 } | |
1806 } | |
1807 | |
1808 void | |
6844 | 1809 axes::properties::set_defaults (base_graphics_object& obj, |
6890 | 1810 const std::string& mode) |
6705 | 1811 { |
7427 | 1812 position = default_axes_position (); |
7363 | 1813 title = graphics_handle (); |
6705 | 1814 box = "on"; |
1815 key = "off"; | |
1816 keybox = "off"; | |
7363 | 1817 keypos = 1.0; |
6962 | 1818 colororder = default_colororder (); |
6705 | 1819 dataaspectratio = Matrix (1, 3, 1.0); |
1820 dataaspectratiomode = "auto"; | |
7363 | 1821 layer = "bottom"; |
6705 | 1822 |
1823 Matrix tlim (1, 2, 0.0); | |
1824 tlim(1) = 1; | |
1825 xlim = tlim; | |
1826 ylim = tlim; | |
1827 zlim = tlim; | |
6807 | 1828 |
1829 Matrix cl (1, 2, 0); | |
1830 cl(1) = 1; | |
1831 clim = cl; | |
1832 | |
7363 | 1833 xlimmode = "auto"; |
1834 ylimmode = "auto"; | |
1835 zlimmode = "auto"; | |
1836 climmode = "auto"; | |
1837 xlabel = graphics_handle (); | |
1838 ylabel = graphics_handle (); | |
1839 zlabel = graphics_handle (); | |
6705 | 1840 xgrid = "off"; |
1841 ygrid = "off"; | |
1842 zgrid = "off"; | |
1843 xminorgrid = "off"; | |
1844 yminorgrid = "off"; | |
1845 zminorgrid = "off"; | |
1846 xtick = Matrix (); | |
1847 ytick = Matrix (); | |
1848 ztick = Matrix (); | |
1849 xtickmode = "auto"; | |
1850 ytickmode = "auto"; | |
1851 ztickmode = "auto"; | |
1852 xticklabel = ""; | |
1853 yticklabel = ""; | |
1854 zticklabel = ""; | |
1855 xticklabelmode = "auto"; | |
1856 yticklabelmode = "auto"; | |
1857 zticklabelmode = "auto"; | |
7453 | 1858 color = color_values (1, 1, 1); |
7364 | 1859 xcolor = color_values ("black"); |
1860 ycolor = color_values ("black"); | |
1861 zcolor = color_values ("black"); | |
7363 | 1862 xscale = "linear"; |
1863 yscale = "linear"; | |
1864 zscale = "linear"; | |
6705 | 1865 xdir = "normal"; |
1866 ydir = "normal"; | |
1867 zdir = "normal"; | |
7363 | 1868 yaxislocation = "left"; |
1869 xaxislocation = "bottom"; | |
6705 | 1870 |
7427 | 1871 // Note: camera properties will be set through update_transform |
1872 camerapositionmode = "auto"; | |
1873 cameratargetmode = "auto"; | |
1874 cameraupvectormode = "auto"; | |
1875 cameraviewanglemode = "auto"; | |
1876 plotboxaspectratio = Matrix (1, 3, 1.0); | |
1877 drawmode = "normal"; | |
1878 fontangle = "normal"; | |
1879 fontname = "Helvetica"; | |
1880 fontsize = 12; | |
1881 fontunits = "points"; | |
1882 fontweight = "normal"; | |
7820
cb4838d70ab2
Fix default value for axes gridlinestyle and minorgridlinestyle.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7680
diff
changeset
|
1883 gridlinestyle = ":"; |
7427 | 1884 linestyleorder = "-"; |
1885 linewidth = 0.5; | |
7820
cb4838d70ab2
Fix default value for axes gridlinestyle and minorgridlinestyle.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7680
diff
changeset
|
1886 minorgridlinestyle = ":"; |
7427 | 1887 // Note: plotboxaspectratio will be set through update_aspectratiors |
1888 plotboxaspectratiomode = "auto"; | |
1889 projection = "orthographic"; | |
1890 tickdir = "in"; | |
1891 tickdirmode = "auto"; | |
1892 ticklength = Matrix (1, 2, 0.1); | |
1893 tightinset = Matrix (1, 4, 0.0); | |
1894 | |
1895 sx = "linear"; | |
1896 sy = "linear"; | |
1897 sz = "linear"; | |
1898 | |
6705 | 1899 Matrix tview (1, 2, 0.0); |
1900 tview(1) = 90; | |
1901 view = tview; | |
1902 | |
6765 | 1903 visible = "on"; |
6705 | 1904 nextplot = "replace"; |
1905 | |
1906 // FIXME -- this is not quite right; we should preserve | |
1907 // "position" and "units". | |
1908 | |
1909 if (mode != "replace") | |
1910 { | |
6406 | 1911 Matrix touterposition (1, 4, 0.0); |
1912 touterposition(2) = 1; | |
1913 touterposition(3) = 1; | |
1914 outerposition = touterposition; | |
1915 } | |
1916 | |
7363 | 1917 activepositionproperty = "outerposition"; |
1918 __colorbar__ = "none"; | |
7189 | 1919 |
6705 | 1920 delete_children (); |
6406 | 1921 |
6705 | 1922 children = Matrix (); |
6432 | 1923 |
7427 | 1924 update_transform (); |
1925 | |
6705 | 1926 override_defaults (obj); |
1927 } | |
1928 | |
6874 | 1929 graphics_handle |
1930 axes::properties::get_title (void) const | |
1931 { | |
7363 | 1932 if (! title.handle_value ().ok ()) |
6874 | 1933 title = gh_manager::make_graphics_handle ("text", __myhandle__); |
1934 | |
7363 | 1935 return title.handle_value (); |
6874 | 1936 } |
1937 | |
1938 graphics_handle | |
1939 axes::properties::get_xlabel (void) const | |
1940 { | |
7363 | 1941 if (! xlabel.handle_value ().ok ()) |
6874 | 1942 xlabel = gh_manager::make_graphics_handle ("text", __myhandle__); |
1943 | |
7363 | 1944 return xlabel.handle_value (); |
6874 | 1945 } |
1946 | |
1947 graphics_handle | |
1948 axes::properties::get_ylabel (void) const | |
1949 { | |
7363 | 1950 if (! ylabel.handle_value ().ok ()) |
6874 | 1951 ylabel = gh_manager::make_graphics_handle ("text", __myhandle__); |
1952 | |
7363 | 1953 return ylabel.handle_value (); |
6874 | 1954 } |
1955 | |
1956 graphics_handle | |
1957 axes::properties::get_zlabel (void) const | |
1958 { | |
7363 | 1959 if (! zlabel.handle_value ().ok ()) |
6874 | 1960 zlabel = gh_manager::make_graphics_handle ("text", __myhandle__); |
1961 | |
7363 | 1962 return zlabel.handle_value (); |
6705 | 1963 } |
6406 | 1964 |
6705 | 1965 void |
6844 | 1966 axes::properties::remove_child (const graphics_handle& h) |
6705 | 1967 { |
7363 | 1968 if (title.handle_value ().ok () && h == title.handle_value ()) |
6705 | 1969 title = gh_manager::make_graphics_handle ("text", __myhandle__); |
7363 | 1970 else if (xlabel.handle_value ().ok () && h == xlabel.handle_value ()) |
6705 | 1971 xlabel = gh_manager::make_graphics_handle ("text", __myhandle__); |
7363 | 1972 else if (ylabel.handle_value ().ok () && h == ylabel.handle_value ()) |
6705 | 1973 ylabel = gh_manager::make_graphics_handle ("text", __myhandle__); |
7363 | 1974 else if (zlabel.handle_value ().ok () && h == zlabel.handle_value ()) |
6705 | 1975 zlabel = gh_manager::make_graphics_handle ("text", __myhandle__); |
1976 else | |
1977 base_properties::remove_child (h); | |
1978 } | |
6406 | 1979 |
6705 | 1980 void |
6844 | 1981 axes::properties::delete_children (void) |
6705 | 1982 { |
1983 base_properties::delete_children (); | |
1984 | |
7363 | 1985 gh_manager::free (title.handle_value ()); |
1986 gh_manager::free (xlabel.handle_value ()); | |
1987 gh_manager::free (ylabel.handle_value ()); | |
1988 gh_manager::free (zlabel.handle_value ()); | |
6705 | 1989 } |
6406 | 1990 |
7427 | 1991 inline Matrix |
1992 xform_matrix (void) | |
1993 { | |
1994 Matrix m (4, 4, 0.0); | |
1995 for (int i = 0; i < 4; i++) | |
1996 m(i,i) = 1; | |
1997 return m; | |
1998 } | |
1999 | |
2000 inline ColumnVector | |
2001 xform_vector (void) | |
2002 { | |
2003 ColumnVector v (4, 0.0); | |
2004 v(3) = 1; | |
2005 return v; | |
2006 } | |
2007 | |
2008 inline ColumnVector | |
2009 xform_vector (double x, double y, double z) | |
2010 { | |
2011 ColumnVector v (4, 1.0); | |
2012 v(0) = x; v(1) = y; v(2) = z; | |
2013 return v; | |
2014 } | |
2015 | |
2016 inline ColumnVector | |
2017 transform (const Matrix& m, double x, double y, double z) | |
2018 { | |
2019 return (m * xform_vector (x, y, z)); | |
2020 } | |
2021 | |
2022 inline Matrix | |
2023 xform_scale (double x, double y, double z) | |
2024 { | |
2025 Matrix m (4, 4, 0.0); | |
2026 m(0,0) = x; m(1,1) = y; m(2,2) = z; m(3,3) = 1; | |
2027 return m; | |
2028 } | |
2029 | |
2030 inline Matrix | |
2031 xform_translate (double x, double y, double z) | |
2032 { | |
2033 Matrix m = xform_matrix (); | |
2034 m(0,3) = x; m(1,3) = y; m(2,3) = z; m(3,3) = 1; | |
2035 return m; | |
2036 } | |
2037 | |
2038 inline void | |
2039 scale (Matrix& m, double x, double y, double z) | |
2040 { | |
2041 m = m * xform_scale (x, y, z); | |
2042 } | |
2043 | |
2044 inline void | |
2045 translate (Matrix& m, double x, double y, double z) | |
2046 { | |
2047 m = m * xform_translate (x, y, z); | |
2048 } | |
2049 | |
2050 inline void | |
2051 xform (ColumnVector& v, const Matrix& m) | |
2052 { | |
2053 v = m*v; | |
2054 } | |
2055 | |
2056 inline void | |
2057 scale (ColumnVector& v, double x, double y, double z) | |
2058 { | |
2059 v(0) *= x; | |
2060 v(1) *= y; | |
2061 v(2) *= z; | |
2062 } | |
2063 | |
2064 inline void | |
2065 translate (ColumnVector& v, double x, double y, double z) | |
2066 { | |
2067 v(0) += x; | |
2068 v(1) += y; | |
2069 v(2) += z; | |
2070 } | |
2071 | |
2072 inline void | |
2073 normalize (ColumnVector& v) | |
2074 { | |
2075 double fact = 1.0/sqrt(v(0)*v(0)+v(1)*v(1)+v(2)*v(2)); | |
2076 scale (v, fact, fact, fact); | |
2077 } | |
2078 | |
2079 inline double | |
2080 dot (const ColumnVector& v1, const ColumnVector& v2) | |
2081 { | |
2082 return (v1(0)*v2(0)+v1(1)*v2(1)+v1(2)*v2(2)); | |
2083 } | |
2084 | |
2085 inline double | |
2086 norm (const ColumnVector& v) | |
2087 { | |
2088 return sqrt (dot (v, v)); | |
2089 } | |
2090 | |
2091 inline ColumnVector | |
2092 cross (const ColumnVector& v1, const ColumnVector& v2) | |
2093 { | |
2094 ColumnVector r = xform_vector (); | |
2095 r(0) = v1(1)*v2(2)-v1(2)*v2(1); | |
2096 r(1) = v1(2)*v2(0)-v1(0)*v2(2); | |
2097 r(2) = v1(0)*v2(1)-v1(1)*v2(0); | |
2098 return r; | |
2099 } | |
2100 | |
2101 inline Matrix | |
2102 unit_cube (void) | |
2103 { | |
2104 static double data[32] = { | |
2105 0,0,0,1, | |
2106 1,0,0,1, | |
2107 0,1,0,1, | |
2108 0,0,1,1, | |
2109 1,1,0,1, | |
2110 1,0,1,1, | |
2111 0,1,1,1, | |
2112 1,1,1,1}; | |
2113 Matrix m (4, 8); | |
2114 memcpy (m.fortran_vec (), data, sizeof(double)*32); | |
2115 return m; | |
2116 } | |
2117 | |
2118 inline ColumnVector | |
2119 cam2xform (const Array<double>& m) | |
2120 { | |
2121 ColumnVector retval (4, 1.0); | |
2122 memcpy (retval.fortran_vec (), m.fortran_vec (), sizeof(double)*3); | |
2123 return retval; | |
2124 } | |
2125 | |
2126 inline RowVector | |
2127 xform2cam (const ColumnVector& v) | |
2128 { | |
2129 return v.extract_n (0, 3).transpose (); | |
2130 } | |
2131 | |
2132 void | |
2133 axes::properties::update_camera (void) | |
2134 { | |
2135 double xd = (xdir_is ("normal") ? 1 : -1); | |
2136 double yd = (ydir_is ("normal") ? 1 : -1); | |
2137 double zd = (zdir_is ("normal") ? 1 : -1); | |
2138 | |
7526
52d58b0463ed
graphics.cc, graphics.h.in: avoid some GCC warnings
John W. Eaton <jwe@octave.org>
parents:
7523
diff
changeset
|
2139 Matrix xlimits = sx.scale (get_xlim ().matrix_value ()); |
52d58b0463ed
graphics.cc, graphics.h.in: avoid some GCC warnings
John W. Eaton <jwe@octave.org>
parents:
7523
diff
changeset
|
2140 Matrix ylimits = sy.scale (get_ylim ().matrix_value ()); |
52d58b0463ed
graphics.cc, graphics.h.in: avoid some GCC warnings
John W. Eaton <jwe@octave.org>
parents:
7523
diff
changeset
|
2141 Matrix zlimits = sz.scale (get_zlim ().matrix_value ()); |
52d58b0463ed
graphics.cc, graphics.h.in: avoid some GCC warnings
John W. Eaton <jwe@octave.org>
parents:
7523
diff
changeset
|
2142 |
52d58b0463ed
graphics.cc, graphics.h.in: avoid some GCC warnings
John W. Eaton <jwe@octave.org>
parents:
7523
diff
changeset
|
2143 double xo = xlimits(xd > 0 ? 0 : 1); |
52d58b0463ed
graphics.cc, graphics.h.in: avoid some GCC warnings
John W. Eaton <jwe@octave.org>
parents:
7523
diff
changeset
|
2144 double yo = ylimits(yd > 0 ? 0 : 1); |
52d58b0463ed
graphics.cc, graphics.h.in: avoid some GCC warnings
John W. Eaton <jwe@octave.org>
parents:
7523
diff
changeset
|
2145 double zo = zlimits(zd > 0 ? 0 : 1); |
7427 | 2146 |
2147 Matrix pb = get_plotboxaspectratio ().matrix_value (); | |
2148 | |
2149 bool autocam = (camerapositionmode_is ("auto") | |
2150 && cameratargetmode_is ("auto") | |
2151 && cameraupvectormode_is ("auto") | |
2152 && cameraviewanglemode_is ("auto")); | |
2153 bool dowarp = (autocam && dataaspectratiomode_is("auto") | |
2154 && plotboxaspectratiomode_is ("auto")); | |
2155 | |
2156 ColumnVector c_eye (xform_vector ()); | |
2157 ColumnVector c_center (xform_vector ()); | |
2158 ColumnVector c_upv (xform_vector ()); | |
2159 | |
2160 if (cameratargetmode_is ("auto")) | |
2161 { | |
7526
52d58b0463ed
graphics.cc, graphics.h.in: avoid some GCC warnings
John W. Eaton <jwe@octave.org>
parents:
7523
diff
changeset
|
2162 c_center(0) = (xlimits(0)+xlimits(1))/2; |
52d58b0463ed
graphics.cc, graphics.h.in: avoid some GCC warnings
John W. Eaton <jwe@octave.org>
parents:
7523
diff
changeset
|
2163 c_center(1) = (ylimits(0)+ylimits(1))/2; |
52d58b0463ed
graphics.cc, graphics.h.in: avoid some GCC warnings
John W. Eaton <jwe@octave.org>
parents:
7523
diff
changeset
|
2164 c_center(2) = (zlimits(0)+zlimits(1))/2; |
7427 | 2165 |
2166 cameratarget = xform2cam (c_center); | |
2167 } | |
2168 else | |
2169 c_center = cam2xform (get_cameratarget ().matrix_value ()); | |
2170 | |
2171 if (camerapositionmode_is ("auto")) | |
2172 { | |
7526
52d58b0463ed
graphics.cc, graphics.h.in: avoid some GCC warnings
John W. Eaton <jwe@octave.org>
parents:
7523
diff
changeset
|
2173 Matrix tview = get_view ().matrix_value (); |
52d58b0463ed
graphics.cc, graphics.h.in: avoid some GCC warnings
John W. Eaton <jwe@octave.org>
parents:
7523
diff
changeset
|
2174 double az = tview(0), el = tview(1); |
7427 | 2175 double d = 5*sqrt(pb(0)*pb(0)+pb(1)*pb(1)+pb(2)*pb(2)); |
2176 | |
2177 if (el == 90 || el == -90) | |
2178 c_eye(2) = d*signum(el); | |
2179 else | |
2180 { | |
2181 az *= M_PI/180.0; | |
2182 el *= M_PI/180.0; | |
2183 c_eye(0) = d*cos(el)*sin(az); | |
2184 c_eye(1) = -d*cos(el)*cos(az); | |
2185 c_eye(2) = d*sin(el); | |
2186 } | |
7526
52d58b0463ed
graphics.cc, graphics.h.in: avoid some GCC warnings
John W. Eaton <jwe@octave.org>
parents:
7523
diff
changeset
|
2187 c_eye(0) = c_eye(0)*(xlimits(1)-xlimits(0))/(xd*pb(0))+c_center(0); |
52d58b0463ed
graphics.cc, graphics.h.in: avoid some GCC warnings
John W. Eaton <jwe@octave.org>
parents:
7523
diff
changeset
|
2188 c_eye(1) = c_eye(1)*(ylimits(1)-ylimits(0))/(yd*pb(1))+c_center(1); |
52d58b0463ed
graphics.cc, graphics.h.in: avoid some GCC warnings
John W. Eaton <jwe@octave.org>
parents:
7523
diff
changeset
|
2189 c_eye(2) = c_eye(2)*(zlimits(1)-zlimits(0))/(zd*pb(2))+c_center(2); |
7427 | 2190 |
2191 cameraposition = xform2cam (c_eye); | |
2192 } | |
2193 else | |
2194 c_eye = cam2xform (get_cameraposition ().matrix_value ()); | |
2195 | |
2196 if (cameraupvectormode_is ("auto")) | |
2197 { | |
7526
52d58b0463ed
graphics.cc, graphics.h.in: avoid some GCC warnings
John W. Eaton <jwe@octave.org>
parents:
7523
diff
changeset
|
2198 Matrix tview = get_view ().matrix_value (); |
52d58b0463ed
graphics.cc, graphics.h.in: avoid some GCC warnings
John W. Eaton <jwe@octave.org>
parents:
7523
diff
changeset
|
2199 double az = tview(0), el = tview(1); |
7427 | 2200 |
2201 if (el == 90 || el == -90) | |
2202 { | |
7526
52d58b0463ed
graphics.cc, graphics.h.in: avoid some GCC warnings
John W. Eaton <jwe@octave.org>
parents:
7523
diff
changeset
|
2203 c_upv(0) = -sin(az*M_PI/180.0)*(xlimits(1)-xlimits(0))/pb(0); |
52d58b0463ed
graphics.cc, graphics.h.in: avoid some GCC warnings
John W. Eaton <jwe@octave.org>
parents:
7523
diff
changeset
|
2204 c_upv(1) = cos(az*M_PI/180.0)*(ylimits(1)-ylimits(0))/pb(1); |
7427 | 2205 } |
2206 else | |
2207 c_upv(2) = 1; | |
2208 | |
2209 cameraupvector = xform2cam (c_upv); | |
2210 } | |
2211 else | |
2212 c_upv = cam2xform (get_cameraupvector ().matrix_value ()); | |
2213 | |
2214 Matrix x_view = xform_matrix (); | |
2215 Matrix x_projection = xform_matrix (); | |
2216 Matrix x_viewport = xform_matrix (); | |
2217 Matrix x_normrender = xform_matrix (); | |
2218 Matrix x_pre = xform_matrix (); | |
2219 | |
2220 x_render = xform_matrix (); | |
2221 x_render_inv = xform_matrix (); | |
2222 | |
2223 scale (x_pre, pb(0), pb(1), pb(2)); | |
2224 translate (x_pre, -0.5, -0.5, -0.5); | |
7526
52d58b0463ed
graphics.cc, graphics.h.in: avoid some GCC warnings
John W. Eaton <jwe@octave.org>
parents:
7523
diff
changeset
|
2225 scale (x_pre, xd/(xlimits(1)-xlimits(0)), yd/(ylimits(1)-ylimits(0)), |
52d58b0463ed
graphics.cc, graphics.h.in: avoid some GCC warnings
John W. Eaton <jwe@octave.org>
parents:
7523
diff
changeset
|
2226 zd/(zlimits(1)-zlimits(0))); |
7427 | 2227 translate (x_pre, -xo, -yo, -zo); |
2228 | |
2229 xform (c_eye, x_pre); | |
2230 xform (c_center, x_pre); | |
7526
52d58b0463ed
graphics.cc, graphics.h.in: avoid some GCC warnings
John W. Eaton <jwe@octave.org>
parents:
7523
diff
changeset
|
2231 scale (c_upv, pb(0)/(xlimits(1)-xlimits(0)), pb(1)/(ylimits(1)-ylimits(0)), |
52d58b0463ed
graphics.cc, graphics.h.in: avoid some GCC warnings
John W. Eaton <jwe@octave.org>
parents:
7523
diff
changeset
|
2232 pb(2)/(zlimits(1)-zlimits(0))); |
7427 | 2233 translate (c_center, -c_eye(0), -c_eye(1), -c_eye(2)); |
2234 | |
2235 ColumnVector F (c_center), f (F), UP (c_upv); | |
2236 normalize (f); | |
2237 normalize (UP); | |
2238 | |
7440 | 2239 if (std::abs (dot (f, UP)) > 1e-15) |
7427 | 2240 { |
2241 double fa = 1/sqrt(1-f(2)*f(2)); | |
2242 scale (UP, fa, fa, fa); | |
2243 } | |
2244 | |
2245 ColumnVector s = cross (f, UP); | |
2246 ColumnVector u = cross (s, f); | |
2247 | |
2248 scale (x_view, 1, 1, -1); | |
2249 Matrix l = xform_matrix (); | |
2250 l(0,0) = s(0); l(0,1) = s(1); l(0,2) = s(2); | |
2251 l(1,0) = u(0); l(1,1) = u(1); l(1,2) = u(2); | |
2252 l(2,0) = -f(0); l(2,1) = -f(1); l(2,2) = -f(2); | |
2253 x_view = x_view * l; | |
2254 translate (x_view, -c_eye(0), -c_eye(1), -c_eye(2)); | |
2255 scale (x_view, pb(0), pb(1), pb(2)); | |
2256 translate (x_view, -0.5, -0.5, -0.5); | |
2257 | |
2258 Matrix x_cube = x_view * unit_cube (); | |
2259 ColumnVector cmin = x_cube.row_min (), cmax = x_cube.row_max (); | |
2260 double xM = cmax(0)-cmin(0); | |
2261 double yM = cmax(1)-cmin(1); | |
2262 | |
7447 | 2263 Matrix bb = get_boundingbox (true); |
7427 | 2264 |
2265 double v_angle; | |
2266 | |
2267 if (cameraviewanglemode_is ("auto")) | |
2268 { | |
2269 double af; | |
2270 | |
2271 // FIXME: Was this really needed? When compared to Matlab, it | |
2272 // does not seem to be required. Need investigation with concrete | |
2273 // backend to see results visually. | |
2274 if (false && dowarp) | |
2275 af = 1.0 / (xM > yM ? xM : yM); | |
2276 else | |
2277 { | |
2278 if ((bb(2)/bb(3)) > (xM/yM)) | |
2279 af = 1.0 / yM; | |
2280 else | |
2281 af = 1.0 / xM; | |
2282 } | |
2283 v_angle = 2 * (180.0 / M_PI) * atan (1 / (2 * af * norm (F))); | |
2284 | |
2285 cameraviewangle = v_angle; | |
2286 } | |
2287 else | |
2288 v_angle = get_cameraviewangle (); | |
2289 | |
2290 double pf = 1 / (2 * tan ((v_angle / 2) * M_PI / 180.0) * norm (F)); | |
2291 scale (x_projection, pf, pf, 1); | |
2292 | |
2293 if (dowarp) | |
2294 { | |
2295 xM *= pf; | |
2296 yM *= pf; | |
7447 | 2297 translate (x_viewport, bb(0)+bb(2)/2, bb(1)+bb(3)/2, 0); |
7427 | 2298 scale (x_viewport, bb(2)/xM, -bb(3)/yM, 1); |
2299 } | |
2300 else | |
2301 { | |
2302 double pix = 1; | |
2303 if (autocam) | |
2304 { | |
2305 if ((bb(2)/bb(3)) > (xM/yM)) | |
2306 pix = bb(3); | |
2307 else | |
2308 pix = bb(2); | |
2309 } | |
2310 else | |
2311 pix = (bb(2) < bb(3) ? bb(2) : bb(3)); | |
7447 | 2312 translate (x_viewport, bb(0)+bb(2)/2, bb(1)+bb(3)/2, 0); |
7427 | 2313 scale (x_viewport, pix, -pix, 1); |
2314 } | |
2315 | |
2316 x_normrender = x_viewport * x_projection * x_view; | |
2317 | |
2318 x_cube = x_normrender * unit_cube (); | |
2319 cmin = x_cube.row_min (); | |
2320 cmax = x_cube.row_max (); | |
2321 x_zlim.resize (1, 2); | |
2322 x_zlim(0) = cmin(2); | |
2323 x_zlim(1) = cmax(2); | |
2324 | |
2325 x_render = x_normrender; | |
7526
52d58b0463ed
graphics.cc, graphics.h.in: avoid some GCC warnings
John W. Eaton <jwe@octave.org>
parents:
7523
diff
changeset
|
2326 scale (x_render, xd/(xlimits(1)-xlimits(0)), yd/(ylimits(1)-ylimits(0)), |
52d58b0463ed
graphics.cc, graphics.h.in: avoid some GCC warnings
John W. Eaton <jwe@octave.org>
parents:
7523
diff
changeset
|
2327 zd/(zlimits(1)-zlimits(0))); |
7427 | 2328 translate (x_render, -xo, -yo, -zo); |
2329 | |
2330 x_viewtransform = x_view; | |
2331 x_projectiontransform = x_projection; | |
2332 x_viewporttransform = x_viewport; | |
2333 x_normrendertransform = x_normrender; | |
2334 x_rendertransform = x_render; | |
2335 | |
2336 x_render_inv = x_render.inverse (); | |
2337 | |
2338 // Note: these matrices are a slight modified version of the regular | |
2339 // matrices, more suited for OpenGL rendering (x_gl_mat1 => light | |
2340 // => x_gl_mat2) | |
2341 x_gl_mat1 = x_view; | |
7526
52d58b0463ed
graphics.cc, graphics.h.in: avoid some GCC warnings
John W. Eaton <jwe@octave.org>
parents:
7523
diff
changeset
|
2342 scale (x_gl_mat1, xd/(xlimits(1)-xlimits(0)), yd/(ylimits(1)-ylimits(0)), |
52d58b0463ed
graphics.cc, graphics.h.in: avoid some GCC warnings
John W. Eaton <jwe@octave.org>
parents:
7523
diff
changeset
|
2343 zd/(zlimits(1)-zlimits(0))); |
7427 | 2344 translate (x_gl_mat1, -xo, -yo, -zo); |
2345 x_gl_mat2 = x_viewport * x_projection; | |
2346 } | |
2347 | |
2348 void | |
2349 axes::properties::update_aspectratios (void) | |
2350 { | |
7526
52d58b0463ed
graphics.cc, graphics.h.in: avoid some GCC warnings
John W. Eaton <jwe@octave.org>
parents:
7523
diff
changeset
|
2351 Matrix xlimits = get_xlim ().matrix_value (); |
52d58b0463ed
graphics.cc, graphics.h.in: avoid some GCC warnings
John W. Eaton <jwe@octave.org>
parents:
7523
diff
changeset
|
2352 Matrix ylimits = get_ylim ().matrix_value (); |
52d58b0463ed
graphics.cc, graphics.h.in: avoid some GCC warnings
John W. Eaton <jwe@octave.org>
parents:
7523
diff
changeset
|
2353 Matrix zlimits = get_zlim ().matrix_value (); |
52d58b0463ed
graphics.cc, graphics.h.in: avoid some GCC warnings
John W. Eaton <jwe@octave.org>
parents:
7523
diff
changeset
|
2354 |
52d58b0463ed
graphics.cc, graphics.h.in: avoid some GCC warnings
John W. Eaton <jwe@octave.org>
parents:
7523
diff
changeset
|
2355 double dx = (xlimits(1)-xlimits(0)); |
52d58b0463ed
graphics.cc, graphics.h.in: avoid some GCC warnings
John W. Eaton <jwe@octave.org>
parents:
7523
diff
changeset
|
2356 double dy = (ylimits(1)-ylimits(0)); |
52d58b0463ed
graphics.cc, graphics.h.in: avoid some GCC warnings
John W. Eaton <jwe@octave.org>
parents:
7523
diff
changeset
|
2357 double dz = (zlimits(1)-zlimits(0)); |
7427 | 2358 |
2359 if (dataaspectratiomode_is ("auto")) | |
2360 { | |
2361 double dmin = xmin (xmin (dx, dy), dz); | |
2362 Matrix da (1, 3, 0.0); | |
2363 | |
2364 da(0) = dx/dmin; | |
2365 da(1) = dy/dmin; | |
2366 da(2) = dz/dmin; | |
2367 | |
2368 dataaspectratio = da; | |
2369 } | |
2370 | |
2371 if (plotboxaspectratiomode_is ("auto")) | |
2372 { | |
2373 if (dataaspectratiomode_is ("auto")) | |
2374 plotboxaspectratio = Matrix (1, 3, 1.0); | |
2375 else | |
2376 { | |
2377 Matrix da = get_dataaspectratio ().matrix_value (); | |
2378 Matrix pba (1, 3, 0.0); | |
2379 | |
2380 pba(0) = dx/da(0); | |
2381 pba(1) = dy/da(1); | |
2382 pba(2) = dz/da(2); | |
2383 } | |
2384 } | |
2385 | |
2386 // FIXME: if plotboxaspectratiomode is "manual", limits | |
2387 // and/or dataaspectratio might be adapted | |
2388 } | |
2389 | |
7447 | 2390 // The INTERNAL flag defines whether position or outerposition is used. |
2391 | |
7427 | 2392 Matrix |
7447 | 2393 axes::properties::get_boundingbox (bool internal) const |
7427 | 2394 { |
7447 | 2395 graphics_object obj = gh_manager::get_object (get_parent ()); |
2396 Matrix parent_bb = obj.get_properties ().get_boundingbox (true); | |
2397 Matrix pos = (internal ? | |
2398 get_position ().matrix_value () | |
2399 : get_outerposition ().matrix_value ()); | |
2400 | |
2401 | |
2402 pos = convert_position (pos, get_units (), "pixels", | |
2403 parent_bb.extract_n (0, 2, 1, 2), get_backend ()); | |
7427 | 2404 pos(0)--; |
2405 pos(1)--; | |
7447 | 2406 pos(1) = parent_bb(3) - pos(1) - pos(3); |
7427 | 2407 |
2408 return pos; | |
2409 } | |
2410 | |
7435 | 2411 ColumnVector |
2412 graphics_xform::xform_vector (double x, double y, double z) | |
2413 { return ::xform_vector (x, y, z); } | |
2414 | |
2415 Matrix | |
2416 graphics_xform::xform_eye (void) | |
2417 { return ::xform_matrix (); } | |
2418 | |
2419 ColumnVector | |
2420 graphics_xform::transform (double x, double y, double z, | |
2421 bool use_scale) const | |
2422 { | |
2423 if (use_scale) | |
2424 { | |
2425 x = sx.scale (x); | |
2426 y = sy.scale (y); | |
2427 z = sz.scale (z); | |
2428 } | |
2429 | |
2430 return ::transform (xform, x, y, z); | |
2431 } | |
2432 | |
2433 ColumnVector | |
2434 graphics_xform::untransform (double x, double y, double z, | |
2435 bool use_scale) const | |
2436 { | |
2437 ColumnVector v = ::transform (xform_inv, x, y, z); | |
2438 | |
2439 if (use_scale) | |
2440 { | |
2441 v(0) = sx.unscale (v(0)); | |
2442 v(1) = sy.unscale (v(1)); | |
2443 v(2) = sz.unscale (v(2)); | |
2444 } | |
2445 | |
2446 return v; | |
2447 } | |
2448 | |
6836 | 2449 octave_value |
7189 | 2450 axes::get_default (const caseless_str& name) const |
6836 | 2451 { |
2452 octave_value retval = default_properties.lookup (name); | |
2453 | |
2454 if (retval.is_undefined ()) | |
2455 { | |
2456 graphics_handle parent = get_parent (); | |
2457 graphics_object parent_obj = gh_manager::get_object (parent); | |
2458 | |
2459 retval = parent_obj.get_default (name); | |
2460 } | |
2461 | |
2462 return retval; | |
2463 } | |
2464 | |
7836
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
2465 // FIXME: Remove in case all data_property are converted into |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
2466 // array_property |
7222 | 2467 static void |
2468 check_limit_vals (double& min_val, double& max_val, double& min_pos, | |
2469 const data_property& data) | |
2470 { | |
7267 | 2471 double val = data.min_val (); |
2472 if (! (xisinf (val) || xisnan (val)) && val < min_val) | |
2473 min_val = val; | |
2474 val = data.max_val (); | |
2475 if (! (xisinf (val) || xisnan (val)) && val > max_val) | |
2476 max_val = val; | |
2477 val = data.min_pos (); | |
2478 if (! (xisinf (val) || xisnan (val)) && val > 0 && val < min_pos) | |
2479 min_pos = val; | |
7222 | 2480 } |
2481 | |
7836
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
2482 // FIXME: Maybe this should go into array_property class? |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
2483 static void |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
2484 check_limit_vals (double& min_val, double& max_val, double& min_pos, |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
2485 const array_property& data) |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
2486 { |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
2487 double val = data.min_val (); |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
2488 if (! (xisinf (val) || xisnan (val)) && val < min_val) |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
2489 min_val = val; |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
2490 val = data.max_val (); |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
2491 if (! (xisinf (val) || xisnan (val)) && val > max_val) |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
2492 max_val = val; |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
2493 val = data.min_pos (); |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
2494 if (! (xisinf (val) || xisnan (val)) && val > 0 && val < min_pos) |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
2495 min_pos = val; |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
2496 } |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
2497 |
7827
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2498 // magform(x) Returns (a, b), where x = a * 10^b, a >= 1., and b is |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2499 // integral. |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2500 |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2501 static void magform (double x, double& a, int& b) |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2502 { |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2503 if (x == 0) |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2504 { |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2505 a = 0; |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2506 b = 0; |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2507 } |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2508 else |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2509 { |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2510 double l = std::log10 (std::abs (x)); |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2511 double r = std::fmod (l, 1.); |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2512 a = std::pow (10.0, r); |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2513 b = static_cast<int> (l-r); |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2514 if (a < 1) |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2515 { |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2516 a *= 10; |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2517 b -= 1; |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2518 } |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2519 |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2520 if (x < 0) |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2521 a = -a; |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2522 } |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2523 } |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2524 |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2525 // A translation from Tom Holoryd's python code at |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2526 // http://kurage.nimh.nih.gov/tomh/tics.py |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2527 // FIXME -- add log ticks |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2528 |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2529 double |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2530 axes::properties::calc_tick_sep (double lo, double hi) |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2531 { |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2532 int ticint = 5; |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2533 |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2534 // Reference: Lewart, C. R., "Algorithms SCALE1, SCALE2, and |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2535 // SCALE3 for Determination of Scales on Computer Generated |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2536 // Plots", Communications of the ACM, 10 (1973), 639-640. |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2537 // Also cited as ACM Algorithm 463. |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2538 |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2539 double a; |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2540 int b, x; |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2541 |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2542 magform ((hi-lo)/ticint, a, b); |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2543 |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2544 static const double sqrt_2 = sqrt (2.0); |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2545 static const double sqrt_10 = sqrt (10.0); |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2546 static const double sqrt_50 = sqrt (50.0); |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2547 |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2548 if (a < sqrt_2) |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2549 x = 1; |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2550 else if (a < sqrt_10) |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2551 x = 2; |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2552 else if (a < sqrt_50) |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2553 x = 5; |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2554 else |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2555 x = 10; |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2556 |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2557 return x * std::pow (10., b); |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2558 |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2559 } |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2560 |
7222 | 2561 // Attempt to make "nice" limits from the actual max and min of the |
2562 // data. For log plots, we will also use the smallest strictly positive | |
2563 // value. | |
2564 | |
7827
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2565 Matrix |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2566 axes::properties::get_axis_limits (double xmin, double xmax, double min_pos, bool logscale) |
7222 | 2567 { |
2568 Matrix retval; | |
2569 | |
2570 double min_val = xmin; | |
2571 double max_val = xmax; | |
2572 | |
2573 if (! (xisinf (min_val) || xisinf (max_val))) | |
2574 { | |
2575 if (logscale) | |
2576 { | |
2577 if (xisinf (min_pos)) | |
2578 { | |
2579 // warning ("axis: logscale with no positive values to plot"); | |
2580 return retval; | |
2581 } | |
2582 | |
2583 if (min_val <= 0) | |
2584 { | |
2585 warning ("axis: omitting nonpositive data in log plot"); | |
2586 min_val = min_pos; | |
2587 } | |
2588 // FIXME -- maybe this test should also be relative? | |
2589 if (std::abs (min_val - max_val) < sqrt (DBL_EPSILON)) | |
2590 { | |
2591 min_val *= 0.9; | |
2592 max_val *= 1.1; | |
2593 } | |
2594 min_val = pow (10, floor (log10 (min_val))); | |
2595 max_val = pow (10, ceil (log10 (max_val))); | |
2596 } | |
2597 else | |
2598 { | |
2599 if (min_val == 0 && max_val == 0) | |
2600 { | |
2601 min_val = -1; | |
2602 max_val = 1; | |
2603 } | |
2604 // FIXME -- maybe this test should also be relative? | |
2605 else if (std::abs (min_val - max_val) < sqrt (DBL_EPSILON)) | |
2606 { | |
2607 min_val -= 0.1 * std::abs (min_val); | |
2608 max_val += 0.1 * std::abs (max_val); | |
2609 } | |
7827
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2610 |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2611 double tick_sep = calc_tick_sep (min_val , max_val); |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2612 min_val = tick_sep * std::floor (min_val / tick_sep); |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2613 max_val = tick_sep * ceil (max_val / tick_sep); |
7222 | 2614 } |
2615 } | |
2616 | |
2617 retval.resize (1, 2); | |
2618 | |
2619 retval(0) = min_val; | |
2620 retval(1) = max_val; | |
2621 | |
2622 return retval; | |
2623 } | |
2624 | |
7446 | 2625 void |
7827
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2626 axes::properties::calc_ticks_and_lims (array_property& lims, array_property& ticks, bool limmode_is_auto) |
7446 | 2627 { |
7827
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2628 |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2629 // FIXME -- add log ticks and lims |
7446 | 2630 |
2631 if (lims.get ().is_empty ()) | |
2632 return; | |
2633 | |
2634 double lo = (lims.get ().matrix_value ()) (0); | |
2635 double hi = (lims.get ().matrix_value ()) (1); | |
7843
d3dcfdfdc434
handle unsorted limits when calculatin gticks and limits
Shai Ayal <shaiay@users.sourceforge.net>
parents:
7836
diff
changeset
|
2636 // FIXME should this be checked for somewhere else? (i.e. set{x,y,z}lim) |
d3dcfdfdc434
handle unsorted limits when calculatin gticks and limits
Shai Ayal <shaiay@users.sourceforge.net>
parents:
7836
diff
changeset
|
2637 if (hi < lo) |
d3dcfdfdc434
handle unsorted limits when calculatin gticks and limits
Shai Ayal <shaiay@users.sourceforge.net>
parents:
7836
diff
changeset
|
2638 { |
d3dcfdfdc434
handle unsorted limits when calculatin gticks and limits
Shai Ayal <shaiay@users.sourceforge.net>
parents:
7836
diff
changeset
|
2639 double tmp = hi; |
d3dcfdfdc434
handle unsorted limits when calculatin gticks and limits
Shai Ayal <shaiay@users.sourceforge.net>
parents:
7836
diff
changeset
|
2640 hi = lo; |
d3dcfdfdc434
handle unsorted limits when calculatin gticks and limits
Shai Ayal <shaiay@users.sourceforge.net>
parents:
7836
diff
changeset
|
2641 lo = tmp; |
d3dcfdfdc434
handle unsorted limits when calculatin gticks and limits
Shai Ayal <shaiay@users.sourceforge.net>
parents:
7836
diff
changeset
|
2642 } |
7827
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2643 |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2644 double tick_sep = calc_tick_sep (lo , hi); |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2645 |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2646 int i1 = static_cast<int> (std::floor (lo / tick_sep)); |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2647 int i2 = static_cast<int> (std::ceil (hi / tick_sep)); |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2648 |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2649 if (limmode_is_auto) |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2650 { |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2651 // adjust limits to include min and max tics |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2652 Matrix tmp_lims (1,2); |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2653 tmp_lims(0) = tick_sep * i1; |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2654 tmp_lims(1) = tick_sep * i2; |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2655 |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2656 lims = tmp_lims; |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2657 } |
7446 | 2658 else |
7827
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2659 { |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2660 // adjust min and max tics if they are out of limits |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2661 i1 = static_cast<int> (std::ceil (lo / tick_sep)); |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2662 i2 = static_cast<int> (std::floor (hi / tick_sep)); |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2663 } |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2664 |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2665 Matrix tmp_ticks (1, i2-i1+1); |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2666 for (int i = 0; i <= i2-i1; i++) |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2667 tmp_ticks (i) = tick_sep * (i+i1); |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2668 |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2669 ticks = tmp_ticks; |
7446 | 2670 } |
2671 | |
7222 | 2672 static bool updating_axis_limits = false; |
2673 | |
7214 | 2674 void |
7222 | 2675 axes::update_axis_limits (const std::string& axis_type) |
7214 | 2676 { |
7222 | 2677 if (updating_axis_limits) |
2678 return; | |
2679 | |
2680 Matrix kids = xproperties.get_children (); | |
2681 | |
2682 octave_idx_type n = kids.numel (); | |
2683 | |
2684 double min_val = octave_Inf; | |
2685 double max_val = -octave_Inf; | |
2686 double min_pos = octave_Inf; | |
2687 | |
2688 char update_type = 0; | |
2689 | |
2690 Matrix limits; | |
2691 | |
2692 if (axis_type == "xdata" || axis_type == "xscale" | |
2693 || axis_type == "xldata" || axis_type == "xudata" | |
2694 || axis_type == "xlimmode") | |
2695 { | |
7363 | 2696 if (xproperties.xlimmode_is ("auto")) |
7222 | 2697 { |
2698 for (octave_idx_type i = 0; i < n; i++) | |
2699 { | |
2700 graphics_object obj = gh_manager::get_object (kids(i)); | |
2701 | |
2702 if (obj.isa ("line") || obj.isa ("image") | |
2703 || obj.isa ("patch") || obj.isa ("surface")) | |
2704 { | |
7363 | 2705 data_property xdata = obj.get_xdata_property (); |
7222 | 2706 |
2707 check_limit_vals (min_val, max_val, min_pos, xdata); | |
2708 | |
2709 if (obj.isa ("line")) | |
2710 { | |
7363 | 2711 data_property xldata = obj.get_xldata_property (); |
2712 data_property xudata = obj.get_xudata_property (); | |
7222 | 2713 |
2714 check_limit_vals (min_val, max_val, min_pos, xldata); | |
2715 check_limit_vals (min_val, max_val, min_pos, xudata); | |
2716 } | |
2717 } | |
2718 } | |
2719 | |
7827
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2720 limits = xproperties.get_axis_limits (min_val, max_val, min_pos, |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2721 xproperties.xscale_is ("log")); |
7222 | 2722 |
2723 update_type = 'x'; | |
2724 } | |
2725 } | |
2726 else if (axis_type == "ydata" || axis_type == "yscale" | |
2727 || axis_type == "ldata" || axis_type == "udata" | |
2728 || axis_type == "ylimmode") | |
2729 { | |
7363 | 2730 if (xproperties.ylimmode_is ("auto")) |
7222 | 2731 { |
2732 for (octave_idx_type i = 0; i < n; i++) | |
2733 { | |
2734 graphics_object obj = gh_manager::get_object (kids(i)); | |
2735 | |
2736 if (obj.isa ("line") || obj.isa ("image") | |
2737 || obj.isa ("patch") || obj.isa ("surface")) | |
2738 { | |
7363 | 2739 data_property ydata = obj.get_ydata_property (); |
7222 | 2740 |
2741 check_limit_vals (min_val, max_val, min_pos, ydata); | |
2742 | |
2743 if (obj.isa ("line")) | |
2744 { | |
7363 | 2745 data_property ldata = obj.get_ldata_property (); |
2746 data_property udata = obj.get_udata_property (); | |
7222 | 2747 |
2748 check_limit_vals (min_val, max_val, min_pos, ldata); | |
2749 check_limit_vals (min_val, max_val, min_pos, udata); | |
2750 } | |
2751 } | |
2752 } | |
2753 | |
7827
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2754 limits = xproperties.get_axis_limits (min_val, max_val, min_pos, |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2755 xproperties.yscale_is ("log")); |
7222 | 2756 |
2757 update_type = 'y'; | |
2758 } | |
2759 } | |
2760 else if (axis_type == "zdata" || axis_type == "zscale" | |
2761 || axis_type == "zlimmode") | |
2762 { | |
7363 | 2763 if (xproperties.zlimmode_is ("auto")) |
7222 | 2764 { |
2765 for (octave_idx_type i = 0; i < n; i++) | |
2766 { | |
2767 graphics_object obj = gh_manager::get_object (kids(i)); | |
2768 | |
2769 if (obj.isa ("line") || obj.isa ("patch") || obj.isa ("surface")) | |
2770 { | |
7363 | 2771 data_property zdata = obj.get_zdata_property (); |
7222 | 2772 |
2773 check_limit_vals (min_val, max_val, min_pos, zdata); | |
2774 } | |
2775 } | |
2776 | |
7827
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2777 limits = xproperties.get_axis_limits (min_val, max_val, min_pos, |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2778 xproperties.zscale_is ("log")); |
7222 | 2779 |
2780 update_type = 'z'; | |
2781 } | |
2782 } | |
2783 else if (axis_type == "cdata" || axis_type == "climmode") | |
2784 { | |
7363 | 2785 if (xproperties.climmode_is ("auto")) |
7222 | 2786 { |
2787 for (octave_idx_type i = 0; i < n; i++) | |
2788 { | |
2789 graphics_object obj = gh_manager::get_object (kids(i)); | |
2790 | |
2791 if (obj.isa ("image") || obj.isa ("patch") || obj.isa ("surface")) | |
2792 { | |
7836
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
2793 array_property cdata = obj.get_cdata_property (); |
7222 | 2794 |
2795 check_limit_vals (min_val, max_val, min_pos, cdata); | |
2796 } | |
2797 } | |
2798 | |
2799 if (min_val == max_val) | |
2800 max_val = min_val + 1; | |
2801 | |
2802 limits.resize (1, 2); | |
2803 | |
2804 limits(0) = min_val; | |
2805 limits(1) = max_val; | |
2806 | |
2807 update_type = 'c'; | |
2808 } | |
2809 | |
2810 } | |
2811 | |
2812 unwind_protect_bool (updating_axis_limits); | |
2813 updating_axis_limits = true; | |
2814 | |
2815 switch (update_type) | |
2816 { | |
2817 case 'x': | |
2818 xproperties.set_xlim (limits); | |
2819 xproperties.set_xlimmode ("auto"); | |
7446 | 2820 xproperties.update_xlim (); |
7222 | 2821 break; |
2822 | |
2823 case 'y': | |
2824 xproperties.set_ylim (limits); | |
2825 xproperties.set_ylimmode ("auto"); | |
7446 | 2826 xproperties.update_ylim (); |
7222 | 2827 break; |
2828 | |
2829 case 'z': | |
2830 xproperties.set_zlim (limits); | |
2831 xproperties.set_zlimmode ("auto"); | |
7446 | 2832 xproperties.update_zlim (); |
7222 | 2833 break; |
2834 | |
2835 case 'c': | |
2836 xproperties.set_clim (limits); | |
2837 xproperties.set_climmode ("auto"); | |
2838 break; | |
2839 | |
2840 default: | |
2841 break; | |
2842 } | |
2843 | |
7427 | 2844 xproperties.update_transform (); |
2845 | |
7222 | 2846 unwind_protect::run (); |
7214 | 2847 } |
2848 | |
7363 | 2849 // --------------------------------------------------------------------- |
2850 | |
2851 // Note: "line" code is entirely auto-generated | |
6406 | 2852 |
2853 // --------------------------------------------------------------------- | |
2854 | |
7363 | 2855 // Note: "text" code is entirely auto-generated |
6406 | 2856 |
2857 // --------------------------------------------------------------------- | |
2858 | |
7363 | 2859 // Note: "image" code is entirely auto-generated |
6406 | 2860 |
2861 // --------------------------------------------------------------------- | |
2862 | |
7833
8ff92634982d
Add initial support for patch rendering through GLU tessellation (no transparency, no border, no markers yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7829
diff
changeset
|
2863 octave_value |
8ff92634982d
Add initial support for patch rendering through GLU tessellation (no transparency, no border, no markers yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7829
diff
changeset
|
2864 patch::properties::get_color_data (void) const |
8ff92634982d
Add initial support for patch rendering through GLU tessellation (no transparency, no border, no markers yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7829
diff
changeset
|
2865 { |
8ff92634982d
Add initial support for patch rendering through GLU tessellation (no transparency, no border, no markers yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7829
diff
changeset
|
2866 return convert_cdata (*this, get_facevertexcdata (), |
8ff92634982d
Add initial support for patch rendering through GLU tessellation (no transparency, no border, no markers yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7829
diff
changeset
|
2867 cdatamapping_is ("scaled"), 2); |
8ff92634982d
Add initial support for patch rendering through GLU tessellation (no transparency, no border, no markers yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7829
diff
changeset
|
2868 } |
6807 | 2869 |
2870 // --------------------------------------------------------------------- | |
2871 | |
7829
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2872 octave_value |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2873 surface::properties::get_color_data (void) const |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2874 { |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2875 return convert_cdata (*this, get_cdata (), cdatamapping_is ("scaled"), 3); |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2876 } |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2877 |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2878 inline void |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2879 cross_product (double x1, double y1, double z1, |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2880 double x2, double y2, double z2, |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2881 double& x, double& y, double& z) |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2882 { |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2883 x += (y1 * z2 - z1 * y2); |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2884 y += (z1 * x2 - x1 * z2); |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2885 z += (x1 * y2 - y1 * x2); |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2886 } |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2887 |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2888 void |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2889 surface::properties::update_normals (void) |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2890 { |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2891 if (normalmode_is ("auto")) |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2892 { |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2893 Matrix x = get_xdata ().matrix_value (); |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2894 Matrix y = get_ydata ().matrix_value (); |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2895 Matrix z = get_zdata ().matrix_value (); |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2896 |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2897 int p = z.columns (), q = z.rows (); |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2898 int i1, i2, i3; |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2899 int j1, j2, j3; |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2900 |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2901 bool x_mat = (x.rows () == q); |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2902 bool y_mat = (y.columns () == p); |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2903 |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2904 NDArray n (dim_vector (q, p, 3), 0.0); |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2905 |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2906 i1 = i2 = i3 = 0; |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2907 j1 = j2 = j3 = 0; |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2908 |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2909 // FIXME: normal computation at boundaries |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2910 for (int i = 1; i < (p-1); i++) |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2911 { |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2912 if (y_mat) |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2913 { |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2914 i1 = i-1; |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2915 i2 = i; |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2916 i3 = i+1; |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2917 } |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2918 |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2919 for (int j = 1; j < (q-1); j++) |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2920 { |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2921 if (x_mat) |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2922 { |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2923 j1 = j-1; |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2924 j2 = j; |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2925 j3 = j+1; |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2926 } |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2927 |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2928 double& nx = n(j, i, 0); |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2929 double& ny = n(j, i, 1); |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2930 double& nz = n(j, i, 2); |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2931 |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2932 cross_product (x(j3,i)-x(j2,i), y(j+1,i2)-y(j,i2), z(j+1,i)-z(j,i), |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2933 x(j2,i+1)-x(j2,i), y(j,i3)-y(j,i2), z(j,i+1)-z(i,j), |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2934 nx, ny, nz); |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2935 cross_product (x(j2,i-1)-x(j2,i), y(j,i1)-y(j,i2), z(j,i-1)-z(j,i), |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2936 x(j3,i)-x(j2,i), y(j+1,i2)-y(j,i2), z(j+1,i)-z(i,j), |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2937 nx, ny, nz); |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2938 cross_product (x(j1,i)-x(j2,i), y(j-1,i2)-y(j,i2), z(j-1,i)-z(j,i), |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2939 x(j2,i-1)-x(j2,i), y(j,i1)-y(j,i2), z(j,i-1)-z(i,j), |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2940 nx, ny, nz); |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2941 cross_product (x(j2,i+1)-x(j2,i), y(j,i3)-y(j,i2), z(j,i+1)-z(j,i), |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2942 x(j1,i)-x(j2,i), y(j-1,i2)-y(j,i2), z(j-1,i)-z(i,j), |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2943 nx, ny, nz); |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2944 |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2945 double d = - sqrt (nx*nx + ny*ny + nz*nz); |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2946 |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2947 nx /= d; |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2948 ny /= d; |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2949 nz /= d; |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2950 } |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2951 } |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2952 |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2953 vertexnormals = n; |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2954 } |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2955 } |
6406 | 2956 |
2957 // --------------------------------------------------------------------- | |
2958 | |
2959 octave_value | |
7189 | 2960 base_graphics_object::get_default (const caseless_str& name) const |
6406 | 2961 { |
2962 graphics_handle parent = get_parent (); | |
2963 graphics_object parent_obj = gh_manager::get_object (parent); | |
2964 | |
2965 return parent_obj.get_default (type () + name); | |
2966 } | |
2967 | |
2968 octave_value | |
7189 | 2969 base_graphics_object::get_factory_default (const caseless_str& name) const |
6406 | 2970 { |
2971 graphics_object parent_obj = gh_manager::get_object (0); | |
2972 | |
2973 return parent_obj.get_factory_default (type () + name); | |
2974 } | |
2975 | |
7286 | 2976 // We use a random value for the handle to avoid issues with plots and |
2977 // scalar values for the first argument. | |
6406 | 2978 gh_manager::gh_manager (void) |
7286 | 2979 : handle_map (), handle_free_list (), |
2980 next_handle (-1.0 - (rand () + 1.0) / (RAND_MAX + 2.0)) | |
6406 | 2981 { |
2982 handle_map[0] = graphics_object (new root_figure ()); | |
2983 } | |
2984 | |
2985 graphics_handle | |
2986 gh_manager::do_make_graphics_handle (const std::string& go_name, | |
7370 | 2987 const graphics_handle& p, bool do_createfcn) |
6406 | 2988 { |
2989 graphics_handle h = get_handle (go_name); | |
2990 | |
2991 base_graphics_object *go = 0; | |
2992 | |
2993 if (go_name == "figure") | |
2994 go = new figure (h, p); | |
2995 else if (go_name == "axes") | |
2996 go = new axes (h, p); | |
2997 else if (go_name == "line") | |
2998 go = new line (h, p); | |
2999 else if (go_name == "text") | |
3000 go = new text (h, p); | |
3001 else if (go_name == "image") | |
3002 go = new image (h, p); | |
6807 | 3003 else if (go_name == "patch") |
3004 go = new patch (h, p); | |
6406 | 3005 else if (go_name == "surface") |
3006 go = new surface (h, p); | |
3007 if (go) | |
7370 | 3008 { |
3009 handle_map[h] = graphics_object (go); | |
3010 if (do_createfcn) | |
3011 go->get_properties ().execute_createfcn (); | |
3012 } | |
6406 | 3013 else |
3014 error ("gh_manager::do_make_graphics_handle: invalid object type `%s'", | |
3015 go_name.c_str ()); | |
3016 | |
3017 return h; | |
3018 } | |
3019 | |
3020 graphics_handle | |
3021 gh_manager::do_make_figure_handle (double val) | |
3022 { | |
3023 graphics_handle h = val; | |
3024 | |
3025 handle_map[h] = graphics_object (new figure (h, 0)); | |
3026 | |
3027 return h; | |
3028 } | |
3029 | |
3030 void | |
3031 gh_manager::do_push_figure (const graphics_handle& h) | |
3032 { | |
3033 do_pop_figure (h); | |
3034 | |
3035 figure_list.push_front (h); | |
3036 } | |
3037 | |
3038 void | |
3039 gh_manager::do_pop_figure (const graphics_handle& h) | |
3040 { | |
3041 for (figure_list_iterator p = figure_list.begin (); | |
3042 p != figure_list.end (); | |
3043 p++) | |
3044 { | |
3045 if (*p == h) | |
3046 { | |
3047 figure_list.erase (p); | |
3048 break; | |
3049 } | |
3050 } | |
3051 } | |
3052 | |
3053 property_list::plist_map_type | |
3054 root_figure::init_factory_properties (void) | |
3055 { | |
3056 property_list::plist_map_type plist_map; | |
3057 | |
6844 | 3058 plist_map["figure"] = figure::properties::factory_defaults (); |
3059 plist_map["axes"] = axes::properties::factory_defaults (); | |
3060 plist_map["line"] = line::properties::factory_defaults (); | |
3061 plist_map["text"] = text::properties::factory_defaults (); | |
3062 plist_map["image"] = image::properties::factory_defaults (); | |
3063 plist_map["patch"] = patch::properties::factory_defaults (); | |
3064 plist_map["surface"] = surface::properties::factory_defaults (); | |
6406 | 3065 |
3066 return plist_map; | |
3067 } | |
3068 | |
3069 // --------------------------------------------------------------------- | |
3070 | |
3071 DEFUN (ishandle, args, , | |
3072 "-*- texinfo -*-\n\ | |
6678 | 3073 @deftypefn {Built-in Function} {} ishandle (@var{h})\n\ |
6406 | 3074 Return true if @var{h} is a graphics handle and false otherwise.\n\ |
3075 @end deftypefn") | |
3076 { | |
3077 octave_value retval; | |
3078 | |
3079 if (args.length () == 1) | |
3080 retval = is_handle (args(0)); | |
3081 else | |
3082 print_usage (); | |
3083 | |
3084 return retval; | |
3085 } | |
3086 | |
3087 DEFUN (set, args, , | |
3088 "-*- texinfo -*-\n\ | |
6678 | 3089 @deftypefn {Built-in Function} {} set (@var{h}, @var{p}, @var{v}, @dots{})\n\ |
6732 | 3090 Set the named property value or vector @var{p} to the value @var{v}\n\ |
6894 | 3091 for the graphics handle @var{h}.\n\ |
6406 | 3092 @end deftypefn") |
3093 { | |
3094 octave_value retval; | |
3095 | |
3096 int nargin = args.length (); | |
3097 | |
3098 if (nargin > 0) | |
3099 { | |
6732 | 3100 ColumnVector hcv (args(0).vector_value ()); |
6406 | 3101 |
3102 if (! error_state) | |
6732 | 3103 { |
6733 | 3104 bool request_drawnow = false; |
3105 | |
6732 | 3106 for (octave_idx_type n = 0; n < hcv.length (); n++) |
3107 { | |
3108 graphics_object obj = gh_manager::get_object (hcv(n)); | |
6406 | 3109 |
6732 | 3110 if (obj) |
3111 { | |
3112 obj.set (args.splice (0, 1)); | |
6406 | 3113 |
6733 | 3114 request_drawnow = true; |
6732 | 3115 } |
3116 else | |
6733 | 3117 { |
3118 error ("set: invalid handle (= %g)", hcv(n)); | |
3119 break; | |
3120 } | |
6732 | 3121 } |
6733 | 3122 |
3123 if (! error_state && request_drawnow) | |
7409 | 3124 Vdrawnow_requested = true; |
6732 | 3125 } |
6406 | 3126 else |
6732 | 3127 error ("set: expecting graphics handle as first argument"); |
6406 | 3128 } |
3129 else | |
3130 print_usage (); | |
3131 | |
3132 return retval; | |
3133 } | |
3134 | |
3135 DEFUN (get, args, , | |
3136 "-*- texinfo -*-\n\ | |
6678 | 3137 @deftypefn {Built-in Function} {} get (@var{h}, @var{p})\n\ |
6406 | 3138 Return the named property @var{p} from the graphics handle @var{h}.\n\ |
3139 If @var{p} is omitted, return the complete property list for @var{h}.\n\ | |
6732 | 3140 If @var{h} is a vector, return a cell array including the property\n\ |
3141 values or lists respectively.\n\ | |
6406 | 3142 @end deftypefn") |
3143 { | |
3144 octave_value retval; | |
6732 | 3145 octave_value_list vlist; |
6406 | 3146 |
3147 int nargin = args.length (); | |
3148 | |
3149 if (nargin == 1 || nargin == 2) | |
3150 { | |
6732 | 3151 ColumnVector hcv (args(0).vector_value ()); |
6406 | 3152 |
3153 if (! error_state) | |
6732 | 3154 { |
6733 | 3155 octave_idx_type len = hcv.length (); |
3156 | |
3157 vlist.resize (len); | |
3158 | |
3159 for (octave_idx_type n = 0; n < len; n++) | |
6732 | 3160 { |
3161 graphics_object obj = gh_manager::get_object (hcv(n)); | |
6406 | 3162 |
6732 | 3163 if (obj) |
3164 { | |
3165 if (nargin == 1) | |
3166 vlist(n) = obj.get (); | |
3167 else | |
3168 { | |
7189 | 3169 caseless_str property = args(1).string_value (); |
6406 | 3170 |
6732 | 3171 if (! error_state) |
3172 vlist(n) = obj.get (property); | |
3173 else | |
6733 | 3174 { |
3175 error ("get: expecting property name as second argument"); | |
3176 break; | |
3177 } | |
6732 | 3178 } |
3179 } | |
3180 else | |
6733 | 3181 { |
3182 error ("get: invalid handle (= %g)", hcv(n)); | |
3183 break; | |
3184 } | |
6732 | 3185 } |
3186 } | |
6406 | 3187 else |
6732 | 3188 error ("get: expecting graphics handle as first argument"); |
6406 | 3189 } |
3190 else | |
3191 print_usage (); | |
3192 | |
6733 | 3193 if (! error_state) |
6732 | 3194 { |
6733 | 3195 octave_idx_type len = vlist.length (); |
3196 | |
3197 if (len > 1) | |
3198 retval = Cell (vlist); | |
3199 else if (len == 1) | |
3200 retval = vlist(0); | |
6732 | 3201 } |
3202 | |
6406 | 3203 return retval; |
3204 } | |
3205 | |
7379 | 3206 DEFUN (__get__, args, , |
3207 "-*- texinfo -*-\n\ | |
3208 @deftypefn {Built-in Function} {} __get__ (@var{h})\n\ | |
3209 Return all properties from the graphics handle @var{h}.\n\ | |
3210 If @var{h} is a vector, return a cell array including the property\n\ | |
3211 values or lists respectively.\n\ | |
3212 @end deftypefn") | |
3213 { | |
3214 octave_value retval; | |
3215 octave_value_list vlist; | |
3216 | |
3217 int nargin = args.length (); | |
3218 | |
3219 if (nargin == 1) | |
3220 { | |
3221 ColumnVector hcv (args(0).vector_value ()); | |
3222 | |
3223 if (! error_state) | |
3224 { | |
3225 octave_idx_type len = hcv.length (); | |
3226 | |
3227 vlist.resize (len); | |
3228 | |
3229 for (octave_idx_type n = 0; n < len; n++) | |
3230 { | |
3231 graphics_object obj = gh_manager::get_object (hcv(n)); | |
3232 | |
3233 if (obj) | |
3234 vlist(n) = obj.get (true); | |
3235 else | |
3236 { | |
3237 error ("get: invalid handle (= %g)", hcv(n)); | |
3238 break; | |
3239 } | |
3240 } | |
3241 } | |
3242 else | |
3243 error ("get: expecting graphics handle as first argument"); | |
3244 } | |
3245 else | |
3246 print_usage (); | |
3247 | |
3248 if (! error_state) | |
3249 { | |
3250 octave_idx_type len = vlist.length (); | |
3251 | |
3252 if (len > 1) | |
3253 retval = Cell (vlist); | |
3254 else if (len == 1) | |
3255 retval = vlist(0); | |
3256 } | |
3257 | |
3258 return retval; | |
3259 } | |
3260 | |
6406 | 3261 static octave_value |
3262 make_graphics_object (const std::string& go_name, | |
6874 | 3263 const octave_value_list& args) |
6406 | 3264 { |
3265 octave_value retval; | |
3266 | |
3267 double val = args(0).double_value (); | |
3268 | |
3269 if (! error_state) | |
3270 { | |
3271 graphics_handle parent = gh_manager::lookup (val); | |
3272 | |
7056 | 3273 if (parent.ok ()) |
6406 | 3274 { |
3275 graphics_handle h | |
7370 | 3276 = gh_manager::make_graphics_handle (go_name, parent, false); |
6406 | 3277 |
3278 if (! error_state) | |
3279 { | |
3280 adopt (parent, h); | |
3281 | |
3282 xset (h, args.splice (0, 1)); | |
7370 | 3283 xcreatefcn (h); |
6406 | 3284 |
6874 | 3285 retval = h.value (); |
7296 | 3286 |
3287 if (! error_state) | |
7409 | 3288 Vdrawnow_requested = true; |
6406 | 3289 } |
3290 else | |
3291 error ("__go%s__: unable to create graphics handle", | |
3292 go_name.c_str ()); | |
3293 } | |
3294 else | |
3295 error ("__go_%s__: invalid parent", go_name.c_str ()); | |
3296 } | |
3297 else | |
3298 error ("__go_%s__: invalid parent", go_name.c_str ()); | |
3299 | |
3300 return retval; | |
3301 } | |
3302 | |
3303 DEFUN (__go_figure__, args, , | |
3304 "-*- texinfo -*-\n\ | |
3305 @deftypefn {Built-in Function} {} __go_figure__ (@var{fignum})\n\ | |
6945 | 3306 Undocumented internal function.\n\ |
6406 | 3307 @end deftypefn") |
3308 { | |
3309 octave_value retval; | |
3310 | |
3311 if (args.length () > 0) | |
3312 { | |
3313 double val = args(0).double_value (); | |
3314 | |
3315 if (! error_state) | |
3316 { | |
3317 if (is_figure (val)) | |
3318 { | |
3319 graphics_handle h = gh_manager::lookup (val); | |
3320 | |
3321 xset (h, args.splice (0, 1)); | |
3322 | |
6874 | 3323 retval = h.value (); |
6406 | 3324 } |
3325 else | |
3326 { | |
3327 graphics_handle h = octave_NaN; | |
3328 | |
3329 if (xisnan (val)) | |
7370 | 3330 h = gh_manager::make_graphics_handle ("figure", 0, false); |
6406 | 3331 else if (val > 0 && D_NINT (val) == val) |
3332 h = gh_manager::make_figure_handle (val); | |
3333 else | |
3334 error ("__go_figure__: invalid figure number"); | |
3335 | |
7056 | 3336 if (! error_state && h.ok ()) |
6406 | 3337 { |
3338 adopt (0, h); | |
3339 | |
3340 xset (h, args.splice (0, 1)); | |
7370 | 3341 xcreatefcn (h); |
6406 | 3342 |
6874 | 3343 retval = h.value (); |
6406 | 3344 } |
3345 else | |
3346 error ("__go_figure__: failed to create figure handle"); | |
3347 } | |
3348 } | |
3349 else | |
3350 error ("__go_figure__: expecting figure number to be double value"); | |
3351 } | |
3352 else | |
3353 print_usage (); | |
3354 | |
3355 return retval; | |
3356 } | |
3357 | |
3358 #define GO_BODY(TYPE) \ | |
3359 octave_value retval; \ | |
3360 \ | |
3361 if (args.length () > 0) \ | |
3362 retval = make_graphics_object (#TYPE, args); \ | |
3363 else \ | |
3364 print_usage (); \ | |
3365 \ | |
3366 return retval | |
3367 | |
3368 DEFUN (__go_axes__, args, , | |
3369 "-*- texinfo -*-\n\ | |
3370 @deftypefn {Built-in Function} {} __go_axes__ (@var{parent})\n\ | |
6945 | 3371 Undocumented internal function.\n\ |
6406 | 3372 @end deftypefn") |
3373 { | |
3374 GO_BODY (axes); | |
3375 } | |
3376 | |
3377 DEFUN (__go_line__, args, , | |
3378 "-*- texinfo -*-\n\ | |
3379 @deftypefn {Built-in Function} {} __go_line__ (@var{parent})\n\ | |
6945 | 3380 Undocumented internal function.\n\ |
6406 | 3381 @end deftypefn") |
3382 { | |
3383 GO_BODY (line); | |
3384 } | |
3385 | |
3386 DEFUN (__go_text__, args, , | |
3387 "-*- texinfo -*-\n\ | |
3388 @deftypefn {Built-in Function} {} __go_text__ (@var{parent})\n\ | |
6945 | 3389 Undocumented internal function.\n\ |
6406 | 3390 @end deftypefn") |
3391 { | |
3392 GO_BODY (text); | |
3393 } | |
3394 | |
3395 DEFUN (__go_image__, args, , | |
3396 "-*- texinfo -*-\n\ | |
3397 @deftypefn {Built-in Function} {} __go_image__ (@var{parent})\n\ | |
6945 | 3398 Undocumented internal function.\n\ |
6406 | 3399 @end deftypefn") |
3400 { | |
3401 GO_BODY (image); | |
3402 } | |
3403 | |
3404 DEFUN (__go_surface__, args, , | |
3405 "-*- texinfo -*-\n\ | |
3406 @deftypefn {Built-in Function} {} __go_surface__ (@var{parent})\n\ | |
6945 | 3407 Undocumented internal function.\n\ |
6406 | 3408 @end deftypefn") |
3409 { | |
3410 GO_BODY (surface); | |
3411 } | |
3412 | |
6807 | 3413 DEFUN (__go_patch__, args, , |
3414 "-*- texinfo -*-\n\ | |
3415 @deftypefn {Built-in Function} {} __go_patch__ (@var{parent})\n\ | |
6945 | 3416 Undocumented internal function.\n\ |
6807 | 3417 @end deftypefn") |
3418 { | |
3419 GO_BODY (patch); | |
3420 } | |
3421 | |
6406 | 3422 DEFUN (__go_delete__, args, , |
3423 "-*- texinfo -*-\n\ | |
3424 @deftypefn {Built-in Function} {} __go_delete__ (@var{h})\n\ | |
6945 | 3425 Undocumented internal function.\n\ |
6406 | 3426 @end deftypefn") |
3427 { | |
3428 octave_value_list retval; | |
3429 | |
3430 if (args.length () == 1) | |
3431 { | |
3432 graphics_handle h = octave_NaN; | |
3433 | |
3434 double val = args(0).double_value (); | |
3435 | |
3436 if (! error_state) | |
3437 { | |
3438 h = gh_manager::lookup (val); | |
3439 | |
7056 | 3440 if (h.ok ()) |
6406 | 3441 { |
3442 graphics_object obj = gh_manager::get_object (h); | |
3443 | |
3444 graphics_handle parent_h = obj.get_parent (); | |
3445 | |
3446 graphics_object parent_obj = gh_manager::get_object (parent_h); | |
3447 | |
7367 | 3448 // NOTE: free the handle before removing it from its parent's |
3449 // children, such that the object's state is correct when | |
3450 // the deletefcn callback is executed | |
6406 | 3451 |
3452 gh_manager::free (h); | |
7367 | 3453 |
3454 parent_obj.remove_child (h); | |
6406 | 3455 } |
3456 else | |
3457 error ("delete: invalid graphics object (= %g)", val); | |
3458 } | |
3459 else | |
3460 error ("delete: invalid graphics object"); | |
3461 } | |
3462 else | |
3463 print_usage (); | |
3464 | |
3465 return retval; | |
3466 } | |
3467 | |
3468 DEFUN (__go_axes_init__, args, , | |
3469 "-*- texinfo -*-\n\ | |
3470 @deftypefn {Built-in Function} {} __go_axes_init__ (@var{h}, @var{mode})\n\ | |
6945 | 3471 Undocumented internal function.\n\ |
6406 | 3472 @end deftypefn") |
3473 { | |
3474 octave_value retval; | |
3475 | |
3476 int nargin = args.length (); | |
3477 | |
3478 std::string mode = ""; | |
3479 | |
3480 if (nargin == 2) | |
3481 { | |
3482 mode = args(1).string_value (); | |
3483 | |
3484 if (error_state) | |
3485 return retval; | |
3486 } | |
3487 | |
3488 if (nargin == 1 || nargin == 2) | |
3489 { | |
3490 graphics_handle h = octave_NaN; | |
3491 | |
3492 double val = args(0).double_value (); | |
3493 | |
3494 if (! error_state) | |
3495 { | |
3496 h = gh_manager::lookup (val); | |
3497 | |
7056 | 3498 if (h.ok ()) |
6406 | 3499 { |
3500 graphics_object obj = gh_manager::get_object (h); | |
3501 | |
3502 obj.set_defaults (mode); | |
3503 } | |
3504 else | |
3505 error ("__go_axes_init__: invalid graphics object (= %g)", val); | |
3506 } | |
3507 else | |
3508 error ("__go_axes_init__: invalid graphics object"); | |
3509 } | |
3510 else | |
3511 print_usage (); | |
3512 | |
3513 return retval; | |
3514 } | |
3515 | |
3516 DEFUN (__go_handles__, , , | |
3517 "-*- texinfo -*-\n\ | |
3518 @deftypefn {Built-in Function} {} __go_handles__ ()\n\ | |
6945 | 3519 Undocumented internal function.\n\ |
6406 | 3520 @end deftypefn") |
3521 { | |
6425 | 3522 return octave_value (gh_manager::handle_list ()); |
3523 } | |
3524 | |
3525 DEFUN (__go_figure_handles__, , , | |
3526 "-*- texinfo -*-\n\ | |
3527 @deftypefn {Built-in Function} {} __go_figure_handles__ ()\n\ | |
6945 | 3528 Undocumented internal function.\n\ |
6425 | 3529 @end deftypefn") |
3530 { | |
3531 return octave_value (gh_manager::figure_handle_list ()); | |
6406 | 3532 } |
3533 | |
7835
ca8b97bb952c
added the function available_backends
Shai Ayal <shaiay@sourceforge.net>
parents:
7833
diff
changeset
|
3534 DEFUN (available_backends, args, , |
ca8b97bb952c
added the function available_backends
Shai Ayal <shaiay@sourceforge.net>
parents:
7833
diff
changeset
|
3535 "-*- texinfo -*-\n\ |
ca8b97bb952c
added the function available_backends
Shai Ayal <shaiay@sourceforge.net>
parents:
7833
diff
changeset
|
3536 @deftypefn {Built-in Function} {} available_backends ()\n\ |
ca8b97bb952c
added the function available_backends
Shai Ayal <shaiay@sourceforge.net>
parents:
7833
diff
changeset
|
3537 Returns resgistered graphics backends.\n\ |
ca8b97bb952c
added the function available_backends
Shai Ayal <shaiay@sourceforge.net>
parents:
7833
diff
changeset
|
3538 @end deftypefn") |
ca8b97bb952c
added the function available_backends
Shai Ayal <shaiay@sourceforge.net>
parents:
7833
diff
changeset
|
3539 { |
ca8b97bb952c
added the function available_backends
Shai Ayal <shaiay@sourceforge.net>
parents:
7833
diff
changeset
|
3540 return octave_value (graphics_backend::available_backends_list ()); |
ca8b97bb952c
added the function available_backends
Shai Ayal <shaiay@sourceforge.net>
parents:
7833
diff
changeset
|
3541 } |
ca8b97bb952c
added the function available_backends
Shai Ayal <shaiay@sourceforge.net>
parents:
7833
diff
changeset
|
3542 |
7409 | 3543 static void |
3544 clear_drawnow_request (void *) | |
3545 { | |
3546 Vdrawnow_requested = false; | |
3547 } | |
3548 | |
7408 | 3549 DEFUN (drawnow, args, , |
3550 "-*- texinfo -*-\n\ | |
3551 @deftypefn {Built-in Function} {} __go_drawnow__ ()\n\ | |
3552 @deftypefnx {Built-in Function} {} __go_drawnow__ (@var{term}, @var{file}, @var{mono}, @var{debug_file})\n\ | |
3553 Undocumented internal function.\n\ | |
3554 @end deftypefn") | |
3555 { | |
3556 static int drawnow_executing = 0; | |
3557 static bool __go_close_all_registered__ = false; | |
3558 | |
3559 octave_value retval; | |
3560 | |
7409 | 3561 unwind_protect::begin_frame ("Fdrawnow"); |
3562 unwind_protect::add (clear_drawnow_request); | |
3563 | |
3564 unwind_protect_int (drawnow_executing); | |
3565 | |
3566 if (++drawnow_executing <= 1) | |
7408 | 3567 { |
7409 | 3568 if (! __go_close_all_registered__) |
3569 { | |
3570 octave_add_atexit_function ("__go_close_all__"); | |
3571 | |
3572 __go_close_all_registered__ = true; | |
3573 } | |
3574 | |
3575 if (args.length () == 0) | |
7408 | 3576 { |
7409 | 3577 Matrix hlist = gh_manager::figure_handle_list (); |
3578 | |
3579 for (int i = 0; ! error_state && i < hlist.length (); i++) | |
7408 | 3580 { |
7409 | 3581 graphics_handle h = gh_manager::lookup (hlist(i)); |
3582 | |
3583 if (h.ok () && h != 0) | |
7408 | 3584 { |
7409 | 3585 graphics_object go = gh_manager::get_object (h); |
3586 figure::properties& fprops = dynamic_cast <figure::properties&> (go.get_properties ()); | |
3587 | |
3588 if (fprops.is_modified ()) | |
7408 | 3589 { |
7409 | 3590 if (fprops.is_visible ()) |
3591 fprops.get_backend ().redraw_figure (h); | |
3592 else if (! fprops.get___plot_stream__ ().is_empty ()) | |
3593 { | |
3594 fprops.close (false); | |
3595 fprops.set___plot_stream__ (Matrix ()); | |
3596 fprops.set___enhanced__ (false); | |
3597 } | |
3598 fprops.set_modified (false); | |
7408 | 3599 } |
3600 } | |
3601 } | |
3602 } | |
7409 | 3603 else if (args.length () >= 2 && args.length () <= 4) |
7408 | 3604 { |
7409 | 3605 std::string term, file, debug_file; |
3606 bool mono; | |
3607 | |
3608 term = args(0).string_value (); | |
7408 | 3609 |
3610 if (! error_state) | |
3611 { | |
7409 | 3612 file = args(1).string_value (); |
7408 | 3613 |
3614 if (! error_state) | |
3615 { | |
7409 | 3616 size_t pos = file.find_last_of (file_ops::dir_sep_chars); |
3617 | |
3618 if (pos != NPOS) | |
3619 { | |
3620 file_stat fs (file.substr (0, pos)); | |
3621 | |
3622 if (! (fs && fs.is_dir ())) | |
3623 error ("drawnow: nonexistent directory `%s'", | |
3624 file.substr (0, pos).c_str ()); | |
3625 } | |
3626 | |
3627 mono = (args.length () >= 3 ? args(2).bool_value () : false); | |
7408 | 3628 |
3629 if (! error_state) | |
3630 { | |
7409 | 3631 debug_file = (args.length () > 3 ? args(3).string_value () |
3632 : ""); | |
3633 | |
3634 if (! error_state) | |
7408 | 3635 { |
7409 | 3636 graphics_handle h = gcf (); |
3637 | |
3638 if (h.ok ()) | |
3639 { | |
3640 graphics_object go = gh_manager::get_object (h); | |
3641 | |
7419 | 3642 go.get_backend () |
7409 | 3643 .print_figure (h, term, file, mono, debug_file); |
3644 } | |
3645 else | |
3646 error ("drawnow: nothing to draw"); | |
7408 | 3647 } |
3648 else | |
7409 | 3649 error ("drawnow: invalid debug_file, expected a string value"); |
7408 | 3650 } |
3651 else | |
7409 | 3652 error ("drawnow: invalid colormode, expected a boolean value"); |
7408 | 3653 } |
3654 else | |
7409 | 3655 error ("drawnow: invalid file, expected a string value"); |
7408 | 3656 } |
3657 else | |
7409 | 3658 error ("drawnow: invalid terminal, expected a string value"); |
7408 | 3659 } |
3660 else | |
7409 | 3661 print_usage (); |
7408 | 3662 } |
7409 | 3663 |
3664 unwind_protect::run_frame ("Fdrawnow"); | |
7408 | 3665 |
3666 return retval; | |
3667 } | |
3668 | |
6595 | 3669 octave_value |
7447 | 3670 get_property_from_handle (double handle, const std::string& property, |
3671 const std::string& func) | |
6595 | 3672 { |
3673 graphics_object obj = gh_manager::get_object (handle); | |
3674 octave_value retval; | |
3675 | |
3676 if (obj) | |
3677 { | |
7189 | 3678 caseless_str p = std::string (property); |
6595 | 3679 retval = obj.get (p); |
3680 } | |
3681 else | |
3682 error ("%s: invalid handle (= %g)", func.c_str(), handle); | |
3683 | |
3684 return retval; | |
3685 } | |
3686 | |
3687 bool | |
7447 | 3688 set_property_in_handle (double handle, const std::string& property, |
3689 const octave_value& arg, const std::string& func) | |
6595 | 3690 { |
3691 graphics_object obj = gh_manager::get_object (handle); | |
3692 int ret = false; | |
3693 | |
3694 if (obj) | |
3695 { | |
7189 | 3696 caseless_str p = std::string (property); |
6595 | 3697 obj.set (p, arg); |
3698 if (!error_state) | |
3699 ret = true; | |
3700 } | |
3701 else | |
3702 error ("%s: invalid handle (= %g)", func.c_str(), handle); | |
3703 | |
3704 return ret; | |
3705 } | |
3706 | |
6406 | 3707 /* |
3708 ;;; Local Variables: *** | |
3709 ;;; mode: C++ *** | |
3710 ;;; End: *** | |
3711 */ |