NCCOOS Trac Projects: Top | Web | Platforms | Processing | Viz | Sprints | Sandbox | (Wind)

root/gliderproc/trunk/MATLAB/plots/tcolor.m

Revision 495 (checked in by cbc, 12 years ago)

Initial import of Stark code.

Line 
1 function H=tcolor(x,y,c,varargin)
2 % for use like pcolor but with c as a true color matrix (uses texturemap for speed)...
3 %
4 % H=tcolor(x,y,c[,method])
5 %
6 % valid methods are: 'corners','normal','triangles'
7 %
8 % The normal method is texture mapping unto the plane given by x and y
9 % (which may be distorted arbitrarily)
10 %
11 % The 'corners' method is the fastest way to draw. However it requires that
12 % the area is non-distorted... E.g. that the box defined by the corners
13 % defines the area.
14 %
15 % The slowest method is 'triangles'... (sort of like pcolor). But shading
16 % interp works with it.
17 %
18 % c=imread('C:\Projects\My Pictures\peppermint_girl.jpg');
19 % [x,y] = meshgrid(1:size(im,2),1:size(im,1));
20 % x=x+y/10; %skew the image
21 % H=tcolor(x,y,c,'corners')
22 %
23 % Aslak Grinsted - July 2003
24
25 cax = newplot;
26 hold_state = ishold;
27
28 lims = [min(min(x)) max(max(x)) min(min(y)) max(max(y))];
29
30
31 method=1; %1=normal,2=corners,3=triangles
32 if length(varargin)>0
33     method=strmatch(lower(varargin{1}),strvcat({'normal' 'corners' 'triangles'}));
34 end
35
36 triangles=0;
37 switch method
38     case 1
39     case 2
40         if length(size(x))==2
41             x=x([1 end],[1 end]);
42             y=y([1 end],[1 end]);
43         else
44             x=x([1 1;end end]);
45             y=y([1 end;1 end]);   
46         end
47     case 3
48         triangles=1;
49     otherwise
50         error('Unknown method?')
51         return
52 end
53    
54 if length(size(x))==1
55     [x,y]=meshgrid(x,y);
56 end
57
58 if triangles
59     H=patch(surf2patch(x,y,zeros(size(x)),im2double(c),'triangles'),'edgecolor','none','facecolor','flat');
60 else
61     H=surface(x,y,zeros(size(x)),c,'EdgeColor','none','FaceColor','texturemap');
62 end
63
64
65 if ~hold_state
66     set(cax,'View',[0 90]);
67     set(cax,'Box','on');
68     axis(lims);
69 end
70
71
72 if (nargout==0) clear H; end;
Note: See TracBrowser for help on using the browser.