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