comparison scripts/plot/private/__contour__.m @ 10549:95c3e38098bf

Untabify .m scripts
author Rik <code@nomad.inbox5.com>
date Fri, 23 Apr 2010 11:28:50 -0700
parents f074aa6b2c80
children 60542efcfa2c
comparison
equal deleted inserted replaced
10548:479536c5bb10 10549:95c3e38098bf
32 for i = 3 : nargin 32 for i = 3 : nargin
33 arg = varargin {i}; 33 arg = varargin {i};
34 if ((ischar (arg) || iscell (arg))) 34 if ((ischar (arg) || iscell (arg)))
35 [linespec, valid] = __pltopt__ ("__contour__", arg, false); 35 [linespec, valid] = __pltopt__ ("__contour__", arg, false);
36 if (isempty (linespec.color)) 36 if (isempty (linespec.color))
37 linespec.color = "auto"; 37 linespec.color = "auto";
38 endif 38 endif
39 if (isempty (linespec.linestyle)) 39 if (isempty (linespec.linestyle))
40 linespec.linestyle = "-"; 40 linespec.linestyle = "-";
41 endif 41 endif
42 if (valid) 42 if (valid)
43 have_line_spec = true; 43 have_line_spec = true;
44 varargin(i) = []; 44 varargin(i) = [];
45 break; 45 break;
46 endif 46 endif
47 endif 47 endif
48 endfor 48 endfor
49 49
50 opts = {}; 50 opts = {};
51 i = 3; 51 i = 3;
52 while (i < length (varargin)) 52 while (i < length (varargin))
53 if (ischar (varargin {i})) 53 if (ischar (varargin {i}))
54 if (strcmpi (varargin{i}, "fill")) 54 if (strcmpi (varargin{i}, "fill"))
55 filled = varargin {i + 1}; 55 filled = varargin {i + 1};
56 varargin(i:i+1) = []; 56 varargin(i:i+1) = [];
57 elseif (strcmpi (varargin{i}, "linecolor")) 57 elseif (strcmpi (varargin{i}, "linecolor"))
58 linespec.color = varargin {i + 1}; 58 linespec.color = varargin {i + 1};
59 edgecolor = linespec.color; 59 edgecolor = linespec.color;
60 if (ischar (edgecolor) && strcmpi (edgecolor, "auto")) 60 if (ischar (edgecolor) && strcmpi (edgecolor, "auto"))
61 edgecolor = "flat"; 61 edgecolor = "flat";
62 endif 62 endif
63 varargin(i:i+1) = []; 63 varargin(i:i+1) = [];
64 elseif (strcmpi (varargin{i}, "edgecolor")) 64 elseif (strcmpi (varargin{i}, "edgecolor"))
65 linespec.color = varargin {i + 1}; 65 linespec.color = varargin {i + 1};
66 edgecolor = linespec.color; 66 edgecolor = linespec.color;
67 if (ischar (edgecolor) && strcmpi (edgecolor, "flat")) 67 if (ischar (edgecolor) && strcmpi (edgecolor, "flat"))
68 linespec.color = "auto"; 68 linespec.color = "auto";
69 endif 69 endif
70 varargin(i:i+1) = []; 70 varargin(i:i+1) = [];
71 else 71 else
72 opts{end+1} = varargin{i}; 72 opts{end+1} = varargin{i};
73 varargin(i) = []; 73 varargin(i) = [];
74 opts{end+1} = varargin{i}; 74 opts{end+1} = varargin{i};
75 varargin(i) = []; 75 varargin(i) = [];
76 endif 76 endif
77 else 77 else
96 vn = 10; 96 vn = 10;
97 endif 97 endif
98 98
99 if (isscalar (vn)) 99 if (isscalar (vn))
100 lvl = linspace (min (z1(!isinf(z1))), max (z1(!isinf(z1))), 100 lvl = linspace (min (z1(!isinf(z1))), max (z1(!isinf(z1))),
101 vn + 2)(1:end-1); 101 vn + 2)(1:end-1);
102 else 102 else
103 lvl = vn; 103 lvl = vn;
104 endif 104 endif
105 105
106 if (strcmpi (filled, "on")) 106 if (strcmpi (filled, "on"))
254 ## background colour. 254 ## background colour.
255 for k = 1:numel (lev) 255 for k = 1:numel (lev)
256 lvl_idx = find (abs (cont_lev - lev(k)) < lvl_eps); 256 lvl_idx = find (abs (cont_lev - lev(k)) < lvl_eps);
257 len = numel (lvl_idx); 257 len = numel (lvl_idx);
258 if (len > 1) 258 if (len > 1)
259 ## mark = logical(zeros(size(lvl_idx))); 259 ## mark = logical(zeros(size(lvl_idx)));
260 mark = false (size (lvl_idx)); 260 mark = false (size (lvl_idx));
261 a = 1; 261 a = 1;
262 while (a < len) 262 while (a < len)
263 ## take 1st patch 263 ## take 1st patch
264 b = a + 1; 264 b = a + 1;
265 pa_idx = lvl_idx(a); 265 pa_idx = lvl_idx(a);
266 ## get pointer to contour start, and contour length 266 ## get pointer to contour start, and contour length
267 curr_ct_idx = cont_idx(pa_idx); 267 curr_ct_idx = cont_idx(pa_idx);
268 curr_ct_len = cont_len(pa_idx); 268 curr_ct_len = cont_len(pa_idx);
269 ## get contour 269 ## get contour
270 curr_ct = c(:, curr_ct_idx:curr_ct_idx+curr_ct_len-1); 270 curr_ct = c(:, curr_ct_idx:curr_ct_idx+curr_ct_len-1);
271 b_vec = (a+1):len; 271 b_vec = (a+1):len;
272 next_ct_pt_vec = c(:, cont_idx(lvl_idx(b_vec))); 272 next_ct_pt_vec = c(:, cont_idx(lvl_idx(b_vec)));
273 in = inpolygon (next_ct_pt_vec(1,:), next_ct_pt_vec(2,:), 273 in = inpolygon (next_ct_pt_vec(1,:), next_ct_pt_vec(2,:),
274 curr_ct(1, :), curr_ct(2, :)); 274 curr_ct(1, :), curr_ct(2, :));
275 mark(b_vec(in)) = !mark(b_vec(in)); 275 mark(b_vec(in)) = !mark(b_vec(in));
276 a++; 276 a++;
277 endwhile 277 endwhile
278 if (numel (mark) > 0) 278 if (numel (mark) > 0)
279 ## All marked contours describe a hole in a larger contour of 279 ## All marked contours describe a hole in a larger contour of
280 ## the same level and must be filled with colour of level below. 280 ## the same level and must be filled with colour of level below.
281 ma_idx = lvl_idx(mark); 281 ma_idx = lvl_idx(mark);
282 if (k > 1) 282 if (k > 1)
283 ## Find color of level below. 283 ## Find color of level below.
284 tmp = find(abs(cont_lev - lev(k - 1)) < lvl_eps); 284 tmp = find(abs(cont_lev - lev(k - 1)) < lvl_eps);
285 lvl_bel_idx = tmp(1); 285 lvl_bel_idx = tmp(1);
286 ## Set color of patches found. 286 ## Set color of patches found.
287 cont_lev(ma_idx) = cont_lev(lvl_bel_idx); 287 cont_lev(ma_idx) = cont_lev(lvl_bel_idx);
288 else 288 else
289 ## Set lowest level contour to NaN. 289 ## Set lowest level contour to NaN.
290 cont_lev(ma_idx) = NaN; 290 cont_lev(ma_idx) = NaN;
291 endif 291 endif
292 endif 292 endif
293 endif 293 endif
294 endfor 294 endfor
295 295
296 ## The algorithm can create patches with the size of the plotting 296 ## The algorithm can create patches with the size of the plotting
297 ## area, we would like to draw only the patch with the highest level. 297 ## area, we would like to draw only the patch with the highest level.
313 idx = svec(n); 313 idx = svec(n);
314 ctmp = c(:, cont_idx(idx):cont_idx(idx) + cont_len(idx) - 1); 314 ctmp = c(:, cont_idx(idx):cont_idx(idx) + cont_len(idx) - 1);
315 if (all (ctmp(:,1) == ctmp(:,end))) 315 if (all (ctmp(:,1) == ctmp(:,end)))
316 ctmp(:, end) = []; 316 ctmp(:, end) = [];
317 else 317 else
318 ## Special case unclosed contours 318 ## Special case unclosed contours
319 endif 319 endif
320 h = [h; patch(ctmp(1, :), ctmp(2, :), cont_lev(idx), "edgecolor", lc, 320 h = [h; patch(ctmp(1, :), ctmp(2, :), cont_lev(idx), "edgecolor", lc,
321 "linestyle", ls, "linewidth", lw, "parent", hg)]; 321 "linestyle", ls, "linewidth", lw, "parent", hg)];
322 endfor 322 endfor
323 323
324 if (min (lev) == max (lev)) 324 if (min (lev) == max (lev))
325 set (gca (), "clim", [min(lev)-1, max(lev)+1]); 325 set (gca (), "clim", [min(lev)-1, max(lev)+1]);
326 else 326 else
335 while (i1 < length (c)) 335 while (i1 < length (c))
336 clev = c(1,i1); 336 clev = c(1,i1);
337 clen = c(2,i1); 337 clen = c(2,i1);
338 338
339 if (all (c(:,i1+1) == c(:,i1+clen))) 339 if (all (c(:,i1+1) == c(:,i1+clen)))
340 p = c(:, i1+1:i1+clen-1); 340 p = c(:, i1+1:i1+clen-1);
341 else 341 else
342 p = [c(:, i1+1:i1+clen), NaN(2, 1)]; 342 p = [c(:, i1+1:i1+clen), NaN(2, 1)];
343 endif 343 endif
344 344
345 switch (zmode) 345 switch (zmode)
346 case "none" 346 case "none"
347 h = [h; patch(p(1,:), p(2,:), "facecolor", "none", 347 h = [h; patch(p(1,:), p(2,:), "facecolor", "none",
348 "edgecolor", lc, "linestyle", ls, "linewidth", lw, 348 "edgecolor", lc, "linestyle", ls, "linewidth", lw,
349 "cdata", clev, "parent", hg)]; 349 "cdata", clev, "parent", hg)];
350 case "auto" 350 case "auto"
351 h = [h; patch(p(1,:), p(2,:), clev * ones (1, columns (p)), 351 h = [h; patch(p(1,:), p(2,:), clev * ones (1, columns (p)),
352 "facecolor", "none", "edgecolor", lc, 352 "facecolor", "none", "edgecolor", lc,
353 "linestyle", ls, "linewidth", lw, "cdata", clev, 353 "linestyle", ls, "linewidth", lw, "cdata", clev,
354 "parent", hg)]; 354 "parent", hg)];
355 otherwise 355 otherwise
356 h = [h; patch(p(1,:), p(2,:), z * ones (1, columns (p)), 356 h = [h; patch(p(1,:), p(2,:), z * ones (1, columns (p)),
357 "facecolor", "none", "edgecolor", lc, 357 "facecolor", "none", "edgecolor", lc,
358 "linestyle", ls, "linewidth", lw, "cdata", clev, 358 "linestyle", ls, "linewidth", lw, "cdata", clev,
359 "parent", hg)]; 359 "parent", hg)];
360 endswitch 360 endswitch
361 i1 += clen+1; 361 i1 += clen+1;
362 endwhile 362 endwhile
363 endif 363 endif
364 364
372 switch (zmode) 372 switch (zmode)
373 case "none" 373 case "none"
374 set (kids, "zdata", []); 374 set (kids, "zdata", []);
375 case "auto" 375 case "auto"
376 for i = 1 : length (kids) 376 for i = 1 : length (kids)
377 set (kids(i), "zdata", get (kids (i), "cdata") .* 377 set (kids(i), "zdata", get (kids (i), "cdata") .*
378 ones (size (get (kids (i), "xdata")))); 378 ones (size (get (kids (i), "xdata"))));
379 endfor 379 endfor
380 otherwise 380 otherwise
381 for i = 1 : length (kids) 381 for i = 1 : length (kids)
382 set (kids(i), "zdata", z .* ones (size (get (kids (i), "xdata")))); 382 set (kids(i), "zdata", z .* ones (size (get (kids (i), "xdata"))));
383 endfor 383 endfor
384 endswitch 384 endswitch
385 endfunction 385 endfunction
386 386
387 function update_edgecolor (h, d) 387 function update_edgecolor (h, d)
429 if (strcmpi (get (h, "fill"), "on")) 429 if (strcmpi (get (h, "fill"), "on"))
430 X = get (h, "xdata"); 430 X = get (h, "xdata");
431 Y = get (h, "ydata"); 431 Y = get (h, "ydata");
432 Z = get (h, "zdata"); 432 Z = get (h, "zdata");
433 if (isvector (X) || isvector (Y)) 433 if (isvector (X) || isvector (Y))
434 [X, Y] = meshgrid (X, Y); 434 [X, Y] = meshgrid (X, Y);
435 endif 435 endif
436 [nr, nc] = size (Z); 436 [nr, nc] = size (Z);
437 X0 = prepad(X, nc+1, 2 * X(1, 1) - X(1, 2), 2); 437 X0 = prepad(X, nc+1, 2 * X(1, 1) - X(1, 2), 2);
438 X0 = postpad(X0, nc+2, 2 * X(1, nc) - X(1, nc - 1), 2); 438 X0 = postpad(X0, nc+2, 2 * X(1, nc) - X(1, nc - 1), 2);
439 X0 = [X0(1, :); X0; X0(1, :)]; 439 X0 = [X0(1, :); X0; X0(1, :)];
443 Z0 = -Inf(nr+2, nc+2); 443 Z0 = -Inf(nr+2, nc+2);
444 Z0(2:nr+1, 2:nc+1) = Z; 444 Z0(2:nr+1, 2:nc+1) = Z;
445 [c, lev] = contourc (X0, Y0, Z0, lvl); 445 [c, lev] = contourc (X0, Y0, Z0, lvl);
446 else 446 else
447 [c, lev] = contourc (get (h, "xdata"), get (h, "ydata"), 447 [c, lev] = contourc (get (h, "xdata"), get (h, "ydata"),
448 get (h, "zdata"), lvl); 448 get (h, "zdata"), lvl);
449 endif 449 endif
450 set (h, "contourmatrix", c); 450 set (h, "contourmatrix", c);
451 451
452 if (strcmpi (get (h, "levellistmode"), "manual")) 452 if (strcmpi (get (h, "levellistmode"), "manual"))
453 ## Do nothing 453 ## Do nothing
491 set (h, "textlist", lvl, "textstep", get (h, "levelstep")); 491 set (h, "textlist", lvl, "textstep", get (h, "levelstep"));
492 endif 492 endif
493 493
494 if (strcmpi (get (h, "showtext"), "on")) 494 if (strcmpi (get (h, "showtext"), "on"))
495 switch (get (h, "zlevelmode")) 495 switch (get (h, "zlevelmode"))
496 case "manual" 496 case "manual"
497 __clabel__ (get (h, "contourmatrix"), lvl, h, 497 __clabel__ (get (h, "contourmatrix"), lvl, h,
498 get (h, "labelspacing"), get (h, "zlevel")); 498 get (h, "labelspacing"), get (h, "zlevel"));
499 case "auto" 499 case "auto"
500 __clabel__ (get (h, "contourmatrix"), lvl, h, 500 __clabel__ (get (h, "contourmatrix"), lvl, h,
501 get (h, "labelspacing"), "auto"); 501 get (h, "labelspacing"), "auto");
502 otherwise 502 otherwise
503 __clabel__ (get (h, "contourmatrix"), lvl, h, 503 __clabel__ (get (h, "contourmatrix"), lvl, h,
504 get (h, "labelspacing"), []); 504 get (h, "labelspacing"), []);
505 endswitch 505 endswitch
506 endif 506 endif
507 endif 507 endif
508 508
509 recursive = false; 509 recursive = false;