Mercurial > octave-nkf
annotate src/graphics.cc @ 7848:6bb2bbc2bf45
Remove data_property, replace with array_property or row_vector_property.
author | Michael Goffioul <michael.goffioul@gmail.com> |
---|---|
date | Wed, 27 Feb 2008 21:45:12 +0100 |
parents | 40b16e04172a |
children | 3249f64f69b2 |
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: 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
|
2466 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
|
2467 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
|
2468 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
|
2469 { |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
2470 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
|
2471 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
|
2472 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
|
2473 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
|
2474 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
|
2475 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
|
2476 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
|
2477 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
|
2478 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
|
2479 } |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
2480 |
7827
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2481 // 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
|
2482 // integral. |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2483 |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2484 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
|
2485 { |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2486 if (x == 0) |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2487 { |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2488 a = 0; |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2489 b = 0; |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2490 } |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2491 else |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2492 { |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2493 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
|
2494 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
|
2495 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
|
2496 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
|
2497 if (a < 1) |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2498 { |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2499 a *= 10; |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2500 b -= 1; |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2501 } |
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 a = -a; |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2505 } |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2506 } |
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 // 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
|
2509 // 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
|
2510 // FIXME -- add log ticks |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2511 |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2512 double |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2513 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
|
2514 { |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2515 int ticint = 5; |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2516 |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2517 // 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
|
2518 // 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
|
2519 // 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
|
2520 // 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
|
2521 |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2522 double a; |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2523 int b, x; |
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 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
|
2526 |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2527 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
|
2528 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
|
2529 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
|
2530 |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2531 if (a < sqrt_2) |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2532 x = 1; |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2533 else if (a < sqrt_10) |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2534 x = 2; |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2535 else if (a < sqrt_50) |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2536 x = 5; |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2537 else |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2538 x = 10; |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2539 |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2540 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
|
2541 |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2542 } |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2543 |
7222 | 2544 // Attempt to make "nice" limits from the actual max and min of the |
2545 // data. For log plots, we will also use the smallest strictly positive | |
2546 // value. | |
2547 | |
7827
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2548 Matrix |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2549 axes::properties::get_axis_limits (double xmin, double xmax, double min_pos, bool logscale) |
7222 | 2550 { |
2551 Matrix retval; | |
2552 | |
2553 double min_val = xmin; | |
2554 double max_val = xmax; | |
2555 | |
2556 if (! (xisinf (min_val) || xisinf (max_val))) | |
2557 { | |
2558 if (logscale) | |
2559 { | |
2560 if (xisinf (min_pos)) | |
2561 { | |
2562 // warning ("axis: logscale with no positive values to plot"); | |
2563 return retval; | |
2564 } | |
2565 | |
2566 if (min_val <= 0) | |
2567 { | |
2568 warning ("axis: omitting nonpositive data in log plot"); | |
2569 min_val = min_pos; | |
2570 } | |
2571 // FIXME -- maybe this test should also be relative? | |
2572 if (std::abs (min_val - max_val) < sqrt (DBL_EPSILON)) | |
2573 { | |
2574 min_val *= 0.9; | |
2575 max_val *= 1.1; | |
2576 } | |
2577 min_val = pow (10, floor (log10 (min_val))); | |
2578 max_val = pow (10, ceil (log10 (max_val))); | |
2579 } | |
2580 else | |
2581 { | |
2582 if (min_val == 0 && max_val == 0) | |
2583 { | |
2584 min_val = -1; | |
2585 max_val = 1; | |
2586 } | |
2587 // FIXME -- maybe this test should also be relative? | |
2588 else if (std::abs (min_val - max_val) < sqrt (DBL_EPSILON)) | |
2589 { | |
2590 min_val -= 0.1 * std::abs (min_val); | |
2591 max_val += 0.1 * std::abs (max_val); | |
2592 } | |
7827
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2593 |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2594 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
|
2595 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
|
2596 max_val = tick_sep * ceil (max_val / tick_sep); |
7222 | 2597 } |
2598 } | |
2599 | |
2600 retval.resize (1, 2); | |
2601 | |
2602 retval(0) = min_val; | |
2603 retval(1) = max_val; | |
2604 | |
2605 return retval; | |
2606 } | |
2607 | |
7446 | 2608 void |
7827
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2609 axes::properties::calc_ticks_and_lims (array_property& lims, array_property& ticks, bool limmode_is_auto) |
7446 | 2610 { |
7827
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2611 |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2612 // FIXME -- add log ticks and lims |
7446 | 2613 |
2614 if (lims.get ().is_empty ()) | |
2615 return; | |
2616 | |
2617 double lo = (lims.get ().matrix_value ()) (0); | |
2618 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
|
2619 // 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
|
2620 if (hi < lo) |
d3dcfdfdc434
handle unsorted limits when calculatin gticks and limits
Shai Ayal <shaiay@users.sourceforge.net>
parents:
7836
diff
changeset
|
2621 { |
d3dcfdfdc434
handle unsorted limits when calculatin gticks and limits
Shai Ayal <shaiay@users.sourceforge.net>
parents:
7836
diff
changeset
|
2622 double tmp = hi; |
d3dcfdfdc434
handle unsorted limits when calculatin gticks and limits
Shai Ayal <shaiay@users.sourceforge.net>
parents:
7836
diff
changeset
|
2623 hi = lo; |
d3dcfdfdc434
handle unsorted limits when calculatin gticks and limits
Shai Ayal <shaiay@users.sourceforge.net>
parents:
7836
diff
changeset
|
2624 lo = tmp; |
d3dcfdfdc434
handle unsorted limits when calculatin gticks and limits
Shai Ayal <shaiay@users.sourceforge.net>
parents:
7836
diff
changeset
|
2625 } |
7827
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2626 |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2627 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
|
2628 |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2629 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
|
2630 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
|
2631 |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2632 if (limmode_is_auto) |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2633 { |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2634 // 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
|
2635 Matrix tmp_lims (1,2); |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2636 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
|
2637 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
|
2638 |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2639 lims = tmp_lims; |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2640 } |
7446 | 2641 else |
7827
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2642 { |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2643 // 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
|
2644 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
|
2645 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
|
2646 } |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2647 |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2648 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
|
2649 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
|
2650 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
|
2651 |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2652 ticks = tmp_ticks; |
7446 | 2653 } |
2654 | |
7222 | 2655 static bool updating_axis_limits = false; |
2656 | |
7214 | 2657 void |
7222 | 2658 axes::update_axis_limits (const std::string& axis_type) |
7214 | 2659 { |
7222 | 2660 if (updating_axis_limits) |
2661 return; | |
2662 | |
2663 Matrix kids = xproperties.get_children (); | |
2664 | |
2665 octave_idx_type n = kids.numel (); | |
2666 | |
2667 double min_val = octave_Inf; | |
2668 double max_val = -octave_Inf; | |
2669 double min_pos = octave_Inf; | |
2670 | |
2671 char update_type = 0; | |
2672 | |
2673 Matrix limits; | |
2674 | |
2675 if (axis_type == "xdata" || axis_type == "xscale" | |
2676 || axis_type == "xldata" || axis_type == "xudata" | |
2677 || axis_type == "xlimmode") | |
2678 { | |
7363 | 2679 if (xproperties.xlimmode_is ("auto")) |
7222 | 2680 { |
2681 for (octave_idx_type i = 0; i < n; i++) | |
2682 { | |
2683 graphics_object obj = gh_manager::get_object (kids(i)); | |
2684 | |
2685 if (obj.isa ("line") || obj.isa ("image") | |
2686 || obj.isa ("patch") || obj.isa ("surface")) | |
2687 { | |
7848
6bb2bbc2bf45
Remove data_property, replace with array_property or row_vector_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7847
diff
changeset
|
2688 array_property xdata = obj.get_xdata_property (); |
7222 | 2689 |
2690 check_limit_vals (min_val, max_val, min_pos, xdata); | |
2691 | |
2692 if (obj.isa ("line")) | |
2693 { | |
7848
6bb2bbc2bf45
Remove data_property, replace with array_property or row_vector_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7847
diff
changeset
|
2694 array_property xldata = obj.get_xldata_property (); |
6bb2bbc2bf45
Remove data_property, replace with array_property or row_vector_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7847
diff
changeset
|
2695 array_property xudata = obj.get_xudata_property (); |
7222 | 2696 |
2697 check_limit_vals (min_val, max_val, min_pos, xldata); | |
2698 check_limit_vals (min_val, max_val, min_pos, xudata); | |
2699 } | |
2700 } | |
2701 } | |
2702 | |
7827
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2703 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
|
2704 xproperties.xscale_is ("log")); |
7222 | 2705 |
2706 update_type = 'x'; | |
2707 } | |
2708 } | |
2709 else if (axis_type == "ydata" || axis_type == "yscale" | |
2710 || axis_type == "ldata" || axis_type == "udata" | |
2711 || axis_type == "ylimmode") | |
2712 { | |
7363 | 2713 if (xproperties.ylimmode_is ("auto")) |
7222 | 2714 { |
2715 for (octave_idx_type i = 0; i < n; i++) | |
2716 { | |
2717 graphics_object obj = gh_manager::get_object (kids(i)); | |
2718 | |
2719 if (obj.isa ("line") || obj.isa ("image") | |
2720 || obj.isa ("patch") || obj.isa ("surface")) | |
2721 { | |
7848
6bb2bbc2bf45
Remove data_property, replace with array_property or row_vector_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7847
diff
changeset
|
2722 array_property ydata = obj.get_ydata_property (); |
7222 | 2723 |
2724 check_limit_vals (min_val, max_val, min_pos, ydata); | |
2725 | |
2726 if (obj.isa ("line")) | |
2727 { | |
7848
6bb2bbc2bf45
Remove data_property, replace with array_property or row_vector_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7847
diff
changeset
|
2728 array_property ldata = obj.get_ldata_property (); |
6bb2bbc2bf45
Remove data_property, replace with array_property or row_vector_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7847
diff
changeset
|
2729 array_property udata = obj.get_udata_property (); |
7222 | 2730 |
2731 check_limit_vals (min_val, max_val, min_pos, ldata); | |
2732 check_limit_vals (min_val, max_val, min_pos, udata); | |
2733 } | |
2734 } | |
2735 } | |
2736 | |
7827
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2737 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
|
2738 xproperties.yscale_is ("log")); |
7222 | 2739 |
2740 update_type = 'y'; | |
2741 } | |
2742 } | |
2743 else if (axis_type == "zdata" || axis_type == "zscale" | |
2744 || axis_type == "zlimmode") | |
2745 { | |
7363 | 2746 if (xproperties.zlimmode_is ("auto")) |
7222 | 2747 { |
2748 for (octave_idx_type i = 0; i < n; i++) | |
2749 { | |
2750 graphics_object obj = gh_manager::get_object (kids(i)); | |
2751 | |
2752 if (obj.isa ("line") || obj.isa ("patch") || obj.isa ("surface")) | |
2753 { | |
7848
6bb2bbc2bf45
Remove data_property, replace with array_property or row_vector_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7847
diff
changeset
|
2754 array_property zdata = obj.get_zdata_property (); |
7222 | 2755 |
2756 check_limit_vals (min_val, max_val, min_pos, zdata); | |
2757 } | |
2758 } | |
2759 | |
7827
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2760 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
|
2761 xproperties.zscale_is ("log")); |
7222 | 2762 |
2763 update_type = 'z'; | |
2764 } | |
2765 } | |
2766 else if (axis_type == "cdata" || axis_type == "climmode") | |
2767 { | |
7363 | 2768 if (xproperties.climmode_is ("auto")) |
7222 | 2769 { |
2770 for (octave_idx_type i = 0; i < n; i++) | |
2771 { | |
2772 graphics_object obj = gh_manager::get_object (kids(i)); | |
2773 | |
2774 if (obj.isa ("image") || obj.isa ("patch") || obj.isa ("surface")) | |
2775 { | |
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
|
2776 array_property cdata = obj.get_cdata_property (); |
7222 | 2777 |
2778 check_limit_vals (min_val, max_val, min_pos, cdata); | |
2779 } | |
2780 } | |
2781 | |
2782 if (min_val == max_val) | |
2783 max_val = min_val + 1; | |
2784 | |
2785 limits.resize (1, 2); | |
2786 | |
2787 limits(0) = min_val; | |
2788 limits(1) = max_val; | |
2789 | |
2790 update_type = 'c'; | |
2791 } | |
2792 | |
2793 } | |
2794 | |
2795 unwind_protect_bool (updating_axis_limits); | |
2796 updating_axis_limits = true; | |
2797 | |
2798 switch (update_type) | |
2799 { | |
2800 case 'x': | |
2801 xproperties.set_xlim (limits); | |
2802 xproperties.set_xlimmode ("auto"); | |
7446 | 2803 xproperties.update_xlim (); |
7222 | 2804 break; |
2805 | |
2806 case 'y': | |
2807 xproperties.set_ylim (limits); | |
2808 xproperties.set_ylimmode ("auto"); | |
7446 | 2809 xproperties.update_ylim (); |
7222 | 2810 break; |
2811 | |
2812 case 'z': | |
2813 xproperties.set_zlim (limits); | |
2814 xproperties.set_zlimmode ("auto"); | |
7446 | 2815 xproperties.update_zlim (); |
7222 | 2816 break; |
2817 | |
2818 case 'c': | |
2819 xproperties.set_clim (limits); | |
2820 xproperties.set_climmode ("auto"); | |
2821 break; | |
2822 | |
2823 default: | |
2824 break; | |
2825 } | |
2826 | |
7427 | 2827 xproperties.update_transform (); |
2828 | |
7222 | 2829 unwind_protect::run (); |
7214 | 2830 } |
2831 | |
7363 | 2832 // --------------------------------------------------------------------- |
2833 | |
2834 // Note: "line" code is entirely auto-generated | |
6406 | 2835 |
2836 // --------------------------------------------------------------------- | |
2837 | |
7363 | 2838 // Note: "text" code is entirely auto-generated |
6406 | 2839 |
2840 // --------------------------------------------------------------------- | |
2841 | |
7363 | 2842 // Note: "image" code is entirely auto-generated |
6406 | 2843 |
2844 // --------------------------------------------------------------------- | |
2845 | |
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
|
2846 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
|
2847 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
|
2848 { |
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
|
2849 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
|
2850 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
|
2851 } |
6807 | 2852 |
2853 // --------------------------------------------------------------------- | |
2854 | |
7829
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2855 octave_value |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2856 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
|
2857 { |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2858 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
|
2859 } |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2860 |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2861 inline void |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2862 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
|
2863 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
|
2864 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
|
2865 { |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2866 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
|
2867 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
|
2868 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
|
2869 } |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2870 |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2871 void |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2872 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
|
2873 { |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2874 if (normalmode_is ("auto")) |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2875 { |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2876 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
|
2877 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
|
2878 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
|
2879 |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2880 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
|
2881 int i1, i2, i3; |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2882 int j1, j2, j3; |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2883 |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2884 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
|
2885 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
|
2886 |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2887 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
|
2888 |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2889 i1 = i2 = i3 = 0; |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2890 j1 = j2 = j3 = 0; |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2891 |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2892 // 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
|
2893 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
|
2894 { |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2895 if (y_mat) |
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 i1 = i-1; |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2898 i2 = i; |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2899 i3 = i+1; |
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 |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2902 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
|
2903 { |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2904 if (x_mat) |
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 j1 = j-1; |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2907 j2 = j; |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2908 j3 = j+1; |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2909 } |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2910 |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2911 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
|
2912 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
|
2913 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
|
2914 |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2915 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
|
2916 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
|
2917 nx, ny, nz); |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2918 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
|
2919 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
|
2920 nx, ny, nz); |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2921 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
|
2922 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
|
2923 nx, ny, nz); |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2924 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
|
2925 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
|
2926 nx, ny, nz); |
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 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
|
2929 |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2930 nx /= d; |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2931 ny /= d; |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2932 nz /= d; |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2933 } |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2934 } |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2935 |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2936 vertexnormals = n; |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2937 } |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
2938 } |
6406 | 2939 |
2940 // --------------------------------------------------------------------- | |
2941 | |
2942 octave_value | |
7189 | 2943 base_graphics_object::get_default (const caseless_str& name) const |
6406 | 2944 { |
2945 graphics_handle parent = get_parent (); | |
2946 graphics_object parent_obj = gh_manager::get_object (parent); | |
2947 | |
2948 return parent_obj.get_default (type () + name); | |
2949 } | |
2950 | |
2951 octave_value | |
7189 | 2952 base_graphics_object::get_factory_default (const caseless_str& name) const |
6406 | 2953 { |
2954 graphics_object parent_obj = gh_manager::get_object (0); | |
2955 | |
2956 return parent_obj.get_factory_default (type () + name); | |
2957 } | |
2958 | |
7286 | 2959 // We use a random value for the handle to avoid issues with plots and |
2960 // scalar values for the first argument. | |
6406 | 2961 gh_manager::gh_manager (void) |
7286 | 2962 : handle_map (), handle_free_list (), |
2963 next_handle (-1.0 - (rand () + 1.0) / (RAND_MAX + 2.0)) | |
6406 | 2964 { |
2965 handle_map[0] = graphics_object (new root_figure ()); | |
7847
40b16e04172a
Make backend switching work.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7844
diff
changeset
|
2966 |
40b16e04172a
Make backend switching work.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7844
diff
changeset
|
2967 // Make sure the default backend is registered. |
40b16e04172a
Make backend switching work.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7844
diff
changeset
|
2968 graphics_backend::default_backend (); |
6406 | 2969 } |
2970 | |
2971 graphics_handle | |
2972 gh_manager::do_make_graphics_handle (const std::string& go_name, | |
7370 | 2973 const graphics_handle& p, bool do_createfcn) |
6406 | 2974 { |
2975 graphics_handle h = get_handle (go_name); | |
2976 | |
2977 base_graphics_object *go = 0; | |
2978 | |
2979 if (go_name == "figure") | |
2980 go = new figure (h, p); | |
2981 else if (go_name == "axes") | |
2982 go = new axes (h, p); | |
2983 else if (go_name == "line") | |
2984 go = new line (h, p); | |
2985 else if (go_name == "text") | |
2986 go = new text (h, p); | |
2987 else if (go_name == "image") | |
2988 go = new image (h, p); | |
6807 | 2989 else if (go_name == "patch") |
2990 go = new patch (h, p); | |
6406 | 2991 else if (go_name == "surface") |
2992 go = new surface (h, p); | |
2993 if (go) | |
7370 | 2994 { |
2995 handle_map[h] = graphics_object (go); | |
2996 if (do_createfcn) | |
2997 go->get_properties ().execute_createfcn (); | |
2998 } | |
6406 | 2999 else |
3000 error ("gh_manager::do_make_graphics_handle: invalid object type `%s'", | |
3001 go_name.c_str ()); | |
3002 | |
3003 return h; | |
3004 } | |
3005 | |
3006 graphics_handle | |
3007 gh_manager::do_make_figure_handle (double val) | |
3008 { | |
3009 graphics_handle h = val; | |
3010 | |
3011 handle_map[h] = graphics_object (new figure (h, 0)); | |
3012 | |
3013 return h; | |
3014 } | |
3015 | |
3016 void | |
3017 gh_manager::do_push_figure (const graphics_handle& h) | |
3018 { | |
3019 do_pop_figure (h); | |
3020 | |
3021 figure_list.push_front (h); | |
3022 } | |
3023 | |
3024 void | |
3025 gh_manager::do_pop_figure (const graphics_handle& h) | |
3026 { | |
3027 for (figure_list_iterator p = figure_list.begin (); | |
3028 p != figure_list.end (); | |
3029 p++) | |
3030 { | |
3031 if (*p == h) | |
3032 { | |
3033 figure_list.erase (p); | |
3034 break; | |
3035 } | |
3036 } | |
3037 } | |
3038 | |
3039 property_list::plist_map_type | |
3040 root_figure::init_factory_properties (void) | |
3041 { | |
3042 property_list::plist_map_type plist_map; | |
3043 | |
6844 | 3044 plist_map["figure"] = figure::properties::factory_defaults (); |
3045 plist_map["axes"] = axes::properties::factory_defaults (); | |
3046 plist_map["line"] = line::properties::factory_defaults (); | |
3047 plist_map["text"] = text::properties::factory_defaults (); | |
3048 plist_map["image"] = image::properties::factory_defaults (); | |
3049 plist_map["patch"] = patch::properties::factory_defaults (); | |
3050 plist_map["surface"] = surface::properties::factory_defaults (); | |
6406 | 3051 |
3052 return plist_map; | |
3053 } | |
3054 | |
3055 // --------------------------------------------------------------------- | |
3056 | |
3057 DEFUN (ishandle, args, , | |
3058 "-*- texinfo -*-\n\ | |
6678 | 3059 @deftypefn {Built-in Function} {} ishandle (@var{h})\n\ |
6406 | 3060 Return true if @var{h} is a graphics handle and false otherwise.\n\ |
3061 @end deftypefn") | |
3062 { | |
3063 octave_value retval; | |
3064 | |
3065 if (args.length () == 1) | |
3066 retval = is_handle (args(0)); | |
3067 else | |
3068 print_usage (); | |
3069 | |
3070 return retval; | |
3071 } | |
3072 | |
3073 DEFUN (set, args, , | |
3074 "-*- texinfo -*-\n\ | |
6678 | 3075 @deftypefn {Built-in Function} {} set (@var{h}, @var{p}, @var{v}, @dots{})\n\ |
6732 | 3076 Set the named property value or vector @var{p} to the value @var{v}\n\ |
6894 | 3077 for the graphics handle @var{h}.\n\ |
6406 | 3078 @end deftypefn") |
3079 { | |
3080 octave_value retval; | |
3081 | |
3082 int nargin = args.length (); | |
3083 | |
3084 if (nargin > 0) | |
3085 { | |
6732 | 3086 ColumnVector hcv (args(0).vector_value ()); |
6406 | 3087 |
3088 if (! error_state) | |
6732 | 3089 { |
6733 | 3090 bool request_drawnow = false; |
3091 | |
6732 | 3092 for (octave_idx_type n = 0; n < hcv.length (); n++) |
3093 { | |
3094 graphics_object obj = gh_manager::get_object (hcv(n)); | |
6406 | 3095 |
6732 | 3096 if (obj) |
3097 { | |
3098 obj.set (args.splice (0, 1)); | |
6406 | 3099 |
6733 | 3100 request_drawnow = true; |
6732 | 3101 } |
3102 else | |
6733 | 3103 { |
3104 error ("set: invalid handle (= %g)", hcv(n)); | |
3105 break; | |
3106 } | |
6732 | 3107 } |
6733 | 3108 |
3109 if (! error_state && request_drawnow) | |
7409 | 3110 Vdrawnow_requested = true; |
6732 | 3111 } |
6406 | 3112 else |
6732 | 3113 error ("set: expecting graphics handle as first argument"); |
6406 | 3114 } |
3115 else | |
3116 print_usage (); | |
3117 | |
3118 return retval; | |
3119 } | |
3120 | |
3121 DEFUN (get, args, , | |
3122 "-*- texinfo -*-\n\ | |
6678 | 3123 @deftypefn {Built-in Function} {} get (@var{h}, @var{p})\n\ |
6406 | 3124 Return the named property @var{p} from the graphics handle @var{h}.\n\ |
3125 If @var{p} is omitted, return the complete property list for @var{h}.\n\ | |
6732 | 3126 If @var{h} is a vector, return a cell array including the property\n\ |
3127 values or lists respectively.\n\ | |
6406 | 3128 @end deftypefn") |
3129 { | |
3130 octave_value retval; | |
6732 | 3131 octave_value_list vlist; |
6406 | 3132 |
3133 int nargin = args.length (); | |
3134 | |
3135 if (nargin == 1 || nargin == 2) | |
3136 { | |
6732 | 3137 ColumnVector hcv (args(0).vector_value ()); |
6406 | 3138 |
3139 if (! error_state) | |
6732 | 3140 { |
6733 | 3141 octave_idx_type len = hcv.length (); |
3142 | |
3143 vlist.resize (len); | |
3144 | |
3145 for (octave_idx_type n = 0; n < len; n++) | |
6732 | 3146 { |
3147 graphics_object obj = gh_manager::get_object (hcv(n)); | |
6406 | 3148 |
6732 | 3149 if (obj) |
3150 { | |
3151 if (nargin == 1) | |
3152 vlist(n) = obj.get (); | |
3153 else | |
3154 { | |
7189 | 3155 caseless_str property = args(1).string_value (); |
6406 | 3156 |
6732 | 3157 if (! error_state) |
3158 vlist(n) = obj.get (property); | |
3159 else | |
6733 | 3160 { |
3161 error ("get: expecting property name as second argument"); | |
3162 break; | |
3163 } | |
6732 | 3164 } |
3165 } | |
3166 else | |
6733 | 3167 { |
3168 error ("get: invalid handle (= %g)", hcv(n)); | |
3169 break; | |
3170 } | |
6732 | 3171 } |
3172 } | |
6406 | 3173 else |
6732 | 3174 error ("get: expecting graphics handle as first argument"); |
6406 | 3175 } |
3176 else | |
3177 print_usage (); | |
3178 | |
6733 | 3179 if (! error_state) |
6732 | 3180 { |
6733 | 3181 octave_idx_type len = vlist.length (); |
3182 | |
3183 if (len > 1) | |
3184 retval = Cell (vlist); | |
3185 else if (len == 1) | |
3186 retval = vlist(0); | |
6732 | 3187 } |
3188 | |
6406 | 3189 return retval; |
3190 } | |
3191 | |
7379 | 3192 DEFUN (__get__, args, , |
3193 "-*- texinfo -*-\n\ | |
3194 @deftypefn {Built-in Function} {} __get__ (@var{h})\n\ | |
3195 Return all properties from the graphics handle @var{h}.\n\ | |
3196 If @var{h} is a vector, return a cell array including the property\n\ | |
3197 values or lists respectively.\n\ | |
3198 @end deftypefn") | |
3199 { | |
3200 octave_value retval; | |
3201 octave_value_list vlist; | |
3202 | |
3203 int nargin = args.length (); | |
3204 | |
3205 if (nargin == 1) | |
3206 { | |
3207 ColumnVector hcv (args(0).vector_value ()); | |
3208 | |
3209 if (! error_state) | |
3210 { | |
3211 octave_idx_type len = hcv.length (); | |
3212 | |
3213 vlist.resize (len); | |
3214 | |
3215 for (octave_idx_type n = 0; n < len; n++) | |
3216 { | |
3217 graphics_object obj = gh_manager::get_object (hcv(n)); | |
3218 | |
3219 if (obj) | |
3220 vlist(n) = obj.get (true); | |
3221 else | |
3222 { | |
3223 error ("get: invalid handle (= %g)", hcv(n)); | |
3224 break; | |
3225 } | |
3226 } | |
3227 } | |
3228 else | |
3229 error ("get: expecting graphics handle as first argument"); | |
3230 } | |
3231 else | |
3232 print_usage (); | |
3233 | |
3234 if (! error_state) | |
3235 { | |
3236 octave_idx_type len = vlist.length (); | |
3237 | |
3238 if (len > 1) | |
3239 retval = Cell (vlist); | |
3240 else if (len == 1) | |
3241 retval = vlist(0); | |
3242 } | |
3243 | |
3244 return retval; | |
3245 } | |
3246 | |
6406 | 3247 static octave_value |
3248 make_graphics_object (const std::string& go_name, | |
6874 | 3249 const octave_value_list& args) |
6406 | 3250 { |
3251 octave_value retval; | |
3252 | |
3253 double val = args(0).double_value (); | |
3254 | |
3255 if (! error_state) | |
3256 { | |
3257 graphics_handle parent = gh_manager::lookup (val); | |
3258 | |
7056 | 3259 if (parent.ok ()) |
6406 | 3260 { |
3261 graphics_handle h | |
7370 | 3262 = gh_manager::make_graphics_handle (go_name, parent, false); |
6406 | 3263 |
3264 if (! error_state) | |
3265 { | |
3266 adopt (parent, h); | |
3267 | |
3268 xset (h, args.splice (0, 1)); | |
7370 | 3269 xcreatefcn (h); |
6406 | 3270 |
6874 | 3271 retval = h.value (); |
7296 | 3272 |
3273 if (! error_state) | |
7409 | 3274 Vdrawnow_requested = true; |
6406 | 3275 } |
3276 else | |
3277 error ("__go%s__: unable to create graphics handle", | |
3278 go_name.c_str ()); | |
3279 } | |
3280 else | |
3281 error ("__go_%s__: invalid parent", go_name.c_str ()); | |
3282 } | |
3283 else | |
3284 error ("__go_%s__: invalid parent", go_name.c_str ()); | |
3285 | |
3286 return retval; | |
3287 } | |
3288 | |
3289 DEFUN (__go_figure__, args, , | |
3290 "-*- texinfo -*-\n\ | |
3291 @deftypefn {Built-in Function} {} __go_figure__ (@var{fignum})\n\ | |
6945 | 3292 Undocumented internal function.\n\ |
6406 | 3293 @end deftypefn") |
3294 { | |
3295 octave_value retval; | |
3296 | |
3297 if (args.length () > 0) | |
3298 { | |
3299 double val = args(0).double_value (); | |
3300 | |
3301 if (! error_state) | |
3302 { | |
3303 if (is_figure (val)) | |
3304 { | |
3305 graphics_handle h = gh_manager::lookup (val); | |
3306 | |
3307 xset (h, args.splice (0, 1)); | |
3308 | |
6874 | 3309 retval = h.value (); |
6406 | 3310 } |
3311 else | |
3312 { | |
3313 graphics_handle h = octave_NaN; | |
3314 | |
3315 if (xisnan (val)) | |
7370 | 3316 h = gh_manager::make_graphics_handle ("figure", 0, false); |
6406 | 3317 else if (val > 0 && D_NINT (val) == val) |
3318 h = gh_manager::make_figure_handle (val); | |
3319 else | |
3320 error ("__go_figure__: invalid figure number"); | |
3321 | |
7056 | 3322 if (! error_state && h.ok ()) |
6406 | 3323 { |
3324 adopt (0, h); | |
3325 | |
3326 xset (h, args.splice (0, 1)); | |
7370 | 3327 xcreatefcn (h); |
6406 | 3328 |
6874 | 3329 retval = h.value (); |
6406 | 3330 } |
3331 else | |
3332 error ("__go_figure__: failed to create figure handle"); | |
3333 } | |
3334 } | |
3335 else | |
3336 error ("__go_figure__: expecting figure number to be double value"); | |
3337 } | |
3338 else | |
3339 print_usage (); | |
3340 | |
3341 return retval; | |
3342 } | |
3343 | |
3344 #define GO_BODY(TYPE) \ | |
3345 octave_value retval; \ | |
3346 \ | |
3347 if (args.length () > 0) \ | |
3348 retval = make_graphics_object (#TYPE, args); \ | |
3349 else \ | |
3350 print_usage (); \ | |
3351 \ | |
3352 return retval | |
3353 | |
3354 DEFUN (__go_axes__, args, , | |
3355 "-*- texinfo -*-\n\ | |
3356 @deftypefn {Built-in Function} {} __go_axes__ (@var{parent})\n\ | |
6945 | 3357 Undocumented internal function.\n\ |
6406 | 3358 @end deftypefn") |
3359 { | |
3360 GO_BODY (axes); | |
3361 } | |
3362 | |
3363 DEFUN (__go_line__, args, , | |
3364 "-*- texinfo -*-\n\ | |
3365 @deftypefn {Built-in Function} {} __go_line__ (@var{parent})\n\ | |
6945 | 3366 Undocumented internal function.\n\ |
6406 | 3367 @end deftypefn") |
3368 { | |
3369 GO_BODY (line); | |
3370 } | |
3371 | |
3372 DEFUN (__go_text__, args, , | |
3373 "-*- texinfo -*-\n\ | |
3374 @deftypefn {Built-in Function} {} __go_text__ (@var{parent})\n\ | |
6945 | 3375 Undocumented internal function.\n\ |
6406 | 3376 @end deftypefn") |
3377 { | |
3378 GO_BODY (text); | |
3379 } | |
3380 | |
3381 DEFUN (__go_image__, args, , | |
3382 "-*- texinfo -*-\n\ | |
3383 @deftypefn {Built-in Function} {} __go_image__ (@var{parent})\n\ | |
6945 | 3384 Undocumented internal function.\n\ |
6406 | 3385 @end deftypefn") |
3386 { | |
3387 GO_BODY (image); | |
3388 } | |
3389 | |
3390 DEFUN (__go_surface__, args, , | |
3391 "-*- texinfo -*-\n\ | |
3392 @deftypefn {Built-in Function} {} __go_surface__ (@var{parent})\n\ | |
6945 | 3393 Undocumented internal function.\n\ |
6406 | 3394 @end deftypefn") |
3395 { | |
3396 GO_BODY (surface); | |
3397 } | |
3398 | |
6807 | 3399 DEFUN (__go_patch__, args, , |
3400 "-*- texinfo -*-\n\ | |
3401 @deftypefn {Built-in Function} {} __go_patch__ (@var{parent})\n\ | |
6945 | 3402 Undocumented internal function.\n\ |
6807 | 3403 @end deftypefn") |
3404 { | |
3405 GO_BODY (patch); | |
3406 } | |
3407 | |
6406 | 3408 DEFUN (__go_delete__, args, , |
3409 "-*- texinfo -*-\n\ | |
3410 @deftypefn {Built-in Function} {} __go_delete__ (@var{h})\n\ | |
6945 | 3411 Undocumented internal function.\n\ |
6406 | 3412 @end deftypefn") |
3413 { | |
3414 octave_value_list retval; | |
3415 | |
3416 if (args.length () == 1) | |
3417 { | |
3418 graphics_handle h = octave_NaN; | |
3419 | |
3420 double val = args(0).double_value (); | |
3421 | |
3422 if (! error_state) | |
3423 { | |
3424 h = gh_manager::lookup (val); | |
3425 | |
7056 | 3426 if (h.ok ()) |
6406 | 3427 { |
3428 graphics_object obj = gh_manager::get_object (h); | |
3429 | |
3430 graphics_handle parent_h = obj.get_parent (); | |
3431 | |
3432 graphics_object parent_obj = gh_manager::get_object (parent_h); | |
3433 | |
7367 | 3434 // NOTE: free the handle before removing it from its parent's |
3435 // children, such that the object's state is correct when | |
3436 // the deletefcn callback is executed | |
6406 | 3437 |
3438 gh_manager::free (h); | |
7367 | 3439 |
3440 parent_obj.remove_child (h); | |
6406 | 3441 } |
3442 else | |
3443 error ("delete: invalid graphics object (= %g)", val); | |
3444 } | |
3445 else | |
3446 error ("delete: invalid graphics object"); | |
3447 } | |
3448 else | |
3449 print_usage (); | |
3450 | |
3451 return retval; | |
3452 } | |
3453 | |
3454 DEFUN (__go_axes_init__, args, , | |
3455 "-*- texinfo -*-\n\ | |
3456 @deftypefn {Built-in Function} {} __go_axes_init__ (@var{h}, @var{mode})\n\ | |
6945 | 3457 Undocumented internal function.\n\ |
6406 | 3458 @end deftypefn") |
3459 { | |
3460 octave_value retval; | |
3461 | |
3462 int nargin = args.length (); | |
3463 | |
3464 std::string mode = ""; | |
3465 | |
3466 if (nargin == 2) | |
3467 { | |
3468 mode = args(1).string_value (); | |
3469 | |
3470 if (error_state) | |
3471 return retval; | |
3472 } | |
3473 | |
3474 if (nargin == 1 || nargin == 2) | |
3475 { | |
3476 graphics_handle h = octave_NaN; | |
3477 | |
3478 double val = args(0).double_value (); | |
3479 | |
3480 if (! error_state) | |
3481 { | |
3482 h = gh_manager::lookup (val); | |
3483 | |
7056 | 3484 if (h.ok ()) |
6406 | 3485 { |
3486 graphics_object obj = gh_manager::get_object (h); | |
3487 | |
3488 obj.set_defaults (mode); | |
3489 } | |
3490 else | |
3491 error ("__go_axes_init__: invalid graphics object (= %g)", val); | |
3492 } | |
3493 else | |
3494 error ("__go_axes_init__: invalid graphics object"); | |
3495 } | |
3496 else | |
3497 print_usage (); | |
3498 | |
3499 return retval; | |
3500 } | |
3501 | |
3502 DEFUN (__go_handles__, , , | |
3503 "-*- texinfo -*-\n\ | |
3504 @deftypefn {Built-in Function} {} __go_handles__ ()\n\ | |
6945 | 3505 Undocumented internal function.\n\ |
6406 | 3506 @end deftypefn") |
3507 { | |
6425 | 3508 return octave_value (gh_manager::handle_list ()); |
3509 } | |
3510 | |
3511 DEFUN (__go_figure_handles__, , , | |
3512 "-*- texinfo -*-\n\ | |
3513 @deftypefn {Built-in Function} {} __go_figure_handles__ ()\n\ | |
6945 | 3514 Undocumented internal function.\n\ |
6425 | 3515 @end deftypefn") |
3516 { | |
3517 return octave_value (gh_manager::figure_handle_list ()); | |
6406 | 3518 } |
3519 | |
7835
ca8b97bb952c
added the function available_backends
Shai Ayal <shaiay@sourceforge.net>
parents:
7833
diff
changeset
|
3520 DEFUN (available_backends, args, , |
ca8b97bb952c
added the function available_backends
Shai Ayal <shaiay@sourceforge.net>
parents:
7833
diff
changeset
|
3521 "-*- texinfo -*-\n\ |
ca8b97bb952c
added the function available_backends
Shai Ayal <shaiay@sourceforge.net>
parents:
7833
diff
changeset
|
3522 @deftypefn {Built-in Function} {} available_backends ()\n\ |
ca8b97bb952c
added the function available_backends
Shai Ayal <shaiay@sourceforge.net>
parents:
7833
diff
changeset
|
3523 Returns resgistered graphics backends.\n\ |
ca8b97bb952c
added the function available_backends
Shai Ayal <shaiay@sourceforge.net>
parents:
7833
diff
changeset
|
3524 @end deftypefn") |
ca8b97bb952c
added the function available_backends
Shai Ayal <shaiay@sourceforge.net>
parents:
7833
diff
changeset
|
3525 { |
ca8b97bb952c
added the function available_backends
Shai Ayal <shaiay@sourceforge.net>
parents:
7833
diff
changeset
|
3526 return octave_value (graphics_backend::available_backends_list ()); |
ca8b97bb952c
added the function available_backends
Shai Ayal <shaiay@sourceforge.net>
parents:
7833
diff
changeset
|
3527 } |
ca8b97bb952c
added the function available_backends
Shai Ayal <shaiay@sourceforge.net>
parents:
7833
diff
changeset
|
3528 |
7409 | 3529 static void |
3530 clear_drawnow_request (void *) | |
3531 { | |
3532 Vdrawnow_requested = false; | |
3533 } | |
3534 | |
7408 | 3535 DEFUN (drawnow, args, , |
3536 "-*- texinfo -*-\n\ | |
3537 @deftypefn {Built-in Function} {} __go_drawnow__ ()\n\ | |
3538 @deftypefnx {Built-in Function} {} __go_drawnow__ (@var{term}, @var{file}, @var{mono}, @var{debug_file})\n\ | |
3539 Undocumented internal function.\n\ | |
3540 @end deftypefn") | |
3541 { | |
3542 static int drawnow_executing = 0; | |
3543 static bool __go_close_all_registered__ = false; | |
3544 | |
3545 octave_value retval; | |
3546 | |
7409 | 3547 unwind_protect::begin_frame ("Fdrawnow"); |
3548 unwind_protect::add (clear_drawnow_request); | |
3549 | |
3550 unwind_protect_int (drawnow_executing); | |
3551 | |
3552 if (++drawnow_executing <= 1) | |
7408 | 3553 { |
7409 | 3554 if (! __go_close_all_registered__) |
3555 { | |
3556 octave_add_atexit_function ("__go_close_all__"); | |
3557 | |
3558 __go_close_all_registered__ = true; | |
3559 } | |
3560 | |
3561 if (args.length () == 0) | |
7408 | 3562 { |
7409 | 3563 Matrix hlist = gh_manager::figure_handle_list (); |
3564 | |
3565 for (int i = 0; ! error_state && i < hlist.length (); i++) | |
7408 | 3566 { |
7409 | 3567 graphics_handle h = gh_manager::lookup (hlist(i)); |
3568 | |
3569 if (h.ok () && h != 0) | |
7408 | 3570 { |
7409 | 3571 graphics_object go = gh_manager::get_object (h); |
3572 figure::properties& fprops = dynamic_cast <figure::properties&> (go.get_properties ()); | |
3573 | |
3574 if (fprops.is_modified ()) | |
7408 | 3575 { |
7409 | 3576 if (fprops.is_visible ()) |
3577 fprops.get_backend ().redraw_figure (h); | |
3578 else if (! fprops.get___plot_stream__ ().is_empty ()) | |
3579 { | |
3580 fprops.close (false); | |
3581 fprops.set___plot_stream__ (Matrix ()); | |
3582 fprops.set___enhanced__ (false); | |
3583 } | |
3584 fprops.set_modified (false); | |
7408 | 3585 } |
3586 } | |
3587 } | |
3588 } | |
7409 | 3589 else if (args.length () >= 2 && args.length () <= 4) |
7408 | 3590 { |
7409 | 3591 std::string term, file, debug_file; |
3592 bool mono; | |
3593 | |
3594 term = args(0).string_value (); | |
7408 | 3595 |
3596 if (! error_state) | |
3597 { | |
7409 | 3598 file = args(1).string_value (); |
7408 | 3599 |
3600 if (! error_state) | |
3601 { | |
7409 | 3602 size_t pos = file.find_last_of (file_ops::dir_sep_chars); |
3603 | |
3604 if (pos != NPOS) | |
3605 { | |
3606 file_stat fs (file.substr (0, pos)); | |
3607 | |
3608 if (! (fs && fs.is_dir ())) | |
3609 error ("drawnow: nonexistent directory `%s'", | |
3610 file.substr (0, pos).c_str ()); | |
3611 } | |
3612 | |
3613 mono = (args.length () >= 3 ? args(2).bool_value () : false); | |
7408 | 3614 |
3615 if (! error_state) | |
3616 { | |
7409 | 3617 debug_file = (args.length () > 3 ? args(3).string_value () |
3618 : ""); | |
3619 | |
3620 if (! error_state) | |
7408 | 3621 { |
7409 | 3622 graphics_handle h = gcf (); |
3623 | |
3624 if (h.ok ()) | |
3625 { | |
3626 graphics_object go = gh_manager::get_object (h); | |
3627 | |
7419 | 3628 go.get_backend () |
7409 | 3629 .print_figure (h, term, file, mono, debug_file); |
3630 } | |
3631 else | |
3632 error ("drawnow: nothing to draw"); | |
7408 | 3633 } |
3634 else | |
7409 | 3635 error ("drawnow: invalid debug_file, expected a string value"); |
7408 | 3636 } |
3637 else | |
7409 | 3638 error ("drawnow: invalid colormode, expected a boolean value"); |
7408 | 3639 } |
3640 else | |
7409 | 3641 error ("drawnow: invalid file, expected a string value"); |
7408 | 3642 } |
3643 else | |
7409 | 3644 error ("drawnow: invalid terminal, expected a string value"); |
7408 | 3645 } |
3646 else | |
7409 | 3647 print_usage (); |
7408 | 3648 } |
7409 | 3649 |
3650 unwind_protect::run_frame ("Fdrawnow"); | |
7408 | 3651 |
3652 return retval; | |
3653 } | |
3654 | |
6595 | 3655 octave_value |
7447 | 3656 get_property_from_handle (double handle, const std::string& property, |
3657 const std::string& func) | |
6595 | 3658 { |
3659 graphics_object obj = gh_manager::get_object (handle); | |
3660 octave_value retval; | |
3661 | |
3662 if (obj) | |
3663 { | |
7189 | 3664 caseless_str p = std::string (property); |
6595 | 3665 retval = obj.get (p); |
3666 } | |
3667 else | |
3668 error ("%s: invalid handle (= %g)", func.c_str(), handle); | |
3669 | |
3670 return retval; | |
3671 } | |
3672 | |
3673 bool | |
7447 | 3674 set_property_in_handle (double handle, const std::string& property, |
3675 const octave_value& arg, const std::string& func) | |
6595 | 3676 { |
3677 graphics_object obj = gh_manager::get_object (handle); | |
3678 int ret = false; | |
3679 | |
3680 if (obj) | |
3681 { | |
7189 | 3682 caseless_str p = std::string (property); |
6595 | 3683 obj.set (p, arg); |
3684 if (!error_state) | |
3685 ret = true; | |
3686 } | |
3687 else | |
3688 error ("%s: invalid handle (= %g)", func.c_str(), handle); | |
3689 | |
3690 return ret; | |
3691 } | |
3692 | |
6406 | 3693 /* |
3694 ;;; Local Variables: *** | |
3695 ;;; mode: C++ *** | |
3696 ;;; End: *** | |
3697 */ |