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